0.0.4 • Published 8 years ago

nodepi v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

nodepi

A lightweight node javascript library for interacting with the GPIO of a raspberry PI.

Models Supported*

  • Raspberry PI 2 Model B

*While other models are not officially supported, any devices using sysfs at /sys/class/gpio/ for their GPIO may still work with physical mapping turned off.

How to Install

npm install nodepi

How to Use

var NodePI = require("nodepi");

NodePI by default uses a physical pin mapping. This means you can use the physical numbering system as defined here: https://www.raspberrypi.org/documentation/usage/gpio/ However, if you wish, you can use raw GPIO values instead by turning physical mapping off.

NodePI.usePhysicalPins(false);

Constants

NodePI has 4 constants, IN and OUT for pin direction, and HIGH and LOW for pin values. They are all on the NodePI object.

Methods

The following methods are available.

void enablePin(Number pin, Boolean, enabled, Function callback)

Callback Signature: callback(Error err)

Enables or disables a pin.

Boolean isPinEnabled(Number pin)

Returns true if the given pin is enabled.

void setPinDirection(Number Pin, NodePI.IN || NodePI.OUT, Function callback)

Callback Signature: callback(Error err)

Sets the direction of the pin. Pin directions can either be NodePI.IN, in which case you can read incoming voltage by reading their pin value (See getPinValue). If direction is NodePI.OUT, then you can set the pin voltage to LOW or HIGH. See setPinValue for more information.

void getPinDirection(Number Pin, Function callback)

Callback Signature: callback(Error err, NodePI.IN || NodePI.OUT);

Gets the current pin direction. It can either be NodePI.IN, or NodePI.out.

void setPinValue(Number Pin, NodePI.LOW || NodePI.HIGH, Function callback)

Callback Signature: callback(Error err)

Sets the pin value to either LOW or HIGH. Only pins with the OUT direction can be set. If value is LOW, then the pin will output 0 volts. If value is HIGH, then the pin will output volts, (typically 3.3v on most devices).

void getPinValue(Number Pin, Function callback)

Callback Signature: callback(Error err, NodePI.LOW || NodePI.HIGH)

Gets the pin value. Pin value can either be NodePI.LOW or NodePI.HIGH.

Pulse-Width Module

Pulse-Width Modulation is not yet supported by this library.

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

9 years ago

0.0.1

9 years ago