Public Member Functions | |
def | __init__ (self, host=os.getenv("PIGPIO_ADDR", 'localhost'), port=os.getenv("PIGPIO_PORT", 8888), show_errors=True) |
def | bb_i2c_close (self, SDA) |
def | bb_i2c_open (self, SDA, SCL, baud=100000) |
def | bb_i2c_zip (self, SDA, data) |
def | bb_serial_invert (self, user_gpio, invert) |
def | bb_serial_read (self, user_gpio) |
def | bb_serial_read_close (self, user_gpio) |
def | bb_serial_read_open (self, user_gpio, baud, bb_bits=8) |
def | bb_spi_close (self, CS) |
def | bb_spi_open (self, CS, MISO, MOSI, SCLK, baud=100000, spi_flags=0) |
def | bb_spi_xfer (self, CS, data) |
def | bsc_i2c (self, i2c_address, data=[]) |
def | bsc_xfer (self, bsc_control, data) |
def | callback (self, user_gpio, edge=RISING_EDGE, func=None) |
def | clear_bank_1 (self, bits) |
def | clear_bank_2 (self, bits) |
def | custom_1 (self, arg1=0, arg2=0, argx=[]) |
def | custom_2 (self, arg1=0, argx=[], retMax=8192) |
def | delete_script (self, script_id) |
def | event_callback (self, event, func=None) |
def | event_trigger (self, event) |
def | file_close (self, handle) |
def | file_list (self, fpattern) |
def | file_open (self, file_name, file_mode) |
def | file_read (self, handle, count) |
def | file_seek (self, handle, seek_offset, seek_from) |
def | file_write (self, handle, data) |
def | get_current_tick (self) |
def | get_hardware_revision (self) |
def | get_mode (self, gpio) |
def | get_pad_strength (self, pad) |
def | get_pigpio_version (self) |
def | get_PWM_dutycycle (self, user_gpio) |
def | get_PWM_frequency (self, user_gpio) |
def | get_PWM_range (self, user_gpio) |
def | get_PWM_real_range (self, user_gpio) |
def | get_servo_pulsewidth (self, user_gpio) |
def | gpio_trigger (self, user_gpio, pulse_len=10, level=1) |
def | hardware_clock (self, gpio, clkfreq) |
def | hardware_PWM (self, gpio, PWMfreq, PWMduty) |
def | i2c_block_process_call (self, handle, reg, data) |
def | i2c_close (self, handle) |
def | i2c_open (self, i2c_bus, i2c_address, i2c_flags=0) |
def | i2c_process_call (self, handle, reg, word_val) |
def | i2c_read_block_data (self, handle, reg) |
def | i2c_read_byte (self, handle) |
def | i2c_read_byte_data (self, handle, reg) |
def | i2c_read_device (self, handle, count) |
def | i2c_read_i2c_block_data (self, handle, reg, count) |
def | i2c_read_word_data (self, handle, reg) |
def | i2c_write_block_data (self, handle, reg, data) |
def | i2c_write_byte (self, handle, byte_val) |
def | i2c_write_byte_data (self, handle, reg, byte_val) |
def | i2c_write_device (self, handle, data) |
def | i2c_write_i2c_block_data (self, handle, reg, data) |
def | i2c_write_quick (self, handle, bit) |
def | i2c_write_word_data (self, handle, reg, word_val) |
def | i2c_zip (self, handle, data) |
def | notify_begin (self, handle, bits) |
def | notify_close (self, handle) |
def | notify_open (self) |
def | notify_pause (self, handle) |
def | read (self, gpio) |
def | read_bank_1 (self) |
def | read_bank_2 (self) |
def | run_script (self, script_id, params=None) |
def | script_status (self, script_id) |
def | serial_close (self, handle) |
def | serial_data_available (self, handle) |
def | serial_open (self, tty, baud, ser_flags=0) |
def | serial_read (self, handle, count=1000) |
def | serial_read_byte (self, handle) |
def | serial_write (self, handle, data) |
def | serial_write_byte (self, handle, byte_val) |
def | set_bank_1 (self, bits) |
def | set_bank_2 (self, bits) |
def | set_glitch_filter (self, user_gpio, steady) |
def | set_mode (self, gpio, mode) |
def | set_noise_filter (self, user_gpio, steady, active) |
def | set_pad_strength (self, pad, pad_strength) |
def | set_pull_up_down (self, gpio, pud) |
def | set_PWM_dutycycle (self, user_gpio, dutycycle) |
def | set_PWM_frequency (self, user_gpio, frequency) |
def | set_PWM_range (self, user_gpio, range_) |
def | set_servo_pulsewidth (self, user_gpio, pulsewidth) |
def | set_watchdog (self, user_gpio, wdog_timeout) |
def | shell (self, shellscr, pstring="") |
def | spi_close (self, handle) |
def | spi_open (self, spi_channel, baud, spi_flags=0) |
def | spi_read (self, handle, count) |
def | spi_write (self, handle, data) |
def | spi_xfer (self, handle, data) |
def | stop (self) |
def | stop_script (self, script_id) |
def | store_script (self, script) |
def | update_script (self, script_id, params=None) |
def | wait_for_edge (self, user_gpio, edge=RISING_EDGE, wait_timeout=60.0) |
def | wait_for_event (self, event, wait_timeout=60.0) |
def | wave_add_generic (self, pulses) |
def | wave_add_new (self) |
def | wave_add_serial (self, user_gpio, baud, data, offset=0, bb_bits=8, bb_stop=2) |
def | wave_chain (self, data) |
def | wave_clear (self) |
def | wave_create (self) |
def | wave_delete (self, wave_id) |
def | wave_get_cbs (self) |
def | wave_get_max_cbs (self) |
def | wave_get_max_micros (self) |
def | wave_get_max_pulses (self) |
def | wave_get_micros (self) |
def | wave_get_pulses (self) |
def | wave_send_once (self, wave_id) |
def | wave_send_repeat (self, wave_id) |
def | wave_send_using_mode (self, wave_id, mode) |
def | wave_tx_at (self) |
def | wave_tx_busy (self) |
def | wave_tx_repeat (self) |
def | wave_tx_start (self) |
def | wave_tx_stop (self) |
def | write (self, gpio, level) |
Public Attributes | |
connected | |
sl | |
Private Member Functions | |
def | _rxbuf (self, count) |
Private Attributes | |
_host | |
_notify | |
_port | |
def pigpio.pi.__init__ | ( | self, | |
host = os.getenv("PIGPIO_ADDR", 'localhost') , |
|||
port = os.getenv("PIGPIO_PORT", 8888) , |
|||
show_errors = True |
|||
) |
Grants access to a Pi's GPIO. host:= the host name of the Pi on which the pigpio daemon is running. The default is localhost unless overridden by the PIGPIO_ADDR environment variable. port:= the port number on which the pigpio daemon is listening. The default is 8888 unless overridden by the PIGPIO_PORT environment variable. The pigpio daemon must have been started with the same port number. This connects to the pigpio daemon and reserves resources to be used for sending commands and receiving notifications. An instance attribute [*connected*] may be used to check the success of the connection. If the connection is established successfully [*connected*] will be True, otherwise False. ... pi = pigio.pi() # use defaults pi = pigpio.pi('mypi') # specify host, default port pi = pigpio.pi('mypi', 7777) # specify host and port pi = pigpio.pi() # exit script if no connection if not pi.connected: exit() ...
|
private |
def pigpio.pi.bb_i2c_close | ( | self, | |
SDA | |||
) |
def pigpio.pi.bb_i2c_open | ( | self, | |
SDA, | |||
SCL, | |||
baud = 100000 |
|||
) |
This function selects a pair of GPIO for bit banging I2C at a specified baud rate. Bit banging I2C allows for certain operations which are not possible with the standard I2C driver. o baud rates as low as 50 o repeated starts o clock stretching o I2C on any pair of spare GPIO SDA:= 0-31 SCL:= 0-31 baud:= 50-500000 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or PI_GPIO_IN_USE. NOTE: 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. ... h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps ...
def pigpio.pi.bb_i2c_zip | ( | self, | |
SDA, | |||
data | |||
) |
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. SDA:= 0-31 (as used in a prior call to [*bb_i2c_open*]) data:= the concatenated I2C commands, see below 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). ... (count, data) = pi.bb_i2c_zip( SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0]) ... The following command codes are supported: Name @ Cmd & Data @ Meaning End @ 0 @ No more commands Escape @ 1 @ Next P is two bytes Start @ 2 @ Start condition Stop @ 3 @ Stop condition Address @ 4 P @ Set I2C address to P Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) Read @ 6 P @ Read P bytes of data Write @ 7 P ... @ Write P bytes of data 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). The address and flags default to 0. The address and flags maintain their previous value until updated. No flags are currently defined. Any read I2C data is concatenated in the returned bytearray. ... Set address 0x53 start, write 0x32, (re)start, read 6 bytes, stop Set address 0x1E start, write 0x03, (re)start, read 6 bytes, stop Set address 0x68 start, write 0x1B, (re)start, read 8 bytes, stop End 0x04 0x53 0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 0x04 0x1E 0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 0x04 0x68 0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 0x00 ...
def pigpio.pi.bb_serial_invert | ( | self, | |
user_gpio, | |||
invert | |||
) |
def pigpio.pi.bb_serial_read | ( | self, | |
user_gpio | |||
) |
Returns data from the bit bang serial cyclic buffer. user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) 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). The bytes returned for each character depend upon the number of data bits [*bb_bits*] specified in the [*bb_serial_read_open*] command. For [*bb_bits*] 1-8 there will be one byte per character. For [*bb_bits*] 9-16 there will be two bytes per character. For [*bb_bits*] 17-32 there will be four bytes per character. ... (count, data) = pi.bb_serial_read(4) ...
def pigpio.pi.bb_serial_read_close | ( | self, | |
user_gpio | |||
) |
def pigpio.pi.bb_serial_read_open | ( | self, | |
user_gpio, | |||
baud, | |||
bb_bits = 8 |
|||
) |
Opens a GPIO for bit bang reading of serial data. user_gpio:= 0-31, the GPIO to use. baud:= 50-250000, the baud rate. bb_bits:= 1-32, the number of bits per word, default 8. The serial data is held in a cyclic buffer and is read using [*bb_serial_read*]. It is the caller's responsibility to read data from the cyclic buffer in a timely fashion. ... status = pi.bb_serial_read_open(4, 19200) status = pi.bb_serial_read_open(17, 9600) ...
def pigpio.pi.bb_spi_close | ( | self, | |
CS | |||
) |
def pigpio.pi.bb_spi_open | ( | self, | |
CS, | |||
MISO, | |||
MOSI, | |||
SCLK, | |||
baud = 100000 , |
|||
spi_flags = 0 |
|||
) |
This function selects a set of GPIO for bit banging SPI at a specified baud rate. CS := 0-31 MISO := 0-31 MOSI := 0-31 SCLK := 0-31 baud := 50-250000 spiFlags := see below spiFlags consists of the least significant 22 bits. . . 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m . . mm defines the SPI mode, defaults to 0 . . Mode CPOL CPHA 0 0 0 1 0 1 2 1 0 3 1 1 . . The following constants may be used to set the mode: . . pigpio.SPI_MODE_0 pigpio.SPI_MODE_1 pigpio.SPI_MODE_2 pigpio.SPI_MODE_3 . . Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA may be used. 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. 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. 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. The other bits in spiFlags should be set to zero. Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or PI_GPIO_IN_USE. If more than one device is connected to the SPI bus (defined by SCLK, MOSI, and MISO) each must have its own CS. ... bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1 bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2 ...
def pigpio.pi.bb_spi_xfer | ( | self, | |
CS, | |||
data | |||
) |
This function executes a bit banged SPI transfer. CS:= 0-31 (as used in a prior call to [*bb_spi_open*]) data:= data to be sent 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). ... #!/usr/bin/env python import pigpio CE0=5 CE1=6 MISO=13 MOSI=19 SCLK=12 pi = pigpio.pi() if not pi.connected: exit() pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC for i in range(256): count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value if count == 2: count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC if count == 2: set_val = data[1] count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC if count == 3: read_val = ((data[1]&3)<<8) | data[2] print("{} {}".format(set_val, read_val)) pi.bb_spi_close(CE0) pi.bb_spi_close(CE1) pi.stop() ...
def pigpio.pi.bsc_i2c | ( | self, | |
i2c_address, | |||
data = [] |
|||
) |
This function allows the Pi to act as a slave I2C device. The data bytes (if any) are written to the BSC transmit FIFO and the bytes in the BSC receive FIFO are returned. i2c_address:= the I2C slave address. data:= the data bytes to transmit. The returned value is a tuple of the status, the number of bytes read, and a bytearray containing the read bytes. See [*bsc_xfer*] for details of the status value. If there was an error the status will be less than zero (and will contain the error code). Note that an i2c_address of 0 may be used to close the BSC device and reassign the used GPIO (18/19) as inputs. This example assumes GPIO 2/3 are connected to GPIO 18/19. ... #!/usr/bin/env python import time import pigpio I2C_ADDR=0x13 def i2c(id, tick): global pi s, b, d = pi.bsc_i2c(I2C_ADDR) if b: if d[0] == ord('t'): # 116 send 'HH:MM:SS*' print("sent={} FR={} received={} [{}]". format(s>>16, s&0xfff,b,d)) s, b, d = pi.bsc_i2c(I2C_ADDR, "{}*".format(time.asctime()[11:19])) elif d[0] == ord('d'): # 100 send 'Sun Oct 30*' print("sent={} FR={} received={} [{}]". format(s>>16, s&0xfff,b,d)) s, b, d = pi.bsc_i2c(I2C_ADDR, "{}*".format(time.asctime()[:10])) pi = pigpio.pi() if not pi.connected: exit() # Respond to BSC slave activity e = pi.event_callback(pigpio.EVENT_BSC, i2c) pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave time.sleep(600) e.cancel() pi.bsc_i2c(0) # Disable BSC peripheral pi.stop() ... While running the above. . . $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- $ pigs i2co 1 0x13 0 0 $ pigs i2cwd 0 116 $ pigs i2crd 0 9 -a 9 10:13:58* $ pigs i2cwd 0 116 $ pigs i2crd 0 9 -a 9 10:14:29* $ pigs i2cwd 0 100 $ pigs i2crd 0 11 -a 11 Sun Oct 30* $ pigs i2cwd 0 100 $ pigs i2crd 0 11 -a 11 Sun Oct 30* $ pigs i2cwd 0 116 $ pigs i2crd 0 9 -a 9 10:23:16* $ pigs i2cwd 0 100 $ pigs i2crd 0 11 -a 11 Sun Oct 30* . .
def pigpio.pi.bsc_xfer | ( | self, | |
bsc_control, | |||
data | |||
) |
This function provides a low-level interface to the SPI/I2C Slave peripheral. This peripheral allows the Pi to act as a slave device on an I2C or SPI bus. I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. 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. bsc_control:= see below data:= the data bytes to place in the transmit FIFO. 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). Note that the control word sets the BSC mode. The BSC will stay in that mode until a different control word is sent. The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You need to swap MISO/MOSI between master and slave. When a zero control word is received GPIO 18-21 will be reset to INPUT mode. bsc_control consists of the following bits: . . 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN . . Bits 0-13 are copied unchanged to the BSC CR register. See pages 163-165 of the Broadcom peripherals document for full details. aaaaaaa @ defines the I2C slave address (only relevant in I2C mode) IT @ invert transmit status flags HC @ enable host control TF @ enable test FIFO IR @ invert receive status flags RE @ enable receive TE @ enable transmit BK @ abort operation and clear FIFOs EC @ send control register as first I2C byte ES @ send status register as first I2C byte PL @ set SPI polarity high PH @ set SPI phase high I2 @ enable I2C mode SP @ enable SPI mode EN @ enable BSC peripheral The status has the following format: . . 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 S S S S S R R R R R T T T T T RB TE RF TF RE TB . . Bits 0-15 are copied unchanged from the BSC FR register. See pages 165-166 of the Broadcom peripherals document for full details. SSSSS @ number of bytes successfully copied to transmit FIFO RRRRR @ number of bytes in receieve FIFO TTTTT @ number of bytes in transmit FIFO RB @ receive busy TE @ transmit FIFO empty RF @ receive FIFO full TF @ transmit FIFO full RE @ receive FIFO empty TB @ transmit busy ... (status, count, data) = pi.bsc_xfer(0x330305, "Hello!") ...
def pigpio.pi.callback | ( | self, | |
user_gpio, | |||
edge = RISING_EDGE , |
|||
func = None |
|||
) |
Calls a user supplied function (a callback) whenever the specified GPIO edge is detected. user_gpio:= 0-31. edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE. func:= user supplied callback function. The user supplied callback receives three parameters, the GPIO, the level, and the tick. . . Parameter Value Meaning GPIO 0-31 The GPIO which has changed state level 0-2 0 = change to low (a falling edge) 1 = change to high (a rising edge) 2 = no level change (a watchdog timeout) tick 32 bit The number of microseconds since boot WARNING: this wraps around from 4294967295 to 0 roughly every 72 minutes . . 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. The callback may be cancelled by calling the cancel function. A GPIO may have multiple callbacks (although I can't think of a reason to do so). ... def cbf(gpio, level, tick): print(gpio, level, tick) cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf) cb2 = pi.callback(4, pigpio.EITHER_EDGE) cb3 = pi.callback(17) print(cb3.tally()) cb3.reset_tally() cb1.cancel() # To cancel callback cb1. ...
def pigpio.pi.clear_bank_1 | ( | self, | |
bits | |||
) |
Clears GPIO 0-31 if the corresponding bit in bits is set. bits:= a 32 bit mask with 1 set if the corresponding GPIO is to be cleared. A returned status of PI_SOME_PERMITTED indicates that the user is not allowed to write to one or more of the GPIO. ... pi.clear_bank_1(int("111110010000",2)) ...
def pigpio.pi.clear_bank_2 | ( | self, | |
bits | |||
) |
Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. bits:= a 32 bit mask with 1 set if the corresponding GPIO is to be cleared. A returned status of PI_SOME_PERMITTED indicates that the user is not allowed to write to one or more of the GPIO. ... pi.clear_bank_2(0x1010) ...
def pigpio.pi.custom_1 | ( | self, | |
arg1 = 0 , |
|||
arg2 = 0 , |
|||
argx = [] |
|||
) |
Calls a pigpio function customised by the user. arg1:= >=0, default 0. arg2:= >=0, default 0. argx:= extra arguments (each 0-255), default empty. The returned value is an integer which by convention should be >=0 for OK and <0 for error. ... value = pi.custom_1() value = pi.custom_1(23) value = pi.custom_1(0, 55) value = pi.custom_1(23, 56, [1, 5, 7]) value = pi.custom_1(23, 56, b"hello") value = pi.custom_1(23, 56, "hello") ...
def pigpio.pi.custom_2 | ( | self, | |
arg1 = 0 , |
|||
argx = [] , |
|||
retMax = 8192 |
|||
) |
Calls a pigpio function customised by the user. arg1:= >=0, default 0. argx:= extra arguments (each 0-255), default empty. retMax:= >=0, maximum number of bytes to return, default 8192. 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). ... (count, data) = pi.custom_2() (count, data) = pi.custom_2(23) (count, data) = pi.custom_2(23, [1, 5, 7]) (count, data) = pi.custom_2(23, b"hello") (count, data) = pi.custom_2(23, "hello", 128) ...
def pigpio.pi.delete_script | ( | self, | |
script_id | |||
) |
def pigpio.pi.event_callback | ( | self, | |
event, | |||
func = None |
|||
) |
Calls a user supplied function (a callback) whenever the specified event is signalled. event:= 0-31. func:= user supplied callback function. The user supplied callback receives two parameters, the event id, and the tick. 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. The callback may be cancelled by calling the event_cancel function. An event may have multiple callbacks (although I can't think of a reason to do so). ... def cbf(event, tick): print(event, tick) cb1 = pi.event_callback(22, cbf) cb2 = pi.event_callback(4) print(cb2.tally()) cb2.reset_tally() cb1.event_cancel() # To cancel callback cb1. ...
def pigpio.pi.event_trigger | ( | self, | |
event | |||
) |
This function signals the occurrence of an event. event:= 0-31, the event Returns 0 if OK, otherwise PI_BAD_EVENT_ID. 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 [*event_callback*]) will be informed by a callback. One event, EVENT_BSC (31) is predefined. This event is auto generated on BSC slave activity. The meaning of other events is arbitrary. Note that other than its id and its tick there is no data associated with an event. ... pi.event_trigger(23) ...
def pigpio.pi.file_close | ( | self, | |
handle | |||
) |
def pigpio.pi.file_list | ( | self, | |
fpattern | |||
) |
Returns a list of files which match a pattern. fpattern:= file pattern to match. Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. The pattern must match an entry in /opt/pigpio/access. The pattern may contain wildcards. See [*file_open*]. NOTE 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. ... #!/usr/bin/env python import pigpio pi = pigpio.pi() if not pi.connected: exit() # Assumes /opt/pigpio/access contains the following line: # /ram/*.c r c, d = pi.file_list("/ram/p*.c") if c > 0: print(d) pi.stop() ...
def pigpio.pi.file_open | ( | self, | |
file_name, | |||
file_mode | |||
) |
This function returns a handle to a file opened in a specified mode. file_name:= the file to open. file_mode:= the file open mode. 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. ... h = pi.file_open("/home/pi/shared/dir_3/file.txt", pigpio.FILE_WRITE | pigpio.FILE_CREATE) pi.file_write(h, "Hello world") pi.file_close(h) ... File 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. 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. Where more than one entry matches a file the most specific rule applies. If no entry matches a file then access is denied. Suppose /opt/pigpio/access contains the following entries: . . /home/* n /home/pi/shared/dir_1/* w /home/pi/shared/dir_2/* r /home/pi/shared/dir_3/* u /home/pi/shared/dir_1/file.txt n . . Files may be written in directory dir_1 with the exception of file.txt. Files may be read in directory dir_2. Files may be read and written in directory dir_3. If a directory allows read, write, or read/write access then files may be created in that directory. In an attempt to prevent risky permissions the following paths are ignored in /opt/pigpio/access: . . a path containing .. a path containing only wildcards (*?) a path containing less than two non-wildcard parts . . Mode The mode may have the following values: Constant @ Value @ Meaning FILE_READ @ 1 @ open file for reading FILE_WRITE @ 2 @ open file for writing FILE_RW @ 3 @ open file for reading and writing The following values may be or'd into the mode: Name @ Value @ Meaning FILE_APPEND @ 4 @ All writes append data to the end of the file FILE_CREATE @ 8 @ The file is created if it doesn't exist FILE_TRUNC @ 16 @ The file is truncated Newly created files are owned by root with permissions owner read and write. ... #!/usr/bin/env python import pigpio pi = pigpio.pi() if not pi.connected: exit() # Assumes /opt/pigpio/access contains the following line: # /ram/*.c r handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ) done = False while not done: c, d = pi.file_read(handle, 60000) if c > 0: print(d) else: done = True pi.file_close(handle) pi.stop() ...
def pigpio.pi.file_read | ( | self, | |
handle, | |||
count | |||
) |
Reads up to count bytes from the file associated with handle. handle:= >=0 (as returned by a prior call to [*file_open*]). count:= >0, the number of bytes to read. 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). ... (b, d) = pi.file_read(h2, 100) if b > 0: # process read data ...
def pigpio.pi.file_seek | ( | self, | |
handle, | |||
seek_offset, | |||
seek_from | |||
) |
Seeks to a position relative to the start, current position, or end of the file. Returns the new position. handle:= >=0 (as returned by a prior call to [*file_open*]). seek_offset:= byte offset. seek_from:= FROM_START, FROM_CURRENT, or FROM_END. ... new_pos = pi.file_seek(h, 100, pigpio.FROM_START) cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT) file_size = pi.file_seek(h, 0, pigpio.FROM_END) ...
def pigpio.pi.file_write | ( | self, | |
handle, | |||
data | |||
) |
Writes the data bytes to the file associated with handle. handle:= >=0 (as returned by a prior call to [*file_open*]). data:= the bytes to write. ... pi.file_write(h1, b'\\x02\\x03\\x04') pi.file_write(h2, b'help') pi.file_write(h2, "hello") pi.file_write(h1, [2, 3, 4]) ...
def pigpio.pi.get_current_tick | ( | self | ) |
def pigpio.pi.get_hardware_revision | ( | self | ) |
Returns the Pi's hardware revision number. The hardware revision is the last few characters on the Revision line of /proc/cpuinfo. The revision number can be used to determine the assignment of GPIO to pins (see [*gpio*]). There are at least three types of board. Type 1 boards have hardware revision numbers of 2 and 3. Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. Type 3 boards have hardware revision numbers of 16 or greater. If the hardware revision can not be found or is not a valid hexadecimal number the function returns 0. ... print(pi.get_hardware_revision()) 2 ...
def pigpio.pi.get_mode | ( | self, | |
gpio | |||
) |
def pigpio.pi.get_pad_strength | ( | self, | |
pad | |||
) |
def pigpio.pi.get_pigpio_version | ( | self | ) |
def pigpio.pi.get_PWM_dutycycle | ( | self, | |
user_gpio | |||
) |
Returns the PWM dutycycle being used on the GPIO. user_gpio:= 0-31. Returns the PWM dutycycle. For normal PWM the dutycycle will be out of the defined range for the GPIO (see [*get_PWM_range*]). If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M). If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). ... pi.set_PWM_dutycycle(4, 25) print(pi.get_PWM_dutycycle(4)) 25 pi.set_PWM_dutycycle(4, 203) print(pi.get_PWM_dutycycle(4)) 203 ...
def pigpio.pi.get_PWM_frequency | ( | self, | |
user_gpio | |||
) |
Returns the frequency of PWM being used on the GPIO. user_gpio:= 0-31. Returns the frequency (in Hz) used for the GPIO. For normal PWM the frequency will be that defined for the GPIO by [*set_PWM_frequency*]. If a hardware clock is active on the GPIO the reported frequency will be that set by [*hardware_clock*]. If hardware PWM is active on the GPIO the reported frequency will be that set by [*hardware_PWM*]. ... pi.set_PWM_frequency(4,0) print(pi.get_PWM_frequency(4)) 10 pi.set_PWM_frequency(4, 800) print(pi.get_PWM_frequency(4)) 800 ...
def pigpio.pi.get_PWM_range | ( | self, | |
user_gpio | |||
) |
def pigpio.pi.get_PWM_real_range | ( | self, | |
user_gpio | |||
) |
Returns the real (underlying) range of PWM values being used on the GPIO. user_gpio:= 0-31. If a hardware clock is active on the GPIO the reported real range will be 1000000 (1M). If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. ... pi.set_PWM_frequency(4, 800) print(pi.get_PWM_real_range(4)) 250 ...
def pigpio.pi.get_servo_pulsewidth | ( | self, | |
user_gpio | |||
) |
def pigpio.pi.gpio_trigger | ( | self, | |
user_gpio, | |||
pulse_len = 10 , |
|||
level = 1 |
|||
) |
def pigpio.pi.hardware_clock | ( | self, | |
gpio, | |||
clkfreq | |||
) |
Starts a hardware clock on a GPIO at the specified frequency. Frequencies above 30MHz are unlikely to work. gpio:= see description clkfreq:= 0 (off) or 4689-250000000 (250M) Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. The same clock is available on multiple GPIO. The latest frequency setting will be used by all GPIO which share a clock. The GPIO must be one of the following: . . 4 clock 0 All models 5 clock 1 All models but A and B (reserved for system use) 6 clock 2 All models but A and B 20 clock 0 All models but A and B 21 clock 1 All models but A and Rev.2 B (reserved for system use) 32 clock 0 Compute module only 34 clock 0 Compute module only 42 clock 1 Compute module only (reserved for system use) 43 clock 2 Compute module only 44 clock 1 Compute module only (reserved for system use) . . 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. ... pi.hardware_clock(4, 5000) # 5 KHz clock on GPIO 4 pi.hardware_clock(4, 40000000) # 40 MHz clock on GPIO 4 ...
def pigpio.pi.hardware_PWM | ( | self, | |
gpio, | |||
PWMfreq, | |||
PWMduty | |||
) |
Starts hardware PWM on a GPIO at the specified frequency and dutycycle. Frequencies above 30MHz are unlikely to work. NOTE: Any waveform started by [*wave_send_once*], [*wave_send_repeat*], or [*wave_chain*] will be cancelled. 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). gpio:= see descripton PWMfreq:= 0 (off) or 1-125000000 (125M). PWMduty:= 0 (off) to 1000000 (1M)(fully on). Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. 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. The GPIO must be one of the following: . . 12 PWM channel 0 All models but A and B 13 PWM channel 1 All models but A and B 18 PWM channel 0 All models 19 PWM channel 1 All models but A and B 40 PWM channel 0 Compute module only 41 PWM channel 1 Compute module only 45 PWM channel 1 Compute module only 52 PWM channel 0 Compute module only 53 PWM channel 1 Compute module only . . The actual number of steps beween off and fully on is the integral part of 250 million divided by PWMfreq. The actual frequency set is 250 million / steps. There will only be a million steps for a PWMfreq of 250. Lower frequencies will have more steps and higher frequencies will have fewer steps. PWMduty is automatically scaled to take this into account. ... pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle ...
def pigpio.pi.i2c_block_process_call | ( | self, | |
handle, | |||
reg, | |||
data | |||
) |
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. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. data:= the bytes to write. 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. SMBus 2.0 5.5.8 - Block write-block read. . . S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A] S Addr Rd [A] [Count] A [Data] ... A P . . 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). ... (b, d) = pi.i2c_block_process_call(h, 10, b'\\x02\\x05\\x00') (b, d) = pi.i2c_block_process_call(h, 10, b'abcdr') (b, d) = pi.i2c_block_process_call(h, 10, "abracad") (b, d) = pi.i2c_block_process_call(h, 10, [2, 5, 16]) ...
def pigpio.pi.i2c_close | ( | self, | |
handle | |||
) |
def pigpio.pi.i2c_open | ( | self, | |
i2c_bus, | |||
i2c_address, | |||
i2c_flags = 0 |
|||
) |
Returns a handle (>=0) for the device at the I2C bus address. i2c_bus:= >=0. i2c_address:= 0-0x7F. i2c_flags:= 0, no flags are currently defined. Normally you would only use the [*i2c_**] 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 SMBus module instead. 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. For the SMBus commands the low level transactions are shown at the end of the function description. The following abbreviations are used: . . S (1 bit) : Start bit P (1 bit) : Stop bit Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. A, NA (1 bit) : Accept and not accept bit. Addr (7 bits): I2C 7 bit address. reg (8 bits): Command byte, which often selects a register. Data (8 bits): A data byte. Count (8 bits): A byte defining the length of a block operation. [..]: Data sent by the device. . . ... h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1 ...
def pigpio.pi.i2c_process_call | ( | self, | |
handle, | |||
reg, | |||
word_val | |||
) |
Writes 16 bits of data to the specified register of the device associated with handle and reads 16 bits of data in return. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. word_val:= 0-65535, the value to write. SMBus 2.0 5.5.6 - Process call. . . S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P . . ... r = pi.i2c_process_call(h, 4, 0x1231) r = pi.i2c_process_call(h, 6, 0) ...
def pigpio.pi.i2c_read_block_data | ( | self, | |
handle, | |||
reg | |||
) |
Reads a block of up to 32 bytes from the specified register of the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. SMBus 2.0 5.5.7 - Block read. . . S Addr Wr [A] reg [A] S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P . . The amount of returned data is set by the device. 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). ... (b, d) = pi.i2c_read_block_data(h, 10) if b >= 0: # process data else: # process read failure ...
def pigpio.pi.i2c_read_byte | ( | self, | |
handle | |||
) |
def pigpio.pi.i2c_read_byte_data | ( | self, | |
handle, | |||
reg | |||
) |
Reads a single byte from the specified register of the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. SMBus 2.0 5.5.5 - Read byte. . . S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P . . ... # read byte from reg 17 of device 2 b = pi.i2c_read_byte_data(2, 17) # read byte from reg 1 of device 0 b = pi.i2c_read_byte_data(0, 1) ...
def pigpio.pi.i2c_read_device | ( | self, | |
handle, | |||
count | |||
) |
Returns count bytes read from the raw device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). count:= >0, the number of bytes to read. . . S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P . . 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). ... (count, data) = pi.i2c_read_device(h, 12) ...
def pigpio.pi.i2c_read_i2c_block_data | ( | self, | |
handle, | |||
reg, | |||
count | |||
) |
Reads count bytes from the specified register of the device associated with handle . The count may be 1-32. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. count:= >0, the number of bytes to read. . . S Addr Wr [A] reg [A] S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P . . 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). ... (b, d) = pi.i2c_read_i2c_block_data(h, 4, 32) if b >= 0: # process data else: # process read failure ...
def pigpio.pi.i2c_read_word_data | ( | self, | |
handle, | |||
reg | |||
) |
Reads a single 16 bit word from the specified register of the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. SMBus 2.0 5.5.5 - Read word. . . S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P . . ... # read word from reg 2 of device 3 w = pi.i2c_read_word_data(3, 2) # read word from reg 7 of device 2 w = pi.i2c_read_word_data(2, 7) ...
def pigpio.pi.i2c_write_block_data | ( | self, | |
handle, | |||
reg, | |||
data | |||
) |
Writes up to 32 bytes to the specified register of the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. data:= the bytes to write. SMBus 2.0 5.5.7 - Block write. . . S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A] datan [A] P . . ... pi.i2c_write_block_data(4, 5, b'hello') pi.i2c_write_block_data(4, 5, "data bytes") pi.i2c_write_block_data(5, 0, b'\\x00\\x01\\x22') pi.i2c_write_block_data(6, 2, [0, 1, 0x22]) ...
def pigpio.pi.i2c_write_byte | ( | self, | |
handle, | |||
byte_val | |||
) |
Sends a single byte to the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). byte_val:= 0-255, the value to write. SMBus 2.0 5.5.2 - Send byte. . . S Addr Wr [A] byte_val [A] P . . ... pi.i2c_write_byte(1, 17) # send byte 17 to device 1 pi.i2c_write_byte(2, 0x23) # send byte 0x23 to device 2 ...
def pigpio.pi.i2c_write_byte_data | ( | self, | |
handle, | |||
reg, | |||
byte_val | |||
) |
Writes a single byte to the specified register of the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. byte_val:= 0-255, the value to write. SMBus 2.0 5.5.4 - Write byte. . . S Addr Wr [A] reg [A] byte_val [A] P . . ... # send byte 0xC5 to reg 2 of device 1 pi.i2c_write_byte_data(1, 2, 0xC5) # send byte 9 to reg 4 of device 2 pi.i2c_write_byte_data(2, 4, 9) ...
def pigpio.pi.i2c_write_device | ( | self, | |
handle, | |||
data | |||
) |
Writes the data bytes to the raw device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). data:= the bytes to write. . . S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P . . ... pi.i2c_write_device(h, b"\\x12\\x34\\xA8") pi.i2c_write_device(h, b"help") pi.i2c_write_device(h, 'help') pi.i2c_write_device(h, [23, 56, 231]) ...
def pigpio.pi.i2c_write_i2c_block_data | ( | self, | |
handle, | |||
reg, | |||
data | |||
) |
Writes data bytes to the specified register of the device associated with handle . 1-32 bytes may be written. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. data:= the bytes to write. . . S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P . . ... pi.i2c_write_i2c_block_data(4, 5, 'hello') pi.i2c_write_i2c_block_data(4, 5, b'hello') pi.i2c_write_i2c_block_data(5, 0, b'\\x00\\x01\\x22') pi.i2c_write_i2c_block_data(6, 2, [0, 1, 0x22]) ...
def pigpio.pi.i2c_write_quick | ( | self, | |
handle, | |||
bit | |||
) |
Sends a single bit to the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). bit:= 0 or 1, the value to write. SMBus 2.0 5.5.1 - Quick command. . . S Addr bit [A] P . . ... pi.i2c_write_quick(0, 1) # send 1 to device 0 pi.i2c_write_quick(3, 0) # send 0 to device 3 ...
def pigpio.pi.i2c_write_word_data | ( | self, | |
handle, | |||
reg, | |||
word_val | |||
) |
Writes a single 16 bit word to the specified register of the device associated with handle. handle:= >=0 (as returned by a prior call to [*i2c_open*]). reg:= >=0, the device register. word_val:= 0-65535, the value to write. SMBus 2.0 5.5.4 - Write word. . . S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P . . ... # send word 0xA0C5 to reg 5 of device 4 pi.i2c_write_word_data(4, 5, 0xA0C5) # send word 2 to reg 2 of device 5 pi.i2c_write_word_data(5, 2, 23) ...
def pigpio.pi.i2c_zip | ( | self, | |
handle, | |||
data | |||
) |
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. handle:= >=0 (as returned by a prior call to [*i2c_open*]). data:= the concatenated I2C commands, see below 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). ... (count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0]) ... The following command codes are supported: Name @ Cmd & Data @ Meaning End @ 0 @ No more commands Escape @ 1 @ Next P is two bytes On @ 2 @ Switch combined flag on Off @ 3 @ Switch combined flag off Address @ 4 P @ Set I2C address to P Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) Read @ 6 P @ Read P bytes of data Write @ 7 P ... @ Write P bytes of data 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). The address defaults to that associated with the handle. The flags default to 0. The address and flags maintain their previous value until updated. Any read I2C data is concatenated in the returned bytearray. ... Set address 0x53, write 0x32, read 6 bytes Set address 0x1E, write 0x03, read 6 bytes Set address 0x68, write 0x1B, read 8 bytes End 0x04 0x53 0x07 0x01 0x32 0x06 0x06 0x04 0x1E 0x07 0x01 0x03 0x06 0x06 0x04 0x68 0x07 0x01 0x1B 0x06 0x08 0x00 ...
def pigpio.pi.notify_begin | ( | self, | |
handle, | |||
bits | |||
) |
Starts notifications on a handle. handle:= >=0 (as returned by a prior call to [*notify_open*]) bits:= a 32 bit mask indicating the GPIO to be notified. The notification sends state changes for each GPIO whose corresponding bit in bits is set. The following code starts notifications for GPIO 1, 4, 6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). ... h = pi.notify_open() if h >= 0: pi.notify_begin(h, 1234) ...
def pigpio.pi.notify_close | ( | self, | |
handle | |||
) |
def pigpio.pi.notify_open | ( | self | ) |
Returns a notification handle (>=0). A notification is a method for being notified of GPIO state changes via a pipe. 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 [*callback*] should be used instead. Notifications for handle x will be available at the pipe named /dev/pigpiox (where x is the handle number). E.g. if the function returns 15 then the notifications must be read from /dev/pigpio15. Notifications have the following structure: . . H seqno H flags I tick I level . . seqno: starts at 0 each time the handle is opened and then increments by one for each report. flags: three flags are defined, PI_NTFY_FLAGS_WDOG, PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. 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. 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. If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags indicate an event which has been triggered. tick: the number of microseconds since system boot. It wraps around after 1h12m. level: indicates the level of each GPIO. If bit 1<<x is set then GPIO x is high. ... h = pi.notify_open() if h >= 0: pi.notify_begin(h, 1234) ...
def pigpio.pi.notify_pause | ( | self, | |
handle | |||
) |
Pauses notifications on a handle. handle:= >=0 (as returned by a prior call to [*notify_open*]) Notifications for the handle are suspended until [*notify_begin*] is called again. ... h = pi.notify_open() if h >= 0: pi.notify_begin(h, 1234) ... pi.notify_pause(h) ... pi.notify_begin(h, 1234) ... ...
def pigpio.pi.read | ( | self, | |
gpio | |||
) |
def pigpio.pi.read_bank_1 | ( | self | ) |
def pigpio.pi.read_bank_2 | ( | self | ) |
def pigpio.pi.run_script | ( | self, | |
script_id, | |||
params = None |
|||
) |
def pigpio.pi.script_status | ( | self, | |
script_id | |||
) |
Returns the run status of a stored script as well as the current values of parameters 0 to 9. script_id:= id of stored script. The run status may be . . PI_SCRIPT_INITING PI_SCRIPT_HALTED PI_SCRIPT_RUNNING PI_SCRIPT_WAITING PI_SCRIPT_FAILED . . 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. ... (s, pars) = pi.script_status(sid) ...
def pigpio.pi.serial_close | ( | self, | |
handle | |||
) |
def pigpio.pi.serial_data_available | ( | self, | |
handle | |||
) |
def pigpio.pi.serial_open | ( | self, | |
tty, | |||
baud, | |||
ser_flags = 0 |
|||
) |
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. tty:= the serial device to open. baud:= baud rate in bits per second, see below. ser_flags:= 0, no flags are currently defined. Normally you would only use the [*serial_**] 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. 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. ... h1 = pi.serial_open("/dev/ttyAMA0", 300) h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0) h3 = pi.serial_open("/dev/serial0", 9600) ...
def pigpio.pi.serial_read | ( | self, | |
handle, | |||
count = 1000 |
|||
) |
Reads up to count bytes from the device associated with handle. handle:= >=0 (as returned by a prior call to [*serial_open*]). count:= >0, the number of bytes to read (defaults to 1000). 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). If no data is ready a bytes read of zero is returned. ... (b, d) = pi.serial_read(h2, 100) if b > 0: # process read data ...
def pigpio.pi.serial_read_byte | ( | self, | |
handle | |||
) |
def pigpio.pi.serial_write | ( | self, | |
handle, | |||
data | |||
) |
Writes the data bytes to the device associated with handle. handle:= >=0 (as returned by a prior call to [*serial_open*]). data:= the bytes to write. ... pi.serial_write(h1, b'\\x02\\x03\\x04') pi.serial_write(h2, b'help') pi.serial_write(h2, "hello") pi.serial_write(h1, [2, 3, 4]) ...
def pigpio.pi.serial_write_byte | ( | self, | |
handle, | |||
byte_val | |||
) |
def pigpio.pi.set_bank_1 | ( | self, | |
bits | |||
) |
Sets GPIO 0-31 if the corresponding bit in bits is set. bits:= a 32 bit mask with 1 set if the corresponding GPIO is to be set. A returned status of PI_SOME_PERMITTED indicates that the user is not allowed to write to one or more of the GPIO. ... pi.set_bank_1(int("111110010000",2)) ...
def pigpio.pi.set_bank_2 | ( | self, | |
bits | |||
) |
Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. bits:= a 32 bit mask with 1 set if the corresponding GPIO is to be set. A returned status of PI_SOME_PERMITTED indicates that the user is not allowed to write to one or more of the GPIO. ... pi.set_bank_2(0x303) ...
def pigpio.pi.set_glitch_filter | ( | self, | |
user_gpio, | |||
steady | |||
) |
Sets a glitch filter on a GPIO. Level changes on the GPIO are not reported unless the level has been stable for at least [*steady*] microseconds. The level is then reported. Level changes of less than [*steady*] microseconds are ignored. user_gpio:= 0-31 steady:= 0-300000 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. This filter affects the GPIO samples returned to callbacks set up with [*callback*] and [*wait_for_edge*]. It does not affect levels read by [*read*], [*read_bank_1*], or [*read_bank_2*]. Each (stable) edge will be timestamped [*steady*] microseconds after it was first detected. ... pi.set_glitch_filter(23, 100) ...
def pigpio.pi.set_mode | ( | self, | |
gpio, | |||
mode | |||
) |
def pigpio.pi.set_noise_filter | ( | self, | |
user_gpio, | |||
steady, | |||
active | |||
) |
Sets a noise filter on a GPIO. Level changes on the GPIO are ignored until a level which has been stable for [*steady*] microseconds is detected. Level changes on the GPIO are then reported for [*active*] microseconds after which the process repeats. user_gpio:= 0-31 steady:= 0-300000 active:= 0-1000000 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. This filter affects the GPIO samples returned to callbacks set up with [*callback*] and [*wait_for_edge*]. It does not affect levels read by [*read*], [*read_bank_1*], or [*read_bank_2*]. Level changes before and after the active period may be reported. Your software must be designed to cope with such reports. ... pi.set_noise_filter(23, 1000, 5000) ...
def pigpio.pi.set_pad_strength | ( | self, | |
pad, | |||
pad_strength | |||
) |
def pigpio.pi.set_pull_up_down | ( | self, | |
gpio, | |||
pud | |||
) |
def pigpio.pi.set_PWM_dutycycle | ( | self, | |
user_gpio, | |||
dutycycle | |||
) |
Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. user_gpio:= 0-31. dutycycle:= 0-range (range defaults to 255). The [*set_PWM_range*] function can change the default range of 255. ... pi.set_PWM_dutycycle(4, 0) # PWM off pi.set_PWM_dutycycle(4, 64) # PWM 1/4 on pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on pi.set_PWM_dutycycle(4, 255) # PWM full on ...
def pigpio.pi.set_PWM_frequency | ( | self, | |
user_gpio, | |||
frequency | |||
) |
Sets the frequency (in Hz) of the PWM to be used on the GPIO. user_gpio:= 0-31. frequency:= >=0 Hz Returns the numerically closest frequency if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PERMITTED. If PWM is currently active on the GPIO it will be switched off and then back on at the new frequency. Each GPIO can be independently set to one of 18 different PWM frequencies. 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. The frequencies for each sample rate are: . . Hertz 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 1250 1000 800 500 400 250 200 100 50 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 625 500 400 250 200 125 100 50 25 4: 10000 5000 2500 2000 1250 1000 625 500 400 313 250 200 125 100 63 50 25 13 sample rate (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 250 200 160 100 80 50 40 20 10 8: 5000 2500 1250 1000 625 500 313 250 200 156 125 100 63 50 31 25 13 6 10: 4000 2000 1000 800 500 400 250 200 160 125 100 80 50 40 25 20 10 5 . . ... pi.set_PWM_frequency(4,0) print(pi.get_PWM_frequency(4)) 10 pi.set_PWM_frequency(4,100000) print(pi.get_PWM_frequency(4)) 8000 ...
def pigpio.pi.set_PWM_range | ( | self, | |
user_gpio, | |||
range_ | |||
) |
Sets the range of PWM values to be used on the GPIO. user_gpio:= 0-31. range_:= 25-40000. ... pi.set_PWM_range(9, 100) # now 25 1/4, 50 1/2, 75 3/4 on pi.set_PWM_range(9, 500) # now 125 1/4, 250 1/2, 375 3/4 on pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on ...
def pigpio.pi.set_servo_pulsewidth | ( | self, | |
user_gpio, | |||
pulsewidth | |||
) |
Starts (500-2500) or stops (0) servo pulses on the GPIO. user_gpio:= 0-31. pulsewidth:= 0 (off), 500 (most anti-clockwise) - 2500 (most clockwise). The selected pulsewidth will continue to be transmitted until changed by a subsequent call to set_servo_pulsewidth. 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. You can DAMAGE a servo if you command it to move beyond its limits. ... pi.set_servo_pulsewidth(17, 0) # off pi.set_servo_pulsewidth(17, 1000) # safe anti-clockwise pi.set_servo_pulsewidth(17, 1500) # centre pi.set_servo_pulsewidth(17, 2000) # safe clockwise ...
def pigpio.pi.set_watchdog | ( | self, | |
user_gpio, | |||
wdog_timeout | |||
) |
Sets a watchdog timeout for a GPIO. user_gpio:= 0-31. wdog_timeout:= 0-60000. The watchdog is nominally in milliseconds. Only one watchdog may be registered per GPIO. The watchdog may be cancelled by setting timeout to 0. Once a watchdog has been started callbacks for the GPIO will be triggered every timeout interval after the last GPIO activity. The callback will receive the special level TIMEOUT. ... pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23 pi.set_watchdog(23, 0) # cancel watchdog on GPIO 23 ...
def pigpio.pi.shell | ( | self, | |
shellscr, | |||
pstring = "" |
|||
) |
This function uses the system call to execute a shell script with the given string as its parameter. shellscr:= the name of the script, only alphanumerics, '-' and '_' are allowed in the name pstring := the parameter string to pass to the script The exit status of the system call is returned if OK, otherwise PI_BAD_SHELL_STATUS. [*shellscr*] must exist in /opt/pigpio/cgi and must be executable. 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. The following table gives some example returned statuses: Script exit status @ Returned system call status 1 @ 256 5 @ 1280 10 @ 2560 200 @ 51200 script not found @ 32512 ... // pass two parameters, hello and world status = pi.shell("scr1", "hello world"); // pass three parameters, hello, string with spaces, and world status = pi.shell("scr1", "hello 'string with spaces' world"); // pass one parameter, hello string with spaces world status = pi.shell("scr1", "\\"hello string with spaces world\\""); ...
def pigpio.pi.spi_close | ( | self, | |
handle | |||
) |
def pigpio.pi.spi_open | ( | self, | |
spi_channel, | |||
baud, | |||
spi_flags = 0 |
|||
) |
Returns a handle for the SPI device on 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. An auxiliary SPI device is available on all models but the A and B and may be selected by setting the A bit in the flags. The auxiliary device has 3 chip selects and a selectable word size in bits. spi_channel:= 0-1 (0-2 for the auxiliary SPI device). baud:= 32K-125M (values above 30M are unlikely to work). spi_flags:= see below. Normally you would only use the [*spi_**] 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 SPI module instead. spi_flags consists of the least significant 22 bits. . . 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m . . mm defines the SPI mode. WARNING: modes 1 and 3 do not appear to work on the auxiliary device. . . Mode POL PHA 0 0 0 1 0 1 2 1 0 3 1 1 . . px is 0 if CEx is active low (default) and 1 for active high. ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. A is 0 for the standard SPI device, 1 for the auxiliary SPI. W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Standard SPI device only. 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. Standard SPI device only. 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 device only. R is 1 if the least significant bit is received on MISO first, the default (0) receives the most significant bit first. Auxiliary SPI device only. bbbbbb defines the word size in bits (0-32). The default (0) sets 8 bits per word. Auxiliary SPI device only. The [*spi_read*], [*spi_write*], and [*spi_xfer*] functions transfer data packed into 1, 2, or 4 bytes according to the word size in bits. 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. Multi-byte transfers are made in least significant byte first order. E.g. to transfer 32 11-bit words data should contain 64 bytes. E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed by 0x1A. The other bits in flags should be set to zero. ... # open SPI device on channel 1 in mode 3 at 50000 bits per second h = pi.spi_open(1, 50000, 3) ...
def pigpio.pi.spi_read | ( | self, | |
handle, | |||
count | |||
) |
Reads count bytes from the SPI device associated with handle. handle:= >=0 (as returned by a prior call to [*spi_open*]). count:= >0, the number of bytes to read. 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). ... (b, d) = pi.spi_read(h, 60) # read 60 bytes from device h if b == 60: # process read data else: # error path ...
def pigpio.pi.spi_write | ( | self, | |
handle, | |||
data | |||
) |
Writes the data bytes to the SPI device associated with handle. handle:= >=0 (as returned by a prior call to [*spi_open*]). data:= the bytes to write. ... pi.spi_write(0, b'\\x02\\xc0\\x80') # write 3 bytes to device 0 pi.spi_write(0, b'defgh') # write 5 bytes to device 0 pi.spi_write(0, "def") # write 3 bytes to device 0 pi.spi_write(1, [2, 192, 128]) # write 3 bytes to device 1 ...
def pigpio.pi.spi_xfer | ( | self, | |
handle, | |||
data | |||
) |
Writes the data bytes to the SPI device associated with handle, returning the data bytes read from the device. handle:= >=0 (as returned by a prior call to [*spi_open*]). data:= the bytes to write. 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). ... (count, rx_data) = pi.spi_xfer(h, b'\\x01\\x80\\x00') (count, rx_data) = pi.spi_xfer(h, [1, 128, 0]) (count, rx_data) = pi.spi_xfer(h, b"hello") (count, rx_data) = pi.spi_xfer(h, "hello") ...
def pigpio.pi.stop | ( | self | ) |
def pigpio.pi.stop_script | ( | self, | |
script_id | |||
) |
def pigpio.pi.store_script | ( | self, | |
script | |||
) |
Store a script for later execution. See [[http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts]] for details. script:= the script text as a series of bytes. Returns a >=0 script id if OK. ... sid = pi.store_script( b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0') ...
def pigpio.pi.update_script | ( | self, | |
script_id, | |||
params = None |
|||
) |
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. script_id:= id of stored script. params:= up to 10 parameters required by the script. ... s = pi.update_script(sid, [par1, par2]) s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) ...
def pigpio.pi.wait_for_edge | ( | self, | |
user_gpio, | |||
edge = RISING_EDGE , |
|||
wait_timeout = 60.0 |
|||
) |
Wait for an edge event on a GPIO. user_gpio:= 0-31. edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE. wait_timeout:= >=0.0 (default 60.0). The function returns when the edge is detected or after the number of seconds specified by timeout has expired. 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 [*callback*] function. The function returns True if the edge is detected, otherwise False. ... if pi.wait_for_edge(23): print("Rising edge detected") else: print("wait for edge timed out") if pi.wait_for_edge(23, pigpio.FALLING_EDGE, 5.0): print("Falling edge detected") else: print("wait for falling edge timed out") ...
def pigpio.pi.wait_for_event | ( | self, | |
event, | |||
wait_timeout = 60.0 |
|||
) |
Wait for an event. event:= 0-31. wait_timeout:= >=0.0 (default 60.0). The function returns when the event is signalled or after the number of seconds specified by timeout has expired. The function returns True if the event is detected, otherwise False. ... if pi.wait_for_event(23): print("event detected") else: print("wait for event timed out") ...
def pigpio.pi.wave_add_generic | ( | self, | |
pulses | |||
) |
Adds a list of pulses to the current waveform. pulses:= list of pulses to add to the waveform. Returns the new total number of pulses in the current waveform. The pulses are interleaved in time order within the existing waveform (if any). Merging allows the waveform to be built in parts, that is the settings for GPIO#1 can be added, and then GPIO#2 etc. If the added waveform is intended to start after or within the existing waveform then the first pulse should consist solely of a delay. ... G1=4 G2=24 pi.set_mode(G1, pigpio.OUTPUT) pi.set_mode(G2, pigpio.OUTPUT) flash_500=[] # flash every 500 ms flash_100=[] # flash every 100 ms # ON OFF DELAY flash_500.append(pigpio.pulse(1<<G1, 1<<G2, 500000)) flash_500.append(pigpio.pulse(1<<G2, 1<<G1, 500000)) flash_100.append(pigpio.pulse(1<<G1, 1<<G2, 100000)) flash_100.append(pigpio.pulse(1<<G2, 1<<G1, 100000)) pi.wave_clear() # clear any existing waveforms pi.wave_add_generic(flash_500) # 500 ms flashes f500 = pi.wave_create() # create and save id pi.wave_add_generic(flash_100) # 100 ms flashes f100 = pi.wave_create() # create and save id pi.wave_send_repeat(f500) time.sleep(4) pi.wave_send_repeat(f100) time.sleep(4) pi.wave_send_repeat(f500) time.sleep(4) pi.wave_tx_stop() # stop waveform pi.wave_clear() # clear all waveforms ...
def pigpio.pi.wave_add_new | ( | self | ) |
def pigpio.pi.wave_add_serial | ( | self, | |
user_gpio, | |||
baud, | |||
data, | |||
offset = 0 , |
|||
bb_bits = 8 , |
|||
bb_stop = 2 |
|||
) |
Adds a waveform representing serial data to the existing waveform (if any). The serial data starts [*offset*] microseconds from the start of the waveform. user_gpio:= GPIO to transmit data. You must set the GPIO mode to output. baud:= 50-1000000 bits per second. data:= the bytes to write. offset:= number of microseconds from the start of the waveform, default 0. bb_bits:= number of data bits, default 8. bb_stop:= number of stop half bits, default 2. Returns the new total number of pulses in the current waveform. The serial data is formatted as one start bit, [*bb_bits*] data bits, and [*bb_stop*]/2 stop bits. It is legal to add serial data streams with different baud rates to the same waveform. The bytes required for each character depend upon [*bb_bits*]. For [*bb_bits*] 1-8 there will be one byte per character. For [*bb_bits*] 9-16 there will be two bytes per character. For [*bb_bits*] 17-32 there will be four bytes per character. ... pi.wave_add_serial(4, 300, 'Hello world') pi.wave_add_serial(4, 300, b"Hello world") pi.wave_add_serial(4, 300, b'\\x23\\x01\\x00\\x45') pi.wave_add_serial(17, 38400, [23, 128, 234], 5000) ...
def pigpio.pi.wave_chain | ( | self, | |
data | |||
) |
This function transmits a chain of waveforms. NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled. The waves to be transmitted are specified by the contents of data which contains an ordered list of [*wave_id*]s and optional command codes and related data. 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. Each wave is transmitted in the order specified. A wave may occur multiple times per chain. 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. Delays between waves may be added with the delay command. The following command codes are supported: Name @ Cmd & Data @ Meaning Loop Start @ 255 0 @ Identify start of a wave block Loop Repeat @ 255 1 x y @ loop x + y*256 times Delay @ 255 2 x y @ delay x + y*256 microseconds Loop Forever @ 255 3 @ loop forever If present Loop Forever must be the last entry in the chain. The code is currently dimensioned to support a chain with roughly 600 entries and 20 loop counters. ... #!/usr/bin/env python import time import pigpio WAVES=5 GPIO=4 wid=[0]*WAVES pi = pigpio.pi() # Connect to local Pi. pi.set_mode(GPIO, pigpio.OUTPUT); for i in range(WAVES): pi.wave_add_generic([ pigpio.pulse(1<<GPIO, 0, 20), pigpio.pulse(0, 1<<GPIO, (i+1)*200)]); wid[i] = pi.wave_create(); pi.wave_chain([ wid[4], wid[3], wid[2], # transmit waves 4+3+2 255, 0, # loop start wid[0], wid[0], wid[0], # transmit waves 0+0+0 255, 0, # loop start wid[0], wid[1], # transmit waves 0+1 255, 2, 0x88, 0x13, # delay 5000us 255, 1, 30, 0, # loop end (repeat 30 times) 255, 0, # loop start wid[2], wid[3], wid[0], # transmit waves 2+3+0 wid[3], wid[1], wid[2], # transmit waves 3+1+2 255, 1, 10, 0, # loop end (repeat 10 times) 255, 1, 5, 0, # loop end (repeat 5 times) wid[4], wid[4], wid[4], # transmit waves 4+4+4 255, 2, 0x20, 0x4E, # delay 20000us wid[0], wid[0], wid[0], # transmit waves 0+0+0 ]) while pi.wave_tx_busy(): time.sleep(0.1); for i in range(WAVES): pi.wave_delete(wid[i]) pi.stop() ...
def pigpio.pi.wave_clear | ( | self | ) |
def pigpio.pi.wave_create | ( | self | ) |
Creates a waveform from the data provided by the prior calls to the [*wave_add_**] functions. Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. The data provided by the [*wave_add_**] functions is consumed by this function. As many waveforms may be created as there is space available. The wave id is passed to [*wave_send_**] to specify the waveform to transmit. Normal usage would be Step 1. [*wave_clear*] to clear all waveforms and added data. Step 2. [*wave_add_**] calls to supply the waveform data. Step 3. [*wave_create*] to create the waveform and get a unique id Repeat steps 2 and 3 as needed. Step 4. [*wave_send_**] with the id of the waveform to transmit. A waveform comprises one or more pulses. A pulse specifies 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. 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). When a waveform is started each pulse is executed in order with the specified delay between the pulse and the next. ... wid = pi.wave_create() ...
def pigpio.pi.wave_delete | ( | self, | |
wave_id | |||
) |
This function deletes the waveform with id wave_id. wave_id:= >=0 (as returned by a prior call to [*wave_create*]). Wave ids are allocated in order, 0, 1, 2, etc. The wave is flagged for deletion. The resources used by the wave will only be reused when either of the following apply. - all waves with higher numbered wave ids have been deleted or have been flagged for deletion. - a new wave is created which uses exactly the same resources as the current wave (see the C source for gpioWaveCreate for details). ... pi.wave_delete(6) # delete waveform with id 6 pi.wave_delete(0) # delete waveform with id 0 ...
def pigpio.pi.wave_get_cbs | ( | self | ) |
def pigpio.pi.wave_get_max_cbs | ( | self | ) |
def pigpio.pi.wave_get_max_micros | ( | self | ) |
def pigpio.pi.wave_get_max_pulses | ( | self | ) |
def pigpio.pi.wave_get_micros | ( | self | ) |
def pigpio.pi.wave_get_pulses | ( | self | ) |
def pigpio.pi.wave_send_once | ( | self, | |
wave_id | |||
) |
Transmits the waveform with id wave_id. The waveform is sent once. NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled. wave_id:= >=0 (as returned by a prior call to [*wave_create*]). Returns the number of DMA control blocks used in the waveform. ... cbs = pi.wave_send_once(wid) ...
def pigpio.pi.wave_send_repeat | ( | self, | |
wave_id | |||
) |
Transmits the waveform with id wave_id. The waveform repeats until wave_tx_stop is called or another call to [*wave_send_**] is made. NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled. wave_id:= >=0 (as returned by a prior call to [*wave_create*]). Returns the number of DMA control blocks used in the waveform. ... cbs = pi.wave_send_repeat(wid) ...
def pigpio.pi.wave_send_using_mode | ( | self, | |
wave_id, | |||
mode | |||
) |
Transmits the waveform with id wave_id using mode mode. wave_id:= >=0 (as returned by a prior call to [*wave_create*]). mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC. WAVE_MODE_ONE_SHOT: same as [*wave_send_once*]. WAVE_MODE_REPEAT same as [*wave_send_repeat*]. WAVE_MODE_ONE_SHOT_SYNC same as [*wave_send_once*] but tries to sync with the previous waveform. WAVE_MODE_REPEAT_SYNC same as [*wave_send_repeat*] but tries to sync with the previous waveform. WARNING: bad things may happen if you delete the previous waveform before it has been synced to the new waveform. NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled. wave_id:= >=0 (as returned by a prior call to [*wave_create*]). Returns the number of DMA control blocks used in the waveform. ... cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC) ...
def pigpio.pi.wave_tx_at | ( | self | ) |
def pigpio.pi.wave_tx_busy | ( | self | ) |
def pigpio.pi.wave_tx_repeat | ( | self | ) |
def pigpio.pi.wave_tx_start | ( | self | ) |
def pigpio.pi.wave_tx_stop | ( | self | ) |
def pigpio.pi.write | ( | self, | |
gpio, | |||
level | |||
) |