• Stars
    star
    173
  • Rank 220,124 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Particle/Spark Core/Photon IO Plugin for Johnny-Five

Particle-io

Build Status

Particle-io is a Firmata-compatibility IO class for writing node programs that interact with Particle devices (formerly Spark). Particle-io was built at Bocoup

Getting Started

In order to use the particle-io library, you will need to load the special voodoospark firmware onto your device. We recommend you review VoodooSpark's Getting Started before continuing. There is also a screencast of how to get started: Get Your Motor Running: Particle Photon and Johnny Five.

We also recommend storing your Particle token and device ID in a dot file so they can be accessed as properties of process.env. Create a file in your home directory called .particlerc that contains:

export PARTICLE_TOKEN="your particle token"
export PARTICLE_DEVICE_ID="your device id"

Then add the following to your dot-rc file of choice:

source ~/.particlerc

Ensure your host computer (where you're running your Node.js application) and the Particle are on the same local network.

Blink an Led

The "Hello World" of microcontroller programming:

var Particle = require("particle-io");
var board = new Particle({
  token: process.env.PARTICLE_TOKEN,
  deviceId: process.env.PARTICLE_DEVICE_ID
});

board.on("ready", function() {
  console.log("Device Ready..");
  this.pinMode("D7", this.MODES.OUTPUT);

  var byte = 0;

  // This will "blink" the on board led
  setInterval(function() {
    this.digitalWrite("D7", (byte ^= 1));
  }.bind(this), 500);
});

Troubleshooting

If your board is connecting, but the board.on("ready", ...) event is not occuring, ensure the wifi network you are connected to allows for direct TCP client/server sockets (this form of communication is often blocked by public wifi networks).

Johnny-Five IO Plugin

Particle-io can be used as an IO Plugin for Johnny-Five:

var five = require("johnny-five");
var Particle = require("particle-io");
var board = new five.Board({
  io: new Particle({
    token: process.env.PARTICLE_TOKEN,
    deviceId: process.env.PARTICLE_DEVICE_ID
  })
});

board.on("ready", function() {
  console.log("Device Ready..");
  var led = new five.Led("D7");
  led.blink();
});

See the above Troubleshooting section if your board is connecting, but the board.on("ready", ...) event is not occuring.

API

Constructor The Particle component can be connected using one of three mechanisms: deviceId, deviceName, or host/port. Both deviceId and deviceName require an additional token so that the host and port of the device can be retrieved from the Particle cloud.

Example:

var Particle = require("particle-io");

var byId = new Particle({
  token: process.env.PARTICLE_TOKEN,
  deviceId: process.env.PARTICLE_DEVICE_ID
});

var byName = new Particle({
  token: process.env.PARTICLE_TOKEN,
  deviceName: process.env.PARTICLE_DEVICE_NAME || "crazy_pickle"
});

var byIp = new Particle({
  host: '192.168.0.111',
  port: 48879
});

device properties You can get the information that the component knows about the chip with some read-only device properties. This is useful for retrieving the IP address of the Particle so that you can swith over to host/port mode if necessary.

The available properties are:

  • deviceId: The ID of the device
  • deviceName: The name of the device
  • deviceIp: The IP address of the device on the local network
  • devicePort: The port the device is listening on for connections

Example:

var Particle = require("particle-io");

var board = new Particle({
  token: process.env.PARTICLE_TOKEN,
  deviceName: process.env.PARTICLE_DEVICE_Name || "crazy_pickle"
});

board.on("ready", function() {
  console.log(
    "Connected to " + board.deviceName + 
    " (" + board.deviceId + ") " +
    "at " + board.deviceIp + ":" + board.devicePort
  );
});

MODES

The MODES property is available as a Particle instance property:

var board = new Particle(...);
board.MODES;
  • INPUT: 0
  • OUTPUT: 1
  • ANALOG: 2
  • PWM: 3
  • SERVO: 4

pinMode(pin, MODE)

Set a pin's mode to any one of the MODES.

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Set digital pin 7 to OUTPUT:
  this.pinMode("D7", this.MODES.OUTPUT);

  // or just use the integer:
  this.pinMode("D7", 1);

});

PWM Support (Servo support is also limited to these pins):

  • Core pins: A0, A1, A4, A5, A6, A7, D0, D1.
  • Photon pins: A4, A5, D0, D1, D2, D3
  • P1 pins: A4, A5, D0, D1, D2, D3

digitalWrite(pin, value)

Sets the pin to 1 or 0, which either connects it to 3.3V (the maximum voltage of the system) or to GND (ground).

Example:

var board = new Particle(...);

board.on("ready", function() {

  // This will turn ON the on-board LED
  this.digitalWrite("D7", 1);

  // OR...

  // This will turn OFF the on-board LED
  this.digitalWrite("D7", 0);

});

analogWrite(pin, value)

Sets the pin to an 8-bit value between 0 and 255, where 0 is the same as LOW and 255 is the same as HIGH. This is sort of like sending a voltage between 0 and 3.3V, but since this is a digital system, it uses a mechanism called Pulse Width Modulation, or PWM. You could use analogWrite to dim an LED, as an example. PWM is available on D0, D1, A0, A1, A4, A5, A6 and A7.

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Set an LED to full brightness
  this.analogWrite("A7", 255);

  // OR...

  // Set an LED to half brightness
  this.analogWrite("A7", 128);

});

servoWrite(pin, value)

Sets the pin to a value between 0 and 180, where the value represents degrees of the servo horn. The value is converted to a PWM signal. PWM is available on D0, D1, A0, A1, A4, A5, A6 and A7.

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Move a servo to 90 degrees
  this.servoWrite("D0", 90);

});

digitalRead(pin, handler) Setup a continuous read handler for specific digital pin (D0-D7).

This will read the digital value of a pin, which can be read as either HIGH or LOW. If you were to connect the pin to a 3.3V source, it would read HIGH (1); if you connect it to GND, it would read LOW (0).

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Log all the readings for D1
  this.digitalRead("D1", function(data) {
    console.log(data);
  });

});

analogRead(pin, handler) Setup a continuous read handler for specific analog pin (A0-A7). Use with all analog sensors

Example:

var board = new Particle(...);

board.on("ready", function() {

  // Log all the readings for A1
  this.analogRead("A1", function(data) {
    console.log(data);
  });

});

License

See LICENSE file.

More Repositories

1

idiomatic.js

Principles of Writing Consistent, Idiomatic JavaScript
23,134
star
2

johnny-five

JavaScript Robotics and IoT programming framework, developed at Bocoup.
JavaScript
13,283
star
3

tc39-notes

TC39 Meeting Notes
JavaScript
587
star
4

jquery-hive

jQuery Plugin for creating and managing web workers across implementations. Includes Hive.Pollen.js - the thread-safe utility library for connecting worker threads to the Hive.
JavaScript
203
star
5

jquery.eventsource

Harnessing the EventSource API with jQuery
JavaScript
186
star
6

dmv

JavaScript
118
star
7

io-plugins

Documentation and discussion point for IO Plugins
117
star
8

galileo-io

Intel Galileo & Intel Edison IO Plugin for Johnny-Five
JavaScript
101
star
9

temporal

Non-blocking, temporal task sequencing. For use with robots built with Johnny-Five
JavaScript
84
star
10

javascript-robotics

JavaScript
71
star
11

grunt-compare-size

JavaScript
62
star
12

proposal-math-extensions

ES Math Extensions
HTML
58
star
13

popcorn.capture

capture any frame from your popcorn video instance and save as png
JavaScript
57
star
14

tessel-io

A Tessel 2 IO Plugin for Johnny-Five JavaScript Robotics programs
JavaScript
50
star
15

proposal-enum-definitions

47
star
16

fritzing-components

Custom Fritzing parts
42
star
17

fact

JavaScript
38
star
18

popcorn.sequence

JavaScript
36
star
19

mediagroup.js

JavaScript
28
star
20

etherport

EtherPort is a transport layer
JavaScript
23
star
21

navigator.getusermedia

JavaScript
22
star
22

popcorn.kernel

JavaScript
20
star
23

playground-io

Adafruit Circuit Playground IO Plugin for Johnny-Five
JavaScript
15
star
24

nodebot-sbc

NodeBots SBC
14
star
25

rwaldron

JavaScript
14
star
26

esp-io

ESP-IO is an IO Plugin that enables writing JavaScript Robotics programs with Johnny-Five, which interact with ESP8266 boards.
13
star
27

imp-io

Electric Imp IO Plugin for Johnny-Five
JavaScript
12
star
28

arduino-adc-io-expander

Turn any Arduino into an ADC IO Expander with an I2C interface.
Arduino
12
star
29

mock-firmata

Mocks used for testing code that depends on Firmata
JavaScript
11
star
30

compulsive

loops and delays without traditional timers
JavaScript
11
star
31

bro

whats up bro
10
star
32

jquery-mobile-badge

JavaScript
10
star
33

subjectisdead

Haskell
9
star
34

popcorn.embedly

JavaScript
9
star
35

edison-io

Intel Edison & Intel Galileo IO Plugin for Johnny-Five
JavaScript
9
star
36

j5-ds-touch

