PiGPIO API

PiGPIO.PiMethod

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 = pigpio.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() ...

PiGPIO.get_modeMethod

Returns the GPIO mode.

gpio:= 0-53.

Returns a value as follows

. . 0 = INPUT 1 = OUTPUT 2 = ALT5 3 = ALT4 4 = ALT0 5 = ALT1 6 = ALT2 7 = ALT3 . .

... print(get_mode(pi, 0)) 4 ...

PiGPIO.set_modeMethod

Sets the GPIO mode.

gpio:= 0-53. mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5.

... setmode(pi, 4, pigpio.INPUT) # GPIO 4 as input setmode(pi, 17, pigpio.OUTPUT) # GPIO 17 as output set_mode(pi, 24, pigpio.ALT2) # GPIO 24 as ALT2 ...

PiGPIO.set_pull_up_downMethod

Sets or clears the internal GPIO pull-up/down resistor.

gpio:= 0-53. pud:= PUDUP, PUDDOWN, PUD_OFF.

... setpullupdown(pi, 17, pigpio.PUDOFF) setpullupdown(pi, 23, pigpio.PUDUP) setpullupdown(pi, 24, pigpio.PUDDOWN) ...

PiGPIO.Callback_ADTType

An ADT class to hold callback information

gpio:= Broadcom GPIO number. edge:= EITHEREDGE, RISINGEDGE, or FALLING_EDGE. func:= a user function taking three arguments (GPIO, level, tick).

PiGPIO.PulseType

A class to store pulse information.

gpioon: the GPIO to switch on at the start of the pulse. gpiooff: the GPIO to switch off at the start of the pulse. delay: the delay in microseconds before the next pulse.

PiGPIO._pigpio_commandFunction

Runs a pigpio socket command.

sl:= command socket and lock. cmd:= the command to be executed. p1:= command parameter 1 (if applicable). p2:= command parameter 2 (if applicable).

PiGPIO._pigpio_command_extFunction

Runs an extended pigpio socket command.

sl:= command socket and lock.

cmd:= the command to be executed. p1:= command parameter 1 (if applicable). p2:= command parameter 2 (if applicable). p3:= total size in bytes of following extents extents:= additional data blocks

PiGPIO._u2iMethod

Converts a 32 bit unsigned number to signed. If the number is negative it indicates an error. On error a pigpio exception will be raised if exceptions is true.

PiGPIO.appendMethod

Adds a callback to the notification thread.

PiGPIO.bb_i2c_closeMethod

This function stops bit banging I2C on a pair of GPIO previously opened with [bbi2copen].

SDA:= 0-31, the SDA GPIO used in a prior call to [bbi2copen]

Returns 0 if OK, otherwise PIBADUSERGPIO, or PINOTI2CGPIO.

... bbi2cclose(pi, SDA) ...

