I hope there are some HC-05 experts as I am pulling my hair out at this!
I am trying to connect my HC-05 to an ELM327 OBD2 bluetooth connector.
The only micro controller that I have to hand at the minute is a Wemos D1 mini, not ideal as there are only one set of serial pins and they are shared with the USB.
So I have connected the HC-05 as follows:
Wemos -> HC-05
5v -> 5v (vin)
gnd -> gnd
RX -> TX
TX -> RX
I have an I2C LCD display also connected as I can't use the serial monitor. I am doing the AT Commands in code.
I am powering the Wemos with the 5v pin.
My AT Command code looks like:
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
const byte rxPin = 3; // Wire this to Tx Pin of ESP8266
const byte txPin = 1; // Wire this to Rx Pin of ESP8266
// We'll use a software serial interface to connect to ESP8266
SoftwareSerial bt_serial(rxPin, txPin);
void setup()
{
delay(7000);
bt_serial.begin(38400); // Change this to the baudrate used by ESP8266
// Initialize the LCD
lcd.init();
lcd.backlight();
delay(1000);
lcd.setCursor(0, 0);
lcd.print("Sending AT");
bt_serial.println("AT");
delay(1000);
String in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
// lcd.setCursor(0, 0);
// lcd.print("Sending AT+INQC");
// bt_serial.println("AT+INQC");
// delay(1000);
// in_data = bt_serial.readStringUntil('\n');
// lcd.setCursor(0, 1);
// lcd.print("Response:");
// lcd.setCursor(0, 2);
// lcd.print(in_data);
// delay(2000);
// lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+UART?");
bt_serial.println("AT+UART?");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+ORGL");
bt_serial.println("AT+ORGL");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+ROLE=1");
bt_serial.println("AT+ROLE=1");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+RESET");
bt_serial.println("AT+RESET");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+ADCN?");
bt_serial.println("AT+ADCN?");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+RMAAD");
bt_serial.println("AT+RMAAD");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+PAIR");
bt_serial.println("AT+PAIR=001D,A5,68988C,20");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+BIND");
bt_serial.println("AT+BIND=001D,A5,68988C");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sending AT+LINK");
bt_serial.println("AT+LINK=001D,A5,68988C");
delay(1000);
in_data = bt_serial.readStringUntil('\n');
lcd.setCursor(0, 1);
lcd.print("Response:");
lcd.setCursor(0, 2);
lcd.print(in_data);
}
void loop()
{
}
I got the MAC of the ELM327 by connecting it to my Mac and finding out there.
I hold the button on the HC-05 as I give it power and the LED does slow blinking.
All the commands come back with a response of OK. (sounds good)
I then load this code onto the wemos:
#include <SoftwareSerial.h>
#include "ELMduino.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
SoftwareSerial mySerial(3, 1); // RX, TX
#define ELM_PORT mySerial
ELM327 myELM327;
uint32_t rpm = 0;
void setup()
{
// Initialize the LCD
lcd.init();
lcd.backlight();
ELM_PORT.begin(9600);
lcd.setCursor(0, 0);
lcd.print("Attempting connect");
if (!myELM327.begin(ELM_PORT))
{
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Failed connect");
while (1);
}
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("Connected to ELM327");
}
void loop()
{
float tempRPM = myELM327.rpm();
if (myELM327.status == ELM_SUCCESS)
{
rpm = (uint32_t)tempRPM;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("RPM: ");
lcd.setCursor(0, 1);
lcd.print(rpm);
}
else
{
lcd.clear();
lcd.print(F("\tERROR: "));
// Serial.println(myELM327.status);S
delay(333);
}
}
The LED on the HC-05 just blinks very fast (not sure what it is meant to do when connected) and it just says failed to connect
What am I doing wrong?
I initially followed this:
But the link command always failed.
I then saw this:
This allowed me to get the link command to pass. I don't understand the bit at the bottom with AT+DISC. I tried loading the above AT Commands, powering down, loading code with just AT, AT+DISC, AT+LINK. The DISC fails with something like NO_SLCE and the LINK just FAILs.
AT+PSWD? shows 1234 and this is correct for the ELM327.
Any help would be appreciated.