pi-fast-gpio
Advanced tools
Comparing version 0.0.1 to 0.1.0
24
index.js
@@ -75,2 +75,26 @@ var net = require('net'); | ||
/** | ||
* Starts (non-zero dutycycle) or stops (0) PWM pulses on the gpio. | ||
* | ||
* pi.set_PWM_dutycycle(4, 0) # PWM off | ||
* pi.set_PWM_dutycycle(4, 64) # PWM 1/4 on | ||
* pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on | ||
* pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on | ||
* pi.set_PWM_dutycycle(4, 255) # PWM full on | ||
* | ||
* @param {number} userGpio The number of the gpio to address. 0-31 | ||
* @param {number} dutycycle The pwm dutycycle to use. | ||
* 0 (off), | ||
* 255 (full on) | ||
*/ | ||
PiFastGpio.prototype.setPwmDutycycle = function(userGpio, dutycycle) { | ||
var cmd = Put() | ||
.word32le(5) // _PI_CMD_PWM | ||
.word32le(userGpio) | ||
.word32le(dutycycle) | ||
.word32le(0); | ||
this.client.write(cmd.buffer()); | ||
}; | ||
module.exports = PiFastGpio; |
{ | ||
"name": "pi-fast-gpio", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Super fast GPIO access on the Raspberry Pi using the pigpio daemon (for pwm, servo control, etc)", | ||
@@ -5,0 +5,0 @@ "author": "Tobbe Lundberg <tobbe@tlundberg.com> (http://tlundberg.com)", |
@@ -36,11 +36,19 @@ pi-fast-gpio | ||
Example | ||
------- | ||
Examples | ||
-------- | ||
An example is included in the examples/ directory that drives two servos. | ||
Watch it in action here: http://youtu.be/AnlUtAq5oAM | ||
There are two examples included, one that drives two servos, and one that uses | ||
PWM to change the brightness of two LEDs | ||
Before running the example, make sure you have two servos connected to your | ||
Raspberry Pi. One on GPIO18 and one on GPIO23. | ||
Before running any of the examples, make sure the pigpio daemon is running: | ||
$ sudo pigpiod | ||
### Servos example | ||
Watch the servos example in action here: http://youtu.be/AnlUtAq5oAM | ||
Before running the example, please connect two servos to your Raspberry Pi. | ||
One on GPIO18 and one on GPIO23. | ||
Go to the examples/ directory and run the code: | ||
@@ -51,1 +59,55 @@ | ||
Watch the servos turn! | ||
### LED PWM example | ||
Watch the LED PWM example in action here: http://youtu.be/OW6yF4NuwLE | ||
Before running the example, please connect to LEDs to your Raspberry Pi with | ||
suitable resistors. Connect one LED to GPIO24 and one to GPIO25. | ||
Go to the examples/ directory and run the code: | ||
$ node js_pwm.js | ||
Watch the LEDs light up with different brightness! | ||
Pin Layout tables | ||
----------------- | ||
(Tables copied from [r-pi-gpio](https://github.com/clebert/r-pi-gpio)'s readme file) | ||
### Raspberry Pi GPIO Pin Layout (Revision 1) | ||
| Assignment | Pin | Pin | Assignment | | ||
| :------------------ | :-- | :-- | :------------------ | | ||
| 3.3V | 1 | 2 | 5V | | ||
| GPIO 0 (I2C0 SDA) | 3 | 4 | DNC | | ||
| GPIO 1 (I2C0 SCL) | 5 | 6 | GROUND | | ||
| GPIO 4 | 7 | 8 | GPIO 14 (UART TXD) | | ||
| DNC | 9 | 10 | GPIO 15 (UART RXD) | | ||
| GPIO 17 | 11 | 12 | GPIO 18 | | ||
| GPIO 21 | 13 | 14 | DNC | | ||
| GPIO 22 | 15 | 16 | GPIO 23 | | ||
| DNC | 17 | 18 | GPIO 24 | | ||
| GPIO 10 (SP10 MOSI) | 19 | 20 | DNC | | ||
| GPIO 9 (SP10 MISO) | 21 | 22 | GPIO 25 | | ||
| GPIO 11 (SP10 SCLK) | 23 | 24 | GPIO 8 (SP10 CE0 N) | | ||
| DNC | 25 | 26 | GPIO 7 (SP10 CE1 N) | | ||
### Raspberry Pi GPIO Pin Layout (Revision 2) | ||
| Assignment | Pin | Pin | Assignment | | ||
| :------------------ | :-- | :-- | :------------------ | | ||
| 3.3V | 1 | 2 | 5V | | ||
| GPIO 2 (I2C1 SDA) | 3 | 4 | 5V | | ||
| GPIO 3 (I2C1 SCL) | 5 | 6 | GROUND | | ||
| GPIO 4 | 7 | 8 | GPIO 14 (UART TXD) | | ||
| GROUND | 9 | 10 | GPIO 15 (UART RXD) | | ||
| GPIO 17 | 11 | 12 | GPIO 18 | | ||
| GPIO 27 | 13 | 14 | GROUND | | ||
| GPIO 22 | 15 | 16 | GPIO 23 | | ||
| 3.3V | 17 | 18 | GPIO 24 | | ||
| GPIO 10 (SP10 MOSI) | 19 | 20 | GROUND | | ||
| GPIO 9 (SP10 MISO) | 21 | 22 | GPIO 25 | | ||
| GPIO 11 (SP10 SCLK) | 23 | 24 | GPIO 8 (SP10 CE0 N) | | ||
| GROUND | 25 | 26 | GPIO 7 (SP10 CE1 N) | |
9926
7
144
112