Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Raspberry Pi IO Plugin for Johnny-Five

License

NotificationsYou must be signed in to change notification settings

fivdi/pi-io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A proof of concept to demonstrate that it's feasible to implement a RaspberryPi IO Plugin for Johnny-Five usingLinux-IO.

Tested on a Raspberry Pi 4 Model B with Node.js v16.0.0. Should function withNode.js v10 or higher.

Installation

Step 1 - Install the pigpio C library

Thepigpio C library is a prerequisitefor pi-io.

Run the following command to determine which version of the pigpio C libraryis installed:

pigpiod -v

For the Raspberry Pi Zero, 1, 2 and 3 V41 or higher of the pigpio C library isrequired. For the Raspberry Pi 4 V69 or higher is required.

If the pigpio C library is not installed or if the installed version is tooold, the latest version can be installed with the following commands:

sudo apt-get updatesudo apt-get install pigpio

Alternative installation instructions for the pigpio C library can be foundhere.

Warning: The pigpio C library contains a number of utilities. One of theseutilities is pigpiod which launches the pigpio C library as a daemon. Thisutility should not be used as the pi-io uses the pigpio C library directly.

Step 2 - Install the pi-io Node.js package

npm install pi-io

Johnny-Five Features Supported

FeatureSupport
Analog Readno
Digital Readyes
Digital Writeyes
PWMyes
Servoyes
I2Cyes
One Wireno
Stepperno
Serial/UARTno
DACno
Pingyes*)

*) Ping was tested with three HC-SR04 proximity sensors with varying degreesof success. One sensor functioned as expected. The second didn't timeout asit should but it's was possible to workaround the issue with software. Thethird sensor didn't function. The issues may be related to the fact that asingle pin is used for both trigger and echo.

To workaround these issues a controller was implemented that allows separatepins to be used for trigger and echo. The same three HC-SR04 proximity sensorsfunctioned well with this controller.

Supported Pins

Pin IDSupported ModesComments
P1-3 or GPIO2INPUT, OUTPUT, PWM, SERVOAlternatively I2C SDA1
P1-5 or GPIO3INPUT, OUTPUT, PWM, SERVOAlternatively I2C SCL1
P1-7 or GPIO4INPUT, OUTPUT, PWM, SERVO
P1-8 or GPIO14INPUT, OUTPUT, PWM, SERVO
P1-10 or GPIO15INPUT, OUTPUT, PWM, SERVO
P1-11 or GPIO17INPUT, OUTPUT, PWM, SERVO
P1-12 or GPIO18INPUT, OUTPUT, PWM, SERVO
P1-13 or GPIO27INPUT, OUTPUT, PWM, SERVO
P1-15 or GPIO22INPUT, OUTPUT, PWM, SERVO
P1-16 or GPIO23INPUT, OUTPUT, PWM, SERVO
P1-18 or GPIO24INPUT, OUTPUT, PWM, SERVO
P1-19 or GPIO10INPUT, OUTPUT, PWM, SERVO
P1-21 or GPIO9INPUT, OUTPUT, PWM, SERVO
P1-22 or GPIO25INPUT, OUTPUT, PWM, SERVO
P1-23 or GPIO11INPUT, OUTPUT, PWM, SERVO
P1-24 or GPIO8INPUT, OUTPUT, PWM, SERVO
P1-26 or GPIO7INPUT, OUTPUT, PWM, SERVO
P1-29 or GPIO5INPUT, OUTPUT, PWM, SERVO
P1-31 or GPIO6INPUT, OUTPUT, PWM, SERVO
P1-32 or GPIO12INPUT, OUTPUT, PWM, SERVO
P1-33 or GPIO13INPUT, OUTPUT, PWM, SERVO
P1-35 or GPIO19INPUT, OUTPUT, PWM, SERVO
P1-36 or GPIO16INPUT, OUTPUT, PWM, SERVO
P1-37 or GPIO26INPUT, OUTPUT, PWM, SERVO
P1-38 or GPIO20INPUT, OUTPUT, PWM, SERVO
P1-40 or GPIO21INPUT, OUTPUT, PWM, SERVO
LED0OUTPUTBuilt-in LED

Usage

Pluse an LED connected to GPIO17

varfive=require('johnny-five');varPiIO=require('pi-io');varboard=newfive.Board({io:newPiIO()});board.on('ready',function(){varled=newfive.Led('GPIO17');led.pulse(1000);});

Rotate a continuous servo connected to GPIO27 clockwise

varfive=require('johnny-five');varPiIO=require('pi-io');varboard=newfive.Board({io:newPiIO()});board.on('ready',function(){varservo=newfive.Servo({pin:'GPIO27',type:"continuous"});servo.cw(0.8);});

Measure proximity with a HC-SR04 using separate pins for trigger and echo

varfive=require('johnny-five');varPiIO=require('pi-io');varboard=newfive.Board({io:newPiIO()});board.on('ready',function(){varproximity=newfive.Proximity({controller:PiIO.HCSR04,// Custom controllertriggerPin:'GPIO23',echoPin:'GPIO24'});proximity.on("change",function(){console.log("cm: ",this.cm);});});

Measure proximity with a HC-SR04 connected to GPIO25

Note that this circuit uses a single pin for trigger and echo. Whether or notthis functions correctly appears to be highly dependent on the particularHC-SR04 sensor being used. The circuit shown above that uses separate pins fortrigger and echo is far more reliable.

varfive=require('johnny-five');varPiIO=require('pi-io');varboard=newfive.Board({io:newPiIO()});board.on('ready',function(){varproximity=newfive.Proximity({controller:'HCSR04',pin:'GPIO25'});proximity.on("data",function(){console.log("cm: ",this.cm);});});

Examples

Additional examples can be found in theexample directory.

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp