===================================================================
Configure the HM-10 Bluetooth 4.0 Module using an Arduino DUE board
===================================================================
I own a DSD Tech HM-10 Bluetooth module for over one year now and wanted to configure it. Therfore I tried the ble.h and ble.cpp from Sunray. But this code didn't work for me.
It looks like there a differnet modules from china available. The original comes from www.jnhuamao.cn as far a I know.
In the following I have described, how I configured my module with the Arduino DUE. I didn't need it for Sunray. Therfore I configured it how I could need this for Raindancer.
Furthermore, Android is not able to connect the HM-10 through the Android Bluetooth settings. You need an App like Serial Bluetooth terminal. In this app you can connect to the
HM-10. If you connect the first time, you will be asked for a password (if the module is configured in that way). If you put in the password, the app will not connect. To connect, you
have to press the connect button after inserting the password.
Note: Most of this text is quoted from:
Step by step instructions:
a) Open Arduino IDE.
Plug your Adruino Uno board into your PC and select the correct board and com port.
Power off the bluetooth module before verifying and uploading the sketch.
Verify and upload the sketch to your Adruino DUE board.
b) Do wiring:
HM10 GND -> DUE GND
HM10 VCC -> DUE 3.3V
HM10 RXD -> DUE TX3/14
HM10 TXD -> DUE RX3/15
C) Open up serial monitor and set your baud to 115200 baud.
Do no connect your mobile phone to the BLE module. The AT commands will then not work.
Note that the AT commands do not require Line Feed or Carriage Return codes (LF, CR).
If you use the Arduino IDE console to send them , make sure that you select "No line ending".
This is from vendor to vendor different. Some Vendors and firmware versions of the HM10 can handle or need NL&CR.
If you will use the sketch to transfer data to the mobile phone select "Both NL&CR"
d) First you need to check if AT commands are working - enter “AT” and press the Send button.
This would print "OK" which signifies of working connection and operation of the module.
If you don't see an answer, select NL&CR in the Arduino IDE console and try again.
If this also not work try: Serial3.begin(115200); in the sketch. (try with and without NL&CR set)
e) Check the firmware version - enter “AT+VERR?” or "AT+VERS?" and press button Send.
Returns the current version of the firmware: “HMSoft V540” for example.
f) Enter “AT+NAME?” and press button Send.
Returns "OK+NAME:HMSoft" (or something similar depending what your module is called). The default depends on the vendor.
g) Enter “AT+ADDR?” and press button Send. You will get local bluetooth MAC address. Returns the address as a 12 digit
hexidecimal number. For example: "OK+ADDR:E0E5CF56D857".
h) Now configure the board: (check the datasheet of your module if the commads are the same!)
========================
AT+RENEW
AT+RESET
AT+NAMEArdumowerBLE
AT+NAME?
AT+BAUD4 //IMPORTANT: Go to the datasheet of the module. Some China clones have 115200 on the number n=8.
AT+BAUD?
AT+RESET
Now you have to change the Arduino sketch line from Serial3.begin(9600); to Serial3.begin(115200);
And upload it to the DUE again.
AT // Check if new configuration is working
AT+PASS123456
AT+PASS? // Query current Pincode.
AT+TYPE3
AT+TYPE? // Query authentication mode
AT+RESET
##########################################
### The configuration is now finished ####
##########################################
i) Description of the configuration statements:
===============================
1) Enter “AT+RENEW” and press button Send. Returns "OK+RENEW". Restores the default factory settings.
A quick and easy way to reset all settings.
2) Enter “AT+RESET” and press button Send. Restarts the module.Will close an active
connection while restarting. Returns "OK+RESET".
3) To change the name enter “AT+NAMEnewname” and press Send button.
Returns “OK+Set:newname” (or something similar depending what your module is called).
The default depends on the vendor.
4) You can get or set baud rate.Enter “AT+BAUD?” and press button Send. Returns: "OK+Get:0".
To change baud rate use "AT+BAUDn"
Where n is:
0 – 9600:
1 – 19200
2 – 38400
3 – 57600
4 – 115200
5 – 4800
6 – 2400
7 – 1200
8 – 230400
IMPORTANT: Go to the datasheet of the module. Some China clones have 115200 on the number n=8.
The default setting is 0 – 9600. Remember that both devices, the Arduino and the HM-10 need to use the same
baud rate. Garbage characters are usually a sign of mismatched baud rates.
Reset the module with "AT+RESET" when done. The maximum baud rate the Arduino DUE s allows is 115200.
If you set the baud rate to 230400 with AT+BAUD8 you won't be able to talk to the module.
5) You can get or set pin code for pairing. Enter “AT+PASS?” or “AT+PIN?” (depending on the vendor)
and press button Send. Returns your PIN: "OK+Get:000000".
To change PIN enter "AT+PASS123456" or “AT+PIN123456” (depending on the vendor) and press button Send.
Answer: OK+Set:123456 PIN changed to 123456 now, reset the module with "AT+RESET".
6) To use the Pin, you have to select a Module Bond Mode.
IMPORTANT: If your module version is less than V515, please don’t use this command.
Under android 4.3 AT+TYPE1 is same to AT+TYPE2.
Note: Value 3 is added in V524.
"AT+TYPE?" selects the current bond mode.
"AT+TYPEn" sets the bond mode:
Where n is:
0:Not need PIN Code
1:Auth not need PIN
2:Auth with PIN
3:Auth and bond
========================================
Further information which we don't need:
========================================
7) Enter “AT+HELP?” and press button Send. Returns the web address of manufacturer: www.jnhuamao.cn
8) Enter “AT+ROLE?” and press button Send. Query the current Role: Master or Slave.
Returns 0 or 1 - “OK+Get:0”. 0 = Slave or Peripheral, 1 = Master or Central.
The default setting is 0 (Slave). To change to Central Mode, enter “AT+ROLE1” and press button Send.
Will return “OK+Set:1” , reset the module with "AT+RESET".
9) Enter “AT+NOTI?” and press button Send. Query the notification status. Returns 0 or 1: “OK+Get:0”.
0 – notifications are off, 1 – notifications are on.
To set the notification status, enter “AT+NOTI1” and press button Send.
Will return “OK+Set:1” , reset the module with "AT+RESET".
If notifications are turned on, the HM-10 will reply to commands with a confirmation message
or send out a message when certain events take place, like “OK” for the AT command
and “OK+LOST” when a connection is broken.
10) Enter “AT+IMME?” and press button Send. Query the start mode. Returns 0 or 1: “OK+Get:0”.
0 = Connect immediately (assuming a previous connection has been applied),
1 = Wait for a connection command before connecting (AT+START, AT+CONN, AT+CONL.
The default setting is 0 (connect on start).To set the start up mode, enter “AT+IMME1” and press button Send.
Will return “OK+Set:1” , reset the module with "AT+RESET".
If there are no previous connections, HM-10s will auto-connect to any other
HM-10 available (normally the one with the strongest signal). The HM-10 (by default)
remembers the address of the last module it was connected to and if there is stored a
previous connection this will take priority when the HM-10 is retrying to auto-connect.
Configure the HM-10 Bluetooth 4.0 Module using an Arduino DUE board
===================================================================
I own a DSD Tech HM-10 Bluetooth module for over one year now and wanted to configure it. Therfore I tried the ble.h and ble.cpp from Sunray. But this code didn't work for me.
It looks like there a differnet modules from china available. The original comes from www.jnhuamao.cn as far a I know.
In the following I have described, how I configured my module with the Arduino DUE. I didn't need it for Sunray. Therfore I configured it how I could need this for Raindancer.
Furthermore, Android is not able to connect the HM-10 through the Android Bluetooth settings. You need an App like Serial Bluetooth terminal. In this app you can connect to the
HM-10. If you connect the first time, you will be asked for a password (if the module is configured in that way). If you put in the password, the app will not connect. To connect, you
have to press the connect button after inserting the password.
Note: Most of this text is quoted from:
Step by step instructions:
a) Open Arduino IDE.
Plug your Adruino Uno board into your PC and select the correct board and com port.
Power off the bluetooth module before verifying and uploading the sketch.
Verify and upload the sketch to your Adruino DUE board.
Code:
#include <Arduino.h>
void setup()
{
Serial.begin(115200); //115200 to console
delay(500);
Serial3.begin(9600); //9600 to HM10
delay(500);
}
void loop(){
char recvChar;
if (Serial3.available()) {
recvChar = Serial3.read();
Serial.print(recvChar);
}
if (Serial.available()) {
recvChar = Serial.read();
Serial3.write(recvChar);
}
}
b) Do wiring:
HM10 GND -> DUE GND
HM10 VCC -> DUE 3.3V
HM10 RXD -> DUE TX3/14
HM10 TXD -> DUE RX3/15
C) Open up serial monitor and set your baud to 115200 baud.
Do no connect your mobile phone to the BLE module. The AT commands will then not work.
Note that the AT commands do not require Line Feed or Carriage Return codes (LF, CR).
If you use the Arduino IDE console to send them , make sure that you select "No line ending".
This is from vendor to vendor different. Some Vendors and firmware versions of the HM10 can handle or need NL&CR.
If you will use the sketch to transfer data to the mobile phone select "Both NL&CR"
d) First you need to check if AT commands are working - enter “AT” and press the Send button.
This would print "OK" which signifies of working connection and operation of the module.
If you don't see an answer, select NL&CR in the Arduino IDE console and try again.
If this also not work try: Serial3.begin(115200); in the sketch. (try with and without NL&CR set)
e) Check the firmware version - enter “AT+VERR?” or "AT+VERS?" and press button Send.
Returns the current version of the firmware: “HMSoft V540” for example.
f) Enter “AT+NAME?” and press button Send.
Returns "OK+NAME:HMSoft" (or something similar depending what your module is called). The default depends on the vendor.
g) Enter “AT+ADDR?” and press button Send. You will get local bluetooth MAC address. Returns the address as a 12 digit
hexidecimal number. For example: "OK+ADDR:E0E5CF56D857".
h) Now configure the board: (check the datasheet of your module if the commads are the same!)
========================
AT+RENEW
AT+RESET
AT+NAMEArdumowerBLE
AT+NAME?
AT+BAUD4 //IMPORTANT: Go to the datasheet of the module. Some China clones have 115200 on the number n=8.
AT+BAUD?
AT+RESET
Now you have to change the Arduino sketch line from Serial3.begin(9600); to Serial3.begin(115200);
And upload it to the DUE again.
AT // Check if new configuration is working
AT+PASS123456
AT+PASS? // Query current Pincode.
AT+TYPE3
AT+TYPE? // Query authentication mode
AT+RESET
##########################################
### The configuration is now finished ####
##########################################
i) Description of the configuration statements:
===============================
1) Enter “AT+RENEW” and press button Send. Returns "OK+RENEW". Restores the default factory settings.
A quick and easy way to reset all settings.
2) Enter “AT+RESET” and press button Send. Restarts the module.Will close an active
connection while restarting. Returns "OK+RESET".
3) To change the name enter “AT+NAMEnewname” and press Send button.
Returns “OK+Set:newname” (or something similar depending what your module is called).
The default depends on the vendor.
4) You can get or set baud rate.Enter “AT+BAUD?” and press button Send. Returns: "OK+Get:0".
To change baud rate use "AT+BAUDn"
Where n is:
0 – 9600:
1 – 19200
2 – 38400
3 – 57600
4 – 115200
5 – 4800
6 – 2400
7 – 1200
8 – 230400
IMPORTANT: Go to the datasheet of the module. Some China clones have 115200 on the number n=8.
The default setting is 0 – 9600. Remember that both devices, the Arduino and the HM-10 need to use the same
baud rate. Garbage characters are usually a sign of mismatched baud rates.
Reset the module with "AT+RESET" when done. The maximum baud rate the Arduino DUE s allows is 115200.
If you set the baud rate to 230400 with AT+BAUD8 you won't be able to talk to the module.
5) You can get or set pin code for pairing. Enter “AT+PASS?” or “AT+PIN?” (depending on the vendor)
and press button Send. Returns your PIN: "OK+Get:000000".
To change PIN enter "AT+PASS123456" or “AT+PIN123456” (depending on the vendor) and press button Send.
Answer: OK+Set:123456 PIN changed to 123456 now, reset the module with "AT+RESET".
6) To use the Pin, you have to select a Module Bond Mode.
IMPORTANT: If your module version is less than V515, please don’t use this command.
Under android 4.3 AT+TYPE1 is same to AT+TYPE2.
Note: Value 3 is added in V524.
"AT+TYPE?" selects the current bond mode.
"AT+TYPEn" sets the bond mode:
Where n is:
0:Not need PIN Code
1:Auth not need PIN
2:Auth with PIN
3:Auth and bond
========================================
Further information which we don't need:
========================================
7) Enter “AT+HELP?” and press button Send. Returns the web address of manufacturer: www.jnhuamao.cn
8) Enter “AT+ROLE?” and press button Send. Query the current Role: Master or Slave.
Returns 0 or 1 - “OK+Get:0”. 0 = Slave or Peripheral, 1 = Master or Central.
The default setting is 0 (Slave). To change to Central Mode, enter “AT+ROLE1” and press button Send.
Will return “OK+Set:1” , reset the module with "AT+RESET".
9) Enter “AT+NOTI?” and press button Send. Query the notification status. Returns 0 or 1: “OK+Get:0”.
0 – notifications are off, 1 – notifications are on.
To set the notification status, enter “AT+NOTI1” and press button Send.
Will return “OK+Set:1” , reset the module with "AT+RESET".
If notifications are turned on, the HM-10 will reply to commands with a confirmation message
or send out a message when certain events take place, like “OK” for the AT command
and “OK+LOST” when a connection is broken.
10) Enter “AT+IMME?” and press button Send. Query the start mode. Returns 0 or 1: “OK+Get:0”.
0 = Connect immediately (assuming a previous connection has been applied),
1 = Wait for a connection command before connecting (AT+START, AT+CONN, AT+CONL.
The default setting is 0 (connect on start).To set the start up mode, enter “AT+IMME1” and press button Send.
Will return “OK+Set:1” , reset the module with "AT+RESET".
If there are no previous connections, HM-10s will auto-connect to any other
HM-10 available (normally the one with the strongest signal). The HM-10 (by default)
remembers the address of the last module it was connected to and if there is stored a
previous connection this will take priority when the HM-10 is retrying to auto-connect.
Zuletzt bearbeitet: