pleasedontcode

Vehicle Communicator rev_02

Jul 11th, 2025
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Vehicle Communicator
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2025-07-11 20:41:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* send translate data over bluetooth */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <SoftwareSerial.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. float T_interpolate(byte DS_Temp); // Prototype added
  32.  
  33. /***** DEFINITION OF Software Serial *****/
  34. const uint8_t hc05_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  35. const uint8_t hc05_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  36. SoftwareSerial hc05_HC05_mySerial(hc05_HC05_mySerial_PIN_SERIAL_RX_A1, hc05_HC05_mySerial_PIN_SERIAL_TX_A0);
  37.  
  38. // ***** Variable declariations
  39. const byte ALDLTestPin = 4; // Input used to listen for 160 BAUD ALDL activity before commanding 8192 BAUD
  40. const byte DecodeDataOutputPin = 5; // Setting this input pin LOW will put decoded data out on the serial port
  41. const byte HexDataOutputPin = 6; // Setting this input LOW will output hex data on the serial port
  42. int ALDLbyte = 0; // One byte of aldl data
  43. int bytecounter = 0; // count bytes for line spacing in output
  44. const int linecount = 64; // 32 bytes per line
  45. byte M1Cmd[4] = {0x80, 0x56, 0x01, 0x29}; // Mode 1 command to start 8192 Mode 1 DataStream (80 56 01 29 HEX)
  46. byte Preamble[3] = {0x80, 0x95, 0x01}; // Preamble from ECM indicates start of 8192 Mode 1 DataStream (80 95 01 HEX)
  47. bool PreambleFound = false; // Reset preamble found flag
  48. bool SilenceFound = false; // Flag to indicate that ECM silence in 160 baud mode has been found
  49. bool CommInit8192 = false; // Flag indicates that 8192 baud communications has been initialized
  50. const double SilenceWait = 15000; // Minimum silence period before transmitting a Mode 1 command
  51. unsigned long PreambleTimer; // Timeout timer for preamble
  52. const int ByteCount = 64; // Number of data bytes following preamble in data stream including checksum
  53. byte DataBytes[ByteCount]; // Array to hold the serial data stream
  54. int DataStreamIndex = 1; // Data stream byte Index, start at 1 and end at 63 to match Assembly listing
  55. int i = 0; // Preamble index counter
  56. unsigned long StartTime; // Microsecond counter for measuring the time of incoming data
  57. unsigned int CheckTotal; // Total of bytes received for calculating the checksum
  58. byte CheckSum; // Actual calculated Checksum
  59.  
  60. // Variables specifically for the decoded data stream
  61. float RPM; // Engine RPM
  62. float TPS; // Percent TPS
  63. float MAF; // Mass Air Flow gm/sec
  64. float InjPW; // Injector Pulse Width
  65. float O2mv; // O2 sensor MV
  66. 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
  67. int BLM; // Block Learn Value for cell being currently used
  68. int INTEGRATOR; // Current fueling control integrator value over 128 indicates fuel is added, under 128 fuel is taken out, 160 max
  69. float MAT; // Intake Manifold Air Temperature
  70. unsigned int Runtime; // Engine Run time
  71.  
  72. // ***** Hardware configuration
  73. //HardwareSerial Serial1(2); // Define uart2 as Serial1 - **** USED ONLY ON ESP32 *****
  74.  
  75. void setup()
  76. {
  77.   // **** I/O configuration and setup first
  78.   pinMode(ALDLTestPin, INPUT); // define D4 as an input pin to listen for the 160 baud input data
  79.   pinMode(HexDataOutputPin, INPUT_PULLUP); // User convenience pin. Grounding this pin will send Decoded Data to the Serial Port
  80.   pinMode(HexDataOutputPin, INPUT_PULLUP); // User convenience pin. Grounding this pin will send HEX Data to the Serial Port
  81.   // **** Now, start the serial functions
  82.   Serial.begin(115200); // Open serial monitoring port
  83.   Serial1.begin(8192); // Test the capability of esp 8222 to run at 8192 baud directly
  84.   delay(1500); // delay for diagnostic print
  85.   Serial.println("Ready for data capture");
  86.   // Initialize Bluetooth serial
  87.   hc05_HC05_mySerial.begin(9600);
  88.   // Initialize the variables, flags, etc
  89.   i = 0; // Reset the preamble index flag
  90. }
  91.  
  92. void loop() {
  93.   // Existing data capture and decoding code...
  94.   // After processing data, send translated data over Bluetooth
  95.   // For demonstration, send a simple message periodically or when new data is received
  96.   static unsigned long lastSendTime = 0;
  97.   unsigned long currentTime = millis();
  98.  
  99.   // Example: send data every 5 seconds
  100.   if (currentTime - lastSendTime >= 5000) {
  101.     lastSendTime = currentTime;
  102.     // Compose a message to send
  103.     String message = "Engine RPM: ";
  104.     message += String(RPM);
  105.     message += " | TPS: ";
  106.     message += String(TPS);
  107.     message += " | MAF: ";
  108.     message += String(MAF);
  109.     // Send over Bluetooth
  110.     hc05_HC05_mySerial.println(message);
  111.   }
  112.  
  113.   // Rest of your existing loop code...
  114.   // (Include your data decoding and processing code here)
  115. }
  116.  
  117. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment