Electronics and Programming for All
Fun with PyRSSI, an Arduino and Twitter
In this little project, the RSSI value (detected by a small python script) is used to control 3 LED’s on an Arduino. The LED’s are used to indicate the proximity (in terms of Far Away, Slightly Closer and Very Close) of a paired device relative to the PC running the script. The python script can also send a message to Twitter when the paired Bluetooth device is in close proximity to the PC.
The Arduino Sketch and companion Python script are both in the zip file rssitracker.zip which can be downloaded from the Software page.
What you need
Hardware:
- 1x Arduino
- 1x Solderless Breadboard
- 3x LED’s (Different Colours if possible. I’ve used Red, Blue and Green to indicate Far Away, Slightly Closer and Very Close proximity.)
- 1x Bluetooth Dongle (If you don’t have built-in Bluetooth on your machine.)
- A Bluetooth device to pair with the PC.
Software:
- Linux
- Python with the PyRSSI, pyBluez and Twitter modules installed.
- Swig
- The Python and Bluetooth development libraries.
You will also need to register a Twitter account to use the Twitter Announce features. You can sign up for free here.
Installing the Software Components
Start off by installing pyBlueZ, swig, python-twitter and the development libraries for Python and Bluetooth. For Ubuntu users, installing these components is as easy as issuing the following command:
sudo apt-get install python-twitter python-bluez swig libbluetooth-dev python-all-dev
The installation of PyRSSI, on the other hand, requires a couple more steps. Here are the steps I taken:
- Download the archive (tar.gz or tar.bz2) from here and uncompress to a directory of your choice.
- Change to the directory where you uncompressed PyRSSI and issue the following command to complete the installation:
sudo python setup.py install
This should install the PyRSSI module and its dependencies to the correct directory.
Hardware Setup
The hardware side of this project is simple and consists of 3 LED’s connected to the Digital pins 2, 4 and 7 of the Arduino. If anyone wants an pic or Circuit diagram putting up, I’ll be more than happy to do so.
Pairing a Bluetooth device
Now that everything is connected up and all software components are installed, we need a Bluetooth device paired to the PC so we can use it. First, make sure the Bluetooth device is in Discoverable mode.
In Ubuntu, you can just load the Bluetooth Setup Wizard by right-clicking on the Bluetooth icon on the top bar of the desktop and selecting the Setup New Device option then just follow the steps.
Getting the Device’s MAC address
Now that the device is paired to the PC we need to get it’s MAC address. You can use the following command in Ubuntu to get the Name and MAC address of any discoverable device:
hcitool scan
When hcitool has finished scanning for devices, you should get output similar to that in the screenshot below:
Have a look at the top entry that I’ve highlighted. You can see the Devices name ‘V630i‘ on the right-hand side, and it’s corresponding MAC address ‘00:1A:75:A0:32:DC” on the left-hand side.
Using the Software
First of all, upload the Arduino sketch (bthoming_dev.pde) to the Arduino. When the sketch has been uploaded successfully, open up the python script (rssitracker.py) and configure it to your needs. A list of the configuration options and what they do can be found below:
- ArduinoPort:
Set to the serial port device your Arduino is connected to.
- DEV_MAC:
Sets the MAC address of your paired Bluetooth device.
- UseTwitter:
Determines whether the Twitter feature is used. Set to True to use it and False to not use it.
- TwitterUser:
The Username of Your Twitter Account.
- TwitterPass:
The Password of your Twitter account.
- TwitterThis:
The message you want to ‘Twitter’ when the Bluetooth device is in close proximity
The three options below configure the RSSI threshold values. What I’ve found from using pyRSSI is that any RSSI value of 0 and above indicates Very Close Proximity, while a RSSI value of -1 or below indicates Very Far or Out Of Range. So bear that in mind when setting the options below:
- VeryClose:
You can set the trigger value for when the bluetooth device is very close to the PC.
- AwayFromPC:
You can set the trigger value for when the bluetooth device is away from the PC, but not too far away from it.
- VeryFarAway:
You can set the trigger value for when the bluetooth device is very far away from the PC.
When you’ve set all the configuration values to your preferences then connect up the Arduino and execute the Python script. There’s no command line arguments to enter here so just type: ‘./rssitracker.py’ to run it.
Limitations
This was just a 5-minute hack and is bound to have problems, so don’t rely on it for anything just yet; I just wanted get it up on here to show you all what you could do with the PyRSSI module. I should hopefully be able to get an improved version of this up in the next few days or so. Until then, Enjoy.
Related posts:
| Print article | This entry was posted by Peter on March 7, 2009 at 16:40, and is filed under Arduino, Programming, Python. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |
Comments are closed.






Recent Comments