pigs(1)

๐Ÿ“ฆ
version 1.78 ยท 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– pigs ๐Ÿ’–

pigpio archive ยท pigs(1) โ€” and also its lil sibling /dev/pigpio, which lives in the same manual page, so bestie, you're getting both ๐Ÿซถ


โœจ NAME โœจ

pigs โ€” command line socket access to the pigpio daemon.

/dev/pigpio โ€” command line pipe access to the pigpio daemon.


๐ŸŒธ SYNOPSIS ๐ŸŒธ

sudo pigpiod

then

pigs {command}+

or

echo {command}+ >/dev/pigpio

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

The socket and pipe interfaces let you control the Pi's GPIO by passing messages to the running pigpio library. It's giving remote control for your pins, fr fr.

The normal way to start the pigpio library would be as a daemon during boot, like:

sudo pigpiod

๐ŸŽ€ Features ๐ŸŽ€

  • hardware timed PWM on any of GPIO 0-31 โœจ
  • hardware timed servo pulses on any of GPIO 0-31 โœจ
  • reading/writing all of the GPIO in a bank as one operation
  • individually setting GPIO modes, reading and writing
  • notifications when any of GPIO 0-31 change state ๐Ÿ””
  • the construction of output waveforms with microsecond timing
  • I2C, SPI, and serial link wrappers
  • creating and running scripts on the pigpio daemon

๐ŸŒˆ GPIO ๐ŸŒˆ

ALL GPIO are identified by their Broadcom number. That's the number, no cap.

๐Ÿ’… Usage ๐Ÿ’…

pigs is a program and internally uses the socket interface to pigpio, whereas /dev/pigpio uses the pipe interface.

pigs and the pipe interface share the same commands and are invoked in a similar fashion from the command line. Same energy, different plumbing.

The pigpio library must be running, either by running a program linked with the library or starting the pigpio daemon (sudo pigpiod).

pigs {command}+
echo "{command}+" >/dev/pigpio

pigs will show the result of the command on screen.

The pigs process returns an exit status (which can be displayed with the command echo $?). Here's the whole mood board:

  • PIGS_OK โ€” 0 โœ…
  • PIGS_CONNECT_ERR โ€” 255
  • PIGS_OPTION_ERR โ€” 254
  • PIGS_SCRIPT_ERR โ€” 253

The results of /dev/pigpio commands need to be read from /dev/pigout, e.g. cat /dev/pigout (try cat /dev/pigout& so that all subsequent results are shown on screen). Yes, the ampersand is doing a lot of heavy lifting there ๐Ÿ’€

In both cases if an error was detected a message will have been written to /dev/pigerr (try cat /dev/pigerr&). This is likely to be more informative than the message returned by pigs or the error code returned by the pipe interface. So like, check pigerr first, it's the one telling the truth.

Several commands may be entered on a line. If present PROC and PARSE must be the last command on a line. ๐Ÿ‘‘

E.g.

pigs w 22 1 mils 1000 w 22 0

is equivalent to

pigs w 22 1
pigs mils 1000
pigs w 22 0

and

echo "m 4 w w 4 0 mils 250 m 4 r r 4" >/dev/pigpio

is equivalent to

echo "m 4 w"    >/dev/pigpio
echo "w 4 0"    >/dev/pigpio
echo "mils 250" >/dev/pigpio
echo "m 4 r"    >/dev/pigpio
echo "r 4"      >/dev/pigpio

๐Ÿ“ Notes ๐Ÿ“

The examples from now on will show the pigs interface but the same commands will also work on the pipe interface.

pigs does not show the status of successful commands unless the command itself returns data. The status (0) will be returned to pigs but will be discarded. Silently slaying, basically ๐Ÿ™ˆ

The status/data of each command sent to the pipe interface should be read from /dev/pigout.

When a command takes a number as a parameter it may be entered as hex (precede by 0x), octal (precede by 0), or decimal.

E.g. 23 is 23 decimal, 0x100 is 256 decimal, 070 is 56 decimal.

Some commands can return a variable number of data bytes. By default this data is displayed as decimal. The pigs -a option can be used to force the display as ASCII and the pigs -x option can be used to force the display as hex.

E.g. assuming the transmitted serial data is the letters ABCDEONM

$ pigs slr 4 100
8 65 66 67 68 69 79 78 77
$ pigs -a slr 4 100
8 ABCDEONM
$ pigs -x slr 4 100
8 41 42 43 44 45 4f 4e 4d

๐Ÿ‘‘ OVERVIEW ๐Ÿ‘‘

๐Ÿ’œ BASIC ๐Ÿ’œ

  • M/MODES g m โ€” Set GPIO mode
  • MG/MODEG g โ€” Get GPIO mode
  • PUD g p โ€” Set GPIO pull up/down
  • R/READ g โ€” Read GPIO level
  • W/WRITE g L โ€” Write GPIO level

๐ŸŒธ PWM (overrides servo commands on same GPIO) ๐ŸŒธ

  • P/PWM u v โ€” Set GPIO PWM value
  • PFS u v โ€” Set GPIO PWM frequency
  • PRS u v โ€” Set GPIO PWM range
  • GDC u โ€” Get GPIO PWM dutycycle
  • PFG u โ€” Get GPIO PWM frequency
  • PRG u โ€” Get GPIO PWM range
  • PRRG u โ€” Get GPIO PWM real range

๐Ÿงš Servo (overrides PWM commands on same GPIO) ๐Ÿงš

  • S/SERVO u v โ€” Set GPIO servo pulsewidth
  • GPW u โ€” Get GPIO servo pulsewidth

โญ INTERMEDIATE โญ

  • TRIG u pl L โ€” Send a trigger pulse
  • WDOG u v โ€” Set GPIO watchdog
  • BR1 โ€” Read bank 1 GPIO
  • BR2 โ€” Read bank 2 GPIO
  • BC1 bits โ€” Clear specified GPIO in bank 1
  • BC2 bits โ€” Clear specified GPIO in bank 2
  • BS1 bits โ€” Set specified GPIO in bank 1
  • BS2 bits โ€” Set specified GPIO in bank 2

๐Ÿ”ฅ ADVANCED ๐Ÿ”ฅ

  • NO โ€” Request a notification
  • NC h โ€” Close notification
  • NB h bits โ€” Start notification
  • NP h โ€” Pause notification
  • HC g cf โ€” Set hardware clock frequency
  • HP g pf pdc โ€” Set hardware PWM frequency and dutycycle
  • FG u stdy โ€” Set a glitch filter on a GPIO
  • FN u stdy actv โ€” Set a noise filter on a GPIO
  • PADS pad padma โ€” Set pad drive strength
  • PADG pad โ€” Get pad drive strength
  • SHELL name str โ€” Execute a shell command

๐Ÿ’– Custom ๐Ÿ’–

  • CF1 uvs โ€” Custom function 1
  • CF2 uvs โ€” Custom function 2

๐ŸŽ€ Events ๐ŸŽ€

  • EVM h bits โ€” Set events to monitor
  • EVT event โ€” Trigger event

๐Ÿ“œ Scripts ๐Ÿ“œ

  • PROC t โ€” Store script
  • PROCR sid pars โ€” Run script
  • PROCU sid pars โ€” Set script parameters
  • PROCP sid โ€” Get script status and parameters
  • PROCS sid โ€” Stop script
  • PROCD sid โ€” Delete script
  • PARSE t โ€” Validate script

๐Ÿฆ‹ I2C ๐Ÿฆ‹

  • I2CO ib id if โ€” Open I2C bus and device with flags
  • I2CC h โ€” Close I2C handle
  • I2CWQ h bit smb โ€” Write Quick: write bit
  • I2CRS h smb โ€” Read Byte: read byte
  • I2CWS h bv smb โ€” Write Byte: write byte
  • I2CRB h r smb โ€” Read Byte Data: read byte from register
  • I2CWB h r bv smb โ€” Write Byte Data: write byte to register
  • I2CRW h r smb โ€” Read Word Data: read word from register
  • I2CWW h r wv smb โ€” Write Word Data: write word to register
  • I2CRK h r smb โ€” Read Block Data: read data from register
  • I2CWK h r bvs smb โ€” Write Block Data: write data to register
  • I2CWI h r bvs smb โ€” Write I2C Block Data
  • I2CRI h r num smb โ€” Read I2C Block Data: read bytes from register
  • I2CRD h num i2c โ€” Read device
  • I2CWD h bvs i2c โ€” Write device
  • I2CPC h r wv smb โ€” Process Call: exchange register with word
  • I2CPK h r bvs smb โ€” Block Process Call: exchange data bytes with register
  • I2CZ h bvs โ€” Performs multiple I2C transactions

๐ŸŒˆ I2C BIT BANG ๐ŸŒˆ

  • BI2CO sda scl b โ€” Open bit bang I2C
  • BI2CC sda โ€” Close bit bang I2C
  • BI2CZ sda bvs โ€” I2C bit bang multiple transactions

๐Ÿ’œ I2C/SPI SLAVE ๐Ÿ’œ

  • BSCX bctl bvs โ€” BSC I2C/SPI transfer

๐Ÿ“ SERIAL ๐Ÿ“

  • SERO dev b sef โ€” Open serial device dev at baud b with flags
  • SERC h โ€” Close serial handle
  • SERRB โ€” Read byte from serial handle
  • SERWB h bv โ€” Write byte to serial handle
  • SERR h num โ€” Read bytes from serial handle
  • SERW h bvs โ€” Write bytes to serial handle
  • SERDA h โ€” Check for serial data ready to read

๐ŸŒธ SERIAL BIT BANG (read only) ๐ŸŒธ

  • SLRO u b db โ€” Open GPIO for bit bang serial data
  • SLRC u โ€” Close GPIO for bit bang serial data
  • SLRI u v โ€” Sets bit bang serial data logic levels
  • SLR u num โ€” Read bit bang serial data from GPIO

โญ SPI โญ

  • SPIO c b spf โ€” SPI open channel at baud b with flags
  • SPIC h โ€” SPI close handle
  • SPIR h num โ€” SPI read bytes from handle
  • SPIW h bvs โ€” SPI write bytes to handle
  • SPIX h bvs โ€” SPI transfer bytes to handle

๐Ÿงš SPI BIT BANG ๐Ÿงš

  • BSPIO cs miso mosi sclk b spf โ€” Open bit bang SPI
  • BSPIC cs โ€” Close bit bang SPI
  • BSPIX cs bvs โ€” SPI bit bang transfer

๐Ÿ“ FILES ๐Ÿ“

  • FO file mode โ€” Open a file in mode
  • FC h โ€” Close file handle
  • FR h num โ€” Read bytes from file handle
  • FW h bvs โ€” Write bytes to file handle
  • FS h num from โ€” Seek to file handle position
  • FL pat num โ€” List files which match pattern

๐ŸŒŠ WAVES ๐ŸŒŠ

  • WVCLR โ€” Clear all waveforms
  • WVNEW โ€” Initialise a new waveform
  • WVAG trips โ€” Add generic pulses to waveform
  • WVAS u b db sb o bvs โ€” Add serial data to waveform
  • WVCRE โ€” Create a waveform
  • WVCAP percent โ€” Create a waveform of fixed size
  • WVDEL wid โ€” Delete selected waveform
  • WVTX wid โ€” Transmits waveform once
  • WVTXM wid wmde โ€” Transmits waveform using mode
  • WVTXR wid โ€” Transmits waveform repeatedly
  • WVCHA bvs โ€” Transmits a chain of waveforms
  • WVTAT โ€” Returns the current transmitting waveform
  • WVBSY โ€” Check if waveform is being transmitted
  • WVHLT โ€” Stop waveform
  • WVSC ws โ€” Get waveform DMA CB stats
  • WVSM ws โ€” Get waveform time stats
  • WVSP ws โ€” Get waveform pulse stats

๐Ÿ› ๏ธ UTILITIES ๐Ÿ› ๏ธ

  • H/HELP โ€” Display command help
  • HWVER โ€” Get hardware version
  • MICS v โ€” Microseconds delay
  • MILS v โ€” Milliseconds delay
  • PIGPV โ€” Get pigpio library version
  • T/TICK โ€” Get current tick

โš™๏ธ CONFIGURATION โš™๏ธ

  • CGI โ€” Configuration get internals
  • CSI v โ€” Configuration set internals

๐Ÿซถ COMMANDS ๐Ÿซถ

๐Ÿ’… BC1 bits โ€” Clear specified GPIO in bank 1

This command clears (sets low) the GPIO specified by bits in bank 1. Bank 1 consists of GPIO 0-31.

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs bc1 0x400010 # clear GPIO 4 (1<<4) and 22 (1<<22)
$ pigs bc1 32 # clear GPIO 5 (1<<5)
-42
ERROR: no permission to update one or more GPIO

๐Ÿ’… BC2 bits โ€” Clear specified GPIO in bank 2

This command clears (sets low) the GPIO specified by bits in bank 2. Bank 2 consists of GPIO 32-53.

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs bc2 0x8000 # clear GPIO 47 (activity LED on A+/B+/Pi2/Pi3)
$ pigs bc2 1 # clear GPIO 32 (first in bank 2)
-42
ERROR: no permission to update one or more GPIO

๐ŸŒˆ BI2CC sda โ€” Close bit bang I2C

This command signals that bit banging I2C on sda (and scl) is no longer required. It's the "we're done here bestie" command โœจ

Example

$ pigs bi2cc 5

๐Ÿฆ‹ BI2CO sda scl b โ€” Open bit bang I2C

This command signals that GPIO sda and scl are to be used for bit banging I2C at b baud.

Bit banging I2C allows for certain operations which are not possible with the standard I2C driver. Like, it just unlocks stuff:

  • baud rates as low as 50
  • repeated starts
  • clock stretching
  • I2C on any pair of spare GPIO

The baud rate may be between 50 and 500000 bits per second.

โš ๏ธ 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. Don't skip the pull-ups, bestie, it will simply not work ๐Ÿ’€

๐Ÿ‘‘ BI2CZ sda bvs โ€” I2C bit bang multiple transactions

This function executes a sequence of bit banged I2C operations. The operations to be performed are specified by the contents of bvs, which contains the concatenated command codes and associated data.

The following command codes are supported:


okay so that's part one, and the command codes are about to spill out โ€” hold that thought, bestie, because there's a whole lot more where this came from ๐Ÿ’–

...and the command byte language goes like this:

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

So address, read and write all take a param P, bestie. Normally P is one byte</> (0-255). But if the Escape command comes first, P is two bytes (0-65535, least significant byte first). Sneaky but iconic. ๐Ÿ’…

The address and flags both default to 0, and they just keep their previous value until you update them. Lowkey forgetful-proof.

No flags are currently defined. (Yes, really. Nada. Zero. ๐Ÿซถ)

โœจ Example โœจ

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

๐ŸŒธ BR1 โ€” Read bank 1 GPIO ๐ŸŒธ

This command reads GPIO 0-31 (bank 1) and hands back the levels as a 32-bit hexadecimal value. She's giving bitmask energy. ๐Ÿ”ฅ

Example

$ pigs br1
1001C1CF

๐Ÿฆ‹ BR2 โ€” Read bank 2 GPIO ๐Ÿฆ‹

Same vibe, different bank: this one reads GPIO 32-53 (bank 2) and returns the levels as a 32-bit hexadecimal value. ๐Ÿ’–

Example

$ pigs br2
003F0000

โญ BS1 bits โ€” Set specified GPIO in bank 1 โญ

This command sets (i.e. sets high) the GPIO you point at with bits, in bank 1. Bank 1 is the 0-31 girlies. ๐Ÿ‘‘

On success: nothing comes back. On error: a negative status code. That's it, that's the whole thing.

Example

$ pigs bs1 16 # set GPIO 4 (1<<4)

$ pigs bs1 1 # set GPIO 1 (1<<0)
-42
ERROR: no permission to update one or more GPIO

๐Ÿ’œ BS2 bits โ€” Set specified GPIO in bank 2 ๐Ÿ’œ

Identical energy, but for bank 2: this sets (sets high) the GPIO specified by bits in bank 2. Bank 2 spans 32-53. ๐ŸŽ€

Success = no output. Failure = negative status code, as always.

Example

$ pigs bs2 0x40 # set GPIO 38 (enable high current mode A+/B+/Pi2/Pi3)

$ pigs bs2 1 # set GPIO 32 (first in bank 2)
-42
ERROR: no permission to update one or more GPIO

๐Ÿ”ฅ BSCX bctl bvs โ€” BSC I2C/SPI transfer ๐Ÿ”ฅ

Ok this one is the main character, genuinely. It performs a BSC I2C/SPI slave transfer as defined by bctl, with data bvs.

It's a low-level interface to the SPI/I2C Slave peripheral on the BCM chip. This peripheral lets your Pi act as a hardware slave device on an I2C or SPI bus. ๐Ÿ˜ญ so cool.

And no, it is not a bit bang version, so it's OS timing independent โ€” the chip handles the bus timing directly. No cap.

The output process is simple: you just append data to the FIFO buffer on the chip. Think of it like a queue โ€” you add stuff, the master takes it out. ๐Ÿ“

I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. (Just so you know, bestie โ€” that's a known thing. ๐Ÿ™ˆ)

The command sets the BSC mode and writes any data bvs to the BSC transmit FIFO. It returns the data count (at least 1 for the status word), the status word, and then any data bytes read from the BSC receive FIFO.

Heads up: the control word sets the BSC mode, and the BSC will stay in that mode until you send a different control word. It's committed. ๐Ÿ’…

For I2C, use a control word of (I2C address << 16) + 0x305.

E.g. to talk as an I2C slave with address 0x13, use 0x130305.

GPIO used for models other than those based on the BCM2711:

      SDA   SCL   MOSI   SCLK   MISO   CE
I2C   18    19    -      -      -      -
SPI   -     -     18     19     20     21

GPIO used for models based on the BCM2711 (e.g. the Pi4B):

      SDA   SCL   MOSI   SCLK   MISO   CE
I2C   10    11    -      -      -      -
SPI   -     -     10     11     9      8

When a zero control word is received, the used GPIO gets reset to INPUT mode. Clean exit, slay. โœจ

The control word 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 returned 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 receive 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

This example assumes that GPIO 2/3 are connected to GPIO 18/19 (GPIO 10/11 on the BCM2711).

Example

$ pigs bscx 0x130305 # start BSC as I2C slave 0x13
1 18

$ 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 # get handle for device 0x13 on bus 1
0

$ pigs i2cwd 0 90 87 51 9 23 # write 5 bytes

$ pigs bscx 0x130305 # check for data
6 18 90 87 51 9 23

$ pigs bscx 0x130305 11 13 15 17 # check for data and send 4 bytes
1 262338

$ pigs i2crd 0 4 # read 4 bytes
4 11 13 15 17

$ pigs i2cwd 0 90 87 51 9 23 # write 5 bytes
$ pigs bscx 0x130305 11 13 15 17 # check for data and send 4 bytes
6 262338 90 87 51 9 23

$ pigs i2crd 0 4
4 11 13 15 17

$ pigs bscx 0x130305 22 33 44 55 66
1 327938
$ pigs i2crd 0 5
5 22 33 44 55 66

๐Ÿงš BSPIC cs โ€” Close bit bang SPI ๐Ÿงš

This command stops bit banging SPI on a set of GPIO that you opened with BSPIO. ๐Ÿ’€

The set of GPIO is specified by cs.

On success: nothing is returned. On error: a negative status code.

Example

$ pigs bspic 10

$ pigs bspic 10
-142
ERROR: no bit bang SPI in progress on GPIO

๐ŸŽ€ BSPIO cs miso mosi sclk b spf โ€” Open bit bang SPI ๐ŸŽ€

This one starts bit banging SPI on a group of GPIO โ€” slave select cs, MISO miso, MOSI mosi, and clock sclk. ๐ŸŒˆ

Data gets transferred at baud b bits per second, and b may be set in the range 50-250000.

The flags spf let you modify the default behaviour of mode 0, active low chip select. Fancy. โœจ

The flags consist 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:

Mode POL PHA
 0    0   0
 1    0   1
 2    1   0
 3    1   1
  • p is 0 if CS is active low (the default) and 1 for active high.
  • T is 1 if the least significant bit is transmitted on MOSI first; the default (0) shifts the most significant bit out first.
  • R is 1 if the least significant bit is received on MISO first; the default (0) receives the most significant bit first.
The other bits in flags should be set to zero. Don't be chaotic. ๐Ÿ™ˆ

On success, 0 is returned. On error, a negative status code.

If more than one device is connected to the SPI bus (defined by SCLK, MOSI, and MISO), each one must have its own CS. No sharing, bestie. ๐Ÿ’…

Example

$ pigs bspio  9 11 12 13 50000 0

$ pigs bspio 10 11 12 13 50000 0

$ pigs bspio 29 19 20 21 50000 0 # GPIO 29 not avaialble on this Pi
-41
ERROR: no permission to update GPIO

๐Ÿ“ BSPIX cs bvs โ€” SPI bit bang transfer ๐Ÿ“

This command writes bytes bvs to the bit bang SPI device associated with slave select cs. Then it returns the same number of bytes read back from the device. Exchange, iconic. ๐Ÿซถ

On success: the count of returned bytes followed by the bytes themselves. On error: a negative status code.

Example

$ pigs bspio 5 13 19 12 10000 0 # MCP4251 DAC
$ pigs bspio 6 13 19 12 20000 3 # MCP3008 ADC

$ pigs bspix 5 0 16             # set DAC to 16
2 255 255

$ pigs bspix 5 12 0             # read back DAC
2 254 16

$ pigs bspix 6 1 128 0          # read ADC input 0
3 0 3 184                       # 952

$ pigs bspix 5 0 240            # set DAC to 240
2 255 255

$ pigs bspix 5 12 0             # read back DAC
2 254 240

$ pigs bspix 6 1 128 0          # read ADC input 0
3 0 0 63                        # 63

$ pigs bspix 5 0 128            # set DAC to 128
2 255 255

$ pigs bspix 5 12 0             # read back DAC
2 254 128

$ pigs bspix 6 1 128 0          # read ADC input 0
3 0 1 255                       # 511

$ pigs bspic 5                  # close SPI CS 5
$ pigs bspic 6                  # close SPI CS 6

$ pigs bspic 5                  # try to close SPI CS 5 again
-142
ERROR: no bit bang SPI in progress on GPIO

๐Ÿ‘‘ CF1 uvs โ€” Custom function 1 ๐Ÿ‘‘

CF2 uvs โ€” custom function 2 ๐ŸŽ€

Bestie, this one calls a user customised function. What the parameters mean and what comes back is entirely up to whoever customised it. No notes. It's giving bespoke. ๐Ÿ’…


CGI โ€” configuration get internals โœจ

This one hands you back the value of the internal library configuration settings. Just... the internals. Spilled. ๐Ÿซ–


CSI v โ€” configuration set internals ๐ŸŒธ

Sets the value of the internal library configuration settings to v. Same energy, but make it a setter.


EVM h bits โ€” set events to monitor ๐Ÿ‘‘

This starts event reporting on handle h โ€” and h is the handle you got back from a prior call to NO. Remember NO? Yeah. That one.

Upon success, nothing is returned. On error, a negative status code comes back at you. ๐Ÿ˜ญ

The notification reports every single event specified by bits.

Example

$ pigs evm 0 -1 # Shorthand for events 0-31.
$ pigs evm 0 0xf0 # Get notifications for events 4-7.

$ pigs evm 1 0xf
-25
ERROR: unknown handle

EVT event โ€” trigger event ๐Ÿ”ฅ

Triggers event. That's it. That's the command.

One event, number 31, is predefined โ€” it's the one that gets auto generated on BSC slave activity. Iconic of it, honestly.

Example

$ pigs evt 12
$ pigs evt 5

$ pigs evt 32
-143
ERROR: bad event id

FC h โ€” close file handle ๐Ÿ™ˆ

Closes a file handle h that you previously opened with FO.

Upon success, nothing is returned. On error, a negative status code. The usual deal.

Example

$ pigs fc 0 # First close okay.

$ pigs fc 0 # Second fails.
-25
ERROR: unknown handle
Not the second one failing ๐Ÿ’€ you already closed it bestie, it's gone.

FG u stdy โ€” set a glitch filter on a GPIO ๐Ÿฆ‹

Level changes on the GPIO u are not reported unless the level has been stable for at least stdy microseconds. Once it's been chill for that long, then the level gets reported. Any level changes shorter than stdy microseconds? Ignored. Not on the timeline. โœ‹

The filter only affects callbacks (including pipe notifications).

The R/READ, BR1, and BR2 commands are not affected.

Heads up: each (stable) edge will be timestamped stdy microseconds after it was first detected. So it's a little late to the party, by design.

Example

$ pigs fg 4 250

$ pigs fg 4 1000000
-125
ERROR: bad filter parameter

FL pat num โ€” list files which match pattern ๐Ÿ”

Returns a list of the files matching pat. Up to num bytes may be returned โ€” that's your ceiling.

Upon success you get the count of returned bytes followed by the matching files. On error, a negative status code.

A newline (0x0a) character separates each file name.

Only files which have a matching entry in /opt/pigpio/access may be listed.

Suppose /opt/pigpio/access contains

/sys/bus/w1/devices/28*/w1_slave r

Example

$ pigs -a fl "/sys/bus/w1/devices/28*/w1_slave" 5000
90 /sys/bus/w1/devices/28-000005d34cd2/w1_slave
/sys/bus/w1/devices/28-001414abbeff/w1_slave

$ pigs -a fl "/sys/bus/*" 5000
ERROR: no permission to access file
-137

FN u stdy actv โ€” set a noise filter on a GPIO ๐ŸŒˆ

Level changes on the GPIO u get ignored until a level which has been stable for stdy microseconds is detected. Then level changes on that GPIO are reported for actv microseconds โ€” after which the whole process repeats. A little loop, a little cycle. ๐ŸŒ€

The filter only affects callbacks (including pipe notifications).

The R/READ, BR1, and BR2 commands are not affected.

Real talk: level changes before and after the active period may be reported. Your software must be designed to cope with such reports. Do not come crying to me when you get extra notifications, I warned you. ๐Ÿ’€

Example

$ pigs fn 7 250 1000

$ pigs fn 7 2500000 1000
-125
ERROR: bad filter parameter

FO file mode โ€” open a file in mode ๐Ÿ’–

Returns a handle to a file file opened in a specified mode mode.

Upon success a handle (>=0) is returned. On error, a negative status code.

File ๐Ÿ“

A file may only be opened if permission is granted by an entry in /opt/pigpio/access. The whole point is to allow remote access to files in a more or less controlled manner. Safety first, cutie.

Each entry in /opt/pigpio/access takes the form of a file path (which may contain wildcards) followed by a single letter permission. That permission may be:

  • R โ€” for read
  • W โ€” for write
  • U โ€” for read/write
  • 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. Sorry babe. ๐Ÿšซ

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

Then:

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

  • READ = 1 โ€” open file for reading
  • WRITE = 2 โ€” open file for writing
  • RW = 3 โ€” open file for reading and writing

The following values may be or'd into the mode.

  • APPEND = 4 โ€” All writes append data to the end of the file
  • CREATE = 8 โ€” The file is created if it doesn't exist
  • TRUNC = 16 โ€” The file is truncated
Newly created files are owned by root with permissions owner read and write. Note it. ๐Ÿ“

Example

$ ls /ram/*.c
/ram/command.c      /ram/pigpiod.c  /ram/pigs.c
/ram/x_pigpiod_if.c /ram/pig2vcd.c  /ram/pigpiod_if2.c
/ram/x_pigpio.c     /ram/x_repeat.c /ram/pigpio.c
/ram/pigpiod_if.c   /ram/x_pigpiod_if2.c

# assumes /opt/pigpio/access contains the following line
# /ram/*.c r

$ pigs fo /ram/pigpio.c 1
0

$ pigs fo /ram/new.c 1
-128
ERROR: file open failed

$ pigs fo /ram/new.c 9
1

$ ls /ram/*.c -l
-rw-r--r-- 1 joan joan  42923 Jul 10 11:22 /ram/command.c
-rw------- 1 root root      0 Jul 10 16:54 /ram/new.c
-rw-r--r-- 1 joan joan   2971 Jul 10 11:22 /ram/pig2vcd.c
-rw------- 1 joan joan 296235 Jul 10 11:22 /ram/pigpio.c
-rw-r--r-- 1 joan joan   9266 Jul 10 11:22 /ram/pigpiod.c
-rw-r--r-- 1 joan joan  37331 Jul 10 11:22 /ram/pigpiod_if2.c
-rw-r--r-- 1 joan joan  33088 Jul 10 11:22 /ram/pigpiod_if.c
-rw-r--r-- 1 joan joan   7990 Jul 10 11:22 /ram/pigs.c
-rw-r--r-- 1 joan joan  19970 Jul 10 11:22 /ram/x_pigpio.c
-rw-r--r-- 1 joan joan  20804 Jul 10 11:22 /ram/x_pigpiod_if2.c
-rw-r--r-- 1 joan joan  19844 Jul 10 11:22 /ram/x_pigpiod_if.c
-rw-r--r-- 1 joan joan  19907 Jul 10 11:22 /ram/x_repeat.c

FR h num โ€” read bytes from file handle ๐Ÿ“

Returns up to num bytes of data read from the file associated with handle h.

Upon success the count of returned bytes followed by the bytes themselves is returned. On error, a negative status code.

Example

$ pigs fr 0 10
5 48 49 128 144 255

$ pigs fr 0 10
0

FS h num from โ€” seek to file handle position โญ

Seeks to a position within the file associated with handle h.

The number of bytes to move is num. Positive offsets move forward, negative offsets move backwards. Where the move starts from is determined by from, as follows.

  • 0 โ€” start
  • 1 โ€” current position
  • 2 โ€” end

Upon success the new byte position within the file (>=0) is returned. On error, a negative status code.

Example

$ pigs fs 0 200 0 # Seek to start of file plus 200
200

$ pigs fs 0 0 1 # Return current position
200

$ pigs fs 0 0 2 # Seek to end of file, return size
296235

FW h bvs โ€” write bytes to file handle ๐Ÿ’œ

Writes bytes bvs to the file associated with handle h.

Upon success, nothing is returned. On error, a negative status code.

Example

$ pigs fw 0 23 45 67 89

GDC u โ€” get GPIO PWM dutycycle ๐Ÿงš

Returns the PWM dutycycle in use on GPIO u.

Upon success the dutycycle is returned. On error, a negative status code.

For normal PWM the dutycycle will be out of the defined range for the GPIO (see PRG).

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

Example

$ pigs p 4 129
$ pigs gdc 4
129

pigs gdc 5
-92
ERROR: GPIO is not in use for PWM

GPW u โ€” get GPIO servo pulsewidth ๐ŸŽ€

Returns the servo pulsewidth in use on GPIO u.

Upon success the servo pulsewidth is returned. On error, a negative status code.

Example

$ pigs s 4 1235
$ pigs gpw 4
1235

$ pigs gpw 9
-93
ERROR: GPIO is not in use for servo pulses

H/HELP โ€” display command help โœจ

Displays a brief list of the commands and their parameters. Your little cheat sheet, bestie.

Example

$ pigs h

$ pigs help

HC g cf โ€” set hardware clock frequency ๐Ÿ”ฅ

Sets the hardware clock associated with GPIO g to frequency cf. Frequencies above 30MHz are unlikely to work โ€” so like, don't push it.

Upon success, nothing is returned. On error, a negative status code.

Example

$ pigs hc 4 5000 # start a 5 KHz clock on GPIO 4 (clock 0)

$ pigs hc 5 5000000 # start a 5 MHz clcok on GPIO 5 (clock 1)
-99
ERROR: need password to use hardware clock 1

The same clock is available on multiple GPIO. The latest frequency setting will be used by all GPIO which share a clock. So they're all matching, no cap.

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 B Rev.2 (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)

Clock 1 is password-protected because touching it will very likely crash your Pi ๐Ÿ’€. The password? You or 0x5A000000 with the GPIO number. That's it, that's the secret handshake ๐Ÿค.


๐ŸŒธ HP g pf pdc โ€” Set hardware PWM frequency and dutycycle

Bestie, this one sets the hardware PWM that belongs to GPIO g to frequency pf with dutycycle pdc. Heads up: frequencies above 30MHz? Unlikely to work, don't @ me ๐Ÿ™ˆ.

NOTE: any waveform you started with WVTX, WVTXR, or WVCHA gets cancelled. Gone. Poof. โœจ

This whole thing only works if the pigpio main clock is PCM. The main clock defaults to PCM but can be overridden when you start the pigpio daemon (that's the -t option, iykyk).

Success = nothing comes back at you. Error = a negative status code, as always. ๐Ÿ’…

$ pigs hp 18 100 800000 # 80% dutycycle

$ pigs hp 19 100 200000 # 20% dutycycle

$ pigs hp 19 400000000 100000
-96
ERROR: invalid hardware PWM frequency

Here's the tea ๐Ÿต: the same PWM channel lives on multiple GPIO. So the latest frequency and dutycycle you set gets used by every single GPIO that shares that channel. No takesies backsies.

The GPIO has to be one of these:

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 between off and fully on is the integral part of 250M/pf (375M/pf for the BCM2711). ๐Ÿงฎ

The actual frequency that gets set is 250M/steps (375M/steps for the BCM2711).

There's only a million steps for a pf of 250 (375 for the BCM2711). Lower frequencies โ†’ more steps, higher frequencies โ†’ fewer steps. And pdc gets automatically scaled to account for all that. Math is mathing โœจ


๐Ÿ’œ HWVER โ€” Get hardware version

Returns the hardware revision of your Pi. That's it, that's the command.

Where does it find it? In the last 4 characters on the revision line of /proc/cpuinfo. ๐Ÿ•ต๏ธ

If it can't find the hardware revision, or it's not a valid hexadecimal number, you get 0. Sucks to suck but ok.

You can use that revision number to figure out the GPIO-to-pin assignment (peep the g command for that one).

There are currently 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.

For "Revision : 0002" the command returns 2.

For "Revision : 000f" the command returns 15.

For "Revision : 000g" the command returns 0.

Example

$ pigs hwver # On a B+
16

๐ŸŽ€ I2CC h โ€” Close I2C handle

Closes an I2C handle h that you previously opened with I2CO. Closing time, bestie ๐Ÿšชโœจ

Success = silence (nothing returned). Error = negative status code, standard behaviour.

Example

$ pigs i2cc 0 # First close okay.

$ pigs i2cc 0 # Second fails.
-25
ERROR: unknown handle

๐Ÿฆ‹ I2CO ib id if โ€” Open I2C bus and device with flags

This hands you back a handle to access device id on I2C bus ib. The device gets opened with flags if.

Physically, buses 0 and 1 are the ones available on the Pi. Higher-numbered buses show up if a kernel-supported bus multiplexor is being used. ๐Ÿ”Œ

The GPIO used are given in this table:

        SDA   SCL
I2C 0    0     1
I2C 1    2     3

No flags are currently defined.</purgel> So the parameter if should just be 0. Periodt.

On success you get the next free handle (>=0). On error, negative status code as per usual.

Example

$ pigs i2co 1 0x70 0 # Bus 1, device 0x70, flags 0.
0

$ pigs i2co 1 0x53 0 # Bus 1, device 0x53, flags 0.
1

โญ I2CPC h r wv โ€” smb Process Call: exchange register with word

Writes wv to register r of the I2C device attached to handle h, and gives you back a 16-bit word read from the device. A lil exchange, a lil trade ๐Ÿค

Success = a value between 0 and 65535. Error = negative status code.

Example

$ pigs i2cpc 0 37 43210
39933

$ pigs i2cpc 0 256 43210
ERROR: bad i2c/spi/ser parameter
-81

๐ŸŒˆ I2CPK h r bvs โ€” smb Block Process Call: exchange data bytes with register

Writes the data bytes bvs to register r of the I2C device attached to handle h, then hands you back a device-specific number of bytes.

Success = the count of returned bytes, followed by the bytes themselves. Error = negative status code.

Example

$ pigs i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0

๐Ÿซถ I2CRB h r โ€” smb Read Byte Data: read byte from register

Returns a single byte read from register r of the I2C device attached to handle h.

Success = a value between 0 and 255. Error = negative status code.

Example

$ pigs i2crb 0 0
6

๐Ÿ’– I2CRD h num โ€” i2c Read device

Returns num bytes read from the I2C device attached to handle h. Slurp those bytes bestie ๐Ÿฅค

Success = the count of returned bytes, followed by the bytes themselves. Error = negative status code.

This one operates on the raw I2C device. The max value of num depends on the I2C drivers and the device itself โ€” pigs caps it at about 8000 bytes.

Example

$ pigs i2crd 0 16
16 6 24 0 0 0 0 0 0 0 0 0 0 0 0 32 78

๐Ÿ’… I2CRI h r num โ€” smb Read I2C Block Data: read bytes from register

Returns num bytes from register r of the I2C device attached to handle h.

Success = count of returned bytes, then the bytes. Error = negative status code.

The parameter num may be 1-32.

Example

$ pigs i2cri 0 0 16
16 237 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155

๐ŸŒธ I2CRK h r โ€” smb Read Block Data: read data from register

Returns between 1 and 32 bytes read from register r of the I2C device attached to handle h.

Success = count of returned bytes, then the bytes. Error = negative status code.

How many bytes come back is specific to the device and register โ€” no universal answer, sorry babe.

Example

$ pigs i2crk 0 0
6 0 0 0 0 0 0

$ pigs i2crk 0 1
24 0 0 0 0 0 0 0 0 0 0 0 0 120 222 105 215 128 87 195 217 0 0 0 0

๐Ÿงš I2CRS h โ€” smb Read Byte: read byte

Returns a single byte read from the I2C device attached to handle h.

Success = a value between 0 and 255. Error = negative status code.

Example

$ pigs i2crs 0
0

๐Ÿ’œ I2CRW h r โ€” smb Read Word Data: read word from register

Returns a single 16-bit word read from register r of the I2C device attached to handle h.

Success = a value between 0 and 65535. Error = negative status code.

Example

$ pigs i2crw 0 0
6150

โœจ I2CWB h r bv โ€” smb Write Byte Data: write byte to register

Writes a single byte bv to register r of the I2C device attached to handle h.

Success = nothing returned. Error = negative status code.

Example

$ pigs i2cwb 0 10 0x54

๐Ÿ”ฅ I2CWD h bvs โ€” i2c Write device

Writes a block of bytes bvs to the I2C device attached to handle h.

Success = nothing returned. Error = negative status code.

How many bytes you can write in one transaction depends on the I2C drivers and the device itself โ€” pigs caps it at about 500 bytes.

This one operates on the raw I2C device.

Example

$ pigs i2cwd 0 0x01 0x02 0x03 0x04

๐Ÿ“ I2CWI h r bvs โ€” smb Write I2C Block Data

Writes between 1 and 32 bytes bvs to register r of the I2C device attached to handle h.

Success = nothing returned. Error = negative status code.

Example

$ pigs i2cwi 0 4 0x01 0x04 0xc0

๐Ÿ‘‘ I2CWK h r bvs โ€” smb Write Block Data: write data to register

Writes between 1 and 32 bytes bvs to register r of the I2C device attached to handle h.

Success = nothing returned. Error = negative status code.

Example

pigs i2cwk 0 4 0x01 0x04 0xc0

๐ŸŽ€ I2CWQ h bit โ€” smb Write Quick: write bit

Writes a single bit to the I2C device attached to handle h. One tiny bit, the smallest lil guy ๐Ÿฃ

Success = nothing returned. Error = negative status code.

Example

$ pigs i2cwq 0 1

๐ŸŒธ I2CWS h bv โ€” smb Write Byte: write byte

Writes a single byte bv to the I2C device attached to handle h.

Success = nothing returned. Error = negative status code.

Example

$ pigs i2cws 0 0x12

$ pigs i2cws 0 0xff
-82
ERROR: I2C write failed

๐Ÿ’œ I2CWW h r wv โ€” smb Write Word Data: write word to register

Writes a single 16-bit word wv to register r of the I2C device attached to handle h.

Success = nothing returned. Error = negative status code.

Example

$ pigs i2cww 0 0 0xffff

๐Ÿฆ‹ I2CZ h bvs โ€” Performs multiple I2C transactions

This one runs a whole sequence of I2C operations in one go. The operations to perform are specified by the contents of bvs, which holds the concatenated command codes and their associated data. Combo move, bestie โœจ

The following command codes are supported:

okay so before we get into the individual commands, here's the little legend for the script byte-codes โ€” every command, what number it maps to, and what it actually does:

  • End โ€” code 0 โ€” no more commands, that's a wrap ๐Ÿ’…
  • Escape โ€” code 1 โ€” the next P is gonna be two bytes
  • On โ€” code 2 โ€” switch the combined flag on
  • Off โ€” code 3 โ€” switch the combined flag off
  • Address โ€” code 4 P โ€” set the I2C address to P
  • Flags โ€” code 5 lsb msb โ€” set the I2C flags to lsb + (msb << 8)
  • Read โ€” code 6 P โ€” read P bytes of data
  • Write โ€” code 7 P ... โ€” write P bytes of data

The address, read, and write commands all take a parameter P. Normally P is one byte (0-255). But if the command is preceded by the Escape command, then P is two bytes (0-65535, least significant byte first) โœจ

The address defaults to the one associated with the handle h. The flags default to 0. And both the address and the flags keep their previous value until you update them โ€” they're sticky like that, no cap ๐Ÿซถ

Example

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

โœจ M/MODEG g m โ€” Set GPIO mode โœจ

This one sets GPIO g to mode m โ€” typically input (read) or output (write).

Upon success nothing is returned. On error a negative status code comes back, and it's giving sad girl hours ๐Ÿ˜ญ

Every GPIO can be configured into one of 8 different modes. Their names are Input, Output, ALT0, ALT1, ALT2, ALT3, ALT4, and ALT5. To set the mode, you use the code for the mode:

  • Mode Input โ€” Code R
  • Mode Output โ€” Code W
  • Mode ALT0 โ€” Code 0
  • Mode ALT1 โ€” Code 1
  • Mode ALT2 โ€” Code 2
  • Mode ALT3 โ€” Code 3
  • Mode ALT4 โ€” Code 4
  • Mode ALT5 โ€” Code 5

Example

$ pigs m 4 r # Input (read)
$ pigs m 4 w # Output (write)
$ pigs m 4 0 # ALT 0
$ pigs m 4 5 # ALT 5

๐ŸŒธ MG/MODEG g โ€” Get GPIO mode ๐ŸŒธ

This command returns the current mode of GPIO g.

Upon success the value of the GPIO mode is returned. On error a negative status code will be returned.

  • Value 0 โ€” Mode Input
  • Value 1 โ€” Mode Output
  • Value 2 โ€” Mode ALT5
  • Value 3 โ€” Mode ALT4
  • Value 4 โ€” Mode ALT0
  • Value 5 โ€” Mode ALT1
  • Value 6 โ€” Mode ALT2
  • Value 7 โ€” Mode ALT3
bestie look at that ordering twice, it's not the same order as the setter. ALT5 is 2 but ALT0 is 4. the way that trips people up every single time ๐Ÿ’€

Example

$ pigs mg 4
1

๐Ÿฆ‹ MICS v โ€” Microseconds delay ๐Ÿฆ‹

This command delays execution for v microseconds. yes, it's literally just a nap for your script ๐Ÿ˜ด

Upon success nothing is returned. On error a negative status code will be returned.

The main use of this command is expected to be within Scripts.

Example

$ pigs mics 20 # Delay 20 microseconds.
$ pigs mics 1000000 # Delay 1 second.

$ pigs mics 2000000
-64
ERROR: bad MICS delay (too large)

๐ŸŽ€ MILS v โ€” Milliseconds delay ๐ŸŽ€

This command delays execution for v milliseconds. bigger nap, same energy.

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs mils 2000 # Delay 2 seconds.

$ pigs mils 61000
-65
ERROR: bad MILS delay (too large)

๐Ÿ’– NB h bits โ€” Start notification ๐Ÿ’–

This command starts notifications on handle h returned by a prior call to NO.

Upon success nothing is returned. On error a negative status code will be returned.

The notification gets state changes for each GPIO specified by bits.

Example

$ pigs nb 0 -1 # Shorthand for GPIO 0-31.
$ pigs nb 0 0xf0 # Get notifications for GPIO 4-7.

$ pigs nb 1 0xf
-25
ERROR: unknown handle

๐Ÿ‘‘ NC h โ€” Close notification ๐Ÿ‘‘

This command stops notifications on handle h returned by a prior call to NO and releases the handle for reuse. very much giving "returning your library book" ๐Ÿซถ

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs nc 0 # First call succeeds.

$ pigs nc 1 # Second call fails.
-25
ERROR: unknown handle

๐ŸŒˆ NO โ€” Request a notification ๐ŸŒˆ

This command requests a free notification handle.

A notification is a method for being notified of GPIO state changes via a pipe.

Upon success the command returns a handle greater than or equal to zero. On error a negative status code will be returned.

Notifications for handle x will be available at the pipe named /dev/pigpiox (where x is the handle number).

E.g. if the command returns 15 then the notifications must be read from /dev/pigpio15.

Example

$ pigs no
0

๐Ÿงš NP h โ€” Pause notification ๐Ÿงš

This command pauses notifications on handle h returned by a prior call to NO.

Upon success nothing is returned. On error a negative status code will be returned.

Notifications for the handle are suspended until a new NB command is given for the handle.

Example

$ pigs np 0

โญ P/PWM u v โ€” Set GPIO PWM value โญ

This command starts PWM on GPIO u with dutycycle v. The dutycycle varies from 0 (off) to range (fully on). The range defaults to 255.

Upon success nothing is returned. On error a negative status code will be returned.

This and the servo functionality use the DMA and PWM or PCM peripherals to control and schedule the pulsewidths and dutycycles. fancy fr fr ๐Ÿ’…

The PRS command may be used to change the default range of 255.

Example

$ pigs p 4 64  # Start PWM on GPIO 4 with 25% dutycycle
$ pigs p 4 128 # 50%
$ pigs p 4 192 # 75%
$ pigs p 4 255 # 100%

๐Ÿ’œ PADG pad โ€” Get pad drive strength ๐Ÿ’œ

This command gets the pad drive strength padma in mA.

Returns the pad drive strength if OK. On error a negative status code will be returned.

  • Pad 0 โ€” GPIO 0-27
  • Pad 1 โ€” GPIO 28-45
  • Pad 2 โ€” GPIO 46-53

Example

$ pigs padg 0
8
$ pigs pads 0 16
$ pigs padg 0
16
pigs padg 3
-126
ERROR: bad pad number

๐Ÿ“ PADS pad padma โ€” Set pad drive strength ๐Ÿ“

This command sets the pad drive strength padma in mA.

Upon success nothing is returned. On error a negative status code will be returned.

  • Pad 0 โ€” GPIO 0-27
  • Pad 1 โ€” GPIO 28-45
  • Pad 2 โ€” GPIO 46-53

Example

$ pigs pads 0 16
$ pigs padg 0
16
$ pigs pads 0 17
-127
ERROR: bad pad drive strength

โœจ PARSE t โ€” Validate script โœจ

Validates the text t of a script without storing the script.

Upon success nothing is returned. On error a list of detected script errors will be given.

See Scripts.

This command may be used to find script syntax faults. it's the vibe check for your script, no cap ๐Ÿซถ

Example

$ pigs parse tag 100 w 22 1 mils 200 w 22 0 mils 800 jmp 100

$ pigs parse tag 0 w 22 1 mills 50 w 22 0 dcr p10 jp 99
Unknown command: mills
Unknown command: 50
Bad parameter to dcr
Can't resolve tag 99

๐Ÿ”ฅ PFG u โ€” Get GPIO PWM frequency ๐Ÿ”ฅ

This command returns the PWM frequency in Hz used for GPIO u.

Upon success the PWM frequency is returned. On error a negative status code will be returned.

For normal PWM the frequency will be that defined for the GPIO by PFS.

If a hardware clock is active on the GPIO the reported frequency will be that set by HC.

If hardware PWM is active on the GPIO the reported frequency will be that set by HP.

Example

$ pigs pfg 4
800

$ pigs pfg 34
ERROR: GPIO not 0-31
-2

๐ŸŒธ PFS u v โ€” Set GPIO PWM frequency ๐ŸŒธ

This command sets the PWM frequency v to be used for GPIO u.

The numerically closest frequency to v will be selected. it's not gonna give you exactly what you asked for, it's gonna give you its best approximation, and honestly? relatable ๐Ÿ˜ญ

Upon success the new frequency is returned. On error a negative status code will be returned.

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

  • sample rate (us) 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 1250 1000 800 500 400 250 200 100 50
  • sample rate (us) 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 625 500 400 250 200 125 100 50 25
  • sample rate (us) 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
  • sample rate (us) 8: 5000 2500 1250 1000 625 500 313 250 200 156 125 100 63 50 31 25 13 6
  • sample rate (us) 10: 4000 2000 1000 800 500 400 250 200 160 125 100 80 50 40 25 20 10 5

Example

pigs pfs 4 0 # 0 selects the lowest frequency.
10

$ pigs pfs 4 1000 # Set 1000Hz PWM.
1000

$ pigs pfs 4 100000 # Very big number selects the highest frequency.
8000

๐ŸŽ€ PIGPV โ€” Get pigpio library version ๐ŸŽ€

This command returns the pigpio library version.

Example

$ pigs pigpv
17

๐ŸŒˆ PRG u โ€” Get GPIO PWM range ๐ŸŒˆ

This command returns the dutycycle range for GPIO u.

Upon success the range is returned. On error a negative status code will be returned.

If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). that's a whole million bestie, she's not playing around ๐Ÿ’…

Example

$ pigs prg 4
255

๐Ÿงš PROC t โ€” Store script ๐Ÿงš

This command stores a script t for later execution.

If the script is valid a script id (>=0) is returned which is passed to the other script commands. On error a negative status code will be returned.

See Scripts.

Example

$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123
0

$ pigs proc tag 123 w 4 0 mils 5 w 4 1 mils 5 jmp 12
ERROR: script has unresolved tag
-63

๐Ÿ’– PROCD sid โ€” Delete script ๐Ÿ’–

This command deletes script sid.

Upon success nothing is returned. On error a negative status code will be returned.

See Scripts.

Example

$ pigs procd 1

$ pigs procd 1
ERROR: unknown script id
-48

โญ PROCP sid โ€” Get script status and parameters โญ

This command returns the status of script sid as well as the current value of its 10 parameters.

okay so when it works, the script status and the parameters both come back to you. And if it didn't work? negative status code, sad face ๐Ÿ˜ญ

The script status is one of these, bestie:

  • 0 โ€” being initialised
  • 1 โ€” halted
  • 2 โ€” running
  • 3 โ€” waiting
  • 4 โ€” failed

See Scripts.

Example

$ pigs procp 0
1 0 0 0 0 0 0 0 0 0 0

PROCR sid pars โ€” Run script โœจ

This one runs the stored script sid and hands it up to 10 optional parameters. Ten!! that's so many ๐Ÿซถ

If it works, nothing comes back (silence is golden, no cap). If it doesn't, you get a negative status code.

See Scripts.

Example

$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123
0

$ pigs procr 0 50 # Run script 0 with parameter 0 of 50.

$ pigs procp 0
2 44 0 0 0 0 0 0 0 0 0
$ pigs procp 0
2 37 0 0 0 0 0 0 0 0 0
$ pigs procp 0
2 10 0 0 0 0 0 0 0 0 0
$ pigs procp 0
2 5 0 0 0 0 0 0 0 0 0
$ pigs procp 0
2 2 0 0 0 0 0 0 0 0 0
$ pigs procp 0
1 -1 0 0 0 0 0 0 0 0 0

PROCS sid โ€” Stop script ๐Ÿ›‘

Stops a running script sid. that's it, that's the whole vibe. running script? not anymore bestie ๐Ÿ’…

Upon success nothing is returned. On error a negative status code will be returned.

See Scripts.

Example

$ pigs procs 0

$ pigs procs 1
-48
ERROR: unknown script id

PROCU sid pars โ€” Set script parameters ๐ŸŽ€

Sets the parameters of a stored script sid, passing it up to 10 parameters. yup, ten again ๐ŸŒธ

Upon success nothing is returned. On error a negative status code will be returned.

See Scripts.

Example

$ pigs proc tag 0 hp 18 p0 p1 mils 1000 jmp 0
0
$ pigs procu 0 50 500000
$ pigs procr 0
$ pigs procu 0 100
$ pigs procu 0 200
$ pigs procu 0 200 100000

PRRG u โ€” Get GPIO PWM real range ๐ŸŒˆ

This command returns the real underlying range being used by GPIO u.

  • If a hardware clock is active on the GPIO, the reported real range is 1000000 (1M). iconic.
  • If hardware PWM is active on the GPIO, the reported real range is approximately 250M divided by the set PWM frequency.

On error a negative status code will be returned.

See PRS.

Example

$ pigs prrg 17
250

$ pigs pfs 17 0
10
$ pigs prrg 17
20000

$ pigs pfs 17 100000
8000
$ pigs prrg 17
25

PRS u v โ€” Set GPIO PWM range โญ

This sets the dutycycle range v to be used for GPIO u. So after this, every time you use command P/PWM, your dutycycle lives somewhere between 0 (fully off, napping) and v (fully on, main character energy) ๐Ÿ‘‘

Upon success the real underlying range used by the GPIO is returned. On error a negative status code will be returned.

If PWM is currently active on the GPIO, its dutycycle gets scaled so it matches the new range. no drama, it just adapts ๐Ÿ’…

The real range โ€” that's the number of steps between fully off and fully on for each frequency โ€” is right here:

 #1   #2   #3   #4   #5   #6   #7    #8    #9
 25   50  100  125  200  250  400   500   625

#10  #11  #12  #13  #14  #15  #16   #17   #18
800 1000 1250 2000 2500 4000 5000 10000 20000

The real value set by PRS is (dutycycle * real range) / range.

See PRRG

Example

$ pigs prs 18 1000
250

PUD g p โ€” Set GPIO pull up/down ๐Ÿฆ‹

Sets the internal pull/up down for GPIO g to mode p.

Upon success nothing is returned. On error a negative status code will be returned.

The mode can be pull-down (D), pull-up (U), or off (O).

Example

$ pigs pud 4 d # Set pull-down on GPIO 4.
$ pigs pud 4 u # Set pull-up on GPIO 4.
$ pigs pud 4 o # No pull-up/down on GPIO 4.

R/READ g โ€” Read GPIO level ๐Ÿ‘€

Reads the current level of GPIO g.

Upon success the current level is returned. On error a negative status code will be returned.

Example

$ pigs r 17 # Get level of GPIO 17.
0

$ pigs r 4 # Get level of GPIO 4.
1

S/SERVO u v โ€” Set GPIO servo pulsewidth ๐ŸŽ€

Starts servo pulses of v microseconds on GPIO u.

Upon success nothing is returned. On error a negative status code will be returned.

The servo pulsewidth can be 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise).

The range supported by servos varies, so honestly you should probably just figure it out by experiment. Generally values between 1000-2000 should be safe. A value of 1500 should always be safe and represents the mid-point of rotation. safe queen ๐ŸŒธ

โš ๏ธ bestie listen to me: you can DAMAGE a servo if you command it to move beyond its limits. do not do that. ๐Ÿ’€

Example

$ pigs SERVO 17 1500

This example causes an on pulse of 1500 microseconds duration to be transmitted on GPIO 17 at a rate of 50 times per second.

This will command a servo connected to GPIO 17 to rotate to its mid-point.

Example

pigs s 17 0 # Switch servo pulses off.

SERC h โ€” Close serial handle ๐Ÿ”’

Closes a serial handle h that you previously opened with SERO.

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs serc 0 # First close okay.

$ pigs serc 0 # Second close gives error.
-25
ERROR: unknown handle

SERDA h โ€” Check for serial data ready to read ๐Ÿ“ฌ

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

Upon success the count of bytes available to be read is returned (which may be 0, and that's fine, sometimes there's just no tea). On error a negative status code will be returned.

Example

$ pigs serda 0
0

SERO dev b sef โ€” Open serial device dev at baud b with flags ๐ŸŒˆ

Opens the serial dev at b bits per second.

No flags are currently defined. sef should be set to zero.

Upon success a handle (>=0) is returned. On error a negative status code will be returned.

The device name must start with /dev/tty or /dev/serial.

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. that's the whole list, no substitutions bestie โœจ

Example

$ pigs sero /dev/ttyAMA0 9600 0
0

$ pigs sero /dev/tty1 38400 0
1

SERR h num โ€” Read bytes from serial handle ๐Ÿ“–

Returns up to num bytes of data read from the serial device associated with handle h.

Upon success the count of returned bytes followed by the bytes themselves is returned. On error a negative status code will be returned.

Example

$ pigs serr 0 10
5 48 49 128 144 255

$ pigs serr 0 10
0

SERRB โ€” Read byte from serial handle ๐Ÿ“

Returns a byte of data read from the serial device associated with handle h.

Upon success a number between 0 and 255 is returned. On error a negative status code will be returned.

Example

$ pigs serrb 0
23
$ pigs serrb 0
45

SERW h bvs โ€” Write bytes to serial handle โœ๏ธ

Writes bytes bvs to the serial device associated with handle h.

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs serw 0 23 45 67 89

SERWB h bv โ€” Write byte to serial handle ๐Ÿ’œ

Writes a single byte bv to the serial device associated with handle h.

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs serwb 0 23
$ pigs serwb 0 0xf0

SHELL name str โ€” Execute a shell command ๐Ÿš

This uses the system call to execute a shell script name with the given string str as its parameter.

The exit status of the system call is returned if OK, otherwise PI_BAD_SHELL_STATUS.

name must exist in /opt/pigpio/cgi and must be executable. no exceptions ๐Ÿ’…

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.

Here are some example returned statuses:

Script exit status   Returned system call status
1                    256
5                    1280
10                   2560
200                  51200
script not found     32512

Example

# pass two parameters, hello and world
$ pigs shell scr1 hello world
256

# pass three parameters, hello, string with spaces, and world
$ pigs shell scr1 "hello 'string with spaces' world"
256

# pass one parameter, hello string with spaces world
$ pigs shell scr1 "
256

# non-existent script
$ pigs shell scr78 par1
32512

SLR u num โ€” Read bit bang serial data from GPIO ๐Ÿฆ‹

Returns up to num bytes of bit bang serial data read from GPIO u.

Upon success the count of returned bytes followed by the bytes themselves is returned. On error a negative status code will be returned.

GPIO u should have been initialised with the SLRO command.

The bytes returned for each character depend on the number of data bits db you specified in the SLRO command:

  • For db 1-8 there will be one byte per character.
  • For db 9-16 there will be two bytes per character.
  • For db 17-32 there will be four bytes per character.

Example

$ pigs slr 15 20
6 1 0 23 45 89 0

SLRC u โ€” Close GPIO for bit bang serial data ๐Ÿ”

Closes GPIO u for reading bit bang serial data.

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs slrc 23

$ pigs slrc 23
-38
ERROR: no serial read in progress on GPIO

SLRI u v โ€” Sets bit bang serial data logic levels โšก

Sets the logic level for reading bit bang serial data on GPIO u.

Upon success nothing is returned. On error a negative status code will be returned.

The invert parameter v is 1 for inverted signal, 0 for normal.

Example

$ pigs slri 17 1 # invert logic on GPIO 17

$ pigs slri 23 0 # use normal logic on GPIO 23

SLRO u b db โ€” Open GPIO for bit bang serial data ๐ŸŒธ

Opens GPIO u for reading bit bang serial data at b baud and db data bits.

Upon success nothing is returned. On error a negative status code will be returned.

The baud rate can be anywhere between 50 and 250000 bits per second โ€” pick your vibe โœจ

The received data is held in a cyclic buffer ๐Ÿ”„

And bestie, it is the user's responsibility to read that data out (with SLR) in a timely fashion. Nobody's gonna come collect it for you, that's on you ๐Ÿ’…

Example:

$ pigs slro 23 19200 8

$ pigs slro 23 19200 8
-50
ERROR: GPIO already in use

SPIC h - SPI close handle ๐Ÿงš

Okay so this one closes the SPI handle h that a prior call to SPIO gave you. Cleanup era ๐ŸŒธ

Upon success nothing is returned. On error a negative status code will be returned. Rude but standard.

Example:

$ pigs spic 1

$ pigs spic 1
-25
ERROR: unknown handle

SPIO c b spf - SPI open channel at baud b with flags ๐ŸŽ€

This command returns a handle to a SPI device on channel c. Iconic, honestly.

Data will be transferred at b bits per second. The flags spf may be used to modify the default behaviour, which is 4-wire operation, mode 0, active low chip select.

Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps are unlikely to work โ€” so like, don't be delulu about it ๐Ÿ˜ญ

The Pi has two SPI peripherals: main and auxiliary.

The main SPI has two chip selects (channels), the auxiliary has three.

The auxiliary SPI is available on all models but the A and B.

The GPIO used are given in the following table:

           MISO   MOSI   SCLK   CE0   CE1   CE2
Main SPI      9     10     11     8     7     -
Aux SPI      19     20     21    18    17    16

The 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 SPI. Noted, bestie, don't come for me ๐Ÿซถ
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 main SPI, 1 for the auxiliary SPI.

W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main SPI 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. Main SPI 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 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 only.

bbbbbb defines the word size in bits (0-32). The default (0) sets 8 bits per word. Auxiliary SPI only.

The SPIR, SPIW, and SPIX commands 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. Fr fr, LSB first ๐Ÿ”ฅ

E.g. to transfer 32 11-bit words 64 bytes need to be sent.

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

Upon success a handle (>=0) is returned. On error a negative status code will be returned.

Example:

$ pigs spio 0 100000 3 # Open channel 0 at 100kbps in mode 3.
0

$ pigs spio 0 32000 256 # Open channel 0 of auxiliary spi at 32kbps.
1

SPIR h num - SPI read bytes from handle ๐Ÿฆ‹

This command returns num bytes read from the SPI device associated with handle h.

Upon success the count of returned bytes followed by the bytes themselves is returned. On error a negative status code will be returned.

Example:

$ pigs spir 0 10 # Read 10 bytes from the SPI device.
10 0 0 0 0 0 0 0 0 0 0

SPIW h bvs - SPI write bytes to handle ๐ŸŒˆ

This command writes bytes bvs to the SPI device associated with handle h.

Upon success nothing is returned. On error a negative status code will be returned.

Example:

$ pigs spiw 0 0x22 0x33 0xcc 0xff

SPIX h bvs - SPI transfer bytes to handle โญ

This command writes bytes bvs to the SPI device associated with handle h. It returns the same number of bytes read from the device. Trade offer: I give you bytes, you give me bytes ๐Ÿซถ

Upon success the count of returned bytes followed by the bytes themselves is returned. On error a negative status code will be returned.

Example:

$ pigs spix 0 0x22 0x33 0xcc 0xff
4 0 0 0 0

T/TICK - Get current tick โฑ๏ธ

This command returns the current system tick.

Tick is the number of microseconds since system boot.

As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes. So yeah, it does a little loop-de-loop ๐Ÿ™ˆ

Example:

$ pigs t mils 1000 t
3691823946
3692833987

TRIG u pl L - Send a trigger pulse ๐Ÿ’ฅ

This command sends a trigger pulse of pl microseconds at level L to GPIO u.

Upon success nothing is returned. On error a negative status code will be returned.

The GPIO is set to not level at the end of the pulse.

Example:

$ pigs trig 4 10 1

$ pigs trig 4 51 1
-46
ERROR: trigger pulse > 50 microseconds
Bestie the pulse can't be longer than 50 microseconds. That's the limit. No exceptions ๐Ÿ’€

W/WRITE g L - Write GPIO level โœจ

This command sets GPIO g to level L. The level may be 0 (low, off, clear) or 1 (high, on, set).

Upon success nothing is returned. On error a negative status code will be returned.

Example:

$ pigs w 23 0
$ pigs w 23 1

$ pigs w 23 2
-5
ERROR: level not 0-1

WDOG u v - Set GPIO watchdog ๐Ÿถ

This command sets a watchdog of v milliseconds on GPIO u.

Upon success nothing is returned. On error a negative status code will be returned.

The watchdog is nominally in milliseconds.

One watchdog may be registered per GPIO.

The watchdog may be cancelled by setting timeout to 0.

Once a watchdog has been started, monitors of the GPIO will be triggered every timeout interval after the last GPIO activity. The watchdog expiry will be indicated by a special TIMEOUT value.

Example:

$ pigs wdog 23 90000
-15
ERROR: timeout not 0-60000

$ pigs wdog 23 9000

This example causes a report to be written to any notification pipes listening on GPIO 23 whenever GPIO 23 changes state or approximately every 9000 ms. Main character notification behaviour, honestly ๐Ÿ‘‘


WVAG trips - Add generic pulses to waveform ๐ŸŽต

This command adds 1 one or more triplets trips of GPIO on, GPIO off, delay to the existing waveform (if any).

Upon success the total number of pulses in the waveform so far is returned. On error a negative status code will be returned.

The triplets will be added at the start of the existing waveform. If they are to start offset from the start then the first triplet should consist solely of a delay, i.e. 0 0 offset.

Example:

$ pigs wvag 0x10 0x80 1000 0x80 0x10 9000
2

$ pigs wvag 0 0 10000 0x10 0x80 1000 0x80 0x10 9000
4

WVAS u b db sb o bvs - Add serial data to waveform ๐ŸŒธ

This command adds a waveform representing serial data bvs to GPIO u at b baud to the existing waveform (if any). The serial data starts o microseconds from the start of the waveform.

Upon success the total number of pulses in the waveform so far is returned. On error a negative status code will be returned.

The serial data is formatted as one start bit, db data bits, and sb/2 stop bits.

The baud rate may be between 50 and 1000000 bits per second.

It is legal to add serial data streams with different baud rates to the same waveform. Mix and match, we love versatility ๐Ÿ’–

The bytes required for each character depend upon db.

  • For db 1-8 there will be one byte per character.
  • For db 9-16 there will be two bytes per character.
  • For db 17-32 there will be four bytes per character.

Example:

$ pigs wvas 4 9600 8 2 0 0x30 0x31 0x32 0x33
23

$ pigs wvas 7 38400 8 2 0 0x41 0x42
35

WVTAT - Returns the current transmitting waveform ๐Ÿ“ก

This command returns the id of the waveform currently being transmitted. Chained waves are not supported.

Returns the waveform id or one of the following special values:

  • 9998 - transmitted wave not found
  • 9999 - no wave being transmitted

Example:

$ pigs wvtat
9999

WVBSY - Check if waveform is being transmitted ๐Ÿ‘€

This command checks to see if a waveform is currently being transmitted.

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

Example:

$ pigs wvbsy
0

WVCHA bvs - Transmits a chain of waveforms ๐Ÿ”—

This command transmits a chain of waveforms.

NOTE: Any hardware PWM started by HP will be cancelled. Just so you know, bestie ๐Ÿ˜ญ

The waves to be transmitted are specified by the contents of bvs, which contains an ordered list of wave_ids and optional command codes and related data.

Upon success 0 is returned. On error a negative status code will be returned.

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. Inception vibes ๐ŸŒ€

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.

Example:

#!/bin/bash

GPIO=4
WAVES=5

pigs m $GPIO w

for ((i=0; i<$WAVES; i++))
do
   pigs wvag $((1<<GPIO)) 0 20 0 $((1<<GPIO)) $(((i+1)*200))
   w[i]=$(pigs wvcre)
done
# transmit waves 4+3+2
# loop start
#    transmit waves 0+0+0
#    loop start
#       transmit waves 0+1
#       delay 5000us
#    loop end (repeat 30 times)
#    loop start
#       transmit waves 2+3+0
#       transmit waves 3+1+2
#    loop end (repeat 10 times)
# loop end (repeat 5 times)
# transmit waves 4+4+4
# delay 20000us
# transmit waves 0+0+0

pigs wvcha .br
   ${w[4]} ${w[3]} ${w[2]} .br
   255 0 .br
      ${w[0]} ${w[0]} ${w[0]} .br
      255 0 .br
         ${w[0]} ${w[1]} .br
         255 2 0x88 0x13 .br
      255 1 30 0 .br
      255 0 .br
         ${w[2]} ${w[3]} ${w[0]} .br
         ${w[3]} ${w[1]} ${w[2]} .br
      255 1 10 0 .br
   255 1 5 0 .br
   ${w[4]} ${w[4]} ${w[4]} .br
   255 2 0x20 0x4E .br
   ${w[0]} ${w[0]} ${w[0]}

while [[ $(pigs wvbsy) -eq 1 ]]; do sleep 0.1; done

for ((i=0; i<$WAVES; i++)); do echo ${w[i]}; pigs wvdel ${w[i]}; done

like that's the whole choreography, bestie ๐Ÿซถ wait for it to stop with wvbsy, then sweep up after yourself with wvdel. clean girl behaviour. โœจ


๐ŸŽ€ WVCLR โ€” Clear all waveforms ๐ŸŽ€

ok so this one is the reset button. It clears all the waveforms. Every last one. gone. ๐Ÿ’…

Nothing is returned. literally nothing, she's a woman of few words.

Example

$ pigs wvclr

๐ŸŒธ WVCRE โ€” Create a waveform ๐ŸŒธ

This command creates a waveform out of the data you fed it via the earlier WVAG and WVAS calls.

On a slay: a wave id (>=0) comes back to you. On a not-slay: you get a negative status code. ๐Ÿ˜ญ

๐Ÿšจ important: the data you handed over with WVAG and WVAS is consumed by this command. eaten. devoured. it does not come back.

You can create as many waveforms as there's space for, no cap. That wave id is what you pass to WVTX or WVTXR to say which waveform you want transmitted.

Normal usage, step by step, iykyk:

  1. WVCLR to clear all waveforms and added data.
  2. WVAG/WVAS calls to supply the waveform data.
  3. WVCRE to create the waveform and get a unique id.

Repeat steps 2 and 3 as needed.

  1. WVTX or WVTXR with the id of the waveform to transmit.

A waveform comprises of one or more pulses. and 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. it's giving queue energy fr fr.

Example

$ pigs wvas 4 9600 0 23 45 67 89 90
37
$ pigs wvcre
0

$ pigs wvcre
-69
ERROR: attempt to create an empty waveform

see that second one? empty waveform = instant rejection. the audacity ๐Ÿ™ˆ


๐Ÿฆ‹ WVCAP percent โ€” Create a waveform of fixed size ๐Ÿฆ‹

Create a waveform of fixed size. Similar to WVCRE, this command creates a waveform but pads the consumed resources to a fixed size, specified as a percent of the total resources. Padded waves of equal size can be re-cycled efficiently, which means newly created waves can re-use the resources of deleted waves of the same dimension. recycling? we love her. โ™ป๏ธ

On a slay: a wave id (>=0) is returned. On error: a negative status code. same deal as before.

the data provided by the WVAG and WVAS commands are consumed by this command. gone girl. ๐Ÿ’…

As many waveforms may be created as there is space available. The wave id is passed to WVTX or WVTXR to specify the waveform to transmit.

Normal usage would be:

  1. WVCLR to clear all waveforms and added data.
  2. WVAG/WVAS calls to supply the waveform data.
  3. WVCAP to create a waveform of a uniform size.
  4. WVTX or WVTXR with the id of the waveform to transmit.

Repeat steps 2 - 4 as needed.

  1. Any wave id can now be deleted and another wave of the same size can be created in its place.

Example

Example

# Create a wave that consumes 50% of the total resource:

$ pigs wvag 16 0 5000000 0 16 5000000
2
$ pigs wvcap 50
0
$ pigs wvtx 0
11918

(and yes the manpage really does say Example twice, I'm not editing her, she's iconic ๐Ÿ‘‘)


๐Ÿ’œ WVDEL wid โ€” Delete selected waveform ๐Ÿ’œ

This command deletes the waveform with id wid.

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

Upon success nothing is returned. On error a negative status code will be returned.

Example

$ pigs wvdel 0

$ pigs wvdel 0
-66
ERROR: non existent wave id

deleting something twice? bestie no, she's already gone ๐Ÿ’€


๐Ÿงš WVHLT โ€” Stop waveform ๐Ÿงš

This command aborts the transmission of the current waveform.

Nothing is returned.

This command is intended to stop a waveform started in the repeat mode. so like, if she's looping and you need her to STOP, this is your girl.

Example

$ pigs wvhlt

โญ WVNEW โ€” Initialise a new waveform โญ

This clears any existing waveform data, ready for the creation of a new waveform.

Nothing is returned.

Example

$ pigs wvnew

fresh start energy. out with the old. ๐ŸŒˆ


๐Ÿ“ WVSC ws โ€” Get waveform DMA CB stats ๐Ÿ“

The statistic requested by ws is returned.

ws identifies the subcommand as follows.

  • 0 โ€” Get Cbs
  • 1 โ€” Get High Cbs
  • 2 โ€” Get Max Cbs

Example

$ pigs wvas 4 9600 0 23 45 67 89 90
37

$ pigs wvsc 0
74
$ pigs wvsc 1
74
$ pigs wvsc 2
25016

๐Ÿ’– WVSM ws โ€” Get waveform time stats ๐Ÿ’–

The statistic requested by ws is returned.

ws identifies the subcommand as follows.

  • 0 โ€” Get Micros
  • 1 โ€” Get High Micros
  • 2 โ€” Get Max Micros

Example

$ pigs wvsm 0
5314
$ pigs wvsm 1
5314
$ pigs wvsm 2
1800000000

๐ŸŽ€ WVSP ws โ€” Get waveform pulse stats ๐ŸŽ€

The statistic requested by ws is returned.

ws identifies the subcommand as follows.

  • 0 โ€” Get Pulses
  • 1 โ€” Get High Pulses
  • 2 โ€” Get Max Pulses

Example

$ pigs wvsp 0
37
$ pigs wvsp 1
37
$ pigs wvsp 2
12000

๐Ÿ”ฅ WVTX wid โ€” Transmits waveform once ๐Ÿ”ฅ

This command transmits the waveform with id wid once. one and done, no encore. ๐Ÿ’…

โš ๏ธ NOTE: Any hardware PWM started by HP will be cancelled.

Upon success, the number of DMA control blocks in the waveform is returned. On error a negative status code will be returned.

Example

$ pigs wvtx 1
75

$ pigs wvtx 2
-66
ERROR: non existent wave id

๐ŸŒˆ WVTXM wid wmde โ€” Transmits waveform using mode ๐ŸŒˆ

This command transmits the waveform with id wid using mode wmde.

The mode may be:

  • send once (0)
  • send repeatedly (1)
  • send once but first sync with previous wave (2)
  • send repeatedly but first sync with previous wave (3)
๐Ÿšจ WARNING: bad things may happen if you delete the previous waveform before it has been synced to the new waveform. like genuinely bad. do not do this. ๐Ÿ˜ญ
โš ๏ธ NOTE: Any hardware PWM started by HP will be cancelled.

Upon success, the number of DMA control blocks in the waveform is returned. On error a negative status code will be returned.

Example

$ pigs wvtxm 1 3
75

$ pigs wvtxm 2 0
-66
ERROR: non existent wave id

๐Ÿฆ‹ WVTXR wid โ€” Transmits waveform repeatedly ๐Ÿฆ‹

This command transmits the waveform with id wid repeatedly. she loops. she's a main character who refuses to leave the stage. ๐Ÿ‘‘

โš ๏ธ NOTE: Any hardware PWM started by HP will be cancelled.

Upon success, the number of DMA control blocks in the waveform is returned. On error a negative status code will be returned.

Example

$ pigs wvtxr 1
75

$ pigs wvtxr 2
-66
ERROR: non existent wave id

โœจ PARAMETERS โœจ

okay bestie, this is the big glossary of every lil argument type the commands use. no skips, no summaries, we are keeping all the details. ๐Ÿ’–

  • actv โ€” 0-1000000 โ€” the number of microseconds level changes are reported for once a noise filter has been triggered (by stdy microseconds of a stable level).
  • b โ€” baud โ€” the command expects the baud rate in bits per second for the transmission of serial data (I2C/SPI/serial link, waves).
  • bctl โ€” BSC control word โ€” the command expects a BSC control word, see BSCX.
  • bit โ€” bit value (0-1) โ€” the command expects 0 or 1.
  • bits โ€” a bit mask โ€” a mask is used to select one or more GPIO. A GPIO is selected if bit (1<<GPIO) is set in the mask. E.g. a mask of 6 (binary 110) select GPIO 1 and 2, a mask of 0x103 (binary 100000011) selects GPIO 0, 1, and 8.
  • bv โ€” a byte value (0-255) โ€” the command expects a byte value.
  • bvs โ€” byte values (0-255) โ€” the command expects one or more byte values.
  • c โ€” SPI channel (0-1) โ€” the command expects a SPI channel.
  • cf โ€” hardware clock frequency (4689-250M, 13184-375M for the BCM2711) โ€” the command expects a frequency.
  • cs โ€” GPIO (0-31) โ€” the GPIO used for the slave select signal when bit banging SPI.
  • db โ€” serial data bits (1-32) โ€” the command expects the number of data bits per serial character.
  • dev โ€” a tty serial device (/dev/tty* or /dev/serial*) โ€” the command expects the name of a tty serial device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty0, /dev/serial0.
  • event โ€” 0-31 โ€” an event is a signal used to inform one or more consumers to start an action.
  • file โ€” a file name โ€” the file name must match an entry in /opt/pigpio/access.
  • from โ€” 0-2 โ€” position to seek from FS.
    • 0 โ€” start
    • 1 โ€” current position
    • 2 โ€” end
  • g โ€” GPIO (0-53) โ€” the command expects a GPIO. There are 54 General Purpose Input Outputs (GPIO) named gpio0 through gpio53. They are split into two banks. Bank 1 consists of gpio0 through gpio31. Bank 2 consists of gpio32 through gpio53. All the GPIO which are safe for the user to read and write are in bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. See HWVER. The user GPIO are marked with an X in the following table.
          0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
Type 1    X  X  -  -  X  -  -  X  X  X  X  X  -  -  X  X
Type 2    -  -  X  X  X  -  -  X  X  X  X  X  -  -  X  X
Type 3          X  X  X  X  X  X  X  X  X  X  X  X  X  X

         16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Type 1    -  X  X  -  -  X  X  X  X  X  -  -  -  -  -  -
Type 2    -  X  X  -  -  -  X  X  X  X  -  X  X  X  X  X
Type 3    X  X  X  X  X  X  X  X  X  X  X  X  -  -  -  -

You are not prevented from writing to unsafe GPIO. The consequences of doing so range from no effect, to a crash, or corrupted data.

  • h โ€” handle (>=0) โ€” the command expects a handle. A handle is a number referencing an object opened by one of FO, I2CO, NO, SERO, SPIO.
  • ib โ€” I2C bus (>=0) โ€” the command expects an I2C bus number.
  • id โ€” I2C device (0-0x7F) โ€” the command expects the address of an I2C device.
  • if โ€” I2C flags (0) โ€” the command expects an I2C flags value. No flags are currently defined.
  • L โ€” level (0-1) โ€” the command expects a GPIO level.
  • m โ€” mode (RW540123) โ€” the command expects a mode character. Each GPIO can be configured to be in one of 8 different modes. The modes are named Input, Output, ALT0, ALT1, ALT2, ALT3, ALT4, and ALT5. To set the mode use the code for the mode. The value is returned by the mode get command.
Mode    Input   Output   ALT0   ALT1   ALT2   ALT3   ALT4   ALT5
Code      R        W       0      1      2      3      4      5
Value     0        1       4      5      6      7      3      2
  • miso โ€” GPIO (0-31) โ€” the GPIO used for the MISO signal when bit banging SPI.
  • mode โ€” file open mode โ€” one of the following values.
        Value   Meaning
READ      1     open file for reading
WRITE     2     open file for writing
RW        3     open file for reading and writing

The following values can be or'd into the mode.

         Value   Meaning
APPEND   4       All writes append data to the end of the file
CREATE   8       The file is created if it doesn't exist
TRUNC    16      The file is truncated
  • mosi โ€” GPIO (0-31) โ€” the GPIO used for the MOSI signal when bit banging SPI.
  • name โ€” the name of a script โ€” only alphanumeric characters, - and _ are allowed in the name.
  • num โ€” maximum number of bytes to return (1-) โ€” the command expects the maximum number of bytes to return. For the I2C and SPI commands the requested number of bytes will always be returned. For the serial and file commands the smaller of the number of bytes available to be read (which may be zero) and num bytes will be returned.
  • o โ€” offset (>=0) โ€” serial data is stored offset microseconds from the start of the waveform.
  • p โ€” PUD (ODU) โ€” the command expects a PUD character. Each GPIO can be configured to use or not use an internal pull up or pull down resistor. This is useful to provide a default state for inputs. A pull up will default the input to 1 (high). A pull down will default the input to 0 (low). To set the pull up down state use the command character for the state.
Pull Up Down      Off Pull Down Pull Up
Command Character   O         D       U

There is no mechanism to read the pull up down state.

  • pad โ€” 0-2 โ€” a set of GPIO which share common drivers.
Pad   GPIO
0     0-27
1     28-45
2     46-53
  • padma โ€” 1-16 โ€” the mA which may be drawn from each GPIO whilst still guaranteeing the high and low levels.
  • pars โ€” script parameters โ€” the command expects 0 to 10 numbers as parameters to be passed to the script.
  • pat โ€” a file name pattern โ€” a file path which may contain wildcards. To be accessible the path must match an entry in /opt/pigpio/access.
  • pdc โ€” hardware PWM dutycycle (0-1000000) โ€” the command expects a dutycycle.
  • percent โ€” percent (1-100) โ€” the percent of wave resources to allocate to a wave. It can be useful to create waves of fixed sizes to prevent wave fragmentation (where there are plenty of resources but not a large enough contiguous space).
  • pf โ€” hardware PWM frequency (1-125M, 1-187.5M for the BCM2711) โ€” the command expects a frequency.
  • pl โ€” pulse length (1-100) โ€” the command expects a pulse length in microseconds.
  • r โ€” register (0-255) โ€” the command expects an I2C register number.
  • sb โ€” serial stop (half) bits (2-8) โ€” the command expects the number of stop (half) bits per serial character.
  • scl โ€” user GPIO (0-31) โ€” the command expects the number of the GPIO to be used for SCL when bit banging I2C.
  • sclk โ€” user GPIO (0-31) โ€” the GPIO used for the SCLK signal when bit banging SPI.
  • sda โ€” user GPIO (0-31) โ€” the command expects the number of the GPIO to be used for SDA when bit banging I2C.
  • sef โ€” serial flags (32 bits) โ€” the command expects a flag value. No serial flags are currently defined.
  • sid โ€” script id (>= 0) โ€” the command expects a script id as returned by a call to PROC.
  • spf โ€” SPI flags (32 bits) โ€” see SPIO and BSPIO.
  • stdy โ€” 0-300000 โ€” the number of microseconds level changes must be stable for before reporting the level changed (FG) or triggering the active part of a noise filter (FN).
  • str โ€” a string โ€” the command expects a string.
  • t โ€” a string โ€” the command expects a string.
  • trips โ€” triplets โ€” the command expects 1 or more triplets of GPIO on, GPIO off, delay. E.g. 0x400000 0 100000 0 0x400000 900000 defines two pulses as follows
     GPIO on           GPIO off           delay
0x400000 (GPIO 22)           0 (None) 100000 (1/10th s)
         0 (None) 0x400000 (GPIO 22) 900000 (9/10th s)
  • u โ€” user GPIO (0-31) โ€” the command expects the number of a user GPIO. A number of commands are restricted to GPIO in bank 1, in particular the PWM commands, the servo command, the watchdog command, and the notification command. It is your responsibility to ensure that the PWM and servo commands are only used on safe GPIO. See g.
  • uvs โ€” values โ€” the command expects an arbitrary number of >=0 values (possibly none). Any after the first two must be <= 255.
  • v โ€” value โ€” the command expects a number.
  • wid โ€” wave id (>=0) โ€” the command expects a wave id. When a waveform is created it is given an id (0, 1, 2, ...).
  • wmde โ€” mode (0-3) โ€” the command expects a wave transmission mode. 0 = send once, 1 = send repeatedly, 2 = send once but first sync with previous wave, 3 = send repeatedly but first sync with previous wave.
  • ws โ€” wave stats sucommand (0-2) โ€” the command expects a subcommand. 0 = current value. 1 = highest value so far. 2 = maximum possible value.
  • wv โ€” word value (0-65535) โ€” the command expects a word value.

Scripts are these lil programs that get stored and executed by the pigpio daemon itself, and the whole reason they exist is to dodge the performance drama that comes with the pigpio daemon's server/client model. like, the round-trip tax is real, and scripts are the fix. ๐Ÿ’…


๐Ÿ“ Example ๐Ÿ“

okay so a tiny example, because honestly a tiny example makes this all click.

say you wanna toggle a GPIO on and off as fast as physically possible. relatable.

from the command line you could write:

for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done

time that and you'll see it takes about 14 seconds, which is roughly 70 toggles per second. not it. ๐Ÿ˜ญ

using the pigpio Python module you could use code such as:

#!/usr/bin/env python

import time

import pigpio

PIN=4

TOGGLE=10000

pi = pigpio.pi() # Connect to local Pi.

s = time.time()

for i in range(TOGGLE):
   pi.write(PIN, 1)
   pi.write(PIN, 0)

e = time.time()

print("pigpio did {} toggles per second".format(int(TOGGLE/(e-s))))

pi.stop()

timing that shows a speed improvement to roughly 800 toggles per second. better! but still.

now let's use a script:

pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999

ignore the details for now bestie, we're getting to them.

let's time the script running:

time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];.br
 do sleep 0.2; done)

again, ignore the details for now.

the script takes roughly 12 seconds to complete, or 800,000 toggles per second. ๐Ÿ’… that is the advantage of a stored script. it ate.

some details:

pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999
  • proc introduces a script. everything after proc is part of the script.
  • tag 999 names the current position in the script.
  • w 22 1 writes 1 to GPIO 22.
  • w 22 0 writes 0 to GPIO 22.
  • dcr p0 decrements parameter 0.
  • jp 999 jumps to tag 999 if the result is positive.
time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];.br
 do sleep 0.2; done)
  • pigs procr 0 10000000 starts script 0 with parameter 0 of 10 million.

the rest is bash, apart from:

  • pigs procp 0 asks for the status and parameters of script 0. the status will be 2 while the script is running and 1 when it is complete. iykyk. โœจ

๐Ÿงš Virtual machine ๐Ÿงš

a script runs within a virtual machine that has:

  • a 32 bit accumulator A.
  • a flags register F.
  • a program counter PC.

each script has:

  • 10 parameters named 0 through 9.
  • 150 variables named 0 through 149.
  • 50 labels which are named by any unique number.

๐Ÿ‘‘ Commands ๐Ÿ‘‘

many pigpio commands may be used within a script. however some commands do not work within the script model as designed and are not permitted. so sorry, that's just how it is.

the following commands are not permitted within a script:

  • File โ€” FL FO FR FW
  • I2C โ€” BI2CZ I2CPK I2CRD I2CRI I2CRK I2CWD I2CWI I2CWK I2CZ
  • Misc โ€” BSCX CF1 CF2 SHELL
  • Script control โ€” PARSE PROC PROCD PROCP PROCR PROCS PROCU
  • Serial โ€” SERO SERR SERW SLR
  • SPI โ€” BSPIO BSPIX SPIR SPIW SPIX
  • Waves โ€” WVAG WVAS WVCHA WVGO WVGOR

the following commands are only permitted within a script (command, what it does, and its actual definition, no cap):

  • ADD x โ€” Add x to accumulator โ€” A+=x; F=A
  • AND x โ€” And x with accumulator โ€” A&=x; F=A
  • CALL L โ€” Call subroutine at tag L โ€” push(PC+1); PC=L
  • CMP x โ€” Compare x with accumulator โ€” F=A-x
  • DCR y โ€” Decrement register โ€” --*y; F=*y
  • DCRA โ€” Decrement accumulator โ€” --A; F=A
  • DIV x โ€” Divide x into accumulator โ€” A/=x; F=A
  • EVTWT โ€” Wait for an event to occur โ€” A=wait(x); F=A
  • HALT โ€” Halt โ€” Halt
  • INR y โ€” Increment register โ€” ++*y; F=*y
  • INRA โ€” Increment accumulator โ€” ++A; F=A
  • JM L โ€” Jump if minus to tag L โ€” if (F<0) PC=L
  • JMP L โ€” Jump to tag L โ€” PC=L
  • JNZ L โ€” Jump if non-zero to tag L โ€” if (F) PC=L
  • JP L โ€” Jump if positive to tag L โ€” if (F>=0) PC=L
  • JZ L โ€” Jump if zero to tag L โ€” if (!F) PC=L
  • LD y x โ€” Load register with x โ€” *y=x
  • LDA x โ€” Load accumulator with x โ€” A=x
  • MLT x โ€” Multiply x with accumulator โ€” A*=x; F=A
  • MOD x โ€” Modulus x with accumulator โ€” A%=x; F=A
  • OR x โ€” Or x with accumulator โ€” A|=x; F=A
  • POP y โ€” Pop register โ€” y=pop()
  • POPA โ€” Pop accumulator โ€” A=pop()
  • PUSH y โ€” Push register โ€” push(y)
  • PUSHA โ€” Push accumulator โ€” push(A)
  • RET โ€” Return from subroutine โ€” PC=pop()
  • RL y x โ€” Rotate left register x bits โ€” *y<<=x; F=*y
  • RLA x โ€” Rotate left accumulator x bits โ€” A<<=x; F=A
  • RR y x โ€” Rotate right register x bits โ€” *y>>=x; F=*y
  • RRA x โ€” Rotate right accumulator x bits โ€” A>>=x; F=A
  • STA y โ€” Store accumulator in register โ€” y=A
  • SUB x โ€” Subtract x from accumulator โ€” A-=x; F=A
  • SYS str โ€” Run external script (/opt/pigpio/cgi/str) โ€” system(str); F=A
  • TAG L โ€” Label the current script position โ€” N/A
  • WAIT x โ€” Wait for a GPIO in x to change state โ€” A=wait(x); F=A
  • X y1 y2 โ€” Exchange contents of registers y1 and y2 โ€” t=*y1;*y1=*y2;*y2=t
  • XA y โ€” Exchange contents of accumulator and register โ€” t=A;A=*y;*y=t
  • XOR x โ€” Xor x with accumulator โ€” A^=x; F=A

some ground rules bestie:

  • x may be a constant, a parameter (p0-p9), or a variable (v0-v149).
  • y may be a parameter (p0-p9), or a variable (v0-v149). if p or v isn't specified, y is assumed to be a variable.
  • the EVTWT command parameter is a bit-mask with 1 set for events of interest.
  • the WAIT command parameter is a bit-mask with 1 set for GPIO of interest.
  • the SYS script receives two unsigned parameters: the accumulator A and the current GPIO levels.

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

go read these too, fr fr:


๐ŸŒธ AUTHOR ๐ŸŒธ

joan@abyz.me.uk โ€” the icon, the moment, the legend. ๐Ÿซถ


and that's a wrap on pigs(1), bestie!! this page lives in the Linux manual, dated 2012-2020, and it's the pigs(1) page you just devoured in full. go toggle something. slay. ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from