Back to work on the Ardbot. I've decided to build my control panel competely in java/JavaFX on Linux. One challenge was getting my Bluetooth connectivity going on Linux with this configuration:
- Kensington USB Bluetooth dongle on Fedora 11 PC
- Sparkfun Bluetooth modem on robot
My goal will be to control the robot from a gamepad controller attached to the PC, wirelessly over the Bluetooth link.
To test the connectivity, I came up with a simple Arduino sketch that reads data from the Sharp IR range sensor and sends the distance, in centimeters, out over the wireless link, to be read by whatever program on the PC. Here is the Arduino code:
#include <NewSoftSerial.h>
NewSoftSerial blueSerial(11,8);
int irpin = 0;
int distance = 0;
void setup() {
blueSerial.begin(9600);
}
void loop() {
distance = analogRead(irpin);
blueSerial.println(read_gp2d12_range(distance));
delay(1000);
}
float read_gp2d12_range(int distance) {
if (distance < 3)
return -1; // invalid value
return (6787.0 /((float)distance - 3.0)) - 4.0;
}
The robot is wired like this (i'm leaving out the power, gnd, etc wiring):
Arduino analog pin 0 ---> Sharp IR sensor data pin (yellow wire)
Arduino digital pin 11 ---> BT modem TX pin
Arduino digital pin 8 ---> BT modem RX pin
With the Arduino powered up, if everything is wired correctly, the red power light on the BT modem should come on.
After inserting the USB Bluetooth dongle on my PC, I ran the following commands from the linux command line to get connected:
hcitool scan
this will give me the hardware address of the robot's BT modem - my results came back like this
Scanning ...
01:1E:09:0F:0A:15 SparkFun-BT
To connect, I used the following command, using the hardware address from running hcitool scan:
sudo rfcomm connect 1 01:1E:09:0F:0A:15
If all is well, I should see:
Connected /dev/rfcomm1 to 01:1E:09:0F:0A:15 on channel 1
Press CTRL-C for hangup
There are a couple of ways to see the data coming across the wireless connection. The easiest way that i could think of was to run the cat command in a separate terminal window:
sudo cat /dev/rfcomm1
what do you know, i'm reading the sensor data wirelessly!
68.98
68.20
65.97
68.98
68.20
67.44
every second, the bot is sending the distance to an object in centimeters from the front mounted IR sensor.
To disconnect, from a separate terminal window run this command:
sudo rfcomm release 1
In the original window, you'll see:
Disconnected
More to follow!