PiGPIO.bb_i2c_openFunction

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 PIBADUSERGPIO, PIBADI2CBAUD, or PIGPIOIN_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 = bbi2copen(pi, 4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps ...

PiGPIO.bb_i2c_zipMethod

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 [bbi2copen]) 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.bbi2czip( h, [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 ...

PiGPIO.bb_serial_invertMethod

Invert serial logic.

usergpio:= 0-31 (opened in a prior call to [*bbserialreadopen*]) invert:= 0-1 (1 invert, 0 normal)

... status = bbserialinvert(pi, 17, 1) ...

PiGPIO.bb_serial_readMethod

Returns data from the bit bang serial cyclic buffer.

usergpio:= 0-31 (opened in a prior call to [*bbserialreadopen*])

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 [bbserialread_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) = bbserialread(pi, 4) ...

PiGPIO.bb_serial_read_closeMethod

Closes a GPIO for bit bang reading of serial data.

usergpio:= 0-31 (opened in a prior call to [*bbserialreadopen*])

... status = bbserialread_close(pi, 17) ...

PiGPIO.bb_serial_read_openFunction

Opens a GPIO for bit bang reading of serial data.

usergpio:= 0-31, the GPIO to use. baud:= 50-250000, the baud rate. bbbits:= 1-32, the number of bits per word, default 8.

The serial data is held in a cyclic buffer and is read using [bbserialread].

It is the caller's responsibility to read data from the cyclic buffer in a timely fashion.

... status = bbserialreadopen(pi, 4, 19200) status = bbserialreadopen(pi, 17, 9600) ...

PiGPIO.callbackFunction

Calls a user supplied function (a callback) whenever the specified GPIO edge is detected.

usergpio:= 0-31. edge:= EITHEREDGE, RISINGEDGE (default), or FALLINGEDGE. func:= user supplied callback function.

The user supplied callback receives three parameters, the GPIO, the level, and the tick.

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).

... end

function cbf(gpio, level, tick) print(gpio, level, tick)

cb1 = callback(pi, 22, pigpio.EITHER_EDGE, cbf)

cb2 = callback(pi, 4, pigpio.EITHER_EDGE)

cb3 = callback(pi, 17)

print(cb3.tally())

cb3.reset_tally()

cb1.cancel() # To cancel callback cb1. ...

PiGPIO.cancelMethod

Cancels a callback by removing it from the notification thread.

PiGPIO.clear_bank_1Method

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 PISOMEPERMITTED indicates that the user is not allowed to write to one or more of the GPIO.

... clearbank1(int(pi, "111110010000",2)) ...

PiGPIO.clear_bank_2Method

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 PISOMEPERMITTED indicates that the user is not allowed to write to one or more of the GPIO.

... clearbank2(pi, 0x1010) ...

PiGPIO.custom_1Function

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 = custom_1(pi, )

value = custom_1(pi, 23)

value = custom_1(pi, 0, 55)

value = custom_1(pi, 23, 56, [1, 5, 7])

value = custom_1(pi, 23, 56, b"hello")

value = custom_1(pi, 23, 56, "hello") ...

PiGPIO.custom_2Function

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) = custom_2(pi, )

(count, data) = custom_2(pi, 23)

(count, data) = custom_2(pi, 23, [1, 5, 7])

(count, data) = custom_2(pi, 23, b"hello")

(count, data) = custom_2(pi, 23, "hello", 128) ...

PiGPIO.error_textMethod

Returns a text description of a pigpio error.

errnum:= <0, the error number

... print(pigpio.error_text(-5)) level not 0-1 ...

PiGPIO.get_PWM_dutycycleMethod

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 [getPWMrange]).

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).

... setPWMdutycycle(pi, 4, 25) print(getPWMdutycycle(pi, 4)) 25

setPWMdutycycle(pi, 4, 203) print(getPWMdutycycle(pi, 4)) 203 ...

PiGPIO.get_PWM_frequencyMethod

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 [setPWMfrequency].

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].

... setPWMfrequency(pi, 4,0) print(getPWMfrequency(pi, 4)) 10

setPWMfrequency(pi, 4, 800) print(getPWMfrequency(pi, 4)) 800 ...

PiGPIO.get_PWM_rangeMethod

Returns the range of PWM values being used on the GPIO.

user_gpio:= 0-31.

If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M).

... setPWMrange(pi, 9, 500) print(getPWMrange(pi, 9)) 500 ...

PiGPIO.get_PWM_real_rangeMethod

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.

... setPWMfrequency(pi, 4, 800) print(getPWMreal_range(pi, 4)) 250 ...

PiGPIO.get_current_tickMethod

Returns the current system tick.

Tick is the number of microseconds since system boot. As an unsigned 32 bit quantity tick wraps around approximately every 71.6 minutes.

... t1 = getcurrenttick(pi, ) time.sleep(1) t2 = getcurrenttick(pi, ) ...

PiGPIO.get_hardware_revisionMethod

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(gethardwarerevision(pi, )) 2 ...

PiGPIO.get_servo_pulsewidthMethod

Returns the servo pulsewidth being used on the GPIO.

user_gpio:= 0-31.

Returns the servo pulsewidth.

... setservopulsewidth(pi, 4, 525) print(getservopulsewidth(pi, 4)) 525

setservopulsewidth(pi, 4, 2130) print(getservopulsewidth(pi, 4)) 2130 ...

PiGPIO.hardware_clockMethod

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 PINOTPERMITTED, PIBADGPIO, PINOTHCLKGPIO, PIBADHCLKFREQ,or PIBADHCLK_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.

... hardware_clock(pi, 4, 5000) # 5 KHz clock on GPIO 4

hardware_clock(pi, 4, 40000000) # 40 MHz clock on GPIO 4 ...

PiGPIO.i2c_block_process_callMethod

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] length(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) = i2cblockprocess_call(pi, h, 10, b'\x02\x05\x00')

(b, d) = i2cblockprocess_call(pi, h, 10, b'abcdr')

(b, d) = i2cblockprocess_call(pi, h, 10, "abracad")

(b, d) = i2cblockprocess_call(pi, h, 10, [2, 5, 16]) ...

PiGPIO.i2c_closeMethod

Closes the I2C device associated with handle.

handle:= >=0 (as returned by a prior call to [i2c_open]).

... i2c_close(pi, h) ...

PiGPIO.i2c_openFunction

Returns a handle (>=0) for the device at the I2C bus address.

i2cbus:= >=0. i2caddress:= 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 = i2c_open(pi, 1, 0x53) # open device at address 0x53 on bus 1 ...

PiGPIO.i2c_process_callMethod

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] wordvalLow [A] wordvalHigh [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P . .

... r = i2cprocesscall(pi, h, 4, 0x1231) r = i2cprocesscall(pi, h, 6, 0) ...

PiGPIO.i2c_read_block_dataMethod

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) = i2creadblock_data(pi, h, 10) if b >= 0

process data

else

process read failure

...

PiGPIO.i2c_read_byteMethod

Reads a single byte from the device associated with handle.

handle:= >=0 (as returned by a prior call to [i2c_open]).

SMBus 2.0 5.5.3 - Receive byte. . . S Addr Rd [A] [Data] NA P . .

... b = i2creadbyte(pi, 2) # read a byte from device 2 ...

PiGPIO.i2c_read_byte_dataMethod

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 = i2creadbyte_data(pi, 2, 17)

read byte from reg 1 of device 0

b = i2creadbyte_data(pi, 0, 1) ...

PiGPIO.i2c_read_deviceMethod

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) = i2creaddevice(pi, h, 12) ...

PiGPIO.i2c_read_i2c_block_dataMethod

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) = i2creadi2cblockdata(pi, h, 4, 32) if b >= 0

process data

else

process read failure

...

PiGPIO.i2c_read_word_dataMethod

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 = i2creadword_data(pi, 3, 2)

read word from reg 7 of device 2

w = i2creadword_data(pi, 2, 7) ...

PiGPIO.i2c_write_block_dataMethod

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] length(data) [A] data0 [A] data1 [A] ... [A] datan [A] P . .

... i2cwriteblock_data(pi, 4, 5, b'hello')

i2cwriteblock_data(pi, 4, 5, "data bytes")

i2cwriteblock_data(pi, 5, 0, b'\x00\x01\x22')

i2cwriteblock_data(pi, 6, 2, [0, 1, 0x22]) ...

PiGPIO.i2c_write_byteMethod

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 . .

... i2cwritebyte(pi, 1, 17) # send byte 17 to device 1 i2cwritebyte(pi, 2, 0x23) # send byte 0x23 to device 2 ...

PiGPIO.i2c_write_byte_dataMethod

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

i2cwritebyte_data(pi, 1, 2, 0xC5)

send byte 9 to reg 4 of device 2

i2cwritebyte_data(pi, 2, 4, 9) ...

PiGPIO.i2c_write_deviceMethod

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 . .

... i2cwritedevice(pi, h, b"\x12\x34\xA8")

i2cwritedevice(pi, h, b"help")

i2cwritedevice(pi, h, 'help')

i2cwritedevice(pi, h, [23, 56, 231]) ...

PiGPIO.i2c_write_i2c_block_dataMethod

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 . .

... i2cwritei2cblockdata(pi, 4, 5, 'hello')

i2cwritei2cblockdata(pi, 4, 5, b'hello')

i2cwritei2cblockdata(pi, 5, 0, b'\x00\x01\x22')

i2cwritei2cblockdata(pi, 6, 2, [0, 1, 0x22]) ...

PiGPIO.i2c_write_quickMethod

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 . .

... i2cwritequick(pi, 0, 1) # send 1 to device 0 i2cwritequick(pi, 3, 0) # send 0 to device 3 ...

PiGPIO.i2c_write_word_dataMethod

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] wordvalLow [A] wordvalHigh [A] P . .

...

send word 0xA0C5 to reg 5 of device 4

i2cwriteword_data(pi, 4, 5, 0xA0C5)

send word 2 to reg 2 of device 5

i2cwriteword_data(pi, 5, 2, 23) ...

PiGPIO.i2c_zipMethod

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) = i2c_zip(pi, 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 ...

PiGPIO.notify_beginMethod

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 = notifyopen(pi, ) if h >= 0 notifybegin(pi, h, 1234) ...

PiGPIO.notify_closeMethod

Stops notifications on a handle and releases the handle for reuse.

handle:= >=0 (as returned by a prior call to [notify_open])

... h = notifyopen(pi, ) if h >= 0 notifybegin(pi, h, 1234) ... notify_close(pi, h) ... ...

PiGPIO.notify_openMethod

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.

. . I seqno I flags I tick I level . .

seqno: starts at 0 each time the handle is opened and then increments by one for each report.

flags: two flags are defined, PINTFYFLAGSWDOG and PINTFYFLAGSALIVE. If bit 5 is set (PINTFYFLAGSWDOG) then bits 0-4 of the flags indicate a GPIO which has had a watchdog timeout; if bit 6 is set (PINTFYFLAGSALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity.

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 = notifyopen(pi, ) if h >= 0 notifybegin(pi, h, 1234) ...

PiGPIO.notify_pauseMethod

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 = notifyopen(pi, ) if h >= 0 notifybegin(pi, h, 1234) ... notifypause(pi, h) ... notifybegin(pi, h, 1234) ... ...

PiGPIO.readMethod

Returns the GPIO level.

gpio:= 0-53.

... set_mode(pi, 23, pigpio.INPUT)

setpullupdown(pi, 23, pigpio.PUDDOWN) print(read(pi, 23)) 0

setpullupdown(pi, 23, pigpio.PUDUP) print(read(pi, 23)) 1 ...

PiGPIO.read_bank_1Method

Returns the levels of the bank 1 GPIO (GPIO 0-31).

The returned 32 bit integer has a bit set if the corresponding GPIO is high. GPIO n has bit value (1<<n).

... print(bin(readbank1(pi, ))) 0b10010100000011100100001001111 ...

PiGPIO.read_bank_2Method

Returns the levels of the bank 2 GPIO (GPIO 32-53).

The returned 32 bit integer has a bit set if the corresponding GPIO is high. GPIO n has bit value (1<<(n-32)).

... print(bin(readbank2(pi, ))) 0b1111110000000000000000 ...

PiGPIO.removeMethod

Removes a callback from the notification thread.

PiGPIO.runMethod

Runs the notification thread.

PiGPIO.rxbufMethod

Returns count bytes from the command socket.

PiGPIO.serial_closeMethod

Closes the serial device associated with handle.

handle:= >=0 (as returned by a prior call to [serial_open]).

... serial_close(pi, h1) ...

PiGPIO.serial_data_availableMethod

Returns the number of bytes available to be read from the device associated with handle.

handle:= >=0 (as returned by a prior call to [serial_open]).

... rdy = serialdataavailable(pi, h1)

if rdy > 0 (b, d) = serial_read(pi, h1, rdy) ...

PiGPIO.serial_openFunction

Returns a handle for the serial tty device opened at baud bits per second.

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 = serial_open(pi, "/dev/ttyAMA0", 300)

h2 = serial_open(pi, "/dev/ttyUSB1", 19200, 0) ...

PiGPIO.serial_readMethod

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.

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) = serial_read(pi, h2, 100) if b > 0

process read data

...

PiGPIO.serial_read_byteMethod

Returns a single byte from the device associated with handle.

handle:= >=0 (as returned by a prior call to [serial_open]).

... b = serialreadbyte(pi, h1) ...

PiGPIO.serial_writeMethod

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.

... serial_write(pi, h1, b'\x02\x03\x04')

serial_write(pi, h2, b'help')

serial_write(pi, h2, "hello")

serial_write(pi, h1, [2, 3, 4]) ...

PiGPIO.serial_write_byteMethod

Writes a single byte to the device associated with handle.

handle:= >=0 (as returned by a prior call to [serial_open]). byte_val:= 0-255, the value to write.

... serialwritebyte(pi, h1, 23)

serialwritebyte(h1, ord(pi, 'Z')) ...

PiGPIO.set_PWM_dutycycleMethod

Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO.

user_gpio:= 0-31. dutycycle:= 0-range (range defaults to 255).

The [setPWMrange] function can change the default range of 255.

... setPWMdutycycle(pi, 4, 0) # PWM off setPWMdutycycle(pi, 4, 64) # PWM 1/4 on setPWMdutycycle(pi, 4, 128) # PWM 1/2 on setPWMdutycycle(pi, 4, 192) # PWM 3/4 on setPWMdutycycle(pi, 4, 255) # PWM full on ...

PiGPIO.set_PWM_frequencyMethod

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 PIBADUSERGPIO or PINOT_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

. .

... setPWMfrequency(pi, 4,0) print(getPWMfrequency(pi, 4)) 10

setPWMfrequency(pi, 4,100000) print(getPWMfrequency(pi, 4)) 8000 ...

PiGPIO.set_PWM_rangeMethod

Sets the range of PWM values to be used on the GPIO.

usergpio:= 0-31. range:= 25-40000.

... setPWMrange(pi, 9, 100) # now 25 1/4, 50 1/2, 75 3/4 on setPWMrange(pi, 9, 500) # now 125 1/4, 250 1/2, 375 3/4 on setPWMrange(pi, 9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on ...

PiGPIO.set_bank_1Method

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 PISOMEPERMITTED indicates that the user is not allowed to write to one or more of the GPIO.

... setbank1(int(pi, "111110010000",2)) ...

PiGPIO.set_bank_2Method

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 PISOMEPERMITTED indicates that the user is not allowed to write to one or more of the GPIO.

... setbank2(pi, 0x303) ...

PiGPIO.set_servo_pulsewidthMethod

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 setservopulsewidth.

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.

... setservopulsewidth(pi, 17, 0) # off setservopulsewidth(pi, 17, 1000) # safe anti-clockwise setservopulsewidth(pi, 17, 1500) # centre setservopulsewidth(pi, 17, 2000) # safe clockwise ...

PiGPIO.set_watchdogMethod

Sets a watchdog timeout for a GPIO.

usergpio:= 0-31. wdogtimeout:= 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.

If no level change has been detected for the GPIO for timeout milliseconds any notification for the GPIO has a report written to the fifo with the flags set to indicate a watchdog timeout.

The callback class interprets the flags and will call registered callbacks for the GPIO with level TIMEOUT.

... setwatchdog(pi, 23, 1000) # 1000 ms watchdog on GPIO 23 setwatchdog(pi, 23, 0) # cancel watchdog on GPIO 23 ...

PiGPIO.spi_closeMethod

Closes the SPI device associated with handle.

handle:= >=0 (as returned by a prior call to [spi_open]).

... spi_close(pi, h) ...

PiGPIO.spi_openFunction

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.

spichannel:= 0-1 (0-2 for the auxiliary SPI device). baud:= 32K-125M (values above 30M are unlikely to work). spiflags:= 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.

E.g. 32 12-bit words will be transferred in 64 bytes.

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 = spi_open(pi, 1, 50000, 3) ...

PiGPIO.spi_readMethod

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) = spi_read(pi, h, 60) # read 60 bytes from device h if b == 60

process read data

else

error path

...

PiGPIO.spi_writeMethod

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.

... spi_write(pi, 0, b'\x02\xc0\x80') # write 3 bytes to device 0

spi_write(pi, 0, b'defgh') # write 5 bytes to device 0

spi_write(pi, 0, "def") # write 3 bytes to device 0

spi_write(pi, 1, [2, 192, 128]) # write 3 bytes to device 1 ...

PiGPIO.spi_xferMethod

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, rxdata) = spixfer(pi, h, b'\x01\x80\x00')

(count, rxdata) = spixfer(pi, h, [1, 128, 0])

(count, rxdata) = spixfer(pi, h, b"hello")

(count, rxdata) = spixfer(pi, h, "hello") ...

PiGPIO.stopMethod

Release pigpio resources. ... stop(pi) ...

PiGPIO.tallyMethod

Provides a count of how many times the default tally callback has triggered.

The count will be zero if the user has supplied their own callback function.

PiGPIO.tickDiffMethod

Returns the microsecond difference between two ticks.

t1:= the earlier tick t2:= the later tick

... print(pigpio.tickDiff(4294967272, 12)) 36 ...

PiGPIO.wait_for_edgeFunction

Wait for an edge event on a GPIO.

usergpio:= 0-31. edge:= EITHEREDGE, RISINGEDGE (default), or FALLINGEDGE. 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 waitforedge(pi, 23) print("Rising edge detected") else print("wait for edge timed out")

if waitforedge(pi, 23, pigpio.FALLING_EDGE, 5.0) print("Falling edge detected") else print("wait for falling edge timed out") ...

PiGPIO.wave_add_genericMethod

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

setmode(pi, G1, pigpio.OUTPUT) setmode(pi, G2, pigpio.OUTPUT)

flash500=[] # flash every 500 ms flash100=[] # flash every 100 ms

ON OFF DELAY

flash500.append(pigpio.pulse(1<<G1, 1<<G2, 500000)) flash500.append(pigpio.pulse(1<<G2, 1<<G1, 500000))

flash100.append(pigpio.pulse(1<<G1, 1<<G2, 100000)) flash100.append(pigpio.pulse(1<<G2, 1<<G1, 100000))

wave_clear(pi, ) # clear any existing waveforms

waveaddgeneric(pi, flash500) # 500 ms flashes f500 = wavecreate(pi, ) # create and save id

waveaddgeneric(pi, flash100) # 100 ms flashes f100 = wavecreate(pi, ) # create and save id

wavesendrepeat(pi, f500)

time.sleep(4)

wavesendrepeat(pi, f100)

time.sleep(4)

wavesendrepeat(pi, f500)

time.sleep(4)

wavetxstop(pi, ) # stop waveform

wave_clear(pi, ) # clear all waveforms ...

PiGPIO.wave_add_newMethod

Starts a new empty waveform.

You would not normally need to call this function as it is automatically called after a waveform is created with the [wave_create] function.

... waveaddnew(pi, ) ...

PiGPIO.wave_add_serialFunction

Adds a waveform representing serial data to the existing waveform (if any). The serial data starts [offset] microseconds from the start of the waveform.

usergpio:= 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. bbbits:= 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.

... waveaddserial(pi, 4, 300, 'Hello world')

waveaddserial(pi, 4, 300, b"Hello world")

waveaddserial(pi, 4, 300, b'\x23\x01\x00\x45')

waveaddserial(pi, 17, 38400, [23, 128, 234], 5000) ...

PiGPIO.wave_chainMethod

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 PICHAINNESTING, PICHAINLOOPCNT, PIBADCHAINLOOP, PIBADCHAINCMD, PICHAINCOUNTER, PIBADCHAINDELAY, PICHAINTOOBIG, or PIBADWAVEID.

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 + y256 times Delay @ 255 2 x y @ delay x + y256 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.

set_mode(pi, GPIO, pigpio.OUTPUT);

for i in range(WAVES) pi.waveaddgeneric([ pigpio.pulse(1<<GPIO, 0, 20), pigpio.pulse(0, 1<<GPIO, (i+1)*200)]);

wid[i] = wave_create(pi, );

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 wavetxbusy(pi, ) time.sleep(0.1);

for i in range(WAVES) wave_delete(pi, wid[i])

stop(pi, ) ...

PiGPIO.wave_clearMethod

Clears all waveforms and any data added by calls to the [*waveadd**] functions.

... wave_clear(pi, ) ...

PiGPIO.wave_createMethod

Creates a waveform from the data provided by the prior calls to the [*waveadd**] functions.

Returns a wave id (>=0) if OK, otherwise PIEMPTYWAVEFORM, PITOOMANYCBS, PITOOMANYOOL, or PINOWAVEFORM_ID.

The data provided by the [*waveadd**] functions is consumed by this function.

As many waveforms may be created as there is space available. The wave id is passed to [*wavesend**] to specify the waveform to transmit.

Normal usage would be

Step 1. [wave_clear] to clear all waveforms and added data.

Step 2. [*waveadd**] 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. [*wavesend**] 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 = wave_create(pi, ) ...

PiGPIO.wave_deleteMethod

This function deletes the waveform with id wave_id.

waveid:= >=0 (as returned by a prior call to [*wavecreate*]).

Wave ids are allocated in order, 0, 1, 2, etc.

... wave_delete(pi, 6) # delete waveform with id 6

wave_delete(pi, 0) # delete waveform with id 0 ...

PiGPIO.wave_get_cbsMethod

Returns the length in DMA control blocks of the current waveform.

... cbs = wavegetcbs(pi, ) ...

PiGPIO.wave_get_max_cbsMethod

Returns the maximum possible size of a waveform in DMA control blocks.

... cbs = wavegetmax_cbs(pi, ) ...

PiGPIO.wave_get_max_microsMethod

Returns the maximum possible size of a waveform in microseconds.

... micros = wavegetmax_micros(pi, ) ...

PiGPIO.wave_get_max_pulsesMethod

Returns the maximum possible size of a waveform in pulses.

... pulses = wavegetmax_pulses(pi, ) ...

PiGPIO.wave_get_microsMethod

Returns the length in microseconds of the current waveform.

... micros = wavegetmicros(pi, ) ...

PiGPIO.wave_get_pulsesMethod

Returns the length in pulses of the current waveform.

... pulses = wavegetpulses(pi, ) ...

PiGPIO.wave_send_onceMethod

Transmits the waveform with id wave_id. The waveform is sent once.

NOTE: Any hardware PWM started by [hardware_PWM] will be cancelled.

waveid:= >=0 (as returned by a prior call to [*wavecreate*]).

Returns the number of DMA control blocks used in the waveform.

... cbs = wavesendonce(pi, wid) ...

PiGPIO.wave_send_repeatMethod

Transmits the waveform with id waveid. The waveform repeats until wavetxstop is called or another call to [*wavesend_**] is made.

NOTE: Any hardware PWM started by [hardware_PWM] will be cancelled.

waveid:= >=0 (as returned by a prior call to [*wavecreate*]).

Returns the number of DMA control blocks used in the waveform.

... cbs = wavesendrepeat(pi, wid) ...

PiGPIO.wave_send_using_modeMethod

Transmits the waveform with id wave_id using mode mode.

waveid:= >=0 (as returned by a prior call to [*wavecreate*]). mode:= WAVEMODEONESHOT, WAVEMODEREPEAT, WAVEMODEONESHOTSYNC, or WAVEMODEREPEATSYNC.

WAVEMODEONESHOT: same as [*wavesend_once*].

WAVEMODEREPEAT same as [wavesendrepeat].

WAVEMODEONESHOTSYNC same as [wavesendonce] but tries to sync with the previous waveform.

WAVEMODEREPEATSYNC same as [*wavesend_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.

waveid:= >=0 (as returned by a prior call to [*wavecreate*]).

Returns the number of DMA control blocks used in the waveform.

... cbs = wavesendusingmode(pi, wid, WAVEMODEREPEATSYNC) ...

PiGPIO.wave_tx_atMethod

Returns the id of the waveform currently being transmitted.

Returns the waveform id or one of the following special values

WAVENOTFOUND (9998) - transmitted wave not found. NOTXWAVE (9999) - no wave being transmitted.

... wid = wavetxat(pi, ) ...

PiGPIO.wave_tx_busyMethod

Returns 1 if a waveform is currently being transmitted, otherwise 0.

... wavesendonce(pi, 0) # send first waveform

while wavetxbusy(pi, ): # wait for waveform to be sent time.sleep(0.1)

wavesendonce(pi, 1) # send next waveform ...

PiGPIO.wave_tx_repeatMethod

This function is deprecated and has beeen removed.

Use [wave_create]/[*wavesend**] instead.

PiGPIO.wave_tx_startMethod

This function is deprecated and has been removed.

Use [wave_create]/[*wavesend**] instead.

PiGPIO.wave_tx_stopMethod

Stops the transmission of the current waveform.

This function is intended to stop a waveform started with wavesendrepeat.

... wavesendrepeat(pi, 3)

time.sleep(5)

wavetxstop(pi, ) ...

PiGPIO.writeMethod

Sets the GPIO level.

GPIO:= 0-53. level:= 0, 1.

If PWM or servo pulses are active on the GPIO they are switched off.

... set_mode(pi, 17, pigpio.OUTPUT)

write(pi, 17,0) print(read(pi, 17)) 0

write(pi, 17,1) print(read(pi, 17)) 1 ...