Deprecated: Assigning the return value of new by reference is deprecated in /home/nicholas/public_html/ggnew/components/libraries/cmslib/spframework.php on line 101

Deprecated: Assigning the return value of new by reference is deprecated in /home/nicholas/public_html/ggnew/components/libraries/cmslib/spframework.php on line 644
Bluetooth Howto
Bluetooth Howto
All News -> Jeff's Shop
Written by Jeff Ledger   
Wednesday, 02 May 2012 16:00

How to use those inexpensive Bluetooth modules with your Propeller.

QS_LED_Bluetooth

In this article, 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

 

Step 1Connecting the Bluetooth Module to the Propeller

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...

 

Step 2Connecting to the Module Step 1

install_bt_device_step1

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.

 

Step 3Connecting to the Module Step 2

install_bt_device_step2

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

 

Step 4Connecting to the Module Step 3

install_bt_device_step3

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

 

Step 5Connecting to the Module Step 4

install_bt_device_step4

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.

 

Step 6Connecting to the Module Step 5

install_bt_device_step5

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.

 

Step 7Connecting to the Module Step 6

install_bt_device_step6

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.
Click on the Services tab.  The COM port indicated is the one we'll use. 

 

Step 8Testing your connection

snake_pst

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.

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


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.

 

Step 9Controlling the Propeller

pst_LEDdemo

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 P19, but I'm picky about bending the leads.)

Download, extract, and upload "BT_LED.spin" 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.


Step 10Enhancing the Interface

BASIC_LEDtest

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.

 

Step 11Adding a Servo: Bluetooth robotics 1st step.

QS_Servo

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.

 

Step 12Android Control

sena_term

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.

 

 

 

 

Other Stuff

Get Our RSS Feed

Cool Project