Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Vehicle Communicator
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2025-07-11 20:41:48
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* send translate data over bluetooth */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- float T_interpolate(byte DS_Temp); // Prototype added
- /***** DEFINITION OF Software Serial *****/
- const uint8_t hc05_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
- const uint8_t hc05_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
- SoftwareSerial hc05_HC05_mySerial(hc05_HC05_mySerial_PIN_SERIAL_RX_A1, hc05_HC05_mySerial_PIN_SERIAL_TX_A0);
- // ***** Variable declariations
- const byte ALDLTestPin = 4; // Input used to listen for 160 BAUD ALDL activity before commanding 8192 BAUD
- const byte DecodeDataOutputPin = 5; // Setting this input pin LOW will put decoded data out on the serial port
- const byte HexDataOutputPin = 6; // Setting this input LOW will output hex data on the serial port
- int ALDLbyte = 0; // One byte of aldl data
- int bytecounter = 0; // count bytes for line spacing in output
- const int linecount = 64; // 32 bytes per line
- byte M1Cmd[4] = {0x80, 0x56, 0x01, 0x29}; // Mode 1 command to start 8192 Mode 1 DataStream (80 56 01 29 HEX)
- byte Preamble[3] = {0x80, 0x95, 0x01}; // Preamble from ECM indicates start of 8192 Mode 1 DataStream (80 95 01 HEX)
- bool PreambleFound = false; // Reset preamble found flag
- bool SilenceFound = false; // Flag to indicate that ECM silence in 160 baud mode has been found
- bool CommInit8192 = false; // Flag indicates that 8192 baud communications has been initialized
- const double SilenceWait = 15000; // Minimum silence period before transmitting a Mode 1 command
- unsigned long PreambleTimer; // Timeout timer for preamble
- const int ByteCount = 64; // Number of data bytes following preamble in data stream including checksum
- byte DataBytes[ByteCount]; // Array to hold the serial data stream
- int DataStreamIndex = 1; // Data stream byte Index, start at 1 and end at 63 to match Assembly listing
- int i = 0; // Preamble index counter
- unsigned long StartTime; // Microsecond counter for measuring the time of incoming data
- unsigned int CheckTotal; // Total of bytes received for calculating the checksum
- byte CheckSum; // Actual calculated Checksum
- // Variables specifically for the decoded data stream
- float RPM; // Engine RPM
- float TPS; // Percent TPS
- float MAF; // Mass Air Flow gm/sec
- float InjPW; // Injector Pulse Width
- float O2mv; // O2 sensor MV
- int BLCELL; // Currently used block learn cell #. There are 16 cells organized by RPM and air flow 0, is idle, 15 is max RPM & Airflow
- int BLM; // Block Learn Value for cell being currently used
- int INTEGRATOR; // Current fueling control integrator value over 128 indicates fuel is added, under 128 fuel is taken out, 160 max
- float MAT; // Intake Manifold Air Temperature
- unsigned int Runtime; // Engine Run time
- // ***** Hardware configuration
- //HardwareSerial Serial1(2); // Define uart2 as Serial1 - **** USED ONLY ON ESP32 *****
- void setup()
- {
- // **** I/O configuration and setup first
- pinMode(ALDLTestPin, INPUT); // define D4 as an input pin to listen for the 160 baud input data
- pinMode(HexDataOutputPin, INPUT_PULLUP); // User convenience pin. Grounding this pin will send Decoded Data to the Serial Port
- pinMode(HexDataOutputPin, INPUT_PULLUP); // User convenience pin. Grounding this pin will send HEX Data to the Serial Port
- // **** Now, start the serial functions
- Serial.begin(115200); // Open serial monitoring port
- Serial1.begin(8192); // Test the capability of esp 8222 to run at 8192 baud directly
- delay(1500); // delay for diagnostic print
- Serial.println("Ready for data capture");
- // Initialize Bluetooth serial
- hc05_HC05_mySerial.begin(9600);
- // Initialize the variables, flags, etc
- i = 0; // Reset the preamble index flag
- }
- void loop() {
- // Existing data capture and decoding code...
- // After processing data, send translated data over Bluetooth
- // For demonstration, send a simple message periodically or when new data is received
- static unsigned long lastSendTime = 0;
- unsigned long currentTime = millis();
- // Example: send data every 5 seconds
- if (currentTime - lastSendTime >= 5000) {
- lastSendTime = currentTime;
- // Compose a message to send
- String message = "Engine RPM: ";
- message += String(RPM);
- message += " | TPS: ";
- message += String(TPS);
- message += " | MAF: ";
- message += String(MAF);
- // Send over Bluetooth
- hc05_HC05_mySerial.println(message);
- }
- // Rest of your existing loop code...
- // (Include your data decoding and processing code here)
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment