The following example programs will demonstrate the principles of using the HC-06 Bluetooth module:
These examples can then be used in conjunction with one of the following:
-
A serial port monitor application (such as Termite) on a PC. The PC will connect using either a Bluetooth dongle or a built-in Bluetooth module in the PC and the user will then use the application to send the raw messages to the STM32F4 device via the HC-06.
-
A Visual Basic (VB.NET) program running on a PC, also via either a Bluetooth dongle or built-in module
-
A Basic4Android example on an Android device. The program will then use the Android device's bluetooth module to establish communication with the STM32F4 device.
Basic4Android
This is the corresponding Basic4Android code for the above sample code. It will create Android application(s) to connect serially to the the STM32F4 device via the Android device's built-in bluetooth module.
Download:
VB.NET
This is the corresponding VB.NET code for the above sample code. It will create Visual Basic .NET application(s) to connect serially to the the STM32F4 device via a PC's built-in bluetooth module or usb bluetooth dongle.
Download:
How to use a USB Bluetooth dongle on a PC for the VB.NET examples
The following steps will guide you through the steps to succesfully create a SPP (Serial Port Profile) from a PC's USB Bluetooth dongle to the HC-06 Bluetooth module on the STM32F4 to use with the VB.NET examples:
-
Plug the Bluetooth dongle into a USB port on the PC.
-
Wait for all the drivers to be installed. The drivers are usually generic and should automatically download and install from Microsoft.
-
Sometimes a new COM port will be created after the Bluetooth dongle was installed and will appear as "Standard Serial over Bluetooth link (COM XX)". This is NOT the COM port we are going to use.
-
Make sure the STM32 device and HC-06 is powered up.
-
The STM32 device with the HC-06 module now needs to be added as a device to the PC. Click on Start -> Devices and Printers.
-
Click Add a device
-
Wait for the PC to detect your device. If it doesn't detect your device, try removing the Bluetooth dongle from the PC briefly and plug it in again. Go back to step 5 again.
-
Select you device in the list and click Next.
-
Wait for the PC to make a connection to the device.
-
Click Enter the device's pairing code.
-
Type "1234" (or whatever you changed the pin to) and click Next
-
Click Close
-
Still in the Add Device window, right click on your HC06 device and select Properties.
-
Select the Services tab.
-
Make sure that Serial Port (SPP) is selected. If it isn't, selelect it now and a new COM port will be created. This COM port (the one that appears next to the Serial Port (SPP) option) is the COM port to use in your example code.
-
You can also use a Serial Port Monitor application, such as Termite, to connect to the STM32F4 device.
How to use a built-in Bluetooth module on a PC for the VB.NET examples
The following steps will guide you through the steps to succesfully create a SPP (Serial Port Profile) from a PC's built-in Bluetooth module to the HC-06 Bluetooth module on the STM32F4 to use with the VB.NET examples:
-
Make sure the Bluetooth function is enabled on the PC.
-
Sometimes a COM port for the Bluetooth module already exists and will appear as "Standard Serial over Bluetooth link (COM XX)". This is NOT the COM port we are going to use.
-
Make sure the STM32 device and HC-06 is powered up.
-
The STM32 device with the HC-06 module now needs to be added as a device to the PC. Click on Start -> Devices and Printers.
-
Click Add a device
-
Wait for the PC to detect your device.
-
Select you device in the list and click Next.
-
Wait for the PC to make a connection to the device.
-
Click Enter the device's pairing code.
-
Type "1234" (or whatever you changed the pin to) and click Next
-
Click Close
-
Still in the Add Device window, right click on your HC06 device and select Properties.
-
Select the Services tab.
-
Make sure that Serial Port (SPP) is selected. If it isn't, selelect it now and a new COM port will be created. This COM port (the one that appears next to the Serial Port (SPP) option) is the COM port to use in your example code.
-
You can also use a Serial Port Monitor application, such as Termite, to connect to the STM32F4 device.