Getting started with Bluetooth
From researching Bluetooth connectivity we've found it can be relatively easy to get to grips with, but that a lot of the documentation doesn't show this and just leaps ahead to more advanced uses. This is a quick bit of documentation on making a Bluetooth device that can respond to your computer. In this example a Processing sketch will blink the LED of the Arduino. It requires basic knowledge of soldering, Arduino and Processing.
Tools

Soldering iron
Equipment

Breadboard

Jump wires

Header pins

Solder
Parts

Arduino Decimilla or Duemialnove

BlueSMiRF Gold - Bluetooth Modem
Part 1

First you must upload your sketch to the Arduino. For details on this procedure look here. The sketch below will tell the Arduino to light the LED on pin 13 whenever the character 'H' is sent. Arduino code below.
char val; // Data received from the serial port int ledPin = 13; // Set the pin to digital I/O 4 void setup() { pinMode(ledPin, OUTPUT); // Set pin as OUTPUT Serial.begin(115200); // Start serial communication at 9600 bps } void loop() { if (Serial.available()) { // If data is available to read, val = Serial.read(); // read it and store it in val } if (val == 'H') { // If H was received digitalWrite(ledPin, HIGH); // turn the LED on } else { digitalWrite(ledPin, LOW); // Otherwise turn it OFF } delay(100); // Wait 100 milliseconds for next reading }
Part 2

Snap off a row of 6 pin headers and solder them to the BlueSMiRF.


Part 3

Press the BlueSMiRF into the breadboard, with each pin in a separate row. Then connect the following wires to your Arduino using the jump wires CST–1 — RTS–0 VCC — 5v GND — GND TX — RX RX — TX
Bear in mind that while RX and TX are connected to the Bluetooth module you cannot upload a new sketch.


This is your basic hardware setup for communicating via Bluetooth. You can communicate directly from your computer once you are paired with the device.
Part 4 (Mac)









a) Open Bluetooth Preferences from System Preferences or the Menu Bar.
b) Click "+" to add a new device.
c) Click continue.
d) Select "Any device", click continue.
e) A list of Bluetooth devices in range will be populated. Search for your devices serial number, which should be on a sticker on your device. This should refresh after a time to "FireFly-XXXX", where XXXX is the last last four digits of the serial number. Select and click continue.
f) Once information has been gathered about the device click continue.
g) You'll be prompted for your device passkey. The (new) blue-antenna version's passkey is "1234" and the (old) white-antenna version's passkey is "default".
h) Follow the prompts and your device should now be paired with your computer.
*Windows pairing may vary depending on the version and Bluetooth software.
Part 5



Once the Bluetooth modem is paired with your computer you can treat it like any other serial connection. Below is a slight variation on the 'SimpleWrite' sketch in Processing. When you run the sketch for the first time you must check that this line refers to the correct serial port:
String portName = Serial.list()[4];
The available serial ports should be listed in the text area under the Processing sketch. The correct one should look something like:
[x] "/dev/tty.FireFly-xxxx-SPP-1"
When a successful connection is made the red flashing LED should turn off and a green LED should turn on.
import processing.serial.*; Serial myPort; // Create object from Serial class int val; // Data received from the serial port void setup() { size(200, 200); println(Serial.list()); //This will print a list of the serial ports String portName = Serial.list()[4]; //replace 4 with the number for tty.FireFly-XXXX myPort = new Serial(this, portName, 115200); } void draw() { background(255); if (mouseOverRect() == true) { // If mouse is over square, fill(204); // change color and myPort.write('H'); // send an H to indicate mouse is over square } else { // If mouse is not over square, fill(0); // change color and myPort.write('L'); // send an L otherwise } rect(50, 50, 100, 100); // Draw a square } boolean mouseOverRect() { // Test if mouse is over square return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150)); } Part 6


Pin 13 should now light whenever your cursor over the square in the Processing sketch. If this is working you have the basics of Bluetooth communication and can start tailoring it to your needs.
Tools

Soldering iron
Equipment

Breadboard

Jump wires

Header pins

Solder
Parts

Arduino Decimilla or Duemialnove

BlueSMiRF Gold - Bluetooth Modem
Part 1

First you must upload your sketch to the Arduino. For details on this procedure look here. The sketch below will tell the Arduino to light the LED on pin 13 whenever the character 'H' is sent. Arduino code below.
char val; // Data received from the serial port int ledPin = 13; // Set the pin to digital I/O 4 void setup() { pinMode(ledPin, OUTPUT); // Set pin as OUTPUT Serial.begin(115200); // Start serial communication at 9600 bps } void loop() { if (Serial.available()) { // If data is available to read, val = Serial.read(); // read it and store it in val } if (val == 'H') { // If H was received digitalWrite(ledPin, HIGH); // turn the LED on } else { digitalWrite(ledPin, LOW); // Otherwise turn it OFF } delay(100); // Wait 100 milliseconds for next reading }
Part 2

Snap off a row of 6 pin headers and solder them to the BlueSMiRF.


Part 3

Press the BlueSMiRF into the breadboard, with each pin in a separate row. Then connect the following wires to your Arduino using the jump wires CST–1 — RTS–0 VCC — 5v GND — GND TX — RX RX — TX
Bear in mind that while RX and TX are connected to the Bluetooth module you cannot upload a new sketch.


This is your basic hardware setup for communicating via Bluetooth. You can communicate directly from your computer once you are paired with the device.
Part 4 (Mac)









a) Open Bluetooth Preferences from System Preferences or the Menu Bar.
b) Click "+" to add a new device.
c) Click continue.
d) Select "Any device", click continue.
e) A list of Bluetooth devices in range will be populated. Search for your devices serial number, which should be on a sticker on your device. This should refresh after a time to "FireFly-XXXX", where XXXX is the last last four digits of the serial number. Select and click continue.
f) Once information has been gathered about the device click continue.
g) You'll be prompted for your device passkey. The (new) blue-antenna version's passkey is "1234" and the (old) white-antenna version's passkey is "default".
h) Follow the prompts and your device should now be paired with your computer.
*Windows pairing may vary depending on the version and Bluetooth software.
Part 5



Once the Bluetooth modem is paired with your computer you can treat it like any other serial connection. Below is a slight variation on the 'SimpleWrite' sketch in Processing. When you run the sketch for the first time you must check that this line refers to the correct serial port:
String portName = Serial.list()[4];
The available serial ports should be listed in the text area under the Processing sketch. The correct one should look something like:
[x] "/dev/tty.FireFly-xxxx-SPP-1"
When a successful connection is made the red flashing LED should turn off and a green LED should turn on.
import processing.serial.*; Serial myPort; // Create object from Serial class int val; // Data received from the serial port void setup() { size(200, 200); println(Serial.list()); //This will print a list of the serial ports String portName = Serial.list()[4]; //replace 4 with the number for tty.FireFly-XXXX myPort = new Serial(this, portName, 115200); } void draw() { background(255); if (mouseOverRect() == true) { // If mouse is over square, fill(204); // change color and myPort.write('H'); // send an H to indicate mouse is over square } else { // If mouse is not over square, fill(0); // change color and myPort.write('L'); // send an L otherwise } rect(50, 50, 100, 100); // Draw a square } boolean mouseOverRect() { // Test if mouse is over square return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150)); } Part 6


Pin 13 should now light whenever your cursor over the square in the Processing sketch. If this is working you have the basics of Bluetooth communication and can start tailoring it to your needs.

0 Comments:
Post a Comment
<< Home