Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 4 months ago.
Connecting HC-05 Bluetooth to STM32 Nucleo F401RE
Hello there experts, I am new to MBED and really trying to catch up with this technology. I am currently using the aforementioned platform. Currently I'm trying to get it connected to my HC-05 bluetooth module. Can anybody help to show me the basic input and output programming code to turn on/off led n send a line to my bluetooth terminal at my phone? Please specify the connection pin of the TX RX from the board to the module and also the name of the bluetooth terminal app for android being recommended. I sincerely hope someone can help me.
Thanks in advance. -Maximus Meguard
1 Answer
9 years, 4 months ago.
I am trying to figure out how to connect to BR-LE4.0-D2A chip, so what I figured out so far - Chip has TX/RX traces which are connected to TX/RX on my board, I just had to open serial device.
Setting up serial devices pass-through
#include "mbed.h" Serial pc(USBTX, USBRX); Serial device(PTC17, PTC16); int main() { device.baud(9600); pc.baud(9600); while (1) { if(pc.readable()) { device.putc(pc.getc()); } if(device.readable()) { pc.putc(device.getc()); } } }
- On Windows connection can be established without any pin. I have an impression that serial port is provided by default, and I didn't need to set anything extra. - Windows Drivers in properties show that there are no services (which can be set up by BLE_API which I am not using), but device provides serial port which I can connect to with PuTTY.
Problems so far: - On Linux I cannot establish connection. - On Windows I can only send characters one way only, and data look like with wrong baud rate.
Hope that helps a bit, Look at the schematics where the TX/RX of Bluetooth is broken out, and don't power it with incorrect (too high) voltage :)
Update:
On Linux:
<<code title=Bash commands>>
hcitool scan # To see if the listening device can be found
sdptool search SP # To find device with SP(Serial port profile) and channel
rfcomm connect rfcomm3 xx:xx:xx:xx:xx:xx 1 # Connect to device with xx:xx:xx:xx:xx:xx address on channel 1 and create /dev/rfcomm3 device file
<</code>>
Still my data look like gibberish, but I verified with logic analyzer that it is my bluetooth module either broken or not configured properly. - Using rfcomm listen and rfcomm connect between two Linux laptops worked fine and I could communicate over serial - FXS-MULTI-B board alone with charged battery powering BL module, gets gibberish data on the output pins from BL_RX0.
If you use other BL module that has SP profile, above should work for you, I might need to contact vendor in my case. So far I don't recommend BL module I am using.
posted by 09 Jul 2015Hello Mateusz Kaduk! Thanks for responding. I finally managed to get my bluetooth module working without any problems. I used your script and make a few alterations. The reason why I created this post was because I couldn't get my serial port to function properly. Later, I understand that the same problem had occur while using Arduino. The similarity is that STM32 and Arduino uses Tx and Rx for serial port 2 for USB debugging. That means I cannot utilize that serial port for bluetooth transmission while plugging the board to the computer via USB. What I did was: 1) connect the Tx Rx of the bluetooth module to other serial ports that doesn't being utilized for USB debugging. In my case, I am using PA_11 and PA_12. 2) Import the BluetoothSerial library (Software serial) to my program, 3) Change the declaration from Serial device(PTC17, PTC16) to BluetoothSerial device (PA_11, PA_12) 4) Remove device.baud(9600); from the script. 5) Use Tera Term on my Windows and installed Bluetooth Terminal on my phone. 6) Connect my phone to the platform 7) Voila! Everything works fine.
Btw, I really appreciate for your respond. It has helped me a lot. I hope you can review some of the changes I've made and see if it works better on your end.
posted by 09 Jul 2015