In this article, we describe the methods for using the BLE of the HM-10 module as an iBeacon device. Although the HM-10 functionality can also be used as a data line, a standalone sensor, or a control device, this article will not describe other options for its use.
The HM-10 is a Bluetooth 4.0 module based on the Texas Instruments CC2540 or CC2541 transceiver architecture with low-power Bluetooth wireless technology (BLE) and a system-on-chip (SoC) scheme. The module layout and firmware are owned by Jinan Huamao Technology (JNHuaMao) but are currently sold by various Chinese suppliers, as well as several US and European distributors.
The module has a compact size, as seen in the photo above. The distance between the contacts is 1.5 mm. Care should be taken when soldering wires to the module, which will need to be connected to a power source, and temporarily connected to a USB serial interface and a PC in order to configure the module as iBeacon.
CONNECTING POWER AND PROGRAMMER
To power the module you need to connect two wires, and to configure the module via a USB serial adapter, you need three more connections — two for connecting RX / TX and one for switching to firmware mode.
The photo above shows a module connected to a battery consisting of three Ni-MH rechargeable cells with a nominal voltage of 1.2 V x 3 = 3.6 V, as well as to a serial TTL RS232 converter with a USB interface. If you are an Arduino fan, you probably already have one of these adapters. If not, you can purchase it from us. For example, this one – PL2303 – USB – UART TTL converter RS232. When using this adapter, a positive contact must first be re-soldered from pin 5V to pin 3.3V.
If you use the settings described later in this article, the HM-10 consumes an average of about 0.18 mA. The battery shown has a capacity of about 1,800 mAh, which will ensure operation for more than 10,000 hours.
Below in the photo on the left are the contacts required for connecting and flashing the module, and the full pinout of the HM-10 module is shown.
In the upper figure on the left, the connections are shown in detail. The battery is connected to the module contacts 12 (+) and 13 (-). The RS232 data adapter (RXD) receiver is connected to pin 1, and the transmitter (TXD) is connected to pin 2. (Note: The transmitter and receiver signals on the HM-10 intersect. This is normal – it should be so.) The adapter ground is connected to pin 14 .
USING THE TERMINAL EMULATOR TO CONNECT TO THE HM-10
Your equipment is almost ready, but first you need to check if your HM-10 module is working. When the battery and the serial adapter are connected to the HM-10, connect the USB adapter cable to the computer. If you are using the adapter for the first time, you may be prompted to install a device driver for the module. In most cases, the operating system will automatically find the driver (this may take a couple of minutes). Otherwise, see the documentation that came with the device. If possible, pay attention to the COM port assigned to the adapter.
The HM-10 uses the AT command set, which requires special timing when manually entering commands from a PC. Commands do not end with a carriage return or line feed and depend only on a very short delay after the command line has been entered for completion. Therefore, I strongly recommend using the Arduino IDE serial monitor software to connect to the HM-10. Most people reading this have an Arduino IDE probably already installed on their PC. If it is not already installed, install any available version higher than 1.0x, accessible via the link on the official Arduino website.
In the Arduino IDE, in the drop-down menu of the tools, select Serial Port (port monitor), and then select the COM port that corresponds to your adapter. In most cases, this will be the COM port under the last number. See the screenshot above, where the COM port is denoted as COM3.
Then start the serial monitor by selecting the menu item under the tools. In the bottom menu, select the speed “9600 Baud” and “No line end”. After that, you can connect to the HM-10. Try typing “AT” (without quotes), and then press Enter. The HM-10 should respond with “OK”. The HM-10 device does not complete the output with a new line, so all responses will go one by one.
Then we recommend checking the firmware version on the HM-10 device. Enter the command “AT + VERR?”. If you recently purchased the HM-10, then the firmware version should be 526 or later. In this case, you can skip the “Firmware Update” section and immediately go directly to the “iBeacon Configuration” section. If you still need to install the latest firmware, follow the steps below to upgrade the software.
If the HM-10 device requires a firmware update, you need to download the appropriate version from the official JNHuaMao website. Determine which TI chip is used in your device. This will be either the CC2540 (older devices) or the CC2541 (new devices). From the bottom of the HM-10, you can see the square chip and read the label. Use a magnifier if necessary.
Make sure you download the correct firmware version! It must correspond to the HM-10 device and the TI chip installed in it.
Unzip the firmware update file and place its contents in the same folder. You will see at least 3 files. One of them will be a file readme.txt with brief instructions. The second is the firmware file with the .bin extension. The third file is the firmware update file with the .exe extension for Windows (there are no tools for Linux and Mac yet). It will probably be called HMSoft.exe.
Before upgrading the HM-10 firmware, make sure that the module has a reliable connection and that wires and cables cannot be accidentally pulled out. Keep pets and small children away from the place where you update the firmware to avoid accidentally interrupting the update. Interrupting the update process will instantly disable the module without the possibility of further recovery.
If everything is ready for the flashing process, follow the instructions below:
- Using the Arduino serial monitor, enter the AT + SBLUP command. The HM-10 should respond with OK + SBLUP. After that, the device will wait for the firmware update.
- Exit the serial monitor program.
- Then run the firmware update program (the .exe file extracted from the zip file), which is most likely called HMSoft.exe.
- In the COM port field, enter the number of the COM port connected to the HM-10 device. For example, if it is COM3, enter 3 in the field.
- Click the “…” button in the “Image File” field and select the name of the .bin file that is contained in the zip file: HMSoft.bin.
- Finally, click on the “Load Image” button.
- The firmware update will start, which will take a couple of minutes. Do not interrupt the upgrade process. Do not perform any operations on your PC during the upgrade to reduce the likelihood of interruption.
- After completing the check, it may take several seconds
- Before the “Download completed successfully” message appears.
The screenshot above shows an example of a successfully completed firmware update. When finished, exit the firmware upgrade program and launch the Arduino sequential monitoring program.
IBEACON CONFIGURATION ON HM-10
You need to enter several commands into the HM-10 device in order to configure it as an iBeacon. For this, use the Arduino serial monitoring program. The following list in bold indicates the commands that you need to enter into the HM-10 device, and to the right of them are comments. Each command is confirmed with the OK key …
|1.||AT+RENEW||Restore factory default settings.|
|2.||AT+RESET||Reboot the HM-10 device.|
|3.||AT||Waiting for OK confirmation.|
|4.||AT+MARJ0x1234||Set the main number to 0x1234 (hex).|
|5.||AT+MINO0xFA0||Set the extra number to 0xFA01 (hex).|
|6.||AT+ADVI5||Set advertising interval to 5 (546.25 milliseconds).|
|7.||AT+NAMEDOPEY||Replacing the name of the HM-10 module with DOPEY. Assigning a unique name.|
|8.||AT+ADTY3||Shutdown (to save energy).|
|9.||AT+IBEA1||Enable iBeacon mode.|
|10.||AT+DELO2||iBeacon only for broadcast (energy saving).|
|11.||AT+PWRM0||Auto Sleep Mode This reduces power from 8 to 0.18 mA.|
Note: Parameter values that are highlighted in red should be as you want. The above are only examples.
After sending this command set, the HM-10 should be visible on your Apple or Android device (using your favorite iBeacon app) as an iBeacon. You can select the corresponding main and additional numbers in steps 4 and 5. The main number is the same in the area (for example, a shop or building), and the additional number identifies iBeacon. The above procedure does not change the universally unique identifier HM-10, which is standard approximate by default.
If you want to change it, you can do it using the commands AT + IBE0, AT + IBE1, AT + IBE2 and AT + IBE3. The 16-byte universal unique identifier is divided into 4-byte blocks, and each of them is modified using a different command. The table below shows how much of the universally unique identifier is updated with each of the 4 commands.
DISABLE CABLE PROGRAMMING
When you are sure that the HM-10 is configured the way you want, you can disconnect it from the serial adapter, leaving only the power connected. To protect the battery and the module, we recommend mounting the assembly in a protective case.
IBEACON SCANNING EXAMPLE
The screenshots below show three examples of iBeacons based on the HM-10, scanned on an Android phone, with an indication of the distance to each of the devices.
USING THE HM-10 AS A CONTACT-FREE IBEACON DEVICE
The following eight universal unique identifiers are built into Apple AirLocate as contactless devices. Use them to ensure compatibility with iOS applications using AirLocate.
- 74278BDA-B644-4520-8F0C-720EAF059935 (This address is configured in HM-10 by default)
When the HM-10 device is set to automatically go to sleep, it will quickly go to sleep when it is turned on or restarted. After sending the AT + PWRM0 command and rebooting the HM-10 device, it will no longer respond to AT commands.
To wake the device, send him a long string of random alphabetic characters that are at least 80 characters. The device will wake up and answer OK + WAKE. If you want to work with the device for some time, send him the AT + PWRM1 command so that it does not go into sleep mode during operation. After that, you can send an AT + PWRM0 command to put the module back into sleep mode and reduce power consumption.