2.0.3 • Published 6 years ago

@stheine/pigpiod v2.0.3

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

pigpiod

Node.js interface for pigpiod on the Raspberry Pi Zero, 1, 2, or 3.

Contents

Features

Installation

Step 1

This step can be skipped on Raspbian Jessie 2016-05-10 or newer as it includes the pigpio C library and pigpiod.

The pigpio package is based on the pigpio C library so the C library needs to be installed first. Version V41 or higher of the pigpio C library is required. It can be installed with the following commands:

wget abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd PIGPIO
make
sudo make install

Step 2

npm install pigpio

I have developed and tested on Node.js 6.2.0, so it should be working ok here. It might very well work on the earlier versions of Node.js.

Usage

const pigpiod = require('pigpiod');

let pi  = pigpiod.pigpio_start();
let spi = pigpiod.spi_open(pi, 0); // SPI channel 0

// read A-D converter value on MCP3204 on SPI channel 0, MCP channel 0
const a2dValue = pigpiod.mcp3204(pi, spi, 0);
console.log(`a2dValue = ${a2dValue}`);

// DHT22 (this is a C-based implementation reading the sensor data)
dhtResult = pigpiod.dht22(pi, 18); // read DHT22 sensor on port 18
console.log(dhtResult);

pigpiod.spi_close(pi, spi);
pigpiod.pigpio_stop(pi);

Standard pigpiod API

Following APIs are already implemented. See for details: http://abyz.co.uk/rpi/pigpio/pdif2.html

Where not explicitly stated, the parameters are the same.

The error handling is different, though: Instead of returning an error code, an exception is thrown.

