Im trying to initialize HM10 BLE module through arduino program using software serial on pins (2,3).
Here is the code that I'm using
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2,3);
char c=' ';
void setup()
{
Serial.begin(9600);
Serial.println("HM10 Central device here");
Serial.println("trial:1 ");
Serial.println(" ");
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
Serial.println(" ");
pinMode(13, OUTPUT);
delay(2000);
Serial.println("Setting up HM10");
// connect to the remote Bluetooth module
BTserial.print("AT+IMME0");
Serial.println("auto connect enabled");
delay(1000);
BTserial.print("AT+ROLE1");
Serial.println("Configured as central device");
delay(1000);
BTserial.print("AT+RENEW");
Serial.println("reset device");
delay(1000);
// BTserial.print("AT+CON6CC374F3C221" );
//delay(1000);
}
void loop()
{
BTserial.print("1");
Serial.println("1");
digitalWrite(13, HIGH);
delay(1000);
BTserial.print("0");
Serial.println("0");
digitalWrite(13, LOW);
delay(1000);
}
After uploading this code to my UNO the HM10 doesn't seem to be configured the way I want it to be.
But before I proceeded with this, I used another code which enabled me to send AT commands to HM10 via Arduino UNo through its serial monitor. the code that I used that time is as follows
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2,3); //(Rx,TX)
char c=' ';
boolean NL = true;
void setup()
{
Serial.begin(9600);
Serial.println("Testing HM10 CONNECTED TO uNO");
Serial.println("Trial:1 ");
Serial.println(" ");
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
}
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();
// do not send line end characters to the HM-10
if (c!=10 & c!=13 )
{
BTserial.write(c);
}
// Echo the user input to the main window.
// If there is a new line print the ">" character.
if (NL) { Serial.print("\r\n>"); NL = false; }
Serial.write(c);
if (c==10) { NL = true; }
}
}
the thing with this code is I have to manually enter the AT commands from serial monitor. What I'm trying to do now is that these AT commands should be sent to HM10 automatically. what am I missing here? My HM10 uses version 607 for firmware. Please help me out asap. Thanks in advance
In principle, sending the AT commands as a one-shot in Setup, is a fair thing to do. The Serial.println commands you have are meaningless doodles by you that have nothing to do with what is actually going on in Bluetooth - only what you think ought to be going on. If you really need to read something on the screen, send an interrogation, like "AT+ROLE?", and see something useful.
I don't know much about HM-10 but be aware that there are variations in the AT commands. I have three that are different, and you need to be sure you are sending the correct commands in the correct manner. The IMME command means nothing to me, but I'm sure it doesn't do what you think it does.
You might find some useful information on the Martyn Currey website.
Nick_Pyner:
In principle, sending the AT commands as a one-shot in Setup, is a fair thing to do. The Serial.println commands you have are meaningless doodles by you that have nothing to with what is actually going on in Bluetooth - only what you think ought to be going on. If you really need to read something on the screen, send an interrogation, like "AT+ROLE?", and see something useful.
I don't know much about HM-10 but be aware that there are variations in the AT commands. I have three that are different, and you need to be sure you are sending the correct commands in the correct manner. The IMME command means nothing to me, but I'm sure it doesn't do what you think it does.
You might find some useful information on the Martyn Currey website.
Thanks for the reply. The reason I included those the serial commands is to ensure that and to know when the commands were sent to HM10 when I see those things getting printed in serial monitor I come to know that my program, execution has reached at this particular point.
The issue is definitely not the with AT commands and I can say this because whenever I send these commands manually from the serial monitor it works completely fine. I already mentioned it in the later part of the my question.
So what is wrong with my Arduino code (the first one) where I send AT commands to BT but nothing happens. But when the same commands are entered through serial monitor using another code (the second code) it works completely fine. Am I able to mention my problem clearly? Thanks in advance
I'm not familiar with configuring HM-10, but it could be that you are required to send linefeeds and/or CR after the AT commands and, while the monitor is sending them by virtue of its correct setting, you are not sending them in the one-shot.
Nick_Pyner:
I'm not familiar with configuring HM-10, but it could be that you are required to send linefeeds and/or CR after the AT commands and, while the monitor is sending them by virtue of its correct setting, you are not sending them in the one-shot.
Nick_Pyner:
I'm not familiar with configuring HM-10, but it could be that you are required to send linefeeds and/or CR after the AT commands and, while the monitor is sending them by virtue of its correct setting, you are not sending them in the one-shot.
After adding \r\n to each of the AT commands I send I tried running up my code, but nothing happens. What should be the other thing I need to check?
for now here's the code how it looks now
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2,3);
char c=' ';
void setup()
{
Serial.begin(9600);
Serial.println("HM10 Central device here");
Serial.println("trial:1 ");
Serial.println(" ");
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
Serial.println(" ");
pinMode(13, OUTPUT);
delay(2000);
Serial.println("Setting up HM10");
// connect to the remote Bluetooth module
BTserial.print("AT+IMME0\r\n");
// Serial.println("auto connect enabled");
delay(1000);
BTserial.print("AT+ROLE1\r\n");
// Serial.println("Configured as central device");
delay(1000);
BTserial.print("AT+RENEW\r\n");
//Serial.println("reset device");
delay(1000);
// BTserial.print("AT+CON6CC374F3C221" );
//delay(1000);
}
void loop()
{
BTserial.print("1");
Serial.println("1");
digitalWrite(13, HIGH);
delay(1000);
BTserial.print("0");
Serial.println("0");
digitalWrite(13, LOW);
delay(1000);
}
Since you successfully used HM-10 before, I assume the wiring is still kosher, but it would pay to check that you can sensibly use it for communications... I again suggest you check Martyn Currey for more specific information on config. It is probably something simple. You are still not interrogating Bluetooth. If you don't do that, you won't get any useful response. Your entire loop is as meaningless as it is irrelevant, and can be safely deleted.
Nick_Pyner:
Since you successfully used HM-10 before, I assume the wiring is still kosher, but it would pay to check that you can sensibly use it for communications... I again suggest you check Martyn Currey for more specific information on config. It is probably something simple. You are still not interrogating Bluetooth. If you don't do that, you won't get any useful response. Your entire loop is as meaningless as it is irrelevant, and can be safely deleted.
That's exactly i'm not able to figure out. why I can't communicate with HM10 this especially when it accepts those commands when I manually enter them through serial monitor.
The loop contains those things which I want to run after my BT gets connected.
Nick_Pyner:
Since you successfully used HM-10 before, I assume the wiring is still kosher, but it would pay to check that you can sensibly use it for communications... I again suggest you check Martyn Currey for more specific information on config. It is probably something simple. You are still not interrogating Bluetooth. If you don't do that, you won't get any useful response. Your entire loop is as meaningless as it is irrelevant, and can be safely deleted.
Is there anything else you would advice me to check? I went through that blog again but couldn't find anything
I'm afraid I am at a loss now. One-shot in setup is the only way I configure Bluetooth, but that is for HC-0x. I have just tried the code below on an HM-10 and it didn't work.
I'm a bit pissed off by this, as I would not have expected it to be difficult. I also tried it with the "=" and "\r\n" deleted, as required in the TinySine datasheet. No joy....
Nick_Pyner:
I'm afraid I am at a loss now. One-shot in setup is the only way I configure Bluetooth, but that is for HC-0x. I have just tried the code below on an HM-10 and it didn't work.
I'm a bit pissed off by this, as I would not have expected it to be difficult. I also tried it with the "=" and "\r\n" deleted, as required in the TinySine datasheet. No joy....
That's exactly my concern was. Anyway I made two changes, first I changed my HM10 and next was copied a couple of commands from a online example (unfortunately, I forgot its address, but I can look into history if u need it for your project) got it working. Idk how and why? honestly deadlines are closing on and I don't have enough time to figure out why it didn't worked earlier and why it is working now. Will check and update it here later on.
Count:
I can look into history if u need it for your project
Thanks - when it is convenient.
I don't actually have a project at the moment but I have published notes on HC-0x and have only just started to use HM-10. I was surprised to find that it is more a less a direct equivalent to HC-0x, and now I want to update the notes to include it.