A small node toolkit for raspi modules like sensors, relays etc.
This toolkit does make use of https://github.com/jperkin/node-rpio
npm install garlian/raspi-node-toolkit
npm install rpio
- Get the name or type of your module e.g. HY-SRF05 (Ultra Sonic Sensor)
- Use the instance of the class (classname is always capital letter no special chars: HYSRF05), check constructor for needed params (mostly gpio pin)
- Happy tinker :D
Use this list to check if your module is supported, this list will grow over time.
- HY-SRF05 (Distance)
// Sonic Sensor usage:
const hysrf05 = new HYSRF05(
{
trig:19,
echo:26
},
(sensor:any) => {
console.log(sensor.distance + 'cm');
}
);
hysrf05.start();
- HC-SR501 (Motion)
// Using infrared motion sensor
const hcsr501 = new HCSR501(19);
hcsr501.read((movementDetected:boolean, seconds:number) => {
if (movementDetected) {
console.log('No movement ' + seconds + 's');
} else {
console.log('Moved for ' + seconds + 's');
}
});
- JQC-3FF (Relay)
// Turn relay on/off each second
const jqc3ff = new JQC3FF(21);
while(true) {
jqc3ff.open();
console.log('Open');
rpio.msleep(1000);
jqc3ff.close();
console.log('Close');
rpio.msleep(1000);
}
- Improving overall code quality
- Adding more libraries
- Improving usability due to rpio only being installable on a pi