How to Use Bluetooth With Your Propeller

by Gadget Gangster in Circuits > Microcontrollers

8646 Views, 16 Favorites, 0 Comments

How to Use Bluetooth With Your Propeller

QS_LED_Bluetooth.jpg
In this Instructable, I'll teach you how to install and use a Bluetooth module with your Propeller.

I'll demonstrate several examples of interacting with the module:
  • Interacting with the Propeller using a simple terminal.
  • Controlling devices connected to the Propeller over Bluetooth.
  • Creating a simple Windows application to control the Propeller.
  • Interacting with the Propeller using an Android.
The Bluetooth module is both amazingly inexpensive and extremely easy to work with. 
It's communication range of approximately 20-30 feet, makes it perfect for indoor robotics experiments.

Things you'll need:
  • Your favorite Propeller board or breadboard.  (I'm using Quickstart w/QuickProto.)
  • The Bluetooth module.  (These can be sourced commonly on Ebay. Around $15)
  • A PC equipped with Bluetooth.  (Easily added by USB)
  • An LED or two.
  • Some jumper wires.
  • Installed copy of Propeller Tool w/Serial Terminal
  • Source code for all demos and code in this Instructable.

Things you might want: (depending on your desired direction)
  • A Servo (Any hobby servo will do)
  • An Android equipped with Bluetooth
  • Installed copy of Just Basic

Connecting the Bluetooth Module to the Propeller

QS_LED_Bluetooth.jpg
I'll assume at this step that you already have a Bluetooth module installed in your PC.  These are a common standard item in most modern laptops, and can be easily added as a USB device few a few dollars.   If you are using an XP machine, you'll also want to make sure that you have Service Pack 2 or later installed which included the Bluetooth stack from Microsoft.

Connecting the Bluetooth Module to the Propeller:

Using four jumper wires, make the following connections using the included cable:
  • Bluetooth VCC <--> 3.3v
  • Bluetooth GND <--> GND
  • Bluetooth RXD <--> Propeller P20
  • Bluetooth TXD <--> Propeller P21
That's it!  Now it's time to install the Bluetooth Module on the PC.  
Turn on the Propeller Platform to power up the Bluetooth Module and continue to the next step...

Connecting to the Module Step 1

install_bt_device_step1.JPG
bt_icon_in_cp.JPG
With the Bluetooth connected to your Propeller, powered up, it should have a flashing light.  
This indicates that it does have power, but isn't communicating with anything.


Find the Bluetooth icon.   You'll should one near the clock in Windows, or in the Control Panel. (2nd image)

Open it, and click on Add, under the Devices Tab.

Connecting to the Module Step 2

install_bt_device_step2.JPG
Put a check-mark in the box labeled "My device is setup and ready to be found." , then click Next.

Connecting to the Module Step 3

install_bt_device_step3.JPG
The module should be discovered with the name "linvor" (New Device).  Click to select it, and click Next.

Connecting to the Module Step 4

install_bt_device_step4.JPG
Next, we'll need to add the passkey (password) allowing us to connect to the module..

The passkey is 1234

Select "Use the passkey found in the documentation" and enter 1234.

Click Next.


Connecting to the Module Step 5

install_bt_device_step5.JPG
This Bluetooth device installs itself on your PC a two different COM ports.  We are most interested in the lowest number.
(In my example, COM7)

Click Finish.

Connecting to the Module Step 6

install_bt_device_step6.JPG
install_bt_device_step7.JPG
It's not a bad idea to double check your COM port setting:

Do the following:

Click once on "linvor" in the Devices Tab & click Properties. (1st image)
Click on the Services tab.  The COM port indicated is the one we'll use. (2nd image)




Testing Your Connection

snake_code.JPG
snake_pst.JPG
Now that the Bluetooth module has been added to Windows, it's time to test things out a little.  Let's use a simple game.

Make sure that you have your Propeller and Bluetooth module connected and switched on as indicated in Step 2.
 
Download, extract, and upload "Snake.spin" to your Propeller using F10.

If you've used different I/O pins on your Propeller configuration, simply adjust them in the code as shown in the first image.

Once you've got the spin program running:
  • Open Parallax Serial Terminal.  
  • Set the COM Port to match the one you noted in step 7.
  • Set the baud rate to 9600 and click Connect.  (2nd image)

You should see Snake waiting for you to press a key.   Enjoy a little Snake using your PC keys a,s,w, & z for control.
Snake was written by MagIO2 of the Parallax Forums.  


Controlling the Propeller

pst_LEDdemo.JPG
QS_LED_Bluetooth.jpg
Ok, so Snake was interesting to play with for a few minutes.  It proves communication between the Propeller and PC is working.

This time, grab an LED and insert it into pins 18 and 19 of the Propeller. (1st image)
  • Propeller P18 <--> LED Cathode (Shorter Leg)
  • Propeller P19 <--> LED Anode (Longer Leg)
We'll using a couple lines of code to pull Propeller's P15 pin low allowing us to light it by switching P15 on and off.
(We could have easily put the Cathode of the LED to GND, and Anode to P15, but I'm picky about bending the leads.)

Download, extract, and upload "BT_Led" to your Propeller using F10.

Open Parallax Serial Terminal once again, connect to the same COM port and baud rate as before.
This time you should be able to press a, & b on the PC keyboard to toggle the LED on and off.

Enhancing the Interface

BASIC_LEDtest.JPG
Controlling the LED in a Windows serial terminal, while cool lacks feel of being a true Windows application...

Let's move from using a serial terminal to our own simple Windows application using Just Basic.
Just Basic is a free BASIC programming language for Microsoft Windows. 

Download, and install Just Basic.  
Open LED_Demo.bas which will run on the PC to control our LED.

Adjust the COM7 in line 7 to match your Bluetooth settings.   Pressing the ON/OFF buttons will send the keys, a, & b to the Propeller.

Just Basic is the free version of Liberty BASIC which includes more commands along with the ability to generate self-standing .exe files from your code.   Your Just Basic programs can be distributed with Jbrun.exe and a handful of .DLL files.

Adding a Servo: Bluetooth Robotics 1st Step.

QS_Servo.jpg
While we are at it, let's add a servo and a few lines of code to our Just BASIC program.  
Controlling servos using this method is a snap!

Add a servo to the circuit as demonstrated in the attached photo.
Servos tend to be a little more power hungry, so you may want to add some additional power as well.

In my demonstration, I've attached a servo to Propeller I/O P5, and connected the power and ground connections.
SERVO_DEMO (included in the archive) expands on our LED demo by adding controls 1,2 & 3 to for some basic servo control.



Android Control

sena_term.JPG
Time to take our Bluetooth control on the road!

You'll need to unpair your Bluetooth device on the PC before attempting to connect.  
Double click on the Boothtooth icon and click Remove.

Next visit Android Market and install SENA BTerm Bluetooth Terminal.  (A free application)
  • Press the left-most (menu) button on the bottom of your Android
  • Click on Bluetooth Management
  • Click on connect to
  • Click the select button
  • Click the Start Scan button
  • Click on linvor
  • Click on Connect
  • Enter the passkey (password) as before: 1234

If you have the simple LED_Demo loaded, you should be able to press the a, & b keys to toggle the LED.
If you have the Servo_Demo loaded, you should be able to press 1,2, & 3 to control the servo.

SENA is again a simple terminal.  Do you want something more like the Just BASIC interface?  Check out BlueScripts.

I made it at TechShop!