A DS Touch Screen component plugin for Johnny-Five
JavaScript
9
star
37

idiomatic.json

8
star
38

tyrion

Agent/Device Firmware Pair for Electric Imp. Use with Imp-IO for Johnny-Five
Squirrel
8
star
39

butter

JavaScript
8
star
40

unprefix.js

JavaScript
8
star
41

j5-rc-receiver

RC Receiver component plugin for Johnny-Five
JavaScript
8
star
42

chromakey

html5 video chromakey
JavaScript
8
star
43

nino-io

Linino One & Arduino Yun IO Plugin for Johnny-Five
JavaScript
8
star
44

adventure

JavaScript
7
star
45

burst-core

First pass at re-writing the animation core of The Burst Engine for generic JS Object timeline control.
JavaScript
6
star
46

pee-wee-rover

JSConf 2015 JavaScript Robotics Project Files
JavaScript
5
star
47

node-jsdev

JavaScript
5
star
48

jQuery.Mines

Publisher/Subscriber system with expressive and flexible control - and a cool metaphor.
JavaScript
5
star
49

tiny-query

JavaScript
5
star
50

tinyquery

JavaScript
4
star
51

polyfill

JavaScript polyfill functions
JavaScript
4
star
52

EventSource

THIS IS NOT A RELEASE
JavaScript
4
star
53

avrdude

Arduino-specific version of avrdude
C
3
star
54

jquery-classlist

JavaScript
3
star
55

snippets.js

tab triggered js code snippets... everywhere!
JavaScript
3
star
56

i2c-backpack-workshop

3
star
57

sdactivity

JavaScript
3
star
58

sensors

Notes for Sensor API unification
3
star
59

espresso

Small JavaScript VM for Arduino Mega 2560
C
3
star
60

platoon

JavaScript
3
star
61

footils

For exercisin distributed development
JavaScript
3
star
62

nitwit

nitwit is a command line twitter status update program in python
3
star
63

reflecta-io

IO Plugin for controlling Arduino boards with Johnny-Five via Reflecta
JavaScript
3
star
64

popcorn.zoom

Popcorn plugin to zoom and rotate popcorn video objects
JavaScript
3
star
65

vox-populi-tests

2
star
66

sotu

JavaScript
2
star
67

pcduino-io

pcDuino IO Plugin for Johnny-Five
JavaScript
2
star
68

electron-io

Particle Electron IO Plugin for Johnny-Five
JavaScript
2
star
69

popcorn.create

JavaScript
2
star
70

j5-button-gestures

JavaScript
2
star
71

burst

A javascript vector animation engine for the HTML5 Canvas supporting SVGs, Blender3D objects, timelines, easing, command chanining and callbacks.
JavaScript
2
star
72

lemmy

49% Motherfucker | 51% Son of a Bitch Express + Mocha + HTML5 smart boilerplate for both Javascript and Coffee-Script that kicks your ass!!!
CoffeeScript
2
star
73

NXTI2CDevice

Patched version of NXTI2CDevice for use with Arduino 1.0+
C++
2
star
74

testharness.js

Test framework for writing javascript-based browser tests
JavaScript
1
star
75

cloudnine

hooking up with cloud9 beta
JavaScript
1
star
76

nodysentary.js

1
star
77

b9snvs0

1
star
78

taco

It's a tastier docco built with bootstrap.
CoffeeScript
1
star
79

blitz-node

Node.js API Client for Blitz
JavaScript
1
star
80

tubeyloops

JavaScript
1
star
81

cloudninetest

cloudninetest
JavaScript
1
star
82

popcorn.scene

JavaScript
1
star
83

t2-project

Build a project for deployment to a Tessel 2
JavaScript
1
star
84

animeiosis

JavaScript
1
star
85

junktown

1
star
86

tessel-include-bundling

JavaScript
1
star
87

sumobot

SumoBot class for Johnny-Five
JavaScript
1
star
88

junkbox

1
star
89

geniverse

JavaScript
1
star
90

duokey

JavaScript
1
star
91

webOS

webOS Related Projects.
JavaScript
1
star
92

ObjectLateral

Passing off objects since jqcon 2009
1
star
93

chrome-dev-snippets

JavaScript
1
star
94

scripty2-contrib

1
star
95

euler

JavaScript
1
star
96

tiny-jquery

Interview project
JavaScript
1
star
97

playback.js

JavaScript
1
star
98

Promise

An elegant promise implementation for Javascript
JavaScript
1
star
99

Rust.tmbundle-1

Rust Bundle for TextMate
1
star
100

Sublime-JSLint

Sublime Text Editor 2 JSLint Support
JavaScript
1
star