/raspi

Base functionality for working with a Raspberry Pi from Node.js

Primary LanguageTypeScriptMIT LicenseMIT

Raspi.js

Gitter

Raspi.js provides initialization and base support for the Raspberry Pi. This module, along with Raspi Board and Raspi Peripheral, provide support for various peripherals on the Raspberry Pi. These libraries form the basis for Raspi IO, an IO plugin that adds support for the Raspberry Pi to Johnny-Five.

Check out the following peripheral API modules:

If you have a bug report, feature request, or wish to contribute code, please be sure to check out the Raspi IO Contributing Guide.

System Requirements

  • Raspberry Pi Model B Rev 1 or newer (sorry Model A users)
  • Raspbian Jessie or newer
  • Node 4.0.0 or newer

Detailed instructions for getting a Raspberry Pi ready for NodeBots, including how to install Node.js, can be found in the wiki

Warning: when using this module, it MUST be installed with user-level permissions, but run with root permissions (e.g. sudo node index.js).

Installation

Install with npm:

npm install raspi

Note: this project is written in TypeScript and includes type definitions in the package.json file. This means that if you want to use it from TypeScript, you don't need to install a separate @types module.

Example Usage

In TypeScript/ES6:

import { init } from 'raspi';
import { DigitalInput, DigitalOutput } from 'raspi-gpio';

init(() => {
  const input = new DigitalInput('P1-3');
  const output = new DigitalOutput('P1-5');
  output.write(input.read());
});

in JavaScript:

const raspi = require('raspi');
const gpio = require('raspi-gpio');

raspi.init(() => {
  const input = new gpio.DigitalInput('P1-3');
  const output = new gpio.DigitalOutput('P1-5');
  output.write(input.read());
});

API

Module Constants

Constant Description
module An easily consumable object for indirectly passing this module around. Intended specifically for use by Core IO (details coming soon)
Property Type Description
init Alias of the init method

init(cb)

The init method initializes the library suite. This method MUST be called before using any peripherals.

Arguments:

Argument Type Description
cb Function Callback to be called once the board has been initialized. Takes no arguments
Takes no arguments

Returns: None

License

The MIT License (MIT)

Copyright (c) 2014-2017 Bryan Hughes bryan@nebri.us

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.