Bluetoothserial Library

Hi,

I'm working on an hobby project to communicate bluetooth device (ELM327), using Elmduino library GitHub - PowerBroker2/ELMduino: Arduino OBD-II Bluetooth Scanner Interface Library for Car Hacking Projects, this library requires Bluetoothserial.h, as far as i understand that library part of ESP32 board, so i've installed ESP32 to arduino ide through this tutorial https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md, and when i try to run this code;

#include "BluetoothSerial.h"
#include "ELMduino.h"


BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial


ELM327 myELM327;


uint32_t rpm = 0;


void setup()
{
#if LED_BUILTIN
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
#endif

  DEBUG_PORT.begin(115200);
  SerialBT.setPin("1234");
  ELM_PORT.begin("OBDII", true);
  
  if (!ELM_PORT.connect("OBDII"))
  {
    DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
    while(1);
  }

  if (!myELM327.begin(ELM_PORT))
  {
    Serial.println("Couldn't connect to OBD scanner - Phase 2");
    while (1);
  }

  Serial.println("Connected to ELM327");
}


void loop()
{
  float tempRPM = myELM327.rpm();

  if (myELM327.status == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else
    printError();
}


void printError()
{
  Serial.print("Received: ");
  for (byte i = 0; i < myELM327.recBytes; i++)
    Serial.write(myELM327.payload[i]);
  Serial.println();
  if (myELM327.status == ELM_SUCCESS)
    Serial.println(F("\tELM_SUCCESS"));
  else if (myELM327.status == ELM_NO_RESPONSE)
    Serial.println(F("\tERROR: ELM_NO_RESPONSE"));
  else if (myELM327.status == ELM_BUFFER_OVERFLOW)
    Serial.println(F("\tERROR: ELM_BUFFER_OVERFLOW"));
  else if (myELM327.status == ELM_UNABLE_TO_CONNECT)
    Serial.println(F("\tERROR: ELM_UNABLE_TO_CONNECT"));
  else if (myELM327.status == ELM_NO_DATA)
    Serial.println(F("\tERROR: ELM_NO_DATA"));
  else if (myELM327.status == ELM_STOPPED)
    Serial.println(F("\tERROR: ELM_STOPPED"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_TIMEOUT"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_GENERAL_ERROR"));
  delay(100);
}

it returns :

BluetoothSerial.h: No such file or directory

It seems like it's not downloading necessary library when i install ESP32 board to arduino ide, downloaded library from GitHub - espressif/arduino-esp32: Arduino core for the ESP32 and copied arduino-esp32-master folder to arduino's library folder but when i try the run the code it returns :
BluetoothSerial.h: No such file or directory again, so in the arduino-esp32-master folder, there is libraries folder and there are 27 libraries including BluetoothSerial folder, copied all of them to arduino's library folder, after that when i try run the code it returns:

In file included from C:\Users\FSC\Desktop\SPARKFUN\Bluetooth_ELM327_ILE_CALISAN\ELMduino-master\examples\ESP32_Bluetooth_Serial\ESP32_Bluetooth_Serial.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\BluetoothSerial\src/BluetoothSerial.h:18:10: fatal error: sdkconfig.h: No such file or directory

 #include "sdkconfig.h"

          ^~~~~~~~~~~~~

compilation terminated.

exit status 1

what am i doing wrong here? how i can install the BluetoothSerial library?

1 Like

What’s your arduino? An ESP32?

J-M-L:
What’s your arduino? An ESP32?

no not an ESP32, i'm working with arduino uno+hc-05, i know hc-05 doesn't need BluetoothSerial.h but this code requires that.

this code only works if you have an ESP32,not works on arduino directly, @J-M-L thank you for your time.

Exactly - when choosing the platform you also select what libraries are accessible. That’s why the compiler was not finding the .h file

could you just use SoftwareSerial without BluetoothSerial.h as in ELMduino ?

Are you using level converters with the Uno? the HC-05 Rx and Tx are 3.3V level

If I connect a HC-05 to an Arduino Due

// HC-05 Bluetooth module AT commands
// note Serial1 baudrate is 9600

// using Arduino Due  (not HC-05 Rx and Tx are 3.3V
// Arduino %V and GND to HC-05 5V and GND
// Arduino pin 18 Tx to HC-05 Rx
// Arduino pin 19 Rx to HC-05 Tx

void setup()
{
  Serial.begin(115200);
  Serial.println("Enter AT commands:");
  Serial1.begin(9600);//38400);       // HC-05 default speed in AT command more
}

void loop()
{
  if ( Serial1.available())    // read from HC-05 and send to Arduino Serial Monitor
  Serial.write( Serial1.read());

  if (Serial.available())     // Keep reading from Arduino Serial Monitor and send to HC-05
  Serial1.write(Serial.read());
}

Bluetooth Terminal on an Android recives and transmits text without problems

horace:
could you just use SoftwareSerial without BluetoothSerial.h as in ELMduino ?

Are you using level converters with the Uno? the HC-05 Rx and Tx are 3.3V level

If I connect a HC-05 to an Arduino Due

// HC-05 Bluetooth module AT commands

// note Serial1 baudrate is 9600

// using Arduino Due  (not HC-05 Rx and Tx are 3.3V
// Arduino %V and GND to HC-05 5V and GND
// Arduino pin 18 Tx to HC-05 Rx
// Arduino pin 19 Rx to HC-05 Tx

void setup()
{
  Serial.begin(115200);
  Serial.println("Enter AT commands:");
  Serial1.begin(9600);//38400);      // HC-05 default speed in AT command more
}

void loop()
{
  if ( Serial1.available())    // read from HC-05 and send to Arduino Serial Monitor
  Serial.write( Serial1.read());

if (Serial.available())    // Keep reading from Arduino Serial Monitor and send to HC-05
  Serial1.write(Serial.read());
}



Bluetooth Terminal on an Android recives and transmits text without problems

i already managed to work with HC-05 but the problem is HC-05 is slow compared to esp32, for example you need to add at least 1000ms delay for each parameter (rpm,speed,water coolant etc.) otherwise it freezes after 1-2 minutes, with esp32 you don't having that problem, i'm new at esp32 modules, i thought you are programing esp32 through arduino but i learnt that it has it's own cpu and you need to program by itself and you can communicate through via tx-rx pins, being a rookie is hard man :slight_smile:

sheshman:
i already managed to work with HC-05 but the problem is HC-05 is slow compared to esp32, for example you need to add at least 1000ms delay for each parameter (rpm,speed,water coolant etc.)

Sorry that’s likely BS... the pace is dictated by the baud rate which has to be the same on both side and the way you handle your receiver code. Adding delays can only make things worse.

I would suggest to study Serial Input Basics to handle this