mirror of https://github.com/joan2937/pigpio
1231 lines
171 KiB
Plaintext
1231 lines
171 KiB
Plaintext
pigpio is a Python module for the Raspberry which talks to
|
|
the pigpio daemon to allow control of the general purpose
|
|
input outputs (GPIO).
|
|
<h3>Features</h3>o the pigpio Python module can run on Windows, Macs, or Linux
|
|
<br><br>o controls one or more Pi's
|
|
<br><br>o hardware timed PWM on any of GPIO 0-31
|
|
<br><br>o hardware timed servo pulses on any of GPIO 0-31
|
|
<br><br>o callbacks when any of GPIO 0-31 change state
|
|
<br><br>o creating and transmitting precisely timed waveforms
|
|
<br><br>o reading/writing GPIO and setting their modes
|
|
<br><br>o wrappers for I2C, SPI, and serial links
|
|
<br><br>o creating and running scripts on the pigpio daemon
|
|
<h3>GPIO</h3>ALL GPIO are identified by their Broadcom number.
|
|
<h3>Notes</h3>Transmitted waveforms are accurate to a microsecond.
|
|
<br><br>Callback level changes are time-stamped and will be
|
|
accurate to within a few microseconds.
|
|
<h3>Settings</h3>A number of settings are determined when the pigpio daemon is started.
|
|
<br><br>o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us).
|
|
<br><br>o the set of GPIO which may be updated (generally written to). The
|
|
default set is those available on the Pi board revision.
|
|
<br><br>o the available PWM frequencies (see <a href="#set_PWM_frequency">set_PWM_frequency</a>).
|
|
<h3>Exceptions</h3>By default a fatal exception is raised if you pass an invalid
|
|
argument to a pigpio function.
|
|
<br><br>If you wish to handle the returned status yourself you should set
|
|
pigpio.exceptions to False.
|
|
<br><br>You may prefer to check the returned status in only a few parts
|
|
of your code. In that case do the following:
|
|
<br><br><b><small>Example</small></b><br><br><code>pigpio.exceptions = False<br><br># Code where you want to test the error status.<br><br>pigpio.exceptions = True<br></code><h3>Usage</h3>This module uses the services of the C pigpio library. pigpio
|
|
must be running on the Pi(s) whose GPIO are to be manipulated.
|
|
<br><br>The normal way to start pigpio is as a daemon (during system
|
|
start).
|
|
<br><br>sudo pigpiod
|
|
<br><br>Your Python program must import pigpio and create one or more
|
|
instances of the pigpio.pi class. This class gives access to
|
|
a specified Pi's GPIO.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi1 = pigpio.pi() # pi1 accesses the local Pi's GPIO<br>pi2 = pigpio.pi('tom') # pi2 accesses tom's GPIO<br>pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO<br><br>pi1.write(4, 0) # set local Pi's GPIO 4 low<br>pi2.write(4, 1) # set tom's GPIO 4 to high<br>pi3.read(4) # get level of dick's GPIO 4<br></code><br><br>The later example code snippets assume that pi is an instance of
|
|
the pigpio.pi class.
|
|
<h2>OVERVIEW</h2><table border="0" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td></td></tr><tr><td><b>ESSENTIAL
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#pigpio.pi">pigpio.pi</a></td><td> Initialise Pi connection
|
|
</td></tr><tr><td><a href="#stop">stop</a></td><td> Stop a Pi connection
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>BASIC
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_mode">set_mode</a></td><td> Set a GPIO mode
|
|
</td></tr><tr><td><a href="#get_mode">get_mode</a></td><td> Get a GPIO mode
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_pull_up_down">set_pull_up_down</a></td><td> Set/clear GPIO pull up/down resistor
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#read">read</a></td><td> Read a GPIO
|
|
</td></tr><tr><td><a href="#write">write</a></td><td> Write a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>PWM (overrides servo commands on same GPIO)
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_PWM_dutycycle">set_PWM_dutycycle</a></td><td> Start/stop PWM pulses on a GPIO
|
|
</td></tr><tr><td><a href="#set_PWM_frequency">set_PWM_frequency</a></td><td> Set PWM frequency of a GPIO
|
|
</td></tr><tr><td><a href="#set_PWM_range">set_PWM_range</a></td><td> Configure PWM range of a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_PWM_dutycycle">get_PWM_dutycycle</a></td><td> Get PWM dutycycle set on a GPIO
|
|
</td></tr><tr><td><a href="#get_PWM_frequency">get_PWM_frequency</a></td><td> Get PWM frequency of a GPIO
|
|
</td></tr><tr><td><a href="#get_PWM_range">get_PWM_range</a></td><td> Get configured PWM range of a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_PWM_real_range">get_PWM_real_range</a></td><td> Get underlying PWM range for a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>Servo (overrides PWM commands on same GPIO)
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_servo_pulsewidth">set_servo_pulsewidth</a></td><td> Start/Stop servo pulses on a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_servo_pulsewidth">get_servo_pulsewidth</a></td><td> Get servo pulsewidth set on a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>INTERMEDIATE
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpio_trigger">gpio_trigger</a></td><td> Send a trigger pulse to a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_watchdog">set_watchdog</a></td><td> Set a watchdog on a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#read_bank_1">read_bank_1</a></td><td> Read all bank 1 GPIO
|
|
</td></tr><tr><td><a href="#read_bank_2">read_bank_2</a></td><td> Read all bank 2 GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#clear_bank_1">clear_bank_1</a></td><td> Clear selected GPIO in bank 1
|
|
</td></tr><tr><td><a href="#clear_bank_2">clear_bank_2</a></td><td> Clear selected GPIO in bank 2
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_bank_1">set_bank_1</a></td><td> Set selected GPIO in bank 1
|
|
</td></tr><tr><td><a href="#set_bank_2">set_bank_2</a></td><td> Set selected GPIO in bank 2
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#callback">callback</a></td><td> Create GPIO level change callback
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wait_for_edge">wait_for_edge</a></td><td> Wait for GPIO level change
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>ADVANCED
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#notify_open">notify_open</a></td><td> Request a notification handle
|
|
</td></tr><tr><td><a href="#notify_begin">notify_begin</a></td><td> Start notifications for selected GPIO
|
|
</td></tr><tr><td><a href="#notify_pause">notify_pause</a></td><td> Pause notifications
|
|
</td></tr><tr><td><a href="#notify_close">notify_close</a></td><td> Close a notification
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#hardware_clock">hardware_clock</a></td><td> Start hardware clock on supported GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#hardware_PWM">hardware_PWM</a></td><td> Start hardware PWM on supported GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_glitch_filter">set_glitch_filter</a></td><td> Set a glitch filter on a GPIO
|
|
</td></tr><tr><td><a href="#set_noise_filter">set_noise_filter</a></td><td> Set a noise filter on a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_pad_strength">set_pad_strength</a></td><td> Sets a pads drive strength
|
|
</td></tr><tr><td><a href="#get_pad_strength">get_pad_strength</a></td><td> Gets a pads drive strength
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#shell">shell</a></td><td> Executes a shell command
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>Custom
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#custom_1">custom_1</a></td><td> User custom function 1
|
|
</td></tr><tr><td><a href="#custom_2">custom_2</a></td><td> User custom function 2
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>Events
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#event_callback">event_callback</a></td><td> Sets a callback for an event
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#event_trigger">event_trigger</a></td><td> Triggers an event
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wait_for_event">wait_for_event</a></td><td> Wait for an event
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>Scripts
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#store_script">store_script</a></td><td> Store a script
|
|
</td></tr><tr><td><a href="#run_script">run_script</a></td><td> Run a stored script
|
|
</td></tr><tr><td><a href="#update_script">update_script</a></td><td> Set a scripts parameters
|
|
</td></tr><tr><td><a href="#script_status">script_status</a></td><td> Get script status and parameters
|
|
</td></tr><tr><td><a href="#stop_script">stop_script</a></td><td> Stop a running script
|
|
</td></tr><tr><td><a href="#delete_script">delete_script</a></td><td> Delete a stored script
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>I2C
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_open">i2c_open</a></td><td> Opens an I2C device
|
|
</td></tr><tr><td><a href="#i2c_close">i2c_close</a></td><td> Closes an I2C device
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_write_quick">i2c_write_quick</a></td><td> SMBus write quick
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_byte">i2c_read_byte</a></td><td> SMBus read byte
|
|
</td></tr><tr><td><a href="#i2c_write_byte">i2c_write_byte</a></td><td> SMBus write byte
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_byte_data">i2c_read_byte_data</a></td><td> SMBus read byte data
|
|
</td></tr><tr><td><a href="#i2c_write_byte_data">i2c_write_byte_data</a></td><td> SMBus write byte data
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_word_data">i2c_read_word_data</a></td><td> SMBus read word data
|
|
</td></tr><tr><td><a href="#i2c_write_word_data">i2c_write_word_data</a></td><td> SMBus write word data
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_block_data">i2c_read_block_data</a></td><td> SMBus read block data
|
|
</td></tr><tr><td><a href="#i2c_write_block_data">i2c_write_block_data</a></td><td> SMBus write block data
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_i2c_block_data">i2c_read_i2c_block_data</a></td><td> SMBus read I2C block data
|
|
</td></tr><tr><td><a href="#i2c_write_i2c_block_data">i2c_write_i2c_block_data</a></td><td> SMBus write I2C block data
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_device">i2c_read_device</a></td><td> Reads the raw I2C device
|
|
</td></tr><tr><td><a href="#i2c_write_device">i2c_write_device</a></td><td> Writes the raw I2C device
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_process_call">i2c_process_call</a></td><td> SMBus process call
|
|
</td></tr><tr><td><a href="#i2c_block_process_call">i2c_block_process_call</a></td><td> SMBus block process call
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_zip">i2c_zip</a></td><td> Performs multiple I2C transactions
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>I2C BIT BANG
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_i2c_open">bb_i2c_open</a></td><td> Opens GPIO for bit banging I2C
|
|
</td></tr><tr><td><a href="#bb_i2c_close">bb_i2c_close</a></td><td> Closes GPIO for bit banging I2C
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_i2c_zip">bb_i2c_zip</a></td><td> Performs multiple bit banged I2C transactions
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>I2C/SPI SLAVE
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#bsc_xfer">bsc_xfer</a></td><td> I2C/SPI as slave transfer
|
|
</td></tr><tr><td><a href="#bsc_i2c">bsc_i2c</a></td><td> I2C as slave transfer
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>SERIAL
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_open">serial_open</a></td><td> Opens a serial device
|
|
</td></tr><tr><td><a href="#serial_close">serial_close</a></td><td> Closes a serial device
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_read_byte">serial_read_byte</a></td><td> Reads a byte from a serial device
|
|
</td></tr><tr><td><a href="#serial_write_byte">serial_write_byte</a></td><td> Writes a byte to a serial device
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_read">serial_read</a></td><td> Reads bytes from a serial device
|
|
</td></tr><tr><td><a href="#serial_write">serial_write</a></td><td> Writes bytes to a serial device
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_data_available">serial_data_available</a></td><td> Returns number of bytes ready to be read
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>SERIAL BIT BANG (read only)
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_serial_read_open">bb_serial_read_open</a></td><td> Open a GPIO for bit bang serial reads
|
|
</td></tr><tr><td><a href="#bb_serial_read_close">bb_serial_read_close</a></td><td> Close a GPIO for bit bang serial reads
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_serial_invert">bb_serial_invert</a></td><td> Invert serial logic (1 invert, 0 normal)
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_serial_read">bb_serial_read</a></td><td> Read bit bang serial data from a GPIO
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>SPI
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#spi_open">spi_open</a></td><td> Opens a SPI device
|
|
</td></tr><tr><td><a href="#spi_close">spi_close</a></td><td> Closes a SPI device
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#spi_read">spi_read</a></td><td> Reads bytes from a SPI device
|
|
</td></tr><tr><td><a href="#spi_write">spi_write</a></td><td> Writes bytes to a SPI device
|
|
</td></tr><tr><td><a href="#spi_xfer">spi_xfer</a></td><td> Transfers bytes with a SPI device
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>SPI BIT BANG
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_spi_open">bb_spi_open</a></td><td> Opens GPIO for bit banging SPI
|
|
</td></tr><tr><td><a href="#bb_spi_close">bb_spi_close</a></td><td> Closes GPIO for bit banging SPI
|
|
</td></tr><tr><td><a href="#bb_spi_xfer">bb_spi_xfer</a></td><td> Transfers bytes with bit banging SPI
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>FILES
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#file_open">file_open</a></td><td> Opens a file
|
|
</td></tr><tr><td><a href="#file_close">file_close</a></td><td> Closes a file
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#file_read">file_read</a></td><td> Reads bytes from a file
|
|
</td></tr><tr><td><a href="#file_write">file_write</a></td><td> Writes bytes to a file
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#file_seek">file_seek</a></td><td> Seeks to a position within a file
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#file_list">file_list</a></td><td> List files which match a pattern
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>WAVES
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_clear">wave_clear</a></td><td> Deletes all waveforms
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_add_new">wave_add_new</a></td><td> Starts a new waveform
|
|
</td></tr><tr><td><a href="#wave_add_generic">wave_add_generic</a></td><td> Adds a series of pulses to the waveform
|
|
</td></tr><tr><td><a href="#wave_add_serial">wave_add_serial</a></td><td> Adds serial data to the waveform
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_create">wave_create</a></td><td> Creates a waveform from added data
|
|
</td></tr><tr><td><a href="#wave_create_and_pad">wave_create_and_pad</a></td><td> Creates a waveform of fixed size from added data
|
|
</td></tr><tr><td><a href="#wave_delete">wave_delete</a></td><td> Deletes a waveform
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_send_once">wave_send_once</a></td><td> Transmits a waveform once
|
|
</td></tr><tr><td><a href="#wave_send_repeat">wave_send_repeat</a></td><td> Transmits a waveform repeatedly
|
|
</td></tr><tr><td><a href="#wave_send_using_mode">wave_send_using_mode</a></td><td> Transmits a waveform in the chosen mode
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_chain">wave_chain</a></td><td> Transmits a chain of waveforms
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_tx_at">wave_tx_at</a></td><td> Returns the current transmitting waveform
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_tx_busy">wave_tx_busy</a></td><td> Checks to see if a waveform has ended
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_tx_stop">wave_tx_stop</a></td><td> Aborts the current waveform
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_cbs">wave_get_cbs</a></td><td> Length in cbs of the current waveform
|
|
</td></tr><tr><td><a href="#wave_get_max_cbs">wave_get_max_cbs</a></td><td> Absolute maximum allowed cbs
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_micros">wave_get_micros</a></td><td> Length in microseconds of the current waveform
|
|
</td></tr><tr><td><a href="#wave_get_max_micros">wave_get_max_micros</a></td><td> Absolute maximum allowed micros
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_pulses">wave_get_pulses</a></td><td> Length in pulses of the current waveform
|
|
</td></tr><tr><td><a href="#wave_get_max_pulses">wave_get_max_pulses</a></td><td> Absolute maximum allowed pulses
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><b>UTILITIES
|
|
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_current_tick">get_current_tick</a></td><td> Get current tick (microseconds)
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_hardware_revision">get_hardware_revision</a></td><td> Get hardware revision
|
|
</td></tr><tr><td><a href="#get_pigpio_version">get_pigpio_version</a></td><td> Get the pigpio version
|
|
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#pigpio.error_text">pigpio.error_text</a></td><td> Gets error text from error number
|
|
</td></tr><tr><td><a href="#pigpio.tickDiff">pigpio.tickDiff</a></td><td> Returns difference between two ticks
|
|
</td></tr><tr><td><b></b></td><td></td></tr></tbody></table><h2> class pi
|
|
</h2><h3><a name="pigpio.pi">pigpio.pi<small>(<a href="#host">host</a>, <a href="#port">port</a>, <a href="#show_errors">show_errors</a>)</small></h3>
|
|
Grants access to a Pi's GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>host:= the host name of the Pi on which the pigpio daemon is<br> running. The default is localhost unless overridden by<br> the PIGPIO_ADDR environment variable.<br></samp><br><br><b><small>Parameters</small></b><br><br><samp>port:= the port number on which the pigpio daemon is listening.<br> The default is 8888 unless overridden by the PIGPIO_PORT<br> environment variable. The pigpio daemon must have been<br> started with the same port number.<br></samp><br><br>This connects to the pigpio daemon and reserves resources
|
|
to be used for sending commands and receiving notifications.
|
|
<br><br>An instance attribute <a href="#connected">connected</a> may be used to check the
|
|
success of the connection. If the connection is established
|
|
successfully <a href="#connected">connected</a> will be True, otherwise False.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi = pigio.pi() # use defaults<br>pi = pigpio.pi('mypi') # specify host, default port<br>pi = pigpio.pi('mypi', 7777) # specify host and port<br><br>pi = pigpio.pi() # exit script if no connection<br>if not pi.connected:<br> exit()<br></code><h3><a name="__repr__">__repr__<small>()</small></h3>
|
|
<h3><a name="bb_i2c_close">bb_i2c_close<small>(<a href="#SDA">SDA</a>)</small></h3>
|
|
This function stops bit banging I2C on a pair of GPIO
|
|
previously opened with <a href="#bb_i2c_open">bb_i2c_open</a>.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>SDA:= 0-31, the SDA GPIO used in a prior call to <a href="#bb_i2c_open">bb_i2c_open</a><br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.bb_i2c_close(SDA)<br></code><h3><a name="bb_i2c_open">bb_i2c_open<small>(<a href="#SDA">SDA</a>, <a href="#SCL">SCL</a>, <a href="#baud">baud</a>)</small></h3>
|
|
This function selects a pair of GPIO for bit banging I2C at a
|
|
specified baud rate.
|
|
<br><br>Bit banging I2C allows for certain operations which are not possible
|
|
with the standard I2C driver.
|
|
<br><br>o baud rates as low as 50
|
|
o repeated starts
|
|
o clock stretching
|
|
o I2C on any pair of spare GPIO
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> SDA:= 0-31<br> SCL:= 0-31<br>baud:= 50-500000<br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or
|
|
PI_GPIO_IN_USE.
|
|
<br><br>NOTE:
|
|
<br><br>The GPIO used for SDA and SCL must have pull-ups to 3V3 connected.
|
|
As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value.
|
|
<br><br><b><small>Example</small></b><br><br><code>h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps<br></code><h3><a name="bb_i2c_zip">bb_i2c_zip<small>(<a href="#SDA">SDA</a>, <a href="#data">data</a>)</small></h3>
|
|
This function executes a sequence of bit banged I2C operations.
|
|
The operations to be performed are specified by the contents
|
|
of data which contains the concatenated command codes and
|
|
associated data.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> SDA:= 0-31 (as used in a prior call to <a href="#bb_i2c_open">bb_i2c_open</a>)<br>data:= the concatenated I2C commands, see below<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(count, data) = pi.bb_i2c_zip(<br> SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0])<br></code><br><br>The following command codes are supported:
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Name</td><td>Cmd & Data</td><td>Meaning</td></tr><tr><td>End</td><td>0</td><td>No more commands</td></tr><tr><td>Escape</td><td>1</td><td>Next P is two bytes</td></tr><tr><td>Start</td><td>2</td><td>Start condition</td></tr><tr><td>Stop</td><td>3</td><td>Stop condition</td></tr><tr><td>Address</td><td>4 P</td><td>Set I2C address to P</td></tr><tr><td>Flags</td><td>5 lsb msb</td><td>Set I2C flags to lsb + (msb << 8)</td></tr><tr><td>Read</td><td>6 P</td><td>Read P bytes of data</td></tr><tr><td>Write</td><td>7 P ...</td><td>Write P bytes of data</td></tr></tbody></table><br><br>The address, read, and write commands take a parameter P.
|
|
Normally P is one byte (0-255). If the command is preceded by
|
|
the Escape command then P is two bytes (0-65535, least significant
|
|
byte first).
|
|
<br><br>The address and flags default to 0. The address and flags maintain
|
|
their previous value until updated.
|
|
<br><br>No flags are currently defined.
|
|
<br><br>Any read I2C data is concatenated in the returned bytearray.
|
|
<br><br><b><small>Example</small></b><br><br><code>Set address 0x53<br>start, write 0x32, (re)start, read 6 bytes, stop<br>Set address 0x1E<br>start, write 0x03, (re)start, read 6 bytes, stop<br>Set address 0x68<br>start, write 0x1B, (re)start, read 8 bytes, stop<br>End<br><br>0x04 0x53<br>0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03<br><br>0x04 0x1E<br>0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03<br><br>0x04 0x68<br>0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03<br><br>0x00<br></code><h3><a name="bb_serial_invert">bb_serial_invert<small>(<a href="#user_gpio">user_gpio</a>, <a href="#invert">invert</a>)</small></h3>
|
|
Invert serial logic.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31 (opened in a prior call to <a href="#bb_serial_read_open">bb_serial_read_open</a>)<br> invert:= 0-1 (1 invert, 0 normal)<br></samp><br><br><b><small>Example</small></b><br><br><code>status = pi.bb_serial_invert(17, 1)<br></code><h3><a name="bb_serial_read">bb_serial_read<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
|
|
Returns data from the bit bang serial cyclic buffer.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31 (opened in a prior call to <a href="#bb_serial_read_open">bb_serial_read_open</a>)<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br>The bytes returned for each character depend upon the number of
|
|
data bits <a href="#bb_bits">bb_bits</a> specified in the <a href="#bb_serial_read_open">bb_serial_read_open</a>
|
|
command.
|
|
<br><br>For <a href="#bb_bits">bb_bits</a> 1-8 there will be one byte per character.
|
|
For <a href="#bb_bits">bb_bits</a> 9-16 there will be two bytes per character.
|
|
For <a href="#bb_bits">bb_bits</a> 17-32 there will be four bytes per character.
|
|
<br><br><b><small>Example</small></b><br><br><code>(count, data) = pi.bb_serial_read(4)<br></code><h3><a name="bb_serial_read_close">bb_serial_read_close<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
|
|
Closes a GPIO for bit bang reading of serial data.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31 (opened in a prior call to <a href="#bb_serial_read_open">bb_serial_read_open</a>)<br></samp><br><br><b><small>Example</small></b><br><br><code>status = pi.bb_serial_read_close(17)<br></code><h3><a name="bb_serial_read_open">bb_serial_read_open<small>(<a href="#user_gpio">user_gpio</a>, <a href="#baud">baud</a>, <a href="#bb_bits">bb_bits</a>)</small></h3>
|
|
Opens a GPIO for bit bang reading of serial data.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31, the GPIO to use.<br> baud:= 50-250000, the baud rate.<br> bb_bits:= 1-32, the number of bits per word, default 8.<br></samp><br><br>The serial data is held in a cyclic buffer and is read using
|
|
<a href="#bb_serial_read">bb_serial_read</a>.
|
|
<br><br>It is the caller's responsibility to read data from the cyclic
|
|
buffer in a timely fashion.
|
|
<br><br><b><small>Example</small></b><br><br><code>status = pi.bb_serial_read_open(4, 19200)<br>status = pi.bb_serial_read_open(17, 9600)<br></code><h3><a name="bb_spi_close">bb_spi_close<small>(<a href="#CS">CS</a>)</small></h3>
|
|
This function stops bit banging SPI on a set of GPIO
|
|
opened with <a href="#bb_spi_open">bb_spi_open</a>.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>CS:= 0-31, the CS GPIO used in a prior call to <a href="#bb_spi_open">bb_spi_open</a><br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.bb_spi_close(CS)<br></code><h3><a name="bb_spi_open">bb_spi_open<small>(<a href="#CS">CS</a>, <a href="#MISO">MISO</a>, <a href="#MOSI">MOSI</a>, <a href="#SCLK">SCLK</a>, <a href="#baud">baud</a>, <a href="#spi_flags">spi_flags</a>)</small></h3>
|
|
This function selects a set of GPIO for bit banging SPI at a
|
|
specified baud rate.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> CS := 0-31<br> MISO := 0-31<br> MOSI := 0-31<br> SCLK := 0-31<br> baud := 50-250000<br>spiFlags := see below<br></samp><br><br>spiFlags consists of the least significant 22 bits.
|
|
<br><br><code>21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0<br> 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m<br></code><br><br>mm defines the SPI mode, defaults to 0
|
|
<br><br><code>Mode CPOL CPHA<br> 0 0 0<br> 1 0 1<br> 2 1 0<br> 3 1 1<br></code><br><br>The following constants may be used to set the mode:
|
|
<br><br><code>pigpio.SPI_MODE_0<br>pigpio.SPI_MODE_1<br>pigpio.SPI_MODE_2<br>pigpio.SPI_MODE_3<br></code><br><br>Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA
|
|
may be used.
|
|
<br><br>p is 0 if CS is active low (default) and 1 for active high.
|
|
pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag.
|
|
<br><br>T is 1 if the least significant bit is transmitted on MOSI first,
|
|
the default (0) shifts the most significant bit out first.
|
|
pigpio.SPI_TX_LSBFIRST may be used to set this flag.
|
|
<br><br>R is 1 if the least significant bit is received on MISO first,
|
|
the default (0) receives the most significant bit first.
|
|
pigpio.SPI_RX_LSBFIRST may be used to set this flag.
|
|
<br><br>The other bits in spiFlags should be set to zero.
|
|
<br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
|
|
PI_GPIO_IN_USE.
|
|
<br><br>If more than one device is connected to the SPI bus (defined by
|
|
SCLK, MOSI, and MISO) each must have its own CS.
|
|
<br><br><b><small>Example</small></b><br><br><code>bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1<br>bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2<br></code><h3><a name="bb_spi_xfer">bb_spi_xfer<small>(<a href="#CS">CS</a>, <a href="#data">data</a>)</small></h3>
|
|
This function executes a bit banged SPI transfer.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> CS:= 0-31 (as used in a prior call to <a href="#bb_spi_open">bb_spi_open</a>)<br>data:= data to be sent<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>#!/usr/bin/env python<br><br>import pigpio<br><br>CE0=5<br>CE1=6<br>MISO=13<br>MOSI=19<br>SCLK=12<br><br>pi = pigpio.pi()<br>if not pi.connected:<br> exit()<br><br>pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC<br>pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC<br><br>for i in range(256):<br><br> count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value<br><br> if count == 2:<br><br> count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC<br><br> if count == 2:<br><br> set_val = data[1]<br><br> count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC<br><br> if count == 3:<br><br> read_val = ((data[1]&3)<<8) | data[2]<br><br> print("{} {}".format(set_val, read_val))<br><br>pi.bb_spi_close(CE0)<br>pi.bb_spi_close(CE1)<br><br>pi.stop()<br></code><h3><a name="bsc_i2c">bsc_i2c<small>(<a href="#i2c_address">i2c_address</a>, <a href="#data">data</a>)</small></h3>
|
|
This function allows the Pi to act as a slave I2C device.
|
|
<br><br>This function is not available on the BCM2711 (e.g. as
|
|
used in the Pi4B).
|
|
<br><br>The data bytes (if any) are written to the BSC transmit
|
|
FIFO and the bytes in the BSC receive FIFO are returned.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>i2c_address:= the I2C slave address.<br> data:= the data bytes to transmit.<br></samp><br><br>The returned value is a tuple of the status, the number
|
|
of bytes read, and a bytearray containing the read bytes.
|
|
<br><br>See <a href="#bsc_xfer">bsc_xfer</a> for details of the status value.
|
|
<br><br>If there was an error the status will be less than zero
|
|
(and will contain the error code).
|
|
<br><br>Note that an i2c_address of 0 may be used to close
|
|
the BSC device and reassign the used GPIO as inputs.
|
|
<br><br>This example assumes GPIO 2/3 are connected to GPIO 18/19
|
|
(GPIO 10/11 on the BCM2711).
|
|
<br><br><b><small>Example</small></b><br><br><code>#!/usr/bin/env python<br>import time<br>import pigpio<br><br>I2C_ADDR=0x13<br><br>def i2c(id, tick):<br> global pi<br><br> s, b, d = pi.bsc_i2c(I2C_ADDR)<br> if b:<br> if d[0] == ord('t'): # 116 send 'HH:MM:SS*'<br><br> print("sent={} FR={} received={} [{}]".<br> format(s>>16, s&0xfff,b,d))<br><br> s, b, d = pi.bsc_i2c(I2C_ADDR,<br> "{}*".format(time.asctime()[11:19]))<br><br> elif d[0] == ord('d'): # 100 send 'Sun Oct 30*'<br><br> print("sent={} FR={} received={} [{}]".<br> format(s>>16, s&0xfff,b,d))<br><br> s, b, d = pi.bsc_i2c(I2C_ADDR,<br> "{}*".format(time.asctime()[:10]))<br><br>pi = pigpio.pi()<br><br>if not pi.connected:<br> exit()<br><br># Respond to BSC slave activity<br><br>e = pi.event_callback(pigpio.EVENT_BSC, i2c)<br><br>pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave<br><br>time.sleep(600)<br><br>e.cancel()<br><br>pi.bsc_i2c(0) # Disable BSC peripheral<br><br>pi.stop()<br></code><br><br>While running the above.
|
|
<br><br><code>$ i2cdetect -y 1<br> 0 1 2 3 4 5 6 7 8 9 a b c d e f<br>00: -- -- -- -- -- -- -- -- -- -- -- -- --<br>10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- --<br>20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br>30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br>40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br>50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br>60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br>70: -- -- -- -- -- -- -- --<br><br>$ pigs i2co 1 0x13 0<br>0<br><br>$ pigs i2cwd 0 116<br>$ pigs i2crd 0 9 -a<br>9 10:13:58*<br><br>$ pigs i2cwd 0 116<br>$ pigs i2crd 0 9 -a<br>9 10:14:29*<br><br>$ pigs i2cwd 0 100<br>$ pigs i2crd 0 11 -a<br>11 Sun Oct 30*<br><br>$ pigs i2cwd 0 100<br>$ pigs i2crd 0 11 -a<br>11 Sun Oct 30*<br><br>$ pigs i2cwd 0 116<br>$ pigs i2crd 0 9 -a<br>9 10:23:16*<br><br>$ pigs i2cwd 0 100<br>$ pigs i2crd 0 11 -a<br>11 Sun Oct 30*<br></code><h3><a name="bsc_xfer">bsc_xfer<small>(<a href="#bsc_control">bsc_control</a>, <a href="#data">data</a>)</small></h3>
|
|
This function provides a low-level interface to the SPI/I2C Slave
|
|
peripheral on the BCM chip.
|
|
<br><br>This peripheral allows the Pi to act as a hardware slave device
|
|
on an I2C or SPI bus.
|
|
<br><br>This is not a bit bang version and as such is OS timing
|
|
independent. The bus timing is handled directly by the chip.
|
|
<br><br>The output process is simple. You simply append data to the FIFO
|
|
buffer on the chip. This works like a queue, you add data to the
|
|
queue and the master removes it.
|
|
<br><br>I can't get SPI to work properly. I tried with a
|
|
control word of 0x303 and swapped MISO and MOSI.
|
|
<br><br>The function sets the BSC mode, writes any data in
|
|
the transmit buffer to the BSC transmit FIFO, and
|
|
copies any data in the BSC receive FIFO to the
|
|
receive buffer.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>bsc_control:= see below<br> data:= the data bytes to place in the transmit FIFO.<br></samp><br><br>The returned value is a tuple of the status (see below),
|
|
the number of bytes read, and a bytearray containing the
|
|
read bytes. If there was an error the status will be less
|
|
than zero (and will contain the error code).
|
|
<br><br>Note that the control word sets the BSC mode. The BSC will
|
|
stay in that mode until a different control word is sent.
|
|
<br><br>GPIO used for models other than those based on the BCM2711.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>SDA</td><td>SCL</td><td>MOSI</td><td>SCLK</td><td>MISO</td><td>CE</td></tr><tr><td>I2C</td><td>18</td><td>19</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>SPI</td><td>-</td><td>-</td><td>18</td><td>19</td><td>20</td><td>21</td></tr></tbody></table><br><br>GPIO used for models based on the BCM2711 (e.g. the Pi4B).
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>SDA</td><td>SCL</td><td>MOSI</td><td>SCLK</td><td>MISO</td><td>CE</td></tr><tr><td>I2C</td><td>10</td><td>11</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>SPI</td><td>-</td><td>-</td><td>10</td><td>11</td><td>9</td><td>8</td></tr></tbody></table><br><br>When a zero control word is received the used GPIO will be reset
|
|
to INPUT mode.
|
|
<br><br>bsc_control consists of the following bits:
|
|
<br><br><code>22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0<br> a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN<br></code><br><br>Bits 0-13 are copied unchanged to the BSC CR register. See
|
|
pages 163-165 of the Broadcom peripherals document for full
|
|
details.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>aaaaaaa</td><td>defines the I2C slave address (only relevant in I2C mode)</td></tr><tr><td>IT</td><td>invert transmit status flags</td></tr><tr><td>HC</td><td>enable host control</td></tr><tr><td>TF</td><td>enable test FIFO</td></tr><tr><td>IR</td><td>invert receive status flags</td></tr><tr><td>RE</td><td>enable receive</td></tr><tr><td>TE</td><td>enable transmit</td></tr><tr><td>BK</td><td>abort operation and clear FIFOs</td></tr><tr><td>EC</td><td>send control register as first I2C byte</td></tr><tr><td>ES</td><td>send status register as first I2C byte</td></tr><tr><td>PL</td><td>set SPI polarity high</td></tr><tr><td>PH</td><td>set SPI phase high</td></tr><tr><td>I2</td><td>enable I2C mode</td></tr><tr><td>SP</td><td>enable SPI mode</td></tr><tr><td>EN</td><td>enable BSC peripheral</td></tr></tbody></table><br><br>The status has the following format:
|
|
<br><br><code>20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0<br> S S S S S R R R R R T T T T T RB TE RF TF RE TB<br></code><br><br>Bits 0-15 are copied unchanged from the BSC FR register. See
|
|
pages 165-166 of the Broadcom peripherals document for full
|
|
details.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>SSSSS</td><td>number of bytes successfully copied to transmit FIFO</td></tr><tr><td>RRRRR</td><td>number of bytes in receieve FIFO</td></tr><tr><td>TTTTT</td><td>number of bytes in transmit FIFO</td></tr><tr><td>RB</td><td>receive busy</td></tr><tr><td>TE</td><td>transmit FIFO empty</td></tr><tr><td>RF</td><td>receive FIFO full</td></tr><tr><td>TF</td><td>transmit FIFO full</td></tr><tr><td>RE</td><td>receive FIFO empty</td></tr><tr><td>TB</td><td>transmit busy</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>(status, count, data) = pi.bsc_xfer(0x330305, "Hello!")<br></code><h3><a name="callback">callback<small>(<a href="#user_gpio">user_gpio</a>, <a href="#edge">edge</a>, <a href="#func">func</a>)</small></h3>
|
|
Calls a user supplied function (a callback) whenever the
|
|
specified GPIO edge is detected.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br> edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.<br> func:= user supplied callback function.<br></samp><br><br>The user supplied callback receives three parameters, the GPIO,
|
|
the level, and the tick.
|
|
<br><br><code>Parameter Value Meaning<br><br>GPIO 0-31 The GPIO which has changed state<br><br>level 0-2 0 = change to low (a falling edge)<br> 1 = change to high (a rising edge)<br> 2 = no level change (a watchdog timeout)<br><br>tick 32 bit The number of microseconds since boot<br> WARNING: this wraps around from<br> 4294967295 to 0 roughly every 72 minutes<br></code><br><br>If a user callback is not specified a default tally callback is
|
|
provided which simply counts edges. The count may be retrieved
|
|
by calling the tally function. The count may be reset to zero
|
|
by calling the reset_tally function.
|
|
<br><br>The callback may be cancelled by calling the cancel function.
|
|
<br><br>A GPIO may have multiple callbacks (although I can't think of
|
|
a reason to do so).
|
|
<br><br>The GPIO are sampled at a rate set when the pigpio daemon
|
|
is started (default 5 us).
|
|
<br><br>The number of samples per second is given in the following table.
|
|
<br><br><code> samples<br> per sec<br><br> 1 1,000,000<br> 2 500,000<br>sample 4 250,000<br>rate 5 200,000<br>(us) 8 125,000<br> 10 100,000<br></code><br><br>GPIO level changes shorter than the sample rate may be missed.
|
|
<br><br>The daemon software which generates the callbacks is triggered
|
|
1000 times per second. The callbacks will be called once per
|
|
level change since the last time they were called.
|
|
i.e. The callbacks will get all level changes but there will
|
|
be a latency.
|
|
<br><br>If you want to track the level of more than one GPIO do so by
|
|
maintaining the state in the callback. Do not use <a href="#read">read</a>.
|
|
Remember the event that triggered the callback may have
|
|
happened several milliseconds before and the GPIO may have
|
|
changed level many times since then.
|
|
<br><br><b><small>Example</small></b><br><br><code>def cbf(gpio, level, tick):<br> print(gpio, level, tick)<br><br>cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf)<br><br>cb2 = pi.callback(4, pigpio.EITHER_EDGE)<br><br>cb3 = pi.callback(17)<br><br>print(cb3.tally())<br><br>cb3.reset_tally()<br><br>cb1.cancel() # To cancel callback cb1.<br></code><h3><a name="clear_bank_1">clear_bank_1<small>(<a href="#bits">bits</a>)</small></h3>
|
|
Clears GPIO 0-31 if the corresponding bit in bits is set.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>bits:= a 32 bit mask with 1 set if the corresponding GPIO is<br> to be cleared.<br></samp><br><br>A returned status of PI_SOME_PERMITTED indicates that the user
|
|
is not allowed to write to one or more of the GPIO.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.clear_bank_1(int("111110010000",2))<br></code><h3><a name="clear_bank_2">clear_bank_2<small>(<a href="#bits">bits</a>)</small></h3>
|
|
Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>bits:= a 32 bit mask with 1 set if the corresponding GPIO is<br> to be cleared.<br></samp><br><br>A returned status of PI_SOME_PERMITTED indicates that the user
|
|
is not allowed to write to one or more of the GPIO.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.clear_bank_2(0x1010)<br></code><h3><a name="custom_1">custom_1<small>(<a href="#arg1">arg1</a>, <a href="#arg2">arg2</a>, <a href="#argx">argx</a>)</small></h3>
|
|
Calls a pigpio function customised by the user.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>arg1:= >=0, default 0.<br>arg2:= >=0, default 0.<br>argx:= extra arguments (each 0-255), default empty.<br></samp><br><br>The returned value is an integer which by convention
|
|
should be >=0 for OK and <0 for error.
|
|
<br><br><b><small>Example</small></b><br><br><code>value = pi.custom_1()<br><br>value = pi.custom_1(23)<br><br>value = pi.custom_1(0, 55)<br><br>value = pi.custom_1(23, 56, [1, 5, 7])<br><br>value = pi.custom_1(23, 56, b"hello")<br><br>value = pi.custom_1(23, 56, "hello")<br></code><h3><a name="custom_2">custom_2<small>(<a href="#arg1">arg1</a>, <a href="#argx">argx</a>, <a href="#retMax">retMax</a>)</small></h3>
|
|
Calls a pigpio function customised by the user.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> arg1:= >=0, default 0.<br> argx:= extra arguments (each 0-255), default empty.<br>retMax:= >=0, maximum number of bytes to return, default 8192.<br></samp><br><br>The returned value is a tuple of the number of bytes
|
|
returned and a bytearray containing the bytes. If
|
|
there was an error the number of bytes read will be
|
|
less than zero (and will contain the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(count, data) = pi.custom_2()<br><br>(count, data) = pi.custom_2(23)<br><br>(count, data) = pi.custom_2(23, [1, 5, 7])<br><br>(count, data) = pi.custom_2(23, b"hello")<br><br>(count, data) = pi.custom_2(23, "hello", 128)<br></code><h3><a name="delete_script">delete_script<small>(<a href="#script_id">script_id</a>)</small></h3>
|
|
Deletes a stored script.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:= id of stored script.<br></samp><br><br><b><small>Example</small></b><br><br><code>status = pi.delete_script(sid)<br></code><h3><a name="event_callback">event_callback<small>(<a href="#event">event</a>, <a href="#func">func</a>)</small></h3>
|
|
Calls a user supplied function (a callback) whenever the
|
|
specified event is signalled.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>event:= 0-31.<br> func:= user supplied callback function.<br></samp><br><br>The user supplied callback receives two parameters, the event id,
|
|
and the tick.
|
|
<br><br>If a user callback is not specified a default tally callback is
|
|
provided which simply counts events. The count may be retrieved
|
|
by calling the tally function. The count may be reset to zero
|
|
by calling the reset_tally function.
|
|
<br><br>The callback may be cancelled by calling the event_cancel function.
|
|
<br><br>An event may have multiple callbacks (although I can't think of
|
|
a reason to do so).
|
|
<br><br><b><small>Example</small></b><br><br><code>def cbf(event, tick):<br> print(event, tick)<br><br>cb1 = pi.event_callback(22, cbf)<br><br>cb2 = pi.event_callback(4)<br><br>print(cb2.tally())<br><br>cb2.reset_tally()<br><br>cb1.event_cancel() # To cancel callback cb1.<br></code><h3><a name="event_trigger">event_trigger<small>(<a href="#event">event</a>)</small></h3>
|
|
This function signals the occurrence of an event.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>event:= 0-31, the event<br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_EVENT_ID.
|
|
<br><br>An event is a signal used to inform one or more consumers
|
|
to start an action. Each consumer which has registered an
|
|
interest in the event (e.g. by calling <a href="#event_callback">event_callback</a>) will
|
|
be informed by a callback.
|
|
<br><br>One event, EVENT_BSC (31) is predefined. This event is
|
|
auto generated on BSC slave activity.
|
|
<br><br>The meaning of other events is arbitrary.
|
|
<br><br>Note that other than its id and its tick there is no data associated
|
|
with an event.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.event_trigger(23)<br></code><h3><a name="file_close">file_close<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Closes the file associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#file_open">file_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.file_close(handle)<br></code><h3><a name="file_list">file_list<small>(<a href="#fpattern">fpattern</a>)</small></h3>
|
|
Returns a list of files which match a pattern.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>fpattern:= file pattern to match.<br></samp><br><br>Returns the number of returned bytes if OK, otherwise
|
|
PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH.
|
|
<br><br>The pattern must match an entry in /opt/pigpio/access. The
|
|
pattern may contain wildcards. See <a href="#file_open">file_open</a>.
|
|
<br><br>NOTE
|
|
<br><br>The returned value is not the number of files, it is the number
|
|
of bytes in the buffer. The file names are separated by newline
|
|
characters.
|
|
<br><br><b><small>Example</small></b><br><br><code>#!/usr/bin/env python<br><br>import pigpio<br><br>pi = pigpio.pi()<br><br>if not pi.connected:<br> exit()<br><br># Assumes /opt/pigpio/access contains the following line:<br># /ram/*.c r<br><br>c, d = pi.file_list("/ram/p*.c")<br>if c > 0:<br> print(d)<br><br>pi.stop()<br></code><h3><a name="file_open">file_open<small>(<a href="#file_name">file_name</a>, <a href="#file_mode">file_mode</a>)</small></h3>
|
|
This function returns a handle to a file opened in a specified mode.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>file_name:= the file to open.<br>file_mode:= the file open mode.<br></samp><br><br>Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE,
|
|
PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE,
|
|
PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR.
|
|
<br><br><b><small>Example</small></b><br><br><code>h = pi.file_open("/home/pi/shared/dir_3/file.txt",<br> pigpio.FILE_WRITE | pigpio.FILE_CREATE)<br><br>pi.file_write(h, "Hello world")<br><br>pi.file_close(h)<br></code><br><br>File
|
|
<br><br>A file may only be opened if permission is granted by an entry
|
|
in /opt/pigpio/access. This is intended to allow remote access
|
|
to files in a more or less controlled manner.
|
|
<br><br>Each entry in /opt/pigpio/access takes the form of a file path
|
|
which may contain wildcards followed by a single letter permission.
|
|
The permission may be R for read, W for write, U for read/write,
|
|
and N for no access.
|
|
<br><br>Where more than one entry matches a file the most specific rule
|
|
applies. If no entry matches a file then access is denied.
|
|
<br><br>Suppose /opt/pigpio/access contains the following entries:
|
|
<br><br><code>/home/* n<br>/home/pi/shared/dir_1/* w<br>/home/pi/shared/dir_2/* r<br>/home/pi/shared/dir_3/* u<br>/home/pi/shared/dir_1/file.txt n<br></code><br><br>Files may be written in directory dir_1 with the exception
|
|
of file.txt.
|
|
<br><br>Files may be read in directory dir_2.
|
|
<br><br>Files may be read and written in directory dir_3.
|
|
<br><br>If a directory allows read, write, or read/write access then files
|
|
may be created in that directory.
|
|
<br><br>In an attempt to prevent risky permissions the following paths are
|
|
ignored in /opt/pigpio/access:
|
|
<br><br><code>a path containing ..<br>a path containing only wildcards (*?)<br>a path containing less than two non-wildcard parts<br></code><br><br>Mode
|
|
<br><br>The mode may have the following values:
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Constant</td><td>Value</td><td>Meaning</td></tr><tr><td>FILE_READ</td><td>1</td><td>open file for reading</td></tr><tr><td>FILE_WRITE</td><td>2</td><td>open file for writing</td></tr><tr><td>FILE_RW</td><td>3</td><td>open file for reading and writing</td></tr></tbody></table><br><br>The following values may be or'd into the mode:
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Name</td><td>Value</td><td>Meaning</td></tr><tr><td>FILE_APPEND</td><td>4</td><td>All writes append data to the end of the file</td></tr><tr><td>FILE_CREATE</td><td>8</td><td>The file is created if it doesn't exist</td></tr><tr><td>FILE_TRUNC</td><td>16</td><td>The file is truncated</td></tr></tbody></table><br><br>Newly created files are owned by root with permissions owner
|
|
read and write.
|
|
<br><br><b><small>Example</small></b><br><br><code>#!/usr/bin/env python<br><br>import pigpio<br><br>pi = pigpio.pi()<br><br>if not pi.connected:<br> exit()<br><br># Assumes /opt/pigpio/access contains the following line:<br># /ram/*.c r<br><br>handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ)<br><br>done = False<br><br>while not done:<br> c, d = pi.file_read(handle, 60000)<br> if c > 0:<br> print(d)<br> else:<br> done = True<br><br>pi.file_close(handle)<br><br>pi.stop()<br></code><h3><a name="file_read">file_read<small>(<a href="#handle">handle</a>, <a href="#count">count</a>)</small></h3>
|
|
Reads up to count bytes from the file associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#file_open">file_open</a>).<br> count:= >0, the number of bytes to read.<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(b, d) = pi.file_read(h2, 100)<br>if b > 0:<br> # process read data<br></code><h3><a name="file_seek">file_seek<small>(<a href="#handle">handle</a>, <a href="#seek_offset">seek_offset</a>, <a href="#seek_from">seek_from</a>)</small></h3>
|
|
Seeks to a position relative to the start, current position,
|
|
or end of the file. Returns the new position.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> handle:= >=0 (as returned by a prior call to <a href="#file_open">file_open</a>).<br>seek_offset:= byte offset.<br> seek_from:= FROM_START, FROM_CURRENT, or FROM_END.<br></samp><br><br><b><small>Example</small></b><br><br><code>new_pos = pi.file_seek(h, 100, pigpio.FROM_START)<br><br>cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT)<br><br>file_size = pi.file_seek(h, 0, pigpio.FROM_END)<br></code><h3><a name="file_write">file_write<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
|
|
Writes the data bytes to the file associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#file_open">file_open</a>).<br> data:= the bytes to write.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.file_write(h1, b'\x02\x03\x04')<br><br>pi.file_write(h2, b'help')<br><br>pi.file_write(h2, "hello")<br><br>pi.file_write(h1, [2, 3, 4])<br></code><h3><a name="get_PWM_dutycycle">get_PWM_dutycycle<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
|
|
Returns the PWM dutycycle being used on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br></samp><br><br>Returns the PWM dutycycle.
|
|
<br><br>For normal PWM the dutycycle will be out of the defined range
|
|
for the GPIO (see <a href="#get_PWM_range">get_PWM_range</a>).
|
|
<br><br>If a hardware clock is active on the GPIO the reported
|
|
dutycycle will be 500000 (500k) out of 1000000 (1M).
|
|
<br><br>If hardware PWM is active on the GPIO the reported dutycycle
|
|
will be out of a 1000000 (1M).
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_dutycycle(4, 25)<br>print(pi.get_PWM_dutycycle(4))<br>25<br><br>pi.set_PWM_dutycycle(4, 203)<br>print(pi.get_PWM_dutycycle(4))<br>203<br></code><h3><a name="get_PWM_frequency">get_PWM_frequency<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
|
|
Returns the frequency of PWM being used on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br></samp><br><br>Returns the frequency (in Hz) used for the GPIO.
|
|
<br><br>For normal PWM the frequency will be that defined for the GPIO
|
|
by <a href="#set_PWM_frequency">set_PWM_frequency</a>.
|
|
<br><br>If a hardware clock is active on the GPIO the reported frequency
|
|
will be that set by <a href="#hardware_clock">hardware_clock</a>.
|
|
<br><br>If hardware PWM is active on the GPIO the reported frequency
|
|
will be that set by <a href="#hardware_PWM">hardware_PWM</a>.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_frequency(4,0)<br>print(pi.get_PWM_frequency(4))<br>10<br><br>pi.set_PWM_frequency(4, 800)<br>print(pi.get_PWM_frequency(4))<br>800<br></code><h3><a name="get_PWM_range">get_PWM_range<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
|
|
Returns the range of PWM values being used on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br></samp><br><br>If a hardware clock or hardware PWM is active on the GPIO
|
|
the reported range will be 1000000 (1M).
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_range(9, 500)<br>print(pi.get_PWM_range(9))<br>500<br></code><h3><a name="get_PWM_real_range">get_PWM_real_range<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
|
|
Returns the real (underlying) range of PWM values being
|
|
used on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br></samp><br><br>If a hardware clock is active on the GPIO the reported
|
|
real range will be 1000000 (1M).
|
|
<br><br>If hardware PWM is active on the GPIO the reported real range
|
|
will be approximately 250M divided by the set PWM frequency.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_frequency(4, 800)<br>print(pi.get_PWM_real_range(4))<br>250<br></code><h3><a name="get_current_tick">get_current_tick<small>()</small></h3>
|
|
Returns the current system tick.
|
|
<br><br>Tick is the number of microseconds since system boot. As an
|
|
unsigned 32 bit quantity tick wraps around approximately
|
|
every 71.6 minutes.
|
|
<br><br><b><small>Example</small></b><br><br><code>t1 = pi.get_current_tick()<br>time.sleep(1)<br>t2 = pi.get_current_tick()<br></code><h3><a name="get_hardware_revision">get_hardware_revision<small>()</small></h3>
|
|
Returns the Pi's hardware revision number.
|
|
<br><br>The hardware revision is the last few characters on the
|
|
Revision line of /proc/cpuinfo.
|
|
<br><br>The revision number can be used to determine the assignment
|
|
of GPIO to pins (see <a href="#gpio">gpio</a>).
|
|
<br><br>There are at least three types of board.
|
|
<br><br>Type 1 boards have hardware revision numbers of 2 and 3.
|
|
<br><br>Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
|
|
<br><br>Type 3 boards have hardware revision numbers of 16 or greater.
|
|
<br><br>If the hardware revision can not be found or is not a valid
|
|
hexadecimal number the function returns 0.
|
|
<br><br><b><small>Example</small></b><br><br><code>print(pi.get_hardware_revision())<br>2<br></code><h3><a name="get_mode">get_mode<small>(<a href="#gpio">gpio</a>)</small></h3>
|
|
Returns the GPIO mode.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>gpio:= 0-53.<br></samp><br><br>Returns a value as follows
|
|
<br><br><code>0 = INPUT<br>1 = OUTPUT<br>2 = ALT5<br>3 = ALT4<br>4 = ALT0<br>5 = ALT1<br>6 = ALT2<br>7 = ALT3<br></code><br><br><b><small>Example</small></b><br><br><code>print(pi.get_mode(0))<br>4<br></code><h3><a name="get_pad_strength">get_pad_strength<small>(<a href="#pad">pad</a>)</small></h3>
|
|
This function returns the pad drive strength in mA.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>pad:= 0-2, the pad to get.<br></samp><br><br>Returns the pad drive strength if OK, otherwise PI_BAD_PAD.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Pad</td><td>GPIO</td></tr><tr><td>0</td><td>0-27</td></tr><tr><td>1</td><td>28-45</td></tr><tr><td>2</td><td>46-53</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>strength = pi.get_pad_strength(0) # Get pad 0 strength.<br></code><h3><a name="get_pigpio_version">get_pigpio_version<small>()</small></h3>
|
|
Returns the pigpio software version.
|
|
<br><br><b><small>Example</small></b><br><br><code>v = pi.get_pigpio_version()<br></code><h3><a name="get_servo_pulsewidth">get_servo_pulsewidth<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
|
|
Returns the servo pulsewidth being used on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br></samp><br><br>Returns the servo pulsewidth.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_servo_pulsewidth(4, 525)<br>print(pi.get_servo_pulsewidth(4))<br>525<br><br>pi.set_servo_pulsewidth(4, 2130)<br>print(pi.get_servo_pulsewidth(4))<br>2130<br></code><h3><a name="gpio_trigger">gpio_trigger<small>(<a href="#user_gpio">user_gpio</a>, <a href="#pulse_len">pulse_len</a>, <a href="#level">level</a>)</small></h3>
|
|
Send a trigger pulse to a GPIO. The GPIO is set to
|
|
level for pulse_len microseconds and then reset to not level.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31<br>pulse_len:= 1-100<br> level:= 0-1<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.gpio_trigger(23, 10, 1)<br></code><h3><a name="hardware_PWM">hardware_PWM<small>(<a href="#gpio">gpio</a>, <a href="#PWMfreq">PWMfreq</a>, <a href="#PWMduty">PWMduty</a>)</small></h3>
|
|
Starts hardware PWM on a GPIO at the specified frequency
|
|
and dutycycle. Frequencies above 30MHz are unlikely to work.
|
|
<br><br>NOTE: Any waveform started by <a href="#wave_send_once">wave_send_once</a>,
|
|
<a href="#wave_send_repeat">wave_send_repeat</a>, or <a href="#wave_chain">wave_chain</a> will be cancelled.
|
|
<br><br>This function is only valid if the pigpio main clock is PCM.
|
|
The main clock defaults to PCM but may be overridden when the
|
|
pigpio daemon is started (option -t).
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> gpio:= see descripton<br>PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711).<br>PWMduty:= 0 (off) to 1000000 (1M)(fully on).<br></samp><br><br>Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO,
|
|
PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ.
|
|
<br><br>The same PWM channel is available on multiple GPIO.
|
|
The latest frequency and dutycycle setting will be used
|
|
by all GPIO which share a PWM channel.
|
|
<br><br>The GPIO must be one of the following:
|
|
<br><br><code>12 PWM channel 0 All models but A and B<br>13 PWM channel 1 All models but A and B<br>18 PWM channel 0 All models<br>19 PWM channel 1 All models but A and B<br><br>40 PWM channel 0 Compute module only<br>41 PWM channel 1 Compute module only<br>45 PWM channel 1 Compute module only<br>52 PWM channel 0 Compute module only<br>53 PWM channel 1 Compute module only<br></code><br><br>The actual number of steps beween off and fully on is the
|
|
integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711).
|
|
<br><br>The actual frequency set is 250M/steps (375M/steps
|
|
for the BCM2711).
|
|
<br><br>There will only be a million steps for a PWMfreq of 250
|
|
(375 for the BCM2711). Lower frequencies will have more
|
|
steps and higher frequencies will have fewer steps.
|
|
PWMduty is automatically scaled to take this into account.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle<br><br>pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle<br></code><h3><a name="hardware_clock">hardware_clock<small>(<a href="#gpio">gpio</a>, <a href="#clkfreq">clkfreq</a>)</small></h3>
|
|
Starts a hardware clock on a GPIO at the specified frequency.
|
|
Frequencies above 30MHz are unlikely to work.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> gpio:= see description<br>clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711)<br></samp><br><br>Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO,
|
|
PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS.
|
|
<br><br>The same clock is available on multiple GPIO. The latest
|
|
frequency setting will be used by all GPIO which share a clock.
|
|
<br><br>The GPIO must be one of the following:
|
|
<br><br><code>4 clock 0 All models<br>5 clock 1 All models but A and B (reserved for system use)<br>6 clock 2 All models but A and B<br>20 clock 0 All models but A and B<br>21 clock 1 All models but A and Rev.2 B (reserved for system use)<br><br>32 clock 0 Compute module only<br>34 clock 0 Compute module only<br>42 clock 1 Compute module only (reserved for system use)<br>43 clock 2 Compute module only<br>44 clock 1 Compute module only (reserved for system use)<br></code><br><br>Access to clock 1 is protected by a password as its use will
|
|
likely crash the Pi. The password is given by or'ing 0x5A000000
|
|
with the GPIO number.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.hardware_clock(4, 5000) # 5 KHz clock on GPIO 4<br><br>pi.hardware_clock(4, 40000000) # 40 MHz clock on GPIO 4<br></code><h3><a name="i2c_block_process_call">i2c_block_process_call<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#data">data</a>)</small></h3>
|
|
Writes data bytes to the specified register of the device
|
|
associated with handle and reads a device specified number
|
|
of bytes of data in return.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br> data:= the bytes to write.<br></samp><br><br>The SMBus 2.0 documentation states that a minimum of 1 byte may
|
|
be sent and a minimum of 1 byte may be received. The total
|
|
number of bytes sent/received must be 32 or less.
|
|
<br><br>SMBus 2.0 5.5.8 - Block write-block read.
|
|
<code>S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A]<br> S Addr Rd [A] [Count] A [Data] ... A P<br></code><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00')<br><br>(b, d) = pi.i2c_block_process_call(h, 10, b'abcdr')<br><br>(b, d) = pi.i2c_block_process_call(h, 10, "abracad")<br><br>(b, d) = pi.i2c_block_process_call(h, 10, [2, 5, 16])<br></code><h3><a name="i2c_close">i2c_close<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Closes the I2C device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.i2c_close(h)<br></code><h3><a name="i2c_open">i2c_open<small>(<a href="#i2c_bus">i2c_bus</a>, <a href="#i2c_address">i2c_address</a>, <a href="#i2c_flags">i2c_flags</a>)</small></h3>
|
|
Returns a handle (>=0) for the device at the I2C bus address.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> i2c_bus:= >=0.<br>i2c_address:= 0-0x7F.<br> i2c_flags:= 0, no flags are currently defined.<br></samp><br><br>Physically buses 0 and 1 are available on the Pi. Higher
|
|
numbered buses will be available if a kernel supported bus
|
|
multiplexor is being used.
|
|
<br><br>The GPIO used are given in the following table.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>SDA</td><td>SCL</td></tr><tr><td>I2C 0</td><td>0</td><td>1</td></tr><tr><td>I2C 1</td><td>2</td><td>3</td></tr></tbody></table><br><br>For the SMBus commands the low level transactions are shown
|
|
at the end of the function description. The following
|
|
abbreviations are used:
|
|
<br><br><code>S (1 bit) : Start bit<br>P (1 bit) : Stop bit<br>Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.<br>A, NA (1 bit) : Accept and not accept bit.<br>Addr (7 bits): I2C 7 bit address.<br>reg (8 bits): Command byte, which often selects a register.<br>Data (8 bits): A data byte.<br>Count (8 bits): A byte defining the length of a block operation.<br><br>[..]: Data sent by the device.<br></code><br><br><b><small>Example</small></b><br><br><code>h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1<br></code><h3><a name="i2c_process_call">i2c_process_call<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#word_val">word_val</a>)</small></h3>
|
|
Writes 16 bits of data to the specified register of the device
|
|
associated with handle and reads 16 bits of data in return.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br>word_val:= 0-65535, the value to write.<br></samp><br><br>SMBus 2.0 5.5.6 - Process call.
|
|
<code>S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A]<br> S Addr Rd [A] [DataLow] A [DataHigh] NA P<br></code><br><br><b><small>Example</small></b><br><br><code>r = pi.i2c_process_call(h, 4, 0x1231)<br>r = pi.i2c_process_call(h, 6, 0)<br></code><h3><a name="i2c_read_block_data">i2c_read_block_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>)</small></h3>
|
|
Reads a block of up to 32 bytes from the specified register of
|
|
the device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br></samp><br><br>SMBus 2.0 5.5.7 - Block read.
|
|
<code>S Addr Wr [A] reg [A]<br> S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P<br></code><br><br>The amount of returned data is set by the device.
|
|
<br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(b, d) = pi.i2c_read_block_data(h, 10)<br>if b >= 0:<br> # process data<br>else:<br> # process read failure<br></code><h3><a name="i2c_read_byte">i2c_read_byte<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Reads a single byte from the device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br></samp><br><br>SMBus 2.0 5.5.3 - Receive byte.
|
|
<code>S Addr Rd [A] [Data] NA P<br></code><br><br><b><small>Example</small></b><br><br><code>b = pi.i2c_read_byte(2) # read a byte from device 2<br></code><h3><a name="i2c_read_byte_data">i2c_read_byte_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>)</small></h3>
|
|
Reads a single byte from the specified register of the device
|
|
associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br></samp><br><br>SMBus 2.0 5.5.5 - Read byte.
|
|
<code>S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P<br></code><br><br><b><small>Example</small></b><br><br><code># read byte from reg 17 of device 2<br>b = pi.i2c_read_byte_data(2, 17)<br><br># read byte from reg 1 of device 0<br>b = pi.i2c_read_byte_data(0, 1)<br></code><h3><a name="i2c_read_device">i2c_read_device<small>(<a href="#handle">handle</a>, <a href="#count">count</a>)</small></h3>
|
|
Returns count bytes read from the raw device associated
|
|
with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> count:= >0, the number of bytes to read.<br></samp><br><br><code>S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P<br></code><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(count, data) = pi.i2c_read_device(h, 12)<br></code><h3><a name="i2c_read_i2c_block_data">i2c_read_i2c_block_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#count">count</a>)</small></h3>
|
|
Reads count bytes from the specified register of the device
|
|
associated with handle . The count may be 1-32.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br> count:= >0, the number of bytes to read.<br></samp><br><br><code>S Addr Wr [A] reg [A]<br> S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P<br></code><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(b, d) = pi.i2c_read_i2c_block_data(h, 4, 32)<br>if b >= 0:<br> # process data<br>else:<br> # process read failure<br></code><h3><a name="i2c_read_word_data">i2c_read_word_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>)</small></h3>
|
|
Reads a single 16 bit word from the specified register of the
|
|
device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br></samp><br><br>SMBus 2.0 5.5.5 - Read word.
|
|
<code>S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P<br></code><br><br><b><small>Example</small></b><br><br><code># read word from reg 2 of device 3<br>w = pi.i2c_read_word_data(3, 2)<br><br># read word from reg 7 of device 2<br>w = pi.i2c_read_word_data(2, 7)<br></code><h3><a name="i2c_write_block_data">i2c_write_block_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#data">data</a>)</small></h3>
|
|
Writes up to 32 bytes to the specified register of the device
|
|
associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br> data:= the bytes to write.<br></samp><br><br>SMBus 2.0 5.5.7 - Block write.
|
|
<code>S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A]<br> datan [A] P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_block_data(4, 5, b'hello')<br><br>pi.i2c_write_block_data(4, 5, "data bytes")<br><br>pi.i2c_write_block_data(5, 0, b'\x00\x01\x22')<br><br>pi.i2c_write_block_data(6, 2, [0, 1, 0x22])<br></code><h3><a name="i2c_write_byte">i2c_write_byte<small>(<a href="#handle">handle</a>, <a href="#byte_val">byte_val</a>)</small></h3>
|
|
Sends a single byte to the device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br>byte_val:= 0-255, the value to write.<br></samp><br><br>SMBus 2.0 5.5.2 - Send byte.
|
|
<code>S Addr Wr [A] byte_val [A] P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_byte(1, 17) # send byte 17 to device 1<br>pi.i2c_write_byte(2, 0x23) # send byte 0x23 to device 2<br></code><h3><a name="i2c_write_byte_data">i2c_write_byte_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#byte_val">byte_val</a>)</small></h3>
|
|
Writes a single byte to the specified register of the device
|
|
associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br>byte_val:= 0-255, the value to write.<br></samp><br><br>SMBus 2.0 5.5.4 - Write byte.
|
|
<code>S Addr Wr [A] reg [A] byte_val [A] P<br></code><br><br><b><small>Example</small></b><br><br><code># send byte 0xC5 to reg 2 of device 1<br>pi.i2c_write_byte_data(1, 2, 0xC5)<br><br># send byte 9 to reg 4 of device 2<br>pi.i2c_write_byte_data(2, 4, 9)<br></code><h3><a name="i2c_write_device">i2c_write_device<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
|
|
Writes the data bytes to the raw device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> data:= the bytes to write.<br></samp><br><br><code>S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_device(h, b"\x12\x34\xA8")<br><br>pi.i2c_write_device(h, b"help")<br><br>pi.i2c_write_device(h, 'help')<br><br>pi.i2c_write_device(h, [23, 56, 231])<br></code><h3><a name="i2c_write_i2c_block_data">i2c_write_i2c_block_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#data">data</a>)</small></h3>
|
|
Writes data bytes to the specified register of the device
|
|
associated with handle . 1-32 bytes may be written.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br> data:= the bytes to write.<br></samp><br><br><code>S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_i2c_block_data(4, 5, 'hello')<br><br>pi.i2c_write_i2c_block_data(4, 5, b'hello')<br><br>pi.i2c_write_i2c_block_data(5, 0, b'\x00\x01\x22')<br><br>pi.i2c_write_i2c_block_data(6, 2, [0, 1, 0x22])<br></code><h3><a name="i2c_write_quick">i2c_write_quick<small>(<a href="#handle">handle</a>, <a href="#bit">bit</a>)</small></h3>
|
|
Sends a single bit to the device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> bit:= 0 or 1, the value to write.<br></samp><br><br>SMBus 2.0 5.5.1 - Quick command.
|
|
<code>S Addr bit [A] P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_quick(0, 1) # send 1 to device 0<br>pi.i2c_write_quick(3, 0) # send 0 to device 3<br></code><h3><a name="i2c_write_word_data">i2c_write_word_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#word_val">word_val</a>)</small></h3>
|
|
Writes a single 16 bit word to the specified register of the
|
|
device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> reg:= >=0, the device register.<br>word_val:= 0-65535, the value to write.<br></samp><br><br>SMBus 2.0 5.5.4 - Write word.
|
|
<code>S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P<br></code><br><br><b><small>Example</small></b><br><br><code># send word 0xA0C5 to reg 5 of device 4<br>pi.i2c_write_word_data(4, 5, 0xA0C5)<br><br># send word 2 to reg 2 of device 5<br>pi.i2c_write_word_data(5, 2, 23)<br></code><h3><a name="i2c_zip">i2c_zip<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
|
|
This function executes a sequence of I2C operations. The
|
|
operations to be performed are specified by the contents of data
|
|
which contains the concatenated command codes and associated data.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#i2c_open">i2c_open</a>).<br> data:= the concatenated I2C commands, see below<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0])<br></code><br><br>The following command codes are supported:
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Name</td><td>Cmd & Data</td><td>Meaning</td></tr><tr><td>End</td><td>0</td><td>No more commands</td></tr><tr><td>Escape</td><td>1</td><td>Next P is two bytes</td></tr><tr><td>On</td><td>2</td><td>Switch combined flag on</td></tr><tr><td>Off</td><td>3</td><td>Switch combined flag off</td></tr><tr><td>Address</td><td>4 P</td><td>Set I2C address to P</td></tr><tr><td>Flags</td><td>5 lsb msb</td><td>Set I2C flags to lsb + (msb << 8)</td></tr><tr><td>Read</td><td>6 P</td><td>Read P bytes of data</td></tr><tr><td>Write</td><td>7 P ...</td><td>Write P bytes of data</td></tr></tbody></table><br><br>The address, read, and write commands take a parameter P.
|
|
Normally P is one byte (0-255). If the command is preceded by
|
|
the Escape command then P is two bytes (0-65535, least significant
|
|
byte first).
|
|
<br><br>The address defaults to that associated with the handle.
|
|
The flags default to 0. The address and flags maintain their
|
|
previous value until updated.
|
|
<br><br>Any read I2C data is concatenated in the returned bytearray.
|
|
<br><br><b><small>Example</small></b><br><br><code>Set address 0x53, write 0x32, read 6 bytes<br>Set address 0x1E, write 0x03, read 6 bytes<br>Set address 0x68, write 0x1B, read 8 bytes<br>End<br><br>0x04 0x53 0x07 0x01 0x32 0x06 0x06<br>0x04 0x1E 0x07 0x01 0x03 0x06 0x06<br>0x04 0x68 0x07 0x01 0x1B 0x06 0x08<br>0x00<br></code><h3><a name="notify_begin">notify_begin<small>(<a href="#handle">handle</a>, <a href="#bits">bits</a>)</small></h3>
|
|
Starts notifications on a handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#notify_open">notify_open</a>)<br> bits:= a 32 bit mask indicating the GPIO to be notified.<br></samp><br><br>The notification sends state changes for each GPIO whose
|
|
corresponding bit in bits is set.
|
|
<br><br>The following code starts notifications for GPIO 1, 4,
|
|
6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010).
|
|
<br><br><b><small>Example</small></b><br><br><code>h = pi.notify_open()<br>if h >= 0:<br> pi.notify_begin(h, 1234)<br></code><h3><a name="notify_close">notify_close<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Stops notifications on a handle and releases the handle for reuse.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#notify_open">notify_open</a>)<br></samp><br><br><b><small>Example</small></b><br><br><code>h = pi.notify_open()<br>if h >= 0:<br> pi.notify_begin(h, 1234)<br> ...<br> pi.notify_close(h)<br> ...<br></code><h3><a name="notify_open">notify_open<small>()</small></h3>
|
|
Returns a notification handle (>=0).
|
|
<br><br>A notification is a method for being notified of GPIO state
|
|
changes via a pipe.
|
|
<br><br>Pipes are only accessible from the local machine so this
|
|
function serves no purpose if you are using Python from a
|
|
remote machine. The in-built (socket) notifications
|
|
provided by <a href="#callback">callback</a> should be used instead.
|
|
<br><br>Notifications for handle x will be available at the pipe
|
|
named /dev/pigpiox (where x is the handle number).
|
|
<br><br>E.g. if the function returns 15 then the notifications must be
|
|
read from /dev/pigpio15.
|
|
<br><br>Notifications have the following structure:
|
|
<br><br><code>H seqno<br>H flags<br>I tick<br>I level<br></code><br><br>seqno: starts at 0 each time the handle is opened and then
|
|
increments by one for each report.
|
|
<br><br>flags: three flags are defined, PI_NTFY_FLAGS_WDOG,
|
|
PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT.
|
|
<br><br>If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the
|
|
flags indicate a GPIO which has had a watchdog timeout.
|
|
<br><br>If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep
|
|
alive signal on the pipe/socket and is sent once a minute
|
|
in the absence of other notification activity.
|
|
<br><br>If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the
|
|
flags indicate an event which has been triggered.
|
|
<br><br>tick: the number of microseconds since system boot. It wraps
|
|
around after 1h12m.
|
|
<br><br>level: indicates the level of each GPIO. If bit 1<<x is set
|
|
then GPIO x is high.
|
|
<br><br><b><small>Example</small></b><br><br><code>h = pi.notify_open()<br>if h >= 0:<br> pi.notify_begin(h, 1234)<br></code><h3><a name="notify_pause">notify_pause<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Pauses notifications on a handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#notify_open">notify_open</a>)<br></samp><br><br>Notifications for the handle are suspended until
|
|
<a href="#notify_begin">notify_begin</a> is called again.
|
|
<br><br><b><small>Example</small></b><br><br><code>h = pi.notify_open()<br>if h >= 0:<br> pi.notify_begin(h, 1234)<br> ...<br> pi.notify_pause(h)<br> ...<br> pi.notify_begin(h, 1234)<br> ...<br></code><h3><a name="read">read<small>(<a href="#gpio">gpio</a>)</small></h3>
|
|
Returns the GPIO level.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>gpio:= 0-53.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.set_mode(23, pigpio.INPUT)<br><br>pi.set_pull_up_down(23, pigpio.PUD_DOWN)<br>print(pi.read(23))<br>0<br><br>pi.set_pull_up_down(23, pigpio.PUD_UP)<br>print(pi.read(23))<br>1<br></code><h3><a name="read_bank_1">read_bank_1<small>()</small></h3>
|
|
Returns the levels of the bank 1 GPIO (GPIO 0-31).
|
|
<br><br>The returned 32 bit integer has a bit set if the corresponding
|
|
GPIO is high. GPIO n has bit value (1<<n).
|
|
<br><br><b><small>Example</small></b><br><br><code>print(bin(pi.read_bank_1()))<br>0b10010100000011100100001001111<br></code><h3><a name="read_bank_2">read_bank_2<small>()</small></h3>
|
|
Returns the levels of the bank 2 GPIO (GPIO 32-53).
|
|
<br><br>The returned 32 bit integer has a bit set if the corresponding
|
|
GPIO is high. GPIO n has bit value (1<<(n-32)).
|
|
<br><br><b><small>Example</small></b><br><br><code>print(bin(pi.read_bank_2()))<br>0b1111110000000000000000<br></code><h3><a name="run_script">run_script<small>(<a href="#script_id">script_id</a>, <a href="#params">params</a>)</small></h3>
|
|
Runs a stored script.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:= id of stored script.<br> params:= up to 10 parameters required by the script.<br></samp><br><br><b><small>Example</small></b><br><br><code>s = pi.run_script(sid, [par1, par2])<br><br>s = pi.run_script(sid)<br><br>s = pi.run_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])<br></code><h3><a name="script_status">script_status<small>(<a href="#script_id">script_id</a>)</small></h3>
|
|
Returns the run status of a stored script as well as the
|
|
current values of parameters 0 to 9.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:= id of stored script.<br></samp><br><br>The run status may be
|
|
<br><br><code>PI_SCRIPT_INITING<br>PI_SCRIPT_HALTED<br>PI_SCRIPT_RUNNING<br>PI_SCRIPT_WAITING<br>PI_SCRIPT_FAILED<br></code><br><br>The return value is a tuple of run status and a list of
|
|
the 10 parameters. On error the run status will be negative
|
|
and the parameter list will be empty.
|
|
<br><br><b><small>Example</small></b><br><br><code>(s, pars) = pi.script_status(sid)<br></code><h3><a name="serial_close">serial_close<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Closes the serial device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#serial_open">serial_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.serial_close(h1)<br></code><h3><a name="serial_data_available">serial_data_available<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Returns the number of bytes available to be read from the
|
|
device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#serial_open">serial_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>rdy = pi.serial_data_available(h1)<br><br>if rdy > 0:<br> (b, d) = pi.serial_read(h1, rdy)<br></code><h3><a name="serial_open">serial_open<small>(<a href="#tty">tty</a>, <a href="#baud">baud</a>, <a href="#ser_flags">ser_flags</a>)</small></h3>
|
|
Returns a handle for the serial tty device opened
|
|
at baud bits per second. The device name must start
|
|
with /dev/tty or /dev/serial.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> tty:= the serial device to open.<br> baud:= baud rate in bits per second, see below.<br>ser_flags:= 0, no flags are currently defined.<br></samp><br><br>Normally you would only use the <a href="#serial_*">serial_*</a> functions if
|
|
you are or will be connecting to the Pi over a network. If
|
|
you will always run on the local Pi use the standard serial
|
|
module instead.
|
|
<br><br>The baud rate must be one of 50, 75, 110, 134, 150,
|
|
200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200,
|
|
38400, 57600, 115200, or 230400.
|
|
<br><br><b><small>Example</small></b><br><br><code>h1 = pi.serial_open("/dev/ttyAMA0", 300)<br><br>h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0)<br><br>h3 = pi.serial_open("/dev/serial0", 9600)<br></code><h3><a name="serial_read">serial_read<small>(<a href="#handle">handle</a>, <a href="#count">count</a>)</small></h3>
|
|
Reads up to count bytes from the device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#serial_open">serial_open</a>).<br> count:= >0, the number of bytes to read (defaults to 1000).<br></samp><br><br>The returned value is a tuple of the number of bytes read and
|
|
a bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br>If no data is ready a bytes read of zero is returned.
|
|
<b><small>Example</small></b><br><br><code>(b, d) = pi.serial_read(h2, 100)<br>if b > 0:<br> # process read data<br></code><h3><a name="serial_read_byte">serial_read_byte<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Returns a single byte from the device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#serial_open">serial_open</a>).<br></samp><br><br>If no data is ready a negative error code will be returned.
|
|
<br><br><b><small>Example</small></b><br><br><code>b = pi.serial_read_byte(h1)<br></code><h3><a name="serial_write">serial_write<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
|
|
Writes the data bytes to the device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#serial_open">serial_open</a>).<br> data:= the bytes to write.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.serial_write(h1, b'\x02\x03\x04')<br><br>pi.serial_write(h2, b'help')<br><br>pi.serial_write(h2, "hello")<br><br>pi.serial_write(h1, [2, 3, 4])<br></code><h3><a name="serial_write_byte">serial_write_byte<small>(<a href="#handle">handle</a>, <a href="#byte_val">byte_val</a>)</small></h3>
|
|
Writes a single byte to the device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> handle:= >=0 (as returned by a prior call to <a href="#serial_open">serial_open</a>).<br>byte_val:= 0-255, the value to write.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.serial_write_byte(h1, 23)<br><br>pi.serial_write_byte(h1, ord('Z'))<br></code><h3><a name="set_PWM_dutycycle">set_PWM_dutycycle<small>(<a href="#user_gpio">user_gpio</a>, <a href="#dutycycle">dutycycle</a>)</small></h3>
|
|
Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br>dutycycle:= 0-range (range defaults to 255).<br></samp><br><br>The <a href="#set_PWM_range">set_PWM_range</a> function can change the default range of 255.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_dutycycle(4, 0) # PWM off<br>pi.set_PWM_dutycycle(4, 64) # PWM 1/4 on<br>pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on<br>pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on<br>pi.set_PWM_dutycycle(4, 255) # PWM full on<br></code><h3><a name="set_PWM_frequency">set_PWM_frequency<small>(<a href="#user_gpio">user_gpio</a>, <a href="#frequency">frequency</a>)</small></h3>
|
|
Sets the frequency (in Hz) of the PWM to be used on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br>frequency:= >=0 Hz<br></samp><br><br>Returns the numerically closest frequency if OK, otherwise
|
|
PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
|
|
<br><br>If PWM is currently active on the GPIO it will be switched
|
|
off and then back on at the new frequency.
|
|
<br><br>Each GPIO can be independently set to one of 18 different
|
|
PWM frequencies.
|
|
<br><br>The selectable frequencies depend upon the sample rate which
|
|
may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The
|
|
sample rate is set when the pigpio daemon is started.
|
|
<br><br>The frequencies for each sample rate are:
|
|
<br><br><code> Hertz<br><br> 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600<br> 1250 1000 800 500 400 250 200 100 50<br><br> 2: 20000 10000 5000 4000 2500 2000 1250 1000 800<br> 625 500 400 250 200 125 100 50 25<br><br> 4: 10000 5000 2500 2000 1250 1000 625 500 400<br> 313 250 200 125 100 63 50 25 13<br>sample<br> rate<br> (us) 5: 8000 4000 2000 1600 1000 800 500 400 320<br> 250 200 160 100 80 50 40 20 10<br><br> 8: 5000 2500 1250 1000 625 500 313 250 200<br> 156 125 100 63 50 31 25 13 6<br><br> 10: 4000 2000 1000 800 500 400 250 200 160<br> 125 100 80 50 40 25 20 10 5<br></code><br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_frequency(4,0)<br>print(pi.get_PWM_frequency(4))<br>10<br><br>pi.set_PWM_frequency(4,100000)<br>print(pi.get_PWM_frequency(4))<br>8000<br></code><h3><a name="set_PWM_range">set_PWM_range<small>(<a href="#user_gpio">user_gpio</a>, <a href="#range_">range_</a>)</small></h3>
|
|
Sets the range of PWM values to be used on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31.<br> range_:= 25-40000.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_range(9, 100) # now 25 1/4, 50 1/2, 75 3/4 on<br>pi.set_PWM_range(9, 500) # now 125 1/4, 250 1/2, 375 3/4 on<br>pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on<br></code><h3><a name="set_bank_1">set_bank_1<small>(<a href="#bits">bits</a>)</small></h3>
|
|
Sets GPIO 0-31 if the corresponding bit in bits is set.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>bits:= a 32 bit mask with 1 set if the corresponding GPIO is<br> to be set.<br></samp><br><br>A returned status of PI_SOME_PERMITTED indicates that the user
|
|
is not allowed to write to one or more of the GPIO.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_bank_1(int("111110010000",2))<br></code><h3><a name="set_bank_2">set_bank_2<small>(<a href="#bits">bits</a>)</small></h3>
|
|
Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>bits:= a 32 bit mask with 1 set if the corresponding GPIO is<br> to be set.<br></samp><br><br>A returned status of PI_SOME_PERMITTED indicates that the user
|
|
is not allowed to write to one or more of the GPIO.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_bank_2(0x303)<br></code><h3><a name="set_glitch_filter">set_glitch_filter<small>(<a href="#user_gpio">user_gpio</a>, <a href="#steady">steady</a>)</small></h3>
|
|
Sets a glitch filter on a GPIO.
|
|
<br><br>Level changes on the GPIO are not reported unless the level
|
|
has been stable for at least <a href="#steady">steady</a> microseconds. The
|
|
level is then reported. Level changes of less than <a href="#steady">steady</a>
|
|
microseconds are ignored.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31<br> steady:= 0-300000<br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
|
|
<br><br>This filter affects the GPIO samples returned to callbacks set up
|
|
with <a href="#callback">callback</a> and <a href="#wait_for_edge">wait_for_edge</a>.
|
|
<br><br>It does not affect levels read by <a href="#read">read</a>,
|
|
<a href="#read_bank_1">read_bank_1</a>, or <a href="#read_bank_2">read_bank_2</a>.
|
|
<br><br>Each (stable) edge will be timestamped <a href="#steady">steady</a>
|
|
microseconds after it was first detected.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_glitch_filter(23, 100)<br></code><h3><a name="set_mode">set_mode<small>(<a href="#gpio">gpio</a>, <a href="#mode">mode</a>)</small></h3>
|
|
Sets the GPIO mode.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>gpio:= 0-53.<br>mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.set_mode( 4, pigpio.INPUT) # GPIO 4 as input<br>pi.set_mode(17, pigpio.OUTPUT) # GPIO 17 as output<br>pi.set_mode(24, pigpio.ALT2) # GPIO 24 as ALT2<br></code><h3><a name="set_noise_filter">set_noise_filter<small>(<a href="#user_gpio">user_gpio</a>, <a href="#steady">steady</a>, <a href="#active">active</a>)</small></h3>
|
|
Sets a noise filter on a GPIO.
|
|
<br><br>Level changes on the GPIO are ignored until a level which has
|
|
been stable for <a href="#steady">steady</a> microseconds is detected. Level
|
|
changes on the GPIO are then reported for <a href="#active">active</a>
|
|
microseconds after which the process repeats.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= 0-31<br> steady:= 0-300000<br> active:= 0-1000000<br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
|
|
<br><br>This filter affects the GPIO samples returned to callbacks set up
|
|
with <a href="#callback">callback</a> and <a href="#wait_for_edge">wait_for_edge</a>.
|
|
<br><br>It does not affect levels read by <a href="#read">read</a>,
|
|
<a href="#read_bank_1">read_bank_1</a>, or <a href="#read_bank_2">read_bank_2</a>.
|
|
<br><br>Level changes before and after the active period may
|
|
be reported. Your software must be designed to cope with
|
|
such reports.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_noise_filter(23, 1000, 5000)<br></code><h3><a name="set_pad_strength">set_pad_strength<small>(<a href="#pad">pad</a>, <a href="#pad_strength">pad_strength</a>)</small></h3>
|
|
This function sets the pad drive strength in mA.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> pad:= 0-2, the pad to set.<br>pad_strength:= 1-16 mA.<br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Pad</td><td>GPIO</td></tr><tr><td>0</td><td>0-27</td></tr><tr><td>1</td><td>28-45</td></tr><tr><td>2</td><td>46-53</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA.<br></code><h3><a name="set_pull_up_down">set_pull_up_down<small>(<a href="#gpio">gpio</a>, <a href="#pud">pud</a>)</small></h3>
|
|
Sets or clears the internal GPIO pull-up/down resistor.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>gpio:= 0-53.<br> pud:= PUD_UP, PUD_DOWN, PUD_OFF.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.set_pull_up_down(17, pigpio.PUD_OFF)<br>pi.set_pull_up_down(23, pigpio.PUD_UP)<br>pi.set_pull_up_down(24, pigpio.PUD_DOWN)<br></code><h3><a name="set_servo_pulsewidth">set_servo_pulsewidth<small>(<a href="#user_gpio">user_gpio</a>, <a href="#pulsewidth">pulsewidth</a>)</small></h3>
|
|
Starts (500-2500) or stops (0) servo pulses on the GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> user_gpio:= 0-31.<br>pulsewidth:= 0 (off),<br> 500 (most anti-clockwise) - 2500 (most clockwise).<br></samp><br><br>The selected pulsewidth will continue to be transmitted until
|
|
changed by a subsequent call to set_servo_pulsewidth.
|
|
<br><br>The pulsewidths supported by servos varies and should probably
|
|
be determined by experiment. A value of 1500 should always be
|
|
safe and represents the mid-point of rotation.
|
|
<br><br>You can DAMAGE a servo if you command it to move beyond its
|
|
limits.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_servo_pulsewidth(17, 0) # off<br>pi.set_servo_pulsewidth(17, 1000) # safe anti-clockwise<br>pi.set_servo_pulsewidth(17, 1500) # centre<br>pi.set_servo_pulsewidth(17, 2000) # safe clockwise<br></code><h3><a name="set_watchdog">set_watchdog<small>(<a href="#user_gpio">user_gpio</a>, <a href="#wdog_timeout">wdog_timeout</a>)</small></h3>
|
|
Sets a watchdog timeout for a GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> user_gpio:= 0-31.<br>wdog_timeout:= 0-60000.<br></samp><br><br>The watchdog is nominally in milliseconds.
|
|
<br><br>Only one watchdog may be registered per GPIO.
|
|
<br><br>The watchdog may be cancelled by setting timeout to 0.
|
|
<br><br>Once a watchdog has been started callbacks for the GPIO
|
|
will be triggered every timeout interval after the last
|
|
GPIO activity.
|
|
<br><br>The callback will receive the special level TIMEOUT.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23<br>pi.set_watchdog(23, 0) # cancel watchdog on GPIO 23<br></code><h3><a name="shell">shell<small>(<a href="#shellscr">shellscr</a>, <a href="#pstring">pstring</a>)</small></h3>
|
|
This function uses the system call to execute a shell script
|
|
with the given string as its parameter.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>shellscr:= the name of the script, only alphanumerics,<br> '-' and '_' are allowed in the name<br>pstring := the parameter string to pass to the script<br></samp><br><br>The exit status of the system call is returned if OK,
|
|
otherwise PI_BAD_SHELL_STATUS.
|
|
<br><br><a href="#shellscr">shellscr</a> must exist in /opt/pigpio/cgi and must be executable.
|
|
<br><br>The returned exit status is normally 256 times that set by
|
|
the shell script exit function. If the script can't be
|
|
found 32512 will be returned.
|
|
<br><br>The following table gives some example returned statuses:
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Script exit status</td><td>Returned system call status</td></tr><tr><td>1</td><td>256</td></tr><tr><td>5</td><td>1280</td></tr><tr><td>10</td><td>2560</td></tr><tr><td>200</td><td>51200</td></tr><tr><td>script not found</td><td>32512</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>// pass two parameters, hello and world<br>status = pi.shell("scr1", "hello world");<br><br>// pass three parameters, hello, string with spaces, and world<br>status = pi.shell("scr1", "hello 'string with spaces' world");<br><br>// pass one parameter, hello string with spaces world<br>status = pi.shell("scr1", "\"hello string with spaces world\"");<br></code><h3><a name="spi_close">spi_close<small>(<a href="#handle">handle</a>)</small></h3>
|
|
Closes the SPI device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#spi_open">spi_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.spi_close(h)<br></code><h3><a name="spi_open">spi_open<small>(<a href="#spi_channel">spi_channel</a>, <a href="#baud">baud</a>, <a href="#spi_flags">spi_flags</a>)</small></h3>
|
|
Returns a handle for the SPI device on the channel. Data
|
|
will be transferred at baud bits per second. The flags
|
|
may be used to modify the default behaviour of 4-wire
|
|
operation, mode 0, active low chip select.
|
|
<br><br>The Pi has two SPI peripherals: main and auxiliary.
|
|
<br><br>The main SPI has two chip selects (channels), the auxiliary
|
|
has three.
|
|
<br><br>The auxiliary SPI is available on all models but the A and B.
|
|
<br><br>The GPIO used are given in the following table.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>MISO</td><td>MOSI</td><td>SCLK</td><td>CE0</td><td>CE1</td><td>CE2</td></tr><tr><td>Main SPI</td><td>9</td><td>10</td><td>11</td><td>8</td><td>7</td><td>-</td></tr><tr><td>Aux SPI</td><td>19</td><td>20</td><td>21</td><td>18</td><td>17</td><td>16</td></tr></tbody></table><br><br><b><small>Parameters</small></b><br><br><samp>spi_channel:= 0-1 (0-2 for the auxiliary SPI).<br> baud:= 32K-125M (values above 30M are unlikely to work).<br> spi_flags:= see below.<br></samp><br><br>spi_flags consists of the least significant 22 bits.
|
|
<br><br><code>21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0<br> b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m<br></code><br><br>mm defines the SPI mode.
|
|
<br><br>WARNING: modes 1 and 3 do not appear to work on
|
|
the auxiliary SPI.
|
|
<br><br><code>Mode POL PHA<br> 0 0 0<br> 1 0 1<br> 2 1 0<br> 3 1 1<br></code><br><br>px is 0 if CEx is active low (default) and 1 for active high.
|
|
<br><br>ux is 0 if the CEx GPIO is reserved for SPI (default)
|
|
and 1 otherwise.
|
|
<br><br>A is 0 for the main SPI, 1 for the auxiliary SPI.
|
|
<br><br>W is 0 if the device is not 3-wire, 1 if the device is 3-wire.
|
|
Main SPI only.
|
|
<br><br>nnnn defines the number of bytes (0-15) to write before
|
|
switching the MOSI line to MISO to read data. This field
|
|
is ignored if W is not set. Main SPI only.
|
|
<br><br>T is 1 if the least significant bit is transmitted on MOSI
|
|
first, the default (0) shifts the most significant bit out
|
|
first. Auxiliary SPI only.
|
|
<br><br>R is 1 if the least significant bit is received on MISO
|
|
first, the default (0) receives the most significant bit
|
|
first. Auxiliary SPI only.
|
|
<br><br>bbbbbb defines the word size in bits (0-32). The default (0)
|
|
sets 8 bits per word. Auxiliary SPI only.
|
|
<br><br>The <a href="#spi_read">spi_read</a>, <a href="#spi_write">spi_write</a>, and <a href="#spi_xfer">spi_xfer</a> functions
|
|
transfer data packed into 1, 2, or 4 bytes according to
|
|
the word size in bits.
|
|
<br><br>For bits 1-8 there will be one byte per character.
|
|
For bits 9-16 there will be two bytes per character.
|
|
For bits 17-32 there will be four bytes per character.
|
|
<br><br>Multi-byte transfers are made in least significant byte
|
|
first order.
|
|
<br><br>E.g. to transfer 32 11-bit words data should
|
|
contain 64 bytes.
|
|
<br><br>E.g. to transfer the 14 bit value 0x1ABC send the
|
|
bytes 0xBC followed by 0x1A.
|
|
<br><br>The other bits in flags should be set to zero.
|
|
<br><br><b><small>Example</small></b><br><br><code># open SPI device on channel 1 in mode 3 at 50000 bits per second<br><br>h = pi.spi_open(1, 50000, 3)<br></code><h3><a name="spi_read">spi_read<small>(<a href="#handle">handle</a>, <a href="#count">count</a>)</small></h3>
|
|
Reads count bytes from the SPI device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#spi_open">spi_open</a>).<br> count:= >0, the number of bytes to read.<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(b, d) = pi.spi_read(h, 60) # read 60 bytes from device h<br>if b == 60:<br> # process read data<br>else:<br> # error path<br></code><h3><a name="spi_write">spi_write<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
|
|
Writes the data bytes to the SPI device associated with handle.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#spi_open">spi_open</a>).<br> data:= the bytes to write.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.spi_write(0, b'\x02\xc0\x80') # write 3 bytes to device 0<br><br>pi.spi_write(0, b'defgh') # write 5 bytes to device 0<br><br>pi.spi_write(0, "def") # write 3 bytes to device 0<br><br>pi.spi_write(1, [2, 192, 128]) # write 3 bytes to device 1<br></code><h3><a name="spi_xfer">spi_xfer<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
|
|
Writes the data bytes to the SPI device associated with handle,
|
|
returning the data bytes read from the device.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>handle:= >=0 (as returned by a prior call to <a href="#spi_open">spi_open</a>).<br> data:= the bytes to write.<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
|
|
bytearray containing the bytes. If there was an error the
|
|
number of bytes read will be less than zero (and will contain
|
|
the error code).
|
|
<br><br><b><small>Example</small></b><br><br><code>(count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00')<br><br>(count, rx_data) = pi.spi_xfer(h, [1, 128, 0])<br><br>(count, rx_data) = pi.spi_xfer(h, b"hello")<br><br>(count, rx_data) = pi.spi_xfer(h, "hello")<br></code><h3><a name="stop">stop<small>()</small></h3>
|
|
Release pigpio resources.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.stop()<br></code><h3><a name="stop_script">stop_script<small>(<a href="#script_id">script_id</a>)</small></h3>
|
|
Stops a running script.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:= id of stored script.<br></samp><br><br><b><small>Example</small></b><br><br><code>status = pi.stop_script(sid)<br></code><h3><a name="store_script">store_script<small>(<a href="#script">script</a>)</small></h3>
|
|
Store a script for later execution.
|
|
<br><br>See <a href="http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts">http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts</a> for
|
|
details.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>script:= the script text as a series of bytes.<br></samp><br><br>Returns a >=0 script id if OK.
|
|
<br><br><b><small>Example</small></b><br><br><code>sid = pi.store_script(<br> b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0')<br></code><h3><a name="update_script">update_script<small>(<a href="#script_id">script_id</a>, <a href="#params">params</a>)</small></h3>
|
|
Sets the parameters of a script. The script may or
|
|
may not be running. The first parameters of the script are
|
|
overwritten with the new values.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:= id of stored script.<br> params:= up to 10 parameters required by the script.<br></samp><br><br><b><small>Example</small></b><br><br><code>s = pi.update_script(sid, [par1, par2])<br><br>s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])<br></code><h3><a name="wait_for_edge">wait_for_edge<small>(<a href="#user_gpio">user_gpio</a>, <a href="#edge">edge</a>, <a href="#wait_timeout">wait_timeout</a>)</small></h3>
|
|
Wait for an edge event on a GPIO.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> user_gpio:= 0-31.<br> edge:= EITHER_EDGE, RISING_EDGE (default), or<br> FALLING_EDGE.<br>wait_timeout:= >=0.0 (default 60.0).<br></samp><br><br>The function returns when the edge is detected or after
|
|
the number of seconds specified by timeout has expired.
|
|
<br><br>Do not use this function for precise timing purposes,
|
|
the edge is only checked 20 times a second. Whenever
|
|
you need to know the accurate time of GPIO events use
|
|
a <a href="#callback">callback</a> function.
|
|
<br><br>The function returns True if the edge is detected,
|
|
otherwise False.
|
|
<br><br><b><small>Example</small></b><br><br><code>if pi.wait_for_edge(23):<br> print("Rising edge detected")<br>else:<br> print("wait for edge timed out")<br><br>if pi.wait_for_edge(23, pigpio.FALLING_EDGE, 5.0):<br> print("Falling edge detected")<br>else:<br> print("wait for falling edge timed out")<br></code><h3><a name="wait_for_event">wait_for_event<small>(<a href="#event">event</a>, <a href="#wait_timeout">wait_timeout</a>)</small></h3>
|
|
Wait for an event.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> event:= 0-31.<br>wait_timeout:= >=0.0 (default 60.0).<br></samp><br><br>The function returns when the event is signalled or after
|
|
the number of seconds specified by timeout has expired.
|
|
<br><br>The function returns True if the event is detected,
|
|
otherwise False.
|
|
<br><br><b><small>Example</small></b><br><br><code>if pi.wait_for_event(23):<br> print("event detected")<br>else:<br> print("wait for event timed out")<br></code><h3><a name="wave_add_generic">wave_add_generic<small>(<a href="#pulses">pulses</a>)</small></h3>
|
|
Adds a list of pulses to the current waveform.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>pulses:= list of pulses to add to the waveform.<br></samp><br><br>Returns the new total number of pulses in the current waveform.
|
|
<br><br>The pulses are interleaved in time order within the existing
|
|
waveform (if any).
|
|
<br><br>Merging allows the waveform to be built in parts, that is the
|
|
settings for GPIO#1 can be added, and then GPIO#2 etc.
|
|
<br><br>If the added waveform is intended to start after or within
|
|
the existing waveform then the first pulse should consist
|
|
solely of a delay.
|
|
<br><br><b><small>Example</small></b><br><br><code>G1=4<br>G2=24<br><br>pi.set_mode(G1, pigpio.OUTPUT)<br>pi.set_mode(G2, pigpio.OUTPUT)<br><br>flash_500=[] # flash every 500 ms<br>flash_100=[] # flash every 100 ms<br><br># ON OFF DELAY<br><br>flash_500.append(pigpio.pulse(1<<G1, 1<<G2, 500000))<br>flash_500.append(pigpio.pulse(1<<G2, 1<<G1, 500000))<br><br>flash_100.append(pigpio.pulse(1<<G1, 1<<G2, 100000))<br>flash_100.append(pigpio.pulse(1<<G2, 1<<G1, 100000))<br><br>pi.wave_clear() # clear any existing waveforms<br><br>pi.wave_add_generic(flash_500) # 500 ms flashes<br>f500 = pi.wave_create() # create and save id<br><br>pi.wave_add_generic(flash_100) # 100 ms flashes<br>f100 = pi.wave_create() # create and save id<br><br>pi.wave_send_repeat(f500)<br><br>time.sleep(4)<br><br>pi.wave_send_repeat(f100)<br><br>time.sleep(4)<br><br>pi.wave_send_repeat(f500)<br><br>time.sleep(4)<br><br>pi.wave_tx_stop() # stop waveform<br><br>pi.wave_clear() # clear all waveforms<br></code><h3><a name="wave_add_new">wave_add_new<small>()</small></h3>
|
|
Starts a new empty waveform.
|
|
<br><br>You would not normally need to call this function as it is
|
|
automatically called after a waveform is created with the
|
|
<a href="#wave_create">wave_create</a> function.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.wave_add_new()<br></code><h3><a name="wave_add_serial">wave_add_serial<small>(<a href="#user_gpio">user_gpio</a>, <a href="#baud">baud</a>, <a href="#data">data</a>, <a href="#offset">offset</a>, <a href="#bb_bits">bb_bits</a>, <a href="#bb_stop">bb_stop</a>)</small></h3>
|
|
Adds a waveform representing serial data to the existing
|
|
waveform (if any). The serial data starts <a href="#offset">offset</a>
|
|
microseconds from the start of the waveform.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:= GPIO to transmit data. You must set the GPIO mode<br> to output.<br> baud:= 50-1000000 bits per second.<br> data:= the bytes to write.<br> offset:= number of microseconds from the start of the<br> waveform, default 0.<br> bb_bits:= number of data bits, default 8.<br> bb_stop:= number of stop half bits, default 2.<br></samp><br><br>Returns the new total number of pulses in the current waveform.
|
|
<br><br>The serial data is formatted as one start bit, <a href="#bb_bits">bb_bits</a>
|
|
data bits, and <a href="#bb_stop">bb_stop</a>/2 stop bits.
|
|
<br><br>It is legal to add serial data streams with different baud
|
|
rates to the same waveform.
|
|
<br><br>The bytes required for each character depend upon <a href="#bb_bits">bb_bits</a>.
|
|
<br><br>For <a href="#bb_bits">bb_bits</a> 1-8 there will be one byte per character.
|
|
For <a href="#bb_bits">bb_bits</a> 9-16 there will be two bytes per character.
|
|
For <a href="#bb_bits">bb_bits</a> 17-32 there will be four bytes per character.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.wave_add_serial(4, 300, 'Hello world')<br><br>pi.wave_add_serial(4, 300, b"Hello world")<br><br>pi.wave_add_serial(4, 300, b'\x23\x01\x00\x45')<br><br>pi.wave_add_serial(17, 38400, [23, 128, 234], 5000)<br></code><h3><a name="wave_chain">wave_chain<small>(<a href="#data">data</a>)</small></h3>
|
|
This function transmits a chain of waveforms.
|
|
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a>
|
|
will be cancelled.
|
|
<br><br>The waves to be transmitted are specified by the contents
|
|
of data which contains an ordered list of <a href="#wave_id">wave_id</a>s
|
|
and optional command codes and related data.
|
|
<br><br>Returns 0 if OK, otherwise PI_CHAIN_NESTING,
|
|
PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD,
|
|
PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG,
|
|
or PI_BAD_WAVE_ID.
|
|
<br><br>Each wave is transmitted in the order specified. A wave
|
|
may occur multiple times per chain.
|
|
<br><br>A blocks of waves may be transmitted multiple times by
|
|
using the loop commands. The block is bracketed by loop
|
|
start and end commands. Loops may be nested.
|
|
<br><br>Delays between waves may be added with the delay command.
|
|
<br><br>The following command codes are supported:
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Name</td><td>Cmd & Data</td><td>Meaning</td></tr><tr><td>Loop Start</td><td>255 0</td><td>Identify start of a wave block</td></tr><tr><td>Loop Repeat</td><td>255 1 x y</td><td>loop x + y*256 times</td></tr><tr><td>Delay</td><td>255 2 x y</td><td>delay x + y*256 microseconds</td></tr><tr><td>Loop Forever</td><td>255 3</td><td>loop forever</td></tr></tbody></table><br><br>If present Loop Forever must be the last entry in the chain.
|
|
<br><br>The code is currently dimensioned to support a chain with
|
|
roughly 600 entries and 20 loop counters.
|
|
<br><br><b><small>Example</small></b><br><br><code>#!/usr/bin/env python<br><br>import time<br>import pigpio<br><br>WAVES=5<br>GPIO=4<br><br>wid=[0]*WAVES<br><br>pi = pigpio.pi() # Connect to local Pi.<br><br>pi.set_mode(GPIO, pigpio.OUTPUT);<br><br>for i in range(WAVES):<br> pi.wave_add_generic([<br> pigpio.pulse(1<<GPIO, 0, 20),<br> pigpio.pulse(0, 1<<GPIO, (i+1)*200)]);<br><br> wid[i] = pi.wave_create();<br><br>pi.wave_chain([<br> wid[4], wid[3], wid[2], # transmit waves 4+3+2<br> 255, 0, # loop start<br> wid[0], wid[0], wid[0], # transmit waves 0+0+0<br> 255, 0, # loop start<br> wid[0], wid[1], # transmit waves 0+1<br> 255, 2, 0x88, 0x13, # delay 5000us<br> 255, 1, 30, 0, # loop end (repeat 30 times)<br> 255, 0, # loop start<br> wid[2], wid[3], wid[0], # transmit waves 2+3+0<br> wid[3], wid[1], wid[2], # transmit waves 3+1+2<br> 255, 1, 10, 0, # loop end (repeat 10 times)<br> 255, 1, 5, 0, # loop end (repeat 5 times)<br> wid[4], wid[4], wid[4], # transmit waves 4+4+4<br> 255, 2, 0x20, 0x4E, # delay 20000us<br> wid[0], wid[0], wid[0], # transmit waves 0+0+0<br> ])<br><br>while pi.wave_tx_busy():<br> time.sleep(0.1);<br><br>for i in range(WAVES):<br> pi.wave_delete(wid[i])<br><br>pi.stop()<br></code><h3><a name="wave_clear">wave_clear<small>()</small></h3>
|
|
Clears all waveforms and any data added by calls to the
|
|
<a href="#wave_add_*">wave_add_*</a> functions.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.wave_clear()<br></code><h3><a name="wave_create">wave_create<small>()</small></h3>
|
|
Creates a waveform from the data provided by the prior calls
|
|
to the <a href="#wave_add_*">wave_add_*</a> functions.
|
|
<br><br>Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM,
|
|
PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
|
|
<br><br>The data provided by the <a href="#wave_add_*">wave_add_*</a> functions is consumed by
|
|
this function.
|
|
<br><br>As many waveforms may be created as there is space available.
|
|
The wave id is passed to <a href="#wave_send_*">wave_send_*</a> to specify the waveform
|
|
to transmit.
|
|
<br><br>Normal usage would be
|
|
<br><br>Step 1. <a href="#wave_clear">wave_clear</a> to clear all waveforms and added data.
|
|
<br><br>Step 2. <a href="#wave_add_*">wave_add_*</a> calls to supply the waveform data.
|
|
<br><br>Step 3. <a href="#wave_create">wave_create</a> to create the waveform and get a unique id
|
|
<br><br>Repeat steps 2 and 3 as needed.
|
|
<br><br>Step 4. <a href="#wave_send_*">wave_send_*</a> with the id of the waveform to transmit.
|
|
<br><br>A waveform comprises one or more pulses.
|
|
<br><br>A pulse specifies
|
|
<br><br>1) the GPIO to be switched on at the start of the pulse.
|
|
2) the GPIO to be switched off at the start of the pulse.
|
|
3) the delay in microseconds before the next pulse.
|
|
<br><br>Any or all the fields can be zero. It doesn't make any sense
|
|
to set all the fields to zero (the pulse will be ignored).
|
|
<br><br>When a waveform is started each pulse is executed in order with
|
|
the specified delay between the pulse and the next.
|
|
<br><br><b><small>Example</small></b><br><br><code>wid = pi.wave_create()<br></code><h3><a name="wave_create_and_pad">wave_create_and_pad<small>(<a href="#percent">percent</a>)</small></h3>
|
|
This function creates a waveform like <a href="#wave_create">wave_create</a> but pads the consumed
|
|
resources. Where percent gives the percentage of the resources to use
|
|
(in terms of the theoretical maximum, not the current amount free).
|
|
This allows the reuse of deleted waves while a transmission is active.
|
|
<br><br>Upon success a wave id greater than or equal to 0 is returned, otherwise
|
|
PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
|
|
<br><br><code>percent: 0-100, size of waveform as percentage of maximum available.<br></code><br><br>The data provided by the <a href="#wave_add_*">wave_add_*</a> functions are consumed by this
|
|
function.
|
|
<br><br>As many waveforms may be created as there is space available. The
|
|
wave id is passed to <a href="#wave_send_*">wave_send_*</a> to specify the waveform to transmit.
|
|
<br><br>A usage would be the creation of two waves where one is filled while the
|
|
other is being transmitted. Each wave is assigned 50% of the resources.
|
|
This buffer structure allows the transmission of infinite wave sequences.
|
|
<br><br>Normal usage:
|
|
<br><br>Step 1. <a href="#wave_clear">wave_clear</a> to clear all waveforms and added data.
|
|
<br><br>Step 2. <a href="#wave_add_*">wave_add_*</a> calls to supply the waveform data.
|
|
<br><br>Step 3. <a href="#wave_create_and_pad">wave_create_and_pad</a> to create a waveform of uniform size.
|
|
<br><br>Step 4. <a href="#wave_send_*">wave_send_*</a> with the id of the waveform to transmit.
|
|
<br><br>Repeat steps 2-4 as needed.
|
|
<br><br>Step 5. Any wave id can now be deleted and another wave of the same size
|
|
can be created in its place.
|
|
<br><br><b><small>Example</small></b><br><br><code>wid = pi.wave_create_and_pad(50)<br></code><h3><a name="wave_delete">wave_delete<small>(<a href="#wave_id">wave_id</a>)</small></h3>
|
|
This function deletes the waveform with id wave_id.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:= >=0 (as returned by a prior call to <a href="#wave_create">wave_create</a>).<br></samp><br><br>Wave ids are allocated in order, 0, 1, 2, etc.
|
|
<br><br>The wave is flagged for deletion. The resources used by the wave
|
|
will only be reused when either of the following apply.
|
|
<br><br>- all waves with higher numbered wave ids have been deleted or have
|
|
been flagged for deletion.
|
|
<br><br>- a new wave is created which uses exactly the same resources as
|
|
the current wave (see the C source for gpioWaveCreate for details).
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.wave_delete(6) # delete waveform with id 6<br><br>pi.wave_delete(0) # delete waveform with id 0<br></code><h3><a name="wave_get_cbs">wave_get_cbs<small>()</small></h3>
|
|
Returns the length in DMA control blocks of the current
|
|
waveform.
|
|
<br><br><b><small>Example</small></b><br><br><code>cbs = pi.wave_get_cbs()<br></code><h3><a name="wave_get_max_cbs">wave_get_max_cbs<small>()</small></h3>
|
|
Returns the maximum possible size of a waveform in DMA
|
|
control blocks.
|
|
<br><br><b><small>Example</small></b><br><br><code>cbs = pi.wave_get_max_cbs()<br></code><h3><a name="wave_get_max_micros">wave_get_max_micros<small>()</small></h3>
|
|
Returns the maximum possible size of a waveform in microseconds.
|
|
<br><br><b><small>Example</small></b><br><br><code>micros = pi.wave_get_max_micros()<br></code><h3><a name="wave_get_max_pulses">wave_get_max_pulses<small>()</small></h3>
|
|
Returns the maximum possible size of a waveform in pulses.
|
|
<br><br><b><small>Example</small></b><br><br><code>pulses = pi.wave_get_max_pulses()<br></code><h3><a name="wave_get_micros">wave_get_micros<small>()</small></h3>
|
|
Returns the length in microseconds of the current waveform.
|
|
<br><br><b><small>Example</small></b><br><br><code>micros = pi.wave_get_micros()<br></code><h3><a name="wave_get_pulses">wave_get_pulses<small>()</small></h3>
|
|
Returns the length in pulses of the current waveform.
|
|
<br><br><b><small>Example</small></b><br><br><code>pulses = pi.wave_get_pulses()<br></code><h3><a name="wave_send_once">wave_send_once<small>(<a href="#wave_id">wave_id</a>)</small></h3>
|
|
Transmits the waveform with id wave_id. The waveform is sent
|
|
once.
|
|
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a> will
|
|
be cancelled.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:= >=0 (as returned by a prior call to <a href="#wave_create">wave_create</a>).<br></samp><br><br>Returns the number of DMA control blocks used in the waveform.
|
|
<br><br><b><small>Example</small></b><br><br><code>cbs = pi.wave_send_once(wid)<br></code><h3><a name="wave_send_repeat">wave_send_repeat<small>(<a href="#wave_id">wave_id</a>)</small></h3>
|
|
Transmits the waveform with id wave_id. The waveform repeats
|
|
until wave_tx_stop is called or another call to <a href="#wave_send_*">wave_send_*</a>
|
|
is made.
|
|
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a> will
|
|
be cancelled.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:= >=0 (as returned by a prior call to <a href="#wave_create">wave_create</a>).<br></samp><br><br>Returns the number of DMA control blocks used in the waveform.
|
|
<br><br><b><small>Example</small></b><br><br><code>cbs = pi.wave_send_repeat(wid)<br></code><h3><a name="wave_send_using_mode">wave_send_using_mode<small>(<a href="#wave_id">wave_id</a>, <a href="#mode">mode</a>)</small></h3>
|
|
Transmits the waveform with id wave_id using mode mode.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:= >=0 (as returned by a prior call to <a href="#wave_create">wave_create</a>).<br> mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT,<br> WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC.<br></samp><br><br>WAVE_MODE_ONE_SHOT: same as <a href="#wave_send_once">wave_send_once</a>.
|
|
<br><br>WAVE_MODE_REPEAT same as <a href="#wave_send_repeat">wave_send_repeat</a>.
|
|
<br><br>WAVE_MODE_ONE_SHOT_SYNC same as <a href="#wave_send_once">wave_send_once</a> but tries
|
|
to sync with the previous waveform.
|
|
<br><br>WAVE_MODE_REPEAT_SYNC same as <a href="#wave_send_repeat">wave_send_repeat</a> but tries
|
|
to sync with the previous waveform.
|
|
<br><br>WARNING: bad things may happen if you delete the previous
|
|
waveform before it has been synced to the new waveform.
|
|
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a> will
|
|
be cancelled.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:= >=0 (as returned by a prior call to <a href="#wave_create">wave_create</a>).<br></samp><br><br>Returns the number of DMA control blocks used in the waveform.
|
|
<br><br><b><small>Example</small></b><br><br><code>cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC)<br></code><h3><a name="wave_tx_at">wave_tx_at<small>()</small></h3>
|
|
Returns the id of the waveform currently being
|
|
transmitted.
|
|
<br><br>Returns the waveform id or one of the following special
|
|
values:
|
|
<br><br>WAVE_NOT_FOUND (9998) - transmitted wave not found.
|
|
NO_TX_WAVE (9999) - no wave being transmitted.
|
|
<br><br><b><small>Example</small></b><br><br><code>wid = pi.wave_tx_at()<br></code><h3><a name="wave_tx_busy">wave_tx_busy<small>()</small></h3>
|
|
Returns 1 if a waveform is currently being transmitted,
|
|
otherwise 0.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.wave_send_once(0) # send first waveform<br><br>while pi.wave_tx_busy(): # wait for waveform to be sent<br> time.sleep(0.1)<br><br>pi.wave_send_once(1) # send next waveform<br></code><h3><a name="wave_tx_repeat">wave_tx_repeat<small>()</small></h3>
|
|
This function is deprecated and has beeen removed.
|
|
<br><br>Use <a href="#wave_create">wave_create</a>/<a href="#wave_send_*">wave_send_*</a> instead.
|
|
<h3><a name="wave_tx_start">wave_tx_start<small>()</small></h3>
|
|
This function is deprecated and has been removed.
|
|
<br><br>Use <a href="#wave_create">wave_create</a>/<a href="#wave_send_*">wave_send_*</a> instead.
|
|
<h3><a name="wave_tx_stop">wave_tx_stop<small>()</small></h3>
|
|
Stops the transmission of the current waveform.
|
|
<br><br>This function is intended to stop a waveform started with
|
|
wave_send_repeat.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.wave_send_repeat(3)<br><br>time.sleep(5)<br><br>pi.wave_tx_stop()<br></code><h3><a name="write">write<small>(<a href="#gpio">gpio</a>, <a href="#level">level</a>)</small></h3>
|
|
Sets the GPIO level.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> GPIO:= 0-53.<br>level:= 0, 1.<br></samp><br><br>If PWM or servo pulses are active on the GPIO they are
|
|
switched off.
|
|
<br><br><b><small>Example</small></b><br><br><code>pi.set_mode(17, pigpio.OUTPUT)<br><br>pi.write(17,0)<br>print(pi.read(17))<br>0<br><br>pi.write(17,1)<br>print(pi.read(17))<br>1<br></code><h2> class pulse
|
|
</h2><h3><a name="pigpio.pulse">pigpio.pulse<small>(<a href="#gpio_on">gpio_on</a>, <a href="#gpio_off">gpio_off</a>, <a href="#delay">delay</a>)</small></h3>
|
|
Initialises a pulse.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp> gpio_on:= the GPIO to switch on at the start of the pulse.<br>gpio_off:= the GPIO to switch off at the start of the pulse.<br> delay:= the delay in microseconds before the next pulse.<br></samp><h2>FUNCTIONS</h2><h3><a name="pigpio.error_text">pigpio.error_text<small>(<a href="#errnum">errnum</a>)</small></h3>
|
|
Returns a text description of a pigpio error.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>errnum:= <0, the error number<br></samp><br><br><b><small>Example</small></b><br><br><code>print(pigpio.error_text(-5))<br>level not 0-1<br></code><h3><a name="pigpio.tickDiff">pigpio.tickDiff<small>(<a href="#t1">t1</a>, <a href="#t2">t2</a>)</small></h3>
|
|
Returns the microsecond difference between two ticks.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>t1:= the earlier tick<br>t2:= the later tick<br></samp><br><br><b><small>Example</small></b><br><br><code>print(pigpio.tickDiff(4294967272, 12))<br>36<br></code><h3><a name="pigpio.u2i">pigpio.u2i<small>(<a href="#uint32">uint32</a>)</small></h3>
|
|
Converts a 32 bit unsigned number to signed.
|
|
<br><br><b><small>Parameters</small></b><br><br><samp>uint32:= an unsigned 32 bit number<br></samp><br><br><b><small>Example</small></b><br><br><code>print(u2i(4294967272))<br>-24<br>print(u2i(37))<br>37<br></code><h2>PARAMETERS</h2><h3><a name="active"></a>active: 0-1000000</h3>The number of microseconds level changes are reported for once
|
|
a noise filter has been triggered (by <a href="#steady">steady</a> microseconds of
|
|
a stable level).
|
|
<h3><a name="arg1"></a>arg1: </h3>An unsigned argument passed to a user customised function. Its
|
|
meaning is defined by the customiser.
|
|
<h3><a name="arg2"></a>arg2: </h3>An unsigned argument passed to a user customised function. Its
|
|
meaning is defined by the customiser.
|
|
<h3><a name="argx"></a>argx: </h3>An array of bytes passed to a user customised function.
|
|
Its meaning and content is defined by the customiser.
|
|
<h3><a name="baud"></a>baud: </h3>The speed of serial communication (I2C, SPI, serial link, waves)
|
|
in bits per second.
|
|
<h3><a name="bb_bits"></a>bb_bits: 1-32</h3>The number of data bits to be used when adding serial data to a
|
|
waveform.
|
|
<h3><a name="bb_stop"></a>bb_stop: 2-8</h3>The number of (half) stop bits to be used when adding serial data
|
|
to a waveform.
|
|
<h3><a name="bit"></a>bit: 0-1</h3>A value of 0 or 1.
|
|
<h3><a name="bits"></a>bits: 32 bit number</h3>A mask used to select GPIO to be operated on. If bit n is set
|
|
then GPIO n is selected. A convenient way of setting bit n is to
|
|
bit or in the value (1<<n).
|
|
<br><br>To select GPIO 1, 7, 23
|
|
<br><br>bits = (1<<1) | (1<<7) | (1<<23)
|
|
<h3><a name="bsc_control"></a>bsc_control: </h3><code>22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0<br> a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN<br></code><br><br>aaaaaaa defines the I2C slave address (only relevant in I2C mode)
|
|
<br><br>Bits 0-13 are copied unchanged to the BSC CR register. See
|
|
pages 163-165 of the Broadcom peripherals document.
|
|
<h3><a name="byte_val"></a>byte_val: 0-255</h3>A whole number.
|
|
<h3><a name="clkfreq"></a>clkfreq: 4689-250M (13184-375M for the BCM2711)</h3>The hardware clock frequency.
|
|
<h3><a name="connected"></a>connected: </h3>True if a connection was established, False otherwise.
|
|
<h3><a name="count"></a>count: </h3>The number of bytes of data to be transferred.
|
|
<h3><a name="CS"></a>CS: </h3>The GPIO used for the slave select signal when bit banging SPI.
|
|
<h3><a name="data"></a>data: </h3>Data to be transmitted, a series of bytes.
|
|
<h3><a name="delay"></a>delay: >=1</h3>The length of a pulse in microseconds.
|
|
<h3><a name="dutycycle"></a>dutycycle: 0-range_</h3>A number between 0 and range_.
|
|
<br><br>The dutycycle sets the proportion of time on versus time off during each
|
|
PWM cycle.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Dutycycle</td><td>On time</td></tr><tr><td>0</td><td>Off</td></tr><tr><td>range_ * 0.25</td><td>25% On</td></tr><tr><td>range_ * 0.50</td><td>50% On</td></tr><tr><td>range_ * 0.75</td><td>75% On</td></tr><tr><td>range_</td><td>Fully On</td></tr></tbody></table><h3><a name="edge"></a>edge: 0-2</h3><code>EITHER_EDGE = 2<br>FALLING_EDGE = 1<br>RISING_EDGE = 0<br></code><h3><a name="errnum"></a>errnum: <0</h3><code>PI_BAD_USER_GPIO = -2<br>PI_BAD_GPIO = -3<br>PI_BAD_MODE = -4<br>PI_BAD_LEVEL = -5<br>PI_BAD_PUD = -6<br>PI_BAD_PULSEWIDTH = -7<br>PI_BAD_DUTYCYCLE = -8<br>PI_BAD_WDOG_TIMEOUT = -15<br>PI_BAD_DUTYRANGE = -21<br>PI_NO_HANDLE = -24<br>PI_BAD_HANDLE = -25<br>PI_BAD_WAVE_BAUD = -35<br>PI_TOO_MANY_PULSES = -36<br>PI_TOO_MANY_CHARS = -37<br>PI_NOT_SERIAL_GPIO = -38<br>PI_NOT_PERMITTED = -41<br>PI_SOME_PERMITTED = -42<br>PI_BAD_WVSC_COMMND = -43<br>PI_BAD_WVSM_COMMND = -44<br>PI_BAD_WVSP_COMMND = -45<br>PI_BAD_PULSELEN = -46<br>PI_BAD_SCRIPT = -47<br>PI_BAD_SCRIPT_ID = -48<br>PI_BAD_SER_OFFSET = -49<br>PI_GPIO_IN_USE = -50<br>PI_BAD_SERIAL_COUNT = -51<br>PI_BAD_PARAM_NUM = -52<br>PI_DUP_TAG = -53<br>PI_TOO_MANY_TAGS = -54<br>PI_BAD_SCRIPT_CMD = -55<br>PI_BAD_VAR_NUM = -56<br>PI_NO_SCRIPT_ROOM = -57<br>PI_NO_MEMORY = -58<br>PI_SOCK_READ_FAILED = -59<br>PI_SOCK_WRIT_FAILED = -60<br>PI_TOO_MANY_PARAM = -61<br>PI_SCRIPT_NOT_READY = -62<br>PI_BAD_TAG = -63<br>PI_BAD_MICS_DELAY = -64<br>PI_BAD_MILS_DELAY = -65<br>PI_BAD_WAVE_ID = -66<br>PI_TOO_MANY_CBS = -67<br>PI_TOO_MANY_OOL = -68<br>PI_EMPTY_WAVEFORM = -69<br>PI_NO_WAVEFORM_ID = -70<br>PI_I2C_OPEN_FAILED = -71<br>PI_SER_OPEN_FAILED = -72<br>PI_SPI_OPEN_FAILED = -73<br>PI_BAD_I2C_BUS = -74<br>PI_BAD_I2C_ADDR = -75<br>PI_BAD_SPI_CHANNEL = -76<br>PI_BAD_FLAGS = -77<br>PI_BAD_SPI_SPEED = -78<br>PI_BAD_SER_DEVICE = -79<br>PI_BAD_SER_SPEED = -80<br>PI_BAD_PARAM = -81<br>PI_I2C_WRITE_FAILED = -82<br>PI_I2C_READ_FAILED = -83<br>PI_BAD_SPI_COUNT = -84<br>PI_SER_WRITE_FAILED = -85<br>PI_SER_READ_FAILED = -86<br>PI_SER_READ_NO_DATA = -87<br>PI_UNKNOWN_COMMAND = -88<br>PI_SPI_XFER_FAILED = -89<br>PI_NO_AUX_SPI = -91<br>PI_NOT_PWM_GPIO = -92<br>PI_NOT_SERVO_GPIO = -93<br>PI_NOT_HCLK_GPIO = -94<br>PI_NOT_HPWM_GPIO = -95<br>PI_BAD_HPWM_FREQ = -96<br>PI_BAD_HPWM_DUTY = -97<br>PI_BAD_HCLK_FREQ = -98<br>PI_BAD_HCLK_PASS = -99<br>PI_HPWM_ILLEGAL = -100<br>PI_BAD_DATABITS = -101<br>PI_BAD_STOPBITS = -102<br>PI_MSG_TOOBIG = -103<br>PI_BAD_MALLOC_MODE = -104<br>PI_BAD_SMBUS_CMD = -107<br>PI_NOT_I2C_GPIO = -108<br>PI_BAD_I2C_WLEN = -109<br>PI_BAD_I2C_RLEN = -110<br>PI_BAD_I2C_CMD = -111<br>PI_BAD_I2C_BAUD = -112<br>PI_CHAIN_LOOP_CNT = -113<br>PI_BAD_CHAIN_LOOP = -114<br>PI_CHAIN_COUNTER = -115<br>PI_BAD_CHAIN_CMD = -116<br>PI_BAD_CHAIN_DELAY = -117<br>PI_CHAIN_NESTING = -118<br>PI_CHAIN_TOO_BIG = -119<br>PI_DEPRECATED = -120<br>PI_BAD_SER_INVERT = -121<br>PI_BAD_FOREVER = -124<br>PI_BAD_FILTER = -125<br>PI_BAD_PAD = -126<br>PI_BAD_STRENGTH = -127<br>PI_FIL_OPEN_FAILED = -128<br>PI_BAD_FILE_MODE = -129<br>PI_BAD_FILE_FLAG = -130<br>PI_BAD_FILE_READ = -131<br>PI_BAD_FILE_WRITE = -132<br>PI_FILE_NOT_ROPEN = -133<br>PI_FILE_NOT_WOPEN = -134<br>PI_BAD_FILE_SEEK = -135<br>PI_NO_FILE_MATCH = -136<br>PI_NO_FILE_ACCESS = -137<br>PI_FILE_IS_A_DIR = -138<br>PI_BAD_SHELL_STATUS = -139<br>PI_BAD_SCRIPT_NAME = -140<br>PI_BAD_SPI_BAUD = -141<br>PI_NOT_SPI_GPIO = -142<br>PI_BAD_EVENT_ID = -143<br>PI_CMD_INTERRUPTED = -144<br>PI_NOT_ON_BCM2711 = -145<br>PI_ONLY_ON_BCM2711 = -146<br></code><h3><a name="event"></a>event: 0-31</h3>An event is a signal used to inform one or more consumers
|
|
to start an action.
|
|
<h3><a name="file_mode"></a>file_mode: </h3>The mode may have the following values
|
|
<br><br><code>FILE_READ 1<br>FILE_WRITE 2<br>FILE_RW 3<br></code><br><br>The following values can be or'd into the file open mode
|
|
<br><br><code>FILE_APPEND 4<br>FILE_CREATE 8<br>FILE_TRUNC 16<br></code><h3><a name="file_name"></a>file_name: </h3>A full file path. To be accessible the path must match
|
|
an entry in /opt/pigpio/access.
|
|
<h3><a name="fpattern"></a>fpattern: </h3>A file path which may contain wildcards. To be accessible the path
|
|
must match an entry in /opt/pigpio/access.
|
|
<h3><a name="frequency"></a>frequency: 0-40000</h3>Defines the frequency to be used for PWM on a GPIO.
|
|
The closest permitted frequency will be used.
|
|
<h3><a name="func"></a>func: </h3>A user supplied callback function.
|
|
<h3><a name="gpio"></a>gpio: 0-53</h3>A Broadcom numbered GPIO. All the user GPIO are in the range 0-31.
|
|
<br><br>There are 54 General Purpose Input Outputs (GPIO) named GPIO0
|
|
through GPIO53.
|
|
<br><br>They are split into two banks. Bank 1 consists of GPIO0
|
|
through GPIO31. Bank 2 consists of GPIO32 through GPIO53.
|
|
<br><br>All the GPIO which are safe for the user to read and write are in
|
|
bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards
|
|
have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26.
|
|
<br><br>See <a href="#get_hardware_revision">get_hardware_revision</a>.
|
|
<br><br>The user GPIO are marked with an X in the following table
|
|
<br><br><code> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15<br>Type 1 X X - - X - - X X X X X - - X X<br>Type 2 - - X X X - - X X X X X - - X X<br>Type 3 X X X X X X X X X X X X X X<br><br> 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31<br>Type 1 - X X - - X X X X X - - - - - -<br>Type 2 - X X - - - X X X X - X X X X X<br>Type 3 X X X X X X X X X X X X - - - -<br></code><h3><a name="gpio_off"></a>gpio_off: </h3>A mask used to select GPIO to be operated on. See <a href="#bits">bits</a>.
|
|
<br><br>This mask selects the GPIO to be switched off at the start
|
|
of a pulse.
|
|
<h3><a name="gpio_on"></a>gpio_on: </h3>A mask used to select GPIO to be operated on. See <a href="#bits">bits</a>.
|
|
<br><br>This mask selects the GPIO to be switched on at the start
|
|
of a pulse.
|
|
<h3><a name="handle"></a>handle: >=0</h3>A number referencing an object opened by one of the following
|
|
<br><br><a href="#file_open">file_open</a>
|
|
<a href="#i2c_open">i2c_open</a>
|
|
<a href="#notify_open">notify_open</a>
|
|
<a href="#serial_open">serial_open</a>
|
|
<a href="#spi_open">spi_open</a>
|
|
<h3><a name="host"></a>host: </h3>The name or IP address of the Pi running the pigpio daemon.
|
|
<h3><a name="i2c_address"></a>i2c_address: 0-0x7F</h3>The address of a device on the I2C bus.
|
|
<h3><a name="i2c_bus"></a>i2c_bus: >=0</h3>An I2C bus number.
|
|
<h3><a name="i2c_flags"></a>i2c_flags: 0</h3>No I2C flags are currently defined.
|
|
<h3><a name="invert"></a>invert: 0-1</h3>A flag used to set normal or inverted bit bang serial data
|
|
level logic.
|
|
<h3><a name="level"></a>level: 0-1 (2)</h3><code>CLEAR = 0<br>HIGH = 1<br>LOW = 0<br>OFF = 0<br>ON = 1<br>SET = 1<br>TIMEOUT = 2 # only returned for a watchdog timeout<br></code><h3><a name="MISO"></a>MISO: </h3>The GPIO used for the MISO signal when bit banging SPI.
|
|
<h3><a name="mode"></a>mode: </h3>1.The operational mode of a GPIO, normally INPUT or OUTPUT.
|
|
<br><br><code>ALT0 = 4<br>ALT1 = 5<br>ALT2 = 6<br>ALT3 = 7<br>ALT4 = 3<br>ALT5 = 2<br>INPUT = 0<br>OUTPUT = 1<br></code><br><br>2. The mode of waveform transmission.
|
|
<br><br><code>WAVE_MODE_ONE_SHOT = 0<br>WAVE_MODE_REPEAT = 1<br>WAVE_MODE_ONE_SHOT_SYNC = 2<br>WAVE_MODE_REPEAT_SYNC = 3<br></code><h3><a name="MOSI"></a>MOSI: </h3>The GPIO used for the MOSI signal when bit banging SPI.
|
|
<h3><a name="offset"></a>offset: >=0</h3>The offset wave data starts from the beginning of the waveform
|
|
being currently defined.
|
|
<h3><a name="pad"></a>pad: 0-2</h3>A set of GPIO which share common drivers.
|
|
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Pad</td><td>GPIO</td></tr><tr><td>0</td><td>0-27</td></tr><tr><td>1</td><td>28-45</td></tr><tr><td>2</td><td>46-53</td></tr></tbody></table><h3><a name="pad_strength"></a>pad_strength: 1-16</h3>The mA which may be drawn from each GPIO whilst still guaranteeing the
|
|
high and low levels.
|
|
<h3><a name="params"></a>params: 32 bit number</h3>When scripts are started they can receive up to 10 parameters
|
|
to define their operation.
|
|
<h3><a name="percent"></a>percent: : 0-100</h3>The size of waveform as percentage of maximum available.
|
|
<h3><a name="port"></a>port: </h3>The port used by the pigpio daemon, defaults to 8888.
|
|
<h3><a name="pstring"></a>pstring: </h3>The string to be passed to a <a href="#shell">shell</a> script to be executed.
|
|
<h3><a name="pud"></a>pud: 0-2</h3><code>PUD_DOWN = 1<br>PUD_OFF = 0<br>PUD_UP = 2<br></code><h3><a name="pulse_len"></a>pulse_len: 1-100</h3>The length of the trigger pulse in microseconds.
|
|
<h3><a name="pulses"></a>pulses: </h3>A list of class pulse objects defining the characteristics of a
|
|
waveform.
|
|
<h3><a name="pulsewidth"></a>pulsewidth: </h3>The servo pulsewidth in microseconds. 0 switches pulses off.
|
|
<h3><a name="PWMduty"></a>PWMduty: 0-1000000 (1M)</h3>The hardware PWM dutycycle.
|
|
<h3><a name="PWMfreq"></a>PWMfreq: 1-125M (1-187.5M for the BCM2711)</h3>The hardware PWM frequency.
|
|
<h3><a name="range_"></a>range_: 25-40000</h3>Defines the limits for the <a href="#dutycycle">dutycycle</a> parameter.
|
|
<br><br>range_ defaults to 255.
|
|
<h3><a name="reg"></a>reg: 0-255</h3>An I2C device register. The usable registers depend on the
|
|
actual device.
|
|
<h3><a name="retMax"></a>retMax: >=0</h3>The maximum number of bytes a user customised function
|
|
should return, default 8192.
|
|
<h3><a name="SCL"></a>SCL: </h3>The user GPIO to use for the clock when bit banging I2C.
|
|
<h3><a name="SCLK"></a>SCLK: :</h3>The GPIO used for the SCLK signal when bit banging SPI.
|
|
<h3><a name="script"></a>script: </h3>The text of a script to store on the pigpio daemon.
|
|
<h3><a name="script_id"></a>script_id: >=0</h3>A number referencing a script created by <a href="#store_script">store_script</a>.
|
|
<h3><a name="SDA"></a>SDA: </h3>The user GPIO to use for data when bit banging I2C.
|
|
<h3><a name="seek_from"></a>seek_from: 0-2</h3>Direction to seek for <a href="#file_seek">file_seek</a>.
|
|
<br><br><code>FROM_START=0<br>FROM_CURRENT=1<br>FROM_END=2<br></code><h3><a name="seek_offset"></a>seek_offset: </h3>The number of bytes to move forward (positive) or backwards
|
|
(negative) from the seek position (start, current, or end of file).
|
|
<h3><a name="ser_flags"></a>ser_flags: 32 bit</h3>No serial flags are currently defined.
|
|
<h3><a name="serial_*"></a>serial_*: </h3>One of the serial_ functions.
|
|
<h3><a name="shellscr"></a>shellscr: </h3>The name of a shell script. The script must exist
|
|
in /opt/pigpio/cgi and must be executable.
|
|
<h3><a name="show_errors"></a>show_errors: </h3>Controls the display of pigpio daemon connection failures.
|
|
The default of True prints the probable failure reasons to
|
|
standard output.
|
|
<h3><a name="spi_channel"></a>spi_channel: 0-2</h3>A SPI channel.
|
|
<h3><a name="spi_flags"></a>spi_flags: 32 bit</h3>See <a href="#spi_open">spi_open</a>.
|
|
<h3><a name="steady"></a>steady: 0-300000</h3>The number of microseconds level changes must be stable for
|
|
before reporting the level changed (<a href="#set_glitch_filter">set_glitch_filter</a>)
|
|
or triggering the active part of a noise filter
|
|
(<a href="#set_noise_filter">set_noise_filter</a>).
|
|
<h3><a name="t1"></a>t1: </h3>A tick (earlier).
|
|
<h3><a name="t2"></a>t2: </h3>A tick (later).
|
|
<h3><a name="tty"></a>tty: </h3>A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0
|
|
<h3><a name="uint32"></a>uint32: </h3>An unsigned 32 bit number.
|
|
<h3><a name="user_gpio"></a>user_gpio: 0-31</h3>A Broadcom numbered GPIO.
|
|
<br><br>All the user GPIO are in the range 0-31.
|
|
<br><br>Not all the GPIO within this range are usable, some are reserved
|
|
for system use.
|
|
<br><br>See <a href="#gpio">gpio</a>.
|
|
<h3><a name="wait_timeout"></a>wait_timeout: 0.0 -</h3>The number of seconds to wait in <a href="#wait_for_edge">wait_for_edge</a> before timing out.
|
|
<h3><a name="wave_add_*"></a>wave_add_*: </h3>One of the following
|
|
<br><br><a href="#wave_add_new">wave_add_new</a>
|
|
<a href="#wave_add_generic">wave_add_generic</a>
|
|
<a href="#wave_add_serial">wave_add_serial</a>
|
|
<h3><a name="wave_id"></a>wave_id: >=0</h3>A number referencing a wave created by <a href="#wave_create">wave_create</a>.
|
|
<h3><a name="wave_send_*"></a>wave_send_*: </h3>One of the following
|
|
<br><br><a href="#wave_send_once">wave_send_once</a>
|
|
<a href="#wave_send_repeat">wave_send_repeat</a>
|
|
<h3><a name="wdog_timeout"></a>wdog_timeout: 0-60000</h3>Defines a GPIO watchdog timeout in milliseconds. If no level
|
|
change is detected on the GPIO for timeout millisecond a watchdog
|
|
timeout report is issued (with level TIMEOUT).
|
|
<h3><a name="word_val"></a>word_val: 0-65535</h3>A whole number.
|
|
<br><br> |