Arduino Firmata implementation on BLE (Bluetooth Low Energy) and Node.js.
- Firmata is a protocol to controll Arduino from software on PC.
- You can embed Arduino code into Node.js application.
- supports BlendMicro.
- also should works on BLE Shield, but I dont't have it.
sites
% npm install ble-firmata
- BlendMicro
- you have to check pin function. pin 4/6/7 are reserved for BLE controll.
- Install patched Standard Firmata v2.3 to BlendMicro
- fix
#define BLE_NAME "BlendMicro"
if you need. - download zip
- fix
Connect
var BLEFirmata = require('ble-firmata');
var arduino = new BLEFirmata();
// search device with BLE peripheral name
arduino.connect("BlendMicro");
// search with default name "BlendMicro"
arduino.connect();
arduino.on('connect', function(){
console.log("board version"+arduino.boardVersion);
// your-code-here
});
Reset
arduino.reset(callback);
Close
arduino.close(callback);
Digital Write
arduino.digitalWrite(13, true, callback);
arduino.digitalWrite(13, false, callback);
Digital Read
arduino.pinMode(1, BLEFirmata.INPUT);
console.log( arduino.digitalRead(1) ); // => true/false
Digital Read (event)
arduino.pinMode(1, BLEFirmata.INPUT);
arduino.on('digitalChange', function(e){
console.log("pin" + e.pin + " : " + e.old_value + " -> " + e.value);
});
Analog Write (PWM)
setInterval(function(){
var an = Math.random()*255; // 0 ~ 255
arduino.analogWrite(9, an, callback);
}, 100);
Analog Read
console.log( arduino.analogRead(0) ); // => 0 ~ 1023
Analog Read (event)
arduino.on('analogChange', function(e){
console.log("pin" + e.pin + " : " + e.old_value + " -> " + e.value);
});
Servo Motor
setInterval(function(){
var angle = Math.random()*180; // 0 ~ 180
arduino.servoWrite(11, angle, callback);
}, 1000);
- http://firmata.org/wiki/V2.1ProtocolDetails#Sysex_Message_Format
- https://github.com/shokai/ble-arduino-firmata/tree/master/samples/sysex
Send
arduino.sysex(0x01, [13, 5, 2], callback); // command, data_array, callback
Register Sysex Event
arduino.on('sysex', function(e){
console.log("command : " + e.command);
console.log(e.data);
});
set DEBUG
env var
% DEBUG=ble-firmata node samples/analog_write.js
% DEBUG=*ble* node samples/analog_write.js
% npm install
% npm test
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request