A Node.js library enabling the use of various Phidgets interface boards.
Phidget boards are a great prototyping tool which can handle digital inputs and outputs, along with a great array of analog sensors (RFID, temperature, distance, etc.). Node.js and io.js are fantastic networking library which makes it easy to create fast networked applications. This project aims to make it simple for them to interact. Synergy!
The API in version 0.5.0 and above has changed and is not backwards-compatible. We had to make this change in order to support more than just the PhidgetInterfaceKit boards. An archived copy of version 0.4.0 is being kept around for those needing to maintain older projects.
This project assumes you have the Phidget WebService up and running. For "regular" (USB) Phidget boards, this simply means that the computer you are connecting to has got the webservice installed and started.
For stand-alone Phidget Single Board Computers (phidgetsbc), this assumes you have configured the server via the web portal. Since you will be connecting to the Phidget server via TCP, be sure you can access the server from the machine running this project.
This library can interface with multiple phidget boards connected to a single computer via the Phidget WebService.
If you already have Node.js installed, you also have npm installed. This means you can
install the phidgets package with:
npm install phidgets.
Phidgets Inc. makes a line of phidget boards which are themselves small ARM Debian computers. It it possble to run Node.js on them, and use this package locally. Here's a gist with the steps and a blog post about how to get this up and running.
The most common way to interact with a phidgets board is to set up listeners for the whatever you are interested in. For example, this code will log to the console all changes detected on the analog sensor inputs of the device:
var phidgets = require'phidgets';var pik = ;pikon'sensor'console.log'Sensor: ' + dataindex + ', value: ' + datavalue;;pikopen;
Obviously, many other events are available. The exact events vary with the device type. As
an example, here are the events specific to
The following events are common to all phidgets:
Since all relevant functions are chainable, the above example can be written more concisely:
var phidgets = require'phidgets';var pik =on'input'console.log'Digital input: ' + dataindex + ', value: ' + datavalue;open;
When no parameters are passed to the
open() method, the first matching device on the
local machine is used. If you have multiple devices connected, you can connect to a
specific one by passing its serial number or label (as defined in the Phidget WebService
control panel). You can also, if necessary, specify a password:
pikopenserial: 123456label: "mydevice"password: "abc";
If you need, you can connect to devices on another machine:
pikopenhost: "220.127.116.11"port: 5001;
As illustrated above, you can retrieve data by adding the appropriate listeners
'sensor', etc.). You can also, at any time, manually check the status of any
inputs, sensors or outputs. Depending on the type of board you are using, all of these
will or will not be available. For example, on a
PhidgetLED board, there are no inputs
or sensors. However, you can still read the state of all LEDS by looking at the
PhidgetLED.leds object. This object will look like this:
0: 01: 672: 03: 13// etc.count: 64 // The total number of LEDs (as reported by the board)
For example, if you wanted to periodically check the status of an analog sensor hooked up
to port 3 of a
PhidgetInterfaceKit, you could to the following:
var phidgets = require'phidgets';var pik =on'opened'setIntervalconsole.log"Sensor 3:" + piksensors3value;1000;open;
outputs object is meant to be read-only. If you want to change the value of an
output, use the relevant method. For example, to change an output on a
PhidgetInterfaceKit, you would use the
PhidgetInterfaceKit.setOutput() method. To do
the same on a
PhidgetLED, you would use
Currently, all interface kit boards are supported through the
object. This includes boards such as:
Also included in the library is full support for the following boards:
Other boards will be added in the future. Help from contributors is always welcomed. Addding support for a specific board is relatively straightforward. If you are in a hurry, and can support the development effort, please contact one of the project contributors.
If this primer wasn't enough, the full API documentation is available for download in the docs folder. You can also view it online.