0% found this document useful (0 votes)
165 views

Don Coleman Connecting Arduino Phones With Bluetooth Cordova PDF

This document summarizes connecting an Arduino to phones using Bluetooth and the Cordova framework. It discusses using the BluetoothSerial Cordova plugin to connect to Arduino devices from Android and Bluetooth Low Energy from iOS. Examples are provided to discover devices, connect, send data to control an LED strip, and receive sensor data. The document also introduces the RFduino Cordova plugin for using Bluetooth Low Energy with RFduino devices.

Uploaded by

muhaned190
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views

Don Coleman Connecting Arduino Phones With Bluetooth Cordova PDF

This document summarizes connecting an Arduino to phones using Bluetooth and the Cordova framework. It discusses using the BluetoothSerial Cordova plugin to connect to Arduino devices from Android and Bluetooth Low Energy from iOS. Examples are provided to discover devices, connect, send data to control an LED strip, and receive sensor data. The document also introduces the RFduino Cordova plugin for using Bluetooth Low Energy with RFduino devices.

Uploaded by

muhaned190
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Connecting Arduino & Phones

with Bluetooth & Cordova
Philly ETE - April 23, 2014
Presented by Don Coleman / @doncoleman
Apache Cordova
PhoneGap
npm install -g cordova
http://docs.cordova.io
Arduino
#include <SoftwareSerial.h>

#define RxD 6
#define TxD 7

SoftwareSerial bluetooth(RxD,TxD);
int counter = 0;
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
Serial.println("Bluetooth Counter\n");
}
void loop() {
Serial.println(counter);
bluetooth.println(counter);
counter++;
delay(1000);
}
Bluetooth Serial
Cordova Plugin
https://github.com/don/BluetoothSerial
Installing
$ cordova plugin install \
com.megster.cordova.bluetoothserial
Connecting
var macAddress = "00:00:AA:BB:CC:DD";

bluetoothSerial.connect(
macAddress,
connected,
disconnected);
Sending Data
bluetoothSerial.write("Hello Arduino");
Receiving Data
var onMessage = function(data) {
console.log(data);
};

bluetoothSerial.subscribe("\n",
onMessage,
onFailure);
Demo
Phone receives data from Arduino
Listing Devices
bluetoothSerial.list(success, failure);
List shows paired devices
[{
"class": 276,
"id": "10:BF:48:CB:00:00",
"address": "10:BF:48:CB:00:00",
"name": "Nexus 7"
}, {
"class": 7936,
"id": "00:06:66:4D:00:00",
"address": "00:06:66:4D:00:00",
"name": "RN42"
}]
What about iOS?
Bluetooth Low Energy
aka Bluetooth Smart
BLE doesn't have SPP
but available hardware has "serial like" services
UART Service
RX - write without response
TX - read, notify
Discovering devices
bluetoothSerial.list(success, failure);

No pairing, finds devices


List discovered devices
[{
"id": "CC410A23-2865-F03E-FC6A-4C17E858E11E",
"uuid": "CC410A23-2865-F03E-FC6A-4C17E858E11E",
"name": "Biscuit",
"rssi": -68
},{
"id": "ED7127D4-593B-490E-9DA7-959FE78EC603",
"uuid": "ED7127D4-593B-490E-9DA7-959FE78EC603",
"name": "UART",
"rssi": -47
}]
Once you're connected
there's no difference
(except BLE only handles small chunks of data)
BLE hardware
RedBearLab BLEmini
RedBearLab BLE Shield
Adafruit Bluefruit LE
c red, green, blue
c0,0,255\n
Demo
Phone controls LED strip on Arduino
Control NeoPixel LED on Arduino from Android
onColorChange: function (evt) {
var c = app.getColor();
rgbText.innerText = c; // 0,0,255
previewColor.style.backgroundColor =
"rgb(" + c + ")";
app.sendToArduino(c);
},
sendToArduino: function(c) {
bluetoothSerial.write("c" + c + "\n");
},
void loop() {

if (bluetooth.find("c")) {
red = bluetooth.parseInt();
green = bluetooth.parseInt();
blue = bluetooth.parseInt();
showColor(red, green, blue);
}
}
Bluetooth Low Energy Lock
BluetoothSerial Plugin
Bluetooth Classic for Android
Bluetooth LE for iOS
List or discover devices
Connect to a peripheral
Write to send data
Subscribe to read data
http://rfduino.com
RFduino Cordova Plugin
https://github.com/don/corodva-plugin-rfduino
rfduino.discover(seconds, success, failure);

{
"name": "RFduino",
"uuid": "BD922605-1B07-4D55-8D09-B66653E51BBA",
"advertising": "echo",
"rssi": -79
}
rfduino.connect(uuid, success, failure);
rfduino.write("hello", success, failure);
rfduino.onData(success, failure);
var onData = function(arrayBuffer) {
var a = new Float32Array(arrayBuffer);
celsius = a[0];
fahrenheit = celsius * 1.8 + 32;
}
RFduino Plugin
Bluetooth LE for iOS and Android
Discover devices
Connect to a peripheral
Write to send data
Subscribe to read data
Future

You might also like