Enabling Nucleo ST F401RE mbed Communication with HC-06 Bluetooth
STMicro announced an mbed enabled development board called the Nucleo. This Internet of Things tutorial shows how to enable the Nucleo with HC-06 Bluetooth.
Join the DZone community and get the full member experience.
Join For FreeARM mbed is designed to provide highly productive Internet of Things solutions. There are numerous boards available in market with different configurations from different vendors. Some of the most popular boards are mbed LPC1768 from NXP, mbed LPC 11U24, Seeeduino-Arch etc.
STMicroelectronics (STMicro) has announced an mbed enabled development board named STM32 Nucleo. These Nucleo boards will allow developers to re-use hardware and software IP for multiple projects thereby making them more scalable. This will also bestows a wide variety of shields that supports functions such as Bluetooth Low Energy (BLE), Wi-Fi connectivity, GPS, proximity sensing etc. ST Nucleo F103RB, ST Nucleo L053R8, ST Nucleo F401RE and ST Nucleo F302R8 are some of the boards from STMicroelectronics.
By default the bluetooth communication is not enabled on the Nucleo ST F401RE board. This blog will walk you through the process to enable the communication between Bluetooth module HC-06 and Nucleo ST F401RE, an mbed enabled Nucleo board.
Firmware Upgradation:
As Nucleo boards are having some issue with the firmwares installed it is mandatory to have the latest firmware installed on the board. For smoother functioning of the board ensure that the board will have latest version of firmware installed on it. If not, follow the steps mentioned belo
- Download and install the ST-Link drivers
- To install ST-Link drivers :
- Extract the Zip folder and run either dpinst_amd64.exe or dpinst_x86.exe depending on PC configuration
- Follow the prompts and finish the installation
- Download latest version firmware from here
- To Verify the firmware upgradation:
- Download latest firmware version from here
- Run the STLinkUpgrade.exe program and press connect
- Device details will be prompted if the ST-Link drivers were properly installed and then press yes
- This ensures firmware was upgraded successfully
Bluetooth HC-06 and Nucleo ST F401RE:
Nucleo board has arduino supported header pins thereby allowing the board to use with other Arduino supported devices/modules. In mbed repository there was variety of libraries and programs that illustrates Bluetooth communication using different modules. There are no libraries for Bluetooth HC-06 module. Hence I explored on how to communicate Arduino Bluetooth HC-06 Slave module with Nucleo ST F401RE. These are the steps to be followed to establish communication between them:
Bluetooth HC-06 has 4 pins namely RXD, TXD, GND and VCC. Connect bluetooth module to nucleo board as follows:
Bluetooth HC-06 | Nucleo ST F401RE |
RXD | TX |
TXD | RX |
Remember, TX/Do and RX/D1 pins of Nucleo Arduino connectors are not enabled by default. In order to enable them, some of the solder bridge configurations (open/close of some pins) are required. Instead of using this procedure I feel comfortable in using the default receiver and transmitter pins of Nucleo board. D10 and D2 pins are configured by default. Here is how to operate an LED using Bluetooth from a mobile and PC terminal.
Connect HC-06 module to Arduino headers on Nucleo ST F401RE as shown in fig below
- Connect Nucleo board to PC and ensure that Nucleo has detected as a drive
- Go to online mbed controller and import any sample code and replace it with the below code.
#include "mbed.h"
Serial bt(D10,D2);
Serial pc(USBTX,USBRX);
DigitalOut myled(D13);
int main() {
bt.baud(9600);
//prints data on mobile
bt.printf("Connection Established");
//print data on pc terminal
pc.printf("Connection Established");
while(1) {
//For reading and writing data from/to bluetooth HC-06
//check if bluetooth is readable and execute commands to toggle LED
if (bt.readable()) {
char input_key= bt.putc(bt.getc());
//tutn on LED if "y" is entered
if(input_key == 'y') {
myled = 1;
bt.printf("LED is ON");
}
//tutn on LED if "n" is entered
if(input_key == 'n') {
myled = 0;
bt.printf("LED is OFF");
}
}
//For reading and writing data from/to pc terminal
//check if pc is readable and execute commands to toggle LED
if (pc.readable()) {
char input_key= pc.putc(pc.getc());
if(input_key == 'y') {
myled = 1;
pc.printf("LED is ON");
}
if(input_key == 'n') {
myled = 0;
pc.printf("LED is OFF");
}
}
}
}
Thus the communication between bluetooth HC06 module and Nucleo board can be established using HTerm and Bluetooth SPP Manager.
Opinions expressed by DZone contributors are their own.
Comments