Go Down

Topic: HM-10 AT command doesn't work  (Read 505 times) previous topic - next topic

Liz0905

May 19, 2018, 07:46 pm Last Edit: May 19, 2018, 10:50 pm by Liz0905
I try to connect HM-10 to arduino micro
RX HM-10 connected to pin 11 and TX HM-10 to pin 10.
serial monitor NL&CR

i use the following code:

Code: [Select]

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(11, 10); //RX|TX


void setup(){
  Serial.begin(9600);
  BTSerial.begin(9600); // default baud rate
  while(!Serial); //if it is an Arduino Micro
  Serial.println("AT commands: ");
}

void loop(){
  //read from the HM-10 and print in the Serial
  if(BTSerial.available())
    Serial.write(BTSerial.read());
   
  //read from the Serial and print to the HM-10
  if(Serial.available())
    BTSerial.write(Serial.read());
}



when i open the serial monitor i see "AT commands: " but when i type AT i don't accept OK.
can you help me please to understand where is my mistake?

thank you very much!

cattledog


Quote
RX HM-10 connected to pin 11 and TX HM-10 to pin 10.
Code: [Select]
SoftwareSerial BTSerial(11, 10); //RX|TX


The constructor for Software Serial lists the pins in the order as you indicate -- Rx then TX. This is from the point of view of the Arudino.

Your connections are not correct.  TX of the HM 10 connects to RX of the Arduino and RX of the HM 10 connects to the TX of the Arduino.

Here's Martyn Curry's tutorial on the HM 10 and AT commands.http://www.martyncurrey.com/hm-10-bluetooth-4ble-modules/#HM-10%20-%20AT%20commands

Liz0905

Code: [Select]
SoftwareSerial BTSerial(11, 10); //RX|TX


The constructor for Software Serial lists the pins in the order as you indicate -- Rx then TX. This is from the point of view of the Arudino.

Your connections are not correct.  TX of the HM 10 connects to RX of the Arduino and RX of the HM 10 connects to the TX of the Arduino.

Here's Martyn Curry's tutorial on the HM 10 and AT commands.http://www.martyncurrey.com/hm-10-bluetooth-4ble-modules/#HM-10%20-%20AT%20commands

thanks,

i try to connect the RX and TX as you said and it still doesn't work, i connect the arduino with USB cable to my PC. All my connections should be fine now but when i try to send AT command i dont accept anything. what else should I try?

thank you!

Liz0905

I also tried to following code:

Code: [Select]

#include <SoftwareSerial.h>

SoftwareSerial ble(2, 3); // RX, TX

void setup() {
  // Open serial port
  Serial.begin(9600);
  // begin bluetooth serial port communication
  ble.begin(9600);
}

// Now for the loop

void loop() {
  Serial.println("Sending Bluetooth Message...");
  ble.write("Testing...");
  delay(500);
 
}


so the Serial.println works and i receive "Sending Bluetooth Message..." when I open the serial monitor but than I get nothing so from these two codes I conclude that I have a problem at the stage of the -SoftwareSerial.
Am I wrong?

thank you!

cattledog

I have a couple of comments.

Quote
so the Serial.println works and i receive "Sending Bluetooth Message..." when I open the serial monitor but than I get nothing so from these two codes I conclude that I have a problem at the stage of the -SoftwareSerial.
Am I wrong?
What are you expecting? You should see "Sending Bluetooth Message" on the monitor, and "Testing" on some paired phone application like a Bluetooth terminal.  What Bluetooth App are you running on the phone? Is the phone paired with the module and the app connected?

If you want to see what is entered from the monitor on the phone and what is entered on the phone in the monitor, you will need a sketch like this,

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3);

void setup()
{
  Serial.begin(9600);
  BTserial.begin(9600);
}

void loop()
{
  if (BTserial.available())
  {
    byte x = BTserial.read();
    Serial.write(x);
  }

  if (Serial.available())
  {
    byte y = Serial.read();
    BTserial.write(y);
  }
}


Your sketch and comments indicate to me thay you may have a misunderstanding of Bluetooth and I would advise you to study the tutorials of Martyn Curry found here http://www.martyncurrey.com/quick-links/#more-2458 and Nick Pyner's tutorial found here http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf

Unless you have some reason to change the default settings of your module,  don't use AT mode until you have everything working and are familiar with Bluetooth.

Liz0905

I have a couple of comments.

What are you expecting? You should see "Sending Bluetooth Message" on the monitor, and "Testing" on some paired phone application like a Bluetooth terminal.  What Bluetooth App are you running on the phone? Is the phone paired with the module and the app connected?

If you want to see what is entered from the monitor on the phone and what is entered on the phone in the monitor, you will need a sketch like this,

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3);

void setup()
{
  Serial.begin(9600);
  BTserial.begin(9600);
}

void loop()
{
  if (BTserial.available())
  {
    byte x = BTserial.read();
    Serial.write(x);
  }

  if (Serial.available())
  {
    byte y = Serial.read();
    BTserial.write(y);
  }
}


Your sketch and comments indicate to me thay you may have a misunderstanding of Bluetooth and I would advise you to study the tutorials of Martyn Curry found here http://www.martyncurrey.com/quick-links/#more-2458 and Nick Pyner's tutorial found here http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf

Unless you have some reason to change the default settings of your module,  don't use AT mode until you have everything working and are familiar with Bluetooth.
thank you for your answer!


I read the tutorials and probably still have gaps in knowledge. I'm using the LightBlue app with my iPhone. What I'm trying to do is get the readings of my temperature sensor on my iphone screen, i.e., see the serial monitor on my iPhone's screen but before that I wanted to try the basic example to see that I can figure out how it all works.

thank you!

cattledog

#6
May 20, 2018, 07:20 pm Last Edit: May 20, 2018, 07:22 pm by cattledog
Quote
I'm using the LightBlue app with my iPhone. What I'm trying to do is get the readings of my temperature sensor on my iphone screen, i.e., see the serial monitor on my iPhone's screen but before that I wanted to try the basic example to see that I can figure out how it all works.
The HM 10 and the iphone are outside of my familiarity with the the HC 05 and android, but that said, here's a possible path for you to take which will simplify things. There is often no need to use the monitor and the phone at the same time. Usually, the phone is to replace the monitor for serial send and receive and display from the Arduino.

Write your Arduino program with input and output to the Serial monitor. No Bluetooth involved. Your starting point should be an arduino program which does what you want with the Serial monitor.

After that program is uploaded, you can connect the bluetooth monitor to the hardware serial pins of the Arduino.  Remember to connect RX to TX and TX to RX. Serial monitor should be closed.

Then, the connected phone app should replace the Serial monitor for input to the arduino and display of the output data. Be sure that the baud rates and character string line ending like CR and NL are the same with the phone app and the serial monitor.


Liz0905

The HM 10 and the iphone are outside of my familiarity with the the HC 05 and android, but that said, here's a possible path for you to take which will simplify things. There is often no need to use the monitor and the phone at the same time. Usually, the phone is to replace the monitor for serial send and receive and display from the Arduino.

Write your Arduino program with input and output to the Serial monitor. No Bluetooth involved. Your starting point should be an arduino program which does what you want with the Serial monitor.

After that program is uploaded, you can connect the bluetooth monitor to the hardware serial pins of the Arduino.  Remember to connect RX to TX and TX to RX. Serial monitor should be closed.

Then, the connected phone app should replace the Serial monitor for input to the arduino and display of the output data. Be sure that the baud rates and character string line ending like CR and NL are the same with the phone app and the serial monitor.


Thank you!

I tried to do exactly as you said, use following code:

Code: [Select]

int val1, val2;
int tempPin1 = A0;
int tempPin2 = A1;


void setup()
{
Serial.begin(9600);
}
void loop()
{
val1 = analogRead(tempPin1);
float C1 = ( val1/1024.0)*500;


Serial.print("TEMPRATURE C1 = ");
Serial.print(C1);
Serial.print("*C");
Serial.println();
delay(1000);

val2 = analogRead(tempPin2);
float C2 = ( val1/1024.0)*500;


Serial.print("TEMPRATURE C2 = ");
Serial.print(C2);
Serial.print("*C");
Serial.println();
delay(1000);

}


