Advices for a bluetooth project, how to connect to external bluetooth device (ANT BMS)

Hello everyone,
I want to use an arduino board (probably mega 2560 mini pro) to connect to an ANT BMS (which has embeded bluetooth).

So far I haven't found anyone else to use arduino to connect to Ant BMS but there are a few projects using a raspberry pi, as I already have an mega2560 board talking with an Energy Meter on Serial1, with my MPP Solar inverter on serial2, I want to use the same board to also talk with the BMS that monitors the battery.

  1. My first concern is regarding about HOW I WILL PAIR Arduino's HC-05 bluetooth module with AntBMS? I haven't found any tutorial yet, only the other way around, smartphone pairs with arduino bluetooth. I belive using AT commands? but it would be great if the pairing could be done in the code, eventually in the void setup() section.

  2. My second problem is regarding sending commands over bluetooth, I don't have any experience regarding sending commands, I just started now 2 weeks ago when I needed to connect to MPP Inverter, and with the help of a few guys on the forum, I have my arduino board running smoothly in the last week, talking to my inverter every 2 seconds, pushing data to my local server every 5 seconds.
    I made a code that theoretically should send the command to AntBMS and print the response to serial, I don't know why the guys that made the python code use the decode(hex) function. In the Communication Manual of Ant BMS it just says to send "0XDBDB00000000 return 140 byte date"

ANT_communication_protocol_EN.pdf (47.5 KB)

Does my code looking correct ?

/*
PYTHON CODE EXAMPLE

while True :
 test='DBDB00000000'
 try:
   ser.write (test.decode('hex'))
 except: 
   ser.close()
 time.sleep(1)
 if(ser.isOpen() == False):
    ser.open()
 Antw33 = ser.read(140)

 #SoC
 data = (Antw33.encode('hex') [(74*2):(75*2)])
 #Power
 data2 = (Antw33.encode('hex') [(111*2):(114*2+2)])

END OF PYTHON CODE EXAMPLE
*/

// ARDUINO CODE 
String Q1 = "0XDBDB00000000";

String bms_response;
  
void setup() {
  Serial.begin(115200);

/*
// ANT BMS COMMUNICATION via Bluetooth
//Protocol Asynchronous serial interface
//Baud Rate   9600 baud
//#Start bits 1
//#Data bits  8
//#Stop bits  1
//Parity      None
*/
  
    Serial2.begin(9600);
    Serial2.setTimeout(1000);
      
}


void loop() {
  Serial.println ("Sending command to Ant BMS");
  Serial2.print(Q1);
  Serial.println ("Printing reply from ANT BMS:");
    bms_response = Serial2.readString();
      Serial.println (bms_response);
        delay(2000);
          bms_response = "";
}
  1. When I initialize the serial2 communication do I need to explicitly set those parameters also: Start bits 1, Data bits 8, Stop bits 1,Parity None? Or those are default values anyway ? If yes can you help me with the commands ?

Thank you

Nobody around to help me with this Bluetooth project ?

I the last days I googled a lot to learn what should be my next steps, so I know now I will need to set my bluetooth module to MASTER (only HC-05 can be master, HC-06 won't work)

I connected HC-05 to RX and TX pins of my mega and issued the commands in serial monitor (set to 38400 and Both NL & CR)

AT
// responded : OK
AT+ROLE=1
// responded : OK
AT+ROLE?
// responded : +ROLE:1
AT+INQ
// responded : ERROR:(16)

I also tried to send the AT+INIT or AT+RESET like in this post but after any of those commands the led starts flashing quickly and it does not accept any other commands :frowning:

AT+STATE?
// responded: +STATE:INQUIRING
// OK

My next step is to find my external device (ANT BMS) address, and I was hoping to find it using the AT+INQ command, which results in error 16 ... anyone around to help me with this ?

Hello Sibianul.
My sorry I can't help you here, as I'm about in the same situation as you are.
But I will follow this post, as I'm also looking for a solution to read out my 30 calls ANT BMS over bluetooth via arduino.
I could find already some 'Smart BMS' examples, but these seems different from the Ant BMS.
Thanks to all more advanced users posting some useful info here !

@BartDePauw I don't know if I have problems with my bluetooth module or I'm doing something wrong, but I ordered a new one , I ordered 2 different modules , one HC-05 module, and an HM-11 BLE module .. but it will take some time till it comes from china :slight_smile:

Have you tried to connect the bluettoth module and pair with your ant bms trough arduino ? I'm stuck at error 16 when I send the command AT+INQ .. if I send the command AT+INIT the led of HC-05 starts flashing fast and it does not accept any other commands...

In the mean time, I used an RaspberryPi Zero w (has bluetooth and wifi built-in) I posted the modified code on the other forum where I found a python script made by someone else, but that used grafana and influx database, instead I needed to send the informations from ant bms to my local server trough http requests.

It does work great so far, I only tested a few days, and today or tomorrow I plan to bring the battery from my workshop to my house, it's quite heavy at ~160kg






That may depend on what a BMS is. If it is a plain vanilla SPP Bluetooth device, you might try connecting it to a phone so that you can retrieve the address, and then configure HC-05 to auto connect with it. See the Martyn Currey website

You obviously need to know which commands you can send. Once you do, you send them. - something like:
Serial1.print(command);

You don't need any of that stuff.