Configure the HM-10 Bluetooth 4.0 Module using an Arduino DUE board

roland

Active member
===================================================================
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:
Hi,

I get this error with this code:

error: expected declaration before '}' token
}
^
exit status 1
expected initializer before 'char'
 
I tried add a capacitator on Wifi-card but it still really not responsive and really hard to manual steer the robot. Any suggestions??
 
Ok thx, code works now but when upload I got buzzer to constant piiip and AT Command does not work.

Reupload Sunray:

Ardumower Sunray,1.0.73
enableCharging 0
trying to detect Bluetooth 4.0/BLE module (make sure your phone is NOT connected)9600...
AT
trying to detect Bluetooth 4.0/BLE module (make sure your phone is NOT connected)115200...
AT
SERIAL_BUFFER_SIZE=128 (increase if you experience GPS checksum errors)
-----------------------------------------------------
NOTE: if you experience GPS checksum errors, try to increase UART FIFO size:
1. Arduino IDE->File->Preferences->Click on 'preferences.txt' at the bottom
2. Locate file 'packages/arduino/hardware/sam/xxxxx/cores/arduino/RingBuffer.h
change: #define SERIAL_BUFFER_SIZE 128 into into: #define SERIAL_BUFFER_SIZE 1024
-----------------------------------------------------
[WiFiEsp] Initializing ESP module
[WiFiEsp] Initilization successful - 1.5.4
WiFi found!
Attempting to connect to WPA SSID: DIG
[WiFiEsp] Connected to DIG
[WiFiEsp] IP address set 192.168.1.56
You're connected with SSID=DIG and IP=192.168.1.56
[WiFiEsp] Server started on port 80
MPU ID=0x0
MPU6050/9150/9250/9255 not found - Did you connect AD0 to 3.3v and choose it in config.h?
temp=998.0 humidity=998
ctlDur=5.00 op=0 freem=44975 volt=23.56 chg=0.10 tg=0.00,0.00 x=0.00 y=0.00 delta=0.00 tow=406143000 lon=18.32948874 lat=59.47160153 n=0.00 e=0.00 d=0.00 sol=0 age=15.17
ublox chka error, msgclass=1, msgid=3C, msglen=40: F4!=5A
 
In Sunray I have BLE on serial 2, do I need to change to serial 2 in your code to get it to work you think?? (if I flash this code to the DUE R3 that is connected in PCB 1.3)
 
Normally you should connect the BLE directly to the DUE with a wire without the Ardumower PCB. The reason for this is to exclude other problems.
If you connect directly, you have not to change the serial port.
If you use the Ardumower PCB and put on the DUE and the BLE module there, then you have to change the port.
 
I tried now to connect DUE R3 with the BLE card at

HM10 GND -> DUE GND
HM10 VCC -> DUE 3.3V
HM10 RXD -> DUE TX3/14
HM10 TXD -> DUE RX3/15

But AT command does not work after uploading the code. I tried Native and programming port
 
maybe try Serial3.begin(115200); did you try all the alteratives in d) ? And disconnect your mobilephone from the BLE.
 
Yes I think im doing correct and I tried all this. You sure about TX3 and RX3 (its used for GPS in Sunray )
 
Not necessary with sunray, simply put at the correct position in the PCB, use the Evo app and select the adapter with conect.
Wifi and BL not work in the same time!
 
PCB Evo app
Not necessary with sunray, simply put at the correct position in the PCB, use the Evo app and select the adapter with conect.
Wifi and BL not work in the same time!
ok using iPhone but maby the same. I connect with Wi-Fi but have little problem with it get disconnected. It work better with AP true. Do you use WiFi and what setup?
 
i use a androit phone.
i use the gps rtk the big one.
No Wifi in my mower only Bluetooth. HM-10
Ok, I was now connected in PCB again. I have also the biggest "Ardumower Komplett Set GPS/RTK Robot Mower System" Wireless Bluetooth Modul HM-10 BT 4.0 (für Android iOS). I find the BLE as HC-05 in settings and with BLE Scanner app but can not find the BLE card in Evo App! ? Only other BLE devices.
 
I was did testdrive with Wi-Fi and now this works pretty good with Android phone.
The problem is that I can not find HC-05 or the MAC number of the BLE in the Evo APP. I have searched all the list. And I disconneted in phone before.

also I have problem that the battery in the mower does not charge. I have to charge manually with 29 V output adapter + and - directly to battery + -. Any known Sunray issue?

With wifi I can manually steer the mower and I was set up small perimeter area but nothing happens when I press START IN Evo App. Do you know what I missed to do?

I think I'm going to succeed with mountain mower. It was promising after first test.

Here is long video if someone is interested.

 
The HC-05 is not a BLE module. It is a normal bluetooth module. The configuration is different compared to HM-10 BLE.

"also I have problem that the battery in the mower does not charge. "
For charging the battery, the realy has to enabled. That is done by software. I don't know, if you can do that manually in Sunray.
 
With wifi I can manually steer the mower and I was set up small perimeter area but nothing happens when I press START IN Evo App. Do you know what I missed to do?

did you transfer the card to the mower after you calculated it in the app? Every time you switch off the mower, the card has to be transferred again, it is not saved permanently.

I would not drive through the tall grass that fast either, it only unnecessarily damages the mechanics. You can also take a look at the following thread:

https://forum.ardumower.de/threads/4-zahnmesser-statt-scheibe-mit-klingen.23849/#post-41381
 
Zuletzt bearbeitet:
Oben