serial monitor closed, HM-10 TX connected to arduino RX and HM-10 RX connected to arduino TX.
my app connected to HM-10 and still didn't receive anything from arduino on my iphone!
where is my mistake?!

thank you very much

ieee488

Why did you switch to this new sketch? Using this sketch leaves you blind.

Did you ever get the cattledog's sketch working?


cattledog

Quote
serial monitor closed, HM-10 TX connected to arduino RX and HM-10 RX connected to arduino TX.
my app connected to HM-10 and still didn't receive anything from arduino on my iphone!
where is my mistake?!
Your code works correctly with with one small error, but this is unrelated to your issue.

Code: [Select]
val2 = analogRead(tempPin2);
//float C2 = ( val1/1024.0)*500;
float C2 = ( val2/1024.0)*500;


There is something I don't understand about your environment with the HM 10 and the iphone app.

When I run this sketch with an HC05 connected to the Arduino (BT_TX to D0 and BT_RX to D1)  and an Android terminal application every is working properly. The BT module is indeed sending to the phone, I see the two temperature readings on the phone screen,  and if I leave the serial monitor window open the data is showing there as well.

You say the phone found and paired with the module and the app connected.

Are you certain that the iphone app is set for 9600 Baud?
Do the line endings match between the phone app and the serial monitor
What iphone do you have?

You might want to consider a simple Bluetooth Serial Terminal app like this one to test if the problem is with LightBlue app.

https://itunes.apple.com/us/app/hm10-bluetooth-serial-lite/id1030454675?mt=8



cattledog

I've done a bit more reading on the HM 10, and I'm still not certain if your module is working properly, because you have never seen the AT > OK.

The wiring in your first posting was backwards, and the code was not quite correct. Try this AT sketch which comes from this tutorial https://arduino-info.wikispaces.com/HM-10%20Bluetooth%20LE

It is the nearly same as your first sketch, but adds a Serial.write to the last section to echo the Bluetooth back to the serial monitor.  There are two important things to note. First, the module should not be connected to the phone. I think that means there is a blinking light. The AT mode will not work when connected. That is why you need the echo back to the monitor as there can be no phone involved.

Second, there appear to be several versions of HM10 firmware, and some modules want a NL and CR, and others do not want that.
So, when you send AT from the monitor looking for the OK response, try it with no line ending and with the NL and CR.

Code: [Select]

#include <SoftwareSerial.h>
SoftwareSerial BTserial(3, 4); //Create software serial instance, pins of your choice

char c = ' ';


// Initialization
void setup()
{
  Serial.begin(9600);
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println(" ");

  BTserial.begin(9600);
  Serial.println("BTserial started at 9600");
}

// Arduino Execution Loop
void loop()
{
  // Read from the Bluetooth module and send to the Arduino Serial Monitor
  if (BTserial.available())
  {
    c = BTserial.read();
    Serial.write(c);
  }

  // Read from the Serial Monitor and send to the Bluetooth module
  if (Serial.available())
  {
    c = Serial.read();
    BTserial.write(c);
    Serial.write(c);
  }
}

Liz0905

I've done a bit more reading on the HM 10, and I'm still not certain if your module is working properly, because you have never seen the AT > OK.

The wiring in your first posting was backwards, and the code was not quite correct. Try this AT sketch which comes from this tutorial https://arduino-info.wikispaces.com/HM-10%20Bluetooth%20LE

It is the nearly same as your first sketch, but adds a Serial.write to the last section to echo the Bluetooth back to the serial monitor.  There are two important things to note. First, the module should not be connected to the phone. I think that means there is a blinking light. The AT mode will not work when connected. That is why you need the echo back to the monitor as there can be no phone involved.

Second, there appear to be several versions of HM10 firmware, and some modules want a NL and CR, and others do not want that.
So, when you send AT from the monitor looking for the OK response, try it with no line ending and with the NL and CR.

Code: [Select]

#include <SoftwareSerial.h>
SoftwareSerial BTserial(3, 4); //Create software serial instance, pins of your choice

char c = ' ';


// Initialization
void setup()
{
  Serial.begin(9600);
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println(" ");

  BTserial.begin(9600);
  Serial.println("BTserial started at 9600");
}

// Arduino Execution Loop
void loop()
{
  // Read from the Bluetooth module and send to the Arduino Serial Monitor
  if (BTserial.available())
  {
    c = BTserial.read();
    Serial.write(c);
  }

  // Read from the Serial Monitor and send to the Bluetooth module
  if (Serial.available())
  {
    c = Serial.read();
    BTserial.write(c);
    Serial.write(c);
  }
}


Thank you so much for trying to help me but it still doesn't works, I'm already frustrated!
I have tried all your advice and it's still no response.
first i have tried it with closed serial monitor and pare my app and than i have tried to receive OK with AT command.

i also tried the following code:

Code: [Select]

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
Serial1.begin(57600);
while (!Serial) {
Serial.println("Waiting"); // wait for serial port to connect. Needed for Leonardo only
}

Serial.println("Goodnight moon!");
Serial.println("1");
Serial1.println("Hello, world?");
Serial.println("2");
}

void loop() {
if (Serial1.available())
    Serial.write(Serial1.read());
if (Serial.available())
    Serial1.write(Serial.read());
}


when i open the serial monitor (57600, NL&CR) i receive :
"waiting
goodnight moon
1
2"

but in my app i see nothing!
tried the "LightBlue" app and also the "serial lite" (using iphone 7)
my HM-RX connected to arduino TX and HM-TX to arduino RX, also tried to connect the HM RX,TX to pins 10,11 respectively according to the guidelines in the example of serialsoftware.

so the problem is probably with my connection of HM to arduino?

thank you! 
 

cattledog

Quote
Thank you so much for trying to help me but it still doesn't works, I'm already frustrated!
I have tried all your advice and it's still no response.
I understand how frustrating this can be, and much of my advice is not helping.
I reread the thread, and realize that you are using a Micro, and my advice about using the hardware Serial connections on D0 and D1 are wrong for the micro, and those pins are accessed through Serial1.

Indeed you seem to have used Serial1 in the last code which also did not show on the phone. I would try that with Serial1 at 9600. I also don't know about how to handle the possible line endings issues with Serial1. There appear to be several versions of the HM10 which handle the line endings differently.

You should also consistently use the while(!Serial); expression in your code.

Software Serial on the micro is only on limited pins, but you have been correct when you used 10 and 11. Some of my software serial postings incorrectly used other pins.

I think with the Micro, you are probably best off using Serial1 and D0 and D1 for the HM 10. I do see that the physical position of the pins on the board is reversed from the numerical order, so be sure of which is which.

Quote
so the problem is probably with my connection of HM to arduino?
I am not sure about that.

Since I do not have a micro, an HM 10, or an iphone, I can not test any of what you are doing, and I am unsure of whether or not you have a defective module, incorrect code for the particular version of HM 10, incorrect code for the micro, or incorrect wiring.

I would certainly try this code with Serial1, replacing software serial, no phone connection, and see if the AT > OK shows on the serial monitor.
Code: [Select]


char c = ' ';

void setup()
{
  Serial.begin(9600);
  While(!Serial);
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println(" ");
  //HM 10 TX to microRX(D0)
 // HM 10 RX to microTX(D1)
  Serial1.begin(9600);
  Serial.println("BTserial started at 9600");
}

// Arduino Execution Loop
void loop()
{
  // Read from the Bluetooth module and send to the Arduino Serial Monitor
  if (Serial1.available())
  {
    c = Serial1.read();
    Serial.write(c);
  }

  // Read from the Serial Monitor and send to the Bluetooth module
  if (Serial.available())
  {
    c = Serial.read();
    Serial1.write(c);
    Serial.write(c);
  }
}





cattledog

Can you provide a link to the HM 10 module that you have. A photograph? Many modules sold as HM 10 are copies/clones.

Consequently, there are several different modules sold as "HM 10" which have different firmware and requirements for the line endings for AT commands. I'm hoping that the lack of AT > OK is a line ending issue.

Issues around the AT communications may or may not be related to the lack of communication with the phone when connected.


Go Up