sudo pigpiod
PIGS_OK 0
PIGS_CONNECT_ERR 255
PIGS_OPTION_ERR 254
PIGS_SCRIPT_ERR 253
pigs w 22 1 mils 1000 w 22 0
pigs w 22 1
pigs mils 1000
pigs w 22 0
echo "m 4 w w 4 0 mils 250 m 4 r r 4" >/dev/pigpio
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
$ 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
BASIC | ||
M/MODES g m | Set GPIO mode | gpioSetMode |
MG/MODEG g | Get GPIO mode | gpioGetMode |
PUD g p | Set GPIO pull up/down | gpioSetPullUpDown |
R/READ g | Read GPIO level | gpioRead |
W/WRITE g L | Write GPIO level | gpioWrite |
PWM (overrides servo commands on same GPIO) | ||
P/PWM u v | Set GPIO PWM value | gpioPWM |
PFS u v | Set GPIO PWM frequency | gpioSetPWMfrequency |
PRS u v | Set GPIO PWM range | gpioSetPWMrange |
GDC u | Get GPIO PWM dutycycle | gpioGetPWMdutycycle |
PFG u | Get GPIO PWM frequency | gpioGetPWMfrequency |
PRG u | Get GPIO PWM range | gpioGetPWMrange |
PRRG u | Get GPIO PWM real range | gpioGetPWMrealRange |
Servo (overrides PWM commands on same GPIO) | ||
S/SERVO u v | Set GPIO servo pulsewidth | gpioServo |
GPW u | Get GPIO servo pulsewidth | gpioGetServoPulsewidth |
INTERMEDIATE | ||
TRIG u pl L | Send a trigger pulse | gpioTrigger |
WDOG u v | Set GPIO watchdog | gpioSetWatchdog |
BR1 | Read bank 1 GPIO | gpioRead_Bits_0_31 |
BR2 | Read bank 2 GPIO | gpioRead_Bits_32_53 |
BC1 bits | Clear specified GPIO in bank 1 | gpioWrite_Bits_0_31_Clear |
BC2 bits | Clear specified GPIO in bank 2 | gpioWrite_Bits_32_53_Clear |
BS1 bits | Set specified GPIO in bank 1 | gpioWrite_Bits_0_31_Set |
BS2 bits | Set specified GPIO in bank 2 | gpioWrite_Bits_32_53_Set |
ADVANCED | ||
NO | Request a notification | gpioNotifyOpen |
NC h | Close notification | gpioNotifyClose |
NB h bits | Start notification | gpioNotifyBegin |
NP h | Pause notification | gpioNotifyPause |
HC g cf | Set hardware clock frequency | gpioHardwareClock |
HP g pf pdc | Set hardware PWM frequency and dutycycle | gpioHardwarePWM |
FG u stdy | Set a glitch filter on a GPIO | gpioGlitchFilter |
FN u stdy actv | Set a noise filter on a GPIO | gpioNoiseFilter |
PADS pad padma | Set pad drive strength | gpioSetPad |
PADG pad | Get pad drive strength | gpioGetPad |
SHELL name str | Execute a shell command | shell |
Custom | ||
CF1 uvs | Custom function 1 | gpioCustom1 |
CF2 uvs | Custom function 2 | gpioCustom1 |
Events | ||
EVM h bits | Set events to monitor | eventMonitor |
EVT event | Trigger event | eventTrigger |
Scripts | ||
PROC t | Store script | gpioStoreScript |
PROCR sid pars | Run script | gpioRunScript |
PROCU sid pars | Set script parameters | gpioUpdateScript |
PROCP sid | Get script status and parameters | gpioScriptStatus |
PROCS sid | Stop script | gpioStopScript |
PROCD sid | Delete script | gpioDeleteScript |
PARSE t | Validate script | gpioParseScript |
I2C | ||
I2CO ib id if | Open I2C bus and device with flags | i2cOpen |
I2CC h | Close I2C handle | i2cClose |
I2CWQ h bit | smb Write Quick: write bit | i2cWriteQuick |
I2CRS h | smb Read Byte: read byte | i2cReadByte |
I2CWS h bv | smb Write Byte: write byte | i2cWriteByte |
I2CRB h r | smb Read Byte Data: read byte from register | i2cReadByteData |
I2CWB h r bv | smb Write Byte Data: write byte to register | i2cWriteByteData |
I2CRW h r | smb Read Word Data: read word from register | i2cReadWordData |
I2CWW h r wv | smb Write Word Data: write word to register | i2cWriteWordData |
I2CRK h r | smb Read Block Data: read data from register | i2cReadBlockData |
I2CWK h r bvs | smb Write Block Data: write data to register | i2cWriteBlockData |
I2CWI h r bvs | smb Write I2C Block Data | i2cWriteI2CBlockData |
I2CRI h r num | smb Read I2C Block Data: read bytes from register | i2cReadI2CBlockData |
I2CRD h num | i2c Read device | i2cReadDevice |
I2CWD h bvs | i2c Write device | i2cWriteDevice |
I2CPC h r wv | smb Process Call: exchange register with word | i2cProcessCall |
I2CPK h r bvs | smb Block Process Call: exchange data bytes with register | i2cBlockProcessCall |
I2CZ h bvs | Performs multiple I2C transactions | i2cZip |
I2C BIT BANG | ||
BI2CO sda scl b | Open bit bang I2C | bbI2COpen |
BI2CC sda | Close bit bang I2C | bbI2CClose |
BI2CZ sda bvs | I2C bit bang multiple transactions | bbI2CZip |
I2C/SPI SLAVE | ||
BSCX bctl bvs | BSC I2C/SPI transfer | bscXfer |
SERIAL | ||
SERO dev b sef | Open serial device dev at baud b with flags | serOpen |
SERC h | Close serial handle | serClose |
SERRB | Read byte from serial handle | serReadByte |
SERWB h bv | Write byte to serial handle | serWriteByte |
SERR h num | Read bytes from serial handle | serRead |
SERW h bvs | Write bytes to serial handle | serWrite |
SERDA h | Check for serial data ready to read | serDataAvailable |
SERIAL BIT BANG (read only) | ||
SLRO u b db | Open GPIO for bit bang serial data | gpioSerialReadOpen |
SLRC u | Close GPIO for bit bang serial data | gpioSerialReadClose |
SLRI u v | Sets bit bang serial data logic levels | gpioSerialReadInvert |
SLR u num | Read bit bang serial data from GPIO | gpioSerialRead |
SPI | ||
SPIO c b spf | SPI open channel at baud b with flags | spiOpen |
SPIC h | SPI close handle | spiClose |
SPIR h num | SPI read bytes from handle | spiRead |
SPIW h bvs | SPI write bytes to handle | spiWrite |
SPIX h bvs | SPI transfer bytes to handle | spiXfer |
SPI BIT BANG | ||
BSPIO cs miso mosi sclk b spf | Open bit bang SPI | bbSPIOpen |
BSPIC cs | Close bit bang SPI | bbSPIClose |
BSPIX cs bvs | SPI bit bang transfer | bbSPIXfer |
FILES | ||
FO file mode | Open a file in mode | fileOpen |
FC h | Close file handle | fileClose |
FR h num | Read bytes from file handle | fileRead |
FW h bvs | Write bytes to file handle | fileWrite |
FS h num from | Seek to file handle position | fileSeek |
FL pat num | List files which match pattern | fileList |
WAVES | ||
WVCLR | Clear all waveforms | gpioWaveClear |
WVNEW | Initialise a new waveform | gpioWaveAddNew |
WVAG trips | Add generic pulses to waveform | gpioWaveAddGeneric |
WVAS u b db sb o bvs | Add serial data to waveform | gpioWaveAddSerial |
WVCRE | Create a waveform | gpioWaveCreate |
WVCAP | Create a waveform of fixed size | gpioWaveCreatePad |
WVDEL wid | Delete selected waveform | gpioWaveDelete |
WVTX wid | Transmits waveform once | gpioWaveTxSend |
WVTXM wid wmde | Transmits waveform using mode | gpioWaveTxSend |
WVTXR wid | Transmits waveform repeatedly | gpioWaveTxSend |
WVCHA bvs | Transmits a chain of waveforms | gpioWaveChain |
WVTAT | Returns the current transmitting waveform | gpioWaveTxAt |
WVBSY | Check if waveform is being transmitted | gpioWaveTxBusy |
WVHLT | Stop waveform | gpioWaveTxStop |
WVSC ws | Get waveform DMA CB stats | gpioWaveGetCbs |
WVSM ws | Get waveform time stats | gpioWaveGetMicros |
WVSP ws | Get waveform pulse stats | gpioWaveGetPulses |
UTILITIES | ||
H/HELP | Display command help | |
HWVER | Get hardware version | gpioHardwareRevision |
MICS v | Microseconds delay | gpioDelay |
MILS v | Milliseconds delay | gpioDelay |
PIGPV | Get pigpio library version | gpioVersion |
T/TICK | Get current tick | gpioTick |
CONFIGURATION | ||
CGI | Configuration get internals | gpioCfgGetInternals |
CSI v | Configuration set internals | gpioCfgSetInternals |
$ 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
$ 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
$ pigs bi2cc 5
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 |
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
$ pigs br1
1001C1CF
$ pigs br2
003F0000
$ 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
$ 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
SDA | SCL | MOSI | SCLK | MISO | CE | |
I2C | 18 | 19 | - | - | - | - |
SPI | - | - | 18 | 19 | 20 | 21 |
SDA | SCL | MOSI | SCLK | MISO | CE | |
I2C | 10 | 11 | - | - | - | - |
SPI | - | - | 10 | 11 | 9 | 8 |
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
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 |
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
SSSSS | number of bytes successfully copied to transmit FIFO |
RRRRR | number of bytes in receieve FIFO |
TTTTT | number of bytes in transmit FIFO |
RB | receive busy |
TE | transmit FIFO empty |
RF | receive FIFO full |
TF | transmit FIFO full |
RE | receive FIFO empty |
TB | transmit busy |
$ 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
$ pigs bspic 10
$ pigs bspic 10
-142
ERROR: no bit bang SPI in progress on GPIO
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
Mode POL PHA
0 0 0
1 0 1
2 1 0
3 1 1
$ 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
$ 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
$ 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
$ pigs evt 12
$ pigs evt 5
$ pigs evt 32
-143
ERROR: bad event id
$ pigs fc 0 # First close okay.
$ pigs fc 0 # Second fails.
-25
ERROR: unknown handle
$ pigs fg 4 250
$ pigs fg 4 1000000
-125
ERROR: bad filter parameter
$ 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
$ pigs fn 7 250 1000
$ pigs fn 7 2500000 1000
-125
ERROR: bad filter parameter
/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
a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts
Value | Meaning | |
READ | 1 | open file for reading |
WRITE | 2 | open file for writing |
RW | 3 | open file for reading and writing |
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 |
$ 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
$ pigs fr 0 10
5 48 49 128 144 255
$ pigs fr 0 10
0
From | |
0 | start |
1 | current position |
2 | end |
$ 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
$ pigs fw 0 23 45 67 89
$ pigs p 4 129
$ pigs gdc 4
129
pigs gdc 5
-92
ERROR: GPIO is not in use for PWM
$ pigs s 4 1235
$ pigs gpw 4
1235
$ pigs gpw 9
-93
ERROR: GPIO is not in use for servo pulses
$ pigs h
$ pigs help
$ 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
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) |
$ 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
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 |
$ pigs hwver # On a B+
16
$ pigs i2cc 0 # First close okay.
$ pigs i2cc 0 # Second fails.
-25
ERROR: unknown handle
SDA | SCL | |
I2C 0 | 0 | 1 |
I2C 1 | 2 | 3 |
$ pigs i2co 1 0x70 0 # Bus 1, device 0x70, flags 0.
0
$ pigs i2co 1 0x53 0 # Bus 1, device 0x53, flags 0.
1
$ pigs i2cpc 0 37 43210
39933
$ pigs i2cpc 0 256 43210
ERROR: bad i2c/spi/ser parameter
-81
$ pigs i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0
$ pigs i2crb 0 0
6
$ pigs i2crd 0 16
16 6 24 0 0 0 0 0 0 0 0 0 0 0 0 32 78
$ pigs i2cri 0 0 16
16 237 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155
$ 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
$ pigs i2crs 0
0
$ pigs i2crw 0 0
6150
$ pigs i2cwb 0 10 0x54
$ pigs i2cwd 0 0x01 0x02 0x03 0x04
$ pigs i2cwi 0 4 0x01 0x04 0xc0
pigs i2cwk 0 4 0x01 0x04 0xc0
$ pigs i2cwq 0 1
$ pigs i2cws 0 0x12
$ pigs i2cws 0 0xff
-82
ERROR: I2C write failed
$ pigs i2cww 0 0 0xffff
Name | Cmd & Data | Meaning |
End | 0 | No more commands |
Escape | 1 | Next P is two bytes |
On | 2 | Switch combined flag on |
Off | 3 | Switch combined flag off |
Address | 4 P | Set I2C address to P |
Flags | 5 lsb msb | Set I2C flags to lsb + (msb << 8) |
Read | 6 P | Read P bytes of data |
Write | 7 P ... | Write P bytes of data |
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
Mode | Input | Output | ALT0 | ALT1 | ALT2 | ALT3 | ALT4 | ALT5 |
Code | R | W | 0 | 1 | 2 | 3 | 4 | 5 |
$ pigs m 4 r # Input (read)
$ pigs m 4 w # Output (write)
$ pigs m 4 0 # ALT 0
$ pigs m 4 5 # ALT 5
Value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Mode | Input | Output | ALT5 | ALT4 | ALT0 | ALT1 | ALT2 | ALT3 |
$ pigs mg 4
1
$ pigs mics 20 # Delay 20 microseconds.
$ pigs mics 1000000 # Delay 1 second.
$ pigs mics 2000000
-64
ERROR: bad MICS delay (too large)
$ pigs mils 2000 # Delay 2 seconds.
$ pigs mils 61000
-65
ERROR: bad MILS delay (too large)
$ 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
$ pigs nc 0 # First call succeeds.
$ pigs nc 1 # Second call fails.
-25
ERROR: unknown handle
$ pigs no
0
$ pigs np 0
$ 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%
Pad | GPIO |
0 | 0-27 |
1 | 28-45 |
2 | 46-53 |
$ pigs padg 0
8
$ pigs pads 0 16
$ pigs padg 0
16
pigs padg 3
-126
ERROR: bad pad number
Pad | GPIO |
0 | 0-27 |
1 | 28-45 |
2 | 46-53 |
$ pigs pads 0 16
$ pigs padg 0
16
$ pigs pads 0 17
-127
ERROR: bad pad drive strength
$ 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
$ pigs pfg 4
800
$ pigs pfg 34
ERROR: GPIO not 0-31
-2
Hertz
1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
1250 1000 800 500 400 250 200 100 50
2: 20000 10000 5000 4000 2500 2000 1250 1000 800
625 500 400 250 200 125 100 50 25
4: 10000 5000 2500 2000 1250 1000 625 500 400
313 250 200 125 100 63 50 25 13
sample
rate
(us) 5: 8000 4000 2000 1600 1000 800 500 400 320
250 200 160 100 80 50 40 20 10
8: 5000 2500 1250 1000 625 500 313 250 200
156 125 100 63 50 31 25 13 6
10: 4000 2000 1000 800 500 400 250 200 160
125 100 80 50 40 25 20 10 5
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
$ pigs pigpv
17
$ pigs prg 4
255
$ 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
$ pigs procd 1
$ pigs procd 1
ERROR: unknown script id
-48
0 | being initialised |
1 | halted |
2 | running |
3 | waiting |
4 | failed |
$ pigs procp 0
1 0 0 0 0 0 0 0 0 0 0
$ 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
$ pigs procs 0
$ pigs procs 1
-48
ERROR: unknown script id
$ 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
$ pigs prrg 17
250
$ pigs pfs 17 0
10
$ pigs prrg 17
20000
$ pigs pfs 17 100000
8000
$ pigs prrg 17
25
#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 |
$ pigs prs 18 1000
250
$ 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.
$ pigs r 17 # Get level of GPIO 17.
0
$ pigs r 4 # Get level of GPIO 4.
1
$ pigs SERVO 17 1500
pigs s 17 0 # Switch servo pulses off.
$ pigs serc 0 # First close okay.
$ pigs serc 0 # Second close gives error.
-25
ERROR: unknown handle
$ pigs serda 0
0
$ pigs sero /dev/ttyAMA0 9600 0
0
$ pigs sero /dev/tty1 38400 0
1
$ pigs serr 0 10
5 48 49 128 144 255
$ pigs serr 0 10
0
$ pigs serrb 0
23
$ pigs serrb 0
45
$ pigs serw 0 23 45 67 89
$ pigs serwb 0 23
$ pigs serwb 0 0xf0
Script exit status | Returned system call status |
1 | 256 |
5 | 1280 |
10 | 2560 |
200 | 51200 |
script not found | 32512 |
# pass two parameters, hello and world
$ 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 "\"hello string with spaces world\""
256
# non-existent script
$ pigs shell scr78 par1
32512
$ pigs slr 15 20
6 1 0 23 45 89 0
$ pigs slrc 23
$ pigs slrc 23
-38
ERROR: no serial read in progress on GPIO
$ pigs slri 17 1 # invert logic on GPIO 17
$ pigs slri 23 0 # use normal logic on GPIO 23
$ pigs slro 23 19200 8
$ pigs slro 23 19200 8
-50
ERROR: GPIO already in use
$ pigs spic 1
$ pigs spic 1
-25
ERROR: unknown handle
MISO | MOSI | SCLK | CE0 | CE1 | CE2 | |
Main SPI | 9 | 10 | 11 | 8 | 7 | - |
Aux SPI | 19 | 20 | 21 | 18 | 17 | 16 |
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
Mode POL PHA
0 0 0
1 0 1
2 1 0
3 1 1
$ 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
$ pigs spir 0 10 # Read 10 bytes from the SPI device.
10 0 0 0 0 0 0 0 0 0 0
$ pigs spiw 0 0x22 0x33 0xcc 0xff
$ pigs spix 0 0x22 0x33 0xcc 0xff
4 0 0 0 0
$ pigs t mils 1000 t
3691823946
3692833987
$ pigs trig 4 10 1
$ pigs trig 4 51 1
-46
ERROR: trigger pulse > 50 microseconds
$ pigs w 23 0
$ pigs w 23 1
$ pigs w 23 2
-5
ERROR: level not 0-1
$ pigs wdog 23 90000
-15
ERROR: timeout not 0-60000
$ pigs wdog 23 9000
$ pigs wvag 0x10 0x80 1000 0x80 0x10 9000
2
$ pigs wvag 0 0 10000 0x10 0x80 1000 0x80 0x10 9000
4
$ pigs wvas 4 9600 8 2 0 0x30 0x31 0x32 0x33
23
$ pigs wvas 7 38400 8 2 0 0x41 0x42
35
$ pigs wvtat
9999
$ pigs wvbsy
0
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 |
#!/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 \
${w[4]} ${w[3]} ${w[2]} \
255 0 \
${w[0]} ${w[0]} ${w[0]} \
255 0 \
${w[0]} ${w[1]} \
255 2 0x88 0x13 \
255 1 30 0 \
255 0 \
${w[2]} ${w[3]} ${w[0]} \
${w[3]} ${w[1]} ${w[2]} \
255 1 10 0 \
255 1 5 0 \
${w[4]} ${w[4]} ${w[4]} \
255 2 0x20 0x4E \
${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
$ pigs wvclr
$ pigs wvas 4 9600 0 23 45 67 89 90
37
$ pigs wvcre
0
$ pigs wvcre
-69
ERROR: attempt to create an empty waveform
# 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
$ pigs wvdel 0
$ pigs wvdel 0
-66
ERROR: non existent wave id
$ pigs wvhlt
$ pigs wvnew
$ pigs wvas 4 9600 0 23 45 67 89 90
37
$ pigs wvsc 0
74
$ pigs wvsc 1
74
$ pigs wvsc 2
25016
$ pigs wvsm 0
5314
$ pigs wvsm 1
5314
$ pigs wvsm 2
1800000000
$ pigs wvsp 0
37
$ pigs wvsp 1
37
$ pigs wvsp 2
12000
$ pigs wvtx 1
75
$ pigs wvtx 2
-66
ERROR: non existent wave id
$ pigs wvtxm 1 3
75
$ pigs wvtxm 2 0
-66
ERROR: non existent wave id
$ pigs wvtxr 1
75
$ pigs wvtxr 2
-66
ERROR: non existent wave id
/dev/ttyAMA0
/dev/ttyUSB0
/dev/tty0
/dev/serial0
From | |
0 | start |
1 | current position |
2 | end |
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 | - | - | - | - |
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 |
Value | Meaning | |
READ | 1 | open file for reading |
WRITE | 2 | open file for writing |
RW | 3 | open file for reading and writing |
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 |
Pull Up Down | Off | Pull Down | Pull Up |
Command Character | O | D | U |
Pad | GPIO |
0 | 0-27 |
1 | 28-45 |
2 | 46-53 |
GPIO on | GPIO off | delay |
0x400000 (GPIO 22) | 0 (None) | 100000 (1/10th s) |
0 (None) | 0x400000 (GPIO 22) | 900000 (9/10th s) |
for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done
#!/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()
pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999
time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
do sleep 0.2; done)
pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999
time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
do sleep 0.2; done)
Command | Description | Definition |
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 |