Bluetooth Low Energy Remote
Bluetooth Low Energy Remote Control In 2015 we presented several Bluetooth Low Energy (
Bluetooth Low Energy Remote Control
In 2015 we presented several Bluetooth Low Energy (BLE) projects (thermometer, power switch, etc.) and a series of articles around a Break-out Board (BoB) for the BLE module BL600 from Laird. This small module has a cousin, the BL620, which functions as a BLE master (it is possible to upgrade a BL600 to a BL620 with a JTAG programmer) and that allows to exchange data between this module and one or more slave modules.
These BLE modules can be programmed in SmartBASIC and we will use the commands presented in the articles about the projects. In this article I propose to configure the BL620 as a remote control for the power switch. For this we will need a new BoB with the BL620 and a CR2032 coin cell mounted (note that we mount the battery on top of the BL620, we name this board BOB-BL620)
The circuit:
The BL620 runs SmartBASIC on its ARM Cortex core (which we described in detail in 2015). The task that we want it to perform is rather simple and so we do not need an additional microcontroller; only a few other components are needed:
- A 6-pin connector for programming the module with the UwTerminal tool.
- A pushbutton to reset the module.
- Two pushbuttons, one to activate and the other to deactivate the power switch.
- Two LEDs: blue for the connection status of a red one for the status of our switch. This one will be switched off after two seconds to save battery power.
The program:
a) Find the power switch
When buttons 0 and 1 are held down during a reset (after pressing the reset pushbutton) or power-up the BL620 will scan for BLE devices in order to find the name of our power switch: JA_SWITCH. If it is found its MacAddress is stored in the BL620’s EEPROM with the function NVRECORDSET. Our module is now ready to control the power switch.
b) Connecting and sending commands
We will profit of the power of SmartBASIC by using its event management system which we described in one of the project articles. As you can see from the diagram, events are used to advance step by step through the transmission of a command ‘0’ or ‘1’. See the diagram : the BL620 waits on a keypress, then waits for a connection to be established, then waits for of the entry of Charateristic, then waits for the disconnection to happen and then enters sleep mode. At the end, we wait until timers 6 and 7 expire for do sleep mode. Do not forget to close the serial port of our module in order to reduce its power consumption to about 5µA
The hardest part is to find the handlers corresponding to the events. By looking up the function in the documentation the name of the handler can be found. It is then enough to copy the corresponding code from the libraries (files slib) into our program. To avoid conflicts between our handlers and those contained in the library, we rename ours by prefixing them with “MyHandler”.
A complete power switch control action takes less than a second which is pretty fast. This is possible because we stored the MacAddress in the module’s EEPROM so that the potentially long scanning procedure can be avoided. This is why we executed a scan when we connected for the first time to the power switch.
Conclusion
As you have seen, it is not very complicated to build a BLE-based remote control with a BL620. A complete event diagram to send a command to the power switch was presented. You are now able to modify this program to control for example the Lumina BLE RGB lamp, also described in Elektor.
Best regards
Jennifer
Diskussion (0 Kommentare)