ESSENTIAL
xpigpio_startConnects to a pigpio daemon
xpigpio_stopDisconnects from a pigpio daemon
BEGINNER
xset_modeSet a GPIO mode
xget_modeGet a GPIO mode
xset_pull_up_downSet/clear GPIO pull up/down resistor
xgpio_readRead a GPIO
xgpio_writeWrite a GPIO
set_PWM_dutycycleStart/stop PWM pulses on a GPIO
get_PWM_dutycycleGet the PWM dutycycle in use on a GPIO
set_servo_pulsewidthStart/stop servo pulses on a GPIO
get_servo_pulsewidthGet the servo pulsewidth in use on a GPIO
xcallbackCreate GPIO level change callback
callback_exCreate GPIO level change callback
xcallback_cancelCancel a callback
wait_for_edgeWait for GPIO level change
INTERMEDIATE
gpio_triggerSend a trigger pulse to a GPIO.
xset_watchdogSet a watchdog on a GPIO.
set_PWM_rangeConfigure PWM range for a GPIO
get_PWM_rangeGet configured PWM range for a GPIO
set_PWM_frequencyConfigure PWM frequency for a GPIO
get_PWM_frequencyGet configured PWM frequency for a GPIO
read_bank_1Read all GPIO in bank 1
read_bank_2Read all GPIO in bank 2
clear_bank_1Clear selected GPIO in bank 1
clear_bank_2Clear selected GPIO in bank 2
set_bank_1Set selected GPIO in bank 1
set_bank_2Set selected GPIO in bank 2
start_threadStart a new thread
stop_threadStop a previously started thread
ADVANCED
get_PWM_real_rangeGet underlying PWM range for a GPIO
notify_openRequest a notification handle
notify_beginStart notifications for selected GPIO
notify_pausePause notifications
notify_closeClose a notification
bb_serial_read_openOpens a GPIO for bit bang serial reads
bb_serial_readReads bit bang serial data from a GPIO
bb_serial_read_closeCloses a GPIO for bit bang serial reads
bb_serial_invertInvert serial logic (1 invert, 0 normal)
hardware_clockStart hardware clock on supported GPIO
hardware_PWMStart hardware PWM on supported GPIO
xset_glitch_filterSet a glitch filter on a GPIO
xset_noise_filterSet a noise filter on a GPIO
SCRIPTS
store_scriptStore a script
run_scriptRun a stored script
script_statusGet script status and parameters
stop_scriptStop a running script
delete_scriptDelete a stored script
WAVES
wave_clearDeletes all waveforms
wave_add_newStarts a new waveform
wave_add_genericAdds a series of pulses to the waveform
wave_add_serialAdds serial data to the waveform
wave_createCreates a waveform from added data
wave_deleteDeletes one or more waveforms
wave_send_onceTransmits a waveform once
wave_send_repeatTransmits a waveform repeatedly
wave_send_using_modeTransmits a waveform in the chosen mode
wave_chainTransmits a chain of waveforms
wave_tx_atReturns the current transmitting waveform
wave_tx_busyChecks to see if the waveform has ended
wave_tx_stopAborts the current waveform
wave_get_microsLength in microseconds of the current waveform
wave_get_high_microsLength of longest waveform so far
wave_get_max_microsAbsolute maximum allowed micros
wave_get_pulsesLength in pulses of the current waveform
wave_get_high_pulsesLength of longest waveform so far
wave_get_max_pulsesAbsolute maximum allowed pulses
wave_get_cbsLength in cbs of the current waveform
wave_get_high_cbsLength of longest waveform so far
wave_get_max_cbsAbsolute maximum allowed cbs
I2C
i2c_openOpens an I2C device
i2c_closeCloses an I2C device
i2c_write_quicksmbus write quick
i2c_write_bytesmbus write byte
i2c_read_bytesmbus read byte
i2c_write_byte_datasmbus write byte data
i2c_write_word_datasmbus write word data
i2c_read_byte_datasmbus read byte data
i2c_read_word_datasmbus read word data
i2c_process_callsmbus process call
i2c_write_block_datasmbus write block data
i2c_read_block_datasmbus read block data
i2c_block_process_callsmbus block process call
i2c_write_i2c_block_datasmbus write I2C block data
i2c_read_i2c_block_datasmbus read I2C block data
i2c_read_deviceReads the raw I2C device
i2c_write_deviceWrites the raw I2C device
i2c_zipPerforms multiple I2C transactions
bb_i2c_openOpens GPIO for bit banging I2C
bb_i2c_closeCloses GPIO for bit banging I2C
bb_i2c_zipPerforms multiple bit banged I2C transactions
SPI
xspi_openOpens a SPI device
xspi_closeCloses a SPI device
spi_readReads bytes from a SPI device
spi_writeWrites bytes to a SPI device
xspi_xferTransfers bytes with a SPI device
SERIAL
xserial_openOpens a serial device (/dev/tty*)
xserial_closeCloses a serial device
xserial_write_byteWrites a byte to a serial device
xserial_read_byteReads a byte from a serial device
xserial_writeWrites bytes to a serial device
xserial_readReads bytes from a serial device
xserial_data_availableReturns number of bytes ready to be read
CUSTOM
custom_1User custom function 1
custom_2User custom function 2
UTILITIES
xget_current_tickGet current tick (microseconds)
xget_hardware_revisionGet hardware revision
xget_pigpio_versionGet the pigpio version
pigpiod_if_versionGet the pigpiod_if2 version
pigpio_errorGet a text description of an error code.
1time_sleepSleeps for a float number of seconds
2time_timeFloat number of seconds since the epoch

1: use js setTimeout() instead.

2: use moment() or Date() instead.

API documentation

Thanks

pigpio library and pigpiod Thanks to joan2937 for the development and documentation of the pigpio C library.

pigpio Thanks for fivdi for his work on the pigpio module for Node.js. I used this as the base for my development and got additional development help.

Breaking change

1.0.0

The dht22 call has been switched to an asynchronous implementation, returning a promise.

2.0.0

I have to revert the changes released in 1.0.0, as the async dht22 API works fine in a standalone example, but causes intermittent process hangs in a project using additional API calls.

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago