HM10 bluetooth module serial comms are not working or weird.

The problem: my Bluetooth modules are not being consistent, and one never works with software serial and it’s driving me nuts.

Right, so I have two Arduinos with one hm-10 Bluetooth module attached to each. It should be noted that they appear to be the Chinese knock-off cc41a.

One Arduino is a 3.3v pro mini and is wired to it’s HM-10 using 4 wires (HM-10 to Arduino):
Tx to pin 4
Rx to pin 3
Vcc to vcc
GND to GND

And when it runs this sketch:

#include <SoftwareSerial.h>

int bluetoothTx = 4;  // TX-O pin of bluetooth
int bluetoothRx = 3;  // RX-I pin of bluetooth

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  Serial.begin(9600);  // Begin the serial monitor at 9600bps


  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
  Serial.print("init");
  bluetooth.print("AT+RENEW");
}

void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    Serial.print((char)bluetooth.read());  
  }
  if(Serial.available())  // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the bluetooth
    bluetooth.print((char)Serial.read());
  }
  // and loop forever and ever!
}

When I open up the serial monitor, the word "init’ appears as expected. And when I type "AT’ and send with NO LINE ENDING selected, it get the repose “OK” appear in the serial monitor as expected. However the response “AT+RENEWOK” (in repsonse to "AT+RENEW) only appears sometimes when the arduino is reset. And I cannot work out a correlation with anything.

However…

I have a Moteino Mega (1284p 3.3v arduino) connected to the other HM-10.

When I run this sketch on it

/*
  Multple Serial test

 Receives from the main serial port, sends to the others.
 Receives from serial port 1, sends to the main serial (Serial 0).

 This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc

 The circuit:
 * Any serial device attached to Serial port 1
 * Serial monitor open on Serial port 0:

 created 30 Dec. 2008
 modified 20 May 2012
 by Tom Igoe & Jed Roach
 modified 27 Nov 2015
 by Arturo Guadalupi

 This example code is in the public domain.

 */


void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte);
  }
}

I am able to get the “OK” response on the serial monitor as expected but only when "BOTH NL AND CR " is selected. Sometimes it needs AT to be in uppercase, sometimes in lower case, and sometimes it doesn’t care. This also appears to be random. And the line end requirements are already different to the other module.

I do realise that the second module is using hardware serial and not software serial, but that is because any sketch I use that communicates with the module over software serial, NEVER works. I can type “AT” in as many different combinations of case and line ending, and I never recieve back “ok”

This is the sketch that never works:

#include <SoftwareSerial.h>

int bluetoothTx = 13;  // TX-O pin of bluetooth
int bluetoothRx = 14;  // RX-I pin of bluetooth

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  Serial.begin(9600);  // Begin the serial monitor at 9600bps


  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
  Serial.println("init");
  bluetooth.print("AT+RENEW");
}

void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    Serial.print((char)bluetooth.read());  
  }
  if(Serial.available())  // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the bluetooth
    bluetooth.print((char)Serial.read());
  }
  // and loop forever and ever!
}

it does show “init” on the serial monitor as expected.

And I when switching between hardware serial and software serial programs, I of course change the pins that the HM-10’s are connected too.

If anyone can help shed some light on this, it will help bring an end to the days of systematic testing I am doing and still getting nowhere. :confused:

Cheers

Hi

Im trying to interface an hm10(arduino) and an hm12(relay board).

Ive been able to send commands to the hm12 from my mac.

Im trying to interface from the hm10 now, from an arduino. So far I get no response with this sketch loaded on the arduino(hm10). Im wondering about pairing, I dont need to pair to get an AT command response, do I?

My post is here: http://forum.arduino.cc/index.php?topic=419574.msg2889358#msg2889358

You do need to pair to send at commands via the serial link.

Can anyone help me and now it seems Marciokoko? Marcio, have you tried my sketch that worked on my mini pro but not my Moteino?

I tried your sketch and I get:

initOK+RENEWOKOK+Set:1

because I entered AT afterwards in the terminal and then I entered AT+ROLE1

But now no matter what I enter I get no response. I enter AT and I get nothing, I entered AT+DISC? and nothing.

I’m confused, you’ve said that you typed AT in the terminal and got OK, and then typed AT+ROLE1 and got Ok+set1 as a response, but then in the next line you say you get no reponse…

Exactly! Here is my setup...

There is nothing there

Sorry

I didnt notice it got rejected…here it is

hm10nano.jpg

The hm12 is inside a relay board casing and I know it works fine because Ive been able to send it commands (and it responds correctly) from my macbook after pairing with it.

So it seems Im missing pairing the hm10 with the hm12.

Im going to stop posting here because I dont want to get in trouble for double posting. If I find out anything Ill get back with what worked for me.

Thanks
http://forum.arduino.cc/index.php?topic=419574.msg2889358#msg2889358

Once again, you do not need to pair to send AT commands over the serial UART serial link.

Anyway,

I have now discovered that I have two different HM-10's. One is a true CC41a and the other is the hardware of a CC41a but with the hmsoft v526 software fromwww.jnhuamao.cn

Which explains the upper and lowercase and line ending shenanigans.....

Which leaves me now with an almost 100% confirmed problem that my 1284p based Moteino Mega will not work with software serial. I've been trying different options for hours but nothing works. Hardware serial connection to HM-10 works fine, SW serial doesn't. Can anyone help?

Ok so then by putting a

bluetooth.print("AT");

in the setup function, the nano is sending the hm10 (connected to the nano), the AT command and so the hm10 responds with OK. I see that works.

How would I code for the hm10 to look-for & discover the hm12? It should be:

AT+DISC?

but it doesnt work. When I send the hm10 (via the Arduino IDE Serial Monitor) the AT+DISC? command I get nothing back in the terminal. As a matter of fact, I can send the hm10 many AT commands and Ill get OK back that many times...but when I send it AT+DISC? it not only doesnt respond, but it doesnt answer to any more commands after that.

Ok it seems the hm10 has successfully connected to the hm12 on the relay board because it returns it as a last address. I even managed to send the AT+COmacaddress to the hm12 and the blinking blue led on hm10 goes steady which i believe means its connected. The reason why I wasnt getting any response from any AT commands (except AT) was that the module was connected.

Now it seems the hm12 module has a ble address and an edr address. Its funny because if I enter the AT+COmac it connects (hm10 steady blue) and because the relay clicks. For some reason the connection sends a command to the relay to open relay 1, i hear the click.

Just wanted to inform of my advance...i just realized bluetooth.print() sends commands from arduino to hm10, not to other arduino...how can i send a command to other bt module?