Advertisement
Maderdash

ESP

Feb 10th, 2022
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //ESP CODE:
  2. #include "BluetoothSerial.h"
  3. #include "ELMduino.h"
  4.  
  5.  
  6. BluetoothSerial SerialBT;
  7. #define ELM_PORT   SerialBT
  8. #define DEBUG_PORT Serial
  9.  
  10.  
  11. ELM327 myELM327;
  12.  
  13.  
  14. uint32_t rpm = 0;
  15.  
  16.  
  17. void setup()
  18. {
  19. #if LED_BUILTIN
  20.   pinMode(LED_BUILTIN, OUTPUT);
  21.   digitalWrite(LED_BUILTIN, LOW);
  22. #endif
  23.  
  24.   DEBUG_PORT.begin(115200);
  25.   //SerialBT.setPin("1234");
  26.   ELM_PORT.begin("ArduHUD", true);
  27.  
  28.   if (!ELM_PORT.connect("Android-Vlink"))
  29.   {
  30.     DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
  31.     while(1);
  32.   }
  33.  
  34.   if (!myELM327.begin(ELM_PORT, true, 2000))
  35.   {
  36.     Serial.println("Couldn't connect to OBD scanner - Phase 2");
  37.     while (1);
  38.   }
  39.  
  40.   Serial.println("Connected to ELM327");
  41. }
  42.  
  43.  
  44. void loop()
  45. {
  46.   float tempRPM = myELM327.rpm();
  47.  
  48.   if (myELM327.nb_rx_state == ELM_SUCCESS)
  49.   {
  50.     rpm = (uint32_t)tempRPM;
  51.     Serial.print("RPM: "); Serial.println(rpm);
  52.   }
  53.   else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  54.     myELM327.printError();
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement