npm.io
1.0.2 • Published 9 years ago

orange-pi-gpio

Licence
ISC
Version
1.0.2
Deps
0
Vulns
0
Weekly
0
Stars
15

orange-pi-gpio

This module allows you to easily manage GPIO pins on your Orange PI PC using Node.js

Before Install

You need to make sure that WiringOP is installed on your Orange PI PC. If not, then you need to install it. To do this, run the following commands:

git clone https://github.com/zhaolei/WiringOP.git -b h3

cd WiringOP
chmod +x ./build
sudo ./build

Install Module##

npm i orange-pi-gpio

Usage

Blink app

const Gpio = require('orange-pi-gpio');

let gpio5 = new Gpio({pin:5, mode: 'out', ready: ()=>{
    let value = 1;

    setInterval(function() {
        process.stdout.write('\x1B[2J\x1B[0f\u001b[0;0H');

        if(value){
            console.log('\x1b[32m%s\x1b[0m', `ON`);
        } else {
            console.log('\x1b[31m%s\x1b[0m', `OFF`);
        }
        
        gpio5.write(value);
        value = +!value;
    }, 50);

}});

Methods

read

const Gpio = require('orange-pi-gpio');

let gpio5 = new Gpio({pin:5});

gpio5.read()
    .then((state)=>{
        console.log(state); //state of pin 5
    });

write

const Gpio = require('orange-pi-gpio');

let gpio5 = new Gpio({pin:5});

gpio5.write(1); // write 1 to pin 5
gpio5.write(0); // write 0 to pin 5