Git Product home page Git Product logo

raspi's Introduction

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 [email protected]

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.

raspi's People

Contributors

nebrius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raspi's Issues

Can't install on Windows

Unfortunately the yarn add fails for me on Windows:

error [email protected]: The CPU architecture "x64" is incompatible with this module. error An unexpected error occurred: "Found incompatible module".

Would it be possible to still allow install on Windows and run in "mock" mode?
This would it make easier to develop for RPI.

Or am I doing something wrong?

ERROR: could not insert 'i2c_dev': Operation not permitted

Hello,

I'm trying raspi-io for the first time and am trying to run the "blink a led" script from the readme.

Here is the script that I'm using:

var raspi = require('raspi-io');
var five = require('johnny-five');
var board = new five.Board({
  io: new raspi()
});

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

  // Create an Led on pin 7 (GPIO4) on P1 and strobe it on/off
  // Optionally set the speed; defaults to 100ms
  (new five.Led('GPIO18')).strobe();

});

When I run the script, I'm seeing the following error:

node j5_test_pi.js 
ERROR: could not insert 'i2c_dev': Operation not permitted
child_process.js:1382
    throw err;
          ^
Error: Command failed: modprobe i2c-dev
ERROR: could not insert 'i2c_dev': Operation not permitted

    at checkExecSyncError (child_process.js:1339:13)
    at execSync (child_process.js:1379:13)
    at new I2C (/home/pi/evcc/node_modules/raspi-io/node_modules/raspi-i2c/lib/index.js:115:5)
    at /home/pi/evcc/node_modules/raspi-io/lib/index.js:150:16
    at new Raspi (/home/pi/evcc/node_modules/raspi-io/lib/index.js:185:7)
    at Object.<anonymous> (/home/pi/evcc/j5_test_pi.js:4:7)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

It looks like the error happens on the line with new raspi().

I then noticed that the output from npm install raspi-io had these lines:

> [email protected] install /home/pi/evcc/node_modules/raspi-io/node_modules/raspi-i2c/node_modules/execSync
> node install.js

[execsync v1.0.2] Attempting to compile native extensions.
[execSync v1.0.2]
    Native code compile failed!!

Have I hosed my installation of raspi-io?

My setup is a Raspberry Pi 2 Model B v1.1, with node v0.12.0, [email protected], and [email protected] installed. I also tried [email protected] and got a similar result.

Jessie and node 4.2.1 ?

Hi,
I've just tried installing raspi, however it failed on npm install.

Could there be an incompatibility with Jessie and node 4.2.1 ?

Cheers

raspi doesn't work consistently

I'm using raspi to control a motor but the module doesn't always connect to the motor.
I've made a test script which runs perfectly every time, but when I implement the code on server it doesn't always connect
Test script that works everytime

const raspi = require('raspi');
const PWM = require('raspi-pwm').PWM;
let speed = 9 ;
if(process.argv[2] ){
    speed = Number(process.argv[2])
    console.log('Speed ',speed);
    raspi.init(() => {
      let pin2 = 'GPIO13';
      const pwm2 = new PWM(pin2);
      pwm2.write(speed); // Center a servo
      console.log('speed On GPIO13 : ',speed);
    });
}else{
  console.log('fail')
}

server code

const raspi = require('raspi');
const PWM = require('raspi-pwm').PWM;
let pwm12,pwm13,pwm18;
let self = {
    init: () =>{
        raspi.init(() => {
            pwm12 = new PWM('GPIO12');
            pwm13 = new PWM('GPIO13');
            pwm18 = new PWM('GPIO18');
            self.motorsArr.push(pwm13);            
            self.motorsArr.push(pwm12);
            self.motorsArr.push(pwm18);
            console.log(self.motorsArr[1]);
        });}
    throttle: (dutyCycle) {
        pwm13.write(dutyCycle);
}
}

Sometimes though it works after closing and reopening the terminal

Installation directory depreciated

When trying to install under the latest Raspbian, the installation aborts with the following output. It seems that the installation script needs tweaking.

npm install raspi
(node:15138) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
npm WARN install Refusing to install raspi as a dependency of itself

Precompile binaries

We should ship precompiled binaries of raspi-core, and all other raspi modules with C++. Only one architecture is being targeted, obviously, so it doesn't make sense to recompile at install time.

"compilation terminated" on Raspbian Raspberry Pi Zero

node -v: v6.9.4

pi@K-pi:~/repos/K-pi/johnny-five-lifx $ npm install [email protected]

> [email protected] install /home/pi/repos/K-pi/johnny-five-lifx/node_modules/raspi
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
make: Entering directory '/home/pi/repos/K-pi/johnny-five-lifx/node_modules/raspi/build'
  CXX(target) Release/obj.target/addon/src-native/addon.o
  CXX(target) Release/obj.target/addon/src-native/init.o
../src-native/init.cc:25:22: fatal error: wiringPi.h: No such file or directory
 #include <wiringPi.h>
                      ^
compilation terminated.
addon.target.mk:93: recipe for target 'Release/obj.target/addon/src-native/init.o' failed
make: *** [Release/obj.target/addon/src-native/init.o] Error 1
make: Leaving directory '/home/pi/repos/K-pi/johnny-five-lifx/node_modules/raspi/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/pi/.nvm/versions/node/v6.9.4/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Linux 4.4.34+
gyp ERR! command "/home/pi/.nvm/versions/node/v6.9.4/bin/node" "/home/pi/.nvm/versions/node/v6.9.4/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/repos/K-pi/johnny-five-lifx/node_modules/raspi
gyp ERR! node -v v6.9.4
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! Linux 4.4.34+
npm ERR! argv "/home/pi/.nvm/versions/node/v6.9.4/bin/node" "/home/pi/.nvm/versions/node/v6.9.4/bin/npm" "install" "[email protected]"
npm ERR! node v6.9.4
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the raspi package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs raspi
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls raspi
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/pi/repos/K-pi/johnny-five-lifx/npm-debug.log

RASPI-GPIO Can't read from output

I am using raspi-gpio in a device control application. I have a digital output line that drives a relay, but I also want to read the current state of the output line to drive a status indicator. If I define the pin as an output, raspi-gpio can't read the state of the pin. If I set it up as an input, I can't write to change the output.

My interface allow multiple connections, so I don't want to simply set a value and keep track of it for status display. I also need to be able to read the state to know that another operator has changed the value.

Is there a reason why I can't read an output value? Am I missing something in the interface that will allow me to do this?

Bob Segrest

Error: Cannot find module 'raspi'

Im using raspberry 2 B+ with last version of raspbian.
node -v => v7.6.0
npm -v =>4.1.2

Problem was that from the repo I cannot install node higher than v0.10 so I just dowloaded the bin from the file, overwrite and fixed the soft link in the bin folder. So far it worked like a charm : )

this is what I get when I install the package:

pi@pegsPi:~/web $ sudo npm install -g raspi

[email protected] install /opt/nodejs/lib/node_modules/raspi
node-gyp rebuild

gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/7.6.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/opt/nodejs/lib/node_modules/raspi/.node-gyp"
make: Entering directory '/opt/nodejs/lib/node_modules/raspi/build'
CXX(target) Release/obj.target/addon/src-native/addon.o
CXX(target) Release/obj.target/addon/src-native/init.o
SOLINK_MODULE(target) Release/obj.target/addon.node
COPY Release/addon.node
make: Leaving directory '/opt/nodejs/lib/node_modules/raspi/build'
/opt/nodejs/lib
└── [email protected]

this is the relevant part of my main.js

var express = require('express');
var app = express();

var server = require('http').Server(app);
var io = require('socket.io')(server);

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

and this is the outcome when I start

nodemon server/main.js

[nodemon] 1.11.0
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node server/main.js
module.js:472
throw err;
^

Error: Cannot find module 'raspi'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object. (/home/pi/web/server/main.js:7:15)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
[nodemon] app crashed - waiting for file changes before starting...

I'm new to node so it could be any stupid thing...

What would be the best way to initialize raspi

I am trying to build a module based on raspi (to make a simple beep) that will be embedded into a bigger project. Here is the module's code:

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

var Scanner = function() {
    var self = this;
    raspi.init(function() {
        self.buzzer = new gpio.DigitalOutput('P1-32');
    });
};

Scanner.prototype.beep = function() {
    var self = this;
    self.buzzer.write(gpio.HIGH);
    setTimeout(function() {
        self.buzzer.write(gpio.LOW);
    }, 20);
};

module.exports = exports = Scanner;

and I am using it in a bigger project as

var Scanner = require('./scanner');
var scanner = new Scanner();

scanner.beep();

but it throws me an error stating that 'buzzer' is not defined. I guess it is because constructor returns before raspi initialization is complete, so the beep() function is invalid. I tried to set a timeout before using beep():

var Scanner = new require('./scanner');
var scanner = new Scanner();

setTimeout(function(){
    scanner.beep();
}, 1000);

and it works... but I was wondering if there exist a better way to do it without timeout.

I read a few discussions about asynchronous constructors that propose constructor to accept a callback to be called when all initialization is complete. Would this be the right way?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.