Today I’ll show you how to connect a bluetooth serial module to a StickOS board.
You may have seen those cheap bluetooth serial modules with carrier boards, that have become very popular amongst Arduino users.
You can buy them for a couple of bucks from ebay.
Mine came with a matching cable.
This module is configured as a SPP (serial port profile) slave.
Means, a bluetooth host (like a PC, a smartphone, or another module configured as host) can connect to it and open a transparent serial connection.
By default, the module is configured for 9600 baud, 8 bit, no parity, one stop bit (9600,n,8,1).
This is very convenient, because it’s exactly the setting that the serial console of StickOS uses.
The PIC32 board I used is a UBW32, flashed with StickOS 1.92, but it also works with every other micro that is able to run StickOS.
The carrier board for the bluetooth module has it’s own voltage regulator, so the module runs from 5V (in this case the USB voltage). Also, it’s pins are 5V tolerant, so it can be connected to 3.3V (i.e. PIC32) or 5V (i.e. Arduino) micros.
I took the 5V and ground for the module from the UBW’s power connector, and connected the modules RXD to the UBW pin F5 (which is pin RF5/U2TX of the PIC32), and the TXD pin of the module to F4 (pin RF4/U2RX of the PIC32).
This is the serial port that StickOS by default uses for the serial console.
Now we can try a bluetooth connection.
Open the bluetooth configuration of your device, find a bluetooth slave named “JY-MCU” (the name may be different, depending on what module you use), and pair your device with it.
This should create a new virtual serial port on your device. As soon as you open this serial port (i.e. using a terminal program), the connection to the bluetooth slave will be established automatically.
This procedure depends on the type and version of your host device, so I don’t show this here.
I used my Huawei Ideos X3 Android smartphone, and the terminal program “Bluetooth Terminal Version 1.0” from the Google Play store (see links at the and of this post).
After sending one character, StickOS will respond with it’s usual prompt.
You can also see the code that I entered.
Lines 10..30 declare variables for the three port pins with LED’s, lines 40..60 switch the LED’s off (the LED’s are connected to +3.3V, therefore you have to set the pins high to switch the LED’s off).
Don’t forget to map the heartbeat LED to something else.
You can now switch an LED on by typing LET led1 = 0.
But we want it something more comfortable, so we use the program “Bluetooth SPP”.
At start, the program will search for available bluetooth devices in range.
Select the module (it should be shown as bonded).
Now Bluetooth SPP shows a mode selection screen.
Choose “Keyboard mode”.
As you can see, I already edited the key functions here.
Open the menu and choose “Set Key func”.
Now press a key, and edit a command to send (here: green LED on):
And the corresponding LED off command:
Repeat this for all other LED’s, if you want.
Now we have buttons to control all LED’s:
As you may imagine, this can be used to control all I/O pins, not only to switch them on and off, but also to change a PWM value, read back ADC inputs, etc.
You should switch autorun on, to ensure that the program is executed after a reset or power cycle, and the I/O’s are configured. Also it doesn’t do any harm if you switch the echo and prompt off.
In part 2, I’ll show you some more sophisticated things.