From 3ea6fd94fd770e331a4cf8ccfafc875bd1d85246 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Tue, 2 Jul 2019 18:04:12 +0100 Subject: V68+: Changes for Pi4B (base address, default DMA channels, PUD) --- pigpio.3 | 36 +++++++++++--- pigpio.c | 167 +++++++++++++++++++++++++++++++++++++++++++++----------------- pigpio.h | 35 ++++++++----- pigpiod.c | 6 +-- 4 files changed, 175 insertions(+), 69 deletions(-) diff --git a/pigpio.3 b/pigpio.3 index 0bb28c8..b37f1e5 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -7029,8 +7029,20 @@ secondaryChannel: 0-14 .br .br -The default setting is to use channel 14 for the primary channel and -channel 6 for the secondary channel. +The default setting depends on whether the Pi has a BCM2711 chip or +not (currently only the Pi4B has a BCM2711). + +.br + +.br +The default setting for a non-BCM2711 is to use channel 14 for the +primary channel and channel 6 for the secondary channel. + +.br + +.br +The default setting for a BCM2711 is to use channel 7 for the +primary channel and channel 6 for the secondary channel. .br @@ -8022,12 +8034,12 @@ PI_MAX_WAVE_DATABITS 32 .br -.IP "\fBDMAchannel\fP: 0-14" 0 +.IP "\fBDMAchannel\fP: 0-15" 0 .EX PI_MIN_DMA_CHANNEL 0 .br -PI_MAX_DMA_CHANNEL 14 +PI_MAX_DMA_CHANNEL 15 .br .EE @@ -8928,7 +8940,7 @@ The position of an item. .br -.IP "\fBprimaryChannel\fP: 0-14" 0 +.IP "\fBprimaryChannel\fP: 0-15" 0 The DMA channel used to time the sampling of GPIO and to time servo and PWM pulses. @@ -10103,15 +10115,15 @@ A 16-bit word value. .br #define PI_BAD_IF_FLAGS -26 // ifFlags > 4 .br -#define PI_BAD_CHANNEL -27 // DMA channel not 0-14 +#define PI_BAD_CHANNEL -27 // DMA channel not 0-15 .br -#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-14 +#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15 .br #define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000 .br #define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command .br -#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-6 +#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15 .br #define PI_NOT_INITIALISED -31 // function called before gpioInitialise .br @@ -10380,6 +10392,12 @@ A 16-bit word value. .br #define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6 .br +#define PI_DEFAULT_DMA_PRIMARY_CH_2711 7 +.br +#define PI_DEFAULT_DMA_SECONDARY_CH_2711 6 +.br +#define PI_DEFAULT_DMA_NOT_SET 15 +.br #define PI_DEFAULT_SOCKET_PORT 8888 .br #define PI_DEFAULT_SOCKET_PORT_STR "8888" @@ -10400,6 +10418,8 @@ A 16-bit word value. .br #define PI_DEFAULT_UPDATE_MASK_PI3B 0x0000000FFFFFFCLL .br +#define PI_DEFAULT_UPDATE_MASK_PI4B 0x0000000FFFFFFCLL +.br #define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL .br #define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO diff --git a/pigpio.c b/pigpio.c index 3102e32..1126ec3 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 68 */ +/* pigpio version 69 */ /* include ------------------------------------------------------- */ @@ -114,6 +114,11 @@ For more information, please refer to 39 GPPUDCLK1 GPIO Pin Pull-up/down Enable Clock 1 40 - Reserved 41 - Test +42-56 Reserved +57 GPPUPPDN1 Pin pull-up/down for pins 15:0 +58 GPPUPPDN1 Pin pull-up/down for pins 31:16 +59 GPPUPPDN2 Pin pull-up/down for pins 47:32 +60 GPPUPPDN3 Pin pull-up/down for pins 57:48 */ /* @@ -317,7 +322,7 @@ bit 0 READ_LAST_NOT_SET_ERROR #define BSCS_LEN 0x40 #define CLK_LEN 0xA8 #define DMA_LEN 0x1000 /* allow access to all channels */ -#define GPIO_LEN 0xB4 +#define GPIO_LEN 0xF4 /* 2711 has more registers */ #define PADS_LEN 0x38 #define PCM_LEN 0x24 #define PWM_LEN 0x28 @@ -357,6 +362,13 @@ bit 0 READ_LAST_NOT_SET_ERROR #define GPPUDCLK0 38 #define GPPUDCLK1 39 +/* BCM2711 has different pulls */ + +#define GPPUPPDN0 57 +#define GPPUPPDN1 58 +#define GPPUPPDN2 59 +#define GPPUPPDN3 60 + #define DMA_CS 0 #define DMA_CONBLK_AD 1 #define DMA_DEBUG 8 @@ -498,8 +510,9 @@ bit 0 READ_LAST_NOT_SET_ERROR #define CLK_CTL_SRC_OSC 1 #define CLK_CTL_SRC_PLLD 6 -#define CLK_OSC_FREQ 19200000 -#define CLK_PLLD_FREQ 500000000 +#define CLK_OSC_FREQ 19200000 +#define CLK_PLLD_FREQ 500000000 +#define CLK_PLLD_FREQ_2711 750000000 #define CLK_DIV_DIVI(x) ((x)<<12) #define CLK_DIV_DIVF(x) ((x)<< 0) @@ -1199,11 +1212,13 @@ typedef struct /* initialise once then preserve */ -static volatile uint32_t piCores = 0; -static volatile uint32_t pi_ispi = 0; -static volatile uint32_t pi_peri_phys = 0x20000000; -static volatile uint32_t pi_dram_bus = 0x40000000; -static volatile uint32_t pi_mem_flag = 0x0C; +static volatile uint32_t piCores = 0; +static volatile uint32_t pi_peri_phys = 0x20000000; +static volatile uint32_t pi_dram_bus = 0x40000000; +static volatile uint32_t pi_mem_flag = 0x0C; +static volatile uint32_t pi_ispi = 0; +static volatile uint32_t pi_is_2711 = 0; +static volatile uint32_t clk_plld_freq = CLK_PLLD_FREQ; static int libInitialised = 0; @@ -1341,8 +1356,8 @@ static volatile gpioCfg_t gpioCfg = PI_DEFAULT_BUFFER_MILLIS, PI_DEFAULT_CLK_MICROS, PI_DEFAULT_CLK_PERIPHERAL, - PI_DEFAULT_DMA_PRIMARY_CHANNEL, - PI_DEFAULT_DMA_SECONDARY_CHANNEL, + PI_DEFAULT_DMA_NOT_SET, /* primary DMA */ + PI_DEFAULT_DMA_NOT_SET, /* secondary DMA */ PI_DEFAULT_SOCKET_PORT, PI_DEFAULT_IF_FLAGS, PI_DEFAULT_MEM_ALLOC_MODE, @@ -4336,7 +4351,7 @@ static void spiGoA( cs = PI_SPI_FLAGS_GET_CSPOLS(flags) & (1< PI_PUD_UP) SOFT_ERROR(PI_BAD_PUD, "gpio %d, bad pud (%d)", gpio, pud); - *(gpioReg + GPPUD) = pud; + if (pi_is_2711) + { + switch (pud) + { + case PI_PUD_OFF: pull = 0; break; + case PI_PUD_UP: pull = 1; break; + case PI_PUD_DOWN: pull = 2; break; + } - myGpioDelay(1); + bits = *(gpioReg + GPPUPPDN0 + (gpio>>4)); + bits &= ~(3 << shift); + bits |= (pull << shift); + *(gpioReg + GPPUPPDN0 + (gpio>>4)) = bits; + } + else + { + *(gpioReg + GPPUD) = pud; + + myGpioDelay(1); - *(gpioReg + GPPUDCLK0 + BANK) = BIT; + *(gpioReg + GPPUDCLK0 + BANK) = BIT; - myGpioDelay(1); + myGpioDelay(1); - *(gpioReg + GPPUD) = 0; + *(gpioReg + GPPUD) = 0; - *(gpioReg + GPPUDCLK0 + BANK) = 0; + *(gpioReg + GPPUDCLK0 + BANK) = 0; + } return 0; } @@ -12611,7 +12652,7 @@ int gpioHardwareClock(unsigned gpio, unsigned frequency) int cctl[] = {CLK_GP0_CTL, CLK_GP1_CTL, CLK_GP2_CTL}; int cdiv[] = {CLK_GP0_DIV, CLK_GP1_DIV, CLK_GP2_DIV}; int csrc[CLK_SRCS] = {CLK_CTL_SRC_OSC, CLK_CTL_SRC_PLLD}; - uint32_t cfreq[CLK_SRCS]={CLK_OSC_FREQ, CLK_PLLD_FREQ}; + uint32_t cfreq[CLK_SRCS]={CLK_OSC_FREQ, clk_plld_freq}; unsigned clock, mode, mash; int password = 0; double f; @@ -12722,13 +12763,13 @@ int gpioHardwarePWM( if (frequency) { - real_range = ((double)CLK_PLLD_FREQ / (2.0 * frequency)) + 0.5; + real_range = ((double)clk_plld_freq / (2.0 * frequency)) + 0.5; real_dutycycle = ((uint64_t)dutycycle * real_range) / PI_HW_PWM_RANGE; /* record the set PWM frequency and dutycycle */ hw_pwm_freq[pwm] = - ((double)CLK_PLLD_FREQ / ( 2.0 * real_range)) + 0.5; + ((double)clk_plld_freq / ( 2.0 * real_range)) + 0.5; hw_pwm_duty[pwm] = dutycycle; @@ -13391,9 +13432,15 @@ unsigned gpioHardwareRevision(void) } } - if (!strncasecmp("hardware\t: BCM", buf, 14)) { + if (!strncasecmp("hardware\t: BCM", buf, 14)) + { int bcmno = atoi(buf+14); - if ((bcmno == 2708) || (bcmno == 2709) || (bcmno == 2710) || (bcmno == 2835) || (bcmno == 2836) || (bcmno == 2837)) + if ((bcmno == 2708) || + (bcmno == 2709) || + (bcmno == 2710) || + (bcmno == 2835) || + (bcmno == 2836) || + (bcmno == 2837)) { pi_ispi = 1; } @@ -13405,12 +13452,37 @@ unsigned gpioHardwareRevision(void) { if (term != '\n') rev = 0; else rev &= 0xFFFFFF; /* mask out warranty bit */ + switch (rev&0xFFF0) /* just interested in BCM model */ + { + case 0x3110: /* Pi4B */ + piCores = 4; + pi_peri_phys = 0xFE000000; + pi_dram_bus = 0xC0000000; + pi_mem_flag = 0x04; + pi_is_2711 = 1; + pi_ispi = 1; + clk_plld_freq = CLK_PLLD_FREQ_2711; + fclose(filp); + if (!gpioMaskSet) + { + gpioMaskSet = 1; + gpioMask = PI_DEFAULT_UPDATE_MASK_PI4B; + } + return rev; + break; + } } } } fclose(filp); - //raspberry pi 3 running arm64 don't put all the information we need in /proc/cpuinfo, but we can get it elsewhere. + + /* + Raspberry pi 3 running arm64 don't put all the + information we need in /proc/cpuinfo, but we can + get it elsewhere. + */ + if (!pi_ispi) { filp = fopen ("/proc/device-tree/model", "r"); @@ -13430,6 +13502,7 @@ unsigned gpioHardwareRevision(void) } fclose(filp); } + if (rev == 0) { filp = fopen ("/proc/device-tree/system/linux,revision", "r"); @@ -13438,8 +13511,11 @@ unsigned gpioHardwareRevision(void) uint32_t tmp; if (fread(&tmp,1 , 4, filp) == 4) { - // for some reason the value returned by reading this - // /proc entry seems to be big endian, convert it. + /* + for some reason the value returned by reading + this /proc entry seems to be big endian, + convert it. + */ rev = ntohl(tmp); rev &= 0xFFFFFF; /* mask out warranty bit */ } @@ -13523,7 +13599,8 @@ int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel) primaryChannel); if ((secondaryChannel > PI_MAX_DMA_CHANNEL) || - (secondaryChannel == primaryChannel)) + ((secondaryChannel == primaryChannel) && + (secondaryChannel != PI_DEFAULT_DMA_NOT_SET))) SOFT_ERROR(PI_BAD_SECO_CHANNEL, "bad secondary channel (%d)", secondaryChannel); diff --git a/pigpio.h b/pigpio.h index 8c79d2c..03ebdca 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 68 +#define PIGPIO_VERSION 6904 /*TEXT @@ -831,10 +831,10 @@ typedef void *(gpioThreadFunc_t) (void *); #define PI_CLOCK_PWM 0 #define PI_CLOCK_PCM 1 -/* DMA channel: 0-14 */ +/* DMA channel: 0-15, 15 is unset */ #define PI_MIN_DMA_CHANNEL 0 -#define PI_MAX_DMA_CHANNEL 14 +#define PI_MAX_DMA_CHANNEL 15 /* port */ @@ -4745,8 +4745,7 @@ D*/ /*F*/ -int gpioCfgDMAchannels( - unsigned primaryChannel, unsigned secondaryChannel); +int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel); /*D Configures pigpio to use the specified DMA channels. @@ -4757,8 +4756,14 @@ This function is only effective if called before [*gpioInitialise*]. secondaryChannel: 0-14 . . -The default setting is to use channel 14 for the primary channel and -channel 6 for the secondary channel. +The default setting depends on whether the Pi has a BCM2711 chip or +not (currently only the Pi4B has a BCM2711). + +The default setting for a non-BCM2711 is to use channel 14 for the +primary channel and channel 6 for the secondary channel. + +The default setting for a BCM2711 is to use channel 7 for the +primary channel and channel 6 for the secondary channel. The secondary channel is only used for the transmission of waves. @@ -5331,10 +5336,10 @@ PI_MIN_WAVE_DATABITS 1 PI_MAX_WAVE_DATABITS 32 . . -DMAchannel::0-14 +DMAchannel::0-15 . . PI_MIN_DMA_CHANNEL 0 -PI_MAX_DMA_CHANNEL 14 +PI_MAX_DMA_CHANNEL 15 . . double:: @@ -5718,7 +5723,7 @@ The port used to bind to the pigpio socket. Defaults to 8888. pos:: The position of an item. -primaryChannel:: 0-14 +primaryChannel:: 0-15 The DMA channel used to time the sampling of GPIO and to time servo and PWM pulses. @@ -6301,11 +6306,11 @@ after this command is issued. #define PI_NO_HANDLE -24 // no handle available #define PI_BAD_HANDLE -25 // unknown handle #define PI_BAD_IF_FLAGS -26 // ifFlags > 4 -#define PI_BAD_CHANNEL -27 // DMA channel not 0-14 -#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-14 +#define PI_BAD_CHANNEL -27 // DMA channel not 0-15 +#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15 #define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000 #define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command -#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-6 +#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15 #define PI_NOT_INITIALISED -31 // function called before gpioInitialise #define PI_INITIALISED -32 // function called after gpioInitialise #define PI_BAD_WAVE_MODE -33 // waveform mode not 0-3 @@ -6440,6 +6445,9 @@ after this command is issued. #define PI_DEFAULT_DMA_CHANNEL 14 #define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14 #define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6 +#define PI_DEFAULT_DMA_PRIMARY_CH_2711 7 +#define PI_DEFAULT_DMA_SECONDARY_CH_2711 6 +#define PI_DEFAULT_DMA_NOT_SET 15 #define PI_DEFAULT_SOCKET_PORT 8888 #define PI_DEFAULT_SOCKET_PORT_STR "8888" #define PI_DEFAULT_SOCKET_ADDR_STR "127.0.0.1" @@ -6450,6 +6458,7 @@ after this command is issued. #define PI_DEFAULT_UPDATE_MASK_ZERO 0x0080000FFFFFFCLL #define PI_DEFAULT_UPDATE_MASK_PI2B 0x0080480FFFFFFCLL #define PI_DEFAULT_UPDATE_MASK_PI3B 0x0000000FFFFFFCLL +#define PI_DEFAULT_UPDATE_MASK_PI4B 0x0000000FFFFFFCLL #define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL #define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO diff --git a/pigpiod.c b/pigpiod.c index ce3833a..899ddf8 100644 --- a/pigpiod.c +++ b/pigpiod.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 65+ +This version is for pigpio version 69+ */ #include @@ -56,8 +56,8 @@ static unsigned clockMicros = PI_DEFAULT_CLK_MICROS; static unsigned clockPeripheral = PI_DEFAULT_CLK_PERIPHERAL; static unsigned ifFlags = PI_DEFAULT_IF_FLAGS; static int foreground = PI_DEFAULT_FOREGROUND; -static unsigned DMAprimaryChannel = PI_DEFAULT_DMA_PRIMARY_CHANNEL; -static unsigned DMAsecondaryChannel = PI_DEFAULT_DMA_SECONDARY_CHANNEL; +static unsigned DMAprimaryChannel = PI_DEFAULT_DMA_NOT_SET; +static unsigned DMAsecondaryChannel = PI_DEFAULT_DMA_NOT_SET; static unsigned socketPort = PI_DEFAULT_SOCKET_PORT; static unsigned memAllocMode = PI_DEFAULT_MEM_ALLOC_MODE; static uint64_t updateMask = -1; -- cgit v1.2.3 From 7ef99aee4240f9cf39f1cc0a1347e2bb94c80e78 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Tue, 2 Jul 2019 18:38:19 +0100 Subject: V68+: #261 close gpio ISR fd when ISR cancelled. --- pigpio.c | 12 ++++++++++++ pigpio.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 1126ec3..56c3489 100644 --- a/pigpio.c +++ b/pigpio.c @@ -970,6 +970,7 @@ typedef struct int timeout; unsigned ex; void *userdata; + int fd; int inited; } gpioISR_t; @@ -11477,12 +11478,16 @@ static void *pthISRThread(void *x) sprintf(buf, "/sys/class/gpio/gpio%d/value", isr->gpio); + isr->fd = -1; /* no fd assigned */ + if ((fd = open(buf, O_RDONLY)) < 0) { DBG(DBG_ALWAYS, "gpio %d not exported", isr->gpio); return NULL; } + isr->fd = fd; /* store fd so it can be closed */ + pfd.fd = fd; pfd.events = POLLPRI; @@ -11602,6 +11607,13 @@ static int intGpioSetISRFunc( if (gpioISR[gpio].pth) /* delete any existing ISR */ { gpioStopThread(gpioISR[gpio].pth); + + if (gpioISR[gpio].fd >= 0) + { + close(gpioISR[gpio].fd); + gpioISR[gpio].fd = -1; + } + gpioISR[gpio].func = NULL; gpioISR[gpio].pth = NULL; } diff --git a/pigpio.h b/pigpio.h index 03ebdca..046af93 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 6904 +#define PIGPIO_VERSION 6905 /*TEXT -- cgit v1.2.3 From 16074f3d83729f097bdf84b58d5f588c7dad04b0 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Tue, 2 Jul 2019 18:41:28 +0100 Subject: V69 --- pigpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.h b/pigpio.h index 046af93..8459509 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 6905 +#define PIGPIO_VERSION 69 /*TEXT -- cgit v1.2.3 From e7c8ff0341d1fc3448f27d0de5c2e26681971ef0 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Tue, 2 Jul 2019 21:41:03 +0100 Subject: Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index e326fca..f7f6ae0 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ pigpio is a C library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO). +At the moment pigpio on the Pi4B is experimental. I am not sure if the DMA channels + being used are safe. The Pi4B defaults are primary channel 7, secondary channel 6. + If these channels do not work you will have to experiment. You can set the channels + used by the pigpio daemon by invoking it with the -d and -e options, e.g. + sudo pigpiod -d 5 -e 8 to specify primary 5, secondary 8. + ## Features * Sampling and time-stamping of GPIO 0-31 between 100,000 and 1,000,000 times per second -- cgit v1.2.3 From a4801d7bd77f3760daa5c29f9669ccca8eb9c880 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Wed, 3 Jul 2019 11:55:57 +0100 Subject: Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7f6ae0..8727e74 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ pigpio is a C library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO). -At the moment pigpio on the Pi4B is experimental. I am not sure if the DMA channels +**At the moment pigpio on the Pi4B is experimental. I am not sure if the DMA channels being used are safe. The Pi4B defaults are primary channel 7, secondary channel 6. If these channels do not work you will have to experiment. You can set the channels used by the pigpio daemon by invoking it with the -d and -e options, e.g. - sudo pigpiod -d 5 -e 8 to specify primary 5, secondary 8. + sudo pigpiod -d 5 -e 8 to specify primary 5, secondary 8.** ## Features -- cgit v1.2.3 From e41362f24382bdfde217bcc80e6844c5b57176f1 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 7 Jul 2019 09:58:43 +0100 Subject: V69+: Change DBG_ALWAYS to DBG_USER for expected socket events --- pigpio.c | 15 ++++++++------- pigpio.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pigpio.c b/pigpio.c index 56c3489..282e800 100644 --- a/pigpio.c +++ b/pigpio.c @@ -6982,8 +6982,8 @@ static void *pthSocketThreadHandler(void *fdC) else { /* Serious error. No point continuing. */ - DBG(DBG_ALWAYS, - "ext too large %"PRIdPTR"(%zd), sock=%d", p[3], sizeof(buf), sock); + DBG(DBG_ALWAYS, "ext too large %"PRIdPTR"(%zd), sock=%d", + p[3], sizeof(buf), sock); closeOrphanedNotifications(-1, sock); @@ -7061,7 +7061,7 @@ static void *pthSocketThreadHandler(void *fdC) close(sock); - DBG(DBG_ALWAYS, "Socket %d closed", sock); + DBG(DBG_USER, "Socket %d closed", sock); return 0; } @@ -7126,7 +7126,7 @@ static void * pthSocketThread(void *x) if (addrAllowed((struct sockaddr *)&client)) { - DBG(DBG_ALWAYS, "Connection accepted on socket %d", fdC); + DBG(DBG_USER, "Connection accepted on socket %d", fdC); sock = malloc(sizeof(int)); @@ -7136,12 +7136,13 @@ static void * pthSocketThread(void *x) int optval = 1; socklen_t optlen = sizeof(optval); - if (setsockopt(fdC, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) { - DBG(0, "setsockopt() fail, closing socket %d", fdC); + if (setsockopt(fdC, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) + { + DBG(DBG_ALWAYS, "setsockopt() fail, closing socket %d", fdC); close(fdC); } - DBG(DBG_ALWAYS, "SO_KEEPALIVE enabled on socket %d\n", fdC); + DBG(DBG_USER, "SO_KEEPALIVE enabled on socket %d\n", fdC); if (pthread_create (&thr, &attr, pthSocketThreadHandler, (void*) sock) < 0) diff --git a/pigpio.h b/pigpio.h index 8459509..b61c503 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 69 +#define PIGPIO_VERSION 6901 /*TEXT -- cgit v1.2.3 From 5b416b699bf4baccc5349e6050695ddab0badb0e Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 7 Jul 2019 12:52:44 +0100 Subject: V69+: #280 SPI/BSC SLAVE peripheral not available on BCM2711 --- command.c | 4 +++- command.h | 2 +- pigpio.3 | 10 ++++++++++ pigpio.c | 3 +++ pigpio.h | 8 ++++++-- pigpio.py | 12 +++++++++++- pigpiod_if2.3 | 12 ++++++++++++ pigpiod_if2.c | 2 +- pigpiod_if2.h | 8 +++++++- pigs.1 | 4 ++++ pigs.c | 5 +++-- setup.py | 2 +- 12 files changed, 62 insertions(+), 10 deletions(-) diff --git a/command.c b/command.c index 7b339ea..7a799ae 100644 --- a/command.c +++ b/command.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 67+ +This version is for pigpio version 69+ */ #include @@ -564,6 +564,8 @@ static errInfo_t errInfo[]= {PI_NOT_SPI_GPIO , "no bit bang SPI in progress on GPIO"}, {PI_BAD_EVENT_ID , "bad event id"}, {PI_CMD_INTERRUPTED , "command interrupted, Python"}, + {PI_NOT_ON_BCM2711 , "not available on BCM2711"}, + {PI_ONLY_ON_BCM2711 , "only available on BCM2711"}, }; diff --git a/command.h b/command.h index d95eb49..0a09d69 100644 --- a/command.h +++ b/command.h @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 57+ +This version is for pigpio version 69+ */ #ifndef COMMAND_H diff --git a/pigpio.3 b/pigpio.3 index b37f1e5..54e23e1 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -3634,6 +3634,12 @@ Pi to act as a slave device on an I2C or SPI bus. .br +.br +This function is not available on the BCM2711 (e.g. as +used in the Pi4B). + +.br + .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -10355,6 +10361,10 @@ A 16-bit word value. .br #define PI_CMD_INTERRUPTED -144 // Used by Python .br +#define PI_NOT_ON_BCM2711 -145 // not available on BCM2711 +.br +#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711 +.br .br #define PI_PIGIF_ERR_0 -2000 diff --git a/pigpio.c b/pigpio.c index 282e800..fc308d8 100644 --- a/pigpio.c +++ b/pigpio.c @@ -10731,6 +10731,9 @@ int bscXfer(bsc_xfer_t *xfer) CHECK_INITED; + if (pi_is_2711) + SOFT_ERROR(PI_NOT_ON_BCM2711, "SPI/BSC slave not available on BCM2711"); + eventAlert[PI_EVENT_BSC].ignore = 1; if (xfer->control) diff --git a/pigpio.h b/pigpio.h index b61c503..178e3c8 100644 --- a/pigpio.h +++ b/pigpio.h @@ -13,7 +13,6 @@ of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. @@ -31,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 6901 +#define PIGPIO_VERSION 6902 /*TEXT @@ -2880,6 +2879,9 @@ This function provides a low-level interface to the SPI/I2C Slave peripheral. This peripheral allows the Pi to act as a slave device on an I2C or SPI bus. +This function is not available on the BCM2711 (e.g. as +used in the Pi4B). + I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -6426,6 +6428,8 @@ after this command is issued. #define PI_NOT_SPI_GPIO -142 // no bit bang SPI in progress on GPIO #define PI_BAD_EVENT_ID -143 // bad event id #define PI_CMD_INTERRUPTED -144 // Used by Python +#define PI_NOT_ON_BCM2711 -145 // not available on BCM2711 +#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711 #define PI_PIGIF_ERR_0 -2000 #define PI_PIGIF_ERR_99 -2099 diff --git a/pigpio.py b/pigpio.py index ae7be89..d66485d 100644 --- a/pigpio.py +++ b/pigpio.py @@ -300,7 +300,7 @@ import threading import os import atexit -VERSION = "1.42" +VERSION = "1.43" exceptions = True @@ -689,6 +689,8 @@ PI_BAD_SPI_BAUD =-141 PI_NOT_SPI_GPIO =-142 PI_BAD_EVENT_ID =-143 PI_CMD_INTERRUPTED =-144 +PI_NOT_ON_BCM2711 =-145 +PI_ONLY_ON_BCM2711 =-146 # pigpio error text @@ -835,6 +837,8 @@ _errors=[ [PI_NOT_SPI_GPIO , "no bit bang SPI in progress on GPIO"], [PI_BAD_EVENT_ID , "bad event id"], [PI_CMD_INTERRUPTED , "pigpio command interrupted"], + [PI_NOT_ON_BCM2711 , "not available on BCM2711"], + [PI_ONLY_ON_BCM2711 , "only available on BCM2711"], ] _except_a = "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n{}" @@ -3513,6 +3517,9 @@ class pi(): SPI/I2C Slave peripheral. This peripheral allows the Pi to act as a slave device on an I2C or SPI bus. + This function is not available on the BCM2711 (e.g. as + used in the Pi4B). + I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -3619,6 +3626,9 @@ class pi(): """ This function allows the Pi to act as a slave I2C device. + This function is not available on the BCM2711 (e.g. as + used in the Pi4B). + The data bytes (if any) are written to the BSC transmit FIFO and the bytes in the BSC receive FIFO are returned. diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index d91c686..f39dfa4 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -5604,6 +5604,12 @@ Pi to act as a slave device on an I2C or SPI bus. .br +.br +This function is not available on the BCM2711 (e.g. as +used in the Pi4B). + +.br + .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -5847,6 +5853,12 @@ This function allows the Pi to act as a slave I2C device. .br +.br +This function is not available on the BCM2711 (e.g.as +used in the Pi4B). + +.br + .br The data bytes (if any) are written to the BSC transmit FIFO and the bytes in the BSC receive FIFO are returned. diff --git a/pigpiod_if2.c b/pigpiod_if2.c index 85bc27c..fa97d31 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 13 */ +/* PIGPIOD_IF2_VERSION 14 */ #include #include diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 062f71c..4cd7cf8 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF2_VERSION 13 +#define PIGPIOD_IF2_VERSION 14 /*TEXT @@ -3402,6 +3402,9 @@ This function provides a low-level interface to the SPI/I2C Slave peripheral. This peripheral allows the Pi to act as a slave device on an I2C or SPI bus. +This function is not available on the BCM2711 (e.g. as +used in the Pi4B). + I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -3522,6 +3525,9 @@ int bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer); /*D This function allows the Pi to act as a slave I2C device. +This function is not available on the BCM2711 (e.g.as +used in the Pi4B). + The data bytes (if any) are written to the BSC transmit FIFO and the bytes in the BSC receive FIFO are returned. diff --git a/pigs.1 b/pigs.1 index ebb0777..cb55e3d 100644 --- a/pigs.1 +++ b/pigs.1 @@ -542,6 +542,10 @@ ERROR: no permission to update one or more GPIO This command performs a BSC I2C/SPI slave transfer as defined by \fBbctl\fP with data \fBbvs\fP. +.br +This function is not available on the BCM2711 (e.g. as +used in the Pi4B). + .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. diff --git a/pigs.c b/pigs.c index 0d0f44e..928afa3 100644 --- a/pigs.c +++ b/pigs.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 67+ +This version is for pigpio version 69+ */ #include @@ -233,8 +233,9 @@ void print_result(int sock, int rv, cmdCmd_t cmd) */ if (r < 0) { - printf("%d", r); + printf("%d\n", r); report(PIGS_SCRIPT_ERR, "ERROR: %s", cmdErrStr(r)); + break; } p = (uint32_t *)response_buf; diff --git a/setup.py b/setup.py index 9de06d2..a0cb293 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.42', + version='1.43', author='joan', author_email='joan@abyz.me.uk', maintainer='joan', -- cgit v1.2.3 From b407ab741d00c317ebf7e0bc1d09b630c024fd6e Mon Sep 17 00:00:00 2001 From: joan2937 Date: Thu, 11 Jul 2019 10:09:35 +0100 Subject: V69+: #258 reject and document illegal script commands --- command.c | 390 ++++++++++++++++++++++++++++++++------------------------------ command.h | 4 +- pigpio.c | 2 +- pigpio.h | 2 +- pigs.1 | 31 ++++- 5 files changed, 234 insertions(+), 195 deletions(-) diff --git a/command.c b/command.c index 7a799ae..5d02652 100644 --- a/command.c +++ b/command.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 69+ +This version is for pigpio version 70+ */ #include @@ -41,223 +41,223 @@ This version is for pigpio version 69+ cmdInfo_t cmdInfo[]= { - /* num str vfyt retv */ + /* num str vfyt retv script*/ - {PI_CMD_BC1, "BC1", 111, 1}, // gpioWrite_Bits_0_31_Clear - {PI_CMD_BC2, "BC2", 111, 1}, // gpioWrite_Bits_32_53_Clear + {PI_CMD_BC1, "BC1", 111, 1, 1}, // gpioWrite_Bits_0_31_Clear + {PI_CMD_BC2, "BC2", 111, 1, 1}, // gpioWrite_Bits_32_53_Clear - {PI_CMD_BI2CC, "BI2CC", 112, 0}, // bbI2CClose - {PI_CMD_BI2CO, "BI2CO", 131, 0}, // bbI2COpen - {PI_CMD_BI2CZ, "BI2CZ", 193, 6}, // bbI2CZip + {PI_CMD_BI2CC, "BI2CC", 112, 0, 1}, // bbI2CClose + {PI_CMD_BI2CO, "BI2CO", 131, 0, 1}, // bbI2COpen + {PI_CMD_BI2CZ, "BI2CZ", 193, 6, 0}, // bbI2CZip - {PI_CMD_BR1, "BR1", 101, 3}, // gpioRead_Bits_0_31 - {PI_CMD_BR2, "BR2", 101, 3}, // gpioRead_Bits_32_53 + {PI_CMD_BR1, "BR1", 101, 3, 1}, // gpioRead_Bits_0_31 + {PI_CMD_BR2, "BR2", 101, 3, 1}, // gpioRead_Bits_32_53 - {PI_CMD_BS1, "BS1", 111, 1}, // gpioWrite_Bits_0_31_Set - {PI_CMD_BS2, "BS2", 111, 1}, // gpioWrite_Bits_32_53_Set + {PI_CMD_BS1, "BS1", 111, 1, 1}, // gpioWrite_Bits_0_31_Set + {PI_CMD_BS2, "BS2", 111, 1, 1}, // gpioWrite_Bits_32_53_Set - {PI_CMD_BSCX, "BSCX", 193, 8}, // bscXfer + {PI_CMD_BSCX, "BSCX", 193, 8, 0}, // bscXfer - {PI_CMD_BSPIC, "BSPIC", 112, 0}, // bbSPIClose - {PI_CMD_BSPIO, "BSPIO", 134, 0}, // bbSPIOpen - {PI_CMD_BSPIX, "BSPIX", 193, 6}, // bbSPIXfer + {PI_CMD_BSPIC, "BSPIC", 112, 0, 1}, // bbSPIClose + {PI_CMD_BSPIO, "BSPIO", 134, 0, 0}, // bbSPIOpen + {PI_CMD_BSPIX, "BSPIX", 193, 6, 0}, // bbSPIXfer - {PI_CMD_CF1, "CF1", 195, 2}, // gpioCustom1 - {PI_CMD_CF2, "CF2", 195, 6}, // gpioCustom2 + {PI_CMD_CF1, "CF1", 195, 2, 0}, // gpioCustom1 + {PI_CMD_CF2, "CF2", 195, 6, 0}, // gpioCustom2 - {PI_CMD_CGI, "CGI", 101, 4}, // gpioCfgGetInternals - {PI_CMD_CSI, "CSI", 111, 1}, // gpioCfgSetInternals + {PI_CMD_CGI, "CGI", 101, 4, 1}, // gpioCfgGetInternals + {PI_CMD_CSI, "CSI", 111, 1, 1}, // gpioCfgSetInternals - {PI_CMD_EVM, "EVM", 122, 1}, // eventMonitor - {PI_CMD_EVT, "EVT", 112, 0}, // eventTrigger + {PI_CMD_EVM, "EVM", 122, 1, 1}, // eventMonitor + {PI_CMD_EVT, "EVT", 112, 0, 1}, // eventTrigger - {PI_CMD_FC, "FC", 112, 0}, // fileClose + {PI_CMD_FC, "FC", 112, 0, 1}, // fileClose - {PI_CMD_FG, "FG", 121, 0}, // gpioGlitchFilter + {PI_CMD_FG, "FG", 121, 0, 1}, // gpioGlitchFilter - {PI_CMD_FL, "FL", 127, 6}, // fileList + {PI_CMD_FL, "FL", 127, 6, 0}, // fileList - {PI_CMD_FN, "FN", 131, 0}, // gpioNoiseFilter + {PI_CMD_FN, "FN", 131, 0, 1}, // gpioNoiseFilter - {PI_CMD_FO, "FO", 127, 2}, // fileOpen - {PI_CMD_FR, "FR", 121, 6}, // fileRead - {PI_CMD_FS, "FS", 133, 2}, // fileSeek - {PI_CMD_FW, "FW", 193, 0}, // fileWrite + {PI_CMD_FO, "FO", 127, 2, 0}, // fileOpen + {PI_CMD_FR, "FR", 121, 6, 0}, // fileRead + {PI_CMD_FS, "FS", 133, 2, 1}, // fileSeek + {PI_CMD_FW, "FW", 193, 0, 0}, // fileWrite - {PI_CMD_GDC, "GDC", 112, 2}, // gpioGetPWMdutycycle - {PI_CMD_GPW, "GPW", 112, 2}, // gpioGetServoPulsewidth + {PI_CMD_GDC, "GDC", 112, 2, 1}, // gpioGetPWMdutycycle + {PI_CMD_GPW, "GPW", 112, 2, 1}, // gpioGetServoPulsewidth - {PI_CMD_HELP, "H", 101, 5}, // cmdUsage - {PI_CMD_HELP, "HELP", 101, 5}, // cmdUsage + {PI_CMD_HELP, "H", 101, 5, 0}, // cmdUsage + {PI_CMD_HELP, "HELP", 101, 5, 0}, // cmdUsage - {PI_CMD_HC, "HC", 121, 0}, // gpioHardwareClock - {PI_CMD_HP, "HP", 131, 0}, // gpioHardwarePWM + {PI_CMD_HC, "HC", 121, 0, 1}, // gpioHardwareClock + {PI_CMD_HP, "HP", 131, 0, 1}, // gpioHardwarePWM - {PI_CMD_HWVER, "HWVER", 101, 4}, // gpioHardwareRevision + {PI_CMD_HWVER, "HWVER", 101, 4, 1}, // gpioHardwareRevision - {PI_CMD_I2CC, "I2CC", 112, 0}, // i2cClose - {PI_CMD_I2CO, "I2CO", 131, 2}, // i2cOpen + {PI_CMD_I2CC, "I2CC", 112, 0, 1}, // i2cClose + {PI_CMD_I2CO, "I2CO", 131, 2, 1}, // i2cOpen - {PI_CMD_I2CPC, "I2CPC", 131, 2}, // i2cProcessCall - {PI_CMD_I2CPK, "I2CPK", 194, 6}, // i2cBlockProcessCall + {PI_CMD_I2CPC, "I2CPC", 131, 2, 1}, // i2cProcessCall + {PI_CMD_I2CPK, "I2CPK", 194, 6, 0}, // i2cBlockProcessCall - {PI_CMD_I2CRB, "I2CRB", 121, 2}, // i2cReadByteData - {PI_CMD_I2CRD, "I2CRD", 121, 6}, // i2cReadDevice - {PI_CMD_I2CRI, "I2CRI", 131, 6}, // i2cReadI2CBlockData - {PI_CMD_I2CRK, "I2CRK", 121, 6}, // i2cReadBlockData - {PI_CMD_I2CRS, "I2CRS", 112, 2}, // i2cReadByte - {PI_CMD_I2CRW, "I2CRW", 121, 2}, // i2cReadWordData + {PI_CMD_I2CRB, "I2CRB", 121, 2, 1}, // i2cReadByteData + {PI_CMD_I2CRD, "I2CRD", 121, 6, 0}, // i2cReadDevice + {PI_CMD_I2CRI, "I2CRI", 131, 6, 0}, // i2cReadI2CBlockData + {PI_CMD_I2CRK, "I2CRK", 121, 6, 0}, // i2cReadBlockData + {PI_CMD_I2CRS, "I2CRS", 112, 2, 1}, // i2cReadByte + {PI_CMD_I2CRW, "I2CRW", 121, 2, 1}, // i2cReadWordData - {PI_CMD_I2CWB, "I2CWB", 131, 0}, // i2cWriteByteData - {PI_CMD_I2CWD, "I2CWD", 193, 0}, // i2cWriteDevice - {PI_CMD_I2CWI, "I2CWI", 194, 0}, // i2cWriteI2CBlockData - {PI_CMD_I2CWK, "I2CWK", 194, 0}, // i2cWriteBlockData - {PI_CMD_I2CWQ, "I2CWQ", 121, 0}, // i2cWriteQuick - {PI_CMD_I2CWS, "I2CWS", 121, 0}, // i2cWriteByte - {PI_CMD_I2CWW, "I2CWW", 131, 0}, // i2cWriteWordData + {PI_CMD_I2CWB, "I2CWB", 131, 0, 1}, // i2cWriteByteData + {PI_CMD_I2CWD, "I2CWD", 193, 0, 0}, // i2cWriteDevice + {PI_CMD_I2CWI, "I2CWI", 194, 0, 0}, // i2cWriteI2CBlockData + {PI_CMD_I2CWK, "I2CWK", 194, 0, 0}, // i2cWriteBlockData + {PI_CMD_I2CWQ, "I2CWQ", 121, 0, 1}, // i2cWriteQuick + {PI_CMD_I2CWS, "I2CWS", 121, 0, 1}, // i2cWriteByte + {PI_CMD_I2CWW, "I2CWW", 131, 0, 1}, // i2cWriteWordData - {PI_CMD_I2CZ, "I2CZ", 193, 6}, // i2cZip + {PI_CMD_I2CZ, "I2CZ", 193, 6, 0}, // i2cZip - {PI_CMD_MICS, "MICS", 112, 0}, // gpioDelay - {PI_CMD_MILS, "MILS", 112, 0}, // gpioDelay + {PI_CMD_MICS, "MICS", 112, 0, 1}, // gpioDelay + {PI_CMD_MILS, "MILS", 112, 0, 1}, // gpioDelay - {PI_CMD_MODEG, "MG" , 112, 2}, // gpioGetMode - {PI_CMD_MODEG, "MODEG", 112, 2}, // gpioGetMode + {PI_CMD_MODEG, "MG" , 112, 2, 1}, // gpioGetMode + {PI_CMD_MODEG, "MODEG", 112, 2, 1}, // gpioGetMode - {PI_CMD_MODES, "M", 125, 0}, // gpioSetMode - {PI_CMD_MODES, "MODES", 125, 0}, // gpioSetMode + {PI_CMD_MODES, "M", 125, 0, 1}, // gpioSetMode + {PI_CMD_MODES, "MODES", 125, 0, 1}, // gpioSetMode - {PI_CMD_NB, "NB", 122, 0}, // gpioNotifyBegin - {PI_CMD_NC, "NC", 112, 0}, // gpioNotifyClose - {PI_CMD_NO, "NO", 101, 2}, // gpioNotifyOpen - {PI_CMD_NP, "NP", 112, 0}, // gpioNotifyPause + {PI_CMD_NB, "NB", 122, 0, 1}, // gpioNotifyBegin + {PI_CMD_NC, "NC", 112, 0, 1}, // gpioNotifyClose + {PI_CMD_NO, "NO", 101, 2, 1}, // gpioNotifyOpen + {PI_CMD_NP, "NP", 112, 0, 1}, // gpioNotifyPause - {PI_CMD_PADG, "PADG", 112, 2}, // gpioGetPad - {PI_CMD_PADS, "PADS", 121, 0}, // gpioSetPad + {PI_CMD_PADG, "PADG", 112, 2, 1}, // gpioGetPad + {PI_CMD_PADS, "PADS", 121, 0, 1}, // gpioSetPad - {PI_CMD_PARSE, "PARSE", 115, 0}, // cmdParseScript - - {PI_CMD_PFG, "PFG", 112, 2}, // gpioGetPWMfrequency - {PI_CMD_PFS, "PFS", 121, 2}, // gpioSetPWMfrequency - - {PI_CMD_PIGPV, "PIGPV", 101, 4}, // gpioVersion - - {PI_CMD_PRG, "PRG", 112, 2}, // gpioGetPWMrange - - {PI_CMD_PROC, "PROC", 115, 2}, // gpioStoreScript - {PI_CMD_PROCD, "PROCD", 112, 0}, // gpioDeleteScript - {PI_CMD_PROCP, "PROCP", 112, 7}, // gpioScriptStatus - {PI_CMD_PROCR, "PROCR", 191, 0}, // gpioRunScript - {PI_CMD_PROCS, "PROCS", 112, 0}, // gpioStopScript - {PI_CMD_PROCU, "PROCU", 191, 0}, // gpioUpdateScript - - {PI_CMD_PRRG, "PRRG", 112, 2}, // gpioGetPWMrealRange - {PI_CMD_PRS, "PRS", 121, 2}, // gpioSetPWMrange - - {PI_CMD_PUD, "PUD", 126, 0}, // gpioSetPullUpDown - - {PI_CMD_PWM, "P", 121, 0}, // gpioPWM - {PI_CMD_PWM, "PWM", 121, 0}, // gpioPWM - - {PI_CMD_READ, "R", 112, 2}, // gpioRead - {PI_CMD_READ, "READ", 112, 2}, // gpioRead - - {PI_CMD_SERRB, "SERRB", 112, 2}, // serReadByte - {PI_CMD_SERWB, "SERWB", 121, 0}, // serWriteByte - {PI_CMD_SERC, "SERC", 112, 0}, // serClose - {PI_CMD_SERDA, "SERDA", 112, 2}, // serDataAvailable - {PI_CMD_SERO, "SERO", 132, 2}, // serOpen - {PI_CMD_SERR, "SERR", 121, 6}, // serRead - {PI_CMD_SERW, "SERW", 193, 0}, // serWrite - - {PI_CMD_SERVO, "S", 121, 0}, // gpioServo - {PI_CMD_SERVO, "SERVO", 121, 0}, // gpioServo - - {PI_CMD_SHELL, "SHELL", 128, 2}, // shell - - {PI_CMD_SLR, "SLR", 121, 6}, // gpioSerialRead - {PI_CMD_SLRC, "SLRC", 112, 0}, // gpioSerialReadClose - {PI_CMD_SLRO, "SLRO", 131, 0}, // gpioSerialReadOpen - {PI_CMD_SLRI, "SLRI", 121, 0}, // gpioSerialReadInvert - - {PI_CMD_SPIC, "SPIC", 112, 0}, // spiClose - {PI_CMD_SPIO, "SPIO", 131, 2}, // spiOpen - {PI_CMD_SPIR, "SPIR", 121, 6}, // spiRead - {PI_CMD_SPIW, "SPIW", 193, 0}, // spiWrite - {PI_CMD_SPIX, "SPIX", 193, 6}, // spiXfer - - {PI_CMD_TICK, "T", 101, 4}, // gpioTick - {PI_CMD_TICK, "TICK", 101, 4}, // gpioTick - - {PI_CMD_TRIG, "TRIG", 131, 0}, // gpioTrigger - - {PI_CMD_WDOG, "WDOG", 121, 0}, // gpioSetWatchdog - - {PI_CMD_WRITE, "W", 121, 0}, // gpioWrite - {PI_CMD_WRITE, "WRITE", 121, 0}, // gpioWrite - - {PI_CMD_WVAG, "WVAG", 192, 2}, // gpioWaveAddGeneric - {PI_CMD_WVAS, "WVAS", 196, 2}, // gpioWaveAddSerial - {PI_CMD_WVTAT, "WVTAT", 101, 2}, // gpioWaveTxAt - {PI_CMD_WVBSY, "WVBSY", 101, 2}, // gpioWaveTxBusy - {PI_CMD_WVCHA, "WVCHA", 197, 0}, // gpioWaveChain - {PI_CMD_WVCLR, "WVCLR", 101, 0}, // gpioWaveClear - {PI_CMD_WVCRE, "WVCRE", 101, 2}, // gpioWaveCreate - {PI_CMD_WVDEL, "WVDEL", 112, 0}, // gpioWaveDelete - {PI_CMD_WVGO, "WVGO" , 101, 2}, // gpioWaveTxStart - {PI_CMD_WVGOR, "WVGOR", 101, 2}, // gpioWaveTxStart - {PI_CMD_WVHLT, "WVHLT", 101, 0}, // gpioWaveTxStop - {PI_CMD_WVNEW, "WVNEW", 101, 0}, // gpioWaveAddNew - {PI_CMD_WVSC, "WVSC", 112, 2}, // gpioWaveGet*Cbs - {PI_CMD_WVSM, "WVSM", 112, 2}, // gpioWaveGet*Micros - {PI_CMD_WVSP, "WVSP", 112, 2}, // gpioWaveGet*Pulses - {PI_CMD_WVTX, "WVTX", 112, 2}, // gpioWaveTxSend - {PI_CMD_WVTXM, "WVTXM", 121, 2}, // gpioWaveTxSend - {PI_CMD_WVTXR, "WVTXR", 112, 2}, // gpioWaveTxSend - - {PI_CMD_ADD , "ADD" , 111, 0}, - {PI_CMD_AND , "AND" , 111, 0}, - {PI_CMD_CALL , "CALL" , 114, 0}, - {PI_CMD_CMDR ,"CMDR" , 111, 0}, - {PI_CMD_CMDW , "CMDW" , 111, 0}, - {PI_CMD_CMP , "CMP" , 111, 0}, - {PI_CMD_DCR , "DCR" , 113, 0}, - {PI_CMD_DCRA , "DCRA" , 101, 0}, - {PI_CMD_DIV , "DIV" , 111, 0}, - {PI_CMD_EVTWT, "EVTWT", 111, 0}, - {PI_CMD_HALT , "HALT" , 101, 0}, - {PI_CMD_INR , "INR" , 113, 0}, - {PI_CMD_INRA , "INRA" , 101, 0}, - {PI_CMD_JM , "JM" , 114, 0}, - {PI_CMD_JMP , "JMP" , 114, 0}, - {PI_CMD_JNZ , "JNZ" , 114, 0}, - {PI_CMD_JP , "JP" , 114, 0}, - {PI_CMD_JZ , "JZ" , 114, 0}, - {PI_CMD_LD , "LD" , 123, 0}, - {PI_CMD_LDA , "LDA" , 111, 0}, - {PI_CMD_LDAB , "LDAB" , 111, 0}, - {PI_CMD_MLT , "MLT" , 111, 0}, - {PI_CMD_MOD , "MOD" , 111, 0}, - {PI_CMD_NOP , "NOP" , 101, 0}, - {PI_CMD_OR , "OR" , 111, 0}, - {PI_CMD_POP , "POP" , 113, 0}, - {PI_CMD_POPA , "POPA" , 101, 0}, - {PI_CMD_PUSH , "PUSH" , 113, 0}, - {PI_CMD_PUSHA, "PUSHA", 101, 0}, - {PI_CMD_RET , "RET" , 101, 0}, - {PI_CMD_RL , "RL" , 123, 0}, - {PI_CMD_RLA , "RLA" , 111, 0}, - {PI_CMD_RR , "RR" , 123, 0}, - {PI_CMD_RRA , "RRA" , 111, 0}, - {PI_CMD_STA , "STA" , 113, 0}, - {PI_CMD_STAB , "STAB" , 111, 0}, - {PI_CMD_SUB , "SUB" , 111, 0}, - {PI_CMD_SYS , "SYS" , 116, 0}, - {PI_CMD_TAG , "TAG" , 114, 0}, - {PI_CMD_WAIT , "WAIT" , 111, 0}, - {PI_CMD_X , "X" , 124, 0}, - {PI_CMD_XA , "XA" , 113, 0}, - {PI_CMD_XOR , "XOR" , 111, 0}, + {PI_CMD_PARSE, "PARSE", 115, 0, 0}, // cmdParseScript + + {PI_CMD_PFG, "PFG", 112, 2, 1}, // gpioGetPWMfrequency + {PI_CMD_PFS, "PFS", 121, 2, 1}, // gpioSetPWMfrequency + + {PI_CMD_PIGPV, "PIGPV", 101, 4, 1}, // gpioVersion + + {PI_CMD_PRG, "PRG", 112, 2, 1}, // gpioGetPWMrange + + {PI_CMD_PROC, "PROC", 115, 2, 0}, // gpioStoreScript + {PI_CMD_PROCD, "PROCD", 112, 0, 0}, // gpioDeleteScript + {PI_CMD_PROCP, "PROCP", 112, 7, 0}, // gpioScriptStatus + {PI_CMD_PROCR, "PROCR", 191, 0, 0}, // gpioRunScript + {PI_CMD_PROCS, "PROCS", 112, 0, 0}, // gpioStopScript + {PI_CMD_PROCU, "PROCU", 191, 0, 0}, // gpioUpdateScript + + {PI_CMD_PRRG, "PRRG", 112, 2, 1}, // gpioGetPWMrealRange + {PI_CMD_PRS, "PRS", 121, 2, 1}, // gpioSetPWMrange + + {PI_CMD_PUD, "PUD", 126, 0, 1}, // gpioSetPullUpDown + + {PI_CMD_PWM, "P", 121, 0, 1}, // gpioPWM + {PI_CMD_PWM, "PWM", 121, 0, 1}, // gpioPWM + + {PI_CMD_READ, "R", 112, 2, 1}, // gpioRead + {PI_CMD_READ, "READ", 112, 2, 1}, // gpioRead + + {PI_CMD_SERC, "SERC", 112, 0, 1}, // serClose + {PI_CMD_SERDA, "SERDA", 112, 2, 1}, // serDataAvailable + {PI_CMD_SERO, "SERO", 132, 2, 0}, // serOpen + {PI_CMD_SERR, "SERR", 121, 6, 0}, // serRead + {PI_CMD_SERRB, "SERRB", 112, 2, 1}, // serReadByte + {PI_CMD_SERW, "SERW", 193, 0, 0}, // serWrite + {PI_CMD_SERWB, "SERWB", 121, 0, 1}, // serWriteByte + + {PI_CMD_SERVO, "S", 121, 0, 1}, // gpioServo + {PI_CMD_SERVO, "SERVO", 121, 0, 1}, // gpioServo + + {PI_CMD_SHELL, "SHELL", 128, 2, 0}, // shell + + {PI_CMD_SLR, "SLR", 121, 6, 0}, // gpioSerialRead + {PI_CMD_SLRC, "SLRC", 112, 0, 1}, // gpioSerialReadClose + {PI_CMD_SLRO, "SLRO", 131, 0, 1}, // gpioSerialReadOpen + {PI_CMD_SLRI, "SLRI", 121, 0, 1}, // gpioSerialReadInvert + + {PI_CMD_SPIC, "SPIC", 112, 0, 1}, // spiClose + {PI_CMD_SPIO, "SPIO", 131, 2, 1}, // spiOpen + {PI_CMD_SPIR, "SPIR", 121, 6, 0}, // spiRead + {PI_CMD_SPIW, "SPIW", 193, 0, 0}, // spiWrite + {PI_CMD_SPIX, "SPIX", 193, 6, 0}, // spiXfer + + {PI_CMD_TICK, "T", 101, 4, 1}, // gpioTick + {PI_CMD_TICK, "TICK", 101, 4, 1}, // gpioTick + + {PI_CMD_TRIG, "TRIG", 131, 0, 1}, // gpioTrigger + + {PI_CMD_WDOG, "WDOG", 121, 0, 1}, // gpioSetWatchdog + + {PI_CMD_WRITE, "W", 121, 0, 1}, // gpioWrite + {PI_CMD_WRITE, "WRITE", 121, 0, 1}, // gpioWrite + + {PI_CMD_WVAG, "WVAG", 192, 2, 0}, // gpioWaveAddGeneric + {PI_CMD_WVAS, "WVAS", 196, 2, 0}, // gpioWaveAddSerial + {PI_CMD_WVBSY, "WVBSY", 101, 2, 1}, // gpioWaveTxBusy + {PI_CMD_WVCHA, "WVCHA", 197, 0, 0}, // gpioWaveChain + {PI_CMD_WVCLR, "WVCLR", 101, 0, 1}, // gpioWaveClear + {PI_CMD_WVCRE, "WVCRE", 101, 2, 1}, // gpioWaveCreate + {PI_CMD_WVDEL, "WVDEL", 112, 0, 1}, // gpioWaveDelete + {PI_CMD_WVGO, "WVGO" , 101, 2, 0}, // gpioWaveTxStart + {PI_CMD_WVGOR, "WVGOR", 101, 2, 0}, // gpioWaveTxStart + {PI_CMD_WVHLT, "WVHLT", 101, 0, 1}, // gpioWaveTxStop + {PI_CMD_WVNEW, "WVNEW", 101, 0, 1}, // gpioWaveAddNew + {PI_CMD_WVSC, "WVSC", 112, 2, 1}, // gpioWaveGet*Cbs + {PI_CMD_WVSM, "WVSM", 112, 2, 1}, // gpioWaveGet*Micros + {PI_CMD_WVSP, "WVSP", 112, 2, 1}, // gpioWaveGet*Pulses + {PI_CMD_WVTAT, "WVTAT", 101, 2, 1}, // gpioWaveTxAt + {PI_CMD_WVTX, "WVTX", 112, 2, 1}, // gpioWaveTxSend + {PI_CMD_WVTXM, "WVTXM", 121, 2, 1}, // gpioWaveTxSend + {PI_CMD_WVTXR, "WVTXR", 112, 2, 1}, // gpioWaveTxSend + + {PI_CMD_ADD , "ADD" , 111, 0, 1}, + {PI_CMD_AND , "AND" , 111, 0, 1}, + {PI_CMD_CALL , "CALL" , 114, 0, 1}, + {PI_CMD_CMDR ,"CMDR" , 111, 0, 1}, + {PI_CMD_CMDW , "CMDW" , 111, 0, 1}, + {PI_CMD_CMP , "CMP" , 111, 0, 1}, + {PI_CMD_DCR , "DCR" , 113, 0, 1}, + {PI_CMD_DCRA , "DCRA" , 101, 0, 1}, + {PI_CMD_DIV , "DIV" , 111, 0, 1}, + {PI_CMD_EVTWT, "EVTWT", 111, 0, 1}, + {PI_CMD_HALT , "HALT" , 101, 0, 1}, + {PI_CMD_INR , "INR" , 113, 0, 1}, + {PI_CMD_INRA , "INRA" , 101, 0, 1}, + {PI_CMD_JM , "JM" , 114, 0, 1}, + {PI_CMD_JMP , "JMP" , 114, 0, 1}, + {PI_CMD_JNZ , "JNZ" , 114, 0, 1}, + {PI_CMD_JP , "JP" , 114, 0, 1}, + {PI_CMD_JZ , "JZ" , 114, 0, 1}, + {PI_CMD_LD , "LD" , 123, 0, 1}, + {PI_CMD_LDA , "LDA" , 111, 0, 1}, + {PI_CMD_LDAB , "LDAB" , 111, 0, 1}, + {PI_CMD_MLT , "MLT" , 111, 0, 1}, + {PI_CMD_MOD , "MOD" , 111, 0, 1}, + {PI_CMD_NOP , "NOP" , 101, 0, 1}, + {PI_CMD_OR , "OR" , 111, 0, 1}, + {PI_CMD_POP , "POP" , 113, 0, 1}, + {PI_CMD_POPA , "POPA" , 101, 0, 1}, + {PI_CMD_PUSH , "PUSH" , 113, 0, 1}, + {PI_CMD_PUSHA, "PUSHA", 101, 0, 1}, + {PI_CMD_RET , "RET" , 101, 0, 1}, + {PI_CMD_RL , "RL" , 123, 0, 1}, + {PI_CMD_RLA , "RLA" , 111, 0, 1}, + {PI_CMD_RR , "RR" , 123, 0, 1}, + {PI_CMD_RRA , "RRA" , 111, 0, 1}, + {PI_CMD_STA , "STA" , 113, 0, 1}, + {PI_CMD_STAB , "STAB" , 111, 0, 1}, + {PI_CMD_SUB , "SUB" , 111, 0, 1}, + {PI_CMD_SYS , "SYS" , 116, 0, 1}, + {PI_CMD_TAG , "TAG" , 114, 0, 1}, + {PI_CMD_WAIT , "WAIT" , 111, 0, 1}, + {PI_CMD_X , "X" , 124, 0, 1}, + {PI_CMD_XA , "XA" , 113, 0, 1}, + {PI_CMD_XOR , "XOR" , 111, 0, 1}, }; @@ -623,6 +623,7 @@ static int getNum(char *str, uintptr_t *val, int8_t *opt) } static char intCmdStr[32]; +static int intCmdIdx; char *cmdStr(void) { @@ -653,6 +654,8 @@ int cmdParse( idx = cmdMatch(intCmdStr); + intCmdIdx = idx; + if (idx < 0) return idx; valid = 0; @@ -1304,6 +1307,13 @@ int cmdParseScript(char *script, cmdScript_t *s, int diags) { idx = cmdParse(script, p, CMD_MAX_EXTENSION, v, &ctl); + /* abort if command is illegal in a script */ + + if ((idx >= 0) || (idx != CMD_UNKNOWN_CMD)) + { + if (!cmdInfo[intCmdIdx].cvis) idx = CMD_NOT_IN_SCRIPT; + } + if (idx >= 0) { if (p[3]) @@ -1356,6 +1366,8 @@ int cmdParseScript(char *script, cmdScript_t *s, int diags) { if (idx == CMD_UNKNOWN_CMD) fprintf(stderr, "Unknown command: %s\n", cmdStr()); + else if (idx == CMD_NOT_IN_SCRIPT) + fprintf(stderr, "Command illegal in script: %s\n", cmdStr()); else fprintf(stderr, "Bad parameter to %s\n", cmdStr()); } diff --git a/command.h b/command.h index 0a09d69..3e5c336 100644 --- a/command.h +++ b/command.h @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 69+ +This version is for pigpio version 70+ */ #ifndef COMMAND_H @@ -43,6 +43,7 @@ This version is for pigpio version 69+ #define CMD_UNKNOWN_CMD -1 #define CMD_BAD_PARAMETER -2 #define CMD_EXT_TOO_SMALL -3 +#define CMD_NOT_IN_SCRIPT -4 #define CMD_P_ARR 10 #define CMD_V_ARR 10 @@ -76,6 +77,7 @@ typedef struct char *name; /* command name */ int vt; /* command verification type */ int rv; /* command return value type */ + int cvis; /* command valid in a script */ } cmdInfo_t; typedef struct diff --git a/pigpio.c b/pigpio.c index fc308d8..5187078 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 69 */ +/* pigpio version 70 */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index 178e3c8..77164bd 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 6902 +#define PIGPIO_VERSION 6906 /*TEXT diff --git a/pigs.1 b/pigs.1 index cb55e3d..0780ab5 100644 --- a/pigs.1 +++ b/pigs.1 @@ -5755,11 +5755,36 @@ Each script has .br .SS Commands .br -All the normal pigs commands may be used within a script. However -commands which return more than an integer will be of little use. +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. .br -The following commands are only legal within a script. +The following commands are not permitted within a script: + +.br +File - FL FO FR FW + +.br +I2C - BI2CZ I2CPK I2CRD I2CRI I2CRK I2CWD I2CWI I2CWK I2CZ + +.br +Misc - BSCX CF1 CF2 SHELL + +.br +Script control - PARSE PROC PROCD PROCP PROCR PROCS PROCU + +.br +Serial - SERO SERR SERW SLR + +.br +SPI - BSPIO BSPIX SPIR SPIW SPIX + +.br +Waves - WVAG WVAS WVCHA WVGO WVGOR + +.br +The following commands are only permitted within a script: .br -- cgit v1.2.3 From f660834a7a5a9707d55db1947aef29b6a71df4de Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 14 Jul 2019 20:47:20 +0100 Subject: V69+: BCM2711 PLLD 500->750 MHz Crystal 19.2->54M --- command.c | 4 ++-- pigpio.3 | 24 ++++++++++++++---------- pigpio.c | 28 +++++++++++++++++++++------- pigpio.h | 33 +++++++++++++++++++-------------- pigpio.py | 29 ++++++++++++++++------------- pigpiod_if2.3 | 18 ++++++++++-------- pigpiod_if2.c | 2 +- pigpiod_if2.h | 19 ++++++++++--------- pigs.1 | 16 ++++++++-------- setup.py | 2 +- 10 files changed, 102 insertions(+), 73 deletions(-) diff --git a/command.c b/command.c index 5d02652..4a1da4d 100644 --- a/command.c +++ b/command.c @@ -515,9 +515,9 @@ static errInfo_t errInfo[]= {PI_NOT_SERVO_GPIO , "GPIO is not in use for servo pulses"}, {PI_NOT_HCLK_GPIO , "GPIO has no hardware clock"}, {PI_NOT_HPWM_GPIO , "GPIO has no hardware PWM"}, - {PI_BAD_HPWM_FREQ , "hardware PWM frequency not 1-125M"}, + {PI_BAD_HPWM_FREQ , "invalid hardware PWM frequency"}, {PI_BAD_HPWM_DUTY , "hardware PWM dutycycle not 0-1M"}, - {PI_BAD_HCLK_FREQ , "hardware clock frequency not 4689-250M"}, + {PI_BAD_HCLK_FREQ , "invalid hardware clock frequency"}, {PI_BAD_HCLK_PASS , "need password to use hardware clock 1"}, {PI_HPWM_ILLEGAL , "illegal, PWM in use for main clock"}, {PI_BAD_DATABITS , "serial data bits not 1-32"}, diff --git a/pigpio.3 b/pigpio.3 index 54e23e1..f8c1675 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -5585,7 +5585,7 @@ Frequencies above 30MHz are unlikely to work. .EX gpio: see description .br -clkfreq: 0 (off) or 4689-250000000 (250M) +clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711) .br .EE @@ -5669,7 +5669,7 @@ main clock defaults to PCM but may be overridden by a call to .EX gpio: see description .br -PWMfreq: 0 (off) or 1-125000000 (125M) +PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) .br PWMduty: 0 (off) to 1000000 (1M)(fully on) .br @@ -5726,18 +5726,18 @@ The GPIO must be one of the following. .br The actual number of steps beween off and fully on is the -integral part of 250 million divided by PWMfreq. +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). .br .br -The actual frequency set is 250 million / steps. +The actual frequency set is 250M/steps (375M/steps for the BCM2711). .br .br -There will only be a million steps for a PWMfreq of 250. -Lower frequencies will have more steps and higher +There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher frequencies will have fewer steps. PWMduty is automatically scaled to take this into account. @@ -7978,7 +7978,7 @@ A single character, an 8 bit quantity able to store 0-255. .br -.IP "\fBclkfreq\fP: 4689-250M" 0 +.IP "\fBclkfreq\fP: 4689-250M (13184-375M for the BCM2711)" 0 .br @@ -7994,6 +7994,8 @@ PI_HW_CLK_MIN_FREQ 4689 .br PI_HW_CLK_MAX_FREQ 250000000 .br +PI_HW_CLK_MAX_FREQ_2711 375000000 +.br .EE @@ -9057,7 +9059,7 @@ PI_HW_PWM_RANGE 1000000 .br -.IP "\fBPWMfreq\fP: 5-250K" 0 +.IP "\fBPWMfreq\fP: 1-125M (1-187.5M for the BCM2711)" 0 The hardware PWM frequency. .br @@ -9069,6 +9071,8 @@ PI_HW_PWM_MIN_FREQ 1 .br PI_HW_PWM_MAX_FREQ 125000000 .br +PI_HW_PWM_MAX_FREQ_2711 187500000 +.br .EE @@ -10263,11 +10267,11 @@ A 16-bit word value. .br #define PI_NOT_HPWM_GPIO -95 // GPIO has no hardware PWM .br -#define PI_BAD_HPWM_FREQ -96 // hardware PWM frequency not 1-125M +#define PI_BAD_HPWM_FREQ -96 // invalid hardware PWM frequency .br #define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M .br -#define PI_BAD_HCLK_FREQ -98 // hardware clock frequency not 4689-250M +#define PI_BAD_HCLK_FREQ -98 // invalid hardware clock frequency .br #define PI_BAD_HCLK_PASS -99 // need password to use hardware clock 1 .br diff --git a/pigpio.c b/pigpio.c index 5187078..a41a3d7 100644 --- a/pigpio.c +++ b/pigpio.c @@ -511,6 +511,7 @@ bit 0 READ_LAST_NOT_SET_ERROR #define CLK_CTL_SRC_PLLD 6 #define CLK_OSC_FREQ 19200000 +#define CLK_OSC_FREQ_2711 54000000 #define CLK_PLLD_FREQ 500000000 #define CLK_PLLD_FREQ_2711 750000000 @@ -1219,7 +1220,11 @@ static volatile uint32_t pi_dram_bus = 0x40000000; static volatile uint32_t pi_mem_flag = 0x0C; static volatile uint32_t pi_ispi = 0; static volatile uint32_t pi_is_2711 = 0; +static volatile uint32_t clk_osc_freq = CLK_OSC_FREQ; static volatile uint32_t clk_plld_freq = CLK_PLLD_FREQ; +static volatile uint32_t hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ; +static volatile uint32_t hw_clk_min_freq = PI_HW_CLK_MIN_FREQ; +static volatile uint32_t hw_clk_max_freq = PI_HW_CLK_MAX_FREQ; static int libInitialised = 0; @@ -12668,7 +12673,7 @@ int gpioHardwareClock(unsigned gpio, unsigned frequency) int cctl[] = {CLK_GP0_CTL, CLK_GP1_CTL, CLK_GP2_CTL}; int cdiv[] = {CLK_GP0_DIV, CLK_GP1_DIV, CLK_GP2_DIV}; int csrc[CLK_SRCS] = {CLK_CTL_SRC_OSC, CLK_CTL_SRC_PLLD}; - uint32_t cfreq[CLK_SRCS]={CLK_OSC_FREQ, clk_plld_freq}; + uint32_t cfreq[CLK_SRCS]={clk_osc_freq, clk_plld_freq}; unsigned clock, mode, mash; int password = 0; double f; @@ -12688,11 +12693,12 @@ int gpioHardwareClock(unsigned gpio, unsigned frequency) if (!clkDef[gpio]) SOFT_ERROR(PI_NOT_HCLK_GPIO, "bad gpio for clock (%d)", gpio); - if (((frequency < PI_HW_CLK_MIN_FREQ) || - (frequency > PI_HW_CLK_MAX_FREQ)) && + if (((frequency < hw_clk_min_freq) || + (frequency > hw_clk_max_freq)) && (frequency)) SOFT_ERROR(PI_BAD_HCLK_FREQ, - "bad hardware clock frequency (%d)", frequency); + "bad hardware clock frequency %d-%d: (%d)", + hw_clk_min_freq, hw_clk_max_freq, frequency); clock = (clkDef[gpio] >> 4) & 3; @@ -12727,7 +12733,8 @@ int gpioHardwareClock(unsigned gpio, unsigned frequency) else { SOFT_ERROR(PI_BAD_HCLK_FREQ, - "bad hardware clock frequency (%d)", frequency); + "bad hardware clock frequency %d-%d: (%d)", + hw_clk_min_freq, hw_clk_max_freq, frequency); } } else @@ -12766,10 +12773,12 @@ int gpioHardwarePWM( SOFT_ERROR(PI_BAD_HPWM_DUTY, "bad PWM dutycycle (%d)", dutycycle); if (((frequency < PI_HW_PWM_MIN_FREQ) || - (frequency > PI_HW_PWM_MAX_FREQ)) && + (frequency > hw_pwm_max_freq)) && (frequency)) SOFT_ERROR(PI_BAD_HPWM_FREQ, - "bad hardware PWM frequency (%d)", frequency); + "bad hardware PWM frequency %d-%d: (%d)", + PI_HW_PWM_MIN_FREQ, hw_pwm_max_freq, frequency); + if (gpioCfg.clockPeriph == PI_CLOCK_PWM) SOFT_ERROR(PI_HPWM_ILLEGAL, "illegal, PWM in use for main clock"); @@ -13477,7 +13486,12 @@ unsigned gpioHardwareRevision(void) pi_mem_flag = 0x04; pi_is_2711 = 1; pi_ispi = 1; + clk_osc_freq = CLK_OSC_FREQ_2711; clk_plld_freq = CLK_PLLD_FREQ_2711; + hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ_2711; + hw_clk_min_freq = PI_HW_CLK_MIN_FREQ_2711; + hw_clk_max_freq = PI_HW_CLK_MAX_FREQ_2711; + fclose(filp); if (!gpioMaskSet) { diff --git a/pigpio.h b/pigpio.h index 77164bd..72852d5 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 6906 +#define PIGPIO_VERSION 6909 /*TEXT @@ -610,13 +610,16 @@ typedef void *(gpioThreadFunc_t) (void *); /* hardware PWM */ #define PI_HW_PWM_MIN_FREQ 1 -#define PI_HW_PWM_MAX_FREQ 125000000 +#define PI_HW_PWM_MAX_FREQ 125000000 +#define PI_HW_PWM_MAX_FREQ_2711 187500000 #define PI_HW_PWM_RANGE 1000000 /* hardware clock */ -#define PI_HW_CLK_MIN_FREQ 4689 -#define PI_HW_CLK_MAX_FREQ 250000000 +#define PI_HW_CLK_MIN_FREQ 4689 +#define PI_HW_CLK_MIN_FREQ_2711 13184 +#define PI_HW_CLK_MAX_FREQ 250000000 +#define PI_HW_CLK_MAX_FREQ_2711 375000000 #define PI_NOTIFY_SLOTS 32 @@ -3982,7 +3985,7 @@ Frequencies above 30MHz are unlikely to work. . . gpio: see description -clkfreq: 0 (off) or 4689-250000000 (250M) +clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711) . . Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, @@ -4027,7 +4030,7 @@ main clock defaults to PCM but may be overridden by a call to . . gpio: see description -PWMfreq: 0 (off) or 1-125000000 (125M) +PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) PWMduty: 0 (off) to 1000000 (1M)(fully on) . . @@ -4054,12 +4057,12 @@ The GPIO must be one of the following. . . The actual number of steps beween off and fully on is the -integral part of 250 million divided by PWMfreq. +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -The actual frequency set is 250 million / steps. +The actual frequency set is 250M/steps (375M/steps for the BCM2711). -There will only be a million steps for a PWMfreq of 250. -Lower frequencies will have more steps and higher +There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher frequencies will have fewer steps. PWMduty is automatically scaled to take this into account. D*/ @@ -5312,13 +5315,14 @@ char:: A single character, an 8 bit quantity able to store 0-255. -clkfreq::4689-250M +clkfreq::4689-250M (13184-375M for the BCM2711) The hardware clock frequency. . . PI_HW_CLK_MIN_FREQ 4689 PI_HW_CLK_MAX_FREQ 250000000 +PI_HW_CLK_MAX_FREQ_2711 375000000 . . count:: @@ -5770,12 +5774,13 @@ The hardware PWM dutycycle. PI_HW_PWM_RANGE 1000000 . . -PWMfreq::5-250K +PWMfreq::1-125M (1-187.5M for the BCM2711) The hardware PWM frequency. . . PI_HW_PWM_MIN_FREQ 1 PI_HW_PWM_MAX_FREQ 125000000 +PI_HW_PWM_MAX_FREQ_2711 187500000 . . range::25-40000 @@ -6379,9 +6384,9 @@ after this command is issued. #define PI_NOT_SERVO_GPIO -93 // GPIO is not in use for servo pulses #define PI_NOT_HCLK_GPIO -94 // GPIO has no hardware clock #define PI_NOT_HPWM_GPIO -95 // GPIO has no hardware PWM -#define PI_BAD_HPWM_FREQ -96 // hardware PWM frequency not 1-125M +#define PI_BAD_HPWM_FREQ -96 // invalid hardware PWM frequency #define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M -#define PI_BAD_HCLK_FREQ -98 // hardware clock frequency not 4689-250M +#define PI_BAD_HCLK_FREQ -98 // invalid hardware clock frequency #define PI_BAD_HCLK_PASS -99 // need password to use hardware clock 1 #define PI_HPWM_ILLEGAL -100 // illegal, PWM in use for main clock #define PI_BAD_DATABITS -101 // serial data bits not 1-32 diff --git a/pigpio.py b/pigpio.py index d66485d..4da6171 100644 --- a/pigpio.py +++ b/pigpio.py @@ -300,7 +300,7 @@ import threading import os import atexit -VERSION = "1.43" +VERSION = "1.44" exceptions = True @@ -788,9 +788,9 @@ _errors=[ [PI_NOT_SERVO_GPIO , "GPIO is not in use for servo pulses"], [PI_NOT_HCLK_GPIO , "GPIO has no hardware clock"], [PI_NOT_HPWM_GPIO , "GPIO has no hardware PWM"], - [PI_BAD_HPWM_FREQ , "hardware PWM frequency not 1-125M"], + [PI_BAD_HPWM_FREQ , "invalid hardware PWM frequency"], [PI_BAD_HPWM_DUTY , "hardware PWM dutycycle not 0-1M"], - [PI_BAD_HCLK_FREQ , "hardware clock frequency not 4689-250M"], + [PI_BAD_HCLK_FREQ , "invalid hardware clock frequency"], [PI_BAD_HCLK_PASS , "need password to use hardware clock 1"], [PI_HPWM_ILLEGAL , "illegal, PWM in use for main clock"], [PI_BAD_DATABITS , "serial data bits not 1-32"], @@ -1909,7 +1909,7 @@ class pi(): Frequencies above 30MHz are unlikely to work. gpio:= see description - clkfreq:= 0 (off) or 4689-250000000 (250M) + clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711) Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, @@ -1959,7 +1959,7 @@ class pi(): pigpio daemon is started (option -t). gpio:= see descripton - PWMfreq:= 0 (off) or 1-125000000 (125M). + PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711). PWMduty:= 0 (off) to 1000000 (1M)(fully on). Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, @@ -1985,14 +1985,15 @@ class pi(): . . The actual number of steps beween off and fully on is the - integral part of 250 million divided by PWMfreq. + integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). - The actual frequency set is 250 million / steps. + The actual frequency set is 250M/steps (375M/steps + for the BCM2711). - There will only be a million steps for a PWMfreq of 250. - Lower frequencies will have more steps and higher - frequencies will have fewer steps. PWMduty is - automatically scaled to take this into account. + There will only be a million steps for a PWMfreq of 250 + (375 for the BCM2711). Lower frequencies will have more + steps and higher frequencies will have fewer steps. + PWMduty is automatically scaled to take this into account. ... pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle @@ -5184,7 +5185,7 @@ def xref(): byte_val: 0-255 A whole number. - clkfreq: 4689-250M + clkfreq: 4689-250M (13184-375M for the BCM2711) The hardware clock frequency. connected: @@ -5340,6 +5341,8 @@ def xref(): PI_NOT_SPI_GPIO = -142 PI_BAD_EVENT_ID = -143 PI_CMD_INTERRUPTED = -144 + PI_NOT_ON_BCM2711 = -145 + PI_ONLY_ON_BCM2711 = -146 . . event:0-31 @@ -5532,7 +5535,7 @@ def xref(): PWMduty: 0-1000000 (1M) The hardware PWM dutycycle. - PWMfreq: 1-125000000 (125M) + PWMfreq: 1-125M (1-187.5M for the BCM2711) The hardware PWM frequency. range_: 25-40000 diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index f39dfa4..2354d88 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -1412,7 +1412,7 @@ Frequencies above 30MHz are unlikely to work. .br gpio: see description .br -frequency: 0 (off) or 4689-250000000 (250M) +frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711) .br .EE @@ -1498,7 +1498,7 @@ daemon is started (option -t). .br gpio: see descripton .br -PWMfreq: 0 (off) or 1-125000000 (125M) +PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) .br PWMduty: 0 (off) to 1000000 (1M)(fully on) .br @@ -1556,18 +1556,18 @@ The GPIO must be one of the following. .br The actual number of steps beween off and fully on is the -integral part of 250 million divided by PWMfreq. +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). .br .br -The actual frequency set is 250 million / steps. +The actual frequency set is 250M/steps (375M/steps for the BCM2711). .br .br -There will only be a million steps for a PWMfreq of 250. -Lower frequencies will have more steps and higher +There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher frequencies will have fewer steps. PWMduty is automatically scaled to take this into account. @@ -6294,7 +6294,7 @@ A single character, an 8 bit quantity able to store 0-255. .br -.IP "\fBclkfreq\fP: 4689-250000000 (250M)" 0 +.IP "\fBclkfreq\fP: 4689-250M (13184-375M for the BCM2711)" 0 The hardware clock frequency. .br @@ -6972,7 +6972,7 @@ The hardware PWM dutycycle. .br -.IP "\fBPWMfreq\fP: 1-125000000 (125M)" 0 +.IP "\fBPWMfreq\fP: 1-125M (1-187.5M for the BCM2711)" 0 The hardware PWM frequency. .br @@ -6984,6 +6984,8 @@ The hardware PWM frequency. .br #define PI_HW_PWM_MAX_FREQ 125000000 .br +#define PI_HW_PWM_MAX_FREQ_2711 187500000 +.br .EE diff --git a/pigpiod_if2.c b/pigpiod_if2.c index fa97d31..cd343c0 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 14 */ +/* PIGPIOD_IF2_VERSION 15 */ #include #include diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 4cd7cf8..b63dbc7 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF2_VERSION 14 +#define PIGPIOD_IF2_VERSION 15 /*TEXT @@ -1049,7 +1049,7 @@ Frequencies above 30MHz are unlikely to work. . . pi: >=0 (as returned by [*pigpio_start*]). gpio: see description -frequency: 0 (off) or 4689-250000000 (250M) +frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711) . . Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, @@ -1096,7 +1096,7 @@ daemon is started (option -t). . . pi: >=0 (as returned by [*pigpio_start*]). gpio: see descripton -PWMfreq: 0 (off) or 1-125000000 (125M) +PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) PWMduty: 0 (off) to 1000000 (1M)(fully on) . . @@ -1124,12 +1124,12 @@ The GPIO must be one of the following. . . The actual number of steps beween off and fully on is the -integral part of 250 million divided by PWMfreq. +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -The actual frequency set is 250 million / steps. +The actual frequency set is 250M/steps (375M/steps for the BCM2711). -There will only be a million steps for a PWMfreq of 250. -Lower frequencies will have more steps and higher +There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher frequencies will have fewer steps. PWMduty is automatically scaled to take this into account. D*/ @@ -3749,7 +3749,7 @@ typedef void (*CBFuncEx_t) char:: A single character, an 8 bit quantity able to store 0-255. -clkfreq::4689-250000000 (250M) +clkfreq::4689-250M (13184-375M for the BCM2711) The hardware clock frequency. count:: @@ -4053,12 +4053,13 @@ The hardware PWM dutycycle. #define PI_HW_PWM_RANGE 1000000 . . -PWMfreq::1-125000000 (125M) +PWMfreq::1-125M (1-187.5M for the BCM2711) The hardware PWM frequency. . . #define PI_HW_PWM_MIN_FREQ 1 #define PI_HW_PWM_MAX_FREQ 125000000 +#define PI_HW_PWM_MAX_FREQ_2711 187500000 . . range::25-40000 diff --git a/pigs.1 b/pigs.1 index 0780ab5..3926b64 100644 --- a/pigs.1 +++ b/pigs.1 @@ -1705,11 +1705,11 @@ $ pigs hp 19 100 200000 # 20% dutycycle .br .br -$ pigs hp 19 125000001 100000 +$ pigs hp 19 400000000 100000 .br -96 .br -ERROR: hardware PWM frequency not 1-125M +ERROR: invalid hardware PWM frequency .br .EE @@ -1745,14 +1745,14 @@ The GPIO must be one of the following. .br The actual number of steps beween off and fully on is the -integral part of 250 million divided by \fBpf\fP. +integral part of 250M/\fBpf\fP (375M/\fBpf\fP for the BCM2711). .br -The actual frequency set is 250 million / steps. +The actual frequency set is 250M/steps (375M/steps for the BCM2711). .br -There will only be a million steps for a \fBpf\fP of 250. -Lower frequencies will have more steps and higher +There will only be a million steps for a \fBpf\fP of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher frequencies will have fewer steps. \fBpdc\fP is automatically scaled to take this into account. @@ -5125,7 +5125,7 @@ The command expects a SPI channel. .br -.IP "\fBcf\fP - hardware clock frequency (4689-250M)" 0 +.IP "\fBcf\fP - hardware clock frequency (4689-250M, 13184-375M for the BCM2711)" 0 The command expects a frequency. .br @@ -5408,7 +5408,7 @@ The command expects a dutycycle. .br -.IP "\fBpf\fP - hardware PWM frequency (1-125M)" 0 +.IP "\fBpf\fP - hardware PWM frequency (1-125M, 1-187.5M for the BCM2711)" 0 The command expects a frequency. .br diff --git a/setup.py b/setup.py index a0cb293..2b5505c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.43', + version='1.44', author='joan', author_email='joan@abyz.me.uk', maintainer='joan', -- cgit v1.2.3 From 8081a97ba27ac0afee12d9459b4774523b284c3c Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 14 Jul 2019 21:25:18 +0100 Subject: V70 --- pigpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.h b/pigpio.h index 72852d5..2891c87 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 6909 +#define PIGPIO_VERSION 70 /*TEXT -- cgit v1.2.3 From 710a9462a3f321d72062b91c496155dfcf32a470 Mon Sep 17 00:00:00 2001 From: foreignmeloman Date: Sun, 21 Jul 2019 14:09:48 +0400 Subject: Added option to build the libraries statically --- CMakeLists.txt | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aac33fa..b36b0d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,23 +6,19 @@ set(CMAKE_C_FLAGS "-O3 -Wall -pthread") set(PIGPIO_FLAGS "-L. -lrt") #set(DESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/build/dest) -# libpigpio.so -add_library(pigpio SHARED pigpio.c command.c custom.cext) -set_property(TARGET pigpio - PROPERTY POSITION_INDEPENDENT_CODE ON -) +if(NOT DEFINED BUILD_SHARED_LIBS) +set(BUILD_SHARED_LIBS "ON") +endif(NOT DEFINED BUILD_SHARED_LIBS) -# libpigpiod_if.so -add_library(pigpiod_if SHARED pigpiod_if.c command.c) -set_property(TARGET pigpiod_if - PROPERTY POSITION_INDEPENDENT_CODE ON -) +# libpigpio.(so|a) +add_library(pigpio pigpio.c command.c custom.cext) + +# libpigpiod_if.(so|a) +add_library(pigpiod_if pigpiod_if.c command.c) + +# libpigpiod_if2.(so|a) +add_library(pigpiod_if2 pigpiod_if2.c command.c) -# libpigpiod_if2.so -add_library(pigpiod_if2 SHARED pigpiod_if2.c command.c) -set_property(TARGET pigpiod_if2 - PROPERTY POSITION_INDEPENDENT_CODE ON -) # x_pigpio add_executable(x_pigpio x_pigpio.c) @@ -74,6 +70,7 @@ install(DIRECTORY install(TARGETS pigpio pigpiod_if pigpiod_if2 pig2vcd pigpiod pigs LIBRARY DESTINATION ${DESTDIR}/usr/local/lib RUNTIME DESTINATION ${DESTDIR}/usr/local/bin + ARCHIVE DESTINATION ${DESTDIR}/usr/local/lib ) install(FILES pigpio.h pigpiod_if.h pigpiod_if2.h -- cgit v1.2.3 From 5847d5c0991ba3d8b00fe11125aca5f74f72bc9d Mon Sep 17 00:00:00 2001 From: Alexander Simon Date: Wed, 7 Aug 2019 13:36:37 +0200 Subject: Add support for RPi4 Model B running arm64 Linux --- pigpio.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pigpio.c b/pigpio.c index a41a3d7..6dba0d8 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13528,6 +13528,25 @@ unsigned gpioHardwareRevision(void) pi_dram_bus = 0xC0000000; pi_mem_flag = 0x04; } + else if (!strncmp("Raspberry Pi 4 Model B", buf, 22)) + { + pi_ispi = 1; + piCores = 4; + pi_peri_phys = 0xFE000000; + pi_dram_bus = 0xC0000000; + pi_mem_flag = 0x04; + pi_is_2711 = 1; + clk_osc_freq = CLK_OSC_FREQ_2711; + clk_plld_freq = CLK_PLLD_FREQ_2711; + hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ_2711; + hw_clk_min_freq = PI_HW_CLK_MIN_FREQ_2711; + hw_clk_max_freq = PI_HW_CLK_MAX_FREQ_2711; + if (!gpioMaskSet) + { + gpioMaskSet = 1; + gpioMask = PI_DEFAULT_UPDATE_MASK_PI4B; + } + } } } fclose(filp); -- cgit v1.2.3 From 55d8b880fca26ccf4b897bca1fe66796b9972345 Mon Sep 17 00:00:00 2001 From: Alexander Simon Date: Wed, 7 Aug 2019 13:39:18 +0200 Subject: Fix network communication on arm64 Base messages consist of four uint32 integers. Wrongly, integers are declared as a four-element uintptr_t array. The 16 bytes are written directly by recv(). This works great for arm32, but on arm64 uintptr_t is 64 bit (8 bytes). This patch reads four 32-bit integers and writes them into the uintptr_t array. --- pigpio.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 6dba0d8..d78afd6 100644 --- a/pigpio.c +++ b/pigpio.c @@ -6953,6 +6953,7 @@ static void *pthSocketThreadHandler(void *fdC) { int sock = *(int*)fdC; uintptr_t p[10]; + uint32_t tmp; int opt; char buf[CMD_MAX_EXTENSION]; @@ -6964,7 +6965,21 @@ static void *pthSocketThreadHandler(void *fdC) while (1) { - if (recv(sock, p, 16, MSG_WAITALL) != 16) break; + if (sizeof(uintptr_t) == 8) + { + if (recv(sock, &tmp, 4, MSG_WAITALL) != 4) break; + p[0] = (uintptr_t)tmp; + if (recv(sock, &tmp, 4, MSG_WAITALL) != 4) break; + p[1] = (uintptr_t)tmp; + if (recv(sock, &tmp, 4, MSG_WAITALL) != 4) break; + p[2] = (uintptr_t)tmp; + if (recv(sock, &tmp, 4, MSG_WAITALL) != 4) break; + p[3] = (uintptr_t)tmp; + } + else + { + if (recv(sock, p, 16, MSG_WAITALL) != 16) break; + } if (p[3]) { -- cgit v1.2.3 From 331b5a14519645ac43c26f28e2894c30d7609ca3 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Thu, 15 Aug 2019 16:26:18 +0100 Subject: V70+: #282 close notification sockets when pigpiod "-m" option is used. --- pigpio.c | 21 ++++++++++++++++++++- pigpio.h | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index d78afd6..7f8b72e 100644 --- a/pigpio.c +++ b/pigpio.c @@ -11958,6 +11958,8 @@ int gpioNotifyPause (unsigned handle) int gpioNotifyClose(unsigned handle) { + char fifo[32]; + DBG(DBG_USER, "handle=%d", handle); CHECK_INITED; @@ -11974,7 +11976,24 @@ int gpioNotifyClose(unsigned handle) intNotifyBits(); - /* actual close done in alert thread */ + if (gpioCfg.ifFlags & PI_DISABLE_ALERT) + { + if (gpioNotify[handle].pipe) + { + DBG(DBG_INTERNAL, "close notify pipe %d", gpioNotify[handle].fd); + close(gpioNotify[handle].fd); + + sprintf(fifo, "/dev/pigpio%d", handle); + + unlink(fifo); + } + + gpioNotify[handle].state = PI_NOTIFY_CLOSED; + } + else + { + /* actual close done in alert thread */ + } return 0; } diff --git a/pigpio.h b/pigpio.h index 2891c87..524a2f5 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 70 +#define PIGPIO_VERSION 7008 /*TEXT -- cgit v1.2.3 From b6fe5874516eb67745fa6277d2060b715dac09a9 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Thu, 15 Aug 2019 17:06:53 +0100 Subject: V71 --- pigpio.c | 2 +- pigpio.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index 7f8b72e..cbe818f 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 70 */ +/* pigpio version 71 */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index 524a2f5..f8a94bd 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7008 +#define PIGPIO_VERSION 71 /*TEXT -- cgit v1.2.3 From d1f3bc81d924d8ff4383f752eedcd094fd3c3949 Mon Sep 17 00:00:00 2001 From: PB Date: Fri, 16 Aug 2019 10:26:05 +0200 Subject: Fix network communication on arm64 - continued The 55d8b880fca26ccf4b897bca1fe66796b9972345 commit on the original pigpio repo fixed parsing data received from a socket on 64bit systems. This one fixes also the response that is being sent back to the socket - 64bit array is translated back to a 32bit array that is passed to the send function. --- pigpio.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index cbe818f..47c5838 100644 --- a/pigpio.c +++ b/pigpio.c @@ -6953,7 +6953,8 @@ static void *pthSocketThreadHandler(void *fdC) { int sock = *(int*)fdC; uintptr_t p[10]; - uint32_t tmp; + uint32_t tmp, response[4]; + int i; int opt; char buf[CMD_MAX_EXTENSION]; @@ -7043,7 +7044,16 @@ static void *pthSocketThreadHandler(void *fdC) p[3] = myDoCommand(p, sizeof(buf)-1, buf); } - if (write(sock, p, 16) == -1) { /* ignore errors */ } + if (sizeof(uintptr_t) == 8) // 64-bit system + { + for (i = 0; i < 4; i++) + response[i] = (uint32_t)p[i]; + if (write(sock, response, 16) == -1) { /* ignore errors */ } + } + else // 32-bit system + { + if (write(sock, p, 16) == -1) { /* ignore errors */ } + } switch (p[0]) { -- cgit v1.2.3 From ad89f458c80a4f1629d100c99d2342db41e490fc Mon Sep 17 00:00:00 2001 From: joan2937 Date: Fri, 16 Aug 2019 16:58:45 +0100 Subject: V71+: #286 arm64 socket i/f response --- pigpio.c | 2 +- pigpio.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index 47c5838..0097cb8 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 71 */ +/* pigpio version 71+ */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index f8a94bd..39229af 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 71 +#define PIGPIO_VERSION 7101 /*TEXT -- cgit v1.2.3 From 2e1d22fca34a98dea2d4ead93cf674a4da79e42d Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:31:15 +0200 Subject: optimized cmake configuration --- CMakeLists.txt | 164 ++++++++++++++++++++++++++--------------------- cmake/FindRT.cmake | 39 +++++++++++ cmake/pigpioConfig.cmake | 1 + 3 files changed, 131 insertions(+), 73 deletions(-) create mode 100644 cmake/FindRT.cmake create mode 100644 cmake/pigpioConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b36b0d6..012a3a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,18 @@ cmake_minimum_required(VERSION 3.0) -project(pigpio) +project(pigpio LANGUAGES C VERSION 0.71) -set(CMAKE_C_FLAGS "-O3 -Wall -pthread") -set(PIGPIO_FLAGS "-L. -lrt") -#set(DESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/build/dest) +list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) + +find_package(Threads REQUIRED) +find_package(RT REQUIRED) if(NOT DEFINED BUILD_SHARED_LIBS) set(BUILD_SHARED_LIBS "ON") endif(NOT DEFINED BUILD_SHARED_LIBS) +add_compile_options(-Wall) + # libpigpio.(so|a) add_library(pigpio pigpio.c command.c custom.cext) @@ -22,59 +25,87 @@ add_library(pigpiod_if2 pigpiod_if2.c command.c) # x_pigpio add_executable(x_pigpio x_pigpio.c) -add_dependencies(x_pigpio pigpio) -target_link_libraries(x_pigpio - ${PIGPIO_FLAGS} - -lpigpio -) +target_link_libraries(x_pigpio pigpio RT::RT Threads::Threads) # x_pigpiod_if add_executable(x_pigpiod_if x_pigpiod_if.c) -add_dependencies(x_pigpiod_if pigpiod_if) -target_link_libraries(x_pigpiod_if - ${PIGPIO_FLAGS} - -lpigpiod_if -) +target_link_libraries(x_pigpiod_if pigpio_if RT::RT Threads::Threads) # x_pigpiod_if2 add_executable(x_pigpiod_if2 x_pigpiod_if2.c) -add_dependencies(x_pigpiod_if2 pigpiod_if2) -target_link_libraries(x_pigpiod_if2 - ${PIGPIO_FLAGS} - -lpigpiod_if2 -) +target_link_libraries(x_pigpiod_if2 pigpio_if2 RT::RT Threads::Threads) # pigpiod add_executable(pigpiod pigpiod.c) -add_dependencies(pigpiod pigpio) -target_link_libraries(pigpiod - ${PIGPIO_FLAGS} - -lpigpio -) +target_link_libraries(pigpiod pigpio RT::RT Threads::Threads) # pigs add_executable(pigs pigs.c command.c) +target_link_libraries(pigs Threads::Threads) # pig2vcd add_executable(pig2vcd pig2vcd.c command.c) +target_link_libraries(pig2vcd Threads::Threads) # install -install(DIRECTORY - DESTINATION ${DESTDIR}/opt/pigpio/cgi - PATTERN "" - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ - GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE -) + +include (GenerateExportHeader) +include (CMakePackageConfigHelpers) + +generate_export_header(${PROJECT_NAME}) + +#install(DIRECTORY +# DESTINATION ${DESTDIR}/opt/pigpio/cgi +# PATTERN "" +# PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ +# GROUP_READ GROUP_EXECUTE +# WORLD_READ WORLD_EXECUTE +#) install(TARGETS pigpio pigpiod_if pigpiod_if2 pig2vcd pigpiod pigs - LIBRARY DESTINATION ${DESTDIR}/usr/local/lib - RUNTIME DESTINATION ${DESTDIR}/usr/local/bin - ARCHIVE DESTINATION ${DESTDIR}/usr/local/lib + EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) + +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${${PROJECT_NAME}_VERSION} + COMPATIBILITY AnyNewerVersion +) + +export(EXPORT ${PROJECT_NAME}Targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" + NAMESPACE pigpio:: +) + +#configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake +# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" +# COPYONLY +#) + +set(ConfigPackageLocation lib/cmake/${PROJECT_NAME}) +install(EXPORT ${PROJECT_NAME}Targets + FILE + ${PROJECT_NAME}Targets.cmake + NAMESPACE + pigpio:: + DESTINATION + ${ConfigPackageLocation} +) + +install( + FILES + ${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION + ${ConfigPackageLocation} ) install(FILES pigpio.h pigpiod_if.h pigpiod_if2.h - DESTINATION ${DESTDIR}/usr/local/include + DESTINATION include PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ @@ -82,7 +113,7 @@ install(FILES pigpio.h pigpiod_if.h pigpiod_if2.h file(GLOB man_1_SRC "*.1") install(FILES ${man_1_SRC} - DESTINATION ${DESTDIR}/usr/local/man/man1 + DESTINATION man/man1 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ @@ -90,48 +121,35 @@ install(FILES ${man_1_SRC} file(GLOB man_3_SRC "*.3") install(FILES ${man_3_SRC} - DESTINATION ${DESTDIR}/usr/local/man/man3 + DESTINATION man/man3 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ ) -file(GLOB setup_SRC "setup.py") -find_program(PYTHON2_FOUND python2) -if(PYTHON2_FOUND) - install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && python2 ${setup_SRC} install)") -endif() -find_program(PYTHON3_FOUND python3) -if(PYTHON3_FOUND) - install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && python3 ${setup_SRC} install)") -endif() +find_package(Python COMPONENTS Interpreter QUIET) -install(CODE "execute_process(COMMAND ldconfig)") +#file(GLOB setup_SRC "setup.py") +#if(Python_FOUND) +# install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && ${Python_EXECUTABLE} ${setup_SRC} install)") +#endif() +# +#install(CODE "execute_process(COMMAND ldconfig)") +# One does not need a uninstall command if every file was installed via cmake +# install commands. That python script however seems to need some more +# script code. # uninstall -if(PYTHON2_FOUND) - set(PY2_CMD python2 ${setup_SRC} install --record /tmp/pigpio > /dev/null) - set(PY2_CMD ${PY2_CMD} && xargs rm -f < /tmp/pigpio > /dev/null) -endif() - -if(PYTHON3_FOUND) - set(PY3_CMD python3 ${setup_SRC} install --record /tmp/pigpio > /dev/null) - set(PY3_CMD ${PY3_CMD} && xargs rm -f < /tmp/pigpio > /dev/null) -endif() - -add_custom_target(uninstall - COMMAND rm -f ${DESTDIR}/usr/local/include/pigpio.h - COMMAND rm -f ${DESTDIR}/usr/local/include/pigpiod_if.h - COMMAND rm -f ${DESTDIR}/usr/local/include/pigpiod_if2.h - COMMAND rm -f ${DESTDIR}/usr/local/lib/libpigpio.so - COMMAND rm -f ${DESTDIR}/usr/local/lib/libpigpiod_if.so - COMMAND rm -f ${DESTDIR}/usr/local/lib/libpigpiod_if2.so - COMMAND rm -f ${DESTDIR}/usr/local/bin/pig2vcd - COMMAND rm -f ${DESTDIR}/usr/local/bin/pigpiod - COMMAND rm -f ${DESTDIR}/usr/local/bin/pigs - COMMAND cd ${CMAKE_SOURCE_DIR} && ${PY2_CMD} - COMMAND cd ${CMAKE_SOURCE_DIR} && ${PY3_CMD} - COMMAND rm -f ${DESTDIR}/usr/local/man/man1/pig*.1 - COMMAND rm -f ${DESTDIR}/usr/local/man/man3/pig*.3 - COMMAND ldconfig -) +#if(Python_FOUND) +# set(PY_CMD ${Python_EXECUTABLE} ${setup_SRC} install --record /tmp/pigpio > /dev/null) +# set(PY_CMD ${PY2_CMD} && xargs rm -f < /tmp/pigpio > /dev/null) +#endif() + +#add_custom_target(uninstall +# COMMAND cd ${CMAKE_SOURCE_DIR} && ${PY_CMD} +#) + + +# package project + +include (CPack) \ No newline at end of file diff --git a/cmake/FindRT.cmake b/cmake/FindRT.cmake new file mode 100644 index 0000000..db7c4de --- /dev/null +++ b/cmake/FindRT.cmake @@ -0,0 +1,39 @@ +# FindRT.cmake - Try to find the RT library +# Once done this will define +# +# RT_FOUND - System has rt +# RT_INCLUDE_DIR - The rt include directory +# RT_LIBRARIES - The libraries needed to use rt +# RT_DEFINITIONS - Compiler switches required for using rt +# +# Also creates an import target called RT::RT + +find_path (RT_INCLUDE_DIR NAMES time.h + PATHS + /usr + /usr/local + /opt + PATH_SUFFIXES +) + +find_library(RT_LIBRARIES NAMES rt + PATHS + /usr + /usr/local + /opt +) + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(rt DEFAULT_MSG RT_LIBRARIES RT_INCLUDE_DIR) + +mark_as_advanced(RT_INCLUDE_DIR RT_LIBRARIES) + +if (NOT TARGET RT::RT) + add_library(RT::RT INTERFACE IMPORTED) + + set_target_properties(RT::RT PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${RT_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES ${RT_LIBRARIES} + ) +endif() \ No newline at end of file diff --git a/cmake/pigpioConfig.cmake b/cmake/pigpioConfig.cmake new file mode 100644 index 0000000..7912526 --- /dev/null +++ b/cmake/pigpioConfig.cmake @@ -0,0 +1 @@ +include (${CMAKE_CURRENT_LIST_DIR}/pigpioTargets.cmake) \ No newline at end of file -- cgit v1.2.3 From 062e981608df09299c9a78fce656c498a310abdf Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:36:24 +0200 Subject: fixed usage of wrongly spelled target --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 012a3a2..dca39fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,11 +29,11 @@ target_link_libraries(x_pigpio pigpio RT::RT Threads::Threads) # x_pigpiod_if add_executable(x_pigpiod_if x_pigpiod_if.c) -target_link_libraries(x_pigpiod_if pigpio_if RT::RT Threads::Threads) +target_link_libraries(x_pigpiod_if pigpiod_if RT::RT Threads::Threads) # x_pigpiod_if2 add_executable(x_pigpiod_if2 x_pigpiod_if2.c) -target_link_libraries(x_pigpiod_if2 pigpio_if2 RT::RT Threads::Threads) +target_link_libraries(x_pigpiod_if2 pigpiod_if2 RT::RT Threads::Threads) # pigpiod add_executable(pigpiod pigpiod.c) -- cgit v1.2.3 From b59425c9b89aad8d6b651afa6dde0585f6248305 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:43:07 +0200 Subject: Reenabled python isntall --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dca39fb..ea1bd55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,10 +129,10 @@ install(FILES ${man_3_SRC} find_package(Python COMPONENTS Interpreter QUIET) -#file(GLOB setup_SRC "setup.py") -#if(Python_FOUND) -# install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && ${Python_EXECUTABLE} ${setup_SRC} install)") -#endif() +file(GLOB setup_SRC "setup.py") +if(Python_FOUND) + install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && ${Python_EXECUTABLE} ${setup_SRC} install)") +endif() # #install(CODE "execute_process(COMMAND ldconfig)") -- cgit v1.2.3 From 61cf7041870d41eb61ee1daa0be5ecf83ef16117 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:45:08 +0200 Subject: Try to make things work --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea1bd55..af8a3c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,9 +129,9 @@ install(FILES ${man_3_SRC} find_package(Python COMPONENTS Interpreter QUIET) -file(GLOB setup_SRC "setup.py") if(Python_FOUND) - install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && ${Python_EXECUTABLE} ${setup_SRC} install)") + message(STATUS "Installing python modules.") + install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") -- cgit v1.2.3 From b5f0e61ccf6d6bb115670aac016f634da7f69514 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:52:04 +0200 Subject: Python setup needs to be called from root --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af8a3c1..393e38f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,8 +130,7 @@ install(FILES ${man_3_SRC} find_package(Python COMPONENTS Interpreter QUIET) if(Python_FOUND) - message(STATUS "Installing python modules.") - install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/setup.py install)") + install(CODE "execute_process(COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") -- cgit v1.2.3 From 492d83d0d34a20f6e697cdaba1a12429fb12dcde Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 12:00:09 +0200 Subject: optimized python setup --- CMakeLists.txt | 6 +++++- cmake/setup.py.in | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cmake/setup.py.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 393e38f..face031 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,11 @@ install(FILES ${man_3_SRC} find_package(Python COMPONENTS Interpreter QUIET) if(Python_FOUND) - install(CODE "execute_process(COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/setup.py install)") + configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/setup.py.in + ${CMAKE_CURRENT_BINARY_DIR}/setup.py + ) + + install(CODE "execute_process(${Python_EXECUTABLE} setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") diff --git a/cmake/setup.py.in b/cmake/setup.py.in new file mode 100644 index 0000000..a5913a2 --- /dev/null +++ b/cmake/setup.py.in @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +from distutils.core import setup + +setup(name='pigpio', + version='1.44', + author='joan', + author_email='joan@abyz.me.uk', + maintainer='joan', + maintainer_email='joan@abyz.me.uk', + url='http://abyz.me.uk/rpi/pigpio/python.html', + description='Raspberry Pi GPIO module', + long_description='Raspberry Pi Python module to access the pigpio daemon', + download_url='http://abyz.me.uk/rpi/pigpio/pigpio.zip', + license='unlicense.org', + py_modules=['pigpio'], + keywords=['raspberrypi', 'gpio',], + classifiers=[ + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 3", + ], + package_dir={ '': '${CMAKE_CURRENT_SOURCE_DIR}'} + ) + -- cgit v1.2.3 From 964bdb1e7924b672963322de5ad03cfd33c6a1fd Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 12:02:02 +0200 Subject: Fixed path issue --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index face031..5ad5d37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,7 +134,7 @@ if(Python_FOUND) ${CMAKE_CURRENT_BINARY_DIR}/setup.py ) - install(CODE "execute_process(${Python_EXECUTABLE} setup.py install)") + install(CODE "execute_process(${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") -- cgit v1.2.3 From a8498a02955823b62cd6bdb5aa2410d920fe8dc1 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 12:03:31 +0200 Subject: Forgot the command option --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ad5d37..25d46be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,7 +134,7 @@ if(Python_FOUND) ${CMAKE_CURRENT_BINARY_DIR}/setup.py ) - install(CODE "execute_process(${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") + install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") -- cgit v1.2.3 From ee7a6be22706238aa4efe214206128d3ce0bebc4 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 12:08:08 +0200 Subject: Moved option like option to actual option --- CMakeLists.txt | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25d46be..383c445 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,7 @@ list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) find_package(Threads REQUIRED) find_package(RT REQUIRED) -if(NOT DEFINED BUILD_SHARED_LIBS) -set(BUILD_SHARED_LIBS "ON") -endif(NOT DEFINED BUILD_SHARED_LIBS) +option(BUILD_SHARED_LIBS "Create shared libraries" ON) add_compile_options(-Wall) @@ -22,7 +20,6 @@ add_library(pigpiod_if pigpiod_if.c command.c) # libpigpiod_if2.(so|a) add_library(pigpiod_if2 pigpiod_if2.c command.c) - # x_pigpio add_executable(x_pigpio x_pigpio.c) target_link_libraries(x_pigpio pigpio RT::RT Threads::Threads) @@ -47,21 +44,13 @@ target_link_libraries(pigs Threads::Threads) add_executable(pig2vcd pig2vcd.c command.c) target_link_libraries(pig2vcd Threads::Threads) -# install +# Configure and install project include (GenerateExportHeader) include (CMakePackageConfigHelpers) generate_export_header(${PROJECT_NAME}) -#install(DIRECTORY -# DESTINATION ${DESTDIR}/opt/pigpio/cgi -# PATTERN "" -# PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ -# GROUP_READ GROUP_EXECUTE -# WORLD_READ WORLD_EXECUTE -#) - install(TARGETS pigpio pigpiod_if pigpiod_if2 pig2vcd pigpiod pigs EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION lib @@ -81,11 +70,6 @@ export(EXPORT ${PROJECT_NAME}Targets NAMESPACE pigpio:: ) -#configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake -# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" -# COPYONLY -#) - set(ConfigPackageLocation lib/cmake/${PROJECT_NAME}) install(EXPORT ${PROJECT_NAME}Targets FILE @@ -127,6 +111,7 @@ install(FILES ${man_3_SRC} WORLD_READ ) +# Install python modules. find_package(Python COMPONENTS Interpreter QUIET) if(Python_FOUND) @@ -136,22 +121,6 @@ if(Python_FOUND) install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") endif() -# -#install(CODE "execute_process(COMMAND ldconfig)") - -# One does not need a uninstall command if every file was installed via cmake -# install commands. That python script however seems to need some more -# script code. -# uninstall -#if(Python_FOUND) -# set(PY_CMD ${Python_EXECUTABLE} ${setup_SRC} install --record /tmp/pigpio > /dev/null) -# set(PY_CMD ${PY2_CMD} && xargs rm -f < /tmp/pigpio > /dev/null) -#endif() - -#add_custom_target(uninstall -# COMMAND cd ${CMAKE_SOURCE_DIR} && ${PY_CMD} -#) - # package project -- cgit v1.2.3 From 5966a50e45d9e42211570e6de7b36e1a4e694c4a Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 29 Sep 2019 10:13:04 +0100 Subject: V71+: change the way DMA is reset to cater for edge case --- pigpio.c | 36 ++++++++++++++++++++++-------------- pigpio.h | 2 +- x_pigpio.c | 2 ++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/pigpio.c b/pigpio.c index 0097cb8..da91ace 100644 --- a/pigpio.c +++ b/pigpio.c @@ -375,12 +375,13 @@ bit 0 READ_LAST_NOT_SET_ERROR /* DMA CS Control and Status bits */ #define DMA_CHANNEL_RESET (1<<31) +#define DMA_CHANNEL_ABORT (1<<30) #define DMA_WAIT_ON_WRITES (1<<28) #define DMA_PANIC_PRIORITY(x) ((x)<<20) #define DMA_PRIORITY(x) ((x)<<16) #define DMA_INTERRUPT_STATUS (1<< 2) #define DMA_END_FLAG (1<< 1) -#define DMA_ACTIVATE (1<< 0) +#define DMA_ACTIVE (1<< 0) /* DMA control block "info" field bits */ #define DMA_NO_WIDE_BURSTS (1<<26) @@ -7848,13 +7849,22 @@ static void initClock(int mainClock) myGpioDelay(2000); } +static void initKillDMA(volatile uint32_t *dmaAddr) +{ + dmaAddr[DMA_CS] = DMA_CHANNEL_ABORT; + dmaAddr[DMA_CS] = 0; + dmaAddr[DMA_CS] = DMA_CHANNEL_RESET; + + dmaAddr[DMA_CONBLK_AD] = 0; +} + /* ----------------------------------------------------------------------- */ static void initDMAgo(volatile uint32_t *dmaAddr, uint32_t cbAddr) { DBG(DBG_STARTUP, ""); - dmaAddr[DMA_CS] = DMA_CHANNEL_RESET; + initKillDMA(dmaAddr); dmaAddr[DMA_CS] = DMA_INTERRUPT_STATUS | DMA_END_FLAG; @@ -7870,7 +7880,7 @@ static void initDMAgo(volatile uint32_t *dmaAddr, uint32_t cbAddr) dmaAddr[DMA_CS] = DMA_WAIT_ON_WRITES | DMA_PANIC_PRIORITY(8) | DMA_PRIORITY(8) | - DMA_ACTIVATE; + DMA_ACTIVE; } /* ----------------------------------------------------------------------- */ @@ -8632,8 +8642,11 @@ void gpioTerminate(void) /* reset DMA */ - if (dmaReg != MAP_FAILED) dmaIn[DMA_CS] = DMA_CHANNEL_RESET; - if (dmaReg != MAP_FAILED) dmaOut[DMA_CS] = DMA_CHANNEL_RESET; + if (dmaReg != MAP_FAILED) + { + initKillDMA(dmaIn); + initKillDMA(dmaOut); + } #ifndef EMBEDDED_IN_VM if ((gpioCfg.internals & PI_CFG_STATS) && @@ -9688,11 +9701,7 @@ int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode) PWMClockInited = 0; } - if (wave_mode < PI_WAVE_MODE_ONE_SHOT_SYNC) - { - dmaOut[DMA_CS] = DMA_CHANNEL_RESET; - dmaOut[DMA_CONBLK_AD] = 0; - } + if (wave_mode < PI_WAVE_MODE_ONE_SHOT_SYNC) initKillDMA(dmaOut); p = rawWaveCBAdr(waveInfo[wave_id].topCB); @@ -9935,8 +9944,8 @@ int gpioWaveChain(char *buf, unsigned bufSize) PWMClockInited = 0; } - dmaOut[DMA_CS] = DMA_CHANNEL_RESET; - dmaOut[DMA_CONBLK_AD] = 0; + initKillDMA(dmaOut); + waveEndPtr = NULL; endPtr = NULL; @@ -10257,8 +10266,7 @@ int gpioWaveTxStop(void) CHECK_INITED; - dmaOut[DMA_CS] = DMA_CHANNEL_RESET; - dmaOut[DMA_CONBLK_AD] = 0; + initKillDMA(dmaOut); waveEndPtr = NULL; diff --git a/pigpio.h b/pigpio.h index 39229af..8139fa9 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7101 +#define PIGPIO_VERSION 7102 /*TEXT diff --git a/x_pigpio.c b/x_pigpio.c index c51732a..cd15389 100644 --- a/x_pigpio.c +++ b/x_pigpio.c @@ -63,10 +63,12 @@ void t1() CHECK(1, 1, v, 0, 0, "set mode, get mode"); gpioSetPullUpDown(GPIO, PI_PUD_UP); + gpioDelay(1); /* 1 micro delay to let GPIO reach level reliably */ v = gpioRead(GPIO); CHECK(1, 2, v, 1, 0, "set pull up down, read"); gpioSetPullUpDown(GPIO, PI_PUD_DOWN); + gpioDelay(1); /* 1 micro delay to let GPIO reach level reliably */ v = gpioRead(GPIO); CHECK(1, 3, v, 0, 0, "set pull up down, read"); -- cgit v1.2.3 From adf7caeff596c0bf26c00852afa7a03bf8037d05 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Wed, 27 Nov 2019 18:44:25 +0000 Subject: V71+: tidy up documentation overviews --- pig2vcd.1 | 2 +- pigpio.3 | 570 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- pigpio.h | 266 +++++++++++++++------------ pigpio.py | 207 ++++++++++++--------- pigpiod.1 | 2 +- pigpiod_if.3 | 338 +++++++++++++++++++++++++++++++++- pigpiod_if2.3 | 481 ++++++++++++++++++++++++++++++++++++++++++++++++- pigpiod_if2.c | 2 +- pigpiod_if2.h | 221 +++++++++++++---------- pigs.1 | 403 +++++++++++++++++++++++++++++++++++++++-- setup.py | 2 +- 11 files changed, 2171 insertions(+), 323 deletions(-) diff --git a/pig2vcd.1 b/pig2vcd.1 index e5271ee..2ad95ae 100644 --- a/pig2vcd.1 +++ b/pig2vcd.1 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pig2vcd.1 ." -.TH pig2vcd 1 2012-2018 Linux "pigpio archive" +.TH pig2vcd 1 2012-2019 Linux "pigpio archive" .SH NAME pig2vd - A utility to convert pigpio notifications to VCD. diff --git a/pigpio.3 b/pigpio.3 index f8c1675..b8f6789 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pigpio.3 ." -.TH pigpio 3 2012-2018 Linux "pigpio archive" +.TH pigpio 3 2012-2019 Linux "pigpio archive" .SH NAME pigpio - A C library to manipulate the Pi's GPIO. @@ -115,11 +115,6 @@ This use was inspired by Richard Hirst's servoblaster kernel module. .br -.br -See \fBhttps://github.com/richardghirst/PiBits/tree/master/ServoBlaster\fP - -.br - .br .SS Usage .br @@ -194,6 +189,540 @@ error PI_INITIALISED. .br +.br + +.SH OVERVIEW + +.br +.SS ESSENTIAL +.br + +.br +gpioInitialise Initialise library +.br +gpioTerminate Stop library +.br +.SS BASIC +.br + +.br +gpioSetMode Set a GPIO mode +.br +gpioGetMode Get a GPIO mode +.br + +.br +gpioSetPullUpDown Set/clear GPIO pull up/down resistor +.br + +.br +gpioRead Read a GPIO +.br +gpioWrite Write a GPIO +.br +.SS PWM (overrides servo commands on same GPIO) +.br + +.br +gpioPWM Start/stop PWM pulses on a GPIO +.br +gpioSetPWMfrequency Configure PWM frequency for a GPIO +.br +gpioSetPWMrange Configure PWM range for a GPIO +.br + +.br +gpioGetPWMdutycycle Get dutycycle setting on a GPIO +.br +gpioGetPWMfrequency Get configured PWM frequency for a GPIO +.br +gpioGetPWMrange Get configured PWM range for a GPIO +.br + +.br +gpioGetPWMrealRange Get underlying PWM range for a GPIO +.br +.SS Servo (overrides PWM commands on same GPIO) +.br + +.br +gpioServo Start/stop servo pulses on a GPIO +.br + +.br +gpioGetServoPulsewidth Get pulsewidth setting on a GPIO +.br +.SS INTERMEDIATE +.br + +.br +gpioTrigger Send a trigger pulse to a GPIO +.br + +.br +gpioSetWatchdog Set a watchdog on a GPIO +.br + +.br +gpioRead_Bits_0_31 Read all GPIO in bank 1 +.br +gpioRead_Bits_32_53 Read all GPIO in bank 2 +.br + +.br +gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 +.br +gpioWrite_Bits_32_53_Clear Clear selected GPIO in bank 2 +.br + +.br +gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 +.br +gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 +.br + +.br +gpioSetAlertFunc Request a GPIO level change callback +.br +gpioSetAlertFuncEx Request a GPIO change callback, extended +.br + +.br +gpioSetTimerFunc Request a regular timed callback +.br +gpioSetTimerFuncEx Request a regular timed callback, extended +.br + +.br +gpioStartThread Start a new thread +.br +gpioStopThread Stop a previously started thread +.br +.SS ADVANCED +.br + +.br +gpioNotifyOpen Request a notification handle +.br +gpioNotifyClose Close a notification +.br +gpioNotifyOpenWithSize Request a notification with sized pipe +.br +gpioNotifyBegin Start notifications for selected GPIO +.br +gpioNotifyPause Pause notifications +.br + +.br +gpioHardwareClock Start hardware clock on supported GPIO +.br + +.br +gpioHardwarePWM Start hardware PWM on supported GPIO +.br + +.br +gpioGlitchFilter Set a glitch filter on a GPIO +.br +gpioNoiseFilter Set a noise filter on a GPIO +.br + +.br +gpioSetPad Sets a pads drive strength +.br +gpioGetPad Gets a pads drive strength +.br + +.br +shell Executes a shell command +.br + +.br +gpioSetISRFunc Request a GPIO interrupt callback +.br +gpioSetISRFuncEx Request a GPIO interrupt callback, extended +.br + +.br +gpioSetSignalFunc Request a signal callback +.br +gpioSetSignalFuncEx Request a signal callback, extended +.br + +.br +gpioSetGetSamplesFunc Requests a GPIO samples callback +.br +gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended +.br +.SS Custom +.br + +.br +gpioCustom1 User custom function 1 +.br +gpioCustom2 User custom function 2 +.br +.SS Events +.br + +.br +eventMonitor Sets the events to monitor +.br +eventSetFunc Request an event callback +.br +eventSetFuncEx Request an event callback, extended +.br + +.br +eventTrigger Trigger an event +.br +.SS Scripts +.br + +.br +gpioStoreScript Store a script +.br +gpioRunScript Run a stored script +.br +gpioUpdateScript Set a scripts parameters +.br +gpioScriptStatus Get script status and parameters +.br +gpioStopScript Stop a running script +.br +gpioDeleteScript Delete a stored script +.br +.SS I2C +.br + +.br +i2cOpen Opens an I2C device +.br +i2cClose Closes an I2C device +.br + +.br +i2cWriteQuick SMBus write quick +.br + +.br +i2cReadByte SMBus read byte +.br +i2cWriteByte SMBus write byte +.br + +.br +i2cReadByteData SMBus read byte data +.br +i2cWriteByteData SMBus write byte data +.br + +.br +i2cReadWordData SMBus read word data +.br +i2cWriteWordData SMBus write word data +.br + +.br +i2cReadBlockData SMBus read block data +.br +i2cWriteBlockData SMBus write block data +.br + +.br +i2cReadI2CBlockData SMBus read I2C block data +.br +i2cWriteI2CBlockData SMBus write I2C block data +.br + +.br +i2cReadDevice Reads the raw I2C device +.br +i2cWriteDevice Writes the raw I2C device +.br + +.br +i2cProcessCall SMBus process call +.br +i2cBlockProcessCall SMBus block process call +.br + +.br +i2cSwitchCombined Sets or clears the combined flag +.br + +.br +i2cSegments Performs multiple I2C transactions +.br + +.br +i2cZip Performs multiple I2C transactions +.br +.SS I2C BIT BANG +.br + +.br +bbI2COpen Opens GPIO for bit banging I2C +.br +bbI2CClose Closes GPIO for bit banging I2C +.br + +.br +bbI2CZip Performs bit banged I2C transactions +.br +.SS I2C/SPI SLAVE +.br + +.br +bscXfer I2C/SPI as slave transfer +.br +.SS SERIAL +.br + +.br +serOpen Opens a serial device +.br +serClose Closes a serial device +.br + +.br +serReadByte Reads a byte from a serial device +.br +serWriteByte Writes a byte to a serial device +.br + +.br +serRead Reads bytes from a serial device +.br +serWrite Writes bytes to a serial device +.br + +.br +serDataAvailable Returns number of bytes ready to be read +.br +.SS SERIAL BIT BANG (read only) +.br + +.br +gpioSerialReadOpen Opens a GPIO for bit bang serial reads +.br +gpioSerialReadClose Closes a GPIO for bit bang serial reads +.br + +.br +gpioSerialReadInvert Configures normal/inverted for serial reads +.br + +.br +gpioSerialRead Reads bit bang serial data from a GPIO +.br +.SS SPI +.br + +.br +spiOpen Opens a SPI device +.br +spiClose Closes a SPI device +.br + +.br +spiRead Reads bytes from a SPI device +.br +spiWrite Writes bytes to a SPI device +.br +spiXfer Transfers bytes with a SPI device +.br +.SS SPI BIT BANG +.br + +.br +bbSPIOpen Opens GPIO for bit banging SPI +.br +bbSPIClose Closes GPIO for bit banging SPI +.br + +.br +bbSPIXfer Performs bit banged SPI transactions +.br +.SS FILES +.br + +.br +fileOpen Opens a file +.br +fileClose Closes a file +.br + +.br +fileRead Reads bytes from a file +.br +fileWrite Writes bytes to a file +.br + +.br +fileSeek Seeks to a position within a file +.br + +.br +fileList List files which match a pattern +.br +.SS WAVES +.br + +.br +gpioWaveClear Deletes all waveforms +.br + +.br +gpioWaveAddNew Starts a new waveform +.br +gpioWaveAddGeneric Adds a series of pulses to the waveform +.br +gpioWaveAddSerial Adds serial data to the waveform +.br + +.br +gpioWaveCreate Creates a waveform from added data +.br +gpioWaveDelete Deletes a waveform +.br + +.br +gpioWaveTxSend Transmits a waveform +.br + +.br +gpioWaveChain Transmits a chain of waveforms +.br + +.br +gpioWaveTxAt Returns the current transmitting waveform +.br + +.br +gpioWaveTxBusy Checks to see if the waveform has ended +.br + +.br +gpioWaveTxStop Aborts the current waveform +.br + +.br +gpioWaveGetCbs Length in CBs of the current waveform +.br +gpioWaveGetHighCbs Length of longest waveform so far +.br +gpioWaveGetMaxCbs Absolute maximum allowed CBs +.br + +.br +gpioWaveGetMicros Length in micros of the current waveform +.br +gpioWaveGetHighMicros Length of longest waveform so far +.br +gpioWaveGetMaxMicros Absolute maximum allowed micros +.br + +.br +gpioWaveGetPulses Length in pulses of the current waveform +.br +gpioWaveGetHighPulses Length of longest waveform so far +.br +gpioWaveGetMaxPulses Absolute maximum allowed pulses +.br +.SS UTILITIES +.br + +.br +gpioDelay Delay for a number of microseconds +.br + +.br +gpioTick Get current tick (microseconds) +.br + +.br +gpioHardwareRevision Get hardware revision +.br +gpioVersion Get the pigpio version +.br + +.br +getBitInBytes Get the value of a bit +.br +putBitInBytes Set the value of a bit +.br + +.br +gpioTime Get current time +.br +gpioSleep Sleep for specified time +.br + +.br +time_sleep Sleeps for a float number of seconds +.br +time_time Float number of seconds since the epoch +.br +.SS CONFIGURATION +.br + +.br +gpioCfgBufferSize Configure the GPIO sample buffer size +.br +gpioCfgClock Configure the GPIO sample rate +.br +gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) +.br +gpioCfgDMAchannels Configure the DMA channels +.br +gpioCfgPermissions Configure the GPIO access permissions +.br +gpioCfgInterfaces Configure user interfaces +.br +gpioCfgSocketPort Configure socket port +.br +gpioCfgMemAlloc Configure DMA memory allocation mode +.br +gpioCfgNetAddr Configure allowed network addresses +.br + +.br +gpioCfgInternals Configure misc. internals (DEPRECATED) +.br +gpioCfgGetInternals Get internal configuration settings +.br +gpioCfgSetInternals Set internal configuration settings +.br +.SS EXPERT +.br + +.br +rawWaveAddSPI Not intended for general use +.br +rawWaveAddGeneric Not intended for general use +.br +rawWaveCB Not intended for general use +.br +rawWaveCBAdr Not intended for general use +.br +rawWaveGetOOL Not intended for general use +.br +rawWaveSetOOL Not intended for general use +.br +rawWaveGetOut Not intended for general use +.br +rawWaveSetOut Not intended for general use +.br +rawWaveGetIn Not intended for general use +.br +rawWaveSetIn Not intended for general use +.br +rawWaveInfo Not intended for general use +.br +rawDumpWave Not intended for general use +.br +rawDumpScript Not intended for general use .br .SH FUNCTIONS @@ -3628,9 +4157,27 @@ End .IP "\fBint bscXfer(bsc_xfer_t *bsc_xfer)\fP" .IP "" 4 -This function provides a low-level interface to the -SPI/I2C Slave peripheral. This peripheral allows the -Pi to act as a slave device on an I2C or SPI bus. +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +.br + +.br +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +.br + +.br +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +.br + +.br +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. .br @@ -3683,8 +4230,9 @@ typedef struct .br .br -To start a transfer set control (see below) and copy the bytes to -be sent (if any) to txBuf and set the byte count in txCnt. +To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. .br diff --git a/pigpio.h b/pigpio.h index 8139fa9..7d8df6a 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7102 +#define PIGPIO_VERSION 7103 /*TEXT @@ -72,8 +72,6 @@ The PWM and servo pulses are timed using the DMA and PWM peripherals. This use was inspired by Richard Hirst's servoblaster kernel module. -See [[https://github.com/richardghirst/PiBits/tree/master/ServoBlaster]] - *Usage* Include in your source files. @@ -117,7 +115,7 @@ ESSENTIAL gpioInitialise Initialise library gpioTerminate Stop library -BEGINNER +BASIC gpioSetMode Set a GPIO mode gpioGetMode Get a GPIO mode @@ -127,29 +125,29 @@ gpioSetPullUpDown Set/clear GPIO pull up/down resistor gpioRead Read a GPIO gpioWrite Write a GPIO +PWM_(overrides_servo_commands_on_same_GPIO) + gpioPWM Start/stop PWM pulses on a GPIO +gpioSetPWMfrequency Configure PWM frequency for a GPIO +gpioSetPWMrange Configure PWM range for a GPIO + gpioGetPWMdutycycle Get dutycycle setting on a GPIO +gpioGetPWMfrequency Get configured PWM frequency for a GPIO +gpioGetPWMrange Get configured PWM range for a GPIO -gpioServo Start/stop servo pulses on a GPIO -gpioGetServoPulsewidth Get pulsewidth setting on a GPIO +gpioGetPWMrealRange Get underlying PWM range for a GPIO -gpioDelay Delay for a number of microseconds +Servo_(overrides_PWM_commands_on_same_GPIO) -gpioSetAlertFunc Request a GPIO level change callback +gpioServo Start/stop servo pulses on a GPIO -gpioSetTimerFunc Request a regular timed callback +gpioGetServoPulsewidth Get pulsewidth setting on a GPIO INTERMEDIATE -gpioTrigger Send a trigger pulse to a GPIO. - -gpioSetWatchdog Set a watchdog on a GPIO. +gpioTrigger Send a trigger pulse to a GPIO -gpioSetPWMrange Configure PWM range for a GPIO -gpioGetPWMrange Get configured PWM range for a GPIO - -gpioSetPWMfrequency Configure PWM frequency for a GPIO -gpioGetPWMfrequency Get configured PWM frequency for a GPIO +gpioSetWatchdog Set a watchdog on a GPIO gpioRead_Bits_0_31 Read all GPIO in bank 1 gpioRead_Bits_32_53 Read all GPIO in bank 2 @@ -160,88 +158,65 @@ gpioWrite_Bits_32_53_Clear Clear selected GPIO in bank 2 gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 -gpioStartThread Start a new thread -gpioStopThread Stop a previously started thread - -ADVANCED - -gpioGetPWMrealRange Get underlying PWM range for a GPIO - +gpioSetAlertFunc Request a GPIO level change callback gpioSetAlertFuncEx Request a GPIO change callback, extended -gpioSetISRFunc Request a GPIO interrupt callback -gpioSetISRFuncEx Request a GPIO interrupt callback, extended - -gpioSetSignalFunc Request a signal callback -gpioSetSignalFuncEx Request a signal callback, extended +gpioSetTimerFunc Request a regular timed callback +gpioSetTimerFuncEx Request a regular timed callback, extended -gpioSetGetSamplesFunc Requests a GPIO samples callback -gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended +gpioStartThread Start a new thread +gpioStopThread Stop a previously started thread -gpioSetTimerFuncEx Request a regular timed callback, extended +ADVANCED gpioNotifyOpen Request a notification handle -gpioNotifyOpenWithSize Request a notification handle with sized pipe +gpioNotifyClose Close a notification +gpioNotifyOpenWithSize Request a notification with sized pipe gpioNotifyBegin Start notifications for selected GPIO gpioNotifyPause Pause notifications -gpioNotifyClose Close a notification - -gpioSerialReadOpen Opens a GPIO for bit bang serial reads -gpioSerialReadInvert Configures normal/inverted for serial reads -gpioSerialRead Reads bit bang serial data from a GPIO -gpioSerialReadClose Closes a GPIO for bit bang serial reads gpioHardwareClock Start hardware clock on supported GPIO + gpioHardwarePWM Start hardware PWM on supported GPIO gpioGlitchFilter Set a glitch filter on a GPIO gpioNoiseFilter Set a noise filter on a GPIO -gpioGetPad Gets a pads drive strength gpioSetPad Sets a pads drive strength +gpioGetPad Gets a pads drive strength shell Executes a shell command -SCRIPTS - -gpioStoreScript Store a script -gpioRunScript Run a stored script -gpioUpdateScript Set a scripts parameters -gpioScriptStatus Get script status and parameters -gpioStopScript Stop a running script -gpioDeleteScript Delete a stored script - -WAVES - -gpioWaveClear Deletes all waveforms +gpioSetISRFunc Request a GPIO interrupt callback +gpioSetISRFuncEx Request a GPIO interrupt callback, extended -gpioWaveAddNew Starts a new waveform -gpioWaveAddGeneric Adds a series of pulses to the waveform -gpioWaveAddSerial Adds serial data to the waveform +gpioSetSignalFunc Request a signal callback +gpioSetSignalFuncEx Request a signal callback, extended -gpioWaveCreate Creates a waveform from added data -gpioWaveDelete Deletes a waveform +gpioSetGetSamplesFunc Requests a GPIO samples callback +gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended -gpioWaveTxSend Transmits a waveform +Custom -gpioWaveChain Transmits a chain of waveforms +gpioCustom1 User custom function 1 +gpioCustom2 User custom function 2 -gpioWaveTxAt Returns the current transmitting waveform +Events -gpioWaveTxBusy Checks to see if the waveform has ended -gpioWaveTxStop Aborts the current waveform +eventMonitor Sets the events to monitor +eventSetFunc Request an event callback +eventSetFuncEx Request an event callback, extended -gpioWaveGetMicros Length in microseconds of the current waveform -gpioWaveGetHighMicros Length of longest waveform so far -gpioWaveGetMaxMicros Absolute maximum allowed micros +eventTrigger Trigger an event -gpioWaveGetPulses Length in pulses of the current waveform -gpioWaveGetHighPulses Length of longest waveform so far -gpioWaveGetMaxPulses Absolute maximum allowed pulses +Scripts -gpioWaveGetCbs Length in control blocks of the current waveform -gpioWaveGetHighCbs Length of longest waveform so far -gpioWaveGetMaxCbs Absolute maximum allowed control blocks +gpioStoreScript Store a script +gpioRunScript Run a stored script +gpioUpdateScript Set a scripts parameters +gpioScriptStatus Get script status and parameters +gpioStopScript Stop a running script +gpioDeleteScript Delete a stored script I2C @@ -249,45 +224,40 @@ i2cOpen Opens an I2C device i2cClose Closes an I2C device i2cWriteQuick SMBus write quick -i2cWriteByte SMBus write byte + i2cReadByte SMBus read byte -i2cWriteByteData SMBus write byte data -i2cWriteWordData SMBus write word data +i2cWriteByte SMBus write byte + i2cReadByteData SMBus read byte data +i2cWriteByteData SMBus write byte data + i2cReadWordData SMBus read word data -i2cProcessCall SMBus process call -i2cWriteBlockData SMBus write block data +i2cWriteWordData SMBus write word data + i2cReadBlockData SMBus read block data -i2cBlockProcessCall SMBus block process call +i2cWriteBlockData SMBus write block data -i2cWriteI2CBlockData SMBus write I2C block data i2cReadI2CBlockData SMBus read I2C block data +i2cWriteI2CBlockData SMBus write I2C block data i2cReadDevice Reads the raw I2C device i2cWriteDevice Writes the raw I2C device +i2cProcessCall SMBus process call +i2cBlockProcessCall SMBus block process call + i2cSwitchCombined Sets or clears the combined flag i2cSegments Performs multiple I2C transactions i2cZip Performs multiple I2C transactions +I2C_BIT_BANG + bbI2COpen Opens GPIO for bit banging I2C bbI2CClose Closes GPIO for bit banging I2C -bbI2CZip Performs multiple bit banged I2C transactions -SPI - -spiOpen Opens a SPI device -spiClose Closes a SPI device - -spiRead Reads bytes from a SPI device -spiWrite Writes bytes to a SPI device -spiXfer Transfers bytes with a SPI device - -bbSPIOpen Opens GPIO for bit banging SPI -bbSPIClose Closes GPIO for bit banging SPI -bbSPIXfer Performs multiple bit banged SPI transactions +bbI2CZip Performs bit banged I2C transactions I2C/SPI_SLAVE @@ -300,50 +270,86 @@ serClose Closes a serial device serReadByte Reads a byte from a serial device serWriteByte Writes a byte to a serial device + serRead Reads bytes from a serial device serWrite Writes bytes to a serial device serDataAvailable Returns number of bytes ready to be read +SERIAL_BIT_BANG_(read_only) + +gpioSerialReadOpen Opens a GPIO for bit bang serial reads +gpioSerialReadClose Closes a GPIO for bit bang serial reads + +gpioSerialReadInvert Configures normal/inverted for serial reads + +gpioSerialRead Reads bit bang serial data from a GPIO + +SPI + +spiOpen Opens a SPI device +spiClose Closes a SPI device + +spiRead Reads bytes from a SPI device +spiWrite Writes bytes to a SPI device +spiXfer Transfers bytes with a SPI device + +SPI_BIT_BANG + +bbSPIOpen Opens GPIO for bit banging SPI +bbSPIClose Closes GPIO for bit banging SPI + +bbSPIXfer Performs bit banged SPI transactions + FILES fileOpen Opens a file fileClose Closes a file + fileRead Reads bytes from a file fileWrite Writes bytes to a file + fileSeek Seeks to a position within a file + fileList List files which match a pattern -EVENTS +WAVES -eventMonitor Sets the events to monitor -eventSetFunc Request an event callback -eventSetFuncEx Request an event callback, extended -eventTrigger Trigger an event +gpioWaveClear Deletes all waveforms -CONFIGURATION +gpioWaveAddNew Starts a new waveform +gpioWaveAddGeneric Adds a series of pulses to the waveform +gpioWaveAddSerial Adds serial data to the waveform -gpioCfgBufferSize Configure the GPIO sample buffer size -gpioCfgClock Configure the GPIO sample rate -gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) -gpioCfgDMAchannels Configure the DMA channels -gpioCfgPermissions Configure the GPIO access permissions -gpioCfgInterfaces Configure user interfaces -gpioCfgSocketPort Configure socket port -gpioCfgMemAlloc Configure DMA memory allocation mode -gpioCfgNetAddr Configure allowed network addresses +gpioWaveCreate Creates a waveform from added data +gpioWaveDelete Deletes a waveform -gpioCfgInternals Configure miscellaneous internals (DEPRECATED) -gpioCfgGetInternals Get internal configuration settings -gpioCfgSetInternals Set internal configuration settings +gpioWaveTxSend Transmits a waveform -CUSTOM +gpioWaveChain Transmits a chain of waveforms -gpioCustom1 User custom function 1 -gpioCustom2 User custom function 2 +gpioWaveTxAt Returns the current transmitting waveform + +gpioWaveTxBusy Checks to see if the waveform has ended + +gpioWaveTxStop Aborts the current waveform + +gpioWaveGetCbs Length in CBs of the current waveform +gpioWaveGetHighCbs Length of longest waveform so far +gpioWaveGetMaxCbs Absolute maximum allowed CBs + +gpioWaveGetMicros Length in micros of the current waveform +gpioWaveGetHighMicros Length of longest waveform so far +gpioWaveGetMaxMicros Absolute maximum allowed micros + +gpioWaveGetPulses Length in pulses of the current waveform +gpioWaveGetHighPulses Length of longest waveform so far +gpioWaveGetMaxPulses Absolute maximum allowed pulses UTILITIES +gpioDelay Delay for a number of microseconds + gpioTick Get current tick (microseconds) gpioHardwareRevision Get hardware revision @@ -358,6 +364,22 @@ gpioSleep Sleep for specified time time_sleep Sleeps for a float number of seconds time_time Float number of seconds since the epoch +CONFIGURATION + +gpioCfgBufferSize Configure the GPIO sample buffer size +gpioCfgClock Configure the GPIO sample rate +gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) +gpioCfgDMAchannels Configure the DMA channels +gpioCfgPermissions Configure the GPIO access permissions +gpioCfgInterfaces Configure user interfaces +gpioCfgSocketPort Configure socket port +gpioCfgMemAlloc Configure DMA memory allocation mode +gpioCfgNetAddr Configure allowed network addresses + +gpioCfgInternals Configure misc. internals (DEPRECATED) +gpioCfgGetInternals Get internal configuration settings +gpioCfgSetInternals Set internal configuration settings + EXPERT rawWaveAddSPI Not intended for general use @@ -2878,9 +2900,18 @@ D*/ /*F*/ int bscXfer(bsc_xfer_t *bsc_xfer); /*D -This function provides a low-level interface to the -SPI/I2C Slave peripheral. This peripheral allows the -Pi to act as a slave device on an I2C or SPI bus. +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. This function is not available on the BCM2711 (e.g. as used in the Pi4B). @@ -2906,8 +2937,9 @@ typedef struct } bsc_xfer_t; . . -To start a transfer set control (see below) and copy the bytes to -be sent (if any) to txBuf and set the byte count in txCnt. +To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. Upon return rxCnt will be set to the number of received bytes placed in rxBuf. diff --git a/pigpio.py b/pigpio.py index 4da6171..0e2a0a1 100644 --- a/pigpio.py +++ b/pigpio.py @@ -95,41 +95,45 @@ the pigpio.pi class. OVERVIEW -Essential +ESSENTIAL pigpio.pi Initialise Pi connection stop Stop a Pi connection -Beginner +BASIC set_mode Set a GPIO mode get_mode Get a GPIO mode + set_pull_up_down Set/clear GPIO pull up/down resistor read Read a GPIO write Write a GPIO +PWM_(overrides_servo_commands_on_same_GPIO) + set_PWM_dutycycle Start/stop PWM pulses on a GPIO +set_PWM_frequency Set PWM frequency of a GPIO +set_PWM_range Configure PWM range of a GPIO + get_PWM_dutycycle Get PWM dutycycle set on a GPIO +get_PWM_frequency Get PWM frequency of a GPIO +get_PWM_range Get configured PWM range of a GPIO + +get_PWM_real_range Get underlying PWM range for a GPIO + +Servo_(overrides_PWM_commands_on_same_GPIO) set_servo_pulsewidth Start/Stop servo pulses on a GPIO -get_servo_pulsewidth Get servo pulsewidth set on a GPIO -callback Create GPIO level change callback -wait_for_edge Wait for GPIO level change +get_servo_pulsewidth Get servo pulsewidth set on a GPIO -Intermediate +INTERMEDIATE gpio_trigger Send a trigger pulse to a GPIO set_watchdog Set a watchdog on a GPIO -set_PWM_range Configure PWM range of a GPIO -get_PWM_range Get configured PWM range of a GPIO - -set_PWM_frequency Set PWM frequency of a GPIO -get_PWM_frequency Get PWM frequency of a GPIO - read_bank_1 Read all bank 1 GPIO read_bank_2 Read all bank 2 GPIO @@ -139,31 +143,42 @@ clear_bank_2 Clear selected GPIO in bank 2 set_bank_1 Set selected GPIO in bank 1 set_bank_2 Set selected GPIO in bank 2 -Advanced +callback Create GPIO level change callback -get_PWM_real_range Get underlying PWM range for a GPIO +wait_for_edge Wait for GPIO level change + +ADVANCED notify_open Request a notification handle notify_begin Start notifications for selected GPIO notify_pause Pause notifications notify_close Close a notification -bb_serial_read_open Open a GPIO for bit bang serial reads -bb_serial_read Read bit bang serial data from a GPIO -bb_serial_read_close Close a GPIO for bit bang serial reads -bb_serial_invert Invert serial logic (1 invert, 0 normal) - hardware_clock Start hardware clock on supported GPIO + hardware_PWM Start hardware PWM on supported GPIO set_glitch_filter Set a glitch filter on a GPIO set_noise_filter Set a noise filter on a GPIO -get_pad_strength Gets a pads drive strength set_pad_strength Sets a pads drive strength +get_pad_strength Gets a pads drive strength shell Executes a shell command +Custom + +custom_1 User custom function 1 +custom_2 User custom function 2 + +Events + +event_callback Sets a callback for an event + +event_trigger Triggers an event + +wait_for_event Wait for an event + Scripts store_script Store a script @@ -173,50 +188,24 @@ script_status Get script status and parameters stop_script Stop a running script delete_script Delete a stored script -Waves - -wave_clear Deletes all waveforms - -wave_add_new Starts a new waveform -wave_add_generic Adds a series of pulses to the waveform -wave_add_serial Adds serial data to the waveform - -wave_create Creates a waveform from added data -wave_delete Deletes a waveform - -wave_send_once Transmits a waveform once -wave_send_repeat Transmits a waveform repeatedly -wave_send_using_mode Transmits a waveform in the chosen mode - -wave_chain Transmits a chain of waveforms - -wave_tx_at Returns the current transmitting waveform -wave_tx_busy Checks to see if a waveform has ended -wave_tx_stop Aborts the current waveform - -wave_get_micros Length in microseconds of the current waveform -wave_get_max_micros Absolute maximum allowed micros -wave_get_pulses Length in pulses of the current waveform -wave_get_max_pulses Absolute maximum allowed pulses -wave_get_cbs Length in cbs of the current waveform -wave_get_max_cbs Absolute maximum allowed cbs - I2C i2c_open Opens an I2C device i2c_close Closes an I2C device i2c_write_quick SMBus write quick -i2c_write_byte SMBus write byte + i2c_read_byte SMBus read byte -i2c_write_byte_data SMBus write byte data -i2c_write_word_data SMBus write word data +i2c_write_byte SMBus write byte + i2c_read_byte_data SMBus read byte data +i2c_write_byte_data SMBus write byte data + i2c_read_word_data SMBus read word data -i2c_process_call SMBus process call -i2c_write_block_data SMBus write block data +i2c_write_word_data SMBus write word data + i2c_read_block_data SMBus read block data -i2c_block_process_call SMBus block process call +i2c_write_block_data SMBus write block data i2c_read_i2c_block_data SMBus read I2C block data i2c_write_i2c_block_data SMBus write I2C block data @@ -224,64 +213,105 @@ i2c_write_i2c_block_data SMBus write I2C block data i2c_read_device Reads the raw I2C device i2c_write_device Writes the raw I2C device +i2c_process_call SMBus process call +i2c_block_process_call SMBus block process call + i2c_zip Performs multiple I2C transactions +I2C_BIT_BANG + bb_i2c_open Opens GPIO for bit banging I2C bb_i2c_close Closes GPIO for bit banging I2C -bb_i2c_zip Performs multiple bit banged I2C transactions - -SPI - -spi_open Opens a SPI device -spi_close Closes a SPI device -spi_read Reads bytes from a SPI device -spi_write Writes bytes to a SPI device -spi_xfer Transfers bytes with a SPI device - -bb_spi_open Opens GPIO for bit banging SPI -bb_spi_close Closes GPIO for bit banging SPI -bb_spi_xfer Transfers bytes with bit banging SPI +bb_i2c_zip Performs multiple bit banged I2C transactions -I2C/SPI_Slave +I2C/SPI_SLAVE bsc_xfer I2C/SPI as slave transfer bsc_i2c I2C as slave transfer -Serial +SERIAL serial_open Opens a serial device serial_close Closes a serial device -serial_read Reads bytes from a serial device serial_read_byte Reads a byte from a serial device +serial_write_byte Writes a byte to a serial device +serial_read Reads bytes from a serial device serial_write Writes bytes to a serial device -serial_write_byte Writes a byte to a serial device serial_data_available Returns number of bytes ready to be read -Files +SERIAL_BIT_BANG_(read_only) + +bb_serial_read_open Open a GPIO for bit bang serial reads +bb_serial_read_close Close a GPIO for bit bang serial reads + +bb_serial_invert Invert serial logic (1 invert, 0 normal) + +bb_serial_read Read bit bang serial data from a GPIO + +SPI + +spi_open Opens a SPI device +spi_close Closes a SPI device + +spi_read Reads bytes from a SPI device +spi_write Writes bytes to a SPI device +spi_xfer Transfers bytes with a SPI device + +SPI_BIT_BANG + +bb_spi_open Opens GPIO for bit banging SPI +bb_spi_close Closes GPIO for bit banging SPI +bb_spi_xfer Transfers bytes with bit banging SPI + +FILES file_open Opens a file file_close Closes a file + file_read Reads bytes from a file file_write Writes bytes to a file + file_seek Seeks to a position within a file + file_list List files which match a pattern -Events +WAVES -event_callback Sets a callback for an event -event_trigger Triggers an event -wait_for_event Wait for an event +wave_clear Deletes all waveforms -Custom +wave_add_new Starts a new waveform +wave_add_generic Adds a series of pulses to the waveform +wave_add_serial Adds serial data to the waveform -custom_1 User custom function 1 -custom_2 User custom function 2 +wave_create Creates a waveform from added data +wave_delete Deletes a waveform + +wave_send_once Transmits a waveform once +wave_send_repeat Transmits a waveform repeatedly +wave_send_using_mode Transmits a waveform in the chosen mode + +wave_chain Transmits a chain of waveforms -Utility +wave_tx_at Returns the current transmitting waveform + +wave_tx_busy Checks to see if a waveform has ended + +wave_tx_stop Aborts the current waveform + +wave_get_cbs Length in cbs of the current waveform +wave_get_max_cbs Absolute maximum allowed cbs + +wave_get_micros Length in microseconds of the current waveform +wave_get_max_micros Absolute maximum allowed micros + +wave_get_pulses Length in pulses of the current waveform +wave_get_max_pulses Absolute maximum allowed pulses + +UTILITIES get_current_tick Get current tick (microseconds) @@ -300,7 +330,7 @@ import threading import os import atexit -VERSION = "1.44" +VERSION = "1.45" exceptions = True @@ -3514,9 +3544,18 @@ class pi(): def bsc_xfer(self, bsc_control, data): """ - This function provides a low-level interface to the - SPI/I2C Slave peripheral. This peripheral allows the - Pi to act as a slave device on an I2C or SPI bus. + This function provides a low-level interface to the SPI/I2C Slave + peripheral on the BCM chip. + + This peripheral allows the Pi to act as a hardware slave device + on an I2C or SPI bus. + + This is not a bit bang version and as such is OS timing + independent. The bus timing is handled directly by the chip. + + The output process is simple. You simply append data to the FIFO + buffer on the chip. This works like a queue, you add data to the + queue and the master removes it. This function is not available on the BCM2711 (e.g. as used in the Pi4B). diff --git a/pigpiod.1 b/pigpiod.1 index 1f7d3d1..f4a873c 100644 --- a/pigpiod.1 +++ b/pigpiod.1 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pigpiod.1 ." -.TH pigpiod 1 2012-2018 Linux "pigpio archive" +.TH pigpiod 1 2012-2019 Linux "pigpio archive" .SH NAME pigpiod - A utility to start the pigpio library as a daemon. diff --git a/pigpiod_if.3 b/pigpiod_if.3 index c079c78..272113a 100644 --- a/pigpiod_if.3 +++ b/pigpiod_if.3 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pigpiod_if.3 ." -.TH pigpiod_if 3 2012-2018 Linux "pigpio archive" +.TH pigpiod_if 3 2012-2019 Linux "pigpio archive" .SH NAME pigpiod_if - A C library to interface to the pigpio daemon. @@ -175,6 +175,342 @@ All the functions which return an int return < 0 on error .br +.br + +.SH OVERVIEW + +.br +.SS ESSENTIAL +.br + +.br +pigpio_start Connects to the pigpio daemon +.br +pigpio_stop Disconnects from the pigpio daemon +.br +.SS BEGINNER +.br + +.br +set_mode Set a GPIO mode +.br +get_mode Get a GPIO mode +.br + +.br +set_pull_up_down Set/clear GPIO pull up/down resistor +.br + +.br +gpio_read Read a GPIO +.br +gpio_write Write a GPIO +.br + +.br +set_PWM_dutycycle Start/stop PWM pulses on a GPIO +.br +get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +.br + +.br +set_servo_pulsewidth Start/stop servo pulses on a GPIO +.br +get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO +.br + +.br +callback Create GPIO level change callback +.br +callback_ex Create GPIO level change callback +.br +callback_cancel Cancel a callback +.br +wait_for_edge Wait for GPIO level change +.br +.SS INTERMEDIATE +.br + +.br +gpio_trigger Send a trigger pulse to a GPIO. +.br + +.br +set_watchdog Set a watchdog on a GPIO. +.br + +.br +set_PWM_range Configure PWM range for a GPIO +.br +get_PWM_range Get configured PWM range for a GPIO +.br + +.br +set_PWM_frequency Configure PWM frequency for a GPIO +.br +get_PWM_frequency Get configured PWM frequency for a GPIO +.br + +.br +read_bank_1 Read all GPIO in bank 1 +.br +read_bank_2 Read all GPIO in bank 2 +.br + +.br +clear_bank_1 Clear selected GPIO in bank 1 +.br +clear_bank_2 Clear selected GPIO in bank 2 +.br + +.br +set_bank_1 Set selected GPIO in bank 1 +.br +set_bank_2 Set selected GPIO in bank 2 +.br + +.br +start_thread Start a new thread +.br +stop_thread Stop a previously started thread +.br +.SS ADVANCED +.br + +.br +get_PWM_real_range Get underlying PWM range for a GPIO +.br + +.br +notify_open Request a notification handle +.br +notify_begin Start notifications for selected GPIO +.br +notify_pause Pause notifications +.br +notify_close Close a notification +.br + +.br +bb_serial_read_open Opens a GPIO for bit bang serial reads +.br +bb_serial_read Reads bit bang serial data from a GPIO +.br +bb_serial_read_close Closes a GPIO for bit bang serial reads +.br +bb_serial_invert Invert serial logic (1 invert, 0 normal) +.br + +.br +hardware_clock Start hardware clock on supported GPIO +.br +hardware_PWM Start hardware PWM on supported GPIO +.br + +.br +set_glitch_filter Set a glitch filter on a GPIO +.br +set_noise_filter Set a noise filter on a GPIO +.br +.SS SCRIPTS +.br + +.br +store_script Store a script +.br +run_script Run a stored script +.br +script_status Get script status and parameters +.br +stop_script Stop a running script +.br +delete_script Delete a stored script +.br +.SS WAVES +.br + +.br +wave_clear Deletes all waveforms +.br + +.br +wave_add_new Starts a new waveform +.br +wave_add_generic Adds a series of pulses to the waveform +.br +wave_add_serial Adds serial data to the waveform +.br + +.br +wave_create Creates a waveform from added data +.br +wave_delete Deletes one or more waveforms +.br + +.br +wave_send_once Transmits a waveform once +.br +wave_send_repeat Transmits a waveform repeatedly +.br + +.br +wave_chain Transmits a chain of waveforms +.br + +.br +wave_tx_busy Checks to see if the waveform has ended +.br +wave_tx_stop Aborts the current waveform +.br + +.br +wave_get_micros Length in microseconds of the current waveform +.br +wave_get_high_micros Length of longest waveform so far +.br +wave_get_max_micros Absolute maximum allowed micros +.br + +.br +wave_get_pulses Length in pulses of the current waveform +.br +wave_get_high_pulses Length of longest waveform so far +.br +wave_get_max_pulses Absolute maximum allowed pulses +.br + +.br +wave_get_cbs Length in cbs of the current waveform +.br +wave_get_high_cbs Length of longest waveform so far +.br +wave_get_max_cbs Absolute maximum allowed cbs +.br +.SS I2C +.br + +.br +i2c_open Opens an I2C device +.br +i2c_close Closes an I2C device +.br + +.br +i2c_write_quick smbus write quick +.br +i2c_write_byte smbus write byte +.br +i2c_read_byte smbus read byte +.br +i2c_write_byte_data smbus write byte data +.br +i2c_write_word_data smbus write word data +.br +i2c_read_byte_data smbus read byte data +.br +i2c_read_word_data smbus read word data +.br +i2c_process_call smbus process call +.br +i2c_write_block_data smbus write block data +.br +i2c_read_block_data smbus read block data +.br +i2c_block_process_call smbus block process call +.br + +.br +i2c_write_i2c_block_data smbus write I2C block data +.br +i2c_read_i2c_block_data smbus read I2C block data +.br + +.br +i2c_read_device Reads the raw I2C device +.br +i2c_write_device Writes the raw I2C device +.br + +.br +i2c_zip Performs multiple I2C transactions +.br + +.br +bb_i2c_open Opens GPIO for bit banging I2C +.br +bb_i2c_close Closes GPIO for bit banging I2C +.br +bb_i2c_zip Performs multiple bit banged I2C transactions +.br +.SS SPI +.br + +.br +spi_open Opens a SPI device +.br +spi_close Closes a SPI device +.br + +.br +spi_read Reads bytes from a SPI device +.br +spi_write Writes bytes to a SPI device +.br +spi_xfer Transfers bytes with a SPI device +.br +.SS SERIAL +.br + +.br +serial_open Opens a serial device +.br +serial_close Closes a serial device +.br + +.br +serial_write_byte Writes a byte to a serial device +.br +serial_read_byte Reads a byte from a serial device +.br +serial_write Writes bytes to a serial device +.br +serial_read Reads bytes from a serial device +.br + +.br +serial_data_available Returns number of bytes ready to be read +.br +.SS CUSTOM +.br + +.br +custom_1 User custom function 1 +.br +custom_2 User custom function 2 +.br +.SS UTILITIES +.br + +.br +get_current_tick Get current tick (microseconds) +.br + +.br +get_hardware_revision Get hardware revision +.br +get_pigpio_version Get the pigpio version +.br +pigpiod_if_version Get the pigpiod_if version +.br + +.br +pigpio_error Get a text description of an error code. +.br + +.br +time_sleep Sleeps for a float number of seconds +.br +time_time Float number of seconds since the epoch .br .SH FUNCTIONS diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index 2354d88..6b52a7d 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pigpiod_if2.3 ." -.TH pigpiod_if2 3 2012-2018 Linux "pigpio archive" +.TH pigpiod_if2 3 2012-2019 Linux "pigpio archive" .SH NAME pigpiod_if2 - A C library to interface to the pigpio daemon. @@ -169,6 +169,456 @@ All the functions which return an int return < 0 on error .br +.br + +.SH OVERVIEW + +.br +.SS ESSENTIAL +.br + +.br +pigpio_start Connects to a pigpio daemon +.br +pigpio_stop Disconnects from a pigpio daemon +.br +.SS BASIC +.br + +.br +set_mode Set a GPIO mode +.br +get_mode Get a GPIO mode +.br + +.br +set_pull_up_down Set/clear GPIO pull up/down resistor +.br + +.br +gpio_read Read a GPIO +.br +gpio_write Write a GPIO +.br +.SS PWM (overrides servo commands on same GPIO) +.br + +.br +set_PWM_dutycycle Start/stop PWM pulses on a GPIO +.br +set_PWM_frequency Configure PWM frequency for a GPIO +.br +set_PWM_range Configure PWM range for a GPIO +.br + +.br +get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +.br +get_PWM_frequency Get configured PWM frequency for a GPIO +.br +get_PWM_range Get configured PWM range for a GPIO +.br + +.br +get_PWM_real_range Get underlying PWM range for a GPIO +.br +.SS Servo (overrides PWM commands on same GPIO) +.br + +.br +set_servo_pulsewidth Start/stop servo pulses on a GPIO +.br + +.br +get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO +.br +.SS INTERMEDIATE +.br + +.br +gpio_trigger Send a trigger pulse to a GPIO. +.br + +.br +set_watchdog Set a watchdog on a GPIO. +.br + +.br +read_bank_1 Read all GPIO in bank 1 +.br +read_bank_2 Read all GPIO in bank 2 +.br + +.br +clear_bank_1 Clear selected GPIO in bank 1 +.br +clear_bank_2 Clear selected GPIO in bank 2 +.br + +.br +set_bank_1 Set selected GPIO in bank 1 +.br +set_bank_2 Set selected GPIO in bank 2 +.br + +.br +callback Create GPIO level change callback +.br +callback_ex Create GPIO level change callback, extended +.br + +.br +callback_cancel Cancel a callback +.br + +.br +wait_for_edge Wait for GPIO level change +.br + +.br +start_thread Start a new thread +.br +stop_thread Stop a previously started thread +.br +.SS ADVANCED +.br + +.br +notify_open Request a notification handle +.br +notify_begin Start notifications for selected GPIO +.br +notify_pause Pause notifications +.br +notify_close Close a notification +.br + +.br +hardware_clock Start hardware clock on supported GPIO +.br + +.br +hardware_PWM Start hardware PWM on supported GPIO +.br + +.br +set_glitch_filter Set a glitch filter on a GPIO +.br +set_noise_filter Set a noise filter on a GPIO +.br + +.br +set_pad_strength Sets a pads drive strength +.br +get_pad_strength Gets a pads drive strength +.br + +.br +shell_ Executes a shell command +.br +.SS Custom +.br + +.br +custom_1 User custom function 1 +.br +custom_2 User custom function 2 +.br +.SS Events +.br + +.br +event_callback Sets a callback for an event +.br +event_callback_ex Sets a callback for an event, extended +.br + +.br +event_callback_cancel Cancel an event callback +.br + +.br +event_trigger Triggers an event +.br + +.br +wait_for_event Wait for an event +.br +.SS Scripts +.br + +.br +store_script Store a script +.br +run_script Run a stored script +.br +update_script Set a scripts parameters +.br +script_status Get script status and parameters +.br +stop_script Stop a running script +.br +delete_script Delete a stored script +.br +.SS I2C +.br + +.br +i2c_open Opens an I2C device +.br +i2c_close Closes an I2C device +.br + +.br +i2c_write_quick smbus write quick +.br + +.br +i2c_read_byte smbus read byte +.br +i2c_write_byte smbus write byte +.br + +.br +i2c_read_byte_data smbus read byte data +.br +i2c_write_byte_data smbus write byte data +.br + +.br +i2c_read_word_data smbus read word data +.br +i2c_write_word_data smbus write word data +.br + +.br +i2c_read_block_data smbus read block data +.br +i2c_write_block_data smbus write block data +.br + +.br +i2c_read_i2c_block_data smbus read I2C block data +.br +i2c_write_i2c_block_data smbus write I2C block data +.br + +.br +i2c_read_device Reads the raw I2C device +.br +i2c_write_device Writes the raw I2C device +.br + +.br +i2c_process_call smbus process call +.br +i2c_block_process_call smbus block process call +.br + +.br +i2c_zip Performs multiple I2C transactions +.br +.SS I2C BIT BANG +.br + +.br +bb_i2c_open Opens GPIO for bit banging I2C +.br +bb_i2c_close Closes GPIO for bit banging I2C +.br + +.br +bb_i2c_zip Performs bit banged I2C transactions +.br +.SS I2C/SPI SLAVE +.br + +.br +bsc_xfer I2C/SPI as slave transfer +.br +bsc_i2c I2C as slave transfer +.br +.SS SERIAL +.br + +.br +serial_open Opens a serial device +.br +serial_close Closes a serial device +.br + +.br +serial_read_byte Reads a byte from a serial device +.br +serial_write_byte Writes a byte to a serial device +.br + +.br +serial_read Reads bytes from a serial device +.br +serial_write Writes bytes to a serial device +.br + +.br +serial_data_available Returns number of bytes ready to be read +.br +.SS SERIAL BIT BANG (read only) +.br + +.br +bb_serial_read_open Opens a GPIO for bit bang serial reads +.br +bb_serial_read_close Closes a GPIO for bit bang serial reads +.br + +.br +bb_serial_invert Invert serial logic (1 invert, 0 normal) +.br + +.br +bb_serial_read Reads bit bang serial data from a GPIO +.br +.SS SPI +.br + +.br +spi_open Opens a SPI device +.br +spi_close Closes a SPI device +.br + +.br +spi_read Reads bytes from a SPI device +.br +spi_write Writes bytes to a SPI device +.br +spi_xfer Transfers bytes with a SPI device +.br +.SS SPI BIT BANG +.br + +.br +bb_spi_open Opens GPIO for bit banging SPI +.br +bb_spi_close Closes GPIO for bit banging SPI +.br + +.br +bb_spi_xfer Transfers bytes with bit banging SPI +.br +.SS FILES +.br + +.br +file_open Opens a file +.br +file_close Closes a file +.br + +.br +file_read Reads bytes from a file +.br +file_write Writes bytes to a file +.br + +.br +file_seek Seeks to a position within a file +.br + +.br +file_list List files which match a pattern +.br +.SS WAVES +.br + +.br +wave_clear Deletes all waveforms +.br + +.br +wave_add_new Starts a new waveform +.br +wave_add_generic Adds a series of pulses to the waveform +.br +wave_add_serial Adds serial data to the waveform +.br + +.br +wave_create Creates a waveform from added data +.br +wave_delete Deletes one or more waveforms +.br + +.br +wave_send_once Transmits a waveform once +.br +wave_send_repeat Transmits a waveform repeatedly +.br +wave_send_using_mode Transmits a waveform in the chosen mode +.br + +.br +wave_chain Transmits a chain of waveforms +.br + +.br +wave_tx_at Returns the current transmitting waveform +.br + +.br +wave_tx_busy Checks to see if the waveform has ended +.br + +.br +wave_tx_stop Aborts the current waveform +.br + +.br +wave_get_cbs Length in cbs of the current waveform +.br +wave_get_high_cbs Length of longest waveform so far +.br +wave_get_max_cbs Absolute maximum allowed cbs +.br + +.br +wave_get_micros Length in micros of the current waveform +.br +wave_get_high_micros Length of longest waveform so far +.br +wave_get_max_micros Absolute maximum allowed micros +.br + +.br +wave_get_pulses Length in pulses of the current waveform +.br +wave_get_high_pulses Length of longest waveform so far +.br +wave_get_max_pulses Absolute maximum allowed pulses +.br +.SS UTILITIES +.br + +.br +get_current_tick Get current tick (microseconds) +.br + +.br +get_hardware_revision Get hardware revision +.br +get_pigpio_version Get the pigpio version +.br +pigpiod_if_version Get the pigpiod_if2 version +.br + +.br +pigpio_error Get a text description of an error code. +.br + +.br +time_sleep Sleeps for a float number of seconds +.br +time_time Float number of seconds since the epoch .br .SH FUNCTIONS @@ -5598,9 +6048,27 @@ The function returns 1 if the edge occurred, otherwise 0. .IP "\fBint bsc_xfer(int pi, bsc_xfer_t *bscxfer)\fP" .IP "" 4 -This function provides a low-level interface to the -SPI/I2C Slave peripheral. This peripheral allows the -Pi to act as a slave device on an I2C or SPI bus. +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +.br + +.br +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +.br + +.br +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +.br + +.br +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. .br @@ -5655,8 +6123,9 @@ typedef struct .br .br -To start a transfer set control (see below) and copy the bytes to -be sent (if any) to txBuf and set the byte count in txCnt. +To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. .br diff --git a/pigpiod_if2.c b/pigpiod_if2.c index cd343c0..6854d65 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 15 */ +/* PIGPIOD_IF2_VERSION 16 */ #include #include diff --git a/pigpiod_if2.h b/pigpiod_if2.h index b63dbc7..fb214df 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF2_VERSION 15 +#define PIGPIOD_IF2_VERSION 16 /*TEXT @@ -104,7 +104,7 @@ ESSENTIAL pigpio_start Connects to a pigpio daemon pigpio_stop Disconnects from a pigpio daemon -BEGINNER +BASIC set_mode Set a GPIO mode get_mode Get a GPIO mode @@ -114,16 +114,23 @@ set_pull_up_down Set/clear GPIO pull up/down resistor gpio_read Read a GPIO gpio_write Write a GPIO +PWM_(overrides_servo_commands_on_same_GPIO) + set_PWM_dutycycle Start/stop PWM pulses on a GPIO +set_PWM_frequency Configure PWM frequency for a GPIO +set_PWM_range Configure PWM range for a GPIO + get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +get_PWM_frequency Get configured PWM frequency for a GPIO +get_PWM_range Get configured PWM range for a GPIO + +get_PWM_real_range Get underlying PWM range for a GPIO + +Servo_(overrides_PWM_commands_on_same_GPIO) set_servo_pulsewidth Start/stop servo pulses on a GPIO -get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -callback Create GPIO level change callback -callback_ex Create GPIO level change callback, extended -callback_cancel Cancel a callback -wait_for_edge Wait for GPIO level change +get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO INTERMEDIATE @@ -131,12 +138,6 @@ gpio_trigger Send a trigger pulse to a GPIO. set_watchdog Set a watchdog on a GPIO. -set_PWM_range Configure PWM range for a GPIO -get_PWM_range Get configured PWM range for a GPIO - -set_PWM_frequency Configure PWM frequency for a GPIO -get_PWM_frequency Get configured PWM frequency for a GPIO - read_bank_1 Read all GPIO in bank 1 read_bank_2 Read all GPIO in bank 2 @@ -146,75 +147,59 @@ clear_bank_2 Clear selected GPIO in bank 2 set_bank_1 Set selected GPIO in bank 1 set_bank_2 Set selected GPIO in bank 2 +callback Create GPIO level change callback +callback_ex Create GPIO level change callback, extended + +callback_cancel Cancel a callback + +wait_for_edge Wait for GPIO level change + start_thread Start a new thread stop_thread Stop a previously started thread ADVANCED -get_PWM_real_range Get underlying PWM range for a GPIO - notify_open Request a notification handle notify_begin Start notifications for selected GPIO notify_pause Pause notifications notify_close Close a notification -bb_serial_read_open Opens a GPIO for bit bang serial reads -bb_serial_read Reads bit bang serial data from a GPIO -bb_serial_read_close Closes a GPIO for bit bang serial reads -bb_serial_invert Invert serial logic (1 invert, 0 normal) - hardware_clock Start hardware clock on supported GPIO + hardware_PWM Start hardware PWM on supported GPIO set_glitch_filter Set a glitch filter on a GPIO set_noise_filter Set a noise filter on a GPIO -get_pad_strength Gets a pads drive strength set_pad_strength Sets a pads drive strength +get_pad_strength Gets a pads drive strength shell_ Executes a shell command -SCRIPTS - -store_script Store a script -run_script Run a stored script -update_script Set a scripts parameters -script_status Get script status and parameters -stop_script Stop a running script -delete_script Delete a stored script - -WAVES +Custom -wave_clear Deletes all waveforms - -wave_add_new Starts a new waveform -wave_add_generic Adds a series of pulses to the waveform -wave_add_serial Adds serial data to the waveform +custom_1 User custom function 1 +custom_2 User custom function 2 -wave_create Creates a waveform from added data -wave_delete Deletes one or more waveforms +Events -wave_send_once Transmits a waveform once -wave_send_repeat Transmits a waveform repeatedly -wave_send_using_mode Transmits a waveform in the chosen mode +event_callback Sets a callback for an event +event_callback_ex Sets a callback for an event, extended -wave_chain Transmits a chain of waveforms +event_callback_cancel Cancel an event callback -wave_tx_at Returns the current transmitting waveform -wave_tx_busy Checks to see if the waveform has ended -wave_tx_stop Aborts the current waveform +event_trigger Triggers an event -wave_get_micros Length in microseconds of the current waveform -wave_get_high_micros Length of longest waveform so far -wave_get_max_micros Absolute maximum allowed micros +wait_for_event Wait for an event -wave_get_pulses Length in pulses of the current waveform -wave_get_high_pulses Length of longest waveform so far -wave_get_max_pulses Absolute maximum allowed pulses +Scripts -wave_get_cbs Length in cbs of the current waveform -wave_get_high_cbs Length of longest waveform so far -wave_get_max_cbs Absolute maximum allowed cbs +store_script Store a script +run_script Run a stored script +update_script Set a scripts parameters +script_status Get script status and parameters +stop_script Stop a running script +delete_script Delete a stored script I2C @@ -222,41 +207,36 @@ i2c_open Opens an I2C device i2c_close Closes an I2C device i2c_write_quick smbus write quick -i2c_write_byte smbus write byte + i2c_read_byte smbus read byte -i2c_write_byte_data smbus write byte data -i2c_write_word_data smbus write word data +i2c_write_byte smbus write byte + i2c_read_byte_data smbus read byte data +i2c_write_byte_data smbus write byte data + i2c_read_word_data smbus read word data -i2c_process_call smbus process call -i2c_write_block_data smbus write block data +i2c_write_word_data smbus write word data + i2c_read_block_data smbus read block data -i2c_block_process_call smbus block process call +i2c_write_block_data smbus write block data -i2c_write_i2c_block_data smbus write I2C block data i2c_read_i2c_block_data smbus read I2C block data +i2c_write_i2c_block_data smbus write I2C block data i2c_read_device Reads the raw I2C device i2c_write_device Writes the raw I2C device +i2c_process_call smbus process call +i2c_block_process_call smbus block process call + i2c_zip Performs multiple I2C transactions +I2C_BIT_BANG + bb_i2c_open Opens GPIO for bit banging I2C bb_i2c_close Closes GPIO for bit banging I2C -bb_i2c_zip Performs multiple bit banged I2C transactions -SPI - -spi_open Opens a SPI device -spi_close Closes a SPI device - -spi_read Reads bytes from a SPI device -spi_write Writes bytes to a SPI device -spi_xfer Transfers bytes with a SPI device - -bb_spi_open Opens GPIO for bit banging SPI -bb_spi_close Closes GPIO for bit banging SPI -bb_spi_xfer Transfers bytes with bit banging SPI +bb_i2c_zip Performs bit banged I2C transactions I2C/SPI_SLAVE @@ -268,34 +248,85 @@ SERIAL serial_open Opens a serial device serial_close Closes a serial device -serial_write_byte Writes a byte to a serial device serial_read_byte Reads a byte from a serial device -serial_write Writes bytes to a serial device +serial_write_byte Writes a byte to a serial device + serial_read Reads bytes from a serial device +serial_write Writes bytes to a serial device serial_data_available Returns number of bytes ready to be read +SERIAL_BIT_BANG_(read_only) + +bb_serial_read_open Opens a GPIO for bit bang serial reads +bb_serial_read_close Closes a GPIO for bit bang serial reads + +bb_serial_invert Invert serial logic (1 invert, 0 normal) + +bb_serial_read Reads bit bang serial data from a GPIO + +SPI + +spi_open Opens a SPI device +spi_close Closes a SPI device + +spi_read Reads bytes from a SPI device +spi_write Writes bytes to a SPI device +spi_xfer Transfers bytes with a SPI device + +SPI_BIT_BANG + +bb_spi_open Opens GPIO for bit banging SPI +bb_spi_close Closes GPIO for bit banging SPI + +bb_spi_xfer Transfers bytes with bit banging SPI + FILES file_open Opens a file file_close Closes a file + file_read Reads bytes from a file file_write Writes bytes to a file + file_seek Seeks to a position within a file + file_list List files which match a pattern -EVENTS +WAVES -event_callback Sets a callback for an event -event_callback_ex Sets a callback for an event, extended -event_callback_cancel Cancel an event callback -event_trigger Triggers an event -wait_for_event Wait for an event +wave_clear Deletes all waveforms -CUSTOM +wave_add_new Starts a new waveform +wave_add_generic Adds a series of pulses to the waveform +wave_add_serial Adds serial data to the waveform -custom_1 User custom function 1 -custom_2 User custom function 2 +wave_create Creates a waveform from added data +wave_delete Deletes one or more waveforms + +wave_send_once Transmits a waveform once +wave_send_repeat Transmits a waveform repeatedly +wave_send_using_mode Transmits a waveform in the chosen mode + +wave_chain Transmits a chain of waveforms + +wave_tx_at Returns the current transmitting waveform + +wave_tx_busy Checks to see if the waveform has ended + +wave_tx_stop Aborts the current waveform + +wave_get_cbs Length in cbs of the current waveform +wave_get_high_cbs Length of longest waveform so far +wave_get_max_cbs Absolute maximum allowed cbs + +wave_get_micros Length in micros of the current waveform +wave_get_high_micros Length of longest waveform so far +wave_get_max_micros Absolute maximum allowed micros + +wave_get_pulses Length in pulses of the current waveform +wave_get_high_pulses Length of longest waveform so far +wave_get_max_pulses Absolute maximum allowed pulses UTILITIES @@ -3398,9 +3429,18 @@ D*/ /*F*/ int bsc_xfer(int pi, bsc_xfer_t *bscxfer); /*D -This function provides a low-level interface to the -SPI/I2C Slave peripheral. This peripheral allows the -Pi to act as a slave device on an I2C or SPI bus. +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. This function is not available on the BCM2711 (e.g. as used in the Pi4B). @@ -3427,8 +3467,9 @@ typedef struct } bsc_xfer_t; . . -To start a transfer set control (see below) and copy the bytes to -be sent (if any) to txBuf and set the byte count in txCnt. +To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. Upon return rxCnt will be set to the number of received bytes placed in rxBuf. diff --git a/pigs.1 b/pigs.1 index 3926b64..81ccfee 100644 --- a/pigs.1 +++ b/pigs.1 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii foo.1 ." -.TH pigs 1 2012-2018 Linux "pigpio archive" +.TH pigs 1 2012-2019 Linux "pigpio archive" .SH NAME pigs - command line socket access to the pigpio daemon. @@ -28,8 +28,8 @@ or .br -The socket and pipe interfaces allow control of the GPIO by passing -messages to the running pigpio library. +The socket and pipe interfaces allow control of the Pi's GPIO by +passing messages to the running pigpio library. .br The normal way to start the pigpio library would be as a daemon during boot. @@ -42,10 +42,6 @@ sudo pigpiod .EE -.br -pigs is a program and internally uses the socket interface to pigpio -whereas /dev/pigpio uses the pipe interface. - .br .SS Features .br @@ -80,7 +76,11 @@ ALL GPIO are identified by their Broadcom number. .br .SS Usage .br -pigs and the socket interface share the same commands and are invoked in +pigs is a program and internally uses the socket interface to pigpio +whereas /dev/pigpio uses the pipe interface. + +.br +pigs and the pipe interface share the same commands and are invoked in a similar fashion from the command line. .br @@ -242,6 +242,372 @@ $ pigs -x slr 4 100 .br +.SH OVERVIEW +.SS BASIC +.B M/MODES g m +Set GPIO mode +.P +.B MG/MODEG g +Get GPIO mode +.P +.B PUD g p +Set GPIO pull up/down +.P +.B R/READ g +Read GPIO level +.P +.B W/WRITE g L +Write GPIO level +.P +.SS PWM (overrides servo commands on same GPIO) +.B P/PWM u v +Set GPIO PWM value +.P +.B PFS u v +Set GPIO PWM frequency +.P +.B PRS u v +Set GPIO PWM range +.P +.B GDC u +Get GPIO PWM dutycycle +.P +.B PFG u +Get GPIO PWM frequency +.P +.B PRG u +Get GPIO PWM range +.P +.B PRRG u +Get GPIO PWM real range +.P +.SS Servo (overrides PWM commands on same GPIO) +.B S/SERVO u v +Set GPIO servo pulsewidth +.P +.B GPW u +Get GPIO servo pulsewidth +.P +.SS INTERMEDIATE +.B TRIG u pl L +Send a trigger pulse +.P +.B WDOG u v +Set GPIO watchdog +.P +.B BR1 +Read bank 1 GPIO +.P +.B BR2 +Read bank 2 GPIO +.P +.B BC1 bits +Clear specified GPIO in bank 1 +.P +.B BC2 bits +Clear specified GPIO in bank 2 +.P +.B BS1 bits +Set specified GPIO in bank 1 +.P +.B BS2 bits +Set specified GPIO in bank 2 +.P +.SS ADVANCED +.B NO +Request a notification +.P +.B NC h +Close notification +.P +.B NB h bits +Start notification +.P +.B NP h +Pause notification +.P +.B HC g cf +Set hardware clock frequency +.P +.B HP g pf pdc +Set hardware PWM frequency and dutycycle +.P +.B FG u stdy +Set a glitch filter on a GPIO +.P +.B FN u stdy actv +Set a noise filter on a GPIO +.P +.B PADS pad padma +Set pad drive strength +.P +.B PADG pad +Get pad drive strength +.P +.B SHELL name str +Execute a shell command +.P +.SS Custom +.B CF1 uvs +Custom function 1 +.P +.B CF2 uvs +Custom function 2 +.P +.SS Events +.B EVM h bits +Set events to monitor +.P +.B EVT event +Trigger event +.P +.SS Scripts +.B PROC t +Store script +.P +.B PROCR sid pars +Run script +.P +.B PROCU sid pars +Set script parameters +.P +.B PROCP sid +Get script status and parameters +.P +.B PROCS sid +Stop script +.P +.B PROCD sid +Delete script +.P +.B PARSE t +Validate script +.P +.SS I2C +.B I2CO ib id if +Open I2C bus and device with flags +.P +.B I2CC h +Close I2C handle +.P +.B I2CWQ h bit +smb Write Quick: write bit +.P +.B I2CRS h +smb Read Byte: read byte +.P +.B I2CWS h bv +smb Write Byte: write byte +.P +.B I2CRB h r +smb Read Byte Data: read byte from register +.P +.B I2CWB h r bv +smb Write Byte Data: write byte to register +.P +.B I2CRW h r +smb Read Word Data: read word from register +.P +.B I2CWW h r wv +smb Write Word Data: write word to register +.P +.B I2CRK h r +smb Read Block Data: read data from register +.P +.B I2CWK h r bvs +smb Write Block Data: write data to register +.P +.B I2CWI h r bvs +smb Write I2C Block Data +.P +.B I2CRI h r num +smb Read I2C Block Data: read bytes from register +.P +.B I2CRD h num +i2c Read device +.P +.B I2CWD h bvs +i2c Write device +.P +.B I2CPC h r wv +smb Process Call: exchange register with word +.P +.B I2CPK h r bvs +smb Block Process Call: exchange data bytes with register +.P +.B I2CZ h bvs +Performs multiple I2C transactions +.P +.SS I2C BIT BANG +.B BI2CO sda scl b +Open bit bang I2C +.P +.B BI2CC sda +Close bit bang I2C +.P +.B BI2CZ sda bvs +I2C bit bang multiple transactions +.P +.SS I2C/SPI SLAVE +.B BSCX bctl bvs +BSC I2C/SPI transfer +.P +.SS SERIAL +.B SERO dev b sef +Open serial device dev at baud b with flags +.P +.B SERC h +Close serial handle +.P +.B SERRB +Read byte from serial handle +.P +.B SERWB h bv +Write byte to serial handle +.P +.B SERR h num +Read bytes from serial handle +.P +.B SERW h bvs +Write bytes to serial handle +.P +.B SERDA h +Check for serial data ready to read +.P +.SS SERIAL BIT BANG (read only) +.B SLRO u b db +Open GPIO for bit bang serial data +.P +.B SLRC u +Close GPIO for bit bang serial data +.P +.B SLRI u v +Sets bit bang serial data logic levels +.P +.B SLR u num +Read bit bang serial data from GPIO +.P +.SS SPI +.B SPIO c b spf +SPI open channel at baud b with flags +.P +.B SPIC h +SPI close handle +.P +.B SPIR h num +SPI read bytes from handle +.P +.B SPIW h bvs +SPI write bytes to handle +.P +.B SPIX h bvs +SPI transfer bytes to handle +.P +.SS SPI BIT BANG +.B BSPIO cs miso mosi sclk b spf +Open bit bang SPI +.P +.B BSPIC cs +Close bit bang SPI +.P +.B BSPIX cs bvs +SPI bit bang transfer +.P +.SS FILES +.B FO file mode +Open a file in mode +.P +.B FC h +Close file handle +.P +.B FR h num +Read bytes from file handle +.P +.B FW h bvs +Write bytes to file handle +.P +.B FS h num from +Seek to file handle position +.P +.B FL pat num +List files which match pattern +.P +.SS WAVES +.B WVCLR +Clear all waveforms +.P +.B WVNEW +Initialise a new waveform +.P +.B WVAG trips +Add generic pulses to waveform +.P +.B WVAS u b db sb o bvs +Add serial data to waveform +.P +.B WVCRE +Create a waveform +.P +.B WVDEL wid +Delete selected waveform +.P +.B WVTX wid +Transmits waveform once +.P +.B WVTXM wid wmde +Transmits waveform using mode +.P +.B WVTXR wid +Transmits waveform repeatedly +.P +.B WVCHA bvs +Transmits a chain of waveforms +.P +.B WVTAT +Returns the current transmitting waveform +.P +.B WVBSY +Check if waveform is being transmitted +.P +.B WVHLT +Stop waveform +.P +.B WVSC ws +Get waveform DMA CB stats +.P +.B WVSM ws +Get waveform time stats +.P +.B WVSP ws +Get waveform pulse stats +.P +.SS UTILITIES +.B H/HELP +Display command help +.P +.B HWVER +Get hardware version +.P +.B MICS v +Microseconds delay +.P +.B MILS v +Milliseconds delay +.P +.B PIGPV +Get pigpio library version +.P +.B T/TICK +Get current tick +.P +.SS CONFIGURATION +.B CGI +Configuration get internals +.P +.B CSI v +Configuration set internals +.P + .SH COMMANDS .br @@ -542,6 +908,23 @@ ERROR: no permission to update one or more GPIO This command performs a BSC I2C/SPI slave transfer as defined by \fBbctl\fP with data \fBbvs\fP. +.br +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +.br +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +.br +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +.br +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. + .br This function is not available on the BCM2711 (e.g. as used in the Pi4B). @@ -1974,7 +2357,7 @@ $ pigs i2crb 0 0 .br -.IP "\fBI2CRD h num\fP - i2c Read bytes" +.IP "\fBI2CRD h num\fP - i2c Read device" .IP "" 4 .br @@ -2146,7 +2529,7 @@ $ pigs i2cwb 0 10 0x54 .br -.IP "\fBI2CWD h bvs\fP - i2c Write data" +.IP "\fBI2CWD h bvs\fP - i2c Write device" .IP "" 4 .br diff --git a/setup.py b/setup.py index 2b5505c..00f70a0 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.44', + version='1.45', author='joan', author_email='joan@abyz.me.uk', maintainer='joan', -- cgit v1.2.3 From 6b770ad8109b434c733702600d91f21bdf6870b0 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Wed, 27 Nov 2019 21:25:35 +0000 Subject: V71+: #268 obey host name setting with env vars --- pigpio.h | 4 ++-- pigpiod_if2.c | 50 +++++++++++++++++++++----------------------------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/pigpio.h b/pigpio.h index 7d8df6a..0010fd8 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7103 +#define PIGPIO_VERSION 7104 /*TEXT @@ -6491,7 +6491,7 @@ after this command is issued. #define PI_DEFAULT_DMA_NOT_SET 15 #define PI_DEFAULT_SOCKET_PORT 8888 #define PI_DEFAULT_SOCKET_PORT_STR "8888" -#define PI_DEFAULT_SOCKET_ADDR_STR "127.0.0.1" +#define PI_DEFAULT_SOCKET_ADDR_STR "localhost" #define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL #define PI_DEFAULT_UPDATE_MASK_B1 0x03E7CF93 #define PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC7CF9C diff --git a/pigpiod_if2.c b/pigpiod_if2.c index 6854d65..36f01aa 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -234,33 +234,10 @@ static int pigpio_command_ext return cmd.res; } -static int pigpioOpenSocket(char *addr, char *port) +static int pigpioOpenSocket(char *addrStr, char *portStr) { int sock, err, opt; struct addrinfo hints, *res, *rp; - const char *addrStr, *portStr; - - if (!addr) - { - addrStr = getenv(PI_ENVADDR); - - if ((!addrStr) || (!strlen(addrStr))) - { - addrStr = PI_DEFAULT_SOCKET_ADDR_STR; - } - } - else addrStr = addr; - - if (!port) - { - portStr = getenv(PI_ENVPORT); - - if ((!portStr) || (!strlen(portStr))) - { - portStr = PI_DEFAULT_SOCKET_PORT_STR; - } - } - else portStr = port; memset (&hints, 0, sizeof (hints)); @@ -713,11 +690,6 @@ int pigpio_start(char *addrStr, char *portStr) int pi; int *userdata; - if ((!addrStr) || (strlen(addrStr) == 0)) - { - addrStr = "localhost"; - } - for (pi=0; pi Date: Fri, 29 Nov 2019 23:20:19 +0000 Subject: V71+: rewrite chooseBestClock to fix errors --- pigpio.c | 54 ++++++++++++++++++------------------------------------ pigpio.h | 2 +- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/pigpio.c b/pigpio.c index da91ace..cf855e6 100644 --- a/pigpio.c +++ b/pigpio.c @@ -5087,51 +5087,33 @@ int serDataAvailable(unsigned handle) static int chooseBestClock (clkInf_t *clkInf, unsigned f, unsigned numc, unsigned *cf) { - int c, valid, offby, offby2, best_offby; - uint32_t div; - uint64_t frac; + int c, valid; + double fdiv, offby, best_offby; + unsigned div, frac; valid = 0; best_offby = 0; for (c=0; c 1) && (div < 4096)) { - if (f < PI_MASH_MAX_FREQ) - { - frac = cf[c] - (div * f); - frac = (frac * 4096) / f; - offby = cf[c] - (div * f) - ((frac * f) / 4096); - if (frac < 4095) - { - offby2 = cf[c] - (div * f) - (((frac+1) * f) / 4096); - if (offby2 < 0) offby2 = -offby2; - if (offby2 < offby) - { - offby = offby2; - frac++; - } - } - } - else - { - frac = 0; - offby = cf[c] - (div * f); - if (div < 4095) - { - offby2 = cf[c] - ((div+1) * f); - if (offby2 < 0) offby2 = -offby2; - if (offby2 < offby) - { - offby = offby2; - div++; - } - } - } - + offby = f - (cf[c] / (div + (frac / 4096.0))); + if (offby < 0) offby = - offby; if ((!valid) || (offby <= best_offby)) { valid = 1; diff --git a/pigpio.h b/pigpio.h index 0010fd8..b143c40 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7104 +#define PIGPIO_VERSION 7105 /*TEXT -- cgit v1.2.3 From b634058746efaded8b70e2d66b17ada1f7532fbb Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sat, 30 Nov 2019 18:17:04 +0000 Subject: V72 --- pigpio.3 | 2 +- pigpio.c | 2 +- pigpio.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pigpio.3 b/pigpio.3 index b8f6789..c30730a 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -10964,7 +10964,7 @@ A 16-bit word value. .br #define PI_DEFAULT_SOCKET_PORT_STR "8888" .br -#define PI_DEFAULT_SOCKET_ADDR_STR "127.0.0.1" +#define PI_DEFAULT_SOCKET_ADDR_STR "localhost" .br #define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL .br diff --git a/pigpio.c b/pigpio.c index cf855e6..2d80aed 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 71+ */ +/* pigpio version 72 */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index b143c40..44b3ba5 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7105 +#define PIGPIO_VERSION 72 /*TEXT -- cgit v1.2.3 From 1788961a9bd57a0915091d9874e45b2cbac4e990 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Sat, 21 Dec 2019 11:07:05 -0500 Subject: Fix broken close handling --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 2d80aed..c9688ba 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13582,8 +13582,8 @@ unsigned gpioHardwareRevision(void) } } } + fclose(filp); } - fclose(filp); } if (rev == 0) -- cgit v1.2.3 From fb0ffc20e7759403ace4c54c282e5116571c0c7f Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Wed, 1 Jan 2020 20:48:41 -0600 Subject: Create SUPPORT.md (#2) --- SUPPORT.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 SUPPORT.md diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000..c9a5eda --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,8 @@ +Questions about the pigpio library are welcome but we ask that you check these resources first: +* [pigpio library web page](http://abyz.me.uk/rpi/pigpio) +Noobs should start with the FAQ. All +APIs are documented extensively. +* Search the repository issues with a 'question' label +For example, to search for information on PWM type in search box: +`label:question pwm` +* Check the repository's Wiki - WIP, help wanted. -- cgit v1.2.3 From 8f279023a40e76c74bfec319177df0de51916624 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Wed, 1 Jan 2020 20:49:16 -0600 Subject: Create CONTRIBUTING.md (#1) * Create CONTRIBUTING.md * Update CONTRIBUTING.md --- CONTRIBUTING.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..fae6d5f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,21 @@ +## Submitting a New Issue +If you are reporting a **bug** or defect, please provide the steps to reproduce the problem you are describing. +Ideally, provide a simple script that will reproduce the issue. Also provide a description of the hardware and +software types and versions used in your application/test environment. + +Requests for a feature or **enhancement** to the library software will be treated at a lower priority due to the lack +of resources (contributors with skillset, knowledge of the library or time). Unless your request has wide support +from the community it will be treated at a low priority. If the repo's maintainer judges your request to be of value +then it will be labeled `enhancement`. If additional resources are required, it will be tagged with `help wanted`. + +If you simply have a **question**, consult the SUPPORT.md document. + +## Creating a Pull Request +Contributions are welcome. To save time it is best to have an open issue relating to what it is you want to contribute +and to discuss the prospects of getting your contribution accepted. + +Your changes *must* pass the set of test files `x_*`. Please indicate that you have run the test scripts successfuly or attach +a screen shot of the output from the test scripts. + +In addition, you *should* provide updated or additional scripts that at least test the 'happy' paths of your code changes. For +larger changes the additional test cases will be considered mandatory. -- cgit v1.2.3 From 12a1fc5a2a3eacbdb1a0e00f9565429f2a81afe0 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Thu, 2 Jan 2020 15:01:43 +0000 Subject: V72+: new year --- pig2vcd.1 | 2 +- pigpio.3 | 2 +- pigpiod.1 | 2 +- pigpiod_if.3 | 2 +- pigpiod_if2.3 | 2 +- pigs.1 | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pig2vcd.1 b/pig2vcd.1 index 2ad95ae..eacce19 100644 --- a/pig2vcd.1 +++ b/pig2vcd.1 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pig2vcd.1 ." -.TH pig2vcd 1 2012-2019 Linux "pigpio archive" +.TH pig2vcd 1 2012-2020 Linux "pigpio archive" .SH NAME pig2vd - A utility to convert pigpio notifications to VCD. diff --git a/pigpio.3 b/pigpio.3 index c30730a..e218ed1 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pigpio.3 ." -.TH pigpio 3 2012-2019 Linux "pigpio archive" +.TH pigpio 3 2012-2020 Linux "pigpio archive" .SH NAME pigpio - A C library to manipulate the Pi's GPIO. diff --git a/pigpiod.1 b/pigpiod.1 index f4a873c..29f8326 100644 --- a/pigpiod.1 +++ b/pigpiod.1 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pigpiod.1 ." -.TH pigpiod 1 2012-2019 Linux "pigpio archive" +.TH pigpiod 1 2012-2020 Linux "pigpio archive" .SH NAME pigpiod - A utility to start the pigpio library as a daemon. diff --git a/pigpiod_if.3 b/pigpiod_if.3 index 272113a..a0ec196 100644 --- a/pigpiod_if.3 +++ b/pigpiod_if.3 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pigpiod_if.3 ." -.TH pigpiod_if 3 2012-2019 Linux "pigpio archive" +.TH pigpiod_if 3 2012-2020 Linux "pigpio archive" .SH NAME pigpiod_if - A C library to interface to the pigpio daemon. diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index 6b52a7d..1c9291c 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii pigpiod_if2.3 ." -.TH pigpiod_if2 3 2012-2019 Linux "pigpio archive" +.TH pigpiod_if2 3 2012-2020 Linux "pigpio archive" .SH NAME pigpiod_if2 - A C library to interface to the pigpio daemon. diff --git a/pigs.1 b/pigs.1 index 81ccfee..3b5d30b 100644 --- a/pigs.1 +++ b/pigs.1 @@ -2,7 +2,7 @@ ." Process this file with ." groff -man -Tascii foo.1 ." -.TH pigs 1 2012-2019 Linux "pigpio archive" +.TH pigs 1 2012-2020 Linux "pigpio archive" .SH NAME pigs - command line socket access to the pigpio daemon. -- cgit v1.2.3 From da780491d9a7d5cec8cad680c0e219a360d3f4dc Mon Sep 17 00:00:00 2001 From: joan2937 Date: Thu, 2 Jan 2020 15:04:54 +0000 Subject: V73: I2C_SLOTS to 512 (from 64) --- pigpio.c | 2 +- pigpio.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pigpio.c b/pigpio.c index c9688ba..24fe287 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 72 */ +/* pigpio version 73 */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index 44b3ba5..b6547e3 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 72 +#define PIGPIO_VERSION 73 /*TEXT @@ -702,7 +702,7 @@ typedef void *(gpioThreadFunc_t) (void *); /* Files, I2C, SPI, SER */ #define PI_FILE_SLOTS 16 -#define PI_I2C_SLOTS 64 +#define PI_I2C_SLOTS 512 #define PI_SPI_SLOTS 32 #define PI_SER_SLOTS 16 -- cgit v1.2.3 From d1fb6b9272d1aa8ac57d1200a50f50d7b2d4717a Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Wed, 8 Jan 2020 12:09:15 -0600 Subject: Update pigpiod.service Closes #210 --- util/pigpiod.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/pigpiod.service b/util/pigpiod.service index b1d28a6..a0bb916 100644 --- a/util/pigpiod.service +++ b/util/pigpiod.service @@ -2,7 +2,7 @@ Description=Pigpio daemon [Service] -Type=simple +Type=forking ExecStart=/usr/bin/pigpiod [Install] -- cgit v1.2.3 From 4b2a1efdab378fc9831a5a9e48de3291bf83634b Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Fri, 10 Jan 2020 00:32:24 -0600 Subject: Add 'develop' branch model process. --- CONTRIBUTING.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fae6d5f..a698a89 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,3 +19,40 @@ a screen shot of the output from the test scripts. In addition, you *should* provide updated or additional scripts that at least test the 'happy' paths of your code changes. For larger changes the additional test cases will be considered mandatory. + +Beginning 2020, this repo will follow a dual branch model: `master` is the stable branch that people use in production. A second branch, `develop`, is the first branch to receive merges from bug fixes and new features. Only after we consider `develop` stable we merge it into the `master` branch and release the changes with a tagged version. + +Adhering to the following process is the best way to get your work included in the project: + +- Fork the project, clone your fork, and configure the remotes: +``` +# Clone your fork of the repo into the current directory +git clone https://github.com//pigio.git + +# Navigate to the newly cloned directory +cd pigpio + +# Assign the original repo to a remote called "upstream" +git remote add upstream https://github.com/joan2937/pigpio.git +``` +- If you cloned a while ago, get the latest changes from upstream: +``` +git checkout develop +git pull upstream develop +``` +- Create a new topic branch (off the develop branch) to contain your feature, change, or fix: +``` +git checkout -b +``` +- Commit your changes. + +- Locally merge (or rebase) the upstream dev branch into your topic branch: +``` +git pull [--rebase] upstream develop +``` +- Push your topic branch up to your fork: +``` +git push origin +``` +- Open a Pull Request with a clear title and description. See [creating a pull request from a fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork). +Make sure the base branch drop down menu is selecting 'develop'. -- cgit v1.2.3 From 5c1f52215d083830802eff439e1f23d6c0c02651 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Fri, 10 Jan 2020 00:50:53 -0600 Subject: setsockopt() with properly initialized option argument. Fixes issue #298 and possibly #274. --- pigpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index 24fe287..b8a7531 100644 --- a/pigpio.c +++ b/pigpio.c @@ -8292,7 +8292,7 @@ int initInitialise(void) } server6.sin6_port = htons(port); - int opt; + int opt = 1; setsockopt(fdSock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); if (bind(fdSock,(struct sockaddr *)&server6, sizeof(server6)) < 0) SOFT_ERROR(PI_INIT_FAILED, "bind to port %d failed (%m)", port); @@ -8307,7 +8307,7 @@ int initInitialise(void) SOFT_ERROR(PI_INIT_FAILED, "socket failed (%m)"); else { - int opt; + int opt = 1; setsockopt(fdSock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); } server.sin_family = AF_INET; -- cgit v1.2.3 From 714136afe45635c37b0eb45986d261c644810aa5 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Fri, 17 Jan 2020 09:23:58 -0600 Subject: New hardware revision decode Decode hardware revision from either: 1) 'revision' string in /proc/cpuinfo (legacy) 2) binary number in /proc/device-tree/system/linux,revision The second path is recommended by raspberrypi.org for newer operating systems. See raspberrypi/linux#2110 --- pigpio.c | 246 +++++++++++++++++++++++++++++---------------------------------- pigpio.h | 2 +- 2 files changed, 113 insertions(+), 135 deletions(-) diff --git a/pigpio.c b/pigpio.c index b8a7531..15dab59 100644 --- a/pigpio.c +++ b/pigpio.c @@ -8159,7 +8159,8 @@ static void initReleaseResources(void) int initInitialise(void) { - int rev, i, model; + int i; + unsigned rev, model; struct sockaddr_in server; struct sockaddr_in6 server6; char * portStr; @@ -8207,13 +8208,27 @@ int initInitialise(void) 7=Unknown 8=Pi3B 9=Zero + 12=Zero W + 13=Pi3B+ + 14=Pi3A+ + 17=Pi4B */ if (model < 2) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2; else if (model < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; else if (model == 4) gpioMask = PI_DEFAULT_UPDATE_MASK_PI2B; - else if (model == 6) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; - else if (model == 8) gpioMask = PI_DEFAULT_UPDATE_MASK_PI3B; - else if (model == 9) gpioMask = PI_DEFAULT_UPDATE_MASK_ZERO; + + else if (model == 6 + || model ==10 + || model ==16) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; + + else if (model == 8 + || model ==13 + || model ==14) gpioMask = PI_DEFAULT_UPDATE_MASK_PI3B; + + else if (model == 9 + || model ==12) gpioMask = PI_DEFAULT_UPDATE_MASK_ZERO; + + else if (model ==17) gpioMask = PI_DEFAULT_UPDATE_MASK_PI4B; else gpioMask = PI_DEFAULT_UPDATE_MASK_UNKNOWN; } @@ -13431,13 +13446,14 @@ W warranty void if either bit is set S 0=old (bits 0-22 are revision number) 1=new (following fields apply) -M 0=256 1=512 2=1024 +M 0=256 1=512 2=1024 3=2GB 4=4GB -B 0=Sony 1=Egoman 2=Embest 3=Unknown 4=Embest +B 0=Sony 1=Egoman 2=Embest 3=Sony Japan 4=Embest 5=Stadium -P 0=2835, 1=2836, 2=2837 +P 0=2835, 1=2836, 2=2837 3=2711 -T 0=A 1=B 2=A+ 3=B+ 4=Pi2B 5=Alpha 6=Compute Module 7=Unknown 8=Pi3B 9=Zero +T 0=A 1=B 2=A+ 3=B+ 4=Pi2B 5=Alpha 6=CM1 8=Pi3B 9=Zero a=CM3 c=Zero W + d=3B+ e=3A+ 10=CM3+ 11=4B R PCB board revision @@ -13455,157 +13471,119 @@ unsigned gpioHardwareRevision(void) if (rev) return rev; - piCores = 0; - filp = fopen ("/proc/cpuinfo", "r"); + if (filp != NULL) { while (fgets(buf, sizeof(buf), filp) != NULL) { - if (piCores == 0) - { - if (!strncasecmp("model name", buf, 10)) - { - if (strstr (buf, "ARMv6") != NULL) - { - piCores = 1; - pi_peri_phys = 0x20000000; - pi_dram_bus = 0x40000000; - pi_mem_flag = 0x0C; - } - else if (strstr (buf, "ARMv7") != NULL) - { - piCores = 4; - pi_peri_phys = 0x3F000000; - pi_dram_bus = 0xC0000000; - pi_mem_flag = 0x04; - } - else if (strstr (buf, "ARMv8") != NULL) - { - piCores = 4; - pi_peri_phys = 0x3F000000; - pi_dram_bus = 0xC0000000; - pi_mem_flag = 0x04; - } - } - } - - if (!strncasecmp("hardware\t: BCM", buf, 14)) - { - int bcmno = atoi(buf+14); - if ((bcmno == 2708) || - (bcmno == 2709) || - (bcmno == 2710) || - (bcmno == 2835) || - (bcmno == 2836) || - (bcmno == 2837)) - { - pi_ispi = 1; - } - } - if (!strncasecmp("revision\t:", buf, 10)) { if (sscanf(buf+10, "%x%c", &rev, &term) == 2) { if (term != '\n') rev = 0; - else rev &= 0xFFFFFF; /* mask out warranty bit */ - switch (rev&0xFFF0) /* just interested in BCM model */ - { - case 0x3110: /* Pi4B */ - piCores = 4; - pi_peri_phys = 0xFE000000; - pi_dram_bus = 0xC0000000; - pi_mem_flag = 0x04; - pi_is_2711 = 1; - pi_ispi = 1; - clk_osc_freq = CLK_OSC_FREQ_2711; - clk_plld_freq = CLK_PLLD_FREQ_2711; - hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ_2711; - hw_clk_min_freq = PI_HW_CLK_MIN_FREQ_2711; - hw_clk_max_freq = PI_HW_CLK_MAX_FREQ_2711; - - fclose(filp); - if (!gpioMaskSet) - { - gpioMaskSet = 1; - gpioMask = PI_DEFAULT_UPDATE_MASK_PI4B; - } - return rev; - break; - } } } } - fclose(filp); + } - /* - Raspberry pi 3 running arm64 don't put all the - information we need in /proc/cpuinfo, but we can - get it elsewhere. - */ + /* (some) arm64 operating systems get revision number here */ - if (!pi_ispi) + if (rev == 0) + { + DBG(DBG_USER, "searching /proc/device-tree for revision"); + filp = fopen ("/proc/device-tree/system/linux,revision", "r"); + + if (filp != NULL) { - filp = fopen ("/proc/device-tree/model", "r"); - if (filp != NULL) + uint32_t tmp; + if (fread(&tmp,1 , 4, filp) == 4) { - if (fgets(buf, sizeof(buf), filp) != NULL) - { - if (!strncmp("Raspberry Pi 3", buf, 14)) - { - pi_ispi = 1; - piCores = 4; - pi_peri_phys = 0x3F000000; - pi_dram_bus = 0xC0000000; - pi_mem_flag = 0x04; - } - else if (!strncmp("Raspberry Pi 4 Model B", buf, 22)) - { - pi_ispi = 1; - piCores = 4; - pi_peri_phys = 0xFE000000; - pi_dram_bus = 0xC0000000; - pi_mem_flag = 0x04; - pi_is_2711 = 1; - clk_osc_freq = CLK_OSC_FREQ_2711; - clk_plld_freq = CLK_PLLD_FREQ_2711; - hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ_2711; - hw_clk_min_freq = PI_HW_CLK_MIN_FREQ_2711; - hw_clk_max_freq = PI_HW_CLK_MAX_FREQ_2711; - if (!gpioMaskSet) - { - gpioMaskSet = 1; - gpioMask = PI_DEFAULT_UPDATE_MASK_PI4B; - } - } - } - fclose(filp); + /* + for some reason the value returned by reading + this /proc entry seems to be big endian, + convert it. + */ + rev = ntohl(tmp); + rev &= 0xFFFFFF; /* mask out warranty bit */ } } + fclose(filp); + } - if (rev == 0) + piCores = 0; + pi_ispi = 0; + rev &= 0xFFFFFF; /* mask out warranty bit */ + + /* Decode revision code */ + + if ((rev & 0x800000) == 0) /* old rev code */ + { + if (rev < 16) /* all BCM2835 */ { - filp = fopen ("/proc/device-tree/system/linux,revision", "r"); - if (filp != NULL) - { - uint32_t tmp; - if (fread(&tmp,1 , 4, filp) == 4) - { - /* - for some reason the value returned by reading - this /proc entry seems to be big endian, - convert it. - */ - rev = ntohl(tmp); - rev &= 0xFFFFFF; /* mask out warranty bit */ - } - } - fclose(filp); + pi_ispi = 1; + piCores = 1; + pi_peri_phys = 0x20000000; + pi_dram_bus = 0x40000000; + pi_mem_flag = 0x0C; + } + else + { + DBG(DBG_ALWAYS, "unknown revision=%x", rev); + rev = 0; + } + } + else /* new rev code */ + { + switch ((rev >> 12) & 0xF) /* just interested in BCM model */ + { + + case 0x0: /* BCM2835 */ + pi_ispi = 1; + piCores = 1; + pi_peri_phys = 0x20000000; + pi_dram_bus = 0x40000000; + pi_mem_flag = 0x0C; + break; + + case 0x1: /* BCM2836 */ + case 0x2: /* BCM2837 */ + pi_ispi = 1; + piCores = 4; + pi_peri_phys = 0x3F000000; + pi_dram_bus = 0xC0000000; + pi_mem_flag = 0x04; + break; + + case 0x3: /* BCM2711 */ + pi_ispi = 1; + piCores = 4; + pi_peri_phys = 0xFE000000; + pi_dram_bus = 0xC0000000; + pi_mem_flag = 0x04; + pi_is_2711 = 1; + clk_osc_freq = CLK_OSC_FREQ_2711; + clk_plld_freq = CLK_PLLD_FREQ_2711; + hw_pwm_max_freq = PI_HW_PWM_MAX_FREQ_2711; + hw_clk_min_freq = PI_HW_CLK_MIN_FREQ_2711; + hw_clk_max_freq = PI_HW_CLK_MAX_FREQ_2711; + break; + + default: + DBG(DBG_ALWAYS, "unknown rev code (%x)", rev); + rev=0; + pi_ispi = 0; + break; } } + + DBG(DBG_USER, "revision=%x", rev); + DBG(DBG_USER, "pi_peri_phys=%x", pi_peri_phys); + DBG(DBG_USER, "pi_dram_bus=%x", pi_dram_bus); + DBG(DBG_USER, "pi_mem_flag=%x", pi_mem_flag); + return rev; } diff --git a/pigpio.h b/pigpio.h index b6547e3..039a79f 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 73 +#define PIGPIO_VERSION 7301 /*TEXT -- cgit v1.2.3 From fc6e3df43817dce8c5d403f9b759c2f597ca4a6f Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sat, 18 Jan 2020 14:41:09 -0600 Subject: v7302: Fix range of 'old' rev codes --- pigpio.c | 2 +- pigpio.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index 15dab59..261e540 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13521,7 +13521,7 @@ unsigned gpioHardwareRevision(void) if ((rev & 0x800000) == 0) /* old rev code */ { - if (rev < 16) /* all BCM2835 */ + if (rev < 0x0016) /* all BCM2835 */ { pi_ispi = 1; piCores = 1; diff --git a/pigpio.h b/pigpio.h index 039a79f..5817460 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7301 +#define PIGPIO_VERSION 7302 /*TEXT -- cgit v1.2.3 From 47f3bf7ec9db0c89902b8b76b5229094e9641573 Mon Sep 17 00:00:00 2001 From: Phil Wright Date: Fri, 13 Jul 2018 00:04:09 +0000 Subject: v7303 Fix waveform length when merging pulses (#223) --- pigpio.c | 16 ++++++++++++++-- pigpio.h | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pigpio.c b/pigpio.c index 261e540..942a4cc 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 73 */ +/* pigpio version 7303 */ /* include ------------------------------------------------------- */ @@ -3242,7 +3242,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1) unsigned numIn2, numOut; - uint32_t tNow, tNext1, tNext2, tDelay; + uint32_t tNow, tNext1, tNext2, tDelay, tMax; rawWave_t *in2, *out; @@ -3253,6 +3253,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1) out = wf[1-wfcur]; tNow = 0; + tMax = 0; if (!numIn1) tNext1 = -1; else tNext1 = 0; if (!numIn2) tNext2 = -1; else tNext2 = 0; @@ -3275,6 +3276,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1) out[outPos].flags = in1[inPos1].flags; tNext1 = tNow + in1[inPos1].usDelay; ++inPos1; + if (tMax < tNext1) tMax = tNext1; } else if (tNext2 < tNext1) { @@ -3292,6 +3294,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1) out[outPos].flags = in2[inPos2].flags; tNext2 = tNow + in2[inPos2].usDelay; ++inPos2; + if (tMax < tNext2) tMax = tNext2; } else { @@ -3310,6 +3313,8 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1) tNext1 = tNow + in1[inPos1].usDelay; ++inPos1; tNext2 = tNow + in2[inPos2].usDelay; ++inPos2; + if (tMax < tNext1) tMax = tNext1; + if (tMax < tNext2) tMax = tNext2; } if (tNext1 <= tNext2) { tDelay = tNext1 - tNow; tNow = tNext1; } @@ -3342,6 +3347,13 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1) } + if (tNow < tMax) + { + /* extend previous delay */ + out[outPos-1].usDelay += (tMax - tNow); + tNow = tMax; + } + if ((outPos < numOut) && (outPos < level)) { wfStats.micros = tNow; diff --git a/pigpio.h b/pigpio.h index 5817460..f58373c 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7302 +#define PIGPIO_VERSION 7303 /*TEXT -- cgit v1.2.3 From d5dee1d0a55c78d0cb867abc6928cc810dcad3b7 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sat, 25 Jan 2020 21:40:36 -0600 Subject: Bump to v74 --- pigpio.c | 2 +- pigpio.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index 942a4cc..409b981 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 7303 */ +/* pigpio version 74 */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index f58373c..9f12497 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7303 +#define PIGPIO_VERSION 74 /*TEXT -- cgit v1.2.3 From 671adab8ad99629ac9b80dda4c9fabf47f0ecaf5 Mon Sep 17 00:00:00 2001 From: Marco Jassmann Date: Wed, 26 Feb 2020 12:29:55 +0100 Subject: Corrected constant name in spiClose from PI_I2C_CLOSED to PI_SPI_CLOSED --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 409b981..033213c 100644 --- a/pigpio.c +++ b/pigpio.c @@ -4768,7 +4768,7 @@ int spiClose(unsigned handle) if (spiInfo[handle].state != PI_SPI_OPENED) SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); - spiInfo[handle].state = PI_I2C_CLOSED; + spiInfo[handle].state = PI_SPI_CLOSED; if (!spiAnyOpen(spiInfo[handle].flags)) spiTerm(spiInfo[handle].flags); /* terminate on last close */ -- cgit v1.2.3 From 4753b0d37ce16e48685aceafb8dd5df87d5b5acf Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 1 Mar 2020 13:35:16 +0000 Subject: Code for BSC I2C/SPI slave on the BCM2711 (PI4B) Added documentation for callback usage --- pigpio.3 | 46 +++++++++++++++++++++------ pigpio.c | 57 +++++++++++++++++++++++++-------- pigpio.h | 32 ++++++++++++++----- pigpio.py | 60 +++++++++++++++++++++++++++-------- pigpiod_if2.3 | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++------- pigpiod_if2.c | 2 +- pigpiod_if2.h | 55 ++++++++++++++++++++++++++------ pigs.1 | 34 ++++++++++++++------ setup.py | 2 +- 9 files changed, 311 insertions(+), 77 deletions(-) diff --git a/pigpio.3 b/pigpio.3 index e218ed1..cd77e18 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -1682,6 +1682,15 @@ will be a latency. .br +.br +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use \fBgpioRead\fP. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. + +.br + .br The tick value is the time stamp of the sample in microseconds, see \fBgpioTick\fP for more details. @@ -4181,12 +4190,6 @@ queue and the master removes it. .br -.br -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - -.br - .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -4249,14 +4252,37 @@ that mode until a different control word is sent. .br .br -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +GPIO used for models other than those based on the BCM2711. + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 18 19 - - - - +.br +SPI - - 18 19 20 21 +.br + +.br + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 10 11 - - - - +.br +SPI - - 10 11 9 8 +.br .br .br -When a zero control word is received GPIO 18-21 will be reset +When a zero control word is received the used GPIO will be reset to INPUT mode. .br diff --git a/pigpio.c b/pigpio.c index 409b981..fe5fc04 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 74 */ +/* pigpio version 75 */ /* include ------------------------------------------------------- */ @@ -10730,35 +10730,69 @@ int bbI2CZip( void bscInit(int mode) { + int sda, scl, miso, ce; + bscsReg[BSC_CR]=0; /* clear device */ bscsReg[BSC_RSR]=0; /* clear underrun and overrun errors */ bscsReg[BSC_SLV]=0; /* clear I2C slave address */ bscsReg[BSC_IMSC]=0xf; /* mask off all interrupts */ bscsReg[BSC_ICR]=0x0f; /* clear all interrupts */ - gpioSetMode(BSC_SDA_MOSI, PI_ALT3); - gpioSetMode(BSC_SCL_SCLK, PI_ALT3); + if (pi_is_2711) + { + sda = BSC_SDA_MOSI_2711; + scl = BSC_SCL_SCLK_2711; + miso = BSC_MISO_2711; + ce = BSC_CE_N_2711; + } + else + { + sda = BSC_SDA_MOSI; + scl = BSC_SCL_SCLK; + miso = BSC_MISO; + ce = BSC_CE_N; + } + + gpioSetMode(sda, PI_ALT3); + gpioSetMode(scl, PI_ALT3); if (mode > 1) /* SPI uses all GPIO */ { - gpioSetMode(BSC_MISO, PI_ALT3); - gpioSetMode(BSC_CE_N, PI_ALT3); + gpioSetMode(miso, PI_ALT3); + gpioSetMode(ce, PI_ALT3); } } void bscTerm(int mode) { + int sda, scl, miso, ce; + bscsReg[BSC_CR] = 0; /* clear device */ bscsReg[BSC_RSR]=0; /* clear underrun and overrun errors */ bscsReg[BSC_SLV]=0; /* clear I2C slave address */ - gpioSetMode(BSC_SDA_MOSI, PI_INPUT); - gpioSetMode(BSC_SCL_SCLK, PI_INPUT); + if (pi_is_2711) + { + sda = BSC_SDA_MOSI_2711; + scl = BSC_SCL_SCLK_2711; + miso = BSC_MISO_2711; + ce = BSC_CE_N_2711; + } + else + { + sda = BSC_SDA_MOSI; + scl = BSC_SCL_SCLK; + miso = BSC_MISO; + ce = BSC_CE_N; + } + + gpioSetMode(sda, PI_INPUT); + gpioSetMode(scl, PI_INPUT); if (mode > 1) { - gpioSetMode(BSC_MISO, PI_INPUT); - gpioSetMode(BSC_CE_N, PI_INPUT); + gpioSetMode(miso, PI_INPUT); + gpioSetMode(ce, PI_INPUT); } } @@ -10778,9 +10812,6 @@ int bscXfer(bsc_xfer_t *xfer) CHECK_INITED; - if (pi_is_2711) - SOFT_ERROR(PI_NOT_ON_BCM2711, "SPI/BSC slave not available on BCM2711"); - eventAlert[PI_EVENT_BSC].ignore = 1; if (xfer->control) @@ -10794,7 +10825,7 @@ int bscXfer(bsc_xfer_t *xfer) if (mode > bscMode) { - bscInit(bscMode); + bscInit(mode); bscMode = mode; } } diff --git a/pigpio.h b/pigpio.h index 9f12497..e3eb97d 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 74 +#define PIGPIO_VERSION 7401 /*TEXT @@ -797,6 +797,11 @@ typedef void *(gpioThreadFunc_t) (void *); #define BSC_MISO 20 #define BSC_CE_N 21 +#define BSC_SDA_MOSI_2711 10 +#define BSC_SCL_SCLK_2711 11 +#define BSC_MISO_2711 9 +#define BSC_CE_N_2711 8 + /* Longest busy delay */ #define PI_MAX_BUSY_DELAY 100 @@ -1439,6 +1444,12 @@ once per level change since the last time the thread was activated. i.e. The active alert functions will get all level changes but there will be a latency. +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use [*gpioRead*]. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. + The tick value is the time stamp of the sample in microseconds, see [*gpioTick*] for more details. @@ -2913,9 +2924,6 @@ The output process is simple. You simply append data to the FIFO buffer on the chip. This works like a queue, you add data to the queue and the master removes it. -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -2947,11 +2955,19 @@ in rxBuf. Note that the control word sets the BSC mode. The BSC will stay in that mode until a different control word is sent. -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +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 GPIO 18-21 will be reset +When a zero control word is received the used GPIO will be reset to INPUT mode. The returned function value is the status of the transfer (see below). diff --git a/pigpio.py b/pigpio.py index 0e2a0a1..cfaf845 100644 --- a/pigpio.py +++ b/pigpio.py @@ -330,7 +330,7 @@ import threading import os import atexit -VERSION = "1.45" +VERSION = "1.46" exceptions = True @@ -3557,13 +3557,9 @@ class pi(): buffer on the chip. This works like a queue, you add data to the queue and the master removes it. - This function is not available on the BCM2711 (e.g. as - used in the Pi4B). - I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. - The function sets the BSC mode, writes any data in the transmit buffer to the BSC transmit FIFO, and copies any data in the BSC receive FIFO to the @@ -3580,12 +3576,19 @@ class pi(): Note that the control word sets the BSC mode. The BSC will stay in that mode until a different control word is sent. - The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) - in I2C mode and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), - and 21 (CE) in SPI mode. You need to swap MISO/MOSI - between master and slave. + GPIO used for models other than those based on the BCM2711. - When a zero control word is received GPIO 18-21 will be reset + @ 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 will be reset to INPUT mode. bsc_control consists of the following bits: @@ -3684,10 +3687,10 @@ class pi(): (and will contain the error code). Note that an i2c_address of 0 may be used to close - the BSC device and reassign the used GPIO (18/19) - as inputs. + the BSC device and reassign the used GPIO as inputs. - This example assumes GPIO 2/3 are connected to GPIO 18/19. + This example assumes GPIO 2/3 are connected to GPIO 18/19 + (GPIO 10/11 on the BCM2711). ... #!/usr/bin/env python @@ -4939,6 +4942,37 @@ class pi(): A GPIO may have multiple callbacks (although I can't think of a reason to do so). + The GPIO are sampled at a rate set when the pigpio daemon + is started (default 5 us). + + The number of samples per second is given in the following table. + + . . + samples + per sec + + 1 1,000,000 + 2 500,000 + sample 4 250,000 + rate 5 200,000 + (us) 8 125,000 + 10 100,000 + . . + + GPIO level changes shorter than the sample rate may be missed. + + The daemon software which generates the callbacks is triggered + 1000 times per second. The callbacks will be called once per + level change since the last time they were called. + i.e. The callbacks will get all level changes but there will + be a latency. + + If you want to track the level of more than one GPIO do so by + maintaining the state in the callback. Do not use [*read*]. + Remember the event that triggered the callback may have + happened several milliseconds before and the GPIO may have + changed level many times since then. + ... def cbf(gpio, level, tick): print(gpio, level, tick) diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index 1c9291c..33c55e9 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -5920,6 +5920,66 @@ tick 32 bit The number of microseconds since boot .EE +.br + +.br +The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). + +.br + +.br +The number of samples per second is given in the following table. + +.br + +.br + +.EX + samples +.br + per sec +.br + +.br + 1 1,000,000 +.br + 2 500,000 +.br +sample 4 250,000 +.br +rate 5 200,000 +.br +(us) 8 125,000 +.br + 10 100,000 +.br + +.EE + +.br + +.br +GPIO level changes shorter than the sample rate may be missed. + +.br + +.br +The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. + +.br + +.br +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use \fBgpio_read\fP. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. + .IP "\fBint callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP" .IP "" 4 This function initialises a new callback. @@ -6072,12 +6132,6 @@ queue and the master removes it. .br -.br -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - -.br - .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -6160,14 +6214,37 @@ that mode until a different control word is sent. .br .br -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +GPIO used for models other than those based on the BCM2711. + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 18 19 - - - - +.br +SPI - - 18 19 20 21 +.br + +.br + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 10 11 - - - - +.br +SPI - - 10 11 9 8 +.br .br .br -When a zero control word is received GPIO 18-21 will be reset +When a zero control word is received the used GPIO will be reset to INPUT mode. .br @@ -6390,8 +6467,7 @@ If there was an error the status will be less than zero .br Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO (18/19) -as inputs. +the BSC device and reassign the used GPIO as inputs. .IP "\fBint event_callback(int pi, unsigned event, evtCBFunc_t f)\fP" .IP "" 4 diff --git a/pigpiod_if2.c b/pigpiod_if2.c index 36f01aa..90fb5fb 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 16 */ +/* PIGPIOD_IF2_VERSION 17 */ #include #include diff --git a/pigpiod_if2.h b/pigpiod_if2.h index fb214df..8d6f132 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF2_VERSION 16 +#define PIGPIOD_IF2_VERSION 17 /*TEXT @@ -3352,6 +3352,37 @@ tick 32 bit The number of microseconds since boot WARNING: this wraps around from 4294967295 to 0 roughly every 72 minutes . . + +The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). + +The number of samples per second is given in the following table. + +. . + samples + per sec + + 1 1,000,000 + 2 500,000 +sample 4 250,000 +rate 5 200,000 +(us) 8 125,000 + 10 100,000 +. . + +GPIO level changes shorter than the sample rate may be missed. + +The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. + +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use [*gpio_read*]. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. D*/ /*F*/ @@ -3442,9 +3473,6 @@ The output process is simple. You simply append data to the FIFO buffer on the chip. This works like a queue, you add data to the queue and the master removes it. -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -3486,11 +3514,19 @@ less than requested if the FIFO already contained untransmitted data). Note that the control word sets the BSC mode. The BSC will stay in that mode until a different control word is sent. -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +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 GPIO 18-21 will be reset +When a zero control word is received the used GPIO will be reset to INPUT mode. control consists of the following bits. @@ -3598,8 +3634,7 @@ If there was an error the status will be less than zero (and will contain the error code). Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO (18/19) -as inputs. +the BSC device and reassign the used GPIO as inputs. D*/ /*F*/ diff --git a/pigs.1 b/pigs.1 index 3b5d30b..ca31392 100644 --- a/pigs.1 +++ b/pigs.1 @@ -925,10 +925,6 @@ The output process is simple. You simply append data to the FIFO buffer on the chip. This works like a queue, you add data to the queue and the master removes it. -.br -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -950,12 +946,31 @@ For I2C use a control word of (I2C address << 16) + 0x305. E.g. to talk as I2C slave with address 0x13 use 0x130305. .br -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +GPIO used for models other than those based on the BCM2711. + +.br + +.EX + SDA SCL MOSI SCLK MISO CE +I2C 18 19 - - - - +SPI - - 18 19 20 21 + +.EE + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.EX + SDA SCL MOSI SCLK MISO CE +I2C 10 11 - - - - +SPI - - 10 11 9 8 + +.EE .br -When a zero control word is received GPIO 18-21 will be reset +When a zero control word is received the used GPIO will be reset to INPUT mode. .br @@ -1031,7 +1046,8 @@ TB transmit busy .EE .br -This example assumes that GPIO 2/3 are connected to GPIO 18/19. +This example assumes that GPIO 2/3 are connected to GPIO 18/19 +(GPIO 10/11 on the BCM2711). .br diff --git a/setup.py b/setup.py index 00f70a0..023a2c4 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.45', + version='1.46', author='joan', author_email='joan@abyz.me.uk', maintainer='joan', -- cgit v1.2.3 From f4a4b9772f6d039d5026fa7348f09e557abe898c Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Tue, 3 Mar 2020 23:13:57 -0600 Subject: Wave create using fixed size CB, OOL --- command.c | 2 +- pigpio.c | 39 ++++++++++++++++++++++++++++++++++----- pigpio.h | 2 +- pigpio.py | 4 ++-- x_pigpio.c | 4 ++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/command.c b/command.c index 4a1da4d..0687057 100644 --- a/command.c +++ b/command.c @@ -201,7 +201,7 @@ cmdInfo_t cmdInfo[]= {PI_CMD_WVBSY, "WVBSY", 101, 2, 1}, // gpioWaveTxBusy {PI_CMD_WVCHA, "WVCHA", 197, 0, 0}, // gpioWaveChain {PI_CMD_WVCLR, "WVCLR", 101, 0, 1}, // gpioWaveClear - {PI_CMD_WVCRE, "WVCRE", 101, 2, 1}, // gpioWaveCreate + {PI_CMD_WVCRE, "WVCRE", 112, 2, 1}, // gpioWaveCreate {PI_CMD_WVDEL, "WVDEL", 112, 0, 1}, // gpioWaveDelete {PI_CMD_WVGO, "WVGO" , 101, 2, 0}, // gpioWaveTxStart {PI_CMD_WVGOR, "WVGOR", 101, 2, 0}, // gpioWaveTxStart diff --git a/pigpio.c b/pigpio.c index fe5fc04..45d274f 100644 --- a/pigpio.c +++ b/pigpio.c @@ -2432,7 +2432,7 @@ static int myDoCommand(uintptr_t *p, unsigned bufSize, char *buf) case PI_CMD_WVCLR: res = gpioWaveClear(); break; - case PI_CMD_WVCRE: res = gpioWaveCreate(); break; + case PI_CMD_WVCRE: res = gpioWaveCreate(p[1]); break; case PI_CMD_WVDEL: res = gpioWaveDelete(p[1]); break; @@ -2992,7 +2992,7 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) /* ----------------------------------------------------------------------- */ -static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) +static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, int size) { int botCB=*CB, botOOL=*BOOL, topOOL=*TOOL; @@ -3130,6 +3130,25 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) } } + /* pad the wave */ + botCB = *CB + NUM_WAVE_CBS / size - 1; + botOOL = *BOOL + NUM_WAVE_OOL / size - 1; + //topOOL = *TOOL - (NUM_WAVE_OOL / size / 8); + + /* link the last CB to end of wave */ + + p->next = waveCbPOadr(botCB); + + /* add dummy cb at end of DMA */ + + p = rawWaveCBAdr(botCB++); + p->info = NORMAL_DMA | DMA_DEST_IGNORE; + p->src = waveOOLPOadr(botOOL++); + p->dst = ((GPIO_BASE + (GPSET0*4)) & 0x00ffffff) | PI_PERI_BUS; + p->length = 4; + p->next = 0; + + if (p != NULL) { if (wave_mode == PI_WAVE_MODE_ONE_SHOT) @@ -9552,7 +9571,7 @@ int rawWaveAddSPI( /* ----------------------------------------------------------------------- */ -int gpioWaveCreate(void) +int gpioWaveCreate(int size) // Fix: Make variadic. { int i, wid; int numCB, numBOOL, numTOOL; @@ -9566,7 +9585,14 @@ int gpioWaveCreate(void) /* What resources are needed? */ - waveCBsOOLs(&numCB, &numBOOL, &numTOOL); + if (size == 0) + waveCBsOOLs(&numCB, &numBOOL, &numTOOL); + + else { + numCB = NUM_WAVE_CBS / size; + numBOOL = NUM_WAVE_OOL / size; + numTOOL = 0; // ignore TOOL, ie, no flags support + } wid = -1; @@ -9619,7 +9645,7 @@ int gpioWaveCreate(void) BOOL = waveInfo[wid].botOOL; TOOL = waveInfo[wid].topOOL; - wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL); + wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, size); /* Sanity check. */ @@ -9633,6 +9659,9 @@ int gpioWaveCreate(void) numTOOL, waveInfo[wid].topOOL-TOOL); } + DBG(DBG_USER, "Wave Stats: wid=%d CBs %d BOOL %d TOOL %d", wid, + numCB, numBOOL, numTOOL); + waveInfo[wid].deleted = 0; /* Consume waves. */ diff --git a/pigpio.h b/pigpio.h index e3eb97d..8930d12 100644 --- a/pigpio.h +++ b/pigpio.h @@ -1933,7 +1933,7 @@ D*/ /*F*/ -int gpioWaveCreate(void); +int gpioWaveCreate(int); /*D This function creates a waveform from the data provided by the prior calls to the [*gpioWaveAdd**] functions. Upon success a wave id diff --git a/pigpio.py b/pigpio.py index cfaf845..af63a19 100644 --- a/pigpio.py +++ b/pigpio.py @@ -2257,7 +2257,7 @@ class pi(): else: return 0 - def wave_create(self): + def wave_create(self, size): """ Creates a waveform from the data provided by the prior calls to the [*wave_add_**] functions. @@ -2302,7 +2302,7 @@ class pi(): wid = pi.wave_create() ... """ - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, 0, 0)) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, size, 0)) def wave_delete(self, wave_id): """ diff --git a/x_pigpio.c b/x_pigpio.c index cd15389..61b37c2 100644 --- a/x_pigpio.c +++ b/x_pigpio.c @@ -391,7 +391,7 @@ To the lascivious pleasing of a lute.\n\ e = gpioWaveAddGeneric(4, wf); CHECK(5, 2, e, 4, 0, "pulse, wave add generic"); - wid = gpioWaveCreate(); + wid = gpioWaveCreate(0); e = gpioWaveTxSend(wid, PI_WAVE_MODE_REPEAT); if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat"); else CHECK(5, 3, e, 19, 0, "wave tx repeat"); @@ -413,7 +413,7 @@ To the lascivious pleasing of a lute.\n\ e = gpioWaveAddSerial(GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT); CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial"); - wid = gpioWaveCreate(); + wid = gpioWaveCreate(0); e = gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT); if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start"); else CHECK(5, 8, e, 7116, 0, "wave tx start"); -- cgit v1.2.3 From 58c5ad756bb751fab80619ac89d19fbe8bbd8829 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Wed, 4 Mar 2020 01:25:01 -0600 Subject: Skip wave padding when size = 0 --- pigpio.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/pigpio.c b/pigpio.c index 45d274f..a2aeb66 100644 --- a/pigpio.c +++ b/pigpio.c @@ -3130,24 +3130,27 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, int size) } } - /* pad the wave */ - botCB = *CB + NUM_WAVE_CBS / size - 1; - botOOL = *BOOL + NUM_WAVE_OOL / size - 1; - //topOOL = *TOOL - (NUM_WAVE_OOL / size / 8); + if (size) + { + /* pad the wave */ - /* link the last CB to end of wave */ + botCB = *CB + NUM_WAVE_CBS / size - 1; + botOOL = *BOOL + NUM_WAVE_OOL / size - 1; + //topOOL = //Fix: Ignore topOOL, flags not supported. - p->next = waveCbPOadr(botCB); - - /* add dummy cb at end of DMA */ - - p = rawWaveCBAdr(botCB++); - p->info = NORMAL_DMA | DMA_DEST_IGNORE; - p->src = waveOOLPOadr(botOOL++); - p->dst = ((GPIO_BASE + (GPSET0*4)) & 0x00ffffff) | PI_PERI_BUS; - p->length = 4; - p->next = 0; + /* link the last CB to end of wave */ + + p->next = waveCbPOadr(botCB); + /* add dummy cb at end of DMA */ + + p = rawWaveCBAdr(botCB++); + p->info = NORMAL_DMA | DMA_DEST_IGNORE; + p->src = waveOOLPOadr(botOOL++); + p->dst = ((GPIO_BASE + (GPSET0*4)) & 0x00ffffff) | PI_PERI_BUS; + p->length = 4; + p->next = 0; + } if (p != NULL) { -- cgit v1.2.3 From 71fe78aac9389eb0d17349e0d3e90e406e0035da Mon Sep 17 00:00:00 2001 From: Jul3k Date: Thu, 5 Mar 2020 13:53:44 +0100 Subject: Added .so.* to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f67291c..4108796 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.o *.so +*.so.* *.pyc pig2vcd pigpiod -- cgit v1.2.3 From 773378fd24e1a8584613c0b3385f411caae9c7c2 Mon Sep 17 00:00:00 2001 From: Jul3k Date: Thu, 5 Mar 2020 14:02:26 +0100 Subject: Reverte added site paramezer in wave_create --- command.c | 2 +- pigpio.h | 2 +- pigpio.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/command.c b/command.c index 0687057..4a1da4d 100644 --- a/command.c +++ b/command.c @@ -201,7 +201,7 @@ cmdInfo_t cmdInfo[]= {PI_CMD_WVBSY, "WVBSY", 101, 2, 1}, // gpioWaveTxBusy {PI_CMD_WVCHA, "WVCHA", 197, 0, 0}, // gpioWaveChain {PI_CMD_WVCLR, "WVCLR", 101, 0, 1}, // gpioWaveClear - {PI_CMD_WVCRE, "WVCRE", 112, 2, 1}, // gpioWaveCreate + {PI_CMD_WVCRE, "WVCRE", 101, 2, 1}, // gpioWaveCreate {PI_CMD_WVDEL, "WVDEL", 112, 0, 1}, // gpioWaveDelete {PI_CMD_WVGO, "WVGO" , 101, 2, 0}, // gpioWaveTxStart {PI_CMD_WVGOR, "WVGOR", 101, 2, 0}, // gpioWaveTxStart diff --git a/pigpio.h b/pigpio.h index 8930d12..e3eb97d 100644 --- a/pigpio.h +++ b/pigpio.h @@ -1933,7 +1933,7 @@ D*/ /*F*/ -int gpioWaveCreate(int); +int gpioWaveCreate(void); /*D This function creates a waveform from the data provided by the prior calls to the [*gpioWaveAdd**] functions. Upon success a wave id diff --git a/pigpio.py b/pigpio.py index af63a19..cfaf845 100644 --- a/pigpio.py +++ b/pigpio.py @@ -2257,7 +2257,7 @@ class pi(): else: return 0 - def wave_create(self, size): + def wave_create(self): """ Creates a waveform from the data provided by the prior calls to the [*wave_add_**] functions. @@ -2302,7 +2302,7 @@ class pi(): wid = pi.wave_create() ... """ - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, size, 0)) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, 0, 0)) def wave_delete(self, wave_id): """ -- cgit v1.2.3 From b9b8eff3903f322f0ed3d70d7cbda7f153103ee4 Mon Sep 17 00:00:00 2001 From: Jul3k Date: Thu, 5 Mar 2020 16:37:23 +0100 Subject: Reverted size paramter fore wavecreate in x_pigpio.c --- x_pigpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x_pigpio.c b/x_pigpio.c index 61b37c2..cd15389 100644 --- a/x_pigpio.c +++ b/x_pigpio.c @@ -391,7 +391,7 @@ To the lascivious pleasing of a lute.\n\ e = gpioWaveAddGeneric(4, wf); CHECK(5, 2, e, 4, 0, "pulse, wave add generic"); - wid = gpioWaveCreate(0); + wid = gpioWaveCreate(); e = gpioWaveTxSend(wid, PI_WAVE_MODE_REPEAT); if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat"); else CHECK(5, 3, e, 19, 0, "wave tx repeat"); @@ -413,7 +413,7 @@ To the lascivious pleasing of a lute.\n\ e = gpioWaveAddSerial(GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT); CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial"); - wid = gpioWaveCreate(0); + wid = gpioWaveCreate(); e = gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT); if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start"); else CHECK(5, 8, e, 7116, 0, "wave tx start"); -- cgit v1.2.3 From 4ab125cfff720e48fe2d055fe27eb4b8fc415876 Mon Sep 17 00:00:00 2001 From: Jul3k Date: Thu, 5 Mar 2020 17:42:55 +0100 Subject: Added WaveCreatePad to API --- command.c | 3 ++- pigpio.c | 42 +++++------------------------------------- pigpio.h | 38 ++++++++++++++++++++++++++++++++++++++ pigpiod_if2.c | 3 +++ pigpiod_if2.h | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 38 deletions(-) diff --git a/command.c b/command.c index 4a1da4d..0170005 100644 --- a/command.c +++ b/command.c @@ -201,7 +201,8 @@ cmdInfo_t cmdInfo[]= {PI_CMD_WVBSY, "WVBSY", 101, 2, 1}, // gpioWaveTxBusy {PI_CMD_WVCHA, "WVCHA", 197, 0, 0}, // gpioWaveChain {PI_CMD_WVCLR, "WVCLR", 101, 0, 1}, // gpioWaveClear - {PI_CMD_WVCRE, "WVCRE", 101, 2, 1}, // gpioWaveCreate + {PI_CMD_WVCRE, "WVCRE", 101, 2, 1}, // gpioWaveCreate + {PI_CMD_WVCAP, "WVCAP", 112, 2, 1}, // gpioWaveCreatePad {PI_CMD_WVDEL, "WVDEL", 112, 0, 1}, // gpioWaveDelete {PI_CMD_WVGO, "WVGO" , 101, 2, 0}, // gpioWaveTxStart {PI_CMD_WVGOR, "WVGOR", 101, 2, 0}, // gpioWaveTxStart diff --git a/pigpio.c b/pigpio.c index a2aeb66..fe5fc04 100644 --- a/pigpio.c +++ b/pigpio.c @@ -2432,7 +2432,7 @@ static int myDoCommand(uintptr_t *p, unsigned bufSize, char *buf) case PI_CMD_WVCLR: res = gpioWaveClear(); break; - case PI_CMD_WVCRE: res = gpioWaveCreate(p[1]); break; + case PI_CMD_WVCRE: res = gpioWaveCreate(); break; case PI_CMD_WVDEL: res = gpioWaveDelete(p[1]); break; @@ -2992,7 +2992,7 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) /* ----------------------------------------------------------------------- */ -static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, int size) +static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) { int botCB=*CB, botOOL=*BOOL, topOOL=*TOOL; @@ -3130,28 +3130,6 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, int size) } } - if (size) - { - /* pad the wave */ - - botCB = *CB + NUM_WAVE_CBS / size - 1; - botOOL = *BOOL + NUM_WAVE_OOL / size - 1; - //topOOL = //Fix: Ignore topOOL, flags not supported. - - /* link the last CB to end of wave */ - - p->next = waveCbPOadr(botCB); - - /* add dummy cb at end of DMA */ - - p = rawWaveCBAdr(botCB++); - p->info = NORMAL_DMA | DMA_DEST_IGNORE; - p->src = waveOOLPOadr(botOOL++); - p->dst = ((GPIO_BASE + (GPSET0*4)) & 0x00ffffff) | PI_PERI_BUS; - p->length = 4; - p->next = 0; - } - if (p != NULL) { if (wave_mode == PI_WAVE_MODE_ONE_SHOT) @@ -9574,7 +9552,7 @@ int rawWaveAddSPI( /* ----------------------------------------------------------------------- */ -int gpioWaveCreate(int size) // Fix: Make variadic. +int gpioWaveCreate(void) { int i, wid; int numCB, numBOOL, numTOOL; @@ -9588,14 +9566,7 @@ int gpioWaveCreate(int size) // Fix: Make variadic. /* What resources are needed? */ - if (size == 0) - waveCBsOOLs(&numCB, &numBOOL, &numTOOL); - - else { - numCB = NUM_WAVE_CBS / size; - numBOOL = NUM_WAVE_OOL / size; - numTOOL = 0; // ignore TOOL, ie, no flags support - } + waveCBsOOLs(&numCB, &numBOOL, &numTOOL); wid = -1; @@ -9648,7 +9619,7 @@ int gpioWaveCreate(int size) // Fix: Make variadic. BOOL = waveInfo[wid].botOOL; TOOL = waveInfo[wid].topOOL; - wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, size); + wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL); /* Sanity check. */ @@ -9662,9 +9633,6 @@ int gpioWaveCreate(int size) // Fix: Make variadic. numTOOL, waveInfo[wid].topOOL-TOOL); } - DBG(DBG_USER, "Wave Stats: wid=%d CBs %d BOOL %d TOOL %d", wid, - numCB, numBOOL, numTOOL); - waveInfo[wid].deleted = 0; /* Consume waves. */ diff --git a/pigpio.h b/pigpio.h index e3eb97d..da29f1b 100644 --- a/pigpio.h +++ b/pigpio.h @@ -1986,6 +1986,43 @@ Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. D*/ +int gpioWaveCreatePad(int percent); +/*D +This function creates a waveform like wave_create but pads the consumed +resources. Where percent gives the percentage of the resources to use (in terms +of the theoretical maximum, not the current amount free). This allows the reuse +of deleted waves while a transmission is active. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. + +. . +pi: >=0 (as returned by [*pigpio_start*]). +. . + +The data provided by the [*wave_add_**] functions is consumed by this +function. + +As many waveforms may be created as there is space available. The +wave id is passed to [*wave_send_**] to specify the waveform to transmit. + +A usage would be the creation of two waves where one is filled while the other +is beeing transmitted. Each wave is assigned 50% of the available resources. +This buffer structure allows the transmission of infinite wave sequences. + +Step 1. [*wave_clear*] to clear all waveforms and added data. + +Step 2. [*wave_add_**] calls to supply the waveform data. + +Step 3. [*wave_create_and_pad*] to create a 50% padded waveform and get a unique id + +Step 4. [*wave_send_**] with the id of the waveform to transmit. + +Repeat steps 2-4 as needed always waiting for the active waveform to be transmitted +before marking it as deleted. + +Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +D*/ /*F*/ int gpioWaveDelete(unsigned wave_id); @@ -6271,6 +6308,7 @@ PARAMS*/ #define PI_CMD_EVT 116 #define PI_CMD_PROCU 117 +#define PI_CMD_WVCAP 118 /*DEF_E*/ diff --git a/pigpiod_if2.c b/pigpiod_if2.c index 90fb5fb..7af8313 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -953,6 +953,9 @@ int wave_add_serial( int wave_create(int pi) {return pigpio_command(pi, PI_CMD_WVCRE, 0, 0, 1);} +int wave_create_and_pad(int pi, int percent) + {return pigpio_command(pi, PI_CMD_WVCAP, percent, 0, 1);} + int wave_delete(int pi, unsigned wave_id) {return pigpio_command(pi, PI_CMD_WVDEL, wave_id, 0, 1);} diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 8d6f132..5406186 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -1371,6 +1371,43 @@ Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. D*/ +int wave_create_and_pad(int pi, int percent); +/*D +This function creates a waveform like wave_create but pads the consumed +resources. Where percent gives the percentage of the resources to use (in terms +of the theoretical maximum, not the current amount free). This allows the reuse +of deleted waves while a transmission is active. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. + +. . +pi: >=0 (as returned by [*pigpio_start*]). +. . + +The data provided by the [*wave_add_**] functions is consumed by this +function. + +As many waveforms may be created as there is space available. The +wave id is passed to [*wave_send_**] to specify the waveform to transmit. + +A usage would be the creation of two waves where one is filled while the other +is beeing transmitted. Each wave is assigned 50% of the available resources. +This buffer structure allows the transmission of infinite wave sequences. + +Step 1. [*wave_clear*] to clear all waveforms and added data. + +Step 2. [*wave_add_**] calls to supply the waveform data. + +Step 3. [*wave_create_and_pad*] to create a 50% padded waveform and get a unique id + +Step 4. [*wave_send_**] with the id of the waveform to transmit. + +Repeat steps 2-4 as needed always waiting for the active waveform to be transmitted +before marking it as deleted. + +Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +D*/ /*F*/ int wave_delete(int pi, unsigned wave_id); -- cgit v1.2.3 From a9f5dc17d9ae3a17337e6df10a1eebb653c3a742 Mon Sep 17 00:00:00 2001 From: Jul3k Date: Thu, 5 Mar 2020 18:26:08 +0100 Subject: Added wave_create_and_pad to pigpio.py --- pigpio.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pigpio.py b/pigpio.py index cfaf845..fcc54a7 100644 --- a/pigpio.py +++ b/pigpio.py @@ -571,6 +571,7 @@ _PI_CMD_EVM =115 _PI_CMD_EVT =116 _PI_CMD_PROCU=117 +_PI_CMD_WVCAP=118 # pigpio error numbers @@ -2304,6 +2305,42 @@ class pi(): """ return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, 0, 0)) + def wave_create_and_pad(self, percent): + """ + This function creates a waveform like wave_create but pads the consumed + resources. Where percent gives the percentage of the resources to use (in terms + of the theoretical maximum, not the current amount free). This allows the reuse + of deleted waves while a transmission is active. Upon success a wave id + greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, + PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. + + . . + pi: >=0 (as returned by [*pigpio_start*]). + . . + + The data provided by the [*wave_add_**] functions is consumed by this + function. + + As many waveforms may be created as there is space available. The + wave id is passed to [*wave_send_**] to specify the waveform to transmit. + + A usage would be the creation of two waves where one is filled while the other + is beeing transmitted. Each wave is assigned 50% of the available resources. + This buffer structure allows the transmission of infinite wave sequences. + + Step 1. [*wave_clear*] to clear all waveforms and added data. + + Step 2. [*wave_add_**] calls to supply the waveform data. + + Step 3. [*wave_create_and_pad*] to create a 50% padded waveform and get a unique id + + Step 4. [*wave_send_**] with the id of the waveform to transmit. + + Repeat steps 2-4 as needed always waiting for the active waveform to be transmitted + before marking it as deleted. + """ + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCAP, percent, 0)) + def wave_delete(self, wave_id): """ This function deletes the waveform with id wave_id. -- cgit v1.2.3 From c660e3fc8e23c80bbc2f025ac659e07d9f3045e1 Mon Sep 17 00:00:00 2001 From: Jul3k Date: Thu, 5 Mar 2020 18:28:31 +0100 Subject: Added WaveCreatePad to pigpio.c --- pigpio.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 3 deletions(-) diff --git a/pigpio.c b/pigpio.c index fe5fc04..920b9fb 100644 --- a/pigpio.c +++ b/pigpio.c @@ -2434,6 +2434,8 @@ static int myDoCommand(uintptr_t *p, unsigned bufSize, char *buf) case PI_CMD_WVCRE: res = gpioWaveCreate(); break; + case PI_CMD_WVCAP: res = gpioWaveCreatePad(p[1]); break; + case PI_CMD_WVDEL: res = gpioWaveDelete(p[1]); break; case PI_CMD_WVGO: res = gpioWaveTxStart(PI_WAVE_MODE_ONE_SHOT); break; @@ -2992,7 +2994,7 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) /* ----------------------------------------------------------------------- */ -static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) +static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, int size) { int botCB=*CB, botOOL=*BOOL, topOOL=*TOOL; @@ -3130,6 +3132,28 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) } } + if (size) + { + /* pad the wave */ + + botCB = *CB + size - 1; + botOOL = *BOOL + size - 1; + //topOOL = //Fix: Ignore topOOL, flags not supported. + + /* link the last CB to end of wave */ + + p->next = waveCbPOadr(botCB); + + /* add dummy cb at end of DMA */ + + p = rawWaveCBAdr(botCB++); + p->info = NORMAL_DMA | DMA_DEST_IGNORE; + p->src = waveOOLPOadr(botOOL++); + p->dst = ((GPIO_BASE + (GPSET0*4)) & 0x00ffffff) | PI_PERI_BUS; + p->length = 4; + p->next = 0; + } + if (p != NULL) { if (wave_mode == PI_WAVE_MODE_ONE_SHOT) @@ -9566,7 +9590,7 @@ int gpioWaveCreate(void) /* What resources are needed? */ - waveCBsOOLs(&numCB, &numBOOL, &numTOOL); + waveCBsOOLs(&numCB, &numBOOL, &numTOOL); wid = -1; @@ -9619,7 +9643,7 @@ int gpioWaveCreate(void) BOOL = waveInfo[wid].botOOL; TOOL = waveInfo[wid].topOOL; - wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL); + wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, 0); /* Sanity check. */ @@ -9633,6 +9657,9 @@ int gpioWaveCreate(void) numTOOL, waveInfo[wid].topOOL-TOOL); } + DBG(DBG_USER, "Wave Stats: wid=%d CBs %d BOOL %d TOOL %d", wid, + numCB, numBOOL, numTOOL); + waveInfo[wid].deleted = 0; /* Consume waves. */ @@ -9646,6 +9673,104 @@ int gpioWaveCreate(void) return wid; } +int gpioWaveCreatePad(int percent) // Fix: Make variadic. +{ + int i, wid; + int numCB, numBOOL, numTOOL; + int CB, BOOL, TOOL; + + DBG(DBG_USER, ""); + + CHECK_INITED; + + if (wfc[wfcur] == 0) return PI_EMPTY_WAVEFORM; + + /* What resources are needed? */ + + numCB = (NUM_WAVE_CBS * percent) / 100; + numBOOL = (NUM_WAVE_OOL * percent) /100; + numTOOL = 0; // ignore TOOL, ie, no flags support + + wid = -1; + + /* Is there an exact fit with a deleted wave. */ + + for (i=0; i= NUM_WAVE_CBS) + return PI_TOO_MANY_CBS; + + if ((numBOOL+waveOutBotOOL) >= (waveOutTopOOL-numTOOL)) + return PI_TOO_MANY_OOL; + + if (wid >= PI_MAX_WAVES) + return PI_NO_WAVEFORM_ID; + + wid = waveOutCount++; + + waveInfo[wid].botCB = waveOutBotCB; + waveInfo[wid].topCB = waveOutBotCB + numCB -1; + waveInfo[wid].botOOL = waveOutBotOOL; + waveInfo[wid].topOOL = waveOutTopOOL; + waveInfo[wid].numCB = numCB; + waveInfo[wid].numBOOL = numBOOL; + waveInfo[wid].numTOOL = numTOOL; + + waveOutBotCB += numCB; + waveOutBotOOL += numBOOL; + waveOutTopOOL -= numTOOL; + } + + /* Must be room if got this far. */ + + CB = waveInfo[wid].botCB; + BOOL = waveInfo[wid].botOOL; + TOOL = waveInfo[wid].topOOL; + + wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, numCB); + + /* Sanity check. */ + + if ( (numCB != (CB-waveInfo[wid].botCB)) || + (numBOOL != (BOOL-waveInfo[wid].botOOL)) || + (numTOOL != (waveInfo[wid].topOOL-TOOL)) ) + { + DBG(DBG_ALWAYS, "ERROR wid=%d CBs %d=%d BOOL %d=%d TOOL %d=%d", wid, + numCB, CB-waveInfo[wid].botCB, + numBOOL, BOOL-waveInfo[wid].botOOL, + numTOOL, waveInfo[wid].topOOL-TOOL); + } + + DBG(DBG_USER, "Wave Stats: wid=%d CBs %d BOOL %d TOOL %d", wid, + numCB, numBOOL, numTOOL); + + waveInfo[wid].deleted = 0; + + /* Consume waves. */ + + wfc[0] = 0; + wfc[1] = 0; + wfc[2] = 0; + + wfcur = 0; + + return wid; +} /* ----------------------------------------------------------------------- */ int gpioWaveDelete(unsigned wave_id) -- cgit v1.2.3 From 038be6039851577a06624867749d4d817bcaf9f7 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 12 Mar 2020 09:27:51 -0500 Subject: Allow creation of two waves with 50% padding using gpioWaveCreatePad. - gpioWaveCreatePad takes three arguments: %CB, %BOOL, %TOOL - gpioWaveCreatePad checks range of arguments - gpioWaveCreatePad checks dimension of wave fits inside padding - wave2Cbs takes three arguments: numCB, numBOOL, numTOOL - socket command PI_CMD_WVCAP is variadic --- command.c | 2 +- pigpio.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++-------------- pigpio.h | 36 ++++++++++++++------------------ pigpio.py | 2 +- 4 files changed, 74 insertions(+), 38 deletions(-) diff --git a/command.c b/command.c index 0170005..ffc3463 100644 --- a/command.c +++ b/command.c @@ -694,7 +694,7 @@ int cmdParse( case 112: /* BI2CC FC GDC GPW I2CC I2CRB MG MICS MILS MODEG NC NP PADG PFG PRG PROCD PROCP PROCS PRRG R READ SLRC SPIC - WVDEL WVSC WVSM WVSP WVTX WVTXR BSPIC + WVCAP WVDEL WVSC WVSM WVSP WVTX WVTXR BSPIC One positive parameter. */ diff --git a/pigpio.c b/pigpio.c index 920b9fb..bbac95d 100644 --- a/pigpio.c +++ b/pigpio.c @@ -2434,7 +2434,26 @@ static int myDoCommand(uintptr_t *p, unsigned bufSize, char *buf) case PI_CMD_WVCRE: res = gpioWaveCreate(); break; - case PI_CMD_WVCAP: res = gpioWaveCreatePad(p[1]); break; + case PI_CMD_WVCAP: + /* Make WVCAP variadic */ + if (p[3] == 4) + { + memcpy(&tmp3, buf, 4); /* percent TOOL */ + res = gpioWaveCreatePad(p[1], p[2], tmp3); /* rawWaveAdd* usage */ + break; + } + if (p[2] && p[3]==0) + { + res = gpioWaveCreatePad(p[1], p[2], 0); + break; + } + if (p[2]==0 && p[3]==0) + { + res = gpioWaveCreatePad(p[1], p[1], 0); /* typical usage */ + break; + } + res = PI_BAD_WAVE_ID; // FIX? + break; case PI_CMD_WVDEL: res = gpioWaveDelete(p[1]); break; @@ -2994,7 +3013,8 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) /* ----------------------------------------------------------------------- */ -static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, int size) +static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, + int numCB, int numBOOL, int numTOOL) { int botCB=*CB, botOOL=*BOOL, topOOL=*TOOL; @@ -3132,19 +3152,19 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, int size) } } - if (size) + if (numCB) { - /* pad the wave */ + /* Pad the wave */ - botCB = *CB + size - 1; - botOOL = *BOOL + size - 1; - //topOOL = //Fix: Ignore topOOL, flags not supported. + botCB = *CB + numCB - 1; + botOOL = *BOOL + numBOOL - 1; + topOOL = *TOOL - numTOOL; - /* link the last CB to end of wave */ + /* Link the last CB to end of wave */ p->next = waveCbPOadr(botCB); - /* add dummy cb at end of DMA */ + /* Insert sentinel CB at end of DMA */ p = rawWaveCBAdr(botCB++); p->info = NORMAL_DMA | DMA_DEST_IGNORE; @@ -9643,7 +9663,7 @@ int gpioWaveCreate(void) BOOL = waveInfo[wid].botOOL; TOOL = waveInfo[wid].topOOL; - wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, 0); + wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, 0, 0, 0); /* Sanity check. */ @@ -9673,23 +9693,43 @@ int gpioWaveCreate(void) return wid; } -int gpioWaveCreatePad(int percent) // Fix: Make variadic. +int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL) { int i, wid; int numCB, numBOOL, numTOOL; int CB, BOOL, TOOL; - DBG(DBG_USER, ""); + DBG(DBG_USER, "%d, %d, %d", pctCB, pctBOOL, pctTOOL); CHECK_INITED; + if (pctCB < 0 || pctCB > 100) + SOFT_ERROR(PI_BAD_PARAM, "bad wave param, pctCB=(%d)", pctCB); + if (pctBOOL < 0 || pctBOOL > 100) + SOFT_ERROR(PI_BAD_PARAM, "bad wave param, pctBOOL=(%d)", pctCB); + if (pctTOOL < 0 || pctTOOL > 100) + SOFT_ERROR(PI_BAD_PARAM, "bad wave param, pctTOOL=(%d)", pctCB); + if (wfc[wfcur] == 0) return PI_EMPTY_WAVEFORM; /* What resources are needed? */ + waveCBsOOLs(&numCB, &numBOOL, &numTOOL); + + /* Amount of pad required */ + CB = (NUM_WAVE_CBS - PI_WAVE_COUNT_PAGES*CBS_PER_OPAGE -1) * pctCB / 100; + BOOL = (NUM_WAVE_OOL - PI_WAVE_COUNT_PAGES*OOL_PER_OPAGE -1) * pctBOOL /100; + TOOL = (NUM_WAVE_OOL * pctTOOL) / 100; + + /* Reject if wave is too big */ + if (numCB >= CB) return PI_TOO_MANY_CBS; + if (numBOOL >= BOOL) return PI_I2C_WRITE_FAILED; // Fix + if (numTOOL > TOOL) return PI_I2C_READ_FAILED; // Fix + + /* Set the padding */ + numCB = CB; + numBOOL = BOOL; + numTOOL = TOOL; - numCB = (NUM_WAVE_CBS * percent) / 100; - numBOOL = (NUM_WAVE_OOL * percent) /100; - numTOOL = 0; // ignore TOOL, ie, no flags support wid = -1; @@ -9742,7 +9782,7 @@ int gpioWaveCreatePad(int percent) // Fix: Make variadic. BOOL = waveInfo[wid].botOOL; TOOL = waveInfo[wid].topOOL; - wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, numCB); + wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, numCB, numBOOL, numTOOL); /* Sanity check. */ diff --git a/pigpio.h b/pigpio.h index da29f1b..bffcd8d 100644 --- a/pigpio.h +++ b/pigpio.h @@ -1986,42 +1986,38 @@ Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. D*/ -int gpioWaveCreatePad(int percent); +int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL); /*D -This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use (in terms -of the theoretical maximum, not the current amount free). This allows the reuse -of deleted waves while a transmission is active. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +Similar to gpioWaveCreate(), this function creates a waveform but pads the consumed +resources. Padded waves of equal dimension can be re-cycled efficiently allowing +newly created waves to re-use the resources of deleted waves of the same dimension. . . -pi: >=0 (as returned by [*pigpio_start*]). +pctCB: 0-100, the percent of all DMA control blocks to consume. +pctBOOL: 0-100, the percent of On-Off-Level (OOL) buffer to consume for wave output. +pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags). . . -The data provided by the [*wave_add_**] functions is consumed by this -function. +Upon success a wave id greater than or equal to 0 is returned, otherwise +PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -As many waveforms may be created as there is space available. The -wave id is passed to [*wave_send_**] to specify the waveform to transmit. +Waveform data provided by [*gpioWaveAdd**] and [*rawWaveAdd**] functions are +consumed by this function. A usage would be the creation of two waves where one is filled while the other -is beeing transmitted. Each wave is assigned 50% of the available resources. +is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences. -Step 1. [*wave_clear*] to clear all waveforms and added data. +Step 1. [*gpioWaveClear*] to clear all waveforms and added data. -Step 2. [*wave_add_**] calls to supply the waveform data. +Step 2. [*gpioWaveAdd*] calls to supply the waveform data. -Step 3. [*wave_create_and_pad*] to create a 50% padded waveform and get a unique id +Step 3. gpioWaveCreatePad(50,50,0) to create a 50% padded waveform and get a unique id -Step 4. [*wave_send_**] with the id of the waveform to transmit. +Step 4. [*gpioWaveTxSend*] with the wave id and PI_WAVE_MODE_ONE_SHOT_SYNC. Repeat steps 2-4 as needed always waiting for the active waveform to be transmitted before marking it as deleted. - -Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. D*/ /*F*/ diff --git a/pigpio.py b/pigpio.py index fcc54a7..a9f10e3 100644 --- a/pigpio.py +++ b/pigpio.py @@ -2325,7 +2325,7 @@ class pi(): wave id is passed to [*wave_send_**] to specify the waveform to transmit. A usage would be the creation of two waves where one is filled while the other - is beeing transmitted. Each wave is assigned 50% of the available resources. + is being transmitted. Each wave is assigned 50% of the available resources. This buffer structure allows the transmission of infinite wave sequences. Step 1. [*wave_clear*] to clear all waveforms and added data. -- cgit v1.2.3 From 7f05ff4c48b00503b77a08d854364f431758525c Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 12 Mar 2020 09:46:58 -0500 Subject: Fix error messages on gpioWaveCreatePad --- pigpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index bbac95d..4be1b67 100644 --- a/pigpio.c +++ b/pigpio.c @@ -9722,8 +9722,8 @@ int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL) /* Reject if wave is too big */ if (numCB >= CB) return PI_TOO_MANY_CBS; - if (numBOOL >= BOOL) return PI_I2C_WRITE_FAILED; // Fix - if (numTOOL > TOOL) return PI_I2C_READ_FAILED; // Fix + if (numBOOL >= BOOL) return PI_TOO_MANY_OOL; + if (numTOOL > TOOL) return PI_TOO_MANY_OOL; /* Set the padding */ numCB = CB; -- cgit v1.2.3 From c38087352fcc7e4d99af1d8be6eabd18a5b543fc Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Wed, 18 Mar 2020 16:31:42 -0500 Subject: Use two-beat DMA control block on pulse with set and clear OOLs. --- pigpio.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/pigpio.c b/pigpio.c index 4be1b67..1f3dd68 100644 --- a/pigpio.c +++ b/pigpio.c @@ -396,6 +396,7 @@ bit 0 READ_LAST_NOT_SET_ERROR #define DMA_DEST_WIDTH (1<< 5) #define DMA_DEST_INC (1<< 4) #define DMA_WAIT_RESP (1<< 3) +#define DMA_TDMODE (1<< 1) #define DMA_DEBUG_READ_ERR (1<<2) #define DMA_DEBUG_FIFO_ERR (1<<1) @@ -664,6 +665,7 @@ bit 0 READ_LAST_NOT_SET_ERROR /* --------------------------------------------------------------- */ #define NORMAL_DMA (DMA_NO_WIDE_BURSTS | DMA_WAIT_RESP) +#define TWO_BEAT_DMA (DMA_TDMODE | DMA_BURST_LENGTH(1)) #define TIMED_DMA(x) (DMA_DEST_DREQ | DMA_PERIPHERAL_MAPPING(x)) @@ -2998,8 +3000,7 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) for (i=0; iinfo = TWO_BEAT_DMA; + p->src = waveOOLPOadr(botOOL); + waveSetOOL(botOOL++, waves[i].gpioOn); + s_stride = waveOOLPOadr(botOOL) - p->src; + waveSetOOL(botOOL++, waves[i].gpioOff); + p->dst = ((GPIO_BASE + (GPSET0*4)) & 0x00ffffff) | PI_PERI_BUS; + p->length = (2<<16) + 4; // 2 transfers of 4 bytes each + p->stride = (12<<16) + s_stride; // d_stride = (GPCLR0-GPSET0)*4 = 12 + p->next = waveCbPOadr(botCB); + } + if (waves[i].gpioOn && !waves[i].gpioOff) { waveSetOOL(botOOL, waves[i].gpioOn); @@ -3074,8 +3090,7 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, p->length = 4; p->next = waveCbPOadr(botCB); } - - if (waves[i].gpioOff) + if (waves[i].gpioOff && !waves[i].gpioOn) { waveSetOOL(botOOL, waves[i].gpioOff); @@ -3087,7 +3102,6 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, p->length = 4; p->next = waveCbPOadr(botCB); } - if (waves[i].flags & WAVE_FLAG_READ) { p = rawWaveCBAdr(botCB++); @@ -3368,9 +3382,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1) cbs += waveDelayCBs(tDelay); - if (out[outPos].gpioOn) cbs++; /* one cb if gpio on */ - - if (out[outPos].gpioOff) cbs++; /* one cb if gpio off */ + if (out[outPos].gpioOn || out[outPos].gpioOff) cbs++; if (out[outPos].flags & WAVE_FLAG_READ) { -- cgit v1.2.3 From b229b67ce02dbd1ea2daa7bf107e570e0cc73144 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 22 Mar 2020 12:26:26 -0500 Subject: Correct max wave resource comparison tests. --- .gitignore | 2 ++ pigpio.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 4108796..140d796 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ __pycache__ build dist *.egg-info +wavepad_jitter.py + diff --git a/pigpio.c b/pigpio.c index 1f3dd68..474da1c 100644 --- a/pigpio.c +++ b/pigpio.c @@ -9645,10 +9645,10 @@ int gpioWaveCreate(void) { /* Are there enough spare resources? */ - if ((numCB+waveOutBotCB) >= NUM_WAVE_CBS) + if ((numCB+waveOutBotCB) > NUM_WAVE_CBS) return PI_TOO_MANY_CBS; - if ((numBOOL+waveOutBotOOL) >= (waveOutTopOOL-numTOOL)) + if ((numBOOL+waveOutBotOOL) > (waveOutTopOOL-numTOOL)) return PI_TOO_MANY_OOL; if (wid >= PI_MAX_WAVES) @@ -9718,9 +9718,9 @@ int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL) if (pctCB < 0 || pctCB > 100) SOFT_ERROR(PI_BAD_PARAM, "bad wave param, pctCB=(%d)", pctCB); if (pctBOOL < 0 || pctBOOL > 100) - SOFT_ERROR(PI_BAD_PARAM, "bad wave param, pctBOOL=(%d)", pctCB); + SOFT_ERROR(PI_BAD_PARAM, "bad wave param, pctBOOL=(%d)", pctBOOL); if (pctTOOL < 0 || pctTOOL > 100) - SOFT_ERROR(PI_BAD_PARAM, "bad wave param, pctTOOL=(%d)", pctCB); + SOFT_ERROR(PI_BAD_PARAM, "bad wave param, pctTOOL=(%d)", pctTOOL); if (wfc[wfcur] == 0) return PI_EMPTY_WAVEFORM; @@ -9728,13 +9728,13 @@ int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL) waveCBsOOLs(&numCB, &numBOOL, &numTOOL); /* Amount of pad required */ - CB = (NUM_WAVE_CBS - PI_WAVE_COUNT_PAGES*CBS_PER_OPAGE -1) * pctCB / 100; - BOOL = (NUM_WAVE_OOL - PI_WAVE_COUNT_PAGES*OOL_PER_OPAGE -1) * pctBOOL /100; - TOOL = (NUM_WAVE_OOL * pctTOOL) / 100; + CB = (NUM_WAVE_CBS - PI_WAVE_COUNT_PAGES*CBS_PER_OPAGE) * pctCB / 100; + BOOL = (NUM_WAVE_OOL - PI_WAVE_COUNT_PAGES*OOL_PER_OPAGE) * pctBOOL /100; + TOOL = (NUM_WAVE_OOL - PI_WAVE_COUNT_PAGES*OOL_PER_OPAGE) * pctTOOL /100; /* Reject if wave is too big */ - if (numCB >= CB) return PI_TOO_MANY_CBS; - if (numBOOL >= BOOL) return PI_TOO_MANY_OOL; + if (numCB > CB) return PI_TOO_MANY_CBS; + if (numBOOL > BOOL) return PI_TOO_MANY_OOL; if (numTOOL > TOOL) return PI_TOO_MANY_OOL; /* Set the padding */ @@ -9764,10 +9764,10 @@ int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL) { /* Are there enough spare resources? */ - if ((numCB+waveOutBotCB) >= NUM_WAVE_CBS) + if ((numCB+waveOutBotCB) > NUM_WAVE_CBS) return PI_TOO_MANY_CBS; - if ((numBOOL+waveOutBotOOL) >= (waveOutTopOOL-numTOOL)) + if ((numBOOL+waveOutBotOOL) > (waveOutTopOOL-numTOOL)) return PI_TOO_MANY_OOL; if (wid >= PI_MAX_WAVES) @@ -9808,7 +9808,7 @@ int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL) numTOOL, waveInfo[wid].topOOL-TOOL); } - DBG(DBG_USER, "Wave Stats: wid=%d CBs %d BOOL %d TOOL %d", wid, + DBG(DBG_USER, "Wave padding: wid=%d CBs %d BOOL %d TOOL %d", wid, numCB, numBOOL, numTOOL); waveInfo[wid].deleted = 0; -- cgit v1.2.3 From 76cebc73b10279fbc279dffa041d9dc96676fe41 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 22 Mar 2020 23:38:50 -0500 Subject: Change version to 7500 to sync with planned v75 release. --- .gitignore | 2 ++ pigpio.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f67291c..98748da 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ __pycache__ build dist *.egg-info +wavepad_jitter.py + diff --git a/pigpio.h b/pigpio.h index e3eb97d..82a2394 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7401 +#define PIGPIO_VERSION 7500 /*TEXT -- cgit v1.2.3 From f2fdb2db454b242e1ce6342b907abaebedfb040c Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Mon, 23 Mar 2020 00:00:02 -0500 Subject: v75 --- pigpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.h b/pigpio.h index 82a2394..7701b45 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7500 +#define PIGPIO_VERSION 75 /*TEXT -- cgit v1.2.3 From b752ab91645be854c2a361a7d5dfab813b572cba Mon Sep 17 00:00:00 2001 From: joan2937 Date: Tue, 24 Mar 2020 11:55:10 +0000 Subject: Added autogeneation of man pages and HTML for web site --- DOC/HTML/images/LDR-fritz.png | Bin 0 -> 42505 bytes DOC/HTML/images/LDR-gnup-1.png | Bin 0 -> 47487 bytes DOC/HTML/images/LDR-gnup-2.png | Bin 0 -> 31410 bytes DOC/HTML/images/LDR-photo.jpg | Bin 0 -> 109499 bytes DOC/HTML/images/LDR-wave-1.png | Bin 0 -> 4557 bytes DOC/HTML/images/LDR-wave-2.png | Bin 0 -> 4438 bytes DOC/HTML/images/LDR-wave-3.png | Bin 0 -> 4872 bytes DOC/HTML/images/breadboard.jpg | Bin 0 -> 46953 bytes DOC/HTML/images/caps.jpg | Bin 0 -> 35397 bytes DOC/HTML/images/driver.jpg | Bin 0 -> 41058 bytes DOC/HTML/images/faq-i2c-ss.png | Bin 0 -> 9006 bytes DOC/HTML/images/faq-i2c.jpg | Bin 0 -> 42782 bytes DOC/HTML/images/faq-serial.jpg | Bin 0 -> 40297 bytes DOC/HTML/images/faq-spi.jpg | Bin 0 -> 43222 bytes DOC/HTML/images/faq1.jpg | Bin 0 -> 14196 bytes DOC/HTML/images/faq2.jpg | Bin 0 -> 37418 bytes DOC/HTML/images/faq3.jpg | Bin 0 -> 6686 bytes DOC/HTML/images/imu-1.jpg | Bin 0 -> 44650 bytes DOC/HTML/images/imu-2.jpg | Bin 0 -> 42737 bytes DOC/HTML/images/imu-3.jpg | Bin 0 -> 42800 bytes DOC/HTML/images/ir-fritz.png | Bin 0 -> 40477 bytes DOC/HTML/images/ir-motion.jpg | Bin 0 -> 22139 bytes DOC/HTML/images/ir-photo.jpg | Bin 0 -> 90482 bytes DOC/HTML/images/ir-rx.jpg | Bin 0 -> 32358 bytes DOC/HTML/images/ir-wave-1.png | Bin 0 -> 4827 bytes DOC/HTML/images/ir-wave-2.png | Bin 0 -> 4237 bytes DOC/HTML/images/ir-wave-3.png | Bin 0 -> 5038 bytes DOC/HTML/images/keypad.jpg | Bin 0 -> 30294 bytes DOC/HTML/images/lcd.jpg | Bin 0 -> 29926 bytes DOC/HTML/images/ldr-cap.jpg | Bin 0 -> 34448 bytes DOC/HTML/images/ldr.jpg | Bin 0 -> 28458 bytes DOC/HTML/images/leds.jpg | Bin 0 -> 36146 bytes DOC/HTML/images/meter.jpg | Bin 0 -> 29610 bytes DOC/HTML/images/motor.jpg | Bin 0 -> 17593 bytes DOC/HTML/images/msp430.jpg | Bin 0 -> 43686 bytes DOC/HTML/images/nano.jpg | Bin 0 -> 40463 bytes DOC/HTML/images/oled-2.jpg | Bin 0 -> 40888 bytes DOC/HTML/images/oled.jpg | Bin 0 -> 31872 bytes DOC/HTML/images/pigpio-logo.gif | Bin 0 -> 375 bytes DOC/HTML/images/pins.jpg | Bin 0 -> 42788 bytes DOC/HTML/images/pisc-1.jpg | Bin 0 -> 20520 bytes DOC/HTML/images/pisc-2.jpg | Bin 0 -> 17527 bytes DOC/HTML/images/pisc-3.jpg | Bin 0 -> 15915 bytes DOC/HTML/images/pot.jpg | Bin 0 -> 26518 bytes DOC/HTML/images/pro-mini.jpg | Bin 0 -> 36398 bytes DOC/HTML/images/psu.jpg | Bin 0 -> 33988 bytes DOC/HTML/images/re-fritz.png | Bin 0 -> 39702 bytes DOC/HTML/images/re-photo.jpg | Bin 0 -> 50100 bytes DOC/HTML/images/re-wave-1.png | Bin 0 -> 5570 bytes DOC/HTML/images/re-wave-2.png | Bin 0 -> 5404 bytes DOC/HTML/images/remote-1.jpg | Bin 0 -> 27199 bytes DOC/HTML/images/remote-2.jpg | Bin 0 -> 28482 bytes DOC/HTML/images/reverse.jpg | Bin 0 -> 35860 bytes DOC/HTML/images/rf-rx-2.jpg | Bin 0 -> 34515 bytes DOC/HTML/images/rf-rx.jpg | Bin 0 -> 31082 bytes DOC/HTML/images/rf-tx.jpg | Bin 0 -> 40421 bytes DOC/HTML/images/rotary.jpg | Bin 0 -> 22765 bytes DOC/HTML/images/rpi.jpg | Bin 0 -> 37698 bytes DOC/HTML/images/serial.jpg | Bin 0 -> 29831 bytes DOC/HTML/images/servo.jpg | Bin 0 -> 28811 bytes DOC/HTML/images/sidebar.gif | Bin 0 -> 52 bytes DOC/HTML/images/son-fritz.png | Bin 0 -> 69915 bytes DOC/HTML/images/son-gnup-1.png | Bin 0 -> 15447 bytes DOC/HTML/images/son-gnup-2.png | Bin 0 -> 12101 bytes DOC/HTML/images/son-photo.jpg | Bin 0 -> 69827 bytes DOC/HTML/images/son-wave-1.png | Bin 0 -> 4410 bytes DOC/HTML/images/son-wave-2.png | Bin 0 -> 4293 bytes DOC/HTML/images/son-wave-3.png | Bin 0 -> 4757 bytes DOC/HTML/images/son-wave-4.png | Bin 0 -> 5270 bytes DOC/HTML/images/speaker.jpg | Bin 0 -> 34456 bytes DOC/HTML/images/spi-lnx-pi3b.png | Bin 0 -> 9134 bytes DOC/HTML/images/spi-lnx-pibr1.png | Bin 0 -> 7174 bytes DOC/HTML/images/spi-pig-pi3b.png | Bin 0 -> 8896 bytes DOC/HTML/images/spi-pig-pibr1.png | Bin 0 -> 8502 bytes DOC/HTML/images/srf02.jpg | Bin 0 -> 26595 bytes DOC/HTML/images/srf04.jpg | Bin 0 -> 33664 bytes DOC/HTML/images/stepper.jpg | Bin 0 -> 30634 bytes DOC/HTML/images/switches.jpg | Bin 0 -> 43275 bytes DOC/HTML/images/topbar.gif | Bin 0 -> 1015 bytes DOC/HTML/images/transistors.jpg | Bin 0 -> 43174 bytes DOC/HTML/images/ubec-2.jpg | Bin 0 -> 18920 bytes DOC/HTML/images/uln2003a.jpg | Bin 0 -> 26817 bytes DOC/HTML/images/wheel.jpg | Bin 0 -> 23241 bytes DOC/HTML/images/wires.jpg | Bin 0 -> 36804 bytes DOC/HTML/images/yl-40.jpg | Bin 0 -> 43771 bytes DOC/HTML/scripts/index.css | 52 + DOC/HTML/scripts/standard.css | 3 + DOC/README | 16 + DOC/bin/backup.sh | 5 + DOC/bin/body.py | 14 + DOC/bin/build_site.py | 21 + DOC/bin/cmakdoc.py | 563 ++++++ DOC/bin/examples.py | 123 ++ DOC/bin/html.py | 137 ++ DOC/bin/purge.sh | 14 + DOC/bin/pymakdoc.py | 270 +++ DOC/bin/smakdoc.py | 376 ++++ DOC/bin/tidy.py | 28 + DOC/bin/updatesql.py | 21 + DOC/dbase/pigpio.sqlite | Bin 0 -> 1433600 bytes DOC/makedoc | 47 + DOC/src/defs/examples.def | 511 ++++++ DOC/src/defs/pig2vcd.def | 110 ++ DOC/src/defs/pigpiod.def | 101 + DOC/src/defs/pigs.def | 3439 +++++++++++++++++++++++++++++++++++ DOC/src/html/download.html | 66 + DOC/src/html/ex_LDR.html | 150 ++ DOC/src/html/ex_ir_remote.html | 253 +++ DOC/src/html/ex_motor_shield.html | 254 +++ DOC/src/html/ex_rotary_encoder.html | 185 ++ DOC/src/html/ex_sonar_ranger.html | 164 ++ DOC/src/html/faq.html | 462 +++++ DOC/src/html/index.html | 662 +++++++ DOC/src/html/misc.html | 33 + DOC/src/html/pif.html | 30 + DOC/src/html/piscope.html | 216 +++ DOC/src/html/sif.html | 2004 ++++++++++++++++++++ 117 files changed, 10330 insertions(+) create mode 100644 DOC/HTML/images/LDR-fritz.png create mode 100644 DOC/HTML/images/LDR-gnup-1.png create mode 100644 DOC/HTML/images/LDR-gnup-2.png create mode 100644 DOC/HTML/images/LDR-photo.jpg create mode 100644 DOC/HTML/images/LDR-wave-1.png create mode 100644 DOC/HTML/images/LDR-wave-2.png create mode 100644 DOC/HTML/images/LDR-wave-3.png create mode 100644 DOC/HTML/images/breadboard.jpg create mode 100644 DOC/HTML/images/caps.jpg create mode 100644 DOC/HTML/images/driver.jpg create mode 100644 DOC/HTML/images/faq-i2c-ss.png create mode 100644 DOC/HTML/images/faq-i2c.jpg create mode 100644 DOC/HTML/images/faq-serial.jpg create mode 100644 DOC/HTML/images/faq-spi.jpg create mode 100644 DOC/HTML/images/faq1.jpg create mode 100644 DOC/HTML/images/faq2.jpg create mode 100644 DOC/HTML/images/faq3.jpg create mode 100644 DOC/HTML/images/imu-1.jpg create mode 100644 DOC/HTML/images/imu-2.jpg create mode 100644 DOC/HTML/images/imu-3.jpg create mode 100644 DOC/HTML/images/ir-fritz.png create mode 100644 DOC/HTML/images/ir-motion.jpg create mode 100644 DOC/HTML/images/ir-photo.jpg create mode 100644 DOC/HTML/images/ir-rx.jpg create mode 100644 DOC/HTML/images/ir-wave-1.png create mode 100644 DOC/HTML/images/ir-wave-2.png create mode 100644 DOC/HTML/images/ir-wave-3.png create mode 100644 DOC/HTML/images/keypad.jpg create mode 100644 DOC/HTML/images/lcd.jpg create mode 100644 DOC/HTML/images/ldr-cap.jpg create mode 100644 DOC/HTML/images/ldr.jpg create mode 100644 DOC/HTML/images/leds.jpg create mode 100644 DOC/HTML/images/meter.jpg create mode 100644 DOC/HTML/images/motor.jpg create mode 100644 DOC/HTML/images/msp430.jpg create mode 100644 DOC/HTML/images/nano.jpg create mode 100644 DOC/HTML/images/oled-2.jpg create mode 100644 DOC/HTML/images/oled.jpg create mode 100644 DOC/HTML/images/pigpio-logo.gif create mode 100644 DOC/HTML/images/pins.jpg create mode 100644 DOC/HTML/images/pisc-1.jpg create mode 100644 DOC/HTML/images/pisc-2.jpg create mode 100644 DOC/HTML/images/pisc-3.jpg create mode 100644 DOC/HTML/images/pot.jpg create mode 100644 DOC/HTML/images/pro-mini.jpg create mode 100644 DOC/HTML/images/psu.jpg create mode 100644 DOC/HTML/images/re-fritz.png create mode 100644 DOC/HTML/images/re-photo.jpg create mode 100644 DOC/HTML/images/re-wave-1.png create mode 100644 DOC/HTML/images/re-wave-2.png create mode 100644 DOC/HTML/images/remote-1.jpg create mode 100644 DOC/HTML/images/remote-2.jpg create mode 100644 DOC/HTML/images/reverse.jpg create mode 100644 DOC/HTML/images/rf-rx-2.jpg create mode 100644 DOC/HTML/images/rf-rx.jpg create mode 100644 DOC/HTML/images/rf-tx.jpg create mode 100644 DOC/HTML/images/rotary.jpg create mode 100644 DOC/HTML/images/rpi.jpg create mode 100644 DOC/HTML/images/serial.jpg create mode 100644 DOC/HTML/images/servo.jpg create mode 100644 DOC/HTML/images/sidebar.gif create mode 100644 DOC/HTML/images/son-fritz.png create mode 100644 DOC/HTML/images/son-gnup-1.png create mode 100644 DOC/HTML/images/son-gnup-2.png create mode 100644 DOC/HTML/images/son-photo.jpg create mode 100644 DOC/HTML/images/son-wave-1.png create mode 100644 DOC/HTML/images/son-wave-2.png create mode 100644 DOC/HTML/images/son-wave-3.png create mode 100644 DOC/HTML/images/son-wave-4.png create mode 100644 DOC/HTML/images/speaker.jpg create mode 100644 DOC/HTML/images/spi-lnx-pi3b.png create mode 100644 DOC/HTML/images/spi-lnx-pibr1.png create mode 100644 DOC/HTML/images/spi-pig-pi3b.png create mode 100644 DOC/HTML/images/spi-pig-pibr1.png create mode 100644 DOC/HTML/images/srf02.jpg create mode 100644 DOC/HTML/images/srf04.jpg create mode 100644 DOC/HTML/images/stepper.jpg create mode 100644 DOC/HTML/images/switches.jpg create mode 100644 DOC/HTML/images/topbar.gif create mode 100644 DOC/HTML/images/transistors.jpg create mode 100644 DOC/HTML/images/ubec-2.jpg create mode 100644 DOC/HTML/images/uln2003a.jpg create mode 100644 DOC/HTML/images/wheel.jpg create mode 100644 DOC/HTML/images/wires.jpg create mode 100644 DOC/HTML/images/yl-40.jpg create mode 100644 DOC/HTML/scripts/index.css create mode 100644 DOC/HTML/scripts/standard.css create mode 100644 DOC/README create mode 100755 DOC/bin/backup.sh create mode 100755 DOC/bin/body.py create mode 100755 DOC/bin/build_site.py create mode 100755 DOC/bin/cmakdoc.py create mode 100755 DOC/bin/examples.py create mode 100755 DOC/bin/html.py create mode 100755 DOC/bin/purge.sh create mode 100755 DOC/bin/pymakdoc.py create mode 100755 DOC/bin/smakdoc.py create mode 100755 DOC/bin/tidy.py create mode 100755 DOC/bin/updatesql.py create mode 100644 DOC/dbase/pigpio.sqlite create mode 100755 DOC/makedoc create mode 100644 DOC/src/defs/examples.def create mode 100644 DOC/src/defs/pig2vcd.def create mode 100644 DOC/src/defs/pigpiod.def create mode 100644 DOC/src/defs/pigs.def create mode 100644 DOC/src/html/download.html create mode 100644 DOC/src/html/ex_LDR.html create mode 100644 DOC/src/html/ex_ir_remote.html create mode 100644 DOC/src/html/ex_motor_shield.html create mode 100644 DOC/src/html/ex_rotary_encoder.html create mode 100644 DOC/src/html/ex_sonar_ranger.html create mode 100644 DOC/src/html/faq.html create mode 100644 DOC/src/html/index.html create mode 100644 DOC/src/html/misc.html create mode 100644 DOC/src/html/pif.html create mode 100644 DOC/src/html/piscope.html create mode 100644 DOC/src/html/sif.html diff --git a/DOC/HTML/images/LDR-fritz.png b/DOC/HTML/images/LDR-fritz.png new file mode 100644 index 0000000..6265585 Binary files /dev/null and b/DOC/HTML/images/LDR-fritz.png differ diff --git a/DOC/HTML/images/LDR-gnup-1.png b/DOC/HTML/images/LDR-gnup-1.png new file mode 100644 index 0000000..6ec6194 Binary files /dev/null and b/DOC/HTML/images/LDR-gnup-1.png differ diff --git a/DOC/HTML/images/LDR-gnup-2.png b/DOC/HTML/images/LDR-gnup-2.png new file mode 100644 index 0000000..4453096 Binary files /dev/null and b/DOC/HTML/images/LDR-gnup-2.png differ diff --git a/DOC/HTML/images/LDR-photo.jpg b/DOC/HTML/images/LDR-photo.jpg new file mode 100644 index 0000000..95a63a3 Binary files /dev/null and b/DOC/HTML/images/LDR-photo.jpg differ diff --git a/DOC/HTML/images/LDR-wave-1.png b/DOC/HTML/images/LDR-wave-1.png new file mode 100644 index 0000000..69bb43b Binary files /dev/null and b/DOC/HTML/images/LDR-wave-1.png differ diff --git a/DOC/HTML/images/LDR-wave-2.png b/DOC/HTML/images/LDR-wave-2.png new file mode 100644 index 0000000..ea68076 Binary files /dev/null and b/DOC/HTML/images/LDR-wave-2.png differ diff --git a/DOC/HTML/images/LDR-wave-3.png b/DOC/HTML/images/LDR-wave-3.png new file mode 100644 index 0000000..a2ca42a Binary files /dev/null and b/DOC/HTML/images/LDR-wave-3.png differ diff --git a/DOC/HTML/images/breadboard.jpg b/DOC/HTML/images/breadboard.jpg new file mode 100644 index 0000000..5d916f7 Binary files /dev/null and b/DOC/HTML/images/breadboard.jpg differ diff --git a/DOC/HTML/images/caps.jpg b/DOC/HTML/images/caps.jpg new file mode 100644 index 0000000..f82e73b Binary files /dev/null and b/DOC/HTML/images/caps.jpg differ diff --git a/DOC/HTML/images/driver.jpg b/DOC/HTML/images/driver.jpg new file mode 100644 index 0000000..48266fe Binary files /dev/null and b/DOC/HTML/images/driver.jpg differ diff --git a/DOC/HTML/images/faq-i2c-ss.png b/DOC/HTML/images/faq-i2c-ss.png new file mode 100644 index 0000000..0e4c58a Binary files /dev/null and b/DOC/HTML/images/faq-i2c-ss.png differ diff --git a/DOC/HTML/images/faq-i2c.jpg b/DOC/HTML/images/faq-i2c.jpg new file mode 100644 index 0000000..02b4a01 Binary files /dev/null and b/DOC/HTML/images/faq-i2c.jpg differ diff --git a/DOC/HTML/images/faq-serial.jpg b/DOC/HTML/images/faq-serial.jpg new file mode 100644 index 0000000..9963589 Binary files /dev/null and b/DOC/HTML/images/faq-serial.jpg differ diff --git a/DOC/HTML/images/faq-spi.jpg b/DOC/HTML/images/faq-spi.jpg new file mode 100644 index 0000000..65ed087 Binary files /dev/null and b/DOC/HTML/images/faq-spi.jpg differ diff --git a/DOC/HTML/images/faq1.jpg b/DOC/HTML/images/faq1.jpg new file mode 100644 index 0000000..72c6eb6 Binary files /dev/null and b/DOC/HTML/images/faq1.jpg differ diff --git a/DOC/HTML/images/faq2.jpg b/DOC/HTML/images/faq2.jpg new file mode 100644 index 0000000..a22800e Binary files /dev/null and b/DOC/HTML/images/faq2.jpg differ diff --git a/DOC/HTML/images/faq3.jpg b/DOC/HTML/images/faq3.jpg new file mode 100644 index 0000000..9785a49 Binary files /dev/null and b/DOC/HTML/images/faq3.jpg differ diff --git a/DOC/HTML/images/imu-1.jpg b/DOC/HTML/images/imu-1.jpg new file mode 100644 index 0000000..f9de3a3 Binary files /dev/null and b/DOC/HTML/images/imu-1.jpg differ diff --git a/DOC/HTML/images/imu-2.jpg b/DOC/HTML/images/imu-2.jpg new file mode 100644 index 0000000..cd56dfd Binary files /dev/null and b/DOC/HTML/images/imu-2.jpg differ diff --git a/DOC/HTML/images/imu-3.jpg b/DOC/HTML/images/imu-3.jpg new file mode 100644 index 0000000..193fe48 Binary files /dev/null and b/DOC/HTML/images/imu-3.jpg differ diff --git a/DOC/HTML/images/ir-fritz.png b/DOC/HTML/images/ir-fritz.png new file mode 100644 index 0000000..595d8d5 Binary files /dev/null and b/DOC/HTML/images/ir-fritz.png differ diff --git a/DOC/HTML/images/ir-motion.jpg b/DOC/HTML/images/ir-motion.jpg new file mode 100644 index 0000000..7fe557e Binary files /dev/null and b/DOC/HTML/images/ir-motion.jpg differ diff --git a/DOC/HTML/images/ir-photo.jpg b/DOC/HTML/images/ir-photo.jpg new file mode 100644 index 0000000..f42ffa2 Binary files /dev/null and b/DOC/HTML/images/ir-photo.jpg differ diff --git a/DOC/HTML/images/ir-rx.jpg b/DOC/HTML/images/ir-rx.jpg new file mode 100644 index 0000000..130b365 Binary files /dev/null and b/DOC/HTML/images/ir-rx.jpg differ diff --git a/DOC/HTML/images/ir-wave-1.png b/DOC/HTML/images/ir-wave-1.png new file mode 100644 index 0000000..29edad3 Binary files /dev/null and b/DOC/HTML/images/ir-wave-1.png differ diff --git a/DOC/HTML/images/ir-wave-2.png b/DOC/HTML/images/ir-wave-2.png new file mode 100644 index 0000000..f820503 Binary files /dev/null and b/DOC/HTML/images/ir-wave-2.png differ diff --git a/DOC/HTML/images/ir-wave-3.png b/DOC/HTML/images/ir-wave-3.png new file mode 100644 index 0000000..b5292b8 Binary files /dev/null and b/DOC/HTML/images/ir-wave-3.png differ diff --git a/DOC/HTML/images/keypad.jpg b/DOC/HTML/images/keypad.jpg new file mode 100644 index 0000000..d6e1f3b Binary files /dev/null and b/DOC/HTML/images/keypad.jpg differ diff --git a/DOC/HTML/images/lcd.jpg b/DOC/HTML/images/lcd.jpg new file mode 100644 index 0000000..b38a174 Binary files /dev/null and b/DOC/HTML/images/lcd.jpg differ diff --git a/DOC/HTML/images/ldr-cap.jpg b/DOC/HTML/images/ldr-cap.jpg new file mode 100644 index 0000000..cd34bb8 Binary files /dev/null and b/DOC/HTML/images/ldr-cap.jpg differ diff --git a/DOC/HTML/images/ldr.jpg b/DOC/HTML/images/ldr.jpg new file mode 100644 index 0000000..d49be11 Binary files /dev/null and b/DOC/HTML/images/ldr.jpg differ diff --git a/DOC/HTML/images/leds.jpg b/DOC/HTML/images/leds.jpg new file mode 100644 index 0000000..7b79f72 Binary files /dev/null and b/DOC/HTML/images/leds.jpg differ diff --git a/DOC/HTML/images/meter.jpg b/DOC/HTML/images/meter.jpg new file mode 100644 index 0000000..65ce37d Binary files /dev/null and b/DOC/HTML/images/meter.jpg differ diff --git a/DOC/HTML/images/motor.jpg b/DOC/HTML/images/motor.jpg new file mode 100644 index 0000000..1ddcb82 Binary files /dev/null and b/DOC/HTML/images/motor.jpg differ diff --git a/DOC/HTML/images/msp430.jpg b/DOC/HTML/images/msp430.jpg new file mode 100644 index 0000000..04633f3 Binary files /dev/null and b/DOC/HTML/images/msp430.jpg differ diff --git a/DOC/HTML/images/nano.jpg b/DOC/HTML/images/nano.jpg new file mode 100644 index 0000000..03c3fb1 Binary files /dev/null and b/DOC/HTML/images/nano.jpg differ diff --git a/DOC/HTML/images/oled-2.jpg b/DOC/HTML/images/oled-2.jpg new file mode 100644 index 0000000..622713f Binary files /dev/null and b/DOC/HTML/images/oled-2.jpg differ diff --git a/DOC/HTML/images/oled.jpg b/DOC/HTML/images/oled.jpg new file mode 100644 index 0000000..02f093d Binary files /dev/null and b/DOC/HTML/images/oled.jpg differ diff --git a/DOC/HTML/images/pigpio-logo.gif b/DOC/HTML/images/pigpio-logo.gif new file mode 100644 index 0000000..f0980e1 Binary files /dev/null and b/DOC/HTML/images/pigpio-logo.gif differ diff --git a/DOC/HTML/images/pins.jpg b/DOC/HTML/images/pins.jpg new file mode 100644 index 0000000..60e2f4e Binary files /dev/null and b/DOC/HTML/images/pins.jpg differ diff --git a/DOC/HTML/images/pisc-1.jpg b/DOC/HTML/images/pisc-1.jpg new file mode 100644 index 0000000..a83d4c9 Binary files /dev/null and b/DOC/HTML/images/pisc-1.jpg differ diff --git a/DOC/HTML/images/pisc-2.jpg b/DOC/HTML/images/pisc-2.jpg new file mode 100644 index 0000000..1506017 Binary files /dev/null and b/DOC/HTML/images/pisc-2.jpg differ diff --git a/DOC/HTML/images/pisc-3.jpg b/DOC/HTML/images/pisc-3.jpg new file mode 100644 index 0000000..6b473ff Binary files /dev/null and b/DOC/HTML/images/pisc-3.jpg differ diff --git a/DOC/HTML/images/pot.jpg b/DOC/HTML/images/pot.jpg new file mode 100644 index 0000000..ea386e9 Binary files /dev/null and b/DOC/HTML/images/pot.jpg differ diff --git a/DOC/HTML/images/pro-mini.jpg b/DOC/HTML/images/pro-mini.jpg new file mode 100644 index 0000000..af8f0b9 Binary files /dev/null and b/DOC/HTML/images/pro-mini.jpg differ diff --git a/DOC/HTML/images/psu.jpg b/DOC/HTML/images/psu.jpg new file mode 100644 index 0000000..f848d14 Binary files /dev/null and b/DOC/HTML/images/psu.jpg differ diff --git a/DOC/HTML/images/re-fritz.png b/DOC/HTML/images/re-fritz.png new file mode 100644 index 0000000..2f545b5 Binary files /dev/null and b/DOC/HTML/images/re-fritz.png differ diff --git a/DOC/HTML/images/re-photo.jpg b/DOC/HTML/images/re-photo.jpg new file mode 100644 index 0000000..22c4bfe Binary files /dev/null and b/DOC/HTML/images/re-photo.jpg differ diff --git a/DOC/HTML/images/re-wave-1.png b/DOC/HTML/images/re-wave-1.png new file mode 100644 index 0000000..f8a194d Binary files /dev/null and b/DOC/HTML/images/re-wave-1.png differ diff --git a/DOC/HTML/images/re-wave-2.png b/DOC/HTML/images/re-wave-2.png new file mode 100644 index 0000000..399d7a4 Binary files /dev/null and b/DOC/HTML/images/re-wave-2.png differ diff --git a/DOC/HTML/images/remote-1.jpg b/DOC/HTML/images/remote-1.jpg new file mode 100644 index 0000000..2d28bef Binary files /dev/null and b/DOC/HTML/images/remote-1.jpg differ diff --git a/DOC/HTML/images/remote-2.jpg b/DOC/HTML/images/remote-2.jpg new file mode 100644 index 0000000..d11685a Binary files /dev/null and b/DOC/HTML/images/remote-2.jpg differ diff --git a/DOC/HTML/images/reverse.jpg b/DOC/HTML/images/reverse.jpg new file mode 100644 index 0000000..2eb3804 Binary files /dev/null and b/DOC/HTML/images/reverse.jpg differ diff --git a/DOC/HTML/images/rf-rx-2.jpg b/DOC/HTML/images/rf-rx-2.jpg new file mode 100644 index 0000000..1f1e93c Binary files /dev/null and b/DOC/HTML/images/rf-rx-2.jpg differ diff --git a/DOC/HTML/images/rf-rx.jpg b/DOC/HTML/images/rf-rx.jpg new file mode 100644 index 0000000..c246a4f Binary files /dev/null and b/DOC/HTML/images/rf-rx.jpg differ diff --git a/DOC/HTML/images/rf-tx.jpg b/DOC/HTML/images/rf-tx.jpg new file mode 100644 index 0000000..324d257 Binary files /dev/null and b/DOC/HTML/images/rf-tx.jpg differ diff --git a/DOC/HTML/images/rotary.jpg b/DOC/HTML/images/rotary.jpg new file mode 100644 index 0000000..0f7d224 Binary files /dev/null and b/DOC/HTML/images/rotary.jpg differ diff --git a/DOC/HTML/images/rpi.jpg b/DOC/HTML/images/rpi.jpg new file mode 100644 index 0000000..85ce158 Binary files /dev/null and b/DOC/HTML/images/rpi.jpg differ diff --git a/DOC/HTML/images/serial.jpg b/DOC/HTML/images/serial.jpg new file mode 100644 index 0000000..c2bb917 Binary files /dev/null and b/DOC/HTML/images/serial.jpg differ diff --git a/DOC/HTML/images/servo.jpg b/DOC/HTML/images/servo.jpg new file mode 100644 index 0000000..bbd895c Binary files /dev/null and b/DOC/HTML/images/servo.jpg differ diff --git a/DOC/HTML/images/sidebar.gif b/DOC/HTML/images/sidebar.gif new file mode 100644 index 0000000..89a0620 Binary files /dev/null and b/DOC/HTML/images/sidebar.gif differ diff --git a/DOC/HTML/images/son-fritz.png b/DOC/HTML/images/son-fritz.png new file mode 100644 index 0000000..c864641 Binary files /dev/null and b/DOC/HTML/images/son-fritz.png differ diff --git a/DOC/HTML/images/son-gnup-1.png b/DOC/HTML/images/son-gnup-1.png new file mode 100644 index 0000000..be53824 Binary files /dev/null and b/DOC/HTML/images/son-gnup-1.png differ diff --git a/DOC/HTML/images/son-gnup-2.png b/DOC/HTML/images/son-gnup-2.png new file mode 100644 index 0000000..c552306 Binary files /dev/null and b/DOC/HTML/images/son-gnup-2.png differ diff --git a/DOC/HTML/images/son-photo.jpg b/DOC/HTML/images/son-photo.jpg new file mode 100644 index 0000000..6954f40 Binary files /dev/null and b/DOC/HTML/images/son-photo.jpg differ diff --git a/DOC/HTML/images/son-wave-1.png b/DOC/HTML/images/son-wave-1.png new file mode 100644 index 0000000..96261bc Binary files /dev/null and b/DOC/HTML/images/son-wave-1.png differ diff --git a/DOC/HTML/images/son-wave-2.png b/DOC/HTML/images/son-wave-2.png new file mode 100644 index 0000000..73c8b6d Binary files /dev/null and b/DOC/HTML/images/son-wave-2.png differ diff --git a/DOC/HTML/images/son-wave-3.png b/DOC/HTML/images/son-wave-3.png new file mode 100644 index 0000000..346f5ae Binary files /dev/null and b/DOC/HTML/images/son-wave-3.png differ diff --git a/DOC/HTML/images/son-wave-4.png b/DOC/HTML/images/son-wave-4.png new file mode 100644 index 0000000..ad454ef Binary files /dev/null and b/DOC/HTML/images/son-wave-4.png differ diff --git a/DOC/HTML/images/speaker.jpg b/DOC/HTML/images/speaker.jpg new file mode 100644 index 0000000..2be827b Binary files /dev/null and b/DOC/HTML/images/speaker.jpg differ diff --git a/DOC/HTML/images/spi-lnx-pi3b.png b/DOC/HTML/images/spi-lnx-pi3b.png new file mode 100644 index 0000000..09ee665 Binary files /dev/null and b/DOC/HTML/images/spi-lnx-pi3b.png differ diff --git a/DOC/HTML/images/spi-lnx-pibr1.png b/DOC/HTML/images/spi-lnx-pibr1.png new file mode 100644 index 0000000..3c708e4 Binary files /dev/null and b/DOC/HTML/images/spi-lnx-pibr1.png differ diff --git a/DOC/HTML/images/spi-pig-pi3b.png b/DOC/HTML/images/spi-pig-pi3b.png new file mode 100644 index 0000000..602922c Binary files /dev/null and b/DOC/HTML/images/spi-pig-pi3b.png differ diff --git a/DOC/HTML/images/spi-pig-pibr1.png b/DOC/HTML/images/spi-pig-pibr1.png new file mode 100644 index 0000000..308f25d Binary files /dev/null and b/DOC/HTML/images/spi-pig-pibr1.png differ diff --git a/DOC/HTML/images/srf02.jpg b/DOC/HTML/images/srf02.jpg new file mode 100644 index 0000000..22486f8 Binary files /dev/null and b/DOC/HTML/images/srf02.jpg differ diff --git a/DOC/HTML/images/srf04.jpg b/DOC/HTML/images/srf04.jpg new file mode 100644 index 0000000..632d194 Binary files /dev/null and b/DOC/HTML/images/srf04.jpg differ diff --git a/DOC/HTML/images/stepper.jpg b/DOC/HTML/images/stepper.jpg new file mode 100644 index 0000000..11a1473 Binary files /dev/null and b/DOC/HTML/images/stepper.jpg differ diff --git a/DOC/HTML/images/switches.jpg b/DOC/HTML/images/switches.jpg new file mode 100644 index 0000000..6cd1df5 Binary files /dev/null and b/DOC/HTML/images/switches.jpg differ diff --git a/DOC/HTML/images/topbar.gif b/DOC/HTML/images/topbar.gif new file mode 100644 index 0000000..27ae71f Binary files /dev/null and b/DOC/HTML/images/topbar.gif differ diff --git a/DOC/HTML/images/transistors.jpg b/DOC/HTML/images/transistors.jpg new file mode 100644 index 0000000..6f6a14f Binary files /dev/null and b/DOC/HTML/images/transistors.jpg differ diff --git a/DOC/HTML/images/ubec-2.jpg b/DOC/HTML/images/ubec-2.jpg new file mode 100644 index 0000000..8fe87ce Binary files /dev/null and b/DOC/HTML/images/ubec-2.jpg differ diff --git a/DOC/HTML/images/uln2003a.jpg b/DOC/HTML/images/uln2003a.jpg new file mode 100644 index 0000000..aeebee4 Binary files /dev/null and b/DOC/HTML/images/uln2003a.jpg differ diff --git a/DOC/HTML/images/wheel.jpg b/DOC/HTML/images/wheel.jpg new file mode 100644 index 0000000..f274a2d Binary files /dev/null and b/DOC/HTML/images/wheel.jpg differ diff --git a/DOC/HTML/images/wires.jpg b/DOC/HTML/images/wires.jpg new file mode 100644 index 0000000..9574f90 Binary files /dev/null and b/DOC/HTML/images/wires.jpg differ diff --git a/DOC/HTML/images/yl-40.jpg b/DOC/HTML/images/yl-40.jpg new file mode 100644 index 0000000..1320405 Binary files /dev/null and b/DOC/HTML/images/yl-40.jpg differ diff --git a/DOC/HTML/scripts/index.css b/DOC/HTML/scripts/index.css new file mode 100644 index 0000000..64cfd33 --- /dev/null +++ b/DOC/HTML/scripts/index.css @@ -0,0 +1,52 @@ +body +{ +font-size: 100%; +font-family: Arial, Helvetica, sans-serif; +color: #101010; +margin-left: 1%; margin-right: 10%; +} + +h1 {font-size: 2.4em; color: #5d9dce; font-weight: bold;} +h2 {font-size: 1.8em; color: #5d9dce; font-weight: bold;} +h3 {font-size: 1.4em; color: #5d9dce; font-weight: bold;} +h4 {font-size: 1.2em; color: #5d9dce;} +h5 {font-size: 1.0em; color: #5d9dce;} +h6 {font-size: 0.8em; color: #5d9dce;} + +code {display:block;font-size:80%; font-family: "Courier New", Courier, monospace; background-color:#D0D0D0;} +pre {font-size:80%; font-family: Courier; background-color:#D0D020;} + +table.ev +{ +border: 3px solid green; +} + +td.ev1 +{ +width: 200px; +border: 1px solid green; +} + +td.ev2 +{ +border: 1px solid green; +} + +a.l1:link,a.l1:visited +{ +display:block; +font-weight:bold; +color:#FFFFFF; +background-color:#98bf21; +width:120px; +text-align:center; +padding:4px; +text-decoration:none; +} + +a.l1:hover,a.l1:active +{ +background-color:#7A991A; +} + + diff --git a/DOC/HTML/scripts/standard.css b/DOC/HTML/scripts/standard.css new file mode 100644 index 0000000..ad0415b --- /dev/null +++ b/DOC/HTML/scripts/standard.css @@ -0,0 +1,3 @@ +html { height: 100% } +body { height: 100%; margin: 0px; padding: 0px } +#map_canvas { height: 100% } diff --git a/DOC/README b/DOC/README new file mode 100644 index 0000000..19a1516 --- /dev/null +++ b/DOC/README @@ -0,0 +1,16 @@ +bin various scripts to generate man pages and HTML + +dbase defines the structure of the web documentation + +HTML auto generated html web site + +makedoc run to regenerate documentation + +MAN auto generated man pages + +src/defs edit to change pigs, pigpiod, pig2vcd, and examples docs + +src/html edit to change the fairly invariant web pages + DO NOT ADD auto generated HTML to this directory + +tmp stores temporary files, may be deleted diff --git a/DOC/bin/backup.sh b/DOC/bin/backup.sh new file mode 100755 index 0000000..6a45c48 --- /dev/null +++ b/DOC/bin/backup.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# backup database +cp dbase/pigpio.sqlite dbase/pigpio.sqlite.bak + diff --git a/DOC/bin/body.py b/DOC/bin/body.py new file mode 100755 index 0000000..9e4c437 --- /dev/null +++ b/DOC/bin/body.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import glob + +for fn in glob.glob("src/html/*.html"): + f = open(fn) + h = f.read() + f.close() + s1,d1,e1=h.partition("") + s2,d2,e2=e1.partition("") + f = open("tmp/body/" + fn[9:-5] + ".body", "w") + f.write(s2) + f.close() + diff --git a/DOC/bin/build_site.py b/DOC/bin/build_site.py new file mode 100755 index 0000000..c153150 --- /dev/null +++ b/DOC/bin/build_site.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import os +import sqlite3 + +db=sqlite3.connect("dbase/pigpio.sqlite") + +c=db.cursor() + +c.execute("select file_name from pigpio") + +names = c.fetchall() + +for n in names: + os.system("bin/html.py {0} >HTML/{0}.html".format(n[0])) + print(n[0]) + +c.close() + +db.close() + diff --git a/DOC/bin/cmakdoc.py b/DOC/bin/cmakdoc.py new file mode 100755 index 0000000..dd1bd52 --- /dev/null +++ b/DOC/bin/cmakdoc.py @@ -0,0 +1,563 @@ +#!/usr/bin/env python3 + +import sys + +pigpio_m1=""" +.\" Process this file with +.\" groff -man -Tascii pigpio.3 +.\" +.TH pigpio 3 2012-2020 Linux "pigpio archive" +.SH NAME +pigpio - A C library to manipulate the Pi's GPIO.\n +.SH SYNOPSIS\n +#include \n + +gcc -Wall -pthread -o prog prog.c -lpigpio -lrt\n +sudo ./prog +.SH DESCRIPTION\n +""" + +pigpiod_if_m1=""" +.\" Process this file with +.\" groff -man -Tascii pigpiod_if.3 +.\" +.TH pigpiod_if 3 2012-2020 Linux "pigpio archive" +.SH NAME +pigpiod_if - A C library to interface to the pigpio daemon.\n +.SH SYNOPSIS\n +#include \n + +gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt\n + ./prog +.SH DESCRIPTION\n +""" + +pigpiod_if2_m1=""" +.\" Process this file with +.\" groff -man -Tascii pigpiod_if2.3 +.\" +.TH pigpiod_if2 3 2012-2020 Linux "pigpio archive" +.SH NAME +pigpiod_if2 - A C library to interface to the pigpio daemon.\n +.SH SYNOPSIS\n +#include \n + +gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt\n + ./prog +.SH DESCRIPTION\n +""" + +pigpiod_m1=""" +.\" Process this file with +.\" groff -man -Tascii pigpiod.1 +.\" +.TH pigpiod 1 2012-2020 Linux "pigpio archive" +.SH NAME +pigpiod - A utility to start the pigpio library as a daemon.\n +.SH SYNOPSIS\n +sudo pigpiod [OPTION]... +.SH DESCRIPTION\n +""" + +pig2vcd_m1=""" +.\" Process this file with +.\" groff -man -Tascii pig2vcd.1 +.\" +.TH pig2vcd 1 2012-2020 Linux "pigpio archive" +.SH NAME +pig2vd - A utility to convert pigpio notifications to VCD.\n +.SH SYNOPSIS\n +pig2vcd file.VCD +.SH DESCRIPTION\n +""" + +pigpio_m2=""" +.SH SEE ALSO\n +pigpiod(1), pig2vcd(1), pigs(1), pigpiod_if(3), pigpiod_if2(3) +.SH AUTHOR\n +joan@abyz.me.uk +""" + +pigpiod_if_m2=""" +.SH SEE ALSO\n +pigpiod(1), pig2vcd(1), pigs(1), pigpio(3), pigpiod_if2(3) +.SH AUTHOR\n +joan@abyz.me.uk +""" + +pigpiod_if2_m2=""" +.SH SEE ALSO\n +pigpiod(1), pig2vcd(1), pigs(1), pigpio(3), pigpiod_if(3) +.SH AUTHOR\n +joan@abyz.me.uk +""" + +pigpiod_m2=""" +.SH SEE ALSO\n +pig2vcd(1), pigs(1), pigpio(3), pigpiod_if(3), pigpiod_if2(3) +.SH AUTHOR\n +joan@abyz.me.uk +""" + +pig2vcd_m2=""" +.SH SEE ALSO\n +pigpiod(1), pigs(1), pigpio(3), pigpiod_if(3), pigpiod_if2(3) +.SH AUTHOR\n +joan@abyz.me.uk +""" + + +def emit(s): + sys.stdout.write(s) + +def get_line(f): + line = f.readline() + if man: + line = line.replace(" \n", "\n.br\n") + else: + line = line.replace("<", "<") + line = line.replace(">", ">") + line = line.replace(" \n", "
\n") + return line + +def nostar(k): + if k[0] == "*": + return k[1:] + else: + return k + +NONE =0 +MAN =1 +TEXT =2 +OVERVIEW=4 +FUNC =5 +DESC =6 +OPT =7 +PARAMS =8 +DEFS =9 + +param_used = [] +param_defd = [] +param_refd = [] + +at = NONE + +in_code = False +in_pard = False +in_table = False + +if len(sys.argv) > 2: + obj = sys.argv[1] + fn = sys.argv[2] + if len(sys.argv) > 3: + man = True + else: + man = False +else: + exit("bad args, need page file [man]") +try: + f = open(fn, "r") +except: + exit("aborting, can't open {}".format(fn)) + +if man: + if obj == "pigpio": + emit(pigpio_m1) + elif obj == "pigpiod_if": + emit(pigpiod_if_m1) + elif obj == "pigpiod_if2": + emit(pigpiod_if2_m1) + elif obj == "pigpiod": + emit(pigpiod_m1) + elif obj == "pig2vcd": + emit(pig2vcd_m1) + + emit("\n.ad l\n") + emit("\n.nh\n") + +while True: + + line = get_line(f) + + if line == "": + for p in param_used: + if p not in param_defd: + sys.stderr.write("{} used but not defined.\n".format(p)) + for p in param_defd: + if p not in param_used and p not in param_refd: + sys.stderr.write("{} defined but not used.\n".format(p)) + break + + if line == "/*MAN\n": + at = MAN + continue + + elif line == "MAN*/\n": + at = NONE + continue + + if line == "/*TEXT\n": + at = TEXT + continue + + elif line == "TEXT*/\n": + at = NONE + continue + + elif line == "/*OVERVIEW\n": + + if man: + emit("\n.SH OVERVIEW\n") + else: + emit("

OVERVIEW

") + emit( + "") + + at = OVERVIEW + continue + + elif line == "OVERVIEW*/\n": + + if man: + emit(".SH FUNCTIONS\n") + else: + emit("
") + emit("

FUNCTIONS

") + + at = NONE + + elif line == "/*F*/\n": + in_code = False + fdef="" + line = get_line(f) + at = FUNC + + elif line == "/*D\n": + # Function definition should be complete. + fdef = fdef.replace("\n", " ") + + while fdef.find(" ") != -1: + fdef = fdef.replace(" ", " ") + + fdef = fdef.replace("( ", "(") + + (rf, sep1, end1) = fdef.partition("(") + (parl, sep2, end2) = end1.partition(")") + tps = parl.split(",") + rf = rf.split(" ") + ret = rf[0] + func = rf[1] + + if ret not in param_used: + param_used.append(ret) + + if man: + t = "\\fB" + ret + " " + func + "(" + parl + ")\\fP" + emit("\n.IP \"{}\"\n.IP \"\" 4\n".format(t)) + else: + emit("

{} {}". + format(nostar(func), ret, ret,func)) + emit("(") + + x = 0 + for tp in tps: + tp = tp.strip() + (t, sep3, p) = tp.partition(" ") + t = t.strip() + p = p.strip() + if (p != ""): + if p not in param_used: + param_used.append(p) + if t not in param_used: + param_used.append(t) + if x > 0: + + if man: + pass + else: + emit(", ") + + x += 1 + + if man: + pass + else: + + emit("{} {}". + format(t, t, p, p)) + + else: + + if man: + pass + else: + emit("{}".format(t)) + + if man: + pass + else: + emit(")

\n") + + line = get_line(f) + at = DESC + + elif line == "D*/\n": + at = NONE + + elif line == "/*O\n": + if man: + emit(".SH OPTIONS\n") + else: + emit("") + at = OPT + continue + + elif line == "O*/\n": + if man: + pass + else: + emit("
") + at = NONE + continue + + elif line == "/*PARAMS\n": + last_par = "*" + + if man: + emit(".SH PARAMETERS\n") + else: + emit("

PARAMETERS

") + + at = PARAMS + continue + + elif line == "PARAMS*/\n": + at = NONE + + elif line.startswith("/*DEF_S "): + title = line[8:-3] + in_code = True + if man: + emit(".SH {}\n".format(title)) + emit("\n.EX\n") + else: + emit("

{}

".format(title)) + emit("") + at = DEFS + continue + + elif line == "/*DEF_E*/\n": + in_code = False + if man: + emit("\n.EE\n") + else: + emit("") + at = NONE + continue + + + if at != NONE and at != OVERVIEW: + if line.find("@") != -1: + if not in_table: + in_table = True + + if man: + pass + else: + emit("") + + if man: + line = line.replace("@", " ") + emit(line) + # emit("\n.br\n") + emit(".br\n") + else: + emit("") + cols = line.split("@") + for col in cols: + emit("".format(col.strip())) + emit("") + + continue + + else: + if in_table: + in_table = False + + if man: + pass + else: + emit("
{}
") + + if line == "...\n" or line == ". .\n": + if in_code: + in_code = False + + if man: + emit("\n.EE\n") + else: + emit("") + + else: + in_code = True + if line == "...\n": + + if man: + emit("\\fBExample\\fP\n.br\n") + else: + emit("Example

") + + if man: + emit("\n.EX\n") + else: + emit("") + + continue + + if line == "\n": + + if man: + emit("\n.br\n") + else: + emit("
") + + if not in_code: + if man: + emit("\n.br\n") + else: + emit("
") + + continue + + if in_code: + + if man: + line = line.replace("\n", "\n.br\n") + else: + line = line.replace(" ", " ") + line = line.replace("\n", "
") + + while line.find("[*") != -1 and line.find("*]") != -1: + (b, s, e) = line.partition("[*") + (l, s, e) = e.partition("*]") + + if man: + line = "{}\\fB{}\\fP{}".format(b, l, e) + else: + line = "{}{}{}".format(b, l, l, e) + + if l not in param_refd: + param_refd.append(l) + + while line.find("[[") != -1 and line.find("]]") != -1: + (b, s, e) = line.partition("[[") + (l, s, e) = e.partition("]]") + + if man: + line = "{}\\fB{}\\fP{}".format(b, l, e) + else: + line = "{}{}{}".format(b, l, l, e) + + if at == TEXT: + if line[0] == '*' and line[-2] == '*': + if man: + emit(".SS {}".format(line[1:-2])) + else: + emit("

{}

".format(line[1:-2])) + elif line[0] == '^' and line[-2] == '^': + if man: + emit(".SS {}".format(line[1:-2])) + else: + emit("
{}
".format(line[1:-2])) + else: + emit(line) + + elif at == OVERVIEW: + if line == "\n": + + if man: + emit("\n.br\n") + else: + emit("") + + else: + (func, sep, desc) = line.partition(" ") + if desc != "": + + if man: + emit("\n.br\n{}".format(line.strip())) + else: + emit("{}{}". + format(func, func, desc)) + + else: + + if man: + emit(".SS {}".format(line.replace("_", " ").strip())) + else: + emit("{}". + format(func.replace("_", " "))) + + elif at == FUNC: + fdef += line + + elif at == DESC: + emit(line) + + elif at == PARAMS: + if line.find("::") != -1: + (par, sep, end) = line.partition("::") + par = par.strip() + end = end.strip() + + if nostar(par.lower()) < nostar(last_par.lower()): + sys.stderr.write("Out of order {} after {}.\n". + format(par, last_par)) + last_par = par + + if par in param_defd: + sys.stderr.write("Duplicate definition of {}.\n".format(par)) + else: + param_defd.append(par) + + if end != "": + end = ": " + end + if man: + emit("\n.IP \"\\fB{}\\fP{}\" 0\n".format(par, end)) + else: + emit("

{}{}

\n".format(par, par, end)) + + else: + emit(line) + + elif at == MAN: + if man: + emit(line) + + elif at == OPT: + line = line.split("|") + if man: + emit("\n.IP \"\\fB{}\\fP\"\n{}.\n{}.\n{}.".format( + line[0], line[1], line[2], line[3])) + else: + emit("{}{}{}{}". + format(line[0], line[1], line[2], line[3])) + + elif at == DEFS: + emit(line) + +if man: + if obj == "pigpio": + emit(pigpio_m2) + elif obj == "pigpiod_if": + emit(pigpiod_if_m2) + elif obj == "pigpiod_if2": + emit(pigpiod_if2_m2) + elif obj == "pigpiod": + emit(pigpiod_m2) + elif obj == "pig2vcd": + emit(pig2vcd_m2) + + +f.close() + diff --git a/DOC/bin/examples.py b/DOC/bin/examples.py new file mode 100755 index 0000000..e389341 --- /dev/null +++ b/DOC/bin/examples.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 + +import sys +from collections import OrderedDict + +def emit(s): + sys.stdout.write(s) + +def get_line(f): + line = f.readline() + return line + +def get_file(): + try: + fn = sys.argv[1] + f = open(fn, "r") + except: + exit("aborting, can't open {}".format(fn)) + return f + +def cancel_row(): + global in_row + if in_row: + in_row = False + emit('') + +def start_row(): + global in_row + if not in_row: + in_row = True + emit('') + +def cancel_table(): + global in_table + if in_table: + in_table = False + cancel_row() + emit('') + +def start_table(): + global in_table + if not in_table: + in_table = True + emit('') + else: + cancel_row() + start_row() + +index = {} + +in_code = False +in_samp = False +in_table = False +in_row = False + +f = get_file() + +while True: + + line = get_line(f) + + if line == "": + cancel_table() + + emit('
\n') + last = None + ordered = OrderedDict(sorted(index.items(), key=lambda t: t[1].lower())) + for k,v in ordered.items(): + tag=k.split('_')[0] + if last != v.lower(): + if last is not None: + emit('') + last = v.lower() + anchor="index_"+last.replace(" ", "_") + emit('
'+v+'') + emit(' '+tag+'\n') + emit('
') + break + + if line.startswith("?0|"): + s = line.split("|") + anchor=s[1].strip() + emit(''+anchor+'
') + continue + + if line.startswith("?1|"): + cancel_table() + s = line.split("|") + tag = s[1].strip()+"_" + anchor=s[2].strip() + emit('

'+anchor+'

') + continue + + elif line.startswith("?2|") or line.startswith("?3|") or line.startswith("?4|"): + start_table() + + s = line.split("|") + + anchor=tag+s[1].strip() + + if line.startswith("?2|"): + link=s[1].strip()+".html" + elif line.startswith("?3|"): + link="code/"+s[1].strip()+".zip" + elif line.startswith("?4|"): + link=s[1].strip() + else: + link="code/"+s[1].strip() + + date=s[2].strip() + + title=s[3].strip() + emit(''+title+'
'+date+'
') + + index.update({anchor:title}) + + continue + + else: + emit(line.replace("\n", "
\n")) + +f.close() + diff --git a/DOC/bin/html.py b/DOC/bin/html.py new file mode 100755 index 0000000..1259430 --- /dev/null +++ b/DOC/bin/html.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 + +import sys +import sqlite3 +import time + +i_file_name = 0 +i_menu_title = 1 +i_menu_pos = 2 +i_menu_level = 3 +i_page_title = 4 +i_pic1 = 5 +i_pic2 = 6 +i_pic3 = 7 +i_body = 8 + +print(""" + + + + + + + pigpio library + + + + + +""") + +page = sys.argv[1] + +menuH = "" +menuV = "" +sitemap = "" + +header = 'pigpio library' + +footer1 = "© 2012-2020"; +footer2 = "e-mail: pigpio @ abyz.me.uk"; +footer3 = "Updated: " + time.strftime("%d/%m/%Y") + ""; + +db=sqlite3.connect("dbase/pigpio.sqlite") + +c=db.cursor() + +def menu_titles(): + + global menuV, menuH + + c.execute( + "SELECT file_name, menu_title, menu_level FROM pigpio ORDER by menu_pos") + + recs = c.fetchall() + + menuV = "" + menuH = "" + + for r in recs: + if r[2] == 1: + menuV += '' + r[1] + '\n' + menuH += '[' + r[1] + ']\n' + +def sitemap(): + + c.execute( + "SELECT file_name, menu_title, menu_level FROM pigpio ORDER by menu_pos") + + recs = c.fetchall() + + stemap = "" + + for r in recs: + if r[2] > 0: + s = "----" * (r[2]-1) + stemap += s + '' + r[1] + '
\n' + + return stemap + +def check_image(d): + + img = "images/" + d + + try: + with open("HTML/" + img) as f: + print('') + except: + pass + +titles = menu_titles() + +s_sidebar = 'style="background:#EAF2E6 url(\'images/sidebar.gif\') repeat-y; width:35px; height:100%"' + +s_header = 'style="background:url(\'images/topbar.gif\') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"' + +s_menuV = 'style="vertical-align: top; background-color: #98bf21;"' + +c.execute("SELECT * FROM pigpio WHERE file_name=?", (page,)) + +rec = c.fetchone() + +if page == "sitemap": + body = sitemap() +else: + body = rec[i_body] + +c.close() +db.close() + +print('') +print('') +print('') +print('
') +print('') +print('
' + header + '
') +print('
') +print('
') +check_image(rec[i_pic1]) +check_image(rec[i_pic2]) +check_image(rec[i_pic3]) +print('
') +print("") +print('') +print('') +print('
' + menuV + '

' + rec[i_page_title] + '

' + body + '
') +print('
' + menuH + '
') +print('') +print('') +print('') +print('') +print('
' + footer1 + '
' + footer2 + '
' + footer3 + '
') +print('
') + +print('\n') + diff --git a/DOC/bin/purge.sh b/DOC/bin/purge.sh new file mode 100755 index 0000000..54553bb --- /dev/null +++ b/DOC/bin/purge.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# if backup same as new delete it +if cmp -s dbase/pigpio.sqlite dbase/pigpio.sqlite.bak +then + rm dbase/pigpio.sqlite.bak +else + d=$(date "+%F-%H-%M-%S") + mv -f dbase/pigpio.sqlite.bak dbase/pigpio.sqlite.$d +fi + +# delete backups older than a week +find dbase/pigpio.sqlite.2* -mtime +7 -delete &>/dev/null + diff --git a/DOC/bin/pymakdoc.py b/DOC/bin/pymakdoc.py new file mode 100755 index 0000000..c2a6e87 --- /dev/null +++ b/DOC/bin/pymakdoc.py @@ -0,0 +1,270 @@ +#!/usr/bin/env python3 + +import sys + +def emit(s): + sys.stdout.write(s) + +def str2hex(s): + return ":".join("{:02x}".format(ord(c)) for c in s) + +def funchdr(line): + if len(line) > 1 and (not line.startswith(" ")) and line.find("(") != -1: + return True + else: + return False + +def get_line(f): + line = f.readline() + line = line.replace("<", "<") + line = line.replace(">", ">") + return line + +def get_file(): + try: + fn = sys.argv[1] + f = open(fn, "r") + except: + exit("aborting, can't open {}".format(fn)) + return f + + +NONE = 0 +DESCRIPTION = 1 +OVERVIEW = 2 +CLASSES = 3 +CLASS = 4 +FUNC = 5 +XREF = 6 +DATA = 7 + +f = get_file() + +param_used = [] +param_defd = [] +param_refd = [] + +at = NONE + +in_code = False +in_samp = False +in_table = False +left = 0 + +while True: + + line = get_line(f) + + if line == "": + for p in param_used: + if p not in param_defd: + sys.stderr.write("{} is used but not defined.\n".format(p)) + for p in param_defd: + if p not in param_used and p not in param_refd: + sys.stderr.write("{} is defined but not used.\n".format(p)) + break + + if line.startswith("DESCRIPTION"): + left = 4 + at = DESCRIPTION + continue + + elif line.startswith(" OVERVIEW"): + left = 4 + emit("

OVERVIEW

") + emit( + "") + at = OVERVIEW + continue + + elif line.startswith("CLASSES"): + left = 4 + emit("
") + at = NONE + continue + + elif line.startswith(" class "): + in_func = False + if line.startswith(" class error"): + at = NONE + else: + left = 8 + emit("

{}

".format(line)) + _class = line[10:-1] + at = CLASS + continue + + elif line.startswith("FUNCTIONS"): + left = 4 + emit("

FUNCTIONS

") + in_func = False + at = FUNC + continue + + elif line.startswith(" xref()"): + left = 8 + emit("

PARAMETERS

") + in_func = False + last_par = "" + at = XREF + continue + + elif line.startswith("DATA"): + at = DATA + continue + + line = line[left:] + + at_funchdr = funchdr(line) + + if at != NONE and at != OVERVIEW: + + if at == CLASS or at == FUNC: + + if not at_funchdr: + line = line[4:] + + line = line.replace(' \n', '
') + + if line.find('@') != -1: + if not in_table: + in_table = True + emit("") + emit("") + cols = line.split('@') + for col in cols: + emit("".format(col.strip())) + emit("") + continue + else: + if in_table: + in_table = False + emit("
{}
") + + if line.find(":=") != -1: + if not in_samp: + emit("
Parameters

") + in_samp = True + + if line == '...\n' or line == '. .\n': + if in_code: + in_code = False + emit("
") + else: + in_code = True + if line == '...\n': + emit("Example

") + emit("") + continue + + if line == '\n' or line == '': + if in_samp: + emit("") + in_samp = False + emit('
') + if not in_code: + emit('
') + continue + + if in_code or in_samp: + line = line.replace(" ", " ") + line = line.replace("\n", "
") + + while line.find('[*') != -1 and line.find('*]') != -1: + (b, s, e) = line.partition('[*') + (l, s, e) = e.partition('*]') + line = '{}{}{}'.format(b, l, l, e) + if l not in param_refd: + param_refd.append(l) + + while line.find('[[') != -1 and line.find(']]') != -1: + (b, s, e) = line.partition('[[') + (l, s, e) = e.partition(']]') + line = '{}{}{}'.format(b, l, l, e) + + if at == DESCRIPTION: + if line[0] == '*' and line[-2] == '*': + emit("

{}

".format(line[1:-2])) + elif line[0] == '[' and line[-2] == ']': + pass + else: + emit(line) + + elif at == OVERVIEW: + if line == "\n": + emit("") + else: + (func, sep, desc) = line.partition(' ') + if desc != '': + emit("{}{}". + format(func, func, desc)) + else: + emit("{}". + format(func).replace("_", " ")) + + elif at == CLASS or at == FUNC: + if at_funchdr: + in_func = True + + if in_code: + emit("
***C***
") + in_code = False + + if in_samp: + emit("
***S***") + in_samp = False + + (func, sep1, end1) = line.partition("(") + (parl, sep2, end2) = end1.partition(")") + pars = parl.split(",") + + func = func.strip() + + if at == FUNC: + func = "pigpio." + func + else: + if func == "__init__": + func = "pigpio." + _class + + emit("

{}".format(func,func)) + + emit('(') + + x = 0 + for p in pars: + (p, sep3, end3) = p.partition('=') + p = p.strip() + if (p != 'self') and (p != '...') and (p != ''): + if p not in param_used: + param_used.append(p) + if x > 0: + emit(", ") + x += 1 + emit("{}".format(p, p)) + emit(')

\n') + + else: + if in_func: + emit(line) + + elif at == XREF: + if line.find(':') != -1: + (par, sep, end) = line.partition(':') + par = par.strip() + end = end.strip() + emit("

{}: {}

".format(par, par, end)) + + if par.lower() < last_par.lower(): + sys.stderr.write("Out of order {} after {}.\n". + format(par, last_par)) + last_par = par + + if par in param_defd: + sys.stderr.write("Duplicate definition of {}.\n".format(par)) + else: + param_defd.append(par) + else: + emit(line) + +f.close() + diff --git a/DOC/bin/smakdoc.py b/DOC/bin/smakdoc.py new file mode 100755 index 0000000..a36975f --- /dev/null +++ b/DOC/bin/smakdoc.py @@ -0,0 +1,376 @@ +#!/usr/bin/env python3 + +import sys + +def get_file(): + try: + fn = sys.argv[1] + f = open(fn, "r") + except: + exit("aborting, can't open {}".format(fn)) + return f + +def emit(s): + sys.stdout.write(s) + +def str2hex(s): + return ":".join("{:02x}".format(ord(c)) for c in s) + +def get_line(f): + line = f.readline() + if man: + line = line.replace(" \n", "\n.br\n") + else: + line = line.replace("<", "<") + line = line.replace(">", ">") + line = line.replace(" \n", "
\n") + return line + +if len(sys.argv) > 2: # Are we creating a man page? + man = True +else: + man = False + +NONE=0 +INTRO=1 +OVERVIEW=2 +COMMANDS=3 +PARAMETERS=4 +SCRIPTS=5 + +param_used = [] +param_defd = [] + +f = get_file() + +at = NONE + +in_table = False +in_code = False + +funcdef ={} + +if man: + emit(""" +.\" Process this file with +.\" groff -man -Tascii foo.1 +.\" +.TH pigs 1 2012-2020 Linux "pigpio archive" +.SH NAME +pigs - command line socket access to the pigpio daemon.\n +/dev/pigpio - command line pipe access to the pigpio daemon.\n +.SH SYNOPSIS\n +.B sudo pigpiod\n +then\n +.B pigs {command}+\n +or\n +.B \"echo {command}+ >/dev/pigpio\"\n +.SH DESCRIPTION\n +.ad l\n +.nh\n +""") + +while True: + + line = get_line(f) + + if line == "": + for p in param_used: + if p not in param_defd: + sys.stderr.write("{} used but not defined.\n".format(p)) + for p in param_defd: + if p not in param_used: + sys.stderr.write("{} defined but not used.\n".format(p)) + break + + if line.startswith("INTRO"): + line = get_line(f) + + if man: + pass + else: + emit("

Introduction

\n") + + at = INTRO + + elif line.startswith("OVERVIEW"): + line = get_line(f) + + if man: + emit("\n.SH OVERVIEW\n") + else: + emit("

Overview

\n") + emit( + "") + at = OVERVIEW + + elif line.startswith("COMMANDS"): + line = get_line(f) + + if man: + emit("\n.SH COMMANDS\n") + else: + emit("
") + emit("

Commands

\n") + + funcs = sorted(funcdef) + at = COMMANDS + + elif line.startswith("PARAMETERS"): + line = get_line(f) + last_par = "" + + if man: + emit("\n.SH PARAMETERS\n") + else: + emit("

Parameters

\n") + + at = PARAMETERS + + elif line.startswith("SCRIPTS"): + line = get_line(f) + + if man: + emit("\n.SH SCRIPTS\n") + else: + emit("

Scripts

\n") + + at = SCRIPTS + + if at != NONE: + if line.find("@") != -1: + if not in_table: + in_table = True + + if man: + emit("\n.EX\n") + else: + emit("") + if man: + pass + else: + emit("") + + if man: + line = line.replace("@", " ") + emit(line) + else: + cols = line.split("@") + for col in cols: + emit("".format(col.strip())) + + if man: + pass + else: + emit("") + continue + else: + if in_table: + in_table = False + + if man: + emit("\n.EE\n") + else: + emit("
{}
") + + if line == "...\n" or line == ". .\n": + if in_code: + in_code = False + + if man: + emit("\n.EE\n") + else: + emit("") + + else: + in_code = True + + if at == COMMANDS: + + if line == "...\n": + if man: + emit("\n\\fBExample\\fP\n.br\n") + else: + emit("Example

") + + if man: + emit("\n.EX\n") + else: + emit("") + + continue + + if line == "\n" and at != OVERVIEW: + if man: + # emit("\n.br\n.br\n") + emit("\n.br\n") + else: + emit("

") + continue + + if in_code: + if man: + line = line.replace("\n", "\n.br\n") + else: + line = line.replace(" ", " ") + line = line.replace("\n", "
") + + while line.find("[*") != -1 and line.find("*]") != -1: + (b, s, e) = line.partition("[*") + (l, s, e) = e.partition("*]") + if man: + line = "{}\\fB{}\\fP{}".format(b, l, e) + else: + line = "{}{}{}".format(b, l, l, e) + + while line.find("[{") != -1 and line.find("}]") != -1: + (b, s, e) = line.partition("[[") + (l, s, e) = e.partition("]]") + + if man: + line = "{}\\fB{}\\fP{}".format(b, l, e) + else: + line = "{}{}{}".format(b, l, l, e) + + if at == INTRO or at == SCRIPTS: + if line[0] == "*" and line[-2] == "*": + if man: + emit(".SS {}".format(line[1:-2])) + else: + emit("

{}

".format(line[1:-2])) + else: + emit(line) + + elif at == OVERVIEW: + if line == "\n": + + if man: + pass + else: + emit("") + + elif line.find("::") == -1: + + if man: + emit(".SS {}".format(line)) + else: + emit("{}".format(line)) + else: + (funcpar, sep, desc) = line.partition("::") + funcpar = funcpar.strip() + desc = desc.strip() + if desc != "": + (func, sep, parl) = funcpar.partition(" ") + func = func.strip() + parl = parl.strip() + if func in funcdef: + sys.stderr.write("{} has been redefined.\n".format(func)) + funcdef[func]=parl+"::"+desc + + if man: + emit(".B {}\n".format(func+" "+parl+" ")) + pass + else: + emit("{}".format(func, func)) + + pars = parl.split() + + for p in pars: + + if p not in param_used: + param_used.append(p) + + if man: + pass + else: + emit(" {}".format(p, p)) + + (des, sep, c) = desc.partition("::") + c = c.strip() + + if man: + emit("{}\n.P\n".format(des)) + pass + else: + emit("{}{}".format(des, c, c)) + + else: + if man: + pass + else: + emit("{}".format(funcpar)) + + if man: + # emit(".IP {} 9\n".format(func)) + pass + else: + emit("{}".format(func, func)) + + + elif at == COMMANDS: + if line.find("::") != -1: + (func, sep, desc) = line.partition("::") + func = func.strip() + + if func not in funcdef: + parl="unknown" + desc="unknown" + else: + (parl,sep,desc) = funcdef[func].partition("::") + + (des, sep, c) = desc.partition("::") + + if man: + t = "\\fB" + func + " " + parl + "\\fP" + " - " + des.strip() + emit("\n.IP \"{}\"\n.IP \"\" 4\n".format(t)) + else: + emit("

{}\n".format(func,func)) + + pars = parl.split() + for p in pars: + + if man: + pass + else: + emit(" {}".format(p, p)) + + if man: + pass + else: + emit(" - {}

".format(des.strip())) + + else: + emit(line) + + elif at == PARAMETERS: + if line.find("::") != -1: + (par, sep, desc) = line.partition("::") + par = par.strip() + desc = desc.strip() + + if par.lower() < last_par.lower(): + sys.stderr.write("Out of order {} after {}.\n".format(par, last_par)) + last_par = par + + if par in param_defd: + sys.stderr.write("Duplicate definition of {}.\n".format(par)) + else: + param_defd.append(par) + + if man: + emit("\n.IP \"\\fB{}\\fP - {}\" 0\n".format(par, desc)) + else: + emit("

{} - {}

\n".format(par,par,desc)) + else: + emit(line) + +if man: + emit(""" +.SH SEE ALSO\n +pigpiod(1), pig2vcd(1), pigpio(3), pigpiod_if(3), pigpiod_if2(3) +.SH AUTHOR\n +joan@abyz.me.uk +""") + +f.close() + diff --git a/DOC/bin/tidy.py b/DOC/bin/tidy.py new file mode 100755 index 0000000..4a789f4 --- /dev/null +++ b/DOC/bin/tidy.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import glob + +def snafu(t, s, r): + l = t + while l.find(s) != -1: + l = l.replace(s, r) + return l + +for n in glob.glob("tmp/body/*.body"): + + f = open(n, "r"); + t = f.read() + f.close() + + t = snafu(t, "

", "

") + t = snafu(t, "

", "

") + t = snafu(t, "


", "") + t = snafu(t, "\n
", "\n") + t = snafu(t, "
", "") + t = snafu(t, "\n
", "\n") + t = snafu(t, "


", "

") + + f = open(n, "w"); + f.write(t) + f.close() + diff --git a/DOC/bin/updatesql.py b/DOC/bin/updatesql.py new file mode 100755 index 0000000..56a916c --- /dev/null +++ b/DOC/bin/updatesql.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import sqlite3 +import glob + +db=sqlite3.connect("dbase/pigpio.sqlite") + +c=db.cursor() + +for fn in glob.glob("tmp/body/*.body"): + f = open(fn, encoding='utf-8') + body = f.read() + f.close() + c.execute("UPDATE pigpio SET body=? WHERE file_name=?", (body, fn[9:-5])) + +c.close() + +db.commit() + +db.close() + diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite new file mode 100644 index 0000000..0820b48 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/makedoc b/DOC/makedoc new file mode 100755 index 0000000..4494252 --- /dev/null +++ b/DOC/makedoc @@ -0,0 +1,47 @@ +#!/bin/bash + +mkdir -p tmp/pydoc +mkdir -p tmp/body + +echo "*** making man pages ***" + +echo "pigs" +bin/smakdoc.py src/defs/pigs.def man >MAN/pigs.1 + +echo "pigpiod" +bin/cmakdoc.py pigpiod src/defs/pigpiod.def man >MAN/pigpiod.1 + +echo "pig2vcd" +bin/cmakdoc.py pig2vcd src/defs/pig2vcd.def man >MAN/pig2vcd.1 + +echo "pigpio.h" +bin/cmakdoc.py pigpio ../pigpio.h man >MAN/pigpio.3 + +echo "pigpiod_if.h" +bin/cmakdoc.py pigpiod_if ../pigpiod_if.h man >MAN/pigpiod_if.3 + +echo "pigpiod_if2.h" +bin/cmakdoc.py pigpiod_if2 ../pigpiod_if2.h man >MAN/pigpiod_if2.3 + +# *** preparing HTML bodies *** + +bin/smakdoc.py src/defs/pigs.def >tmp/body/pigs.body +bin/cmakdoc.py pigpiod src/defs/pigpiod.def >tmp/body/pigpiod.body +bin/cmakdoc.py pig2vcd src/defs/pig2vcd.def >tmp/body/pig2vcd.body +bin/cmakdoc.py pigpio ../pigpio.h >tmp/body/cif.body +bin/cmakdoc.py pigpiod_if ../pigpiod_if.h >tmp/body/pdif.body +bin/cmakdoc.py pigpiod_if2 ../pigpiod_if2.h >tmp/body/pdif2.body +pydoc ../pigpio.py >tmp/pydoc/pigpio.pydoc +bin/pymakdoc.py tmp/pydoc/pigpio.pydoc >tmp/body/python.body +bin/examples.py src/defs/examples.def >tmp/body/examples.body + +bin/body.py # get bodies of manually generated pages +bin/tidy.py # tidy the bodies +bin/backup.sh # backup database +bin/updatesql.py # update the database with the new bodies +bin/purge.sh # remove redundant datatbase copies + +echo "*** making web pages ***" + +bin/build_site.py # construct the web site + diff --git a/DOC/src/defs/examples.def b/DOC/src/defs/examples.def new file mode 100644 index 0000000..cd793a4 --- /dev/null +++ b/DOC/src/defs/examples.def @@ -0,0 +1,511 @@ +The following examples show various ways pigpio may be used to communicate with sensors via the GPIO. + +Although many are complete programs they are intended to be a starting point in producing your own code, not an end point. + +?0|Index + +?0|Hardware + +?0|Shell code + +?0|C code + +?0|C++ code + +?0|pigpiod_if2 code + +?0|Python code + +?0|Miscellaneous related code + +?0|External links + +?1|Hardware|Hardware + +A few practical examples of using pigpio with hardware. + +?2|ex_ir_remote|2013-06-09|IR Receiver +Reading an infrared remote receiver. + +?2|ex_LDR|2013-06-09|Light Dependent Resistor +Measuring brightness with a light dependent resistor (LDR). Improved methods of timing the start of the capacitor recharge are given for C and Python. + +?2|ex_motor_shield|2013-12-15|Motor Shield +Using an Arduino motor shield. + +?2|ex_rotary_encoder|2013-06-09|Rotary Encoder +Reading a rotary encoder. + +?2|ex_sonar_ranger|2013-06-10|Sonar Ranger +Measuring range with a sonar ranger. + +?1|Shell|Shell code + +Examples of using pigpio with shell code. + +?3|gpiotest|2014-08-11|GPIO test +This bash script tests the user GPIO. Video + +?1|C|C code + +Examples of C pigpio programs. + +If your program is called foobar.c then build with + +gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt + +?3|freq_count_1|2014-08-20|Frequency Counter 1 +A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). + +?3|freq_count_2|2014-08-20|Frequency Counter 2 +A program showing how to use the gpioSetGetSamplesFunc function to set a callback for accumulated GPIO state changes over the last millisecond. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). Generally the method used is more complicated but more efficient than frequency counter 1. + +?3|hall|2014-06-13|Hall Effect Sensor +Program to show status changes for a Hall effect sensor. + +?3|I2C_sniffer|2014-06-15|I2C Sniffer +A program to passively sniff I2C transactions (100kHz bus maximum) and display the results. This C program uses pigpio notifications. + +?3|ir_hasher_c|2015-02-25|IR Receiver +Function to hash a code from an IR receiver (reading an IR remote control). + +?3|PCF8591|2014-08-26|PCF8591 YL-40 +A program to display readings from the (I2C) PCF8591. + +?3|pot_cap_charge_c|2014-03-14|Pot + Capacitor Recharge Timing +Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance. + +?3|rotary_encoder_c|2015-10-03|Rotary Encoder +Function to decode a mechanical rotary encoder. + +?3|rawMCP3008_c|2016-03-20|SPI bit bang MCP3008 +This program shows how to read multiple MCP3008 ADC simultaneously with accurately timed intervals. One 10-bit channel of each ADC may be sampled at up to 25k samples per second. + +?3|rawMCP3202_c|2016-03-20|SPI bit bang MCP3202 +This program shows how to read multiple MCP3202 ADC simultaneously with accurately timed intervals. One 12-bit channel of each ADC may be sampled at up to 25k samples per second. + +?3|rawMCP3XXX_c|2016-03-20|SPI bit bang MCP3008 and MCP3202 +This program shows how to read multiple MCP3008 and MCP3202 ADC simultaneously with accurately timed intervals. One channel of each ADC may be sampled at up to 25k samples per second. The 10-bit MCP3008 readings are multiplied by 4 so they have the same range (0-4095) as the 12-bit MCP3202. + +?3|servo_demo|2016-10-08|Servo Pulse Generator +This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed. + +sudo ./servo_demo # Generate pulses on GPIO 4. + +sudo ./servo_demo 5 9 20 # Generate pulses on GPIO 5, 9, and 20. + +?4|code/spi-pigpio-speed.c|2016-11-06|SPI pigpio driver speed test +This C code is used to benchmark the pigpio SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer. + +?3|wiegand_c|2013-12-30|Wiegand Reader +Function to read a Wiegand Reader. + +?1|C++|C++ code + +Examples of C++ pigpio programs. + +If your program is called foobar.cpp then build with + +g++ -Wall -pthread -o foobar foobar.cpp -lpigpio -lrt + +?3|ir_hasher_cpp|2015-02-22|IR Receiver +Class to hash a code from an IR receiver (reading an IR remote control). + +?3|rotary_encoder_cpp|2013-12-30|Rotary Encoder +Class to decode a mechanical rotary encoder. + +?3|wiegand_cpp|2013-12-30|Wiegand Reader +Class to read a Wiegand Reader. + +?1|pdif2|pigpiod_if2 code +The pigpiod_if2 code examples are linked with libpigpiod_if2 and are written in C. + +The pigpiod_if2 library may be compiled and run on any Linux machine and allows control of the GPIO on one or more networked Pis. + +It should be possible to adapt the library to run on Macs and PCs. + +Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod. + +?3|_433D|2015-11-17|433MHz Keyfob RX/TX +Code to read and transmit 313 and 434 MHz key fob codes. The codes to be read must use Manchester encoding. The transmitted codes use Manchester encoding. + +./_433D -r10 # Print fob keycodes received on GPIO 10. + +./_433D -t5 8246184 # Transmit code on GPIO 5. + +./_433D -r10 -t5 8246184 # Transmit code on GPIO 5 then listen for codes + +./_433D -? for options. + +?3|DHTXXD|2016-02-16|DHT11/21/22/33/44 Sensor +Code to read the DHT temperature and humidity sensors. The sensor may be auto detected. A DHT11 sensor may be read once per second. The other sensors should not be read more often than once every three seconds. + +The code auto detects the DHT model and generally only the GPIO needs to be specified. + +./DHTXXD -g17 # Read a DHT connected to GPIO 17. + +./DHTXXD -g5 -i3 # Read a DHT connected to GPIO 5 every three seconds. + +./DHTXXD -? # for options. + +?3|RED|2015-11-18|Rotary Encoder +Code to monitor a rotary encoder and show the position changes. By default the detent changes are shown. There is an option to show the four steps per detent instead. + +./RED -a7 -b8 -s30 # Show encoder on 7/8 detent changes for 30 seconds. + +./RED -a5 -b6 -m1 # Show encoder on 5/6 step changes forever. + +./RED -? # for options. + +?3|servo_demo_D|2016-10-08|Servo Pulse Generator +This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed. + +./servo_demo_D # Generate pulses on GPIO 4. + +./servo_demo_D 5 9 20 # Generate pulses on GPIO 5, 9, and 20. + +?3|SRTED|2015-11-16|Sonar Ranger +Code to read the SRF-04 and SRF-05 type of sonar rangers which use the trigger echo method of operation. A 10 μs trigger pulse initiates a series of high frequency sonar chirps. The echo line then goes high and stays high until an echo from an object is received. The echo high time is used to calculate the distance of the object. + +For a one-off reading only the trigger and echo GPIO need to be specified. + +./SRTED -t5 -e6 # Read a sonar ranger connected to GPIO 5/6. + +./SRTED -t11 -e5 -i0.1 # Read a sonar ranger connected to GPIO 11/5 every 0.1 seconds. + +./SRTED -? # for options. + +?3|tx_RED|2015-11-25|Transmit Rotary Encoder Test Signals +Code to transmit quadrature signals to test rotary encoder software. + +tx_RED -aGPIO -bGPIO [options] + +tx_RED -? for options + +E.g. + +tx_RED -a5 -b6 -s20 -r-100 + +?3|tx_WD|2015-11-25|Transmit Wiegand Test Signals +Code to transmit Wiegand codes to test Wiegand decoder software. + +tx_WD -gGPIO -wGPIO [options] {code}+ + +tx_WD -? for options + +E.g. + +tx_WD -g5 -w6 -s37 12345 67890 123 899999 + +?3|WD|2015-11-25|Wiegand Reader +Code to read a Wiegand Reader. + +./WD -g7 -w8 -s30 # Read Wiegand codes from GPIO 7/8 for 30 seconds. + +./WD -g5 -w6 # Read Wiegand codes from GPIO 5/6 forever. + +./WD -? # for options. + +?1|Python|Python code +The Python code may be run on any Python machine and allows control of the GPIO on one or more networked Pis. + +The Python machine need not be a Pi, it may run Windows, Mac, Linux, anything as long as it supports Python. + +Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod. + +?3|_433_py|2015-10-30|433MHz Keyfob RX/TX +Classes to send and receive 433MHz wireless keyfob codes. These keyfobs are widely used for remote control of devices. + +?3|_7_segment|2016-12-12|7-Segment LED Display Multiplexing +Script to multiplex several 7-segment LED displays. Each display has the segments a-g and the decimal point connected in parallel but has an individual enable GPIO (connected to the common anode or cathode). + +?3|test-APA102_py|2017-03-28|APA102 LED strip driver +Script to drive an APA102 LED strip. Three different methods are demonstrated - using spidev SPI (only works on the local Pi), pigpio SPI, and pigpio waves. The SPI solutions only work with the dedicated SPI GPIO. Waves may use any spare GPIO. Four different examples are given including a LED strip clock. + +?3|BME280_py|2016-08-05|BME280 Sensor +Class to read the relative humidity, temperature, and pressure from a BME280 sensor. The sensor has both an I2C and a SPI interface which are both +supported by the class. + +?4|code/DHT.py|2019-11-07|DHT11/21/22/33/44 Sensor +Class to read the relative humidity and temperature from a DHT sensor. It can automatically recognize the sensor type. + +The default script prints the reading from the specified DHT every 2 seconds. E.g. ./DHT.py 22 27 displays the data for DHT connected to GPIO 22 and 27. + +The following data is printed for each DHT: timestamp, GPIO, status, temperature, and humidity. + +The timestamp is the number of seconds since the epoch (start of 1970). + +The status will be one of: 0 - a good reading, 1 - checksum failure, 2 - data had one or more invalid values, 3 - no response from sensor. + +?3|DHT22_py|2014-07-11|DHT22 AM2302 Sensor +Class to read the relative humidity and temperature from a DHT22/AM2302 sensor. + +?3|DS18B20-1_py|2016-06-29|DS18B20 Temperature Sensor +Script to read the temperature from any DS18B20 sensors connected to the 1-wire bus. + +To enable the 1-wire bus add the following line to /boot/config.txt and reboot. + +dtoverlay=w1-gpio + +By default you should connect the DS18B20 data line to GPIO 4 (pin 7). + +Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4. + +This script uses the file features of pigpio to access the remote file system. + +The following entry must be in /opt/pigpio/access. + +/sys/bus/w1/devices/28*/w1_slave r + +?3|PPD42NS_py|2015-11-22|Dust Sensor +Class to read a Shinyei PPD42NS Dust Sensor, e.g. as used in the Grove dust sensor. + +?3|gpio_status_py|2014-06-12|GPIO Status +Script to display the status of GPIO 0-31. + +?3|hall|2014-06-13|Hall Effect Sensor +Program to show status changes for a Hall effect sensor. + +?3|HX711_py|2018-03-05|HX711 24-bit ADC +Class to read the channels of a HX711 24-bit ADC. + +?3|i2c_ADXL345_py|2015-04-01|I2C ADXL345 Accelerometer +Script to display the X, Y, and Z values read from an ADXL345 accelerometer. + +?3|i2c_HMC5883L_py|2015-04-01|I2C HMC5883L Magnetometer +Script to display the X, Y, and Z values read from a HMC5883L Magnetometer (compass). + +?3|i2c_ITG3205_py|2015-04-01|I2C ITG3205 Gyroscope +Script to display the X, Y, Z, and temperature values read from an ITG3205 gyroscope. + +?3|i2c_lcd_py|2016-04-20|I2C LCD Display +Class to display text on a LCD character display. The class supports the PCF8574T 8-bit I2C port expander connected to a HD44780 based LCD display. These displays are commonly available in 16x2 and 20x4 character formats. + +?3|bsc_arduino_py|2016-10-31|I2C slave device +This script demonstrates how to transfer messages from an Arduino acting as the I2C bus master to the Pi acting as an I2C slave device. + +?3|I2C_sniffer|2015-06-15|I2C Sniffer +A program to passively sniff I2C transactions (100kHz bus maximum) and display the results. + +?3|i2c_sonar_py|2016-03-24|I2C Sonar +A class to read up to 8 HC-SR04 sonar rangers connected to an MCP23017 port expander. + +?3|ir_hasher_py|2014-06-12|IR Receiver +Class to hash a code from an IR receiver (reading an IR remote control). + +?3|irrp_py|2015-12-21|IR Record and Playback +This script may be used to record and play back arbitrary IR codes. + +To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given. + +E.g. ./irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0 + +To playback the GPIO connected to the IR transmitter, the file containing the recorded codes, and the codes to be played back are given. + +E.g. ./irrp.py -p -g18 -fir-codes 2 3 4 + +./irrp.py -h # for options + +?3|kivy_GPIO_py|2016-12-11|Kivy GPIO control +This example shows how to use Kivy to control a Pi's GPIO. The GPIO may be configured as inputs, outputs, or to generate Servo or PWM pulses. Kivy is an Open source Python library for rapid development of applications. + +?3|MAX6675_py|2016-05-02|MAX6675 SPI Temperature Sensor +A script to read the temperature from a MAX6675 connected to a K-type thermocouple. The MAX6675 supports readings in the range 0 - 1023.75 C. Up to 4 readings may be made per second. + +?3|monitor_py|2016-09-17|Monitor GPIO +Script to monitor GPIO for level changes. By default all GPIO are monitored. At a level change the GPIO, new level, and microseconds since the last change is printed. + +?3|morse_code_py|2015-06-17|Morse Code +Script to transmit the morse code corresponding to a text string. + +?4|code/NRF24.py|2018-01-06|NRF24 radio transceiver +Script to transmit and receive messages using the nRF24L01 radio transceiver. + +?3|PCA9685_py|2016-01-31|PCA9685 16 Channel PWM +Class to control the 16 PWM channels of the I2C PCA9685. All channels use the same frequency. The duty cycle or pulse width may be set independently for each channel. + +?3|PCF8591|2014-08-26|PCF8591 YL-40 +Script to display readings from the (I2C) PCF8591. + +?4|code/PPM.py|2016-02-19|PPM (Pulse Position Modulation) generation +Script to generate PPM signals on a chosen GPIO. + +?4|code/PPM_to_servo.py|2019-10-09|PPM (Pulse Position Modulation) to servo pulses +Script to read a PPM signal on a GPIO and generate the corresponding servo signals on chosen GPIO. + +?3|bench_1_py|2014-06-12|pigpio Benchmark +Script to benchmark the pigpio Python module's performance. + +?3|pigpio_cgi_py|2015-05-04|pigpio CGI +Script demonstrating how to access the pigpio daemon using CGI from a browser. Instructions on how to use with Apache2 on the Pi are given in the comments. + +?3|playback_py|2016-12-23|Playback piscope recordings +Script to playback GPIO data recorded in piscope format. + +To playback GPIO 4 to GPIO 4 from file data.piscope +./playback.py data.piscope 4 + +To playback GPIO 4 to GPIO 7 from file rec.txt +./playback.py rec.txt 7=4 + +?3|pot_cap_py|2016-09-26|Pot + Capacitor Recharge Timing +Class to time capacitor charging (through a resistance). The time can be used to estimate the resistance. + +?3|read_PWM_py|2015-12-08|PWM Monitor +Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle. + +?3|rotary_encoder_py|2014-06-12|Rotary Encoder +Class to decode a mechanical rotary encoder. + +?3|read_RPM_py|2016-01-20|RPM Monitor +Class to monitor speedometer pulses and calculate the RPM (Revolutions Per Minute). + +?3|Si7021_py|2016-05-07|Si7021 I2C Temperature and Humidity Sensor +Class to read the temperature and relative humidity from a Si7021. + +?3|SPI_mon_py|2016-09-21|SPI Monitor +A program to passively sniff SPI transactions and display the results. The SPI rate should be limited to about 70kbps if using the default pigpio 5µs sampling rate. + +?3|servo_demo_py|2016-10-07|Servo Pulse Generator +This script generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed. + +./servo_demo.py # Generate pulses on GPIO 4. + +./servo_demo.py 5 9 20 # Generate pulses on GPIO 5, 9, and 20. + +?3|sonar_trigger_echo_py|2014-06-12|Sonar Ranger +Class to read sonar rangers with separate trigger and echo pins. + +?3|TCS3200_py|2015-07-03|TCS3200 Colour Sensor +Class to read the TCS3200 colour sensor + +?3|vw|2015-10-31|Virtual Wire +Class to send and receive radio messages compatible with the Virtual Wire library for Arduinos. This library is commonly used with 313MHz and 434MHz radio tranceivers. + +?4|code/create_wave.py|2019-11-18|Wave create +Script to generate waves from a template defined in a text file. + +You can also specify one of py, c, or pdif - the script output will then be a complete program to generate the wave (py for Python script, c for a C program, pdif for a C program using the pigpio daemon I/F). + +If none of py, c, or pdif are chosen the waveform will be generated for 30 seconds. + +Example text file + +# GPIO levels +23 11000001 +11 01110000 +12 00011100 +4 00000111 + +To generate a pdif program with a bit time of 100 microseconds +./create_wave.py wave_file 100 pdif >wave_pdif.c + +To just transmit the wave with a bit time of 50 microseconds +./create_wave.py wave_file 50 + +?3|wave_PWM_py|2016-03-19|Wave PWM 1 +Script to show how waves may be used to generate PWM at (one) arbitrary frequency on multiple GPIO. For instance PWM at 10kHz may be generated with 100 steps between off and fully on. + +?3|wavePWM_py|2016-10-06|Wave PWM 2 +Class to generate PWM on multiple GPIO. It is more flexible than the Wave PWM 1 example in that the start of the pulse within each cycle may be specified as well as the duty cycle. The start and length of each pulse may be specified on a GPIO by GPIO basis in microseconds or as a fraction of the cycle time. The class includes a __main__ to demostrate its ability to send servo pulses. + +?3|wiegand_py|2014-06-12|Wiegand Reader +Class to read a Wiegand reader. + +?1|Misc|Miscellaneous related code + +The following code examples do not use pigpio. + +?3|adxl345_c|2014-03-12|ADXL345 +This C program reads x, y, and z accelerations from the ADXL345 via I2C address 0x53. + +?3|DS18B20_py|2016-04-25|DS18B20 Temperature Sensor +This Python script reads the temperature from any DS18B20 sensors connected to the 1-wire bus. + +To enable the 1-wire bus add the following line to /boot/config.txt and reboot. + +dtoverlay=w1-gpio + +By default you should connect the DS18B20 data line to GPIO 4 (pin 7). + +Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4. + +?3|EasyAsPiServer|2014-09-15|Easy as Pi Server +This Python class implements a simple server which allows broswer commands to be executed on the Pi. + +?3|minimal_clk|2015-05-20|Minimal Clock Access +This C code sets GPIO 4 to a specified clock frequency. The frequency can be set between 4.6875 kHz and 500 MHz (untested). The clock can be preferentially set from one of the sources OSC (19.2MHz), HDMI (216MHz), PLLD (500MHz), or PLLC (1000MHz). MASH can be set between 0 and 3. MASH may not work properly for clock dividers less than 5. + +?3|minimal_gpio|2019-07-03|Minimal GPIO Access +This C code has a minimal set of functions needed to control the GPIO and other Broadcom peripherals. The program requires root privileges to run. See Tiny GPIO access for an alternative which controls the GPIO (but not the other peripherals) and does not require root access. + +The code has been updated for the BCM2711 (Pi4B). + +The following functions are provided. + +gpioInitialise +gpioSetMode +gpioGetMode +gpioSetPullUpDown +gpioRead +gpioWrite +gpioTrigger +gpioReadBank1 +gpioReadBank2 +gpioClearBank1 +gpioClearBank2 +gpioSetBank1 +gpioSetBank2 +gpioHardwareRevision +gpioTick + +?3|nanopulse_c|2014-01-29|Nanosecond Pulse Generation +This C program uses the PWM peripheral to generate precisely timed pulses of very short duration. Pulses as short as 4 nano seconds can be generated. + +?3|PCF8591-x|2014-08-26|PCF8591 YL-40 +C and Python code to read the (I2C) PCF8591. + +?4|code/spi-driver-speed.c|2016-11-06|SPI Linux driver speed test +This C code is used to benchmark the Linux SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer. + +?3|tiny_gpio|2016-04-30|Tiny GPIO Access +This C code has a minimal set of functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO). + +You may need to change the permissions and ownership of /dev/gpiomem if they have not been correctly set up. + +sudo chown root:gpio /dev/gpiomem +sudo chmod g+rw /dev/gpiomem + +The user (default pi) needs to be in the gpio group. + +sudo adduser pi gpio + +The following functions are provided. + +gpioInitialise +gpioSetMode +gpioGetMode +gpioSetPullUpDown +gpioRead +gpioWrite +gpioTrigger +gpioReadBank1 +gpioReadBank2 +gpioClearBank1 +gpioClearBank2 +gpioSetBank1 +gpioSetBank2 +gpioHardwareRevision + +?1|External|External links + +Related code. + +?4|https://github.com/stripcode/pigpio-stepper-motor|2016-08-12|Stepper Motor +Stepper motor code. + +?4|https://github.com/choeffer/360pibot|2018-11-03|Parallax ActivityBot 360 +Python 3 implementation for programming a Parallax ActivityBot 360 Robot Kit with a Raspberry Pi. + +?1|Index|Index + diff --git a/DOC/src/defs/pig2vcd.def b/DOC/src/defs/pig2vcd.def new file mode 100644 index 0000000..48e1013 --- /dev/null +++ b/DOC/src/defs/pig2vcd.def @@ -0,0 +1,110 @@ + +/*TEXT +pig2vcd is a utility which reads notifications on stdin and writes the +output as a Value Change Dump (VCD) file on stdout. + +The VCD file can be viewed using GTKWave. + +*Notifications* + +Notifications consist of 12 bytes with the following binary format. + +. . +typedef struct +{ + uint16_t seqno; + uint16_t flags; + uint32_t tick; + uint32_t level; +} gpioReport_t; +. . + +seqno: starts at 0 each time the handle is opened and then increments by one for each report. + +flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. + +tick: the number of microseconds since system boot. It wraps around after 1h12m. + +level: indicates the level of each gpio. If bit 1</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 $?). + +... +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). + +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. + +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. + +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 :: 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 +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 + +COMMANDS + +BC1 :: +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. + +... +$ 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 :: +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. + +... +$ 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 :: +This command signals that bit banging I2C on [*sda*] (and [*scl*]) is no +longer required. + +... +$ pigs bi2cc 5 +... + +BI2CO :: +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. + +o baud rates as low as 50 +o repeated starts +o clock stretching +o 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. + +BI2CZ :: +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: + +Name @ Cmd & Data @ Meaning +End @ 0 @ No more commands +Escape @ 1 @ Next P is two bytes +Start @ 2 @ Start condition +Stop @ 3 @ Stop condition +Address @ 4 P @ Set I2C address to P +Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) +Read @ 6 P @ Read P bytes of data +Write @ 7 P ... @ Write P bytes of data + +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +The address and flags default to 0. The address and flags maintain +their previous value until updated. + +No flags are currently defined. + +... +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 :: +This command read GPIO 0-31 (bank 1) and returns the levels as a +32-bit hexadecimal value. + +... +$ pigs br1 +1001C1CF +... + +BR2 :: +This command read GPIO 32-53 (bank 2) and returns the levels as a +32-bit hexadecimal value. + +... +$ pigs br2 +003F0000 +... + +BS1 :: +This command sets (sets high) 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. + +... +$ 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 :: +This command sets (sets high) 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. + +... +$ 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 :: + +This command performs a BSC I2C/SPI slave transfer as defined by +[*bctl*] with data [*bvs*]. + +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. + +I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. + +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, followed by any data bytes +read from the BSC receive FIFO. + +Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. + +For I2C use a control word of (I2C address << 16) + 0x305. + +E.g. to talk as 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 will be reset +to INPUT mode. + +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 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 + +This example assumes that GPIO 2/3 are connected to GPIO 18/19 +(GPIO 10/11 on the BCM2711). + +... +$ 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 :: + +This command stops bit banging SPI on a set of GPIO +opened with [*BSPIO*]. + +The set of GPIO is specifed by [*cs*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs bspic 10 + +$ pigs bspic 10 +-142 +ERROR: no bit bang SPI in progress on GPIO +... + +BSPIO :: + +This command starts bit banging SPI on a group of GPIO with slave +select [*cs*], MISO [*miso*], MOSI [*mosi*], and clock [*sclk*]. + +Data will be transferred at baud [*b*] bits per second (which may +be set in the range 50-250000). + +The flags [*spf*] may be used to modify the default behaviour of +mode 0, active low chip select. + +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 + 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 (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. + +Upon success 0 is returned. On error a negative status code +will be returned. + +If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. + +... +$ 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:: + +This command writes bytes [*bvs*] to the bit bang SPI device +associated with slave select [*cs*]. It returns the same +number of bytes read from the device. + +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +... +$ 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:: + +This command calls a user customised function. The meaning of +any paramaters and the returned value is defined by the +customiser. + +CF2:: + +This command calls a user customised function. The meaning of +any paramaters and the returned value is defined by the +customiser. + +CGI:: +This command returns the value of the internal library +configuration settings. + +CSI:: +This command sets the value of the internal library +configuration settings to [*v*]. + +EVM :: +This command starts event reporting 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 reports for each event specified by [*bits*]. + +... +$ 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 :: +This command triggers event [*event*]. + +One event, number 31, is predefined. This event is +auto generated on BSC slave activity. + +... +$ pigs evt 12 +$ pigs evt 5 + +$ pigs evt 32 +-143 +ERROR: bad event id +... + +FC:: +This command closes a file handle [*h*] previously opened with [*FO*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs fc 0 # First close okay. + +$ pigs fc 0 # Second fails. +-25 +ERROR: unknown handle +... + +FG :: + +Level changes on the GPIO [*u*] are not reported unless the level +has been stable for at least [*stdy*] microseconds. The +level is then reported. Level changes of less than [*stdy*] +microseconds are ignored. + +The filter only affects callbacks (including pipe notifications). + +The [*R/READ*], [*BR1*], and [*BR2*] commands are not affected. + +Note, each (stable) edge will be timestamped [*stdy*] microseconds +after it was first detected. + +... +$ pigs fg 4 250 + +$ pigs fg 4 1000000 +-125 +ERROR: bad filter parameter +... + +FL :: +This command returns a list of the files matching [*pat*]. Up +to [*num*] bytes may be returned. + +Upon success the count of returned bytes followed by the matching +files is returned. On error a negative status code will be returned. + +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 + +... +$ 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 :: + +Level changes on the GPIO [*u*] are ignored until a level which has +been stable for [*stdy*] microseconds is detected. Level +changes on the GPIO are then reported for [*actv*] microseconds +after which the process repeats. + +The filter only affects callbacks (including pipe notifications). + +The [*R/READ*], [*BR1*], and [*BR2*] commands are not affected. + +Note, level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. + +... +$ pigs fn 7 250 1000 + +$ pigs fn 7 2500000 1000 +-125 +ERROR: bad filter parameter +... + +FO :: +This function 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 +will be returned. + +File + +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +Suppose /opt/pigpio/access contains the following entries + +. . +/home/* n +/home/pi/shared/dir_1/* w +/home/pi/shared/dir_2/* r +/home/pi/shared/dir_3/* u +/home/pi/shared/dir_1/file.txt n +. . + +Files may be written in directory dir_1 with the exception +of file.txt. + +Files may be read in directory dir_2. + +Files may be read and written in directory dir_3. + +If a directory allows read, write, or read/write access then files may +be created in that directory. + +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +. . +a path containing .. +a path containing only wildcards (*?) +a path containing less than two non-wildcard parts +. . + +Mode + +The mode may have the following values. + + @ 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 may 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 + +Newly created files are owned by root with permissions owner read and write. + +... +$ 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:: +This command 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 will be returned. + +... +$ pigs fr 0 10 +5 48 49 128 144 255 + +$ pigs fr 0 10 +0 +... + +FS :: +This command 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 backwards. The move start +position is determined by [*from*] as follows. + + @ From +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 will be returned. + +... +$ 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:: +This command writes bytes [*bvs*] to the file +associated with handle [*h*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs fw 0 23 45 67 89 +... + +GDC :: + +This command returns the PWM dutycycle in use on GPIO [*u*]. + +Upon success the dutycycle is returned. On error a negative +status code will be returned. + +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). + +... +$ pigs p 4 129 +$ pigs gdc 4 +129 + +pigs gdc 5 +-92 +ERROR: GPIO is not in use for PWM +... + +GPW :: + +This command returns the servo pulsewidth in use on GPIO [*u*]. + +Upon success the servo pulsewidth is returned. On error a negative +status code will be returned. + +... +$ pigs s 4 1235 +$ pigs gpw 4 +1235 + +$ pigs gpw 9 +-93 +ERROR: GPIO is not in use for servo pulses +... + +H/HELP :: +This command displays a brief list of the commands and their parameters. + +... +$ pigs h + +$ pigs help +... + +HC :: +This command sets the hardware clock associated with GPIO [*g*] to +frequency [*cf*]. Frequencies above 30MHz are unlikely to work. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ 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. + +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) + +Access to clock 1 is protected by a password as its use will +likely crash the Pi. The password is given by or'ing 0x5A000000 +with the GPIO number. + +HP :: +This command sets the hardware PWM associated with GPIO [*g*] to +frequency [*pf*] with dutycycle [*pdc*]. Frequencies above 30MHz +are unlikely to work. + +NOTE: Any waveform started by [*WVTX*], [*WVTXR*], or [*WVCHA*] +will be cancelled. + +This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). + +Upon success nothing is returned. On error a negative status code +will be returned. + +. . +$ 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 +. . + +The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. + +The GPIO must be one of the following. + +12 @PWM channel 0 @All models but A and B +13 @PWM channel 1 @All models but A and B +18 @PWM channel 0 @All models +19 @PWM channel 1 @All models but A and B + +40 @PWM channel 0 @Compute module only +41 @PWM channel 1 @Compute module only +45 @PWM channel 1 @Compute module only +52 @PWM channel 0 @Compute module only +53 @PWM channel 1 @Compute module only + +The actual number of steps beween off and fully on is the +integral part of 250M/[*pf*] (375M/[*pf*] for the BCM2711). + +The actual frequency set is 250M/steps (375M/steps for the BCM2711). + +There will only be a million steps for a [*pf*] of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. [*pdc*] is +automatically scaled to take this into account. + +HWVER :: +This command returns the hardware revision of the Pi. + +The hardware revision is found in the last 4 characters on the revision +line of /proc/cpuinfo. + +If the hardware revision can not be found or is not a valid hexadecimal +number the command returns 0. + +The revision number can be used to determine the assignment of GPIO +to pins (see [*g*]). + +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. + +... +$ pigs hwver # On a B+ +16 +... + +I2CC :: +This command closes an I2C handle [*h*] previously opened with [*I2CO*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs i2cc 0 # First close okay. + +$ pigs i2cc 0 # Second fails. +-25 +ERROR: unknown handle +... + +I2CO :: +This command returns a handle to access device [*id*] on I2C bus [*ib*]. +The device is opened with flags [*if*]. + +Physically buses 0 and 1 are available on the Pi. Higher +numbered buses will be available if a kernel supported bus +multiplexor is being used. + +The GPIO used are given in the following table. + + @ SDA @ SCL +I2C 0 @ 0 @ 1 +I2C 1 @ 2 @ 3 + +No flags are currently defined. The parameter [*if*] should be 0. + +Upon success the next free handle (>=0) is returned. On error a +negative status code will be returned. + +... +$ 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 :: +This command writes [*wv*] to register [*r*] of the I2C device +associated with handle [*h*] and returns a 16-bit word read from the +device. + +Upon success a value between 0 and 65535 will be returned. On error +a negative status code will be returned. + +... +$ pigs i2cpc 0 37 43210 +39933 + +$ pigs i2cpc 0 256 43210 +ERROR: bad i2c/spi/ser parameter +-81 +... + +I2CPK :: + +This command writes the data bytes [*bvs*] to register [*r*] of the I2C device +associated with handle [*h*] and returns a device specific number of bytes. + +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +... +$ pigs i2cpk 0 0 0x11 0x12 +6 0 0 0 0 0 0 +... + +I2CRB :: + +This command returns a single byte read from register [*r*] of the I2C device +associated with handle [*h*]. + +Upon success a value between 0 and 255 will be returned. On error +a negative status code will be returned. + +... +$ pigs i2crb 0 0 +6 +... + +I2CRD :: + +This command returns [*num*] bytes read from the I2C 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. + +This command operates on the raw I2C device. The maximum value of the +parameter [*num*] is dependent on the I2C drivers and the device +itself. pigs imposes a limit of about 8000 bytes. + +... +$ pigs i2crd 0 16 +16 6 24 0 0 0 0 0 0 0 0 0 0 0 0 32 78 +... + +I2CRI :: + +This command returns [*num*] bytes from register [*r*] of the I2C 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. + +The parameter [*num*] may be 1-32. + +... +$ pigs i2cri 0 0 16 +16 237 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 +... + +I2CRK :: + +This command returns between 1 and 32 bytes read from register [*r*] of +the I2C 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. + +The number of bytes of returned data is specific to the device and +register. + +... +$ 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 :: + +This command returns a single byte read from the I2C device +associated with handle [*h*]. + +Upon success a value between 0 and 255 will be returned. On error +a negative status code will be returned. + +... +$ pigs i2crs 0 +0 +... + +I2CRW :: + +This command returns a single 16 bit word read from register [*r*] of +the I2C device associated with handle [*h*]. + +Upon success a value between 0 and 65535 will be returned. On error +a negative status code will be returned. + +... +$ pigs i2crw 0 0 +6150 +... + +I2CWB :: + +This command writes a single byte [*bv*] to register [*r*] of the +I2C device associated with handle [*h*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs i2cwb 0 10 0x54 +... + +I2CWD :: + +This command writes a block of bytes [*bvs*] to the I2C device +associated with handle [*h*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +The number of bytes which may be written in one transaction is +dependent on the I2C drivers and the device itself. pigs imposes +a limit of about 500 bytes. + +This command operates on the raw I2C device. + +... +$ pigs i2cwd 0 0x01 0x02 0x03 0x04 +... + +I2CWI :: + +This command writes between 1 and 32 bytes [*bvs*] to register [*r*] of +the I2C device associated with handle [*h*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs i2cwi 0 4 0x01 0x04 0xc0 +... + +I2CWK :: + +This command writes between 1 and 32 bytes [*bvs*] to register [*r*] of +the I2C device associated with handle [*h*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +pigs i2cwk 0 4 0x01 0x04 0xc0 +... + +I2CWQ :: + +This command writes a single [*bit*] to the I2C device associated +with handle [*h*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs i2cwq 0 1 +... + +I2CWS :: + +This command writes a single byte [*bv*] to the I2C device associated +with handle [*h*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs i2cws 0 0x12 + +$ pigs i2cws 0 0xff +-82 +ERROR: I2C write failed +... + +I2CWW :: + +This command writes a single 16 bit word [*wv*] to register [*r*] of +the I2C device associated with handle [*h*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs i2cww 0 0 0xffff +... + +I2CZ :: +This command executes a sequence of 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: + +Name @ Cmd & Data @ Meaning +End @ 0 @ No more commands +Escape @ 1 @ Next P is two bytes +On @ 2 @ Switch combined flag on +Off @ 3 @ Switch combined flag off +Address @ 4 P @ Set I2C address to P +Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) +Read @ 6 P @ Read P bytes of data +Write @ 7 P ... @ Write P bytes of data + +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +The address defaults to that associated with the handle [*h*]. +The flags default to 0. The address and flags maintain their +previous value until updated. + +... +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/MODES :: + +This command sets GPIO [*g*] to mode [*m*], typically input (read) +or output (write). + +Upon success nothing is returned. On error a negative status code +will be returned. + +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. + +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 +... + +MG/MODEG :: + +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@ 1@ 2@ 3@ 4@ 5@ 6@ 7 +Mode @Input@Output@ALT5@ALT4@ALT0@ALT1@ALT2@ALT3 + +... +$ pigs mg 4 +1 +... + +MICS :: +This command delays execution for [*v*] microseconds. + +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*]. + +... +$ pigs mics 20 # Delay 20 microseconds. +$ pigs mics 1000000 # Delay 1 second. + +$ pigs mics 2000000 +-64 +ERROR: bad MICS delay (too large) +... + +MILS :: + +This command delays execution for [*v*] milliseconds. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs mils 2000 # Delay 2 seconds. + +$ pigs mils 61000 +-65 +ERROR: bad MILS delay (too large) +... + +NB :: + +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*]. + +... +$ 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 :: + +This command stops notifications on handle [*h*] returned by +a prior call to [*NO*] and releases the handle for reuse. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs nc 0 # First call succeeds. + +$ pigs nc 1 # Second call fails. +-25 +ERROR: unknown handle +... + +NO :: + +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. + +... +$ pigs no +0 +... + +NP :: + +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. + +... +$ pigs np 0 +... + +P/PWM :: + +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. + +The [*PRS*] command may be used to change the default range of 255. + +... +$ 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 :: + +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 @ 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 +... + +PADS:: + +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 @ 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 +... + +PARSE :: + +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. + +... +$ 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 :: + +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*]. + +... +$ pigs pfg 4 +800 + +$ pigs pfg 34 +ERROR: GPIO not 0-31 +-2 +... + +PFS :: +This command sets the PWM frequency [*v*] to be used for GPIO [*u*]. + +The numerically closest frequency to [*v*] will be selected. + +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 + + 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 +... + +PIGPV :: + +This command returns the pigpio library version. + +... +$ pigs pigpv +17 +... + +PRG :: + +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). + +... +$ pigs prg 4 +255 +... + +PROC :: + +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*]. + +... +$ 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 :: + +This command deletes script [*sid*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +See [*Scripts*]. + +... +$ pigs procd 1 + +$ pigs procd 1 +ERROR: unknown script id +-48 +... + +PROCP :: + +This command returns the status of script [*sid*] as well as the +current value of its 10 parameters. + +Upon success the script status and parameters are returned. +On error a negative status code will be returned. + +The script status may be one of + +0 @ being initialised +1 @ halted +2 @ running +3 @ waiting +4 @ failed + +See [*Scripts*]. + +... +$ pigs procp 0 +1 0 0 0 0 0 0 0 0 0 0 +... + +PROCR :: + +This command runs stored script [*sid*] passing it up to 10 optional +parameters. + +Upon success nothing is returned. On error a negative status code +will be returned. + +See [*Scripts*]. + +... +$ 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 :: + +This command stops a running script [*sid*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +See [*Scripts*]. + +... +$ pigs procs 0 + +$ pigs procs 1 +-48 +ERROR: unknown script id +... + +PROCU :: + +This command sets the parameters of a stored script [*sid*] passing +it up to 10 parameters. + +Upon success nothing is returned. On error a negative status code +will be returned. + +See [*Scripts*]. + +... +$ 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 :: + +This command returns the real underlying range used by GPIO [*u*]. + +If a hardware clock is active on the GPIO the reported +real range will be 1000000 (1M). + +If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. + +On error a negative status code will be returned. + +See [*PRS*]. + +... +$ pigs prrg 17 +250 + +$ pigs pfs 17 0 +10 +$ pigs prrg 17 +20000 + +$ pigs pfs 17 100000 +8000 +$ pigs prrg 17 +25 +... + +PRS :: + +This command sets the dutycycle range [*v*] to be used for GPIO [*u*]. +Subsequent uses of command [*P/PWM*] will use a dutycycle between 0 (off) +and [*v*] (fully on). + +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 will be scaled to +reflect the new range. + +The real range, the number of steps between fully off and fully on +for each frequency, is given in the following table. + + #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*] + +... +$ pigs prs 18 1000 +250 +... + +PUD :: + +This command 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 may be pull-down (D), pull-up (U), or off (O). + +... +$ 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 :: + +This reads the current level of GPIO [*g*]. + +Upon success the current level is returned. On error a negative status code +will be returned. + +... +$ pigs r 17 # Get level of GPIO 17. +0 + +$ pigs r 4 # Get level of GPIO 4. +1 +... + +S/SERVO :: + +This command 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 may be 0 (off), 500 (most anti-clockwise) +to 2500 (most clockwise). + +The range supported by servos varies and should probably be determined +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. + +You can DAMAGE a servo if you command it to move beyond its limits. + +... +$ 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. + +... +pigs s 17 0 # Switch servo pulses off. +... + +SERC :: + +This command closes a serial handle [*h*] previously opened with [*SERO*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs serc 0 # First close okay. + +$ pigs serc 0 # Second close gives error. +-25 +ERROR: unknown handle +... + +SERDA :: + +This command 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). On error a negative status code +will be returned. + +... +$ pigs serda 0 +0 +... + +SERO:: + +This command 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. + +... +$ pigs sero /dev/ttyAMA0 9600 0 +0 + +$ pigs sero /dev/tty1 38400 0 +1 +... + +SERR:: + +This command 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. + +... +$ pigs serr 0 10 +5 48 49 128 144 255 + +$ pigs serr 0 10 +0 +... + +SERRB:: + +This command 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. + +... +$ pigs serrb 0 +23 +$ pigs serrb 0 +45 +... + +SERW:: + +This command 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. + +... +$ pigs serw 0 23 45 67 89 +... + +SERWB:: + +This command 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. + +... +$ pigs serwb 0 23 +$ pigs serwb 0 0xf0 +... + +SHELL :: + +This command 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. + +The returned exit status is normally 256 times that set +by the shell script exit function. If the script can't +be found 32512 will be returned. + +The following table gives some example returned statuses. + +Script exit status @ Returned system call status +1 @ 256 +5 @ 1280 +10 @ 2560 +200 @ 51200 +script not found @ 32512 + +... +# pass two parameters, hello and world +$ 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 +... + +SLR :: + +This command 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. + +The GPIO [*u*] should have been initialised with the [*SLRO*] command. + +The bytes returned for each character depend upon the number of +data bits [*db*] 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. + +... +$ pigs slr 15 20 +6 1 0 23 45 89 0 +... + +SLRC :: + +This command closes GPIO [*u*] for reading bit bang serial data. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs slrc 23 + +$ pigs slrc 23 +-38 +ERROR: no serial read in progress on GPIO +... + +SLRI :: + +This command 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. + +... +$ pigs slri 17 1 # invert logic on GPIO 17 + +$ pigs slri 23 0 # use normal logic on GPIO 23 +... + +SLRO :: + +This command 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 may be between 50 and 250000 bits per second. + +The received data is held in a cyclic buffer. + +It is the user's responsibility to read the data (with [*SLR*]) +in a timely fashion. + +... +$ pigs slro 23 19200 8 + +$ pigs slro 23 19200 8 +-50 +ERROR: GPIO already in use +... + +SPIC :: + +This command closes the SPI handle [*h*] returned by a prior +call to [*SPIO*]. + +Upon success nothing is returned. On error a negative status code +will be returned. + +... +$ pigs spic 1 + +$ pigs spic 1 +-25 +ERROR: unknown handle +... + +SPIO :: + +This command returns a handle to a SPI device on channel [*c*]. + +Data will be transferred at [*b*] bits per second. The flags [*spf*] +may be used to modify the default behaviour of 4-wire operation, +mode 0, active low chip select. + +Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps +are unlikely to work. + +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. + +. . +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. + +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. + +Upon success a handle (>=0) is returned. On error a negative status code +will be returned. + +... +$ 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 :: + +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. + +... +$ pigs spir 0 10 # Read 10 bytes from the SPI device. +10 0 0 0 0 0 0 0 0 0 0 +... + +SPIW :: + +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. + +... +$ pigs spiw 0 0x22 0x33 0xcc 0xff +... + +SPIX:: + +This command writes bytes [*bvs*] to the SPI device +associated with handle [*h*]. It returns the same +number of bytes read from the device. + +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +... +$ pigs spix 0 0x22 0x33 0xcc 0xff +4 0 0 0 0 +... + +T/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. + +... +$ pigs t mils 1000 t +3691823946 +3692833987 +... + +TRIG :: + +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. + +... +$ pigs trig 4 10 1 + +$ pigs trig 4 51 1 +-46 +ERROR: trigger pulse > 50 microseconds +... + +W/WRITE :: + +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. + +... +$ pigs w 23 0 +$ pigs w 23 1 + +$ pigs w 23 2 +-5 +ERROR: level not 0-1 +... + +WDOG :: + +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. + +... +$ 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. + +WVAG :: + +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. + +... +$ pigs wvag 0x10 0x80 1000 0x80 0x10 9000 +2 + +$ pigs wvag 0 0 10000 0x10 0x80 1000 0x80 0x10 9000 +4 +... + +WVAS :: + +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. + +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. + +... +$ pigs wvas 4 9600 8 2 0 0x30 0x31 0x32 0x33 +23 + +$ pigs wvas 7 38400 8 2 0 0x41 0x42 +35 +... + +WVTAT :: + +This command returns the id of the waveform currently +being transmitted. + +Returns the waveform id or one of the following special +values: + +9998 - transmitted wave not found +9999 - no wave being transmitted + +... +$ pigs wvtat +9999 +... + +WVBSY :: + +This command checks to see if a waveform is currently being transmitted. + +Returns 1 if a waveform is currently being transmitted, otherwise 0. + +... +$ pigs wvbsy +0 +... + +WVCHA :: + +This command transmits a chain of waveforms. + +NOTE: Any hardware PWM started by [*HP*] will +be cancelled. + +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. + +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. + +... +#!/bin/bash + +GPIO=4 +WAVES=5 + +pigs m $GPIO w + +for ((i=0; i<$WAVES; i++)) +do + pigs wvag $((1<=0) is returned. On error a negative status +code will be returned. + +The data provided by the [*WVAG*] and [*WVAS*] commands is +consumed by this command. + +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 + +Step 1. [*WVCLR*] to clear all waveforms and added data. + +Step 2. [*WVAG*]/[*WVAS*] calls to supply the waveform data. + +Step 3. [*WVCRE*] to create the waveform and get a unique id. + +Repeat steps 2 and 3 as needed. + +Step 4. [*WVTX*] or [*WVTXR*] with the id of the waveform to transmit. + +A waveform comprises of one or more pulses. + +A pulse specifies + +1) the GPIO to be switched on at the start of the pulse. +2) the GPIO to be switched off at the start of the pulse. +3) the delay in microseconds before the next pulse. + +Any or all the fields can be zero. It doesn't make any sense to +set all the fields to zero (the pulse will be ignored). + +When a waveform is started each pulse is executed in order with +the specified delay between the pulse and the next. + +... +$ pigs wvas 4 9600 0 23 45 67 89 90 +37 +$ pigs wvcre +0 + +$ pigs wvcre +-69 +ERROR: attempt to create an empty waveform +... + +WVDEL :: + +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. + +... +$ pigs wvdel 0 + +$ pigs wvdel 0 +-66 +ERROR: non existent wave id +... + +WVHLT :: + +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. + +... +$ pigs wvhlt +... + +WVNEW :: + +This clears any existing waveform data ready for the creation of a new +waveform. + +Nothing is returned. + +... +$ pigs wvnew +... + +WVSC :: + +The statistic requested by [*ws*] is returned. + +[*ws*] identifies the subcommand as follows. + +0 Get Cbs +1 Get High Cbs +2 Get Max Cbs + +... +$ pigs wvas 4 9600 0 23 45 67 89 90 +37 + +$ pigs wvsc 0 +74 +$ pigs wvsc 1 +74 +$ pigs wvsc 2 +25016 +... + +WVSM :: + +The statistic requested by [*ws*] is returned. + +[*ws*] identifies the subcommand as follows. + +0 Get Micros +1 Get High Micros +2 Get Max Micros + +... +$ pigs wvsm 0 +5314 +$ pigs wvsm 1 +5314 +$ pigs wvsm 2 +1800000000 +... + +WVSP :: + +The statistic requested by [*ws*] is returned. + +[*ws*] identifies the subcommand as follows. + +0 Get Pulses +1 Get High Pulses +2 Get Max Pulses + +... +$ pigs wvsp 0 +37 +$ pigs wvsp 1 +37 +$ pigs wvsp 2 +12000 +... + +WVTX :: + +This command transmits the waveform with id [*wid*] once. + +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. + +... +$ pigs wvtx 1 +75 + +$ pigs wvtx 2 +-66 +ERROR: non existent wave id +... + +WVTXM :: + +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), or 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. + +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. + +... +$ pigs wvtxm 1 3 +75 + +$ pigs wvtxm 2 0 +-66 +ERROR: non existent wave id +... + +WVTXR :: + +This command transmits the waveform with id [*wid*] repeatedly. + +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. + +... +$ pigs wvtxr 1 +75 + +$ pigs wvtxr 2 +-66 +ERROR: non existent wave id +... + +PARAMETERS + +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<=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. + +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 + +Scripts are programs to be stored and executed by the pigpio daemon. +They are intended to mitigate any performance problems associated with +the pigpio daemon server/client model. + +*Example* + +A trivial example might be useful. Suppose you want to toggle a GPIO +on and off as fast as possible. + +From the command line you could write + +... +for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done +... + +Timing that you will see it takes about 14 seconds, or roughly +70 toggles per second. + +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. + +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. + +Let's time the script running. + +Again, ignore the details for now. + +... +time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ + do sleep 0.2; done) +... + +The script takes roughly 12 seconds to complete, or 800,000 toggles per second. + +That is the advantage of a stored script. + +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 ]];\ + 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. + +*Virtual machine* + +A script runs within a virtual machine with + +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. + +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@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 + +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. + diff --git a/DOC/src/html/download.html b/DOC/src/html/download.html new file mode 100644 index 0000000..8c2c7be --- /dev/null +++ b/DOC/src/html/download.html @@ -0,0 +1,66 @@ + + + + + +download + + +If the pigpio daemon is running it should be killed (sudo killall +pigpiod) before make install and restarted afterwards (sudo +pigpiod).
+
+The initial part of the make, the +compilation of pigpio.c, takes 100 seconds on early model +Pis.  Be patient.  The overall install takes just over 3 +minutes.
+

Download and install (V75)

+wget https://github.com/joan2937/pigpio/archive/v75.zip
+unzip v75.zip
+cd pigpio-75
+make
+sudo make install

+
+If the Python part of the install fails it may be because you need +the setup tools.
+
+sudo apt install python-setuptools +python3-setuptools

+
+

To check the library

+These tests make extensive use of GPIO 25 (pin 22).  Make sure +nothing, or only a LED, is connected to the GPIO before running the +tests.  Most tests are statistical in nature and so may on +occasion fail.  Repeated failures on the same test or many +failures in a group of tests indicate a problem.
+
+sudo ./x_pigpio # check C I/F
+
+sudo pigpiod    # start daemon
+
+./x_pigpiod_if2 # check C      I/F to +daemon
+./x_pigpio.py   # check Python I/F to daemon
+./x_pigs        # check +pigs   I/F to daemon
+./x_pipe        # check +pipe   I/F to daemon
+
+
+

To compile, link, and run a C program

+gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
+sudo ./foobar


+

To start the pigpio daemon

+sudo pigpiod
+

To stop the pigpio daemon

+sudo killall pigpiod

+

github

+git clone https://github.com/joan2937/pigpio
+

Raspbian (raspberrypi.org image)

+

This may not be the most recent version.  You can check the +version with the command pigpiod -v.

+sudo apt-get update
+sudo apt-get install pigpio python-pigpio python3-pigpio

+
+ + diff --git a/DOC/src/html/ex_LDR.html b/DOC/src/html/ex_LDR.html new file mode 100644 index 0000000..3c54c68 --- /dev/null +++ b/DOC/src/html/ex_LDR.html @@ -0,0 +1,150 @@ + + + + + +LDR example + + +

The following code shows a method of reading analogue sensors on +the digital input only Pi.  A Light Dependent Resistor (LDR) +varies its resistance according to the incident light +intensisty.

+

SETUP

+fritzing diagramThe LDR +used is a Cadmium Sulphide device with a 1MOhm dark resistance and +2-4KOhm at 100 lux.  The capacitor is a 104 +ceramic.
+
+One end of the capacitor is connected to Pi ground.
+
+One end of the LDR is connected to Pi 3V3.
+
+The other ends of the capacitor and LDR are connected to a spare +gpio.

+

Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18 +(P1-12) is used for the gpio.

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/* +-----------------------------------------------------------------------
+ +
+   3V3 ----- Light Dependent Resistor --+-- Capacitor +----- Ground
+                                        +|
+                                        ++-- gpio
+
+
+  cc -o LDR LDR.c -lpigpio -lpthread -lrt
+  sudo ./LDR
+
+*/
+
+#define LDR 18
+
+/* forward declaration */
+
+void alert(int pin, int level, uint32_t tick);
+
+int main (int argc, char *argv[])
+{
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetAlertFunc(LDR, alert); /* call alert when LDR +changes state */
+    
+   while (1)
+   {
+      gpioSetMode(LDR, PI_OUTPUT); /* +drain capacitor */
+
+      gpioWrite(LDR, PI_OFF);
+
+      gpioDelay(200); /* 50 micros is +enough, 200 is overkill */
+
+      gpioSetMode(LDR, PI_INPUT); /* start +capacitor recharge */
+
+      gpioDelay(10000); /* nominal 100 +readings per second */
+   }
+
+   gpioTerminate();
+}
+
+void alert(int pin, int level, uint32_t tick)
+{
+   static uint32_t inited = 0;
+   static uint32_t lastTick, firstTick;
+
+   uint32_t diffTick;
+
+   if (inited)
+   {
+      diffTick = tick - lastTick;
+      lastTick = tick;
+
+      if (level == 1) printf("%u %d\ ", +tick-firstTick, diffTick);
+   }
+   else
+   {
+      inited = 1;
+      firstTick = tick;
+      lastTick = firstTick;
+   }
+}
+

BUILD

+cc -o LDR LDR.c -lpigpio -lrt -lpthread
+

RUN

+sudo ./LDR >LDR.dat &
+
+While the program is running you can capture the waveform using the +notification feature built in to pigpio.  Issue the following +commands on the Pi.
+
+pigs no
+pig2vcd  </dev/pigpio0 >LDR.vcd &
+pigs nb 0 0x40000 # set bit for gpio 18
+

Change the light falling on the LDR for a few seconds (e.g. +shine a torch on it or shade it with your hands).

+pigs nc 0
+

The file LDR.vcd will contain the captured waveform, which can +be viewed using GTKWave.

+

Overview

+LDR waveform 1
+

Reading circa every 10ms

+LDR waveform 2
+

One reading, circa 400us

+LDR waveform 3
+

The file LDR.dat will contain pairs of timestamps and recharge +time (in us).  The following  script will convert the +timestamps into seconds.

+

awk '{print $1/1000000, $2}' LDR.dat +>LDR-secs.dat

+

Gnuplot is a useful tool to graph data.

+plot [14:24] 'LDR-secs.dat' with lines title 'LDR' +

Gnuplot readings 14-24 seconds

+

gnuplot 1

+plot [18:21] 'LDR-secs.dat' with lines title 'LDR'
+
+Gnuplot readings 18-21 seconds +

Gnuplot 2

+ + diff --git a/DOC/src/html/ex_ir_remote.html b/DOC/src/html/ex_ir_remote.html new file mode 100644 index 0000000..2400a11 --- /dev/null +++ b/DOC/src/html/ex_ir_remote.html @@ -0,0 +1,253 @@ + + + + + +IR remote example + + +

The following code shows one way to read an infrared remote +control device (the sort used in TVs and stereo systems).

+

SETUP

+fritzing diagramThe device used +is a SFH5110 (IR Receiver for remote control, +carrier 38 kHz).
+
Pin 1 (left from front) may be connected to any spare +gpio.  Here it's connected via a 4K7 current limiting +resistor.  This isn't really needed as the device has an +internal 23K resistor in-line.  It does no harm though.
+
+Pin 2 should be connected to a Pi ground pin.
+
+Pin 3 should be connected to a Pi 5V pin.
+

Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground +(P1-14), and pin 3 to 5V (P1-2).

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+#define IR_PIN 7
+
+#define OUTSIDE_CODE 0
+#define INSIDE_CODE  1
+
+#define MIN_MESSAGE_GAP 3000
+#define MAX_MESSAGE_END 3000
+
+#define MAX_TRANSITIONS 500
+
+/*
+   using the FNV-1a +hash                
+ +   from +http://isthe.com/chongo/tech/comp/fnv/#FNV-param
+*/
+
+#define FNV_PRIME_32 16777619
+#define FNV_BASIS_32 2166136261U
+
+static volatile uint32_t ir_hash = 0;
+
+typedef struct
+{
+   int state;
+   int count;
+   int level;
+   uint16_t micros[MAX_TRANSITIONS];
+} decode_t;
+
+/* forward declarations */
+
+void     alert(int gpio, int level, uint32_t +tick);
+uint32_t getHash(decode_t * decode);
+void     updateState(decode_t * decode, int +level, uint32_t micros);
+
+int main(int argc, char * argv[])
+{
+   if (gpioInitialise()<0)
+   {
+      return 1 ;
+   }
+
+   /* IR pin as input */
+
+   gpioSetMode(IR_PIN, PI_INPUT);
+
+   /* 5ms max gap after last pulse */
+
+   gpioSetWatchdog(IR_PIN, 5);
+
+   /* monitor IR level changes */
+
+   gpioSetAlertFunc(IR_PIN, alert);
+
+   while (1)
+   {
+      if (ir_hash)
+      {
+         /* non-zero means +new decode */
+         printf("ir code is +%u\ ", ir_hash);
+         ir_hash = 0;
+      }
+
+      gpioDelay(100000); /* check remote +10 times per second */
+   }
+
+   gpioTerminate();
+}
+
+void alert(int gpio, int level, uint32_t tick)
+{
+   static int inited = 0;
+
+   static decode_t activeHigh, activeLow;
+
+   static uint32_t lastTick;
+
+   uint32_t diffTick;
+
+   if (!inited)
+   {
+      inited = 1;
+
+      activeHigh.state = OUTSIDE_CODE; +activeHigh.level = PI_LOW;
+      activeLow.state  = +OUTSIDE_CODE; activeLow.level  = PI_HIGH;
+
+      lastTick = tick;
+      return;
+   }
+
+   diffTick = tick - lastTick;
+
+   if (level != PI_TIMEOUT) lastTick = tick;
+
+   updateState(&activeHigh, level, diffTick);
+   updateState(&activeLow, level, diffTick);
+}
+
+void updateState(decode_t * decode, int level, uint32_t micros)
+{
+   /*
+      We are dealing with active high as +well as active low
+      remotes.  Abstract the common +functionality.
+   */
+
+   if (decode->state == OUTSIDE_CODE)
+   {
+      if (level == decode->level)
+      {
+         if (micros > +MIN_MESSAGE_GAP)
+         {
+            +decode->state = INSIDE_CODE;
+            +decode->count = 0;
+         }
+      }
+   }
+   else
+   {
+      if (micros > MAX_MESSAGE_END)
+      {
+         /* end of message +*/
+
+         /* ignore if last +code not consumed */
+
+         if (!ir_hash) +ir_hash = getHash(decode);
+
+         decode->state = +OUTSIDE_CODE;
+      }
+      else
+      {
+         if +(decode->count < (MAX_TRANSITIONS-1))
+         {
+            +if (level != PI_TIMEOUT)
+               +decode->micros[decode->count++] = micros;
+         }
+      }
+   }
+}
+
+int compare(unsigned int oldval, unsigned int newval)
+{
+   if      (newval < (oldval +* 0.75)) {return 1;}
+   else if (oldval < (newval * 0.75)) {return 2;}
+   +else                               +{return 4;}
+}
+
+uint32_t getHash(decode_t * decode)
+{
+   /* use FNV-1a */
+
+   uint32_t hash;
+   int i, value;
+
+   if (decode->count < 6) {return 0;}
+
+   hash = FNV_BASIS_32;
+
+   for (i=0; i<(decode->count-2); i++)
+   {
+      value = +compare(decode->micros[i], decode->micros[i+2]);
+
+      hash = hash ^ value;
+      hash = (hash * FNV_PRIME_32);
+   }
+
+   return hash;
+}
+

BUILD

+cc -o ir_remote ir_remote.c -lpigpio -lrt +-lpthread
+

RUN

+sudo ./ir_remote
+

A hash code is formed from the level transitions detected during +a remote key press.  This is likely to be unique over multiple +remotes and keys.

+

While the program is running you can capture the waveform using +the notification feature built in to pigpio.  Issue the +following commands on the Pi.

+pigs no
+pig2vcd  </dev/pigpio0 >ir.vcd &
+pigs nb 0 0x80 # set bits for gpios 7 (0x80)
+

Press a few different remotes and keys.  Then enter

+pigs nc 0
+

The file ir.vcd will contain the captured waveform, which can be +viewed using GTKWave.

+

Overview

+ir remote waveform 1
+

Remote A typical waveform

+ir remote waveform 2
+

Remote B typical waveform

++"ir + + diff --git a/DOC/src/html/ex_motor_shield.html b/DOC/src/html/ex_motor_shield.html new file mode 100644 index 0000000..777ba9e --- /dev/null +++ b/DOC/src/html/ex_motor_shield.html @@ -0,0 +1,254 @@ + + + + + +Arduino motor shield example + + +The following example demonstrates the use of an Arduino shield +from the Rasperry Pi.
+
+The shield used is a clone of the Adafruit motor shield.  See +shieldlist.org +for details.
+
+For the demonstration DC motors 3 and 4 are being driven forwards +and backwards with changing speeds (speeds are controlled via +PWM).
+
+Seven connections are made between the Pi and the shield.  +Four to latch the motor states (latch, enable, data, clock); Two to +control motor speed (PWM 3 and 4); and ground.
+
+The code used was ported from the Adafruit Arduino code and +converted to use the pigpio library.  Only the DC motor code +was ported.
+
+A video of the shield in use is available at youtube.com
+
+#include <stdio.h>

+
+#include <pigpio.h>
+
+/*
+   This code may be used to drive the Adafruit (or +clones) Motor Shield.
+
+   The code as written only supports DC motors.
+
+   http://shieldlist.org/adafruit/motor
+
+   The shield pinouts are
+
+   D12 MOTORLATCH
+   D11 PMW motor 1
+   D10 Servo 1
+   D9  Servo 2
+   D8  MOTORDATA
+
+   D7  MOTORENABLE
+   D6  PWM motor 4
+   D5  PWM motor 3
+   D4  MOTORCLK
+   D3  PWM motor 2
+
+   The motor states (forward, backward, brake, release) +are encoded using the
+   MOTOR_ latch pins.  This saves four gpios.
+*/
+
+typedef unsigned char uint8_t;
+
+#define BIT(bit) (1 << (bit))
+
+/* assign gpios to drive the shield pins */
+
+/*      +Shield      Pi */
+
+#define MOTORLATCH  14
+#define MOTORCLK    24
+#define MOTORENABLE 25
+#define MOTORDATA   15
+
+#define MOTOR_3_PWM  7
+#define MOTOR_4_PWM  8
+
+/*
+   The only other connection needed between the Pi and +the shield
+   is ground to ground. I used Pi P1-6 to shield gnd +(next to D13).
+*/
+
+/* assignment of motor states to latch */
+
+#define MOTOR1_A 2
+#define MOTOR1_B 3
+#define MOTOR2_A 1
+#define MOTOR2_B 4
+#define MOTOR4_A 0
+#define MOTOR4_B 6
+#define MOTOR3_A 5
+#define MOTOR3_B 7
+
+#define FORWARD  1
+#define BACKWARD 2
+#define BRAKE    3
+#define RELEASE  4
+
+static uint8_t latch_state;
+
+void latch_tx(void)
+{
+   unsigned char i;
+
+   gpioWrite(MOTORLATCH, PI_LOW);
+
+   gpioWrite(MOTORDATA, PI_LOW);
+
+   for (i=0; i<8; i++)
+   {
+      gpioDelay(10);  // 10 micros +delay
+
+      gpioWrite(MOTORCLK, PI_LOW);
+
+      if (latch_state & BIT(7-i)) +gpioWrite(MOTORDATA, PI_HIGH);
+      +else                        +gpioWrite(MOTORDATA, PI_LOW);
+
+      gpioDelay(10);  // 10 micros +delay
+
+      gpioWrite(MOTORCLK, PI_HIGH);
+   }
+
+   gpioWrite(MOTORLATCH, PI_HIGH);
+}
+
+void init(void)
+{
+   latch_state = 0;
+
+   latch_tx();
+
+   gpioWrite(MOTORENABLE, PI_LOW);
+}
+
+void DCMotorInit(uint8_t num)
+{
+   switch (num)
+   {
+      case 1: latch_state &= +~BIT(MOTOR1_A) & ~BIT(MOTOR1_B); break;
+      case 2: latch_state &= +~BIT(MOTOR2_A) & ~BIT(MOTOR2_B); break;
+      case 3: latch_state &= +~BIT(MOTOR3_A) & ~BIT(MOTOR3_B); break;
+      case 4: latch_state &= +~BIT(MOTOR4_A) & ~BIT(MOTOR4_B); break;
+      default: return;
+   }
+
+   latch_tx();
+
+   printf("Latch=%08X\ ", latch_state);
+}
+
+void DCMotorRun(uint8_t motornum, uint8_t cmd)
+{
+   uint8_t a, b;
+
+   switch (motornum)
+   {
+      case 1: a = MOTOR1_A; b = MOTOR1_B; +break;
+      case 2: a = MOTOR2_A; b = MOTOR2_B; +break;
+      case 3: a = MOTOR3_A; b = MOTOR3_B; +break;
+      case 4: a = MOTOR4_A; b = MOTOR4_B; +break;
+      default: return;
+   }

+   switch (cmd)
+   {
+      case FORWARD:  latch_state +|=  BIT(a); latch_state &= ~BIT(b); break;
+      case BACKWARD: latch_state &= +~BIT(a); latch_state |=  BIT(b); break;
+      case RELEASE:  latch_state +&= ~BIT(a); latch_state &= ~BIT(b); break;
+      default: return;
+   }
+
+   latch_tx();
+
+   printf("Latch=%08X\ ", latch_state);
+}
+
+int main (int argc, char *argv[])
+{
+   int i;
+
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(MOTORLATCH,  PI_OUTPUT);
+   gpioSetMode(MOTORENABLE, PI_OUTPUT);
+   gpioSetMode(MOTORDATA,   PI_OUTPUT);
+   gpioSetMode(MOTORCLK,    +PI_OUTPUT);
+
+   gpioSetMode(MOTOR_3_PWM, PI_OUTPUT);
+   gpioSetMode(MOTOR_4_PWM, PI_OUTPUT);
+
+   gpioPWM(MOTOR_3_PWM, 0);
+   gpioPWM(MOTOR_4_PWM, 0);
+
+   init();
+
+   for (i=60; i<160; i+=20)
+   {
+      gpioPWM(MOTOR_3_PWM, i);
+      gpioPWM(MOTOR_4_PWM, 220-i);
+
+      DCMotorRun(3, FORWARD);
+      DCMotorRun(4, BACKWARD);
+
+      sleep(2);
+
+      DCMotorRun(3, RELEASE);
+      DCMotorRun(4, RELEASE);
+
+      sleep(2);
+
+      gpioPWM(MOTOR_4_PWM, i);
+      gpioPWM(MOTOR_3_PWM, 220-i);
+
+      DCMotorRun(3, BACKWARD);
+      DCMotorRun(4, FORWARD);
+
+      sleep(2);
+
+      DCMotorRun(3, RELEASE);
+      DCMotorRun(4, RELEASE);
+
+      sleep(2);
+   }
+
+   gpioPWM(MOTOR_4_PWM, 0);
+   gpioPWM(MOTOR_3_PWM, 0);
+
+   DCMotorRun(3, RELEASE);
+   DCMotorRun(4, RELEASE);
+
+   gpioTerminate();
+}
+ + diff --git a/DOC/src/html/ex_rotary_encoder.html b/DOC/src/html/ex_rotary_encoder.html new file mode 100644 index 0000000..b95711e --- /dev/null +++ b/DOC/src/html/ex_rotary_encoder.html @@ -0,0 +1,185 @@ + + + + + +Rotary encoder sample + + +

The following code shows one way to read an incremental +mechanical rotary enoder (the sort used for volume control in audio +systems).  These rotary encoders have two switches A and B +which return a quadrature output, i.e. they are 90 degrees out of +phase.

+

SETUP

+fritzing diagramThe common +(centre) terminal should be connected to a Pi ground. +

The A and B terminals may be connected to any spare gpios.

+

Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7 +(P1-26).

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/*
+   Rotary encoder connections:
+
+   Encoder A      - gpio +18   (pin P1-12)
+   Encoder B      - gpio +7    (pin P1-26)
+   Encoder Common - Pi ground (pin P1-20)
+*/
+
+#define ENCODER_A 18
+#define ENCODER_B  7
+
+static volatile int encoderPos;
+
+/* forward declaration */
+
+void encoderPulse(int gpio, int lev, uint32_t tick);
+
+int main(int argc, char * argv[])
+{
+   int pos=0;
+
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(ENCODER_A, PI_INPUT);
+   gpioSetMode(ENCODER_B, PI_INPUT);
+
+   /* pull up is needed as encoder common is grounded +*/
+
+   gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);
+   gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);
+
+   encoderPos = pos;
+
+   /* monitor encoder level changes */
+
+   gpioSetAlertFunc(ENCODER_A, encoderPulse);
+   gpioSetAlertFunc(ENCODER_B, encoderPulse);
+
+   while (1)
+   {
+      if (pos != encoderPos)
+      {
+         pos = +encoderPos;
+         printf("pos=%d\ ", +pos);
+      }
+      gpioDelay(20000); /* check pos 50 +times per second */
+   }
+
+   gpioTerminate();
+}
+
+void encoderPulse(int gpio, int level, uint32_t tick)
+{
+   /*
+
+             ++---------+         ++---------+      0
+             +|         +|         +|         |
+   A         +|         +|         +|         |
+             +|         +|         +|         |
+   ++---------+         ++---------+         +----- +1
+
+       ++---------+         ++---------+            +0
+       +|         +|         +|         |
+   B   +|         +|         +|         |
+       +|         +|         +|         |
+   ----+         ++---------+         ++---------+  1
+
+   */
+
+   static int levA=0, levB=0, lastGpio = -1;
+
+   if (gpio == ENCODER_A) levA = level; else levB = +level;
+
+   if (gpio != lastGpio) /* debounce */
+   {
+      lastGpio = gpio;
+
+      if ((gpio == ENCODER_A) && +(level == 0))
+      {
+         if (!levB) +++encoderPos;
+      }
+      else if ((gpio == ENCODER_B) +&& (level == 1))
+      {
+         if (levA) +--encoderPos;
+      }
+   }
+}
+

BUILD

+cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt +-lpthread
+

RUN

+sudo ./rotary_encoder
+

While the program is running you can capture the waveform using +the notification feature built in to pigpio.  Issue the +following commands on the Pi.

+pigs no
+pig2vcd  </dev/pigpio0 >re.vcd &
+pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18 +(0x40000)
+

Twiddle the rotary encoder forwards and backwards for a few +seconds.  Then enter

+pigs nc 0
+

The file re.vcd will contain the captured waveform, which can be +viewed using GTKWave.

+
+Overview
+
++"rotary
+
+Detail of switch bounce.  Contact A bounces for circa 700 us +before completing the level transition
+
++"rotary
+ + diff --git a/DOC/src/html/ex_sonar_ranger.html b/DOC/src/html/ex_sonar_ranger.html new file mode 100644 index 0000000..8edb9c2 --- /dev/null +++ b/DOC/src/html/ex_sonar_ranger.html @@ -0,0 +1,164 @@ + + + + + +Sonar ranger example + + +

The following code shows a method of reading a class of sonar +rangers.  These rangers requires a trigger pulse.  +Shortly after receiving a trigger they transmit a noise pulse and +set the echo line high.  When the echo is received the echo +line is set low.

+

SETUP

+fritzing diagram
+
+
+
+
+The ranger used is a SRF05 (check the pinouts, there are many +variants).
+
+The fritzing diagram shows the back of the ranger, i.e. pin 1 is +the rightmost.
+
+Pin 1 is 5V.
+Pin 2 is the trigger line.
+Pin 3 is the echo line.
+Pin 4 is out (unused).
+Pin 5 is ground.
+
+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/*
+
+P1  Name  gpio    used for
+
+ 2  5V    ---     +5V
+ 6  GND   ---     +Ground
+24  CE0   8       +Sonar echo
+26  CE1   7       +Sonar trigger
+
+*/
+
+#define SONAR_TRIGGER 7
+#define SONAR_ECHO    8
+
+/* forward prototypes */
+
+void sonarTrigger(void);
+
+void sonarEcho(int gpio, int level, uint32_t tick);
+
+int main(int argc, char *argv[])
+{
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);
+   gpioWrite  (SONAR_TRIGGER, PI_OFF);
+
+   gpioSetMode(SONAR_ECHO,    +PI_INPUT);
+
+   /* update sonar 20 times a second, timer #0 */
+
+   gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms +*/
+
+   /* monitor sonar echos */
+
+   gpioSetAlertFunc(SONAR_ECHO, sonarEcho);
+
+   while (1) sleep(1);
+
+   gpioTerminate();
+
+   return 0;
+}
+
+void sonarTrigger(void)
+{
+   /* trigger a sonar reading */
+
+   gpioWrite(SONAR_TRIGGER, PI_ON);
+
+   gpioDelay(10); /* 10us trigger pulse */
+
+   gpioWrite(SONAR_TRIGGER, PI_OFF);
+}
+
+void sonarEcho(int gpio, int level, uint32_t tick)
+{
+   static uint32_t startTick, firstTick=0;
+
+   int diffTick;
+
+   if (!firstTick) firstTick = tick;
+
+   if (level == PI_ON)
+   {
+      startTick = tick;
+   }
+   else if (level == PI_OFF)
+   {
+      diffTick = tick - startTick;
+
+      printf("%u %u\ ", tick-firstTick, +diffTick);
+   }
+}
+

BUILD

+cc -o sonar sonar.c -lpigpio -lrt -lpthread
+

RUN

+sudo ./sonar >sonar.dat &
+
+While the program is running you can capture the waveform using the +notification feature built in to pigpio.  Issue the following +commands on the Pi.
+
+pigs no
+pig2vcd  </dev/pigpio0 >sonar.vcd &
+pigs nb 0 0x180 # set bits for gpios 7 and 8
+

Move an object in front of the sonar ranger for a few +seconds.

+pigs nc 0
+

The file sonar.vcd will contain the captured waveform, which can +be viewed using GTKWave.

+

Overview

+LDR waveform 1
+

Reading circa every 10ms

+Sonar waveform 2
+

One reading, circa 400us

+Sonar waveform 3
+

another

+Sonar waveform 4
+

The file sonar.dat will contain pairs of timestamps and echo +length (in us).  The following  script will convert the +timestamps into seconds.

+

awk '{print $1/1000000, $2}' sonar.dat +>sonar-secs.dat

+

Gnuplot is a useful tool to graph data.

+plot 'sonar-secs.dat' title 'Sonar'
+

gnuplot 1
+ plot [10:25] 'sonar-secs.dat' title 'Sonar'

+

gnuplot 1

+ + diff --git a/DOC/src/html/faq.html b/DOC/src/html/faq.html new file mode 100644 index 0000000..b8d6df5 --- /dev/null +++ b/DOC/src/html/faq.html @@ -0,0 +1,462 @@ + + + + + +faq + + +Are my GPIO broken?
+
+Audio is broken
+
+Can´t initialise pigpio +library
+
+Can´t lock +var/run/pigpio.pid
+
+Hello World!
+
+Clock skew, make fails
+
+Have I fried my GPIO?
+
+How do I debounce +inputs?
+
+How fast is SPI?
+
+Library update didn't work
+
+make fails with clock skew
+
+Porting pigpio to another CPU/SoC
+
+Sound isn't working
+
+Symbol not found
+
+What is I2C?
+
+What is Serial?
+
+What is SPI?
+
+Which library should I use?
+
+

Are my +GPIO broken?

+

See Have I fried my +GPIO?

+

Audio is +broken

+

See Sound isn't +working

+

Can´t lock +/var/run/pigpio.pid

+

See Can´t_initialise_pigpio_library
+

+

Can´t initialise pigpio +library

+

This message means the pigpio daemon is already running.

+

The default daemon is called pigpiod and may be removed as +follows.

+Check that it is running with the command +

ps aux | grep pigpiod

+

Kill the daemon with

+

sudo killall pigpiod

+

If your own program is acting as the daemon it may be removed as +follows.

+

Find its process id (pid).

+

cat /var/run/pigpio.pid

+

Kill the program with

+

sudo kill -9 pid

+If the above doesn't work do the following and try starting the +daemon again +

sudo rm /var/run/pigpio.pid

+

To start the daemon do

+

sudo pigpiod

+

Have I fried my GPIO?

+

If you think you have damaged one or more GPIO you can carry out +a diagnostic test.

+

The test is a command line script called gpiotest

+For the duration of the test nothing must be connected to the GPIO +(no LEDs, wires, ribbon cables etc.). +

The test checks that each GPIO may be read and written and that +the internal resistor pull-ups and pull-downs are functional.

+

A video +showing what happens to the GPIO during a test.

+

A test with all GPIO okay.

+
This program checks the Pi's (user) gpios.
+
+The program reads and writes all the gpios.  Make sure NOTHING
+is connected to the gpios during this test.
+
+The program uses the pigpio daemon which must be running.
+
+To start the daemon use the command sudo pigpiod.
+
+Press the ENTER key to continue or ctrl-C to abort...
+
+Testing...
+Skipped non-user gpios: 0 1 28 29 30 31 
+Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 +Failed user gpios: None +
+

A test showing failed GPIO.

+
This program checks the Pi's (user) gpios.
+
+The program reads and writes all the gpios. Make sure NOTHING
+is connected to the gpios during this test.
+
+The program uses the pigpio daemon which must be running.
+
+To start the daemon use the command sudo pigpiod.
+
+Press the ENTER key to continue or ctrl-C to abort...
+
+Testing...
+Write 1 to gpio 17 failed.
+Pull up on gpio 17 failed.
+Write 1 to gpio 18 failed.
+Pull up on gpio 18 failed.
+Write 0 to gpio 23 failed.
+Pull down on gpio 23 failed.
+Write 0 to gpio 24 failed.
+Pull down on gpio 24 failed.
+Write 1 to gpio 27 failed.
+Pull up on gpio 27 failed.
+Skipped non-user gpios: 0 1 28 29 30 31
+Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 +Failed user gpios: 17 18 23 24 27 +
+

How do I debounce inputs?

+

Some devices like mechanical switches can generate multiple +interrupts as they bounce between on and off.  It is possible +to debounce the inputs in hardware by the correct use of resistors +and capacitors.

+

In software use the glitch filter which ignores all events +shorter than a set number of microseconds.  C gpioGlitchFilter, Python set_glitch_filter.

+

How fast is +SPI?

+The SPI throughput in samples per second depends on a number of +factors.
+
+
    +
  • The SPI bit rate (transfer rate in bits per second)
  • +
+
    +
  • The number of bytes transferred per sample (a 12 bit ADC sample +may require 3 bytes to transfer)
  • +
+
    +
  • The driver used
  • +
+

Two of those factors are fixed, the variable is the driver +used.

+

The pigpio driver is considerably faster than the Linux SPI +driver as is demonstrated by the following graphs.

+

Each graph shows the SPI bit rate in bits per second along the +horizontal axis.  The samples per second achieved is shown on +the vertical axis.  Each graph contains plots assuming 1 to 5 +bytes per transfer.

+

The source code used for the tests is spi-driver-speed.c and spi-pigpio-speed.c

+

spi-lnx-pibr1.png

+
+

spi-pig-pibr1.png

+
+

spi-lnx-pi3b.png

+
+

spi-pig-pi3b.png

+

Library update didn't work

+

pigpio places files in the following locations

+

/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
+/usr/local/lib (libpigpio.so, libpigpiod_if.so, +libpigpiod_if2.so)
+/usr/local/bin (pig2vcd, pigpiod, pigs)
+/usr/local/man (man pages)

+The raspberrypi.org image containing pigpio uses different +locations.
+

/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
+/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)
+/usr/bin (pig2vcd, pigpiod, pigs)
+/usr/man (man pages)

+

Mostly this doesn't matter as the /usr/local directories will +generally be earlier in the search path.  The pigpio built +includes, binaries, and manuals are normally found first.

+

However the wrong libraries may be linked during the +compilation.  If this is the case remove the /usr/lib entries +for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so

+

Hello World!

+

The following examples show how to use the various components of +the pigpio library.

+

Each example shows how to read the level of a GPIO.

+

C

+read_cif.c +
+#include <stdio.h>
+#include <pigpio.h>
+
+int main(int argc, char *argv[])
+{
+   int GPIO=4;
+   int level;
+
+   if (gpioInitialise() < 0) return 1;
+
+   level = gpioRead(GPIO);
+
+   printf("GPIO %d is %d\n", GPIO, level);
+
+   gpioTerminate();
+}
+    
+

Build

+gcc -pthread -o read_cif read_cif.c -lpigpio +

Run

+sudo ./read_cif +

C via pigpio daemon

+read_pdif.c +
+#include <stdio.h>
+#include <pigpiod_if2.h>
+
+int main(int argc, char *argv[])
+{
+   int pi;
+   int GPIO=4;
+   int level;
+
+   pi = pigpio_start(0, 0); /* Connect to local Pi. */
+
+   if (pi < 0)
+   {
+      printf("Can't connect to pigpio daemon\n");
+      return 1;
+   }
+
+   level = gpio_read(pi, GPIO);
+
+   printf("GPIO %d is %d\n", GPIO, level);
+
+   pigpio_stop(pi); /* Disconnect from local Pi. */
+   
+   return 0;
+}
+
+

Build

+gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2 +

Run

+./read_pdif +

Python

+read_gpio.py +
+#!/usr/bin/env python
+
+import pigpio
+
+GPIO=4
+
+pi = pigpio.pi()
+if not pi.connected:
+   exit()
+
+level = pi.read(GPIO)
+
+print("GPIO {} is {}".format(GPIO, level))
+
+pi.stop()
+    
+

Run

+python read_gpio.py +

pigs

+
+pigs r 4
+    
+

pipe I/F

+
+echo "r 4" >/dev/pigpio
+cat /dev/pigout
+    
+

make fails with clock +skew

+

If make fails with one of the following messages it is probably +because the Pi's clock is wrong.

+

make: Warning: File 'xxx' has modification time x s in the +future
+make: warning: Clock skew detected. Your build may be +incomplete.

+

make uses the current time to work out which files need to be +rebuilt (a file is rebuilt if it depends on other files which have +a later time-stamp).

+

The solution is to make sure the system clock is correct.  +If the Pi is networked this will not normally be a problem.

+

To set the date and time use the date command as in the +following example.

+

sudo date -d "2017-03-01 18:47:00"

+

Porting pigpio +to another CPU/SoC

+

Sound +isn't working

+

The Pi contains two pieces of hardware, a PWM peripheral and a +PCM peripheral, to generate sound.  The PWM peripheral is +normally used and generates medium quality audio out of the +headphone jack.  The PCM peripheral may be used by add-ons +such as HATs and generates high quality audio.

+

pigpio uses at least one of these peripherals during normal +operation (for timing DMA transfers).  pigpio will use both +peripherals if waves or the hardware PWM function is used.

+

By default pigpio uses the PCM peripheral leaving the PWM +peripheral free for medium quality audio.

+

You can change the default with a configuration option.  +For C use gpioCfgClock, for the +pigpio daemon use the -t option.

+

What is I2C?

+

I2C is a data link between the Pi (master) and one or more +slaves.

+

Data may be sent and received but the Pi initiates all +transfers.

+

I2C is a medium speed link.  On the Pi the default speed is +100 kbps, but 400 kbps also works.

+

I2C is implemented as a bus with two lines called

+
    +
  • SDA - for data
  • +
  • SCL - for a clock
  • +
+On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO +3 (pin 5) for SCL.
+
+Only one slave device may be communicated with at a time.  +Each message from the Pi includes the slave to be addressed and +whether a read or write is to be performed.
+
+When the Pi (master) wishes to talk to a slave it begins by issuing +a start sequence on the I2C bus. A start sequence is one of two +special sequences defined for the I2C bus, the other being the stop +sequence. The start sequence and stop sequence are special in that +these are the only places where the SDA (data line) is allowed to +change while the SCL (clock line) is high. When data is being +transferred, SDA must remain stable and not change whilst SCL is +high. The start and stop sequences mark the beginning and end of a +transaction with the slave device.
+
+I2C start and stop sequences
+
+Data is transferred in 8-bit bytes. The bytes are placed on the SDA +line starting with the most significant bit. The SCL line is then +pulsed high, then low. For every byte transferred, the device +receiving the data sends back an acknowledge bit, so there are +actually 9 SCL clock pulses to transfer each 8-bit byte of data. If +the receiving device sends back a low ACK bit, then it has received +the data and is ready to accept another byte. If it sends back a +high then it is indicating it cannot accept any further data and +the master should terminate the transfer by sending a stop +sequence.
+
+

I2C waveform

+

What is +Serial?

+

Serial is a data link between the Pi and one other +device.

+

Data may be sent and received.  Either the Pi or the device +can initiate a transfer.

+

Serial is a low to medium speed link.  On the Pi speeds of +50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, +19200, 38400, 57600, 115200, and 230400 bps may be used.

+

Serial is implemented with one line for transmit called TXD and +one line for receive called RXD.

+

If only receive or transmit are required the other line need not +be connected.

+

The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for +RXD.

+

Data is normally transmitted in 8-bit bytes with a start bit, +eight data bits, no parity, and one stop bit.  This is +represented as 8N1.  The number of transmitted bits per second +(bps) is called the baud rate.   The time for each bit, +1 / baud rate seconds, is +referred to as the bit period.

+

The lines are in the high state when no data is being +transmitted.  The start of a byte is signalled by the line +going low for one bit period (the start bit).  The data bits +are then sent least significant bit firsts (low if the bit is 0, +high if the bit is 1).  The data bits are followed by the +optional parity bit.  Finally the line is set high for at +least the number of stop bit periods.  The line will stay high +if there are no more bytes to be transmitted.

+

Serial waveform

+

What is SPI?

+

SPI is a data link between the Pi (master) and one or more +slaves.

+

Data may be sent and received but the Pi initiates all +transfers.

+

SPI is a medium to high speed link.  On the Pi speeds of 32 +kbps to 8 Mbps may be used.

+

SPI is implemented as a bus with three lines called

+
    +
  • MOSI - for data from the Pi to the slave
  • +
  • MISO - for data from the slave to the Pi
  • +
  • SCLK - for a clock
  • +
+Only one slave device may be communicated with at a time.  An +additional line per slave called slave select is used to identify +the slave to be addressed. +

The Pi has two SPI buses

+
    +
  1. the main SPI bus +
      +
    • MOSI GPIO 10 (pin 19)
    • +
    • MISO GPIO 9 (pin 21)
    • +
    • SCLK GPIO 11 (pin 23)
    • +
    • Slave selects
    • +
    • +
        +
      • CE0 GPIO 8 (pin 24)
      • +
      • CE1 GPIO 7 (pin 26)
      • +
      +
    • +
    +
  2. +
  3. the auxiliary SPI bus +
      +
    • MOSI GPIO 20 (pin 38)
    • +
    • MISO GPIO 19 (pin 35)
    • +
    • SCLK GPIO 21 (pin 40)
    • +
    • Slave selects
    • +
    • +
        +
      • CE0 GPIO 18 (pin 12)
      • +
      • CE1 GPIO 17 (pin 11)
      • +
      • CE2 GPIO 16 (pin 36)
      • +
      +
    • +
    +
  4. +
+

SPI waveform

+


+

Which library +should I use?

+


+ + diff --git a/DOC/src/html/index.html b/DOC/src/html/index.html new file mode 100644 index 0000000..b34ea79 --- /dev/null +++ b/DOC/src/html/index.html @@ -0,0 +1,662 @@ + + + + + +pigpio + + +pigpio is a library for the Raspberry which allows control of the +General Purpose Input Outputs (GPIO).  pigpio works on all +versions of the Pi. +

At the moment pigpio on the Pi4B is experimental. I am not +sure if the DMA channels being used are safe. The Pi4B defaults are +primary channel 7, secondary channel 6. If these channels do not +work you will have to experiment. You can set the channels used by +the pigpio daemon by invoking it with the -d and -e options, e.g. +sudo pigpiod -d 5 -e 8 to specify primary 5, +secondary 8.

+

Download

+

Features

+
    +
  • +

    hardware timed sampling and time-stamping of GPIO 0-31 every 5 +us

    +
  • +
  • +

    hardware timed PWM on all of GPIO 0-31

    +
  • +
  • +

    hardware timed servo pulses on all of GPIO 0-31

    +
  • +
  • +

    callbacks on GPIO 0-31 level change (time accurate to a few +us)

    +
  • +
  • +

    notifications via pipe on GPIO 0-31 level change

    +
  • +
  • +

    callbacks at timed intervals

    +
  • +
  • +

    reading/writing all of the GPIO in a bank (0-31, 32-53) as a +single operation

    +
  • +
  • +

    GPIO reading, writing, modes, and internal pulls

    +
  • +
  • +

    socket and pipe interfaces for the bulk of the functionality

    +
  • +
  • +

    waveforms to generate GPIO level changes (time accurate to a few +us)

    +
  • +
  • +

    software serial links using any user GPIO

    +
  • +
  • +

    rudimentary permission control through the socket and pipe +interfaces

    +
  • +
  • creating and running scripts on the pigpio daemon
  • +
+

General

+The pigpio library is written in the C +programming language.
+
+The pigpio daemon offers a socket and pipe interface to +the underlying C library.
+
+A C library and a Python module allow control of the GPIO via the +pigpio daemon.
+
+There is third party support for a number of other languages.  +

piscope

+

piscope is a logic analyser (digital +waveform viewer).

+piscope is a GTK+3 application and uses pigpio to provide raw GPIO +level data.  piscope may be run on a Pi or on any machine +capable of compiling a GTK+3 application. +

GPIO

+

ALL GPIO are identified +by their Broadcom +number.  See +elinux.org

+There are 54 GPIO in total, arranged in two banks.
+

Bank 1 contains GPIO 0-31.  Bank 2 contains GPIO +32-53.

+For all types of Pi it is safe to read all the GPIO. If you try to +write a system GPIO or change its mode you can crash the Pi or +corrupt the data on the SD card.
+
+There are several types of board, each with different expansion +headers, giving physical access to different GPIO.  + +

Type 1 - Model B (original +model)

+
    +
  • 26 pin header (P1).
  • +
+
    +
  • Hardware revision numbers of 2 and 3.
  • +
+
    +
  • User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA0
34-5V
SCL1
56-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

211314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
+
+

Type 2 - Model A, B (revision +2)

+26 pin header (P1) and an additional 8 pin header (P5). +
    +
  • Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13, +14, 15 (B).
  • +
+
    +
  • User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
5V
-12-3V3
SDA
283429SCL

305631
Ground
-
78-
Ground
+
+

Type 3 - Model A+, B+, Pi +Zero, Pi Zero W, Pi2B, Pi3B, Pi4B

+
    +
  • 40 pin expansion header (J8).
  • +
+
    +
  • Hardware revision numbers of 16 or greater.
  • +
+
    +
  • User GPIO 2-27 (0 and 1 are reserved).
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
ID_SD027281ID_SC

52930-Ground

6313212

133334-Ground
miso19353616ce2

26373820mosi
Ground-394021sclk
+
+

Compute Module

+

All 54 GPIO may be physically accessed.  Some are reserved +for system use - refer to the Compute Module documentation.

+

Only GPIO 0-31 are supported for hardware timed sampling, PWM, +servo pulses, alert callbacks, waves, and software serial +links.

+

Other +Languages

+

There are several third party projects which provide wrappers +for pigpio.

+

Some I am aware of are:

+
    +
  • Erlang +(skvamme)
  • +
  • Java JNI +wrapper around the pigpio C library (mattlewis)
  • +
  • Java via +diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc +(mattlewis)
  • +
  • Java +(nkolban)
  • +
  • .NET/mono +(unosquare)
  • +
  • Node.js +(fivdi)
  • +
  • Perl (Gligan +Calin Horea)
  • +
  • Ruby +(Nak)
  • +
  • Smalltalk(Instantiations)
  • +
  • Xojo(UBogun)
  • +
+
+

The PWM and servo pulses are timed using the DMA +and PWM/PCM peripherals.  This use was inspired by Richard +Hirst's servoblaster kernel module.

+ + diff --git a/DOC/src/html/misc.html b/DOC/src/html/misc.html new file mode 100644 index 0000000..4c6f305 --- /dev/null +++ b/DOC/src/html/misc.html @@ -0,0 +1,33 @@ + + + + + +Miscellaneous + + +There are two C libraries which provide a socket interface to the +pigpio daemon.  They provide an interface very similar to the +pigpio Python module.
+
    +
  • The original pigpiod_if library is +now deprecated and will no longer be updated.  This library is +limited to controlling one Pi at a time.
  • +
+
    +
  • The new pigpiod_if2 library which +should be used for new code.  This library allows multiple Pis +to be controlled at one time.
  • +
+Additional details of the pigpio socket +interface.
+
+Additional details of the pigpio pipe +interface.
+
+pig2vcd is a utility which converts +pigpio notifications into the VCD (Value Change Dump) format.  +VCD can be read by many programs, in particular GTKWave. + + diff --git a/DOC/src/html/pif.html b/DOC/src/html/pif.html new file mode 100644 index 0000000..bc924ff --- /dev/null +++ b/DOC/src/html/pif.html @@ -0,0 +1,30 @@ + + + + + +Pipe interface + + +pigpio provides a pipe interface to many of its functions.
+
+The pipe interface is available whenever pigpio is running, either +because it has been started as a daemon, or it has been linked in +to a running user program.  The pipe interface can be disabled +by the program which initialises the library.  pigpiod offers +the -f option to disable the pipe interface.  User programs +should call gpioCfgInterfaces +if they wish to disable the pipe interface.
+
+pigpio listens for commands on pipe /dev/pigpio.  The commands +consist of a command identifier with, depending on the command, +zero, one, or two parameters.  The result, if any, may be read +from pipe /dev/pigout.  If any errors are detected a message +will be written to pipe /dev/pigerr.
+
+
+The format of the commands is identical to those used by pigs. + + diff --git a/DOC/src/html/piscope.html b/DOC/src/html/piscope.html new file mode 100644 index 0000000..c381057 --- /dev/null +++ b/DOC/src/html/piscope.html @@ -0,0 +1,216 @@ + + + + + +piscope + + +

Introduction

+piscope is a logic analyser (digital +waveform viewer) for the Raspberry.  It shows the state (high +or low) of selected GPIO in real-time.
+
+See video.
+
+piscope uses the services of the pigpio library.  pigpio needs to be running on +the Pi whose GPIO are to be monitored.
+
+The pigpio library may be started as a daemon (background process) +by the following command.
+
+sudo pigpiod

+piscope may be invoked in several different ways
+
+ + + + + + + + + + + + + + + + + + + + + + + +
Pi
pi_host ~ $ piscope +&
Pi captures +data
+Pi processes data
+Pi displays data
Pi plus Linux PC
+
+(with the
+display on a remote
+  Linux PC)
remote_host ~ $ ssh -X pi_host
pi_host ~ $ piscope +&
Pi captures data
+Pi processes data
+Remote Linux PC displays data
Pi plus Windows PC
+
+(with the
+display on a remote
+  Windows PC)
You need to install an SSH +client (putty suggested) and a X11 server (xming suggested).
+
+Run Program Files -> Xming -> XLaunch and accept the +defaults.
+
+Run putty and enter the Pi's host name or IP address.  Click +on SSH X11 and tick Enable X11 forwarding and then select +Open.

+
pi_host ~ $ piscope +&
Pi captures data
+Pi processes data
+Remote Windows PC displays data
Pi plus Linux PC
+
+(with the display and processing on a remote Linux +PC)
remote_host ~ $ export +PIGPIO_ADDR=pi_host
+remote_host ~ $ piscope +&
Pi captures data
+Remote processes data
+Remote displays data
+
+piscope operates in one of three modes
+
+ + + + + + + + + + + + + + + + + + +
Live
The latest GPIO samples are +displayed.
+
+The mode will automatically change to Pause if a sampling trigger +is detected.
+
+There are four triggers.  Each trigger is made up of a +combination of GPIO states (one of don't care, low, high, edge, +falling, or rising per GPIO).  Triggers are always +counted.  In addition a trigger may be sample to, sample +around, or sample from, a so called sampling trigger.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full the oldest samples are discarded.
Play
Recorded GPIO samples are +displayed.
+
+The play speed may be varied between 64 times real-time to 1/32768 +of real-time.
+
+The page up key increases the play speed by a factor of 2.  +The page down key decreases the play speed by a factor of 2.  +The home key sets the play speed to 1X.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full new samples are discarded.
Pause
Recorded GPIO samples are +displayed.
+
+The left and right cursor keys move the blue marker to the previous +or next edge.  By default all GPIO edges are considered.  +Clicking on a GPIO name will limit edge searches to the highlighted +GPIO only.
+
+The left and right square bracket keys move the blue marker to the +previous or next trigger.
+
+The time between the blue and gold markers is displayed.  The +gold marker is set to the blue marker by a press of the 'g' +key.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full new samples are discarded.
+
+In all modes the down and up cursor keys zoom the time scale in and +out.
+
+Samples can be saved with File Save All Samples or File Save +Selected Samples. +

To select samples enter pause mode. Press 1 to specify the start +of the samples (green marker) and 2 to specify the end of the +samples (red marker).

+

The samples may be saved in the native piscope format or in VCD +format.

+

Data saved in VCD format may be viewed and further processed +with GTKWave.

+

Data saved in the native piscope format may be restored later +with File Restore Saved Data.

+

Installation

+

To download and install piscope.

+

Pi (pre-built image)

+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make hf
+make install

+

Linux 64 bit X86/AMD (pre-built image)

+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make x86_64
+make install
+

All machines (building from source)

+You only need to perform this step if you want to build the +executable from the source files.  This is not needed if you +use a pre-built image.
+
+WARNING
: Installing gtk+-3.0 uses a lot of SD card +space.
+
+Most of the space used by gtk+-3.0 is taken up by unneeded *-dbg +packages.
+
+With *-dbg packages an additional 3753MB SD space is required.
+
+If you edit the list of packages to be downloaded and remove the +*-dbg packages only 134MB of additional SD space is needed (as at +the time of writing).
+
+#
# *** This may take a lot of time and use +a lot of SD card space ***
#
+sudo apt-get install gtk+-3.0
#
+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make
+make install

+ + diff --git a/DOC/src/html/sif.html b/DOC/src/html/sif.html new file mode 100644 index 0000000..67b880b --- /dev/null +++ b/DOC/src/html/sif.html @@ -0,0 +1,2004 @@ + + + + + +Socket interface + + +pigpio provides a socket interface to many of its functions.
+
+The socket interface is available whenever pigpio is running, +either because it has been started as a daemon, or it has been +linked in to a running user program.
+
+The socket interface can be disabled by the program which +initialises the library.  pigpiod offers the -k option to +disable the socket interface.  User programs should call +gpioCfgInterfaces if they +wish to disable the socket interface.
+
+pigpio listens for connections on port 8888 by default.  This +default may be overridden when pigpio starts by the gpioCfgSocketPort function +call.  The pigpio daemon uses this function to provide an +option to change the port number.
+
+The pigs utility is an example of using the socket interface from +C.
+

Request

+

pigpio expects messages of type cmdCmd_t immediately followed with an +extension for a few commands.
+
+The caller should fill in cmd, p1, p2, p3/res, and any extension as +needed.  p3 will always be zero unless the command requires an +extension in which case p3 will be the length in bytes of the +extension.
+
+The cmdCmd_t is echoed back with +the result, if any, in p3/res, and an extension immediately +afterwards for a few commands.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
COMMANDcmd
p1p2p3Extension
MODES0gpiomode0-
MODEG1gpio00-
PUD2gpiopud0-
READ3gpio00-
WRITE4gpiolevel0-
PWM5gpiodutycycle0-
PRS6gpiorange0-
PFS7gpiofrequency0-
SERVO8gpiopulsewidth0-
WDOG9gpiotimeout0-
BR110000-
BR211000-
BC112bits00-
BC213bits00-
BS114bits00-
BS215bits00-
TICK16000-
HWVER17000-
NO18000-
NB19handlebits0-
NP20handle00-
NC21handle00-
PRG22gpio00-
PFG23gpio00-
PRRG24gpio00-
HELP
25N/A
N/A
N/A
N/A
PIGPV26000-
WVCLR27000-
WVAG280012*XgpioPulse_t pulse[X]
WVAS29gpiobaud12+Xuint32_t databits
+uint32_t stophalfbits
+uint32_t offset
+uint8_t data[X]
N/A
30000-
N/A
31000-
WVBSY32000-
WVHLT33000-
WVSM34subcmd00-
WVSP35subcmd00-
WVSC36subcmd00-
TRIG37gpiopulselen4uint32_t level
PROC3800Xuint8_t text[X]
PROCD39script_id00-
PROCR40script_id04*X
uint32_t pars[X]
PROCS41script_id00-
SLRO42gpiobaud4uint32_t databits
SLR43gpiocount0-
SLRC44gpio00-
PROCP45script_id00-
MICS46micros00-
MILS47millis00-
PARSE48N/AN/A
N/A
N/A
WVCRE49000-
WVDEL50wave_id00-
WVTX51wave_id00-
WVTXR52wave_id00-
WVNEW53000-
I2CO54busdevice4uint32_t flags
I2CC55handle00-
I2CRD56handlecount0-
I2CWD57handle0Xuint8_t data[X]
I2CWQ58handlebit0-
I2CRS59handle00-
I2CWS60handlebyte0-
I2CRB61handleregister0-
I2CWB62handleregister4uint32_t byte
I2CRW63handleregister0-
I2CWW64handleregister4uint32_t word
I2CRK65handleregister
0-
I2CWK66handleregister
Xuint8_t bvs[X]
I2CRI67handleregister
4uint32_t num
I2CWI68handleregister
X
uint8_t bvs[X]
I2CPC69handleregister
4uint32_t word
I2CPK70handleregister
X
uint8_t data[X]
SPIO
71channelbaud4uint32_t flags
SPIC72handle00-
SPIR73handlecount0-
SPIW74handle0Xuint8_t data[X]
SPIX75handle0Xuint8_t data[X]
SERO76baudflagsXuint8_t device[X]
SERC77handle00-
SERRB78handle00-
SERWB79handlebyte0-
SERR80handlecount0-
SERW81handle0Xuint8_t data[X]
SERDA82handle00-
GDC
83
gpio
0
0
-
GPW
84
gpio
0
0
-
HC
85
gpio
frequency
0
-
HP
86
gpio
frequency
4
uint32_t dutycycle
CF1
87
arg1
arg2
X
uint8_t argx[X]
CF2
88
arg1
retMax
X
uint8_t argx[X]
BI2CC
89
sda
0
0
-
BI2CO
90
sda
scl
4
uint32_t baud
BI2CZ
91
sda
0
X
uint8_t data[X]
I2CZ
92
handle
0
X
uint8_t data[X]
WVCHA
93
0
0
X
uint8_t data[X]
SLRI
94
gpio
invert
0
-
CGI
95
0
0
0
-
CSI
96
config
0
0
-
FG
97
gpio
steady
0
-
FN
98
gpio
steady
4
uint32_t active
NOIB99000-
WVTXM
100
wave_id
mode
0
-
WVTAT
101
0
0
0
-
PADS
102
pad
strength
0
-
PADG
103
pad
0
0
-
FO
104
mode
0
X
uint8_t file[X]
FC
105
handle
0
0
-
FR
106
handle
count
0
-
FW
107
handle
0
X
uint8_t data[X]
FS
108
handle
offset
4
uint32_t from
FL
109
count
0
X
uint8_t pattern[X]
SHELL
110
len(name)
0
len(name)+
+1+
+len(string)
uint8_t name[len(name)]
+uint8_t null (0)
+uint8_t string[len(string)]
BSPIC
111
CS
0
0
-
BSPIO
112
CS
0
20
uint32_t MISO
+uint32_t MOSI
+uint32_t SCLK
+uint32_t baud
+uint32_t spi_flags
BSPIX
113
CS
0
X
uint8_t data[X]
BSCX
114
control
0
X
uint8_t data[X]
EVM
115
handle
bits
0
-
EVT
116
event
0
0
-
PROCU
117
script_id
0
4*X
uint32_t pars[X]
+

Response

+

The response has cmd/p1/p2 as in the request.  p3/res holds +the return value.  If the command returns additional values +they will be in the immediately following extension.

+Normally res should be treated as a 32 bit signed value and will be +greater than or equal to zero.  Upon failure res will be less +than 0 and contains an error code.
+

There are a few commands where the returned value should be +treated as a 32 bit unsigned value.  These commands can not +fail.  They are indicated with a * after the command +name.

+

Commands with an extension have the size of the extension in +bytes returned in res (or <0 on error as above).

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
COMMANDcmd
p1
p2
res
Extension
MODES0-
-
0-
MODEG1-
-
mode
-
PUD2-
-
0-
READ3-
-
level
-
WRITE4-
-
0-
PWM5-
-
0-
PRS6-
-
0-
PFS7-
-
0-
SERVO8-
-
0-
WDOG9-
-
0-
BR1 *10-
-
bits
-
BR2 *11-
-
bits
-
BC112-
-
0-
BC213-
-
0-
BS114-
-
0-
BS215-
-
0-
TICK *
16-
-
tick
-
HWVER *
17-
-
version
-
NO18-
-
handle
-
NB19-
-
0-
NP20-
-
0-
NC21-
-
0-
PRG22-
-
range
-
PFG23-
-
frequency
-
PRRG24-
-
real range
-
HELP25-
-
N/A
N/A
PIGPV *
26-
-
version
-
WVCLR27-
-
0-
WVAG28-
-
wave pulses
-
WVAS29-
-
wave pulses
-
N/A
30-
-
-
-
N/A
31-
-
-
-
WVBSY32-
-
busy (1) or not busy (0)
-
WVHLT33-
-
0-
WVSM34-
-
wave micros
+wave micros - high
+wave micros - max
-
WVSP35-
-
wave pulses
+wave pulses - high
+wave pulses - max
-
WVSC36-
-
wave DMA CBs
+wave DMA CBs - high
+wave DMA CBs - max
-
TRIG37-
-
0
-
PROC38-
-
script id
-
PROCD39-
-
0-
PROCR40-
-
script status
-
PROCS41-
-
0-
SLRO42-
-
0
-
SLR43-
-
X
uint8_t data[X]
SLRC44-
-
0-
PROCP45-
-
44uint32_t script_status
+uint32_t pars[10]
MICS46-
-
0-
MILS47-
-
0-
PARSE48-
-
N/A
-
WVCRE49-
-
wave id
-
WVDEL50-
-
0-
WVTX51-
-
wave DMA CBs
-
WVTXR52-
-
wave DMA CBs
-
WVNEW53-
-
0-
I2CO54-
-
handle-
I2CC55-
-
0-
I2CRD56-
-
X
uint8_t data[X]
I2CWD57-
-
0
-
I2CWQ58-
-
0-
I2CRS59-
-
byte value
-
I2CWS60-
-
0-
I2CRB61-
-
byte value
-
I2CWB62-
-
0
-
I2CRW63-
-
word value
-
I2CWW64-
-
0
-
I2CRK65-
-
0-
I2CWK66-
-
0
-
I2CRI67-
-
X
uint8_t data[X]
I2CWI68-
-
0
-
I2CPC69-
-
word value
-
I2CPK70-
-
X
uint8_t data[X]
SPIO
71-
-
handle
-
SPIC72-
-
0-
SPIR73-
-
X
uint8_t data[X]
SPIW74-
-
0
-
SPIX75-
-
Xuint8_t data[X]
SERO76-
-
handle
-
SERC77-
-
0-
SERRB78-
-
byte value
-
SERWB79-
-
0-
SERR80-
-
X
uint8_t data[X]
SERW81-
-
0
-
SERDA82-
-
data ready count
-
GDC
83
-
-
dutycycle
-
GPW
84
-
-
pulsewidth
-
HC
85
-
-
0
-
HP
86
-
-
0
-
CF1
87
-
-
value
-
CF2
88
-
-
X
uint8_t retBuf[X]
BI2CC
89
-
-
0
-
BI2CO
90
-
-
handle
-
BI2CZ
91
-
-
X
uint8_t data[X]
I2CZ
92
-
-
X
uint8_t data[X]
WVCHA
93
-
-
0
-
SLRI
94
-
-
0
-
CGI
95
-
-
config
-
CSI
96
-
-
0
-
FG
97
-
-
0
-
FN
98
-
-
0
-
NOIB99-
-
0-
WVTXM
100
-
-
wave DMA CBs
-
WVTAT
101
-
-
wave id
-
PADS
102
-
-
0
-
PADG
103
-
-
strength
-
FO
104
-
-
handle
-
FC
105
-
-
0
-
FR
106
-
-
X
uint8_t data[X]
FW
107
-
-
0
-
FS
108
-
-
position
-
FL
109
-
-
X
uint8_t filenames[X]
SHELL
110
-
-
exit status
-
BSPIC
111
-
-
0
-
BSPIO
112
-
-
0
-
BSPIX
113
-
-
X
uint8_t data[X]
BSCX
114
-
-
X+4
uint32_t status
+uint8_t data[X]
EVM
115
-
-
0
-
EVT
116
-
-
0
-
PROCU
117
-
-
0
-
+
+

cmdCmd_t

+typedef struct
+{
+   uint32_t cmd;
+   uint32_t p1;
+   uint32_t p2;
+   union
+   {
+      uint32_t p3;
+      uint32_t ext_len;
+      uint32_t res;
+   };
+} cmdCmd_t;

+ + -- cgit v1.2.3 From 7852103d13df7b061bb8afb2229e6cba7a120a93 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Tue, 24 Mar 2020 16:24:14 +0000 Subject: Added README to ensure DOC/MAN directory exists --- DOC/MAN/README | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 DOC/MAN/README diff --git a/DOC/MAN/README b/DOC/MAN/README new file mode 100644 index 0000000..2a89c86 --- /dev/null +++ b/DOC/MAN/README @@ -0,0 +1,2 @@ +Placeholder directory for man pages. + -- cgit v1.2.3 From ee593a2fc6d08eee8055b81b20ee97343122fbf5 Mon Sep 17 00:00:00 2001 From: hazuki Date: Sun, 26 Apr 2020 17:42:35 +0900 Subject: Remove excessive PROT_EXEC --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 7cd7cbf..b58cb47 100644 --- a/pigpio.c +++ b/pigpio.c @@ -7262,7 +7262,7 @@ static int initGrabLockFile(void) static uint32_t * initMapMem(int fd, uint32_t addr, uint32_t len) { return (uint32_t *) mmap(0, len, - PROT_READ|PROT_WRITE|PROT_EXEC, + PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fd, addr); } -- cgit v1.2.3 From c27a968bcc0f7f5f50c7a416eb76de6a394701a1 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Wed, 29 Apr 2020 11:25:02 -0500 Subject: Add test cases to x_* for padded waves. --- x_pigpio.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ x_pigpio.py | 41 +++++++++++++++++++++++++++++++++++++++++ x_pigpiod_if2.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ x_pigs | 20 ++++++++++++++++++++ 4 files changed, 150 insertions(+) diff --git a/x_pigpio.c b/x_pigpio.c index cd15389..8119d73 100644 --- a/x_pigpio.c +++ b/x_pigpio.c @@ -459,6 +459,51 @@ To the lascivious pleasing of a lute.\n\ c = gpioWaveGetMaxCbs(); CHECK(5, 21, c, 25016, 0, "wave get max cbs"); + + /* waveCreatePad tests */ + gpioWaveTxStop(); + gpioWaveClear(); + gpioSetAlertFunc(GPIO, t5cbf); + + e = gpioWaveAddGeneric(2, (gpioPulse_t[]) + { {1< Date: Wed, 29 Apr 2020 23:43:20 -0500 Subject: Generate docs and make corrections. --- DOC/HTML/cif.html | 1881 +++++ DOC/HTML/download.html | 121 + DOC/HTML/ex_LDR.html | 205 + DOC/HTML/ex_ir_remote.html | 308 + DOC/HTML/ex_motor_shield.html | 309 + DOC/HTML/ex_rotary_encoder.html | 240 + DOC/HTML/ex_sonar_ranger.html | 219 + DOC/HTML/examples.html | 558 ++ DOC/HTML/faq.html | 516 ++ DOC/HTML/index.html | 716 ++ DOC/HTML/misc.html | 88 + DOC/HTML/pdif.html | 1168 +++ DOC/HTML/pdif2.html | 1523 ++++ DOC/HTML/pif.html | 85 + DOC/HTML/pig2vcd.html | 83 + DOC/HTML/pigpiod.html | 114 + DOC/HTML/pigs.html | 1268 +++ DOC/HTML/piscope.html | 269 + DOC/HTML/python.html | 1293 +++ DOC/HTML/sif.html | 2058 +++++ DOC/HTML/sitemap.html | 85 + DOC/MAN/pig2vcd.1 | 246 + DOC/MAN/pigpio.3 | 11116 ++++++++++++++++++++++++++ DOC/MAN/pigpiod.1 | 273 + DOC/MAN/pigpiod_if.3 | 5339 +++++++++++++ DOC/MAN/pigpiod_if2.3 | 8050 +++++++++++++++++++ DOC/MAN/pigs.1 | 6331 +++++++++++++++ DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 | Bin 0 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 | Bin 0 -> 1433600 bytes DOC/src/defs/pigs.def | 44 + DOC/tmp/body/cif.body | 1818 +++++ DOC/tmp/body/download.body | 57 + DOC/tmp/body/ex_LDR.body | 141 + DOC/tmp/body/ex_ir_remote.body | 244 + DOC/tmp/body/ex_motor_shield.body | 245 + DOC/tmp/body/ex_rotary_encoder.body | 176 + DOC/tmp/body/ex_sonar_ranger.body | 155 + DOC/tmp/body/examples.body | 495 ++ DOC/tmp/body/faq.body | 452 ++ DOC/tmp/body/index.body | 652 ++ DOC/tmp/body/misc.body | 24 + DOC/tmp/body/pdif.body | 1105 +++ DOC/tmp/body/pdif2.body | 1460 ++++ DOC/tmp/body/pif.body | 21 + DOC/tmp/body/pig2vcd.body | 20 + DOC/tmp/body/pigpiod.body | 51 + DOC/tmp/body/pigs.body | 1205 +++ DOC/tmp/body/piscope.body | 205 + DOC/tmp/body/python.body | 1230 +++ DOC/tmp/body/sif.body | 1994 +++++ DOC/tmp/pydoc/pigpio.pydoc | 4159 ++++++++++ pigpio.3 | 87 + pigpio.h | 33 +- pigpio.py | 30 +- pigpiod_if2.3 | 83 + pigpiod_if2.h | 16 +- pigs.1 | 74 + 67 files changed, 60713 insertions(+), 25 deletions(-) create mode 100644 DOC/HTML/cif.html create mode 100644 DOC/HTML/download.html create mode 100644 DOC/HTML/ex_LDR.html create mode 100644 DOC/HTML/ex_ir_remote.html create mode 100644 DOC/HTML/ex_motor_shield.html create mode 100644 DOC/HTML/ex_rotary_encoder.html create mode 100644 DOC/HTML/ex_sonar_ranger.html create mode 100644 DOC/HTML/examples.html create mode 100644 DOC/HTML/faq.html create mode 100644 DOC/HTML/index.html create mode 100644 DOC/HTML/misc.html create mode 100644 DOC/HTML/pdif.html create mode 100644 DOC/HTML/pdif2.html create mode 100644 DOC/HTML/pif.html create mode 100644 DOC/HTML/pig2vcd.html create mode 100644 DOC/HTML/pigpiod.html create mode 100644 DOC/HTML/pigs.html create mode 100644 DOC/HTML/piscope.html create mode 100644 DOC/HTML/python.html create mode 100644 DOC/HTML/sif.html create mode 100644 DOC/HTML/sitemap.html create mode 100644 DOC/MAN/pig2vcd.1 create mode 100644 DOC/MAN/pigpio.3 create mode 100644 DOC/MAN/pigpiod.1 create mode 100644 DOC/MAN/pigpiod_if.3 create mode 100644 DOC/MAN/pigpiod_if2.3 create mode 100644 DOC/MAN/pigs.1 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 create mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 create mode 100644 DOC/tmp/body/cif.body create mode 100644 DOC/tmp/body/download.body create mode 100644 DOC/tmp/body/ex_LDR.body create mode 100644 DOC/tmp/body/ex_ir_remote.body create mode 100644 DOC/tmp/body/ex_motor_shield.body create mode 100644 DOC/tmp/body/ex_rotary_encoder.body create mode 100644 DOC/tmp/body/ex_sonar_ranger.body create mode 100644 DOC/tmp/body/examples.body create mode 100644 DOC/tmp/body/faq.body create mode 100644 DOC/tmp/body/index.body create mode 100644 DOC/tmp/body/misc.body create mode 100644 DOC/tmp/body/pdif.body create mode 100644 DOC/tmp/body/pdif2.body create mode 100644 DOC/tmp/body/pif.body create mode 100644 DOC/tmp/body/pig2vcd.body create mode 100644 DOC/tmp/body/pigpiod.body create mode 100644 DOC/tmp/body/pigs.body create mode 100644 DOC/tmp/body/piscope.body create mode 100644 DOC/tmp/body/python.body create mode 100644 DOC/tmp/body/sif.body create mode 100644 DOC/tmp/pydoc/pigpio.pydoc diff --git a/DOC/HTML/cif.html b/DOC/HTML/cif.html new file mode 100644 index 0000000..6b9761f --- /dev/null +++ b/DOC/HTML/cif.html @@ -0,0 +1,1881 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

pigpio C Interface



pigpio is a C library for the Raspberry which allows control of the GPIO. +

Features

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o callbacks when any of GPIO 0-31 change state +

o callbacks at timed intervals +

o reading/writing all of the GPIO in a bank as one operation +

o individually setting GPIO modes, reading and writing +

o notifications when any of GPIO 0-31 change state +

o the construction of output waveforms with microsecond timing +

o rudimentary permission control over GPIO +

o a simple interface to start and stop new threads +

o I2C, SPI, and serial link wrappers +

o creating and running scripts +

GPIO

ALL GPIO are identified by their Broadcom number. +

Credits

The PWM and servo pulses are timed using the DMA and PWM peripherals. +

This use was inspired by Richard Hirst's servoblaster kernel module. +

Usage

Include <pigpio.h> in your source files. +

Assuming your source is in prog.c use the following command to build and +run the executable. +

gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
sudo ./prog


For examples of usage see the C programs within the pigpio archive file. +

Notes

All the functions which return an int return < 0 on error. +

gpioInitialise must be called before all other library functions +with the following exceptions: +

gpioCfg*
gpioVersion
gpioHardwareRevision


If the library is not initialised all but the gpioCfg*, +gpioVersion, and gpioHardwareRevision functions will +return error PI_NOT_INITIALISED. +

If the library is initialised the gpioCfg* functions will return +error PI_INITIALISED. +

OVERVIEW

ESSENTIAL +
gpioInitialise Initialise library +
gpioTerminate Stop library +
BASIC +
gpioSetMode Set a GPIO mode +
gpioGetMode Get a GPIO mode +
gpioSetPullUpDown Set/clear GPIO pull up/down resistor +
gpioRead Read a GPIO +
gpioWrite Write a GPIO +
PWM (overrides servo commands on same GPIO) +
gpioPWM Start/stop PWM pulses on a GPIO +
gpioSetPWMfrequency Configure PWM frequency for a GPIO +
gpioSetPWMrange Configure PWM range for a GPIO +
gpioGetPWMdutycycle Get dutycycle setting on a GPIO +
gpioGetPWMfrequency Get configured PWM frequency for a GPIO +
gpioGetPWMrange Get configured PWM range for a GPIO +
gpioGetPWMrealRange Get underlying PWM range for a GPIO +
Servo (overrides PWM commands on same GPIO) +
gpioServo Start/stop servo pulses on a GPIO +
gpioGetServoPulsewidth Get pulsewidth setting on a GPIO +
INTERMEDIATE +
gpioTrigger Send a trigger pulse to a GPIO +
gpioSetWatchdog Set a watchdog on a GPIO +
gpioRead_Bits_0_31 Read all GPIO in bank 1 +
gpioRead_Bits_32_53 Read all GPIO in bank 2 +
gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 +
gpioWrite_Bits_32_53_ClearClear selected GPIO in bank 2 +
gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 +
gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 +
gpioSetAlertFunc Request a GPIO level change callback +
gpioSetAlertFuncEx Request a GPIO change callback, extended +
gpioSetTimerFunc Request a regular timed callback +
gpioSetTimerFuncEx Request a regular timed callback, extended +
gpioStartThread Start a new thread +
gpioStopThread Stop a previously started thread +
ADVANCED +
gpioNotifyOpen Request a notification handle +
gpioNotifyClose Close a notification +
gpioNotifyOpenWithSize Request a notification with sized pipe +
gpioNotifyBegin Start notifications for selected GPIO +
gpioNotifyPause Pause notifications +
gpioHardwareClock Start hardware clock on supported GPIO +
gpioHardwarePWM Start hardware PWM on supported GPIO +
gpioGlitchFilter Set a glitch filter on a GPIO +
gpioNoiseFilter Set a noise filter on a GPIO +
gpioSetPad Sets a pads drive strength +
gpioGetPad Gets a pads drive strength +
shell Executes a shell command +
gpioSetISRFunc Request a GPIO interrupt callback +
gpioSetISRFuncEx Request a GPIO interrupt callback, extended +
gpioSetSignalFunc Request a signal callback +
gpioSetSignalFuncEx Request a signal callback, extended +
gpioSetGetSamplesFunc Requests a GPIO samples callback +
gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended +
Custom +
gpioCustom1 User custom function 1 +
gpioCustom2 User custom function 2 +
Events +
eventMonitor Sets the events to monitor +
eventSetFunc Request an event callback +
eventSetFuncEx Request an event callback, extended +
eventTrigger Trigger an event +
Scripts +
gpioStoreScript Store a script +
gpioRunScript Run a stored script +
gpioUpdateScript Set a scripts parameters +
gpioScriptStatus Get script status and parameters +
gpioStopScript Stop a running script +
gpioDeleteScript Delete a stored script +
I2C +
i2cOpen Opens an I2C device +
i2cClose Closes an I2C device +
i2cWriteQuick SMBus write quick +
i2cReadByte SMBus read byte +
i2cWriteByte SMBus write byte +
i2cReadByteData SMBus read byte data +
i2cWriteByteData SMBus write byte data +
i2cReadWordData SMBus read word data +
i2cWriteWordData SMBus write word data +
i2cReadBlockData SMBus read block data +
i2cWriteBlockData SMBus write block data +
i2cReadI2CBlockData SMBus read I2C block data +
i2cWriteI2CBlockData SMBus write I2C block data +
i2cReadDevice Reads the raw I2C device +
i2cWriteDevice Writes the raw I2C device +
i2cProcessCall SMBus process call +
i2cBlockProcessCall SMBus block process call +
i2cSwitchCombined Sets or clears the combined flag +
i2cSegments Performs multiple I2C transactions +
i2cZip Performs multiple I2C transactions +
I2C BIT BANG +
bbI2COpen Opens GPIO for bit banging I2C +
bbI2CClose Closes GPIO for bit banging I2C +
bbI2CZip Performs bit banged I2C transactions +
I2C/SPI SLAVE +
bscXfer I2C/SPI as slave transfer +
SERIAL +
serOpen Opens a serial device +
serClose Closes a serial device +
serReadByte Reads a byte from a serial device +
serWriteByte Writes a byte to a serial device +
serRead Reads bytes from a serial device +
serWrite Writes bytes to a serial device +
serDataAvailable Returns number of bytes ready to be read +
SERIAL BIT BANG (read only) +
gpioSerialReadOpen Opens a GPIO for bit bang serial reads +
gpioSerialReadClose Closes a GPIO for bit bang serial reads +
gpioSerialReadInvert Configures normal/inverted for serial reads +
gpioSerialRead Reads bit bang serial data from a GPIO +
SPI +
spiOpen Opens a SPI device +
spiClose Closes a SPI device +
spiRead Reads bytes from a SPI device +
spiWrite Writes bytes to a SPI device +
spiXfer Transfers bytes with a SPI device +
SPI BIT BANG +
bbSPIOpen Opens GPIO for bit banging SPI +
bbSPIClose Closes GPIO for bit banging SPI +
bbSPIXfer Performs bit banged SPI transactions +
FILES +
fileOpen Opens a file +
fileClose Closes a file +
fileRead Reads bytes from a file +
fileWrite Writes bytes to a file +
fileSeek Seeks to a position within a file +
fileList List files which match a pattern +
WAVES +
gpioWaveClear Deletes all waveforms +
gpioWaveAddNew Starts a new waveform +
gpioWaveAddGeneric Adds a series of pulses to the waveform +
gpioWaveAddSerial Adds serial data to the waveform +
gpioWaveCreate Creates a waveform from added data +
gpioWaveCreatePad Creates a waveform of fixed size from added data +
gpioWaveDelete Deletes a waveform +
gpioWaveTxSend Transmits a waveform +
gpioWaveChain Transmits a chain of waveforms +
gpioWaveTxAt Returns the current transmitting waveform +
gpioWaveTxBusy Checks to see if the waveform has ended +
gpioWaveTxStop Aborts the current waveform +
gpioWaveGetCbs Length in CBs of the current waveform +
gpioWaveGetHighCbs Length of longest waveform so far +
gpioWaveGetMaxCbs Absolute maximum allowed CBs +
gpioWaveGetMicros Length in micros of the current waveform +
gpioWaveGetHighMicros Length of longest waveform so far +
gpioWaveGetMaxMicros Absolute maximum allowed micros +
gpioWaveGetPulses Length in pulses of the current waveform +
gpioWaveGetHighPulses Length of longest waveform so far +
gpioWaveGetMaxPulses Absolute maximum allowed pulses +
UTILITIES +
gpioDelay Delay for a number of microseconds +
gpioTick Get current tick (microseconds) +
gpioHardwareRevision Get hardware revision +
gpioVersion Get the pigpio version +
getBitInBytes Get the value of a bit +
putBitInBytes Set the value of a bit +
gpioTime Get current time +
gpioSleep Sleep for specified time +
time_sleep Sleeps for a float number of seconds +
time_time Float number of seconds since the epoch +
CONFIGURATION +
gpioCfgBufferSize Configure the GPIO sample buffer size +
gpioCfgClock Configure the GPIO sample rate +
gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) +
gpioCfgDMAchannels Configure the DMA channels +
gpioCfgPermissions Configure the GPIO access permissions +
gpioCfgInterfaces Configure user interfaces +
gpioCfgSocketPort Configure socket port +
gpioCfgMemAlloc Configure DMA memory allocation mode +
gpioCfgNetAddr Configure allowed network addresses +
gpioCfgInternals Configure misc. internals (DEPRECATED) +
gpioCfgGetInternals Get internal configuration settings +
gpioCfgSetInternals Set internal configuration settings +
EXPERT +
rawWaveAddSPI Not intended for general use +
rawWaveAddGeneric Not intended for general use +
rawWaveCB Not intended for general use +
rawWaveCBAdr Not intended for general use +
rawWaveGetOOL Not intended for general use +
rawWaveSetOOL Not intended for general use +
rawWaveGetOut Not intended for general use +
rawWaveSetOut Not intended for general use +
rawWaveGetIn Not intended for general use +
rawWaveSetIn Not intended for general use +
rawWaveInfo Not intended for general use +
rawDumpWave Not intended for general use +
rawDumpScript Not intended for general use +

FUNCTIONS

int gpioInitialise(void)

+Initialises the library. +

Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. +

gpioInitialise must be called before using the other library functions +with the following exceptions: +

gpioCfg*
gpioVersion
gpioHardwareRevision


Example

if (gpioInitialise() < 0)
{
   // pigpio initialisation failed.
}
else
{
   // pigpio initialised okay.
}

void gpioTerminate(void)

+Terminates the library. +

Returns nothing. +

Call before program exit. +

This function resets the used DMA channels, releases memory, and +terminates any running threads. +

Example

gpioTerminate();

int gpioSetMode(unsigned gpio, unsigned mode)

+Sets the GPIO mode, typically input or output. +

gpio: 0-53
mode: 0-7


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. +

Arduino style: pinMode. +

Example

gpioSetMode(17, PI_INPUT);  // Set GPIO17 as input.

gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output.

gpioSetMode(22,PI_ALT0);    // Set GPIO22 to alternative mode 0.


See http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf page 102 for an overview of the modes. +

int gpioGetMode(unsigned gpio)

+Gets the GPIO mode. +

gpio: 0-53


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. +

Example

if (gpioGetMode(17) != PI_ALT0)
{
   gpioSetMode(17, PI_ALT0);  // set GPIO17 to ALT0
}

int gpioSetPullUpDown(unsigned gpio, unsigned pud)

+Sets or clears resistor pull ups or downs on the GPIO. +

gpio: 0-53
 pud: 0-2


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. +

Example

gpioSetPullUpDown(17, PI_PUD_UP);   // Sets a pull-up.

gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.

gpioSetPullUpDown(23, PI_PUD_OFF);  // Clear any pull-ups/downs.

int gpioRead(unsigned gpio)

+Reads the GPIO level, on or off. +

gpio: 0-53


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. +

Arduino style: digitalRead. +

Example

printf("GPIO24 is level %d", gpioRead(24));

int gpioWrite(unsigned gpio, unsigned level)

+Sets the GPIO level, on or off. +

 gpio: 0-53
level: 0-1


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. +

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

Arduino style: digitalWrite +

Example

gpioWrite(24, 1); // Set GPIO24 high.

int gpioPWM(unsigned user_gpio, unsigned dutycycle)

+Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). +Range defaults to 255. +

user_gpio: 0-31
dutycycle: 0-range


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. +

Arduino style: analogWrite +

This and the servo functionality use the DMA and PWM or PCM peripherals +to control and schedule the pulse lengths and dutycycles. +

The gpioSetPWMrange function may be used to change the default +range of 255. +

Example

gpioPWM(17, 255); // Sets GPIO17 full on.

gpioPWM(18, 128); // Sets GPIO18 half on.

gpioPWM(23, 0);   // Sets GPIO23 full off.

int gpioGetPWMdutycycle(unsigned user_gpio)

+Returns the PWM dutycycle setting for the GPIO. +

user_gpio: 0-31


Returns between 0 (off) and range (fully on) if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. +

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

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

Normal PWM range defaults to 255. +

int gpioSetPWMrange(unsigned user_gpio, unsigned range)

+Selects the dutycycle range to be used for the GPIO. Subsequent calls +to gpioPWM will use a dutycycle between 0 (off) and range (fully on). +

user_gpio: 0-31
    range: 25-40000


Returns the real range for the given GPIO's frequency if OK, +otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. +

If PWM is currently active on the GPIO its dutycycle will be scaled +to reflect the new range. +

The real range, the number of steps between fully off and fully +on for each frequency, is given in the following table. +

  25,   50,  100,  125,  200,  250,  400,   500,   625,
 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000


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

Example

gpioSetPWMrange(24, 2000); // Now 2000 is fully on
                           //     1000 is half on
                           //      500 is quarter on, etc.

int gpioGetPWMrange(unsigned user_gpio)

+Returns the dutycycle range used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. +

user_gpio: 0-31


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

Example

r = gpioGetPWMrange(23);

int gpioGetPWMrealRange(unsigned user_gpio)

+Returns the real range used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. +

user_gpio: 0-31


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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

Example

rr = gpioGetPWMrealRange(17);

int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)

+Sets the frequency in hertz to be used for the GPIO. +

user_gpio: 0-31
frequency: >=0


Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO. +

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 frequencies for each sample rate are: +

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency.

gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz.

gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency.

int gpioGetPWMfrequency(unsigned user_gpio)

+Returns the frequency (in hertz) used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. +

user_gpio: 0-31


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

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

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

Example

f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23.

int gpioServo(unsigned user_gpio, unsigned pulsewidth)

+Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to +2500 (most clockwise). +

 user_gpio: 0-31
pulsewidth: 0, 500-2500


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. +

The range supported by servos varies and should probably be determined +by experiment. A value of 1500 should always be safe and represents +the mid-point of rotation. You can DAMAGE a servo if you command it +to move beyond its limits. +

The following 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

gpioServo(17, 1000); // Move servo to safe position anti-clockwise.

gpioServo(23, 1500); // Move servo to centre position.

gpioServo(25, 2000); // Move servo to safe position clockwise.


OTHER UPDATE RATES: +

This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. +

PWM Hz    50   100  200  400  500
1E6/Hz 20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using gpioSetPWMfrequency. +

Then set the PWM range using gpioSetPWMrange to 1E6/frequency. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. +

E.g. If you want to update a servo connected to GPIO25 at 400Hz +

gpioSetPWMfrequency(25, 400);

gpioSetPWMrange(25, 2500);


Thereafter use the PWM command to move the servo, +e.g. gpioPWM(25, 1500) will set a 1500 us pulse. +

int gpioGetServoPulsewidth(unsigned user_gpio)

+Returns the servo pulsewidth setting for the GPIO. +

user_gpio: 0-31


Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) +if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. +

int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)

+Registers a function to be called (a callback) when the specified +GPIO changes state. +

user_gpio: 0-31
        f: the callback function


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. +

One callback may be registered per GPIO. +

The callback is passed the GPIO, the new level, and the tick. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The alert may be cancelled by passing NULL as the function. +

The GPIO are sampled at a rate set when the library is started. +

If a value isn't specifically set the default of 5 us is used. +

The number of samples per second is given in the following table. +

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


Level changes shorter than the sample rate may be missed. +

The thread which calls the alert functions is triggered nominally +1000 times per second. The active alert functions will be called +once per level change since the last time the thread was activated. +i.e. The active alert functions will get all level changes but there +will be a latency. +

If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use gpioRead. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. +

The tick value is the time stamp of the sample in microseconds, see +gpioTick for more details. +

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state

gpioSetAlertFunc(4, aFunction);

int gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) when the specified +GPIO changes state. +

user_gpio: 0-31
        f: the callback function
 userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. +

One callback may be registered per GPIO. +

The callback is passed the GPIO, the new level, the tick, and +the userdata pointer. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


See gpioSetAlertFunc for further details. +

Only one of gpioSetAlertFunc or gpioSetAlertFuncEx can be +registered per GPIO. +

int gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)

+Registers a function to be called (a callback) whenever the specified +GPIO interrupt occurs. +

   gpio: 0-53
   edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
timeout: interrupt timeout in milliseconds (<=0 to cancel)
      f: the callback function


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, +or PI_BAD_ISR_INIT. +

One function may be registered per GPIO. +

The function is passed the GPIO, the current level, and the +current tick. The level will be PI_TIMEOUT if the optional +interrupt timeout expires. +

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The underlying Linux sysfs GPIO interface is used to provide +the interrupt services. +

The first time the function is called, with a non-NULL f, the +GPIO is exported, set to be an input, and set to interrupt +on the given edge and timeout. +

Subsequent calls, with a non-NULL f, can vary one or more of the +edge, timeout, or function. +

The ISR may be cancelled by passing a NULL f, in which case the +GPIO is unexported. +

The tick is that read at the time the process was informed of +the interrupt. This will be a variable number of microseconds +after the interrupt occurred. Typically the latency will be of +the order of 50 microseconds. The latency is not guaranteed +and will vary with system load. +

The level is that read at the time the process was informed of +the interrupt, or PI_TIMEOUT if the optional interrupt timeout +expired. It may not be the same as the expected edge as +interrupts happening in rapid succession may be missed by the +kernel (i.e. this mechanism can not be used to capture several +interrupts only a few microseconds apart). +

int gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) whenever the specified +GPIO interrupt occurs. +

    gpio: 0-53
    edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 timeout: interrupt timeout in milliseconds (<=0 to cancel)
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, +or PI_BAD_ISR_INIT. +

The function is passed the GPIO, the current level, the +current tick, and the userdata pointer. +

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


Only one of gpioSetISRFunc or gpioSetISRFuncEx can be +registered per GPIO. +

See gpioSetISRFunc for further details. +

int gpioNotifyOpen(void)

+This function requests a free notification handle. +

Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. +

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

Pipe notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). E.g. if the +function returns 15 then the notifications must be read +from /dev/pigpio15. +

Socket notifications are returned to the socket which requested the +handle. +

Example

h = gpioNotifyOpen();

if (h >= 0)
{
   sprintf(str, "/dev/pigpio%d", h);

   fd = open(str, O_RDONLY);

   if (fd >= 0)
   {
      // Okay.
   }
   else
   {
      // Error.
   }
}
else
{
   // Error.
}

int gpioNotifyOpenWithSize(int bufSize)

+This function requests a free notification handle. +

It differs from gpioNotifyOpen in that the pipe size may be +specified, whereas gpioNotifyOpen uses the default pipe size. +

See gpioNotifyOpen for further details. +

int gpioNotifyBegin(unsigned handle, uint32_t bits)

+This function starts notifications on a previously opened handle. +

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the GPIO of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

The notification sends state changes for each GPIO whose corresponding +bit in bits is set. +

Each notification occupies 12 bytes in the fifo and has the +following structure. +

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, +PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. +

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. +

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. +

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags +indicate an event which has been triggered. +

tick: the number of microseconds since system boot. It wraps around +after 1h12m. +

level: indicates the level of each GPIO. If bit 1<<x is set then +GPIO x is high. +

Example

// Start notifications for GPIO 1, 4, 6, 7, 10.

//                         1
//                         0  76 4  1
// (1234 = 0x04D2 = 0b0000010011010010)

gpioNotifyBegin(h, 1234);

int gpioNotifyPause(unsigned handle)

+This function pauses notifications on a previously opened handle. +

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Notifications for the handle are suspended until gpioNotifyBegin +is called again. +

Example

gpioNotifyPause(h);

int gpioNotifyClose(unsigned handle)

+This function stops notifications on a previously opened handle +and releases the handle for reuse. +

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Example

gpioNotifyClose(h);

int gpioWaveClear(void)

+This function clears all waveforms and any data added by calls to the +gpioWaveAdd* functions. +

Returns 0 if OK. +

Example

gpioWaveClear();

int gpioWaveAddNew(void)

+This function starts a new empty waveform. +

You wouldn't normally need to call this function as it is automatically +called after a waveform is created with the gpioWaveCreate function. +

Returns 0 if OK. +

Example

gpioWaveAddNew();

int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)

+This function adds a number of pulses to the current waveform. +

numPulses: the number of pulses
   pulses: an array of pulses


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. +

The pulses are interleaved in time order within the existing waveform +(if any). +

Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist of a delay. +

Example

// Construct and send a 30 microsecond square wave.

gpioSetMode(gpio, PI_OUTPUT);

pulse[0].gpioOn = (1<<gpio);
pulse[0].gpioOff = 0;
pulse[0].usDelay = 15;

pulse[1].gpioOn = 0;
pulse[1].gpioOff = (1<<gpio);
pulse[1].usDelay = 15;

gpioWaveAddNew();

gpioWaveAddGeneric(2, pulse);

wave_id = gpioWaveCreate();

if (wave_id >= 0)
{
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);

   // Transmit for 30 seconds.

   sleep(30);

   gpioWaveTxStop();
}
else
{
   // Wave create failed.
}

int gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

+This function adds a waveform representing serial data to the +existing waveform (if any). The serial data starts offset +microseconds from the start of the waveform. +

user_gpio: 0-31
     baud: 50-1000000
data_bits: 1-32
stop_bits: 2-8
   offset: >=0
 numBytes: >=1
      str: an array of chars (which may contain nulls)


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. +

NOTES: +

The serial data is formatted as one start bit, data_bits data bits, and +stop_bits/2 stop bits. +

It is legal to add serial data streams with different baud rates to +the same waveform. +

numBytes is the number of bytes of data in str. +

The bytes required for each character depend upon data_bits. +

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

Example

#define MSG_LEN 8

int i;
char *str;
char data[MSG_LEN];

str = "Hello world!";

gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str);

for (i=0; i<MSG_LEN; i++) data[i] = i;

// Data added is offset 1 second from the waveform start.
gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);

int gpioWaveCreate(void)

+This function creates a waveform from the data provided by the prior +calls to the gpioWaveAdd* functions. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

The data provided by the gpioWaveAdd* functions is consumed by this +function. +

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

Normal usage would be +

Step 1. gpioWaveClear to clear all waveforms and added data. +

Step 2. gpioWaveAdd* calls to supply the waveform data. +

Step 3. gpioWaveCreate to create the waveform and get a unique id +

Repeat steps 2 and 3 as needed. +

Step 4. gpioWaveTxSend with the id of the waveform to transmit. +

A waveform comprises one of more pulses. Each pulse consists of a +gpioPulse_t structure. +

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify +

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +

int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL)

+Similar to gpioWaveCreate, this function creates a waveform but pads the consumed +resources. Padded waves of equal dimension can be re-cycled efficiently allowing +newly created waves to re-use the resources of deleted waves of the same dimension. +

pctCB: 0-100, the percent of all DMA control blocks to consume.
pctBOOL: 0-100, percent On-Off-Level (OOL) buffer to consume for wave output.
pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags).


Upon success a wave id greater than or equal to 0 is returned, otherwise +PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

Waveform data provided by gpioWaveAdd* and rawWaveAdd* functions are +consumed by this function. +

A usage would be the creation of two waves where one is filled while the other +is being transmitted. Each wave is assigned 50% of the resources. +This buffer structure allows the transmission of infinite wave sequences. +

Example

  // get firstWaveChunk, somehow
  gpioWaveAddGeneric(firstWaveChunk);
  wid = gpioWaveCreatePad(50, 50, 0);
  gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
  // get nextWaveChunk

  while (nextWaveChunk) {
     gpioWaveAddGeneric(nextWaveChunk);
     nextWid = gpioWaveCreatePad(50, 50, 0);
     gpioWaveTxSend(nextWid, PI_WAVE_MODE_ONE_SHOT_SYNC);
     while(gpioWaveTxAt() == wid) time_sleep(0.1);
     gpioWaveDelete(wid);
     wid = nextWid;
     // get nextWaveChunk
  }

int gpioWaveDelete(unsigned wave_id)

+This function deletes the waveform with id wave_id. +

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

wave_id: >=0, as returned by gpioWaveCreate


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

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. +

int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)

+This function transmits the waveform with id wave_id. The mode +determines whether the waveform is sent once or cycles endlessly. +The SYNC variants wait for the current waveform to reach the +end of a cycle or finish before starting the new waveform. +

WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. +

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. +

  wave_id: >=0, as returned by gpioWaveCreate
wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
           PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int gpioWaveChain(char *buf, unsigned bufSize)

+This function transmits a chain of waveforms. +

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. +

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

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. +

Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. +

A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. +

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpio.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (gpioInitialise()<0) return -1;

   gpioSetMode(GPIO, PI_OUTPUT);

   printf("start piscope, press return"); getchar();

   for (i=0; i<WAVES; i++)
   {
      gpioWaveAddGeneric(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = gpioWaveCreate();
   }

   gpioWaveChain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (gpioWaveTxBusy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);

   printf("stop piscope, press return"); getchar();

   gpioTerminate();
}

int gpioWaveTxAt(void)

+This function returns the id of the waveform currently being +transmitted. +

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

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
+PI_NO_TX_WAVE (9999) - no wave being transmitted. +

int gpioWaveTxBusy(void)

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

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

int gpioWaveTxStop(void)

+This function aborts the transmission of the current waveform. +

Returns 0 if OK. +

This function is intended to stop a waveform started in repeat mode. +

int gpioWaveGetMicros(void)

+This function returns the length in microseconds of the current +waveform. +

int gpioWaveGetHighMicros(void)

+This function returns the length in microseconds of the longest waveform +created since gpioInitialise was called. +

int gpioWaveGetMaxMicros(void)

+This function returns the maximum possible size of a waveform in +microseconds. +

int gpioWaveGetPulses(void)

+This function returns the length in pulses of the current waveform. +

int gpioWaveGetHighPulses(void)

+This function returns the length in pulses of the longest waveform +created since gpioInitialise was called. +

int gpioWaveGetMaxPulses(void)

+This function returns the maximum possible size of a waveform in pulses. +

int gpioWaveGetCbs(void)

+This function returns the length in DMA control blocks of the current +waveform. +

int gpioWaveGetHighCbs(void)

+This function returns the length in DMA control blocks of the longest +waveform created since gpioInitialise was called. +

int gpioWaveGetMaxCbs(void)

+This function returns the maximum possible size of a waveform in DMA +control blocks. +

int gpioSerialReadOpen(unsigned user_gpio, unsigned baud, unsigned data_bits)

+This function opens a GPIO for bit bang reading of serial data. +

user_gpio: 0-31
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, +PI_BAD_DATABITS, or PI_GPIO_IN_USE. +

The serial data is returned in a cyclic buffer and is read using +gpioSerialRead. +

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

int gpioSerialReadInvert(unsigned user_gpio, unsigned invert)

+This function configures the level logic for bit bang serial reads. +

Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for +normal logic. Default is PI_BB_SER_NORMAL. +

user_gpio: 0-31
   invert: 0-1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, +PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT. +

The GPIO must be opened for bit bang reading of serial data using +gpioSerialReadOpen prior to calling this function. +

int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize)

+This function copies up to bufSize bytes of data read from the +bit bang serial cyclic buffer to the buffer starting at buf. +

user_gpio: 0-31, previously opened with gpioSerialReadOpen
      buf: an array to receive the read bytes
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. +

The bytes returned for each character depend upon the number of +data bits data_bits specified in the gpioSerialReadOpen command. +

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

int gpioSerialReadClose(unsigned user_gpio)

+This function closes a GPIO for bit bang reading of serial data. +

user_gpio: 0-31, previously opened with gpioSerialReadOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. +

int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)

+This returns a handle for the device at the address on the I2C bus. +

  i2cBus: >=0
 i2cAddr: 0-0x7F
i2cFlags: 0


No flags are currently defined. This parameter should be set to zero. +

Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. +

For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. +

S      (1 bit) : Start bit
P      (1 bit) : Stop bit
Rd/Wr  (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA  (1 bit) : Accept and not accept bit.

Addr   (7 bits): I2C 7 bit address.
i2cReg (8 bits): Command byte, a byte which often selects a register.
Data   (8 bits): A data byte.
Count  (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2cClose(unsigned handle)

+This closes the I2C device associated with the handle. +

handle: >=0, as returned by a call to i2cOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int i2cWriteQuick(unsigned handle, unsigned bit)

+This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. +

handle: >=0, as returned by a call to i2cOpen
   bit: 0-1, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Quick command. SMBus 2.0 5.5.1 +S Addr bit [A] P

int i2cWriteByte(unsigned handle, unsigned bVal)

+This sends a single byte to the device associated with handle. +

handle: >=0, as returned by a call to i2cOpen
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Send byte. SMBus 2.0 5.5.2 +S Addr Wr [A] bVal [A] P

int i2cReadByte(unsigned handle)

+This reads a single byte from the device associated with handle. +

handle: >=0, as returned by a call to i2cOpen


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. +

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

int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)

+This writes a single byte to the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write byte. SMBus 2.0 5.5.4 +S Addr Wr [A] i2cReg [A] bVal [A] P

int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)

+This writes a single 16 bit word to the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  wVal: 0-0xFFFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write word. SMBus 2.0 5.5.4 +S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P

int i2cReadByteData(unsigned handle, unsigned i2cReg)

+This reads a single byte from the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read byte. SMBus 2.0 5.5.5 +S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P

int i2cReadWordData(unsigned handle, unsigned i2cReg)

+This reads a single 16 bit word from the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read word. SMBus 2.0 5.5.5 +S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)

+This writes 16 bits of data to the specified register of the device +associated with handle and reads 16 bits of data in return. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
  wVal: 0-0xFFFF, the value to write


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Process call. SMBus 2.0 5.5.6 +S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

+This writes up to 32 bytes to the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: an array with the data to send
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Block write. SMBus 2.0 5.5.7 +S Addr Wr [A] i2cReg [A] count [A]
   buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)

+This reads a block of up to 32 bytes from the specified register of +the device associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data


The amount of returned data is set by the device. +

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Block read. SMBus 2.0 5.5.7 +S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

+This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
   buf: an array with the data to send and to receive the read data
 count: 1-32, the number of bytes to write


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

The SMBus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. +

Block write-block read. SMBus 2.0 5.5.8 +S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A]
   S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P

int i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

+This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data
 count: 1-32, the number of bytes to read


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

+This writes 1 to 32 bytes to the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: the data to write
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadDevice(unsigned handle, char *buf, unsigned count)

+This reads count bytes from the raw device into buf. +

handle: >=0, as returned by a call to i2cOpen
   buf: an array to receive the read data bytes
 count: >0, the number of bytes to read


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. +

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteDevice(unsigned handle, char *buf, unsigned count)

+This writes count bytes from buf to the raw device. +

handle: >=0, as returned by a call to i2cOpen
   buf: an array containing the data bytes to write
 count: >0, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

void i2cSwitchCombined(int setting)

+This sets the I2C (i2c-bcm2708) module "use combined transactions" +parameter on or off. +

setting: 0 to set the parameter off, non-zero to set it on


NOTE: when the flag is on a write followed by a read to the same +slave address will use a repeated start (rather than a stop/start). +

int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)

+This function executes multiple I2C segments in one transaction by +calling the I2C_RDWR ioctl. +

 handle: >=0, as returned by a call to i2cOpen
   segs: an array of I2C segments
numSegs: >0, the number of I2C segments


Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. +

int i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)

+This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. +

Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. +

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

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. +

NOTE: +

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. +

int bbI2CClose(unsigned SDA)

+This function stops bit banging I2C on a pair of GPIO previously +opened with bbI2COpen. +

SDA: 0-31, the SDA GPIO used in a prior call to bbI2COpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +

int bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

   SDA: 0-31 (as used in a prior call to bbI2COpen)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bscXfer(bsc_xfer_t *bsc_xfer)

+This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. +

This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. +

This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. +

The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. +

I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. +

The function sets the BSC mode, writes any data in +the transmit buffer to the BSC transmit FIFO, and +copies any data in the BSC receive FIFO to the +receive buffer. +

bsc_xfer:= a structure defining the transfer

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. +

Upon return rxCnt will be set to the number of received bytes placed +in rxBuf. +

Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. +

GPIO used for models other than those based on the BCM2711. +

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset +to INPUT mode. +

The returned function value is the status of the transfer (see below). +

If there was an error the status will be less than zero +(and will contain the error code). +

The most significant word of the returned status contains the number +of bytes actually copied from txBuf to the BSC transmit FIFO (may be +less than requested if the FIFO already contained untransmitted data). +

control consists of the following bits. +

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. +

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. +

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as +an I2C slave with address 0x13 and send four bytes. +

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bscXfer(&xfer);

if (status >= 0)
{
   // process transfer
}

int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)

+This function selects a set of GPIO for bit banging SPI with +a specified baud rate and mode. +

      CS: 0-31
    MISO: 0-31
    MOSI: 0-31
    SCLK: 0-31
    baud: 50-250000
spiFlags: see below


spiFlags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 +

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. +

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or +PI_GPIO_IN_USE. +

If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. +

Example

bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bbSPIClose(unsigned CS)

+This function stops bit banging SPI on a set of GPIO +opened with bbSPIOpen. +

CS: 0-31, the CS GPIO used in a prior call to bbSPIOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. +

int bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)

+This function executes a bit banged SPI transfer. +

    CS: 0-31 (as used in a prior call to bbSPIOpen)
 inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
 count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. +

Example

// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
// sudo ./bbSPIx_test

#include <stdio.h>

#include "pigpio.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if (gpioInitialise() < 0)
   {
      fprintf(stderr, "pigpio initialisation failed.\n");
      return 1;
   }

   bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bbSPIClose(CE0);
   bbSPIClose(CE1);

   gpioTerminate();

   return 0;
}

int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)

+This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


 spiChan: 0-1 (0-2 for the auxiliary SPI)
    baud: 32K-125M (values above 30M are unlikely to work)
spiFlags: see below


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. +

spiFlags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 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. +

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 spiRead, spiWrite, and spiXfer functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. +

For bits 1-8 there will be one byte per word.
+For bits 9-16 there will be two bytes per word.
+For bits 17-32 there will be four bytes per word. +

Multi-byte transfers are made in least significant byte first order. +

E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. +

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

int spiClose(unsigned handle)

+This functions closes the SPI device identified by the handle. +

handle: >=0, as returned by a call to spiOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int spiRead(unsigned handle, char *buf, unsigned count)

+This function reads count bytes of data from the SPI +device associated with the handle. +

handle: >=0, as returned by a call to spiOpen
   buf: an array to receive the read data bytes
 count: the number of bytes to read


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spiWrite(unsigned handle, char *buf, unsigned count)

+This function writes count bytes of data from buf to the SPI +device associated with the handle. +

handle: >=0, as returned by a call to spiOpen
   buf: the data bytes to write
 count: the number of bytes to write


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

+This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. +

handle: >=0, as returned by a call to spiOpen
 txBuf: the data bytes to write
 rxBuf: the received data bytes
 count: the number of bytes to transfer


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int serOpen(char *sertty, unsigned baud, unsigned serFlags)

+This function opens a serial device at a specified baud rate +and with specified flags. The device name must start with +/dev/tty or /dev/serial. +

  sertty: the serial device to open
    baud: the baud rate in bits per second, see below
serFlags: 0


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. +

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

No flags are currently defined. This parameter should be set to zero. +

int serClose(unsigned handle)

+This function closes the serial device associated with handle. +

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int serWriteByte(unsigned handle, unsigned bVal)

+This function writes bVal to the serial port associated with handle. +

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serReadByte(unsigned handle)

+This function reads a byte from the serial port associated with handle. +

handle: >=0, as returned by a call to serOpen


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. +

If no data is ready PI_SER_READ_NO_DATA is returned. +

int serWrite(unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the serial port +associated with handle. +

handle: >=0, as returned by a call to serOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serRead(unsigned handle, char *buf, unsigned count)

+This function reads up count bytes from the the serial port +associated with handle and writes them to buf. +

handle: >=0, as returned by a call to serOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_SER_READ_NO_DATA. +

If no data is ready zero is returned. +

int serDataAvailable(unsigned handle)

+This function returns the number of bytes available +to be read from the device associated with handle. +

handle: >=0, as returned by a call to serOpen


Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. +

int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

+This function sends a trigger pulse to a GPIO. The GPIO is set to +level for pulseLen microseconds and then reset to not level. +

user_gpio: 0-31
 pulseLen: 1-100
    level: 0,1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, +or PI_BAD_PULSELEN. +

int gpioSetWatchdog(unsigned user_gpio, unsigned timeout)

+Sets a watchdog for a GPIO. +

user_gpio: 0-31
  timeout: 0-60000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. +

The watchdog is nominally in milliseconds. +

One watchdog may be registered per GPIO. +

The watchdog may be cancelled by setting timeout to 0. +

Until cancelled a timeout will be reported every timeout milliseconds +after the last GPIO activity. +

In particular: +

1) any registered alert function for the GPIO will be called with + the level set to PI_TIMEOUT. +

2) any notification for the GPIO will have a report written to the + fifo with the flags set to indicate a watchdog timeout. +

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state
gpioSetAlertFunc(4, aFunction);

//  or approximately every 5 millis
gpioSetWatchdog(4, 5);

int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)

+Sets a noise filter on a GPIO. +

Level changes on the GPIO are ignored until a level which has +been stable for steady microseconds is detected. Level changes +on the GPIO are then reported for active microseconds after +which the process repeats. +

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, +and gpioSetGetSamplesFuncEx. +

It does not affect interrupts set up with gpioSetISRFunc, +gpioSetISRFuncEx, or levels read by gpioRead, +gpioRead_Bits_0_31, or gpioRead_Bits_32_53. +

Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

int gpioGlitchFilter(unsigned user_gpio, unsigned steady)

+Sets a glitch filter on a GPIO. +

Level changes on the GPIO are not reported unless the level +has been stable for at least steady microseconds. The +level is then reported. Level changes of less than steady +microseconds are ignored. +

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, +and gpioSetGetSamplesFuncEx. +

It does not affect interrupts set up with gpioSetISRFunc, +gpioSetISRFuncEx, or levels read by gpioRead, +gpioRead_Bits_0_31, or gpioRead_Bits_32_53. +

Each (stable) edge will be timestamped steady microseconds +after it was first detected. +

int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)

+Registers a function to be called (a callback) every millisecond +with the latest GPIO samples. +

   f: the function to call
bits: the GPIO of interest


Returns 0 if OK. +

The function is passed a pointer to the samples (an array of +gpioSample_t), and the number of samples. +

Only one function can be registered. +

The callback may be cancelled by passing NULL as the function. +

The samples returned will be the union of bits, plus any active alerts, +plus any active notifications. +

e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO +8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO +7, 8, 9, 10, 17, 23, and 24 will be reported. +

int gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)

+Registers a function to be called (a callback) every millisecond +with the latest GPIO samples. +

       f: the function to call
    bits: the GPIO of interest
userdata: a pointer to arbitrary user data


Returns 0 if OK. +

The function is passed a pointer to the samples (an array of +gpioSample_t), the number of samples, and the userdata pointer. +

Only one of gpioGetSamplesFunc or gpioGetSamplesFuncEx can be +registered. +

See gpioSetGetSamplesFunc for further details. +

int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)

+Registers a function to be called (a callback) every millis milliseconds. +

 timer: 0-9
millis: 10-60000
     f: the function to call


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. +

10 timers are supported numbered 0 to 9. +

One function may be registered per timer. +

The timer may be cancelled by passing NULL as the function. +

Example

void bFunction(void)
{
   printf("two seconds have elapsed");
}

// call bFunction every 2000 milliseconds
gpioSetTimerFunc(0, 2000, bFunction);

int gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) every millis milliseconds. +

   timer: 0-9.
  millis: 10-60000
       f: the function to call
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. +

The function is passed the userdata pointer. +

Only one of gpioSetTimerFunc or gpioSetTimerFuncEx can be +registered per timer. +

See gpioSetTimerFunc for further details. +

pthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)

+Starts a new thread of execution with f as the main routine. +

       f: the main function for the new thread
userdata: a pointer to arbitrary user data


Returns a pointer to pthread_t if OK, otherwise NULL. +

The function is passed the single argument arg. +

The thread can be cancelled by passing the pointer to pthread_t to +gpioStopThread. +

Example

#include <stdio.h>
#include <pigpio.h>

void *myfunc(void *arg)
{
   while (1)
   {
      printf("%s", arg);
      sleep(1);
   }
}

int main(int argc, char *argv[])
{
   pthread_t *p1, *p2, *p3;

   if (gpioInitialise() < 0) return 1;

   p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);

   p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);

   p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);

   gpioStopThread(p3); sleep(3);

   gpioStopThread(p2); sleep(3);

   gpioStopThread(p1); sleep(3);

   gpioTerminate();
}

void gpioStopThread(pthread_t *pth)

+Cancels the thread pointed at by pth. +

pth: a thread pointer returned by gpioStartThread


No value is returned. +

The thread to be stopped should have been started with gpioStartThread. +

int gpioStoreScript(char *script)

+This function stores a null terminated script for later execution. +

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. +

script: the text of the script


The function returns a script id if the script is valid, +otherwise PI_BAD_SCRIPT. +

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

+This function runs a stored script. +

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

+This function runs a stored script. +

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)

+This function sets the parameters of a script. The script may or +may not be running. The first numPar parameters of the script are +overwritten with the new values. +

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int gpioScriptStatus(unsigned script_id, uint32_t *param)

+This function returns the run status of a stored script as well as +the current values of parameters 0 to 9. +

script_id: >=0, as returned by gpioStoreScript
    param: an array to hold the returned 10 parameters


The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. +

The run status may be +

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. +

int gpioStopScript(unsigned script_id)

+This function stops a running script. +

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int gpioDeleteScript(unsigned script_id)

+This function deletes a stored script. +

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)

+Registers a function to be called (a callback) when a signal occurs. +

signum: 0-63
     f: the callback function


Returns 0 if OK, otherwise PI_BAD_SIGNUM. +

The function is passed the signal number. +

One function may be registered per signal. +

The callback may be cancelled by passing NULL. +

By default all signals are treated as fatal and cause the library +to call gpioTerminate and then exit. +

int gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) when a signal occurs. +

  signum: 0-63
       f: the callback function
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_SIGNUM. +

The function is passed the signal number and the userdata pointer. +

Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be +registered per signal. +

See gpioSetSignalFunc for further details. +

uint32_t gpioRead_Bits_0_31(void)

+Returns the current level of GPIO 0-31. +

uint32_t gpioRead_Bits_32_53(void)

+Returns the current level of GPIO 32-53. +

int gpioWrite_Bits_0_31_Clear(uint32_t bits)

+Clears GPIO 0-31 if the corresponding bit in bits is set. +

bits: a bit mask of GPIO to clear


Returns 0 if OK. +

Example

// To clear (set to 0) GPIO 4, 7, and 15
gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );

int gpioWrite_Bits_32_53_Clear(uint32_t bits)

+Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

bits: a bit mask of GPIO to clear


Returns 0 if OK. +

int gpioWrite_Bits_0_31_Set(uint32_t bits)

+Sets GPIO 0-31 if the corresponding bit in bits is set. +

bits: a bit mask of GPIO to set


Returns 0 if OK. +

int gpioWrite_Bits_32_53_Set(uint32_t bits)

+Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

bits: a bit mask of GPIO to set


Returns 0 if OK. +

Example

// To set (set to 1) GPIO 32, 40, and 53
gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));

int gpioHardwareClock(unsigned gpio, unsigned clkfreq)

+Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. +

   gpio: see description
clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, +PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. +

The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. +

The GPIO must be one of the following. +

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely +crash the Pi. The password is given by or'ing 0x5A000000 with the +GPIO number. +

int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)

+Starts hardware PWM on a GPIO at the specified frequency and dutycycle. +Frequencies above 30MHz are unlikely to work. +

NOTE: Any waveform started by gpioWaveTxSend, or +gpioWaveChain will be cancelled. +

This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden by a call to +gpioCfgClock. +

   gpio: see description
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, +PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. +

The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. +

The GPIO must be one of the following. +

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). +

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

There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. PWMduty is +automatically scaled to take this into account. +

int gpioTime(unsigned timetype, int *seconds, int *micros)

+Updates the seconds and micros variables with the current time. +

timetype: 0 (relative), 1 (absolute)
 seconds: a pointer to an int to hold seconds
  micros: a pointer to an int to hold microseconds


Returns 0 if OK, otherwise PI_BAD_TIMETYPE. +

If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the +number of seconds and microseconds since the epoch (1st January 1970). +

If timetype is PI_TIME_RELATIVE updates seconds and micros with the +number of seconds and microseconds since the library was initialised. +

Example

int secs, mics;

// print the number of seconds since the library was started
gpioTime(PI_TIME_RELATIVE, &secs, &mics);
printf("library started %d.%03d seconds ago", secs, mics/1000);

int gpioSleep(unsigned timetype, int seconds, int micros)

+Sleeps for the number of seconds and microseconds specified by seconds +and micros. +

timetype: 0 (relative), 1 (absolute)
 seconds: seconds to sleep
  micros: microseconds to sleep


Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, +or PI_BAD_MICROS. +

If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds +and microseconds since the epoch (1st January 1970) has elapsed. System +clock changes are taken into account. +

If timetype is PI_TIME_RELATIVE the sleep is for the specified number +of seconds and microseconds. System clock changes do not effect the +sleep length. +

For short delays (say, 50 microseonds or less) use gpioDelay. +

Example

gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds

gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds

gpioSleep(PI_TIME_RELATIVE, 60, 0);     // sleep for one minute

uint32_t gpioDelay(uint32_t micros)

+Delays for at least the number of microseconds specified by micros. +

micros: the number of microseconds to sleep


Returns the actual length of the delay in microseconds. +

Delays of 100 microseconds or less use busy waits. +

uint32_t gpioTick(void)

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

You don't need to worry about the wrap around as long as you +take a tick (uint32_t) from another tick, i.e. the following +code will always provide the correct difference. +

Example

uint32_t startTick, endTick;
int diffTick;

startTick = gpioTick();

// do some processing

endTick = gpioTick();

diffTick = endTick - startTick;

printf("some processing took %d microseconds", diffTick);

unsigned gpioHardwareRevision(void)

+Returns the hardware revision. +

If the hardware revision can not be found or is not a valid hexadecimal +number the function returns 0. +

The hardware revision is the last few characters on the Revision line of +/proc/cpuinfo. +

The revision number can be used to determine the assignment of GPIO +to pins (see gpio). +

There are at least three types of board. +

Type 1 boards have hardware revision numbers of 2 and 3. +

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. +

Type 3 boards have hardware revision numbers of 16 or greater. +

for "Revision : 0002" the function returns 2.
+for "Revision : 000f" the function returns 15.
+for "Revision : 000g" the function returns 0. +

unsigned gpioVersion(void)

+Returns the pigpio version. +

int gpioGetPad(unsigned pad)

+This function returns the pad drive strength in mA. +

pad: 0-2, the pad to get


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. +

PadGPIO
00-27
128-45
246-53


Example

strength = gpioGetPad(1); // get pad 1 strength

int gpioSetPad(unsigned pad, unsigned padStrength)

+This function sets the pad drive strength in mA. +

        pad: 0-2, the pad to set
padStrength: 1-16 mA


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. +

PadGPIO
00-27
128-45
246-53


Example

gpioSetPad(0, 16); // set pad 0 strength to 16 mA

int eventMonitor(unsigned handle, uint32_t bits)

+This function selects the events to be reported on a previously +opened handle. +

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the events of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

A report is sent each time an event is triggered providing the +corresponding bit in bits is set. +

See gpioNotifyBegin for the notification format. +

Example

// Start reporting events 3, 6, and 7.

//  bit      76543210
// (0xC8 = 0b11001000)

eventMonitor(h, 0xC8);

int eventSetFunc(unsigned event, eventFunc_t f)

+Registers a function to be called (a callback) when the specified +event occurs. +

event: 0-31
    f: the callback function


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

One function may be registered per event. +

The function is passed the event, and the tick. +

The callback may be cancelled by passing NULL as the function. +

int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) when the specified +event occurs. +

   event: 0-31
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

One function may be registered per event. +

The function is passed the event, the tick, and the ueserdata pointer. +

The callback may be cancelled by passing NULL as the function. +

Only one of eventSetFunc or eventSetFuncEx can be +registered per event. +

int eventTrigger(unsigned event)

+This function signals the occurrence of an event. +

event: 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

An event is a signal used to inform one or more consumers +to start an action. Each consumer which has registered an interest +in the event (e.g. by calling eventSetFunc) will be informed by +a callback. +

One event, PI_EVENT_BSC (31) is predefined. This event is +auto generated on BSC slave activity. +

The meaning of other events is arbitrary. +

Note that other than its id and its tick there is no data associated +with an event. +

int shell(char *scriptName, char *scriptString)

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

  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name
scriptString: the string to pass to the script


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

scriptName must exist in /opt/pigpio/cgi and must be executable. +

The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. +

The following table gives some example returned statuses. +

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell("scr1", "\"hello string with spaces world\"");

int fileOpen(char *file, unsigned mode)

+This function returns a handle to a file opened in a specified mode. +

file: the file to open
mode: the file open mode


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. +

File +

A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. +

Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. +

Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. +

Suppose /opt/pigpio/access contains the following entries +

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception +of file.txt. +

Files may be read in directory dir_2. +

Files may be read and written in directory dir_3. +

If a directory allows read, write, or read/write access then files may +be created in that directory. +

In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. +

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode +

The mode may have the following values. +

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


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

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. +

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int handle, c;
   char buf[60000];

   if (gpioInitialise() < 0) return 1;

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

   handle = fileOpen("/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=fileRead(handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      fileClose(handle);
   }

   gpioTerminate();
}

int fileClose(unsigned handle)

+This function closes the file associated with handle. +

handle: >=0, as returned by a call to fileOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Example

fileClose(h);

int fileWrite(unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the file +associated with handle. +

handle: >=0, as returned by a call to fileOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. +

Example

status = fileWrite(h, buf, count);
if (status == 0)
{
   // okay
}
else
{
   // error
}

int fileRead(unsigned handle, char *buf, unsigned count)

+This function reads up to count bytes from the the file +associated with handle and writes them to buf. +

handle: >=0, as returned by a call to fileOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. +

Example

if (fileRead(h, buf, sizeof(buf)) > 0)
{
   // process read data
}

int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)

+This function seeks to a position within the file associated +with handle. +

    handle: >=0, as returned by a call to fileOpen
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2)


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. +

Example

fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20

size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size

pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position

int fileList(char *fpat, char *buf, unsigned count)

+This function returns a list of files which match a pattern. The +pattern may contain wildcards. +

 fpat: file pattern to match
  buf: an array to receive the matching file names
count: the maximum number of bytes to read


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. +

The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See fileOpen. +

NOTE +

The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. +

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int c;
   char buf[1000];

   if (gpioInitialise() < 0) return 1;

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

   c = fileList("/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      // terminate string
      buf[c] = 0;
      printf("%s", buf);
   }

   gpioTerminate();
}

int gpioCfgBufferSize(unsigned cfgMillis)

+Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. +

This function is only effective if called before gpioInitialise. +

cfgMillis: 100-10000


The default setting is 120 milliseconds. +

The intention is to allow for bursts of data and protection against +other processes hogging cpu time. +

I haven't seen a process locked out for more than 100 milliseconds. +

Making the buffer bigger uses a LOT of memory at the more frequent +sampling rates as shown in the following table in MBs. +

                     buffer milliseconds
               120 250 500 1sec 2sec 4sec 8sec

         1      16  31  55  107  ---  ---  ---
         2      10  18  31   55  107  ---  ---
sample   4       8  12  18   31   55  107  ---
 rate    5       8  10  14   24   45   87  ---
 (us)    8       6   8  12   18   31   55  107
        10       6   8  10   14   24   45   87

int gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)

+Configures pigpio to use a particular sample rate timed by a specified +peripheral. +

This function is only effective if called before gpioInitialise. +

    cfgMicros: 1, 2, 4, 5, 8, 10
cfgPeripheral: 0 (PWM), 1 (PCM)
    cfgSource: deprecated, value is ignored


The timings are provided by the specified peripheral (PWM or PCM). +

The default setting is 5 microseconds using the PCM peripheral. +

The approximate CPU percentage used for each sample rate is: +

sample  cpu
 rate    %

  1     25
  2     16
  4     11
  5     10
  8     15
 10     14


A sample rate of 5 microseconds seeems to be the sweet spot. +

int gpioCfgDMAchannel(unsigned DMAchannel)

+Configures pigpio to use the specified DMA channel. +

This function is only effective if called before gpioInitialise. +

DMAchannel: 0-14


The default setting is to use channel 14. +

int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)

+Configures pigpio to use the specified DMA channels. +

This function is only effective if called before gpioInitialise. +

  primaryChannel: 0-14
secondaryChannel: 0-14


The default setting depends on whether the Pi has a BCM2711 chip or +not (currently only the Pi4B has a BCM2711). +

The default setting for a non-BCM2711 is to use channel 14 for the +primary channel and channel 6 for the secondary channel. +

The default setting for a BCM2711 is to use channel 7 for the +primary channel and channel 6 for the secondary channel. +

The secondary channel is only used for the transmission of waves. +

If possible use one of channels 0 to 6 for the secondary channel +(a full channel). +

A full channel only requires one DMA control block regardless of the +length of a pulse delay. Channels 7 to 14 (lite channels) require +one DMA control block for each 16383 microseconds of delay. I.e. +a 10 second pulse delay requires one control block on a full channel +and 611 control blocks on a lite channel. +

int gpioCfgPermissions(uint64_t updateMask)

+Configures pigpio to restrict GPIO updates via the socket or pipe +interfaces to the GPIO specified by the mask. Programs directly +calling the pigpio library (i.e. linked with -lpigpio are not +affected). A GPIO update is a write to a GPIO or a GPIO mode +change or any function which would force such an action. +

This function is only effective if called before gpioInitialise. +

updateMask: bit (1<<n) is set for each GPIO n which may be updated


The default setting depends upon the Pi model. The user GPIO are +added to the mask. +

If the board revision is not recognised then GPIO 2-27 are allowed. +

Unknown boardPI_DEFAULT_UPDATE_MASK_UNKNOWN0x0FFFFFFC
Type 1 boardPI_DEFAULT_UPDATE_MASK_B10x03E6CF93
Type 2 boardPI_DEFAULT_UPDATE_MASK_A_B20xFBC6CF9C
Type 3 boardPI_DEFAULT_UPDATE_MASK_R30x0FFFFFFC

int gpioCfgSocketPort(unsigned port)

+Configures pigpio to use the specified socket port. +

This function is only effective if called before gpioInitialise. +

port: 1024-32000


The default setting is to use port 8888. +

int gpioCfgInterfaces(unsigned ifFlags)

+Configures pigpio support of the fifo and socket interfaces. +

This function is only effective if called before gpioInitialise. +

ifFlags: 0-7


The default setting (0) is that both interfaces are enabled. +

Or in PI_DISABLE_FIFO_IF to disable the pipe interface. +

Or in PI_DISABLE_SOCK_IF to disable the socket interface. +

Or in PI_LOCALHOST_SOCK_IF to disable remote socket +access (this means that the socket interface is only +usable from the local Pi). +

int gpioCfgMemAlloc(unsigned memAllocMode)

+Selects the method of DMA memory allocation. +

This function is only effective if called before gpioInitialise. +

memAllocMode: 0-2


There are two methods of DMA memory allocation. The original method +uses the /proc/self/pagemap file to allocate bus memory. The new +method uses the mailbox property interface to allocate bus memory. +

Auto will use the mailbox method unless a larger than default buffer +size is requested with gpioCfgBufferSize. +

int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)

+Sets the network addresses which are allowed to talk over the +socket interface. +

This function is only effective if called before gpioInitialise. +

numSockAddr: 0-256 (0 means all addresses allowed)
   sockAddr: an array of permitted network addresses.

int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)

+Used to tune internal settings. +

cfgWhat: see source code
 cfgVal: see source code

uint32_t gpioCfgGetInternals(void)

+This function returns the current library internal configuration +settings. +

int gpioCfgSetInternals(uint32_t cfgVal)

+This function sets the current library internal configuration +settings. +

cfgVal: see source code

int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

+This function is available for user customisation. +

It returns a single integer value. +

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. +

int gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

+This function is available for user customisation. +

It differs from gpioCustom1 in that it returns an array of bytes +rather than just an integer. +

The returned value is an integer indicating the number of returned bytes. +  arg1: >=0
  argx: extra (byte) arguments
  argc: number of extra arguments
retBuf: buffer for returned bytes
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. +

The number of returned bytes must be retMax or less. +

int rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)

+This function adds a waveform representing SPI data to the +existing waveform (if any). +

        spi: a pointer to a spi object
     offset: microseconds from the start of the waveform
      spiSS: the slave select GPIO
        buf: the bits to transmit, most significant bit first
  spiTxBits: the number of bits to write
spiBitFirst: the first bit to read
 spiBitLast: the last bit to read
    spiBits: the number of bits to transfer


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. +

Not intended for general use. +

int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)

+This function adds a number of pulses to the current waveform. +

numPulses: the number of pulses
   pulses: the array containing the pulses


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. +

The advantage of this function over gpioWaveAddGeneric is that it +allows the setting of the flags field. +

The pulses are interleaved in time order within the existing waveform +(if any). +

Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist of a delay. +

Not intended for general use. +

unsigned rawWaveCB(void)

+Returns the number of the cb being currently output. +

Not intended for general use. +

rawCbs_t *rawWaveCBAdr(int cbNum)

+Return the (Linux) address of contol block cbNum. +

cbNum: the cb of interest


Not intended for general use. +

uint32_t rawWaveGetOOL(int pos)

+Gets the OOL parameter stored at pos. +

pos: the position of interest.


Not intended for general use. +

void rawWaveSetOOL(int pos, uint32_t lVal)

+Sets the OOL parameter stored at pos to value. +

 pos: the position of interest
lVal: the value to write


Not intended for general use. +

uint32_t rawWaveGetOut(int pos)

+Gets the wave output parameter stored at pos. +

DEPRECATED: use rawWaveGetOOL instead. +

pos: the position of interest.


Not intended for general use. +

void rawWaveSetOut(int pos, uint32_t lVal)

+Sets the wave output parameter stored at pos to value. +

DEPRECATED: use rawWaveSetOOL instead. +

 pos: the position of interest
lVal: the value to write


Not intended for general use. +

uint32_t rawWaveGetIn(int pos)

+Gets the wave input value parameter stored at pos. +

DEPRECATED: use rawWaveGetOOL instead. +

pos: the position of interest


Not intended for general use. +

void rawWaveSetIn(int pos, uint32_t lVal)

+Sets the wave input value stored at pos to value. +

DEPRECATED: use rawWaveSetOOL instead. +

 pos: the position of interest
lVal: the value to write


Not intended for general use. +

rawWaveInfo_t rawWaveInfo(int wave_id)

+Gets details about the wave with id wave_id. +

wave_id: the wave of interest


Not intended for general use. +

int getBitInBytes(int bitPos, char *buf, int numBits)

+Returns the value of the bit bitPos bits from the start of buf. Returns +0 if bitPos is greater than or equal to numBits. +

 bitPos: bit index from the start of buf
    buf: array of bits
numBits: number of valid bits in buf

void putBitInBytes(int bitPos, char *buf, int bit)

+Sets the bit bitPos bits from the start of buf to bit. +

bitPos: bit index from the start of buf
   buf: array of bits
   bit: 0-1, value to set

double time_time(void)

+Return the current time in seconds since the Epoch. +

void time_sleep(double seconds)

+Delay execution for a given number of seconds +

seconds: the number of seconds to sleep

void rawDumpWave(void)

+Used to print a readable version of the current waveform to stderr. +

Not intended for general use. +

void rawDumpScript(unsigned script_id)

+Used to print a readable version of a script to stderr. +

script_id: >=0, a script_id returned by gpioStoreScript


Not intended for general use. +

PARAMETERS

active: 0-1000000

+The number of microseconds level changes are reported for once +a noise filter has been triggered (by steady microseconds of +a stable level). +

arg1

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

arg2

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

argc

+The count of bytes passed to a user customised function. +

*argx

+A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. +

baud

+The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. +

bit

+A value of 0 or 1. +

bitPos

+A bit position within a byte or word. The least significant bit is +position 0. +

bits

+A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. +

A convenient way to set bit n is to or in (1<<n). +

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). +

*bsc_xfer

+A pointer to a bsc_xfer_t object used to control a BSC transfer. +

bsc_xfer_t

+typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*buf

+A buffer to hold data being sent or being received. +

bufSize

+The size in bytes of a buffer. +

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

+An 8-bit byte value. +

cbNum

+A number identifying a DMA contol block. +

cfgMicros

+The GPIO sample rate in microseconds. The default is 5us, or 200 thousand +samples per second. +

cfgMillis: 100-10000

+The size of the sample buffer in milliseconds. Generally this should be +left at the default of 120ms. If you expect intense bursts of signals it +might be necessary to increase the buffer size. +

cfgPeripheral

+One of the PWM or PCM peripherals used to pace DMA transfers for timing +purposes. +

cfgSource

+Deprecated. +

cfgVal

+A number specifying the value of a configuration item. See cfgWhat. +

cfgWhat

+A number specifying a configuration item. +

562484977: print enhanced statistics at termination.
+984762879: set the initial debug level. +

char

+A single character, an 8 bit quantity able to store 0-255. +

clkfreq: 4689-250M (13184-375M for the BCM2711)

+The hardware clock frequency. +

PI_HW_CLK_MIN_FREQ 4689
PI_HW_CLK_MAX_FREQ 250000000
PI_HW_CLK_MAX_FREQ_2711 375000000

count

+The number of bytes to be transferred in an I2C, SPI, or Serial +command. +

CS

+The GPIO used for the slave select signal when bit banging SPI. +

data_bits: 1-32

+The number of data bits to be used when adding serial data to a +waveform. +

PI_MIN_WAVE_DATABITS 1
PI_MAX_WAVE_DATABITS 32

DMAchannel: 0-15

+PI_MIN_DMA_CHANNEL 0
PI_MAX_DMA_CHANNEL 15

double

+A floating point number. +

dutycycle: 0-range

+A number representing the ratio of on time to off time for PWM. +

The number may vary between 0 and range (default 255) where +0 is off and range is fully on. +

edge: 0-2

+The type of GPIO edge to generate an interrupt. See gpioSetISRFunc +and gpioSetISRFuncEx. +

RISING_EDGE 0
FALLING_EDGE 1
EITHER_EDGE 2

event: 0-31

+An event is a signal used to inform one or more consumers +to start an action. +

eventFunc_t

+typedef void (*eventFunc_t) (int event, uint32_t tick);

eventFuncEx_t

+typedef void (*eventFuncEx_t)
   (int event, uint32_t tick, void *userdata);

f

+A function. +

*file

+A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. +

*fpat

+A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. +

frequency: >=0

+The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. +

gpio

+A Broadcom numbered GPIO, in the range 0-53. +

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

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

gpioAlertFunc_t

+typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);

gpioAlertFuncEx_t

+typedef void (*eventFuncEx_t)
   (int event, int level, uint32_t tick, void *userdata);

gpioCfg*

+These functions are only effective if called before gpioInitialise. +

gpioCfgBufferSize
+gpioCfgClock
+gpioCfgDMAchannel
+gpioCfgDMAchannels
+gpioCfgPermissions
+gpioCfgInterfaces
+gpioCfgSocketPort
+gpioCfgMemAlloc +

gpioGetSamplesFunc_t

+typedef void (*gpioGetSamplesFunc_t)
   (const gpioSample_t *samples, int numSamples);

gpioGetSamplesFuncEx_t

+typedef void (*gpioGetSamplesFuncEx_t)
   (const gpioSample_t *samples, int numSamples, void *userdata);

gpioISRFunc_t

+typedef void (*gpioISRFunc_t)
   (int gpio, int level, uint32_t tick);

gpioISRFuncEx_t

+typedef void (*gpioISRFuncEx_t)
   (int gpio, int level, uint32_t tick, void *userdata);

gpioPulse_t

+typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioSample_t

+typedef struct
{
   uint32_t tick;
   uint32_t level;
} gpioSample_t;

gpioSignalFunc_t

+typedef void (*gpioSignalFunc_t) (int signum);

gpioSignalFuncEx_t

+typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);

gpioThreadFunc_t

+typedef void *(gpioThreadFunc_t) (void *);

gpioTimerFunc_t

+typedef void (*gpioTimerFunc_t) (void);

gpioTimerFuncEx_t

+typedef void (*gpioTimerFuncEx_t) (void *userdata);

gpioWaveAdd*

+One of +

gpioWaveAddNew
+gpioWaveAddGeneric
+gpioWaveAddSerial +

handle: >=0

+A number referencing an object opened by one of +

fileOpen
+gpioNotifyOpen
+i2cOpen
+serOpen
+spiOpen +

i2cAddr: 0-0x7F

+The address of a device on the I2C bus. +

i2cBus: >=0

+An I2C bus number. +

i2cFlags: 0

+Flags which modify an I2C open command. None are currently defined. +

i2cReg: 0-255

+A register of an I2C device. +

ifFlags: 0-3

+PI_DISABLE_FIFO_IF 1
PI_DISABLE_SOCK_IF 2

*inBuf

+A buffer used to pass data to a function. +

inLen

+The number of bytes of data in a buffer. +

int

+A whole number, negative or positive. +

int32_t

+A 32-bit signed value. +

invert

+A flag used to set normal or inverted bit bang serial data level logic. +

level

+The level of a GPIO. Low or High. +

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See gpioSetWatchdog. +

PI_TIMEOUT 2

lVal: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)

+A 32-bit word value. +

memAllocMode: 0-2

+The DMA memory allocation mode. +

PI_MEM_ALLOC_AUTO    0
PI_MEM_ALLOC_PAGEMAP 1
PI_MEM_ALLOC_MAILBOX 2

*micros

+A value representing microseconds. +

micros

+A value representing microseconds. +

millis

+A value representing milliseconds. +

MISO

+The GPIO used for the MISO signal when bit banging SPI. +

mode

+1. The operational mode of a GPIO, normally INPUT or OUTPUT. +

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. A file open mode. +

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


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

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

+The GPIO used for the MOSI signal when bit banging SPI. +

numBits

+The number of bits stored in a buffer. +

numBytes

+The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. +

numPar: 0-10

+The number of parameters passed to a script. +

numPulses

+The number of pulses to be added to a waveform. +

numSegs

+The number of segments in a combined I2C transaction. +

numSockAddr

+The number of network addresses allowed to use the socket interface. +

0 means all addresses allowed. +

offset

+The associated data starts this number of microseconds from the start of +the waveform. +

*outBuf

+A buffer used to return data from a function. +

outLen

+The size in bytes of an output buffer. +

pad: 0-2

+A set of GPIO which share common drivers. +

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

+The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. +

*param

+An array of script parameters. +

pi_i2c_msg_t

+typedef struct
{
   uint16_t addr;  // slave address
   uint16_t flags;
   uint16_t len;   // msg length
   uint8_t  *buf;  // pointer to msg data
} pi_i2c_msg_t;

port: 1024-32000

+The port used to bind to the pigpio socket. Defaults to 8888. +

pos

+The position of an item. +

primaryChannel: 0-15

+The DMA channel used to time the sampling of GPIO and to time servo and +PWM pulses. +

*pth

+A thread identifier, returned by gpioStartThread. +

pthread_t

+A thread identifier. +

pud: 0-2

+The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. +

PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

+1-100, the length of a trigger pulse in microseconds. +

*pulses

+An array of pulses to be added to a waveform. +

pulsewidth: 0, 500-2500

+PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

+The hardware PWM dutycycle. +

PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

+The hardware PWM frequency. +

PI_HW_PWM_MIN_FREQ 1
PI_HW_PWM_MAX_FREQ 125000000
PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

+PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

rawCbs_t

+typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
{
   unsigned long info;
   unsigned long src;
   unsigned long dst;
   unsigned long length;
   unsigned long stride;
   unsigned long next;
   unsigned long pad[2];
} rawCbs_t;

rawSPI_t

+typedef struct
{
   int clk;     // GPIO for clock
   int mosi;    // GPIO for MOSI
   int miso;    // GPIO for MISO
   int ss_pol;  // slave select off state
   int ss_us;   // delay after slave select
   int clk_pol; // clock off state
   int clk_pha; // clock phase
   int clk_us;  // clock micros
} rawSPI_t;

rawWave_t

+typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
   uint32_t flags;
} rawWave_t;

rawWaveInfo_t

+typedef struct
{
   uint16_t botCB;  // first CB used by wave
   uint16_t topCB;  // last CB used by wave
   uint16_t botOOL; // last OOL used by wave
   uint16_t topOOL; // first OOL used by wave
   uint16_t deleted;
   uint16_t numCB;
   uint16_t numBOOL;
   uint16_t numTOOL;
} rawWaveInfo_t;

*retBuf

+A buffer to hold a number of bytes returned to a used customised function, +

retMax

+The maximum number of bytes a user customised function should return. +

*rxBuf

+A pointer to a buffer to receive data. +

SCL

+The user GPIO to use for the clock when bit banging I2C. +

SCLK

+The GPIO used for the SCLK signal when bit banging SPI. +

*script

+A pointer to the text of a script. +

script_id

+An id of a stored script as returned by gpioStoreScript. +

*scriptName

+The name of a shell script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. +

*scriptString

+The string to be passed to a shell script to be executed. +

SDA

+The user GPIO to use for data when bit banging I2C. +

secondaryChannel: 0-6

+The DMA channel used to time output waveforms. +

*seconds

+A pointer to a uint32_t to store the second component of +a returned time. +

seconds

+The number of seconds. +

seekFrom

+PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

+The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). +

*segs

+An array of segments which make up a combined I2C transaction. +

serFlags

+Flags which modify a serial open command. None are currently defined. +

*sertty

+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. +

setting

+A value used to set a flag, 0 for false, non-zero for true. +

signum: 0-63

+PI_MIN_SIGNUM 0
PI_MAX_SIGNUM 63

size_t

+A standard type used to indicate the size of an object in bytes. +

*sockAddr

+An array of network addresses allowed to use the socket interface encoded +as 32 bit numbers. +

E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. +

*spi

+A pointer to a rawSPI_t structure. +

spiBitFirst

+GPIO reads are made from spiBitFirst to spiBitLast. +

spiBitLast

+GPIO reads are made from spiBitFirst to spiBitLast. +

spiBits

+The number of bits to transfer in a raw SPI transaction. +

spiChan

+A SPI channel, 0-2. +

spiFlags

+See spiOpen and bbSPIOpen. +

spiSS

+The SPI slave select GPIO in a raw SPI transaction. +

spiTxBits

+The number of bits to transfer dring a raw SPI transaction +

steady: 0-300000

+The number of microseconds level changes must be stable for +before reporting the level changed (gpioGlitchFilter) or triggering +the active part of a noise filter (gpioNoiseFilter). +

stop_bits: 2-8

+The number of (half) stop bits to be used when adding serial data +to a waveform. +

PI_MIN_WAVE_HALFSTOPBITS 2
PI_MAX_WAVE_HALFSTOPBITS 8

*str

+An array of characters. +

timeout

+A GPIO level change timeout in milliseconds. +

gpioSetWatchdog +PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000


gpioSetISRFunc and gpioSetISRFuncEx +<=0 cancel timeout
>0 timeout after specified milliseconds

timer

+PI_MIN_TIMER 0
PI_MAX_TIMER 9

timetype

+PI_TIME_RELATIVE 0
PI_TIME_ABSOLUTE 1

*txBuf

+An array of bytes to transmit. +

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

+A 32-bit unsigned value. +

uint64_t: 0-(2^64)-1

+A 64-bit unsigned value. +

unsigned

+A whole number >= 0. +

updateMask

+A 64 bit mask indicating which GPIO may be written to by the user. +

If GPIO#n may be written then bit (1<<n) is set. +

user_gpio

+0-31, a Broadcom numbered GPIO. +

See gpio. +

*userdata

+A pointer to arbitrary user data. This may be used to identify the instance. +

You must ensure that the pointer is in scope at the time it is processed. If +it is a pointer to a global this is automatic. Do not pass the address of a +local variable. If you want to pass a transient object then use the +following technique. +

In the calling function: +

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: +

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

+Denoting no parameter is required +

wave_id

+A number identifying a waveform created by gpioWaveCreate. +

wave_mode

+The mode determines if the waveform is sent once or cycles +repeatedly. The SYNC variants wait for the current waveform +to reach the end of a cycle or finish before starting the new +waveform. +

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

+A 16-bit word value. +

Socket Command Codes


#define PI_CMD_MODES  0
#define PI_CMD_MODEG  1
#define PI_CMD_PUD    2
#define PI_CMD_READ   3
#define PI_CMD_WRITE  4
#define PI_CMD_PWM    5
#define PI_CMD_PRS    6
#define PI_CMD_PFS    7
#define PI_CMD_SERVO  8
#define PI_CMD_WDOG   9
#define PI_CMD_BR1   10
#define PI_CMD_BR2   11
#define PI_CMD_BC1   12
#define PI_CMD_BC2   13
#define PI_CMD_BS1   14
#define PI_CMD_BS2   15
#define PI_CMD_TICK  16
#define PI_CMD_HWVER 17
#define PI_CMD_NO    18
#define PI_CMD_NB    19
#define PI_CMD_NP    20
#define PI_CMD_NC    21
#define PI_CMD_PRG   22
#define PI_CMD_PFG   23
#define PI_CMD_PRRG  24
#define PI_CMD_HELP  25
#define PI_CMD_PIGPV 26
#define PI_CMD_WVCLR 27
#define PI_CMD_WVAG  28
#define PI_CMD_WVAS  29
#define PI_CMD_WVGO  30
#define PI_CMD_WVGOR 31
#define PI_CMD_WVBSY 32
#define PI_CMD_WVHLT 33
#define PI_CMD_WVSM  34
#define PI_CMD_WVSP  35
#define PI_CMD_WVSC  36
#define PI_CMD_TRIG  37
#define PI_CMD_PROC  38
#define PI_CMD_PROCD 39
#define PI_CMD_PROCR 40
#define PI_CMD_PROCS 41
#define PI_CMD_SLRO  42
#define PI_CMD_SLR   43
#define PI_CMD_SLRC  44
#define PI_CMD_PROCP 45
#define PI_CMD_MICS  46
#define PI_CMD_MILS  47
#define PI_CMD_PARSE 48
#define PI_CMD_WVCRE 49
#define PI_CMD_WVDEL 50
#define PI_CMD_WVTX  51
#define PI_CMD_WVTXR 52
#define PI_CMD_WVNEW 53

#define PI_CMD_I2CO  54
#define PI_CMD_I2CC  55
#define PI_CMD_I2CRD 56
#define PI_CMD_I2CWD 57
#define PI_CMD_I2CWQ 58
#define PI_CMD_I2CRS 59
#define PI_CMD_I2CWS 60
#define PI_CMD_I2CRB 61
#define PI_CMD_I2CWB 62
#define PI_CMD_I2CRW 63
#define PI_CMD_I2CWW 64
#define PI_CMD_I2CRK 65
#define PI_CMD_I2CWK 66
#define PI_CMD_I2CRI 67
#define PI_CMD_I2CWI 68
#define PI_CMD_I2CPC 69
#define PI_CMD_I2CPK 70

#define PI_CMD_SPIO  71
#define PI_CMD_SPIC  72
#define PI_CMD_SPIR  73
#define PI_CMD_SPIW  74
#define PI_CMD_SPIX  75

#define PI_CMD_SERO  76
#define PI_CMD_SERC  77
#define PI_CMD_SERRB 78
#define PI_CMD_SERWB 79
#define PI_CMD_SERR  80
#define PI_CMD_SERW  81
#define PI_CMD_SERDA 82

#define PI_CMD_GDC   83
#define PI_CMD_GPW   84

#define PI_CMD_HC    85
#define PI_CMD_HP    86

#define PI_CMD_CF1   87
#define PI_CMD_CF2   88

#define PI_CMD_BI2CC 89
#define PI_CMD_BI2CO 90
#define PI_CMD_BI2CZ 91

#define PI_CMD_I2CZ  92

#define PI_CMD_WVCHA 93

#define PI_CMD_SLRI  94

#define PI_CMD_CGI   95
#define PI_CMD_CSI   96

#define PI_CMD_FG    97
#define PI_CMD_FN    98

#define PI_CMD_NOIB  99

#define PI_CMD_WVTXM 100
#define PI_CMD_WVTAT 101

#define PI_CMD_PADS  102
#define PI_CMD_PADG  103

#define PI_CMD_FO    104
#define PI_CMD_FC    105
#define PI_CMD_FR    106
#define PI_CMD_FW    107
#define PI_CMD_FS    108
#define PI_CMD_FL    109

#define PI_CMD_SHELL 110

#define PI_CMD_BSPIC 111
#define PI_CMD_BSPIO 112
#define PI_CMD_BSPIX 113

#define PI_CMD_BSCX  114

#define PI_CMD_EVM   115
#define PI_CMD_EVT   116

#define PI_CMD_PROCU 117
#define PI_CMD_WVCAP 118

Error Codes


#define PI_INIT_FAILED       -1 // gpioInitialise failed
#define PI_BAD_USER_GPIO     -2 // GPIO not 0-31
#define PI_BAD_GPIO          -3 // GPIO not 0-53
#define PI_BAD_MODE          -4 // mode not 0-7
#define PI_BAD_LEVEL         -5 // level not 0-1
#define PI_BAD_PUD           -6 // pud not 0-2
#define PI_BAD_PULSEWIDTH    -7 // pulsewidth not 0 or 500-2500
#define PI_BAD_DUTYCYCLE     -8 // dutycycle outside set range
#define PI_BAD_TIMER         -9 // timer not 0-9
#define PI_BAD_MS           -10 // ms not 10-60000
#define PI_BAD_TIMETYPE     -11 // timetype not 0-1
#define PI_BAD_SECONDS      -12 // seconds < 0
#define PI_BAD_MICROS       -13 // micros not 0-999999
#define PI_TIMER_FAILED     -14 // gpioSetTimerFunc failed
#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
#define PI_NO_ALERT_FUNC    -16 // DEPRECATED
#define PI_BAD_CLK_PERIPH   -17 // clock peripheral not 0-1
#define PI_BAD_CLK_SOURCE   -18 // DEPRECATED
#define PI_BAD_CLK_MICROS   -19 // clock micros not 1, 2, 4, 5, 8, or 10
#define PI_BAD_BUF_MILLIS   -20 // buf millis not 100-10000
#define PI_BAD_DUTYRANGE    -21 // dutycycle range not 25-40000
#define PI_BAD_DUTY_RANGE   -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
#define PI_BAD_SIGNUM       -22 // signum not 0-63
#define PI_BAD_PATHNAME     -23 // can't open pathname
#define PI_NO_HANDLE        -24 // no handle available
#define PI_BAD_HANDLE       -25 // unknown handle
#define PI_BAD_IF_FLAGS     -26 // ifFlags > 4
#define PI_BAD_CHANNEL      -27 // DMA channel not 0-15
#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15
#define PI_BAD_SOCKET_PORT  -28 // socket port not 1024-32000
#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15
#define PI_NOT_INITIALISED  -31 // function called before gpioInitialise
#define PI_INITIALISED      -32 // function called after gpioInitialise
#define PI_BAD_WAVE_MODE    -33 // waveform mode not 0-3
#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
#define PI_BAD_WAVE_BAUD    -35 // baud rate not 50-250K(RX)/50-1M(TX)
#define PI_TOO_MANY_PULSES  -36 // waveform has too many pulses
#define PI_TOO_MANY_CHARS   -37 // waveform has too many chars
#define PI_NOT_SERIAL_GPIO  -38 // no bit bang serial read on GPIO
#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
#define PI_BAD_SERIAL_BUF   -40 // bad (null) serial buf parameter
#define PI_NOT_PERMITTED    -41 // GPIO operation not permitted
#define PI_SOME_PERMITTED   -42 // one or more GPIO not permitted
#define PI_BAD_WVSC_COMMND  -43 // bad WVSC subcommand
#define PI_BAD_WVSM_COMMND  -44 // bad WVSM subcommand
#define PI_BAD_WVSP_COMMND  -45 // bad WVSP subcommand
#define PI_BAD_PULSELEN     -46 // trigger pulse length not 1-100
#define PI_BAD_SCRIPT       -47 // invalid script
#define PI_BAD_SCRIPT_ID    -48 // unknown script id
#define PI_BAD_SER_OFFSET   -49 // add serial data offset > 30 minutes
#define PI_GPIO_IN_USE      -50 // GPIO already in use
#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
#define PI_BAD_PARAM_NUM    -52 // script parameter id not 0-9
#define PI_DUP_TAG          -53 // script has duplicate tag
#define PI_TOO_MANY_TAGS    -54 // script has too many tags
#define PI_BAD_SCRIPT_CMD   -55 // illegal script command
#define PI_BAD_VAR_NUM      -56 // script variable id not 0-149
#define PI_NO_SCRIPT_ROOM   -57 // no more room for scripts
#define PI_NO_MEMORY        -58 // can't allocate temporary memory
#define PI_SOCK_READ_FAILED -59 // socket read failed
#define PI_SOCK_WRIT_FAILED -60 // socket write failed
#define PI_TOO_MANY_PARAM   -61 // too many script parameters (> 10)
#define PI_NOT_HALTED       -62 // DEPRECATED
#define PI_SCRIPT_NOT_READY -62 // script initialising
#define PI_BAD_TAG          -63 // script has unresolved tag
#define PI_BAD_MICS_DELAY   -64 // bad MICS delay (too large)
#define PI_BAD_MILS_DELAY   -65 // bad MILS delay (too large)
#define PI_BAD_WAVE_ID      -66 // non existent wave id
#define PI_TOO_MANY_CBS     -67 // No more CBs for waveform
#define PI_TOO_MANY_OOL     -68 // No more OOL for waveform
#define PI_EMPTY_WAVEFORM   -69 // attempt to create an empty waveform
#define PI_NO_WAVEFORM_ID   -70 // no more waveforms
#define PI_I2C_OPEN_FAILED  -71 // can't open I2C device
#define PI_SER_OPEN_FAILED  -72 // can't open serial device
#define PI_SPI_OPEN_FAILED  -73 // can't open SPI device
#define PI_BAD_I2C_BUS      -74 // bad I2C bus
#define PI_BAD_I2C_ADDR     -75 // bad I2C address
#define PI_BAD_SPI_CHANNEL  -76 // bad SPI channel
#define PI_BAD_FLAGS        -77 // bad i2c/spi/ser open flags
#define PI_BAD_SPI_SPEED    -78 // bad SPI speed
#define PI_BAD_SER_DEVICE   -79 // bad serial device name
#define PI_BAD_SER_SPEED    -80 // bad serial baud rate
#define PI_BAD_PARAM        -81 // bad i2c/spi/ser parameter
#define PI_I2C_WRITE_FAILED -82 // i2c write failed
#define PI_I2C_READ_FAILED  -83 // i2c read failed
#define PI_BAD_SPI_COUNT    -84 // bad SPI count
#define PI_SER_WRITE_FAILED -85 // ser write failed
#define PI_SER_READ_FAILED  -86 // ser read failed
#define PI_SER_READ_NO_DATA -87 // ser read no data available
#define PI_UNKNOWN_COMMAND  -88 // unknown command
#define PI_SPI_XFER_FAILED  -89 // spi xfer/read/write failed
#define PI_BAD_POINTER      -90 // bad (NULL) pointer
#define PI_NO_AUX_SPI       -91 // no auxiliary SPI on Pi A or B
#define PI_NOT_PWM_GPIO     -92 // GPIO is not in use for PWM
#define PI_NOT_SERVO_GPIO   -93 // GPIO is not in use for servo pulses
#define PI_NOT_HCLK_GPIO    -94 // GPIO has no hardware clock
#define PI_NOT_HPWM_GPIO    -95 // GPIO has no hardware PWM
#define PI_BAD_HPWM_FREQ    -96 // invalid hardware PWM frequency
#define PI_BAD_HPWM_DUTY    -97 // hardware PWM dutycycle not 0-1M
#define PI_BAD_HCLK_FREQ    -98 // invalid hardware clock frequency
#define PI_BAD_HCLK_PASS    -99 // need password to use hardware clock 1
#define PI_HPWM_ILLEGAL    -100 // illegal, PWM in use for main clock
#define PI_BAD_DATABITS    -101 // serial data bits not 1-32
#define PI_BAD_STOPBITS    -102 // serial (half) stop bits not 2-8
#define PI_MSG_TOOBIG      -103 // socket/pipe message too big
#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode
#define PI_TOO_MANY_SEGS   -105 // too many I2C transaction segments
#define PI_BAD_I2C_SEG     -106 // an I2C transaction segment failed
#define PI_BAD_SMBUS_CMD   -107 // SMBus command not supported by driver
#define PI_NOT_I2C_GPIO    -108 // no bit bang I2C in progress on GPIO
#define PI_BAD_I2C_WLEN    -109 // bad I2C write length
#define PI_BAD_I2C_RLEN    -110 // bad I2C read length
#define PI_BAD_I2C_CMD     -111 // bad I2C command
#define PI_BAD_I2C_BAUD    -112 // bad I2C baud rate, not 50-500k
#define PI_CHAIN_LOOP_CNT  -113 // bad chain loop count
#define PI_BAD_CHAIN_LOOP  -114 // empty chain loop
#define PI_CHAIN_COUNTER   -115 // too many chain counters
#define PI_BAD_CHAIN_CMD   -116 // bad chain command
#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
#define PI_CHAIN_NESTING   -118 // chain counters nested too deeply
#define PI_CHAIN_TOO_BIG   -119 // chain is too long
#define PI_DEPRECATED      -120 // deprecated function removed
#define PI_BAD_SER_INVERT  -121 // bit bang serial invert not 0 or 1
#define PI_BAD_EDGE        -122 // bad ISR edge value, not 0-2
#define PI_BAD_ISR_INIT    -123 // bad ISR initialisation
#define PI_BAD_FOREVER     -124 // loop forever must be last command
#define PI_BAD_FILTER      -125 // bad filter parameter
#define PI_BAD_PAD         -126 // bad pad number
#define PI_BAD_STRENGTH    -127 // bad pad drive strength
#define PI_FIL_OPEN_FAILED -128 // file open failed
#define PI_BAD_FILE_MODE   -129 // bad file mode
#define PI_BAD_FILE_FLAG   -130 // bad file flag
#define PI_BAD_FILE_READ   -131 // bad file read
#define PI_BAD_FILE_WRITE  -132 // bad file write
#define PI_FILE_NOT_ROPEN  -133 // file not open for read
#define PI_FILE_NOT_WOPEN  -134 // file not open for write
#define PI_BAD_FILE_SEEK   -135 // bad file seek
#define PI_NO_FILE_MATCH   -136 // no files match pattern
#define PI_NO_FILE_ACCESS  -137 // no permission to access file
#define PI_FILE_IS_A_DIR   -138 // file is a directory
#define PI_BAD_SHELL_STATUS -139 // bad shell return status
#define PI_BAD_SCRIPT_NAME -140 // bad script name
#define PI_BAD_SPI_BAUD    -141 // bad SPI baud rate, not 50-500k
#define PI_NOT_SPI_GPIO    -142 // no bit bang SPI in progress on GPIO
#define PI_BAD_EVENT_ID    -143 // bad event id
#define PI_CMD_INTERRUPTED -144 // Used by Python
#define PI_NOT_ON_BCM2711  -145 // not available on BCM2711
#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711

#define PI_PIGIF_ERR_0    -2000
#define PI_PIGIF_ERR_99   -2099

#define PI_CUSTOM_ERR_0   -3000
#define PI_CUSTOM_ERR_999 -3999

Defaults


#define PI_DEFAULT_BUFFER_MILLIS           120
#define PI_DEFAULT_CLK_MICROS              5
#define PI_DEFAULT_CLK_PERIPHERAL          PI_CLOCK_PCM
#define PI_DEFAULT_IF_FLAGS                0
#define PI_DEFAULT_FOREGROUND              0
#define PI_DEFAULT_DMA_CHANNEL             14
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL     14
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL   6
#define PI_DEFAULT_DMA_PRIMARY_CH_2711     7
#define PI_DEFAULT_DMA_SECONDARY_CH_2711   6
#define PI_DEFAULT_DMA_NOT_SET             15
#define PI_DEFAULT_SOCKET_PORT             8888
#define PI_DEFAULT_SOCKET_PORT_STR         "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR         "localhost"
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN     0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_B1          0x03E7CF93
#define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_ZERO        0x0080000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI2B        0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI3B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI4B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_COMPUTE     0x00FFFFFFFFFFFFLL
#define PI_DEFAULT_MEM_ALLOC_MODE          PI_MEM_ALLOC_AUTO

#define PI_DEFAULT_CFG_INTERNALS           0

+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/download.html b/DOC/HTML/download.html new file mode 100644 index 0000000..5da5c77 --- /dev/null +++ b/DOC/HTML/download.html @@ -0,0 +1,121 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Download & Install

+If the pigpio daemon is running it should be killed (sudo killall +pigpiod) before make install and restarted afterwards (sudo +pigpiod).
+
+The initial part of the make, the +compilation of pigpio.c, takes 100 seconds on early model +Pis.  Be patient.  The overall install takes just over 3 +minutes.
+

Download and install (V75)

+wget https://github.com/joan2937/pigpio/archive/v75.zip
+unzip v75.zip
+cd pigpio-75
+make
+sudo make install

+
+If the Python part of the install fails it may be because you need +the setup tools.
+
+sudo apt install python-setuptools +python3-setuptools

+
+

To check the library

+These tests make extensive use of GPIO 25 (pin 22).  Make sure +nothing, or only a LED, is connected to the GPIO before running the +tests.  Most tests are statistical in nature and so may on +occasion fail.  Repeated failures on the same test or many +failures in a group of tests indicate a problem.
+
+sudo ./x_pigpio # check C I/F
+
+sudo pigpiod    # start daemon
+
+./x_pigpiod_if2 # check C      I/F to +daemon
+./x_pigpio.py   # check Python I/F to daemon
+./x_pigs        # check +pigs   I/F to daemon
+./x_pipe        # check +pipe   I/F to daemon
+
+
+

To compile, link, and run a C program

+gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
+sudo ./foobar


+

To start the pigpio daemon

+sudo pigpiod
+

To stop the pigpio daemon

+sudo killall pigpiod

+

github

+git clone https://github.com/joan2937/pigpio
+

Raspbian (raspberrypi.org image)

+

This may not be the most recent version.  You can check the +version with the command pigpiod -v.

+sudo apt-get update
+sudo apt-get install pigpio python-pigpio python3-pigpio

+
+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/ex_LDR.html b/DOC/HTML/ex_LDR.html new file mode 100644 index 0000000..615d9b4 --- /dev/null +++ b/DOC/HTML/ex_LDR.html @@ -0,0 +1,205 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

LDR Example

+

The following code shows a method of reading analogue sensors on +the digital input only Pi.  A Light Dependent Resistor (LDR) +varies its resistance according to the incident light +intensisty.

+

SETUP

+fritzing diagramThe LDR +used is a Cadmium Sulphide device with a 1MOhm dark resistance and +2-4KOhm at 100 lux.  The capacitor is a 104 +ceramic.
+
+One end of the capacitor is connected to Pi ground.
+
+One end of the LDR is connected to Pi 3V3.
+
+The other ends of the capacitor and LDR are connected to a spare +gpio.

+

Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18 +(P1-12) is used for the gpio.

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/* +-----------------------------------------------------------------------
+ +
+   3V3 ----- Light Dependent Resistor --+-- Capacitor +----- Ground
+                                        +|
+                                        ++-- gpio
+
+
+  cc -o LDR LDR.c -lpigpio -lpthread -lrt
+  sudo ./LDR
+
+*/
+
+#define LDR 18
+
+/* forward declaration */
+
+void alert(int pin, int level, uint32_t tick);
+
+int main (int argc, char *argv[])
+{
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetAlertFunc(LDR, alert); /* call alert when LDR +changes state */
+    
+   while (1)
+   {
+      gpioSetMode(LDR, PI_OUTPUT); /* +drain capacitor */
+
+      gpioWrite(LDR, PI_OFF);
+
+      gpioDelay(200); /* 50 micros is +enough, 200 is overkill */
+
+      gpioSetMode(LDR, PI_INPUT); /* start +capacitor recharge */
+
+      gpioDelay(10000); /* nominal 100 +readings per second */
+   }
+
+   gpioTerminate();
+}
+
+void alert(int pin, int level, uint32_t tick)
+{
+   static uint32_t inited = 0;
+   static uint32_t lastTick, firstTick;
+
+   uint32_t diffTick;
+
+   if (inited)
+   {
+      diffTick = tick - lastTick;
+      lastTick = tick;
+
+      if (level == 1) printf("%u %d\ ", +tick-firstTick, diffTick);
+   }
+   else
+   {
+      inited = 1;
+      firstTick = tick;
+      lastTick = firstTick;
+   }
+}
+

BUILD

+cc -o LDR LDR.c -lpigpio -lrt -lpthread
+

RUN

+sudo ./LDR >LDR.dat &
+
+While the program is running you can capture the waveform using the +notification feature built in to pigpio.  Issue the following +commands on the Pi.
+
+pigs no
+pig2vcd  </dev/pigpio0 >LDR.vcd &
+pigs nb 0 0x40000 # set bit for gpio 18
+

Change the light falling on the LDR for a few seconds (e.g. +shine a torch on it or shade it with your hands).

+pigs nc 0
+

The file LDR.vcd will contain the captured waveform, which can +be viewed using GTKWave.

+

Overview

+LDR waveform 1
+

Reading circa every 10ms

+LDR waveform 2
+

One reading, circa 400us

+LDR waveform 3
+

The file LDR.dat will contain pairs of timestamps and recharge +time (in us).  The following  script will convert the +timestamps into seconds.

+

awk '{print $1/1000000, $2}' LDR.dat +>LDR-secs.dat

+

Gnuplot is a useful tool to graph data.

+plot [14:24] 'LDR-secs.dat' with lines title 'LDR' +

Gnuplot readings 14-24 seconds

+

gnuplot 1

+plot [18:21] 'LDR-secs.dat' with lines title 'LDR'
+
+Gnuplot readings 18-21 seconds +

Gnuplot 2

+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/ex_ir_remote.html b/DOC/HTML/ex_ir_remote.html new file mode 100644 index 0000000..257d613 --- /dev/null +++ b/DOC/HTML/ex_ir_remote.html @@ -0,0 +1,308 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

IR Remote Example

+

The following code shows one way to read an infrared remote +control device (the sort used in TVs and stereo systems).

+

SETUP

+fritzing diagramThe device used +is a SFH5110 (IR Receiver for remote control, +carrier 38 kHz).
+
Pin 1 (left from front) may be connected to any spare +gpio.  Here it's connected via a 4K7 current limiting +resistor.  This isn't really needed as the device has an +internal 23K resistor in-line.  It does no harm though.
+
+Pin 2 should be connected to a Pi ground pin.
+
+Pin 3 should be connected to a Pi 5V pin.
+

Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground +(P1-14), and pin 3 to 5V (P1-2).

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+#define IR_PIN 7
+
+#define OUTSIDE_CODE 0
+#define INSIDE_CODE  1
+
+#define MIN_MESSAGE_GAP 3000
+#define MAX_MESSAGE_END 3000
+
+#define MAX_TRANSITIONS 500
+
+/*
+   using the FNV-1a +hash                
+ +   from +http://isthe.com/chongo/tech/comp/fnv/#FNV-param
+*/
+
+#define FNV_PRIME_32 16777619
+#define FNV_BASIS_32 2166136261U
+
+static volatile uint32_t ir_hash = 0;
+
+typedef struct
+{
+   int state;
+   int count;
+   int level;
+   uint16_t micros[MAX_TRANSITIONS];
+} decode_t;
+
+/* forward declarations */
+
+void     alert(int gpio, int level, uint32_t +tick);
+uint32_t getHash(decode_t * decode);
+void     updateState(decode_t * decode, int +level, uint32_t micros);
+
+int main(int argc, char * argv[])
+{
+   if (gpioInitialise()<0)
+   {
+      return 1 ;
+   }
+
+   /* IR pin as input */
+
+   gpioSetMode(IR_PIN, PI_INPUT);
+
+   /* 5ms max gap after last pulse */
+
+   gpioSetWatchdog(IR_PIN, 5);
+
+   /* monitor IR level changes */
+
+   gpioSetAlertFunc(IR_PIN, alert);
+
+   while (1)
+   {
+      if (ir_hash)
+      {
+         /* non-zero means +new decode */
+         printf("ir code is +%u\ ", ir_hash);
+         ir_hash = 0;
+      }
+
+      gpioDelay(100000); /* check remote +10 times per second */
+   }
+
+   gpioTerminate();
+}
+
+void alert(int gpio, int level, uint32_t tick)
+{
+   static int inited = 0;
+
+   static decode_t activeHigh, activeLow;
+
+   static uint32_t lastTick;
+
+   uint32_t diffTick;
+
+   if (!inited)
+   {
+      inited = 1;
+
+      activeHigh.state = OUTSIDE_CODE; +activeHigh.level = PI_LOW;
+      activeLow.state  = +OUTSIDE_CODE; activeLow.level  = PI_HIGH;
+
+      lastTick = tick;
+      return;
+   }
+
+   diffTick = tick - lastTick;
+
+   if (level != PI_TIMEOUT) lastTick = tick;
+
+   updateState(&activeHigh, level, diffTick);
+   updateState(&activeLow, level, diffTick);
+}
+
+void updateState(decode_t * decode, int level, uint32_t micros)
+{
+   /*
+      We are dealing with active high as +well as active low
+      remotes.  Abstract the common +functionality.
+   */
+
+   if (decode->state == OUTSIDE_CODE)
+   {
+      if (level == decode->level)
+      {
+         if (micros > +MIN_MESSAGE_GAP)
+         {
+            +decode->state = INSIDE_CODE;
+            +decode->count = 0;
+         }
+      }
+   }
+   else
+   {
+      if (micros > MAX_MESSAGE_END)
+      {
+         /* end of message +*/
+
+         /* ignore if last +code not consumed */
+
+         if (!ir_hash) +ir_hash = getHash(decode);
+
+         decode->state = +OUTSIDE_CODE;
+      }
+      else
+      {
+         if +(decode->count < (MAX_TRANSITIONS-1))
+         {
+            +if (level != PI_TIMEOUT)
+               +decode->micros[decode->count++] = micros;
+         }
+      }
+   }
+}
+
+int compare(unsigned int oldval, unsigned int newval)
+{
+   if      (newval < (oldval +* 0.75)) {return 1;}
+   else if (oldval < (newval * 0.75)) {return 2;}
+   +else                               +{return 4;}
+}
+
+uint32_t getHash(decode_t * decode)
+{
+   /* use FNV-1a */
+
+   uint32_t hash;
+   int i, value;
+
+   if (decode->count < 6) {return 0;}
+
+   hash = FNV_BASIS_32;
+
+   for (i=0; i<(decode->count-2); i++)
+   {
+      value = +compare(decode->micros[i], decode->micros[i+2]);
+
+      hash = hash ^ value;
+      hash = (hash * FNV_PRIME_32);
+   }
+
+   return hash;
+}
+

BUILD

+cc -o ir_remote ir_remote.c -lpigpio -lrt +-lpthread
+

RUN

+sudo ./ir_remote
+

A hash code is formed from the level transitions detected during +a remote key press.  This is likely to be unique over multiple +remotes and keys.

+

While the program is running you can capture the waveform using +the notification feature built in to pigpio.  Issue the +following commands on the Pi.

+pigs no
+pig2vcd  </dev/pigpio0 >ir.vcd &
+pigs nb 0 0x80 # set bits for gpios 7 (0x80)
+

Press a few different remotes and keys.  Then enter

+pigs nc 0
+

The file ir.vcd will contain the captured waveform, which can be +viewed using GTKWave.

+

Overview

+ir remote waveform 1
+

Remote A typical waveform

+ir remote waveform 2
+

Remote B typical waveform

++"ir +
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/ex_motor_shield.html b/DOC/HTML/ex_motor_shield.html new file mode 100644 index 0000000..8378282 --- /dev/null +++ b/DOC/HTML/ex_motor_shield.html @@ -0,0 +1,309 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Arduino Motor Shield

+The following example demonstrates the use of an Arduino shield +from the Rasperry Pi.
+
+The shield used is a clone of the Adafruit motor shield.  See +shieldlist.org +for details.
+
+For the demonstration DC motors 3 and 4 are being driven forwards +and backwards with changing speeds (speeds are controlled via +PWM).
+
+Seven connections are made between the Pi and the shield.  +Four to latch the motor states (latch, enable, data, clock); Two to +control motor speed (PWM 3 and 4); and ground.
+
+The code used was ported from the Adafruit Arduino code and +converted to use the pigpio library.  Only the DC motor code +was ported.
+
+A video of the shield in use is available at youtube.com
+
+#include <stdio.h>

+
+#include <pigpio.h>
+
+/*
+   This code may be used to drive the Adafruit (or +clones) Motor Shield.
+
+   The code as written only supports DC motors.
+
+   http://shieldlist.org/adafruit/motor
+
+   The shield pinouts are
+
+   D12 MOTORLATCH
+   D11 PMW motor 1
+   D10 Servo 1
+   D9  Servo 2
+   D8  MOTORDATA
+
+   D7  MOTORENABLE
+   D6  PWM motor 4
+   D5  PWM motor 3
+   D4  MOTORCLK
+   D3  PWM motor 2
+
+   The motor states (forward, backward, brake, release) +are encoded using the
+   MOTOR_ latch pins.  This saves four gpios.
+*/
+
+typedef unsigned char uint8_t;
+
+#define BIT(bit) (1 << (bit))
+
+/* assign gpios to drive the shield pins */
+
+/*      +Shield      Pi */
+
+#define MOTORLATCH  14
+#define MOTORCLK    24
+#define MOTORENABLE 25
+#define MOTORDATA   15
+
+#define MOTOR_3_PWM  7
+#define MOTOR_4_PWM  8
+
+/*
+   The only other connection needed between the Pi and +the shield
+   is ground to ground. I used Pi P1-6 to shield gnd +(next to D13).
+*/
+
+/* assignment of motor states to latch */
+
+#define MOTOR1_A 2
+#define MOTOR1_B 3
+#define MOTOR2_A 1
+#define MOTOR2_B 4
+#define MOTOR4_A 0
+#define MOTOR4_B 6
+#define MOTOR3_A 5
+#define MOTOR3_B 7
+
+#define FORWARD  1
+#define BACKWARD 2
+#define BRAKE    3
+#define RELEASE  4
+
+static uint8_t latch_state;
+
+void latch_tx(void)
+{
+   unsigned char i;
+
+   gpioWrite(MOTORLATCH, PI_LOW);
+
+   gpioWrite(MOTORDATA, PI_LOW);
+
+   for (i=0; i<8; i++)
+   {
+      gpioDelay(10);  // 10 micros +delay
+
+      gpioWrite(MOTORCLK, PI_LOW);
+
+      if (latch_state & BIT(7-i)) +gpioWrite(MOTORDATA, PI_HIGH);
+      +else                        +gpioWrite(MOTORDATA, PI_LOW);
+
+      gpioDelay(10);  // 10 micros +delay
+
+      gpioWrite(MOTORCLK, PI_HIGH);
+   }
+
+   gpioWrite(MOTORLATCH, PI_HIGH);
+}
+
+void init(void)
+{
+   latch_state = 0;
+
+   latch_tx();
+
+   gpioWrite(MOTORENABLE, PI_LOW);
+}
+
+void DCMotorInit(uint8_t num)
+{
+   switch (num)
+   {
+      case 1: latch_state &= +~BIT(MOTOR1_A) & ~BIT(MOTOR1_B); break;
+      case 2: latch_state &= +~BIT(MOTOR2_A) & ~BIT(MOTOR2_B); break;
+      case 3: latch_state &= +~BIT(MOTOR3_A) & ~BIT(MOTOR3_B); break;
+      case 4: latch_state &= +~BIT(MOTOR4_A) & ~BIT(MOTOR4_B); break;
+      default: return;
+   }
+
+   latch_tx();
+
+   printf("Latch=%08X\ ", latch_state);
+}
+
+void DCMotorRun(uint8_t motornum, uint8_t cmd)
+{
+   uint8_t a, b;
+
+   switch (motornum)
+   {
+      case 1: a = MOTOR1_A; b = MOTOR1_B; +break;
+      case 2: a = MOTOR2_A; b = MOTOR2_B; +break;
+      case 3: a = MOTOR3_A; b = MOTOR3_B; +break;
+      case 4: a = MOTOR4_A; b = MOTOR4_B; +break;
+      default: return;
+   }

+   switch (cmd)
+   {
+      case FORWARD:  latch_state +|=  BIT(a); latch_state &= ~BIT(b); break;
+      case BACKWARD: latch_state &= +~BIT(a); latch_state |=  BIT(b); break;
+      case RELEASE:  latch_state +&= ~BIT(a); latch_state &= ~BIT(b); break;
+      default: return;
+   }
+
+   latch_tx();
+
+   printf("Latch=%08X\ ", latch_state);
+}
+
+int main (int argc, char *argv[])
+{
+   int i;
+
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(MOTORLATCH,  PI_OUTPUT);
+   gpioSetMode(MOTORENABLE, PI_OUTPUT);
+   gpioSetMode(MOTORDATA,   PI_OUTPUT);
+   gpioSetMode(MOTORCLK,    +PI_OUTPUT);
+
+   gpioSetMode(MOTOR_3_PWM, PI_OUTPUT);
+   gpioSetMode(MOTOR_4_PWM, PI_OUTPUT);
+
+   gpioPWM(MOTOR_3_PWM, 0);
+   gpioPWM(MOTOR_4_PWM, 0);
+
+   init();
+
+   for (i=60; i<160; i+=20)
+   {
+      gpioPWM(MOTOR_3_PWM, i);
+      gpioPWM(MOTOR_4_PWM, 220-i);
+
+      DCMotorRun(3, FORWARD);
+      DCMotorRun(4, BACKWARD);
+
+      sleep(2);
+
+      DCMotorRun(3, RELEASE);
+      DCMotorRun(4, RELEASE);
+
+      sleep(2);
+
+      gpioPWM(MOTOR_4_PWM, i);
+      gpioPWM(MOTOR_3_PWM, 220-i);
+
+      DCMotorRun(3, BACKWARD);
+      DCMotorRun(4, FORWARD);
+
+      sleep(2);
+
+      DCMotorRun(3, RELEASE);
+      DCMotorRun(4, RELEASE);
+
+      sleep(2);
+   }
+
+   gpioPWM(MOTOR_4_PWM, 0);
+   gpioPWM(MOTOR_3_PWM, 0);
+
+   DCMotorRun(3, RELEASE);
+   DCMotorRun(4, RELEASE);
+
+   gpioTerminate();
+}
+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/ex_rotary_encoder.html b/DOC/HTML/ex_rotary_encoder.html new file mode 100644 index 0000000..e6df718 --- /dev/null +++ b/DOC/HTML/ex_rotary_encoder.html @@ -0,0 +1,240 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Rotary Encoder Example

+

The following code shows one way to read an incremental +mechanical rotary enoder (the sort used for volume control in audio +systems).  These rotary encoders have two switches A and B +which return a quadrature output, i.e. they are 90 degrees out of +phase.

+

SETUP

+fritzing diagramThe common +(centre) terminal should be connected to a Pi ground. +

The A and B terminals may be connected to any spare gpios.

+

Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7 +(P1-26).

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/*
+   Rotary encoder connections:
+
+   Encoder A      - gpio +18   (pin P1-12)
+   Encoder B      - gpio +7    (pin P1-26)
+   Encoder Common - Pi ground (pin P1-20)
+*/
+
+#define ENCODER_A 18
+#define ENCODER_B  7
+
+static volatile int encoderPos;
+
+/* forward declaration */
+
+void encoderPulse(int gpio, int lev, uint32_t tick);
+
+int main(int argc, char * argv[])
+{
+   int pos=0;
+
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(ENCODER_A, PI_INPUT);
+   gpioSetMode(ENCODER_B, PI_INPUT);
+
+   /* pull up is needed as encoder common is grounded +*/
+
+   gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);
+   gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);
+
+   encoderPos = pos;
+
+   /* monitor encoder level changes */
+
+   gpioSetAlertFunc(ENCODER_A, encoderPulse);
+   gpioSetAlertFunc(ENCODER_B, encoderPulse);
+
+   while (1)
+   {
+      if (pos != encoderPos)
+      {
+         pos = +encoderPos;
+         printf("pos=%d\ ", +pos);
+      }
+      gpioDelay(20000); /* check pos 50 +times per second */
+   }
+
+   gpioTerminate();
+}
+
+void encoderPulse(int gpio, int level, uint32_t tick)
+{
+   /*
+
+             ++---------+         ++---------+      0
+             +|         +|         +|         |
+   A         +|         +|         +|         |
+             +|         +|         +|         |
+   ++---------+         ++---------+         +----- +1
+
+       ++---------+         ++---------+            +0
+       +|         +|         +|         |
+   B   +|         +|         +|         |
+       +|         +|         +|         |
+   ----+         ++---------+         ++---------+  1
+
+   */
+
+   static int levA=0, levB=0, lastGpio = -1;
+
+   if (gpio == ENCODER_A) levA = level; else levB = +level;
+
+   if (gpio != lastGpio) /* debounce */
+   {
+      lastGpio = gpio;
+
+      if ((gpio == ENCODER_A) && +(level == 0))
+      {
+         if (!levB) +++encoderPos;
+      }
+      else if ((gpio == ENCODER_B) +&& (level == 1))
+      {
+         if (levA) +--encoderPos;
+      }
+   }
+}
+

BUILD

+cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt +-lpthread
+

RUN

+sudo ./rotary_encoder
+

While the program is running you can capture the waveform using +the notification feature built in to pigpio.  Issue the +following commands on the Pi.

+pigs no
+pig2vcd  </dev/pigpio0 >re.vcd &
+pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18 +(0x40000)
+

Twiddle the rotary encoder forwards and backwards for a few +seconds.  Then enter

+pigs nc 0
+

The file re.vcd will contain the captured waveform, which can be +viewed using GTKWave.

+
+Overview
+
++"rotary
+
+Detail of switch bounce.  Contact A bounces for circa 700 us +before completing the level transition
+
++"rotary
+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/ex_sonar_ranger.html b/DOC/HTML/ex_sonar_ranger.html new file mode 100644 index 0000000..9e60c39 --- /dev/null +++ b/DOC/HTML/ex_sonar_ranger.html @@ -0,0 +1,219 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Sonar Ranger Example

+

The following code shows a method of reading a class of sonar +rangers.  These rangers requires a trigger pulse.  +Shortly after receiving a trigger they transmit a noise pulse and +set the echo line high.  When the echo is received the echo +line is set low.

+

SETUP

+fritzing diagram
+
+
+
+
+The ranger used is a SRF05 (check the pinouts, there are many +variants).
+
+The fritzing diagram shows the back of the ranger, i.e. pin 1 is +the rightmost.
+
+Pin 1 is 5V.
+Pin 2 is the trigger line.
+Pin 3 is the echo line.
+Pin 4 is out (unused).
+Pin 5 is ground.
+
+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/*
+
+P1  Name  gpio    used for
+
+ 2  5V    ---     +5V
+ 6  GND   ---     +Ground
+24  CE0   8       +Sonar echo
+26  CE1   7       +Sonar trigger
+
+*/
+
+#define SONAR_TRIGGER 7
+#define SONAR_ECHO    8
+
+/* forward prototypes */
+
+void sonarTrigger(void);
+
+void sonarEcho(int gpio, int level, uint32_t tick);
+
+int main(int argc, char *argv[])
+{
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);
+   gpioWrite  (SONAR_TRIGGER, PI_OFF);
+
+   gpioSetMode(SONAR_ECHO,    +PI_INPUT);
+
+   /* update sonar 20 times a second, timer #0 */
+
+   gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms +*/
+
+   /* monitor sonar echos */
+
+   gpioSetAlertFunc(SONAR_ECHO, sonarEcho);
+
+   while (1) sleep(1);
+
+   gpioTerminate();
+
+   return 0;
+}
+
+void sonarTrigger(void)
+{
+   /* trigger a sonar reading */
+
+   gpioWrite(SONAR_TRIGGER, PI_ON);
+
+   gpioDelay(10); /* 10us trigger pulse */
+
+   gpioWrite(SONAR_TRIGGER, PI_OFF);
+}
+
+void sonarEcho(int gpio, int level, uint32_t tick)
+{
+   static uint32_t startTick, firstTick=0;
+
+   int diffTick;
+
+   if (!firstTick) firstTick = tick;
+
+   if (level == PI_ON)
+   {
+      startTick = tick;
+   }
+   else if (level == PI_OFF)
+   {
+      diffTick = tick - startTick;
+
+      printf("%u %u\ ", tick-firstTick, +diffTick);
+   }
+}
+

BUILD

+cc -o sonar sonar.c -lpigpio -lrt -lpthread
+

RUN

+sudo ./sonar >sonar.dat &
+
+While the program is running you can capture the waveform using the +notification feature built in to pigpio.  Issue the following +commands on the Pi.
+
+pigs no
+pig2vcd  </dev/pigpio0 >sonar.vcd &
+pigs nb 0 0x180 # set bits for gpios 7 and 8
+

Move an object in front of the sonar ranger for a few +seconds.

+pigs nc 0
+

The file sonar.vcd will contain the captured waveform, which can +be viewed using GTKWave.

+

Overview

+LDR waveform 1
+

Reading circa every 10ms

+Sonar waveform 2
+

One reading, circa 400us

+Sonar waveform 3
+

another

+Sonar waveform 4
+

The file sonar.dat will contain pairs of timestamps and echo +length (in us).  The following  script will convert the +timestamps into seconds.

+

awk '{print $1/1000000, $2}' sonar.dat +>sonar-secs.dat

+

Gnuplot is a useful tool to graph data.

+plot 'sonar-secs.dat' title 'Sonar'
+

gnuplot 1
+ plot [10:25] 'sonar-secs.dat' title 'Sonar'

+

gnuplot 1

+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/examples.html b/DOC/HTML/examples.html new file mode 100644 index 0000000..59e3907 --- /dev/null +++ b/DOC/HTML/examples.html @@ -0,0 +1,558 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Examples

The following examples show various ways pigpio may be used to communicate with sensors via the GPIO.
+
+Although many are complete programs they are intended to be a starting point in producing your own code, not an end point.
+
+Index

+Hardware

+Shell code

+C code

+C++ code

+pigpiod_if2 code

+Python code

+Miscellaneous related code

+External links

+

Hardware

+A few practical examples of using pigpio with hardware.
+
+
IR Receiver
2013-06-09
Reading an infrared remote receiver.
+
+
Light Dependent Resistor
2013-06-09
Measuring brightness with a light dependent resistor (LDR). Improved methods of timing the start of the capacitor recharge are given for C and Python.
+
+
Motor Shield
2013-12-15
Using an Arduino motor shield.
+
+
Rotary Encoder
2013-06-09
Reading a rotary encoder.
+
+
Sonar Ranger
2013-06-10
Measuring range with a sonar ranger.
+
+

Shell code

+Examples of using pigpio with shell code.
+
+
GPIO test
2014-08-11
This bash script tests the user GPIO. Video
+
+

C code

+Examples of C pigpio programs.
+
+If your program is called foobar.c then build with
+
+gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
+
+
Frequency Counter 1
2014-08-20
A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs).
+
+
Frequency Counter 2
2014-08-20
A program showing how to use the gpioSetGetSamplesFunc function to set a callback for accumulated GPIO state changes over the last millisecond. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). Generally the method used is more complicated but more efficient than frequency counter 1.
+
+
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
+
+
I2C Sniffer
2014-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results. This C program uses pigpio notifications.
+
+
IR Receiver
2015-02-25
Function to hash a code from an IR receiver (reading an IR remote control).
+
+
PCF8591 YL-40
2014-08-26
A program to display readings from the (I2C) PCF8591.
+
+
Pot + Capacitor Recharge Timing
2014-03-14
Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
+
+
Rotary Encoder
2015-10-03
Function to decode a mechanical rotary encoder.
+
+
SPI bit bang MCP3008
2016-03-20
This program shows how to read multiple MCP3008 ADC simultaneously with accurately timed intervals. One 10-bit channel of each ADC may be sampled at up to 25k samples per second.
+
+
SPI bit bang MCP3202
2016-03-20
This program shows how to read multiple MCP3202 ADC simultaneously with accurately timed intervals. One 12-bit channel of each ADC may be sampled at up to 25k samples per second.
+
+
SPI bit bang MCP3008 and MCP3202
2016-03-20
This program shows how to read multiple MCP3008 and MCP3202 ADC simultaneously with accurately timed intervals. One channel of each ADC may be sampled at up to 25k samples per second. The 10-bit MCP3008 readings are multiplied by 4 so they have the same range (0-4095) as the 12-bit MCP3202.
+
+
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
+
+sudo ./servo_demo # Generate pulses on GPIO 4.
+
+sudo ./servo_demo 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
+
+
SPI pigpio driver speed test
2016-11-06
This C code is used to benchmark the pigpio SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
+
+
Wiegand Reader
2013-12-30
Function to read a Wiegand Reader.
+
+

C++ code

+Examples of C++ pigpio programs.
+
+If your program is called foobar.cpp then build with
+
+g++ -Wall -pthread -o foobar foobar.cpp -lpigpio -lrt
+
+
IR Receiver
2015-02-22
Class to hash a code from an IR receiver (reading an IR remote control).
+
+
Rotary Encoder
2013-12-30
Class to decode a mechanical rotary encoder.
+
+
Wiegand Reader
2013-12-30
Class to read a Wiegand Reader.
+
+

pigpiod_if2 code

The pigpiod_if2 code examples are linked with libpigpiod_if2 and are written in C.
+
+The pigpiod_if2 library may be compiled and run on any Linux machine and allows control of the GPIO on one or more networked Pis.
+
+It should be possible to adapt the library to run on Macs and PCs.
+
+Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
+
+
433MHz Keyfob RX/TX
2015-11-17
Code to read and transmit 313 and 434 MHz key fob codes. The codes to be read must use Manchester encoding. The transmitted codes use Manchester encoding.
+
+./_433D -r10 # Print fob keycodes received on GPIO 10.
+
+./_433D -t5 8246184 # Transmit code on GPIO 5.
+
+./_433D -r10 -t5 8246184 # Transmit code on GPIO 5 then listen for codes
+
+./_433D -? for options.
+
+
DHT11/21/22/33/44 Sensor
2016-02-16
Code to read the DHT temperature and humidity sensors. The sensor may be auto detected. A DHT11 sensor may be read once per second. The other sensors should not be read more often than once every three seconds.
+
+The code auto detects the DHT model and generally only the GPIO needs to be specified.
+
+./DHTXXD -g17 # Read a DHT connected to GPIO 17.
+
+./DHTXXD -g5 -i3 # Read a DHT connected to GPIO 5 every three seconds.
+
+./DHTXXD -? # for options.
+
+
Rotary Encoder
2015-11-18
Code to monitor a rotary encoder and show the position changes. By default the detent changes are shown. There is an option to show the four steps per detent instead.
+
+./RED -a7 -b8 -s30 # Show encoder on 7/8 detent changes for 30 seconds.
+
+./RED -a5 -b6 -m1 # Show encoder on 5/6 step changes forever.
+
+./RED -? # for options.
+
+
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
+
+./servo_demo_D # Generate pulses on GPIO 4.
+
+./servo_demo_D 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
+
+
Sonar Ranger
2015-11-16
Code to read the SRF-04 and SRF-05 type of sonar rangers which use the trigger echo method of operation. A 10 μs trigger pulse initiates a series of high frequency sonar chirps. The echo line then goes high and stays high until an echo from an object is received. The echo high time is used to calculate the distance of the object.
+
+For a one-off reading only the trigger and echo GPIO need to be specified.
+
+./SRTED -t5 -e6 # Read a sonar ranger connected to GPIO 5/6.
+
+./SRTED -t11 -e5 -i0.1 # Read a sonar ranger connected to GPIO 11/5 every 0.1 seconds.
+
+./SRTED -? # for options.
+
+
Transmit Rotary Encoder Test Signals
2015-11-25
Code to transmit quadrature signals to test rotary encoder software.
+
+tx_RED -aGPIO -bGPIO [options]
+
+tx_RED -? for options
+
+E.g.
+
+tx_RED -a5 -b6 -s20 -r-100
+
+
Transmit Wiegand Test Signals
2015-11-25
Code to transmit Wiegand codes to test Wiegand decoder software.
+
+tx_WD -gGPIO -wGPIO [options] {code}+
+
+tx_WD -? for options
+
+E.g.
+
+tx_WD -g5 -w6 -s37 12345 67890 123 899999
+
+
Wiegand Reader
2015-11-25
Code to read a Wiegand Reader.
+
+./WD -g7 -w8 -s30 # Read Wiegand codes from GPIO 7/8 for 30 seconds.
+
+./WD -g5 -w6 # Read Wiegand codes from GPIO 5/6 forever.
+
+./WD -? # for options.
+
+

Python code

The Python code may be run on any Python machine and allows control of the GPIO on one or more networked Pis.
+
+The Python machine need not be a Pi, it may run Windows, Mac, Linux, anything as long as it supports Python.
+
+Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
+
+
433MHz Keyfob RX/TX
2015-10-30
Classes to send and receive 433MHz wireless keyfob codes. These keyfobs are widely used for remote control of devices.
+
+
7-Segment LED Display Multiplexing
2016-12-12
Script to multiplex several 7-segment LED displays. Each display has the segments a-g and the decimal point connected in parallel but has an individual enable GPIO (connected to the common anode or cathode).
+
+
APA102 LED strip driver
2017-03-28
Script to drive an APA102 LED strip. Three different methods are demonstrated - using spidev SPI (only works on the local Pi), pigpio SPI, and pigpio waves. The SPI solutions only work with the dedicated SPI GPIO. Waves may use any spare GPIO. Four different examples are given including a LED strip clock.
+
+
BME280 Sensor
2016-08-05
Class to read the relative humidity, temperature, and pressure from a BME280 sensor. The sensor has both an I2C and a SPI interface which are both
+supported by the class.
+
+
DHT11/21/22/33/44 Sensor
2019-11-07
Class to read the relative humidity and temperature from a DHT sensor. It can automatically recognize the sensor type.
+
+The default script prints the reading from the specified DHT every 2 seconds. E.g. ./DHT.py 22 27 displays the data for DHT connected to GPIO 22 and 27.
+
+The following data is printed for each DHT: timestamp, GPIO, status, temperature, and humidity.
+
+The timestamp is the number of seconds since the epoch (start of 1970).
+
+The status will be one of: 0 - a good reading, 1 - checksum failure, 2 - data had one or more invalid values, 3 - no response from sensor.
+
+
DHT22 AM2302 Sensor
2014-07-11
Class to read the relative humidity and temperature from a DHT22/AM2302 sensor.
+
+
DS18B20 Temperature Sensor
2016-06-29
Script to read the temperature from any DS18B20 sensors connected to the 1-wire bus.
+
+To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
+
+dtoverlay=w1-gpio
+
+By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
+
+Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
+
+This script uses the file features of pigpio to access the remote file system.
+
+The following entry must be in /opt/pigpio/access.
+
+/sys/bus/w1/devices/28*/w1_slave r
+
+
Dust Sensor
2015-11-22
Class to read a Shinyei PPD42NS Dust Sensor, e.g. as used in the Grove dust sensor.
+
+
GPIO Status
2014-06-12
Script to display the status of GPIO 0-31.
+
+
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
+
+
HX711 24-bit ADC
2018-03-05
Class to read the channels of a HX711 24-bit ADC.
+
+
I2C ADXL345 Accelerometer
2015-04-01
Script to display the X, Y, and Z values read from an ADXL345 accelerometer.
+
+
I2C HMC5883L Magnetometer
2015-04-01
Script to display the X, Y, and Z values read from a HMC5883L Magnetometer (compass).
+
+
I2C ITG3205 Gyroscope
2015-04-01
Script to display the X, Y, Z, and temperature values read from an ITG3205 gyroscope.
+
+
I2C LCD Display
2016-04-20
Class to display text on a LCD character display. The class supports the PCF8574T 8-bit I2C port expander connected to a HD44780 based LCD display. These displays are commonly available in 16x2 and 20x4 character formats.
+
+
I2C slave device
2016-10-31
This script demonstrates how to transfer messages from an Arduino acting as the I2C bus master to the Pi acting as an I2C slave device.
+
+
I2C Sniffer
2015-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results.
+
+
I2C Sonar
2016-03-24
A class to read up to 8 HC-SR04 sonar rangers connected to an MCP23017 port expander.
+
+
IR Receiver
2014-06-12
Class to hash a code from an IR receiver (reading an IR remote control).
+
+
IR Record and Playback
2015-12-21
This script may be used to record and play back arbitrary IR codes.
+
+To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given.
+
+E.g. ./irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0
+
+To playback the GPIO connected to the IR transmitter, the file containing the recorded codes, and the codes to be played back are given.
+
+E.g. ./irrp.py -p -g18 -fir-codes 2 3 4
+
+./irrp.py -h # for options
+
+
Kivy GPIO control
2016-12-11
This example shows how to use Kivy to control a Pi's GPIO. The GPIO may be configured as inputs, outputs, or to generate Servo or PWM pulses. Kivy is an Open source Python library for rapid development of applications.
+
+
MAX6675 SPI Temperature Sensor
2016-05-02
A script to read the temperature from a MAX6675 connected to a K-type thermocouple. The MAX6675 supports readings in the range 0 - 1023.75 C. Up to 4 readings may be made per second.
+
+
Monitor GPIO
2016-09-17
Script to monitor GPIO for level changes. By default all GPIO are monitored. At a level change the GPIO, new level, and microseconds since the last change is printed.
+
+
Morse Code
2015-06-17
Script to transmit the morse code corresponding to a text string.
+
+
NRF24 radio transceiver
2018-01-06
Script to transmit and receive messages using the nRF24L01 radio transceiver.
+
+
PCA9685 16 Channel PWM
2016-01-31
Class to control the 16 PWM channels of the I2C PCA9685. All channels use the same frequency. The duty cycle or pulse width may be set independently for each channel.
+
+
PCF8591 YL-40
2014-08-26
Script to display readings from the (I2C) PCF8591.
+
+
PPM (Pulse Position Modulation) generation
2016-02-19
Script to generate PPM signals on a chosen GPIO.
+
+
PPM (Pulse Position Modulation) to servo pulses
2019-10-09
Script to read a PPM signal on a GPIO and generate the corresponding servo signals on chosen GPIO.
+
+
pigpio Benchmark
2014-06-12
Script to benchmark the pigpio Python module's performance.
+
+
pigpio CGI
2015-05-04
Script demonstrating how to access the pigpio daemon using CGI from a browser. Instructions on how to use with Apache2 on the Pi are given in the comments.
+
+
Playback piscope recordings
2016-12-23
Script to playback GPIO data recorded in piscope format.
+
+To playback GPIO 4 to GPIO 4 from file data.piscope
+./playback.py data.piscope 4
+
+To playback GPIO 4 to GPIO 7 from file rec.txt
+./playback.py rec.txt 7=4
+
+
Pot + Capacitor Recharge Timing
2016-09-26
Class to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
+
+
PWM Monitor
2015-12-08
Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle.
+
+
Rotary Encoder
2014-06-12
Class to decode a mechanical rotary encoder.
+
+
RPM Monitor
2016-01-20
Class to monitor speedometer pulses and calculate the RPM (Revolutions Per Minute).
+
+
Si7021 I2C Temperature and Humidity Sensor
2016-05-07
Class to read the temperature and relative humidity from a Si7021.
+
+
SPI Monitor
2016-09-21
A program to passively sniff SPI transactions and display the results. The SPI rate should be limited to about 70kbps if using the default pigpio 5µs sampling rate.
+
+
Servo Pulse Generator
2016-10-07
This script generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
+
+./servo_demo.py # Generate pulses on GPIO 4.
+
+./servo_demo.py 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
+
+
Sonar Ranger
2014-06-12
Class to read sonar rangers with separate trigger and echo pins.
+
+
TCS3200 Colour Sensor
2015-07-03
Class to read the TCS3200 colour sensor
+
+
Virtual Wire
2015-10-31
Class to send and receive radio messages compatible with the Virtual Wire library for Arduinos. This library is commonly used with 313MHz and 434MHz radio tranceivers.
+
+
Wave create
2019-11-18
Script to generate waves from a template defined in a text file.
+
+You can also specify one of py, c, or pdif - the script output will then be a complete program to generate the wave (py for Python script, c for a C program, pdif for a C program using the pigpio daemon I/F).
+
+If none of py, c, or pdif are chosen the waveform will be generated for 30 seconds.
+
+Example text file
+
+# GPIO levels
+23 11000001
+11 01110000
+12 00011100
+4 00000111
+
+To generate a pdif program with a bit time of 100 microseconds
+./create_wave.py wave_file 100 pdif >wave_pdif.c
+
+To just transmit the wave with a bit time of 50 microseconds
+./create_wave.py wave_file 50
+
+
Wave PWM 1
2016-03-19
Script to show how waves may be used to generate PWM at (one) arbitrary frequency on multiple GPIO. For instance PWM at 10kHz may be generated with 100 steps between off and fully on.
+
+
Wave PWM 2
2016-10-06
Class to generate PWM on multiple GPIO. It is more flexible than the Wave PWM 1 example in that the start of the pulse within each cycle may be specified as well as the duty cycle. The start and length of each pulse may be specified on a GPIO by GPIO basis in microseconds or as a fraction of the cycle time. The class includes a __main__ to demostrate its ability to send servo pulses.
+
+
Wiegand Reader
2014-06-12
Class to read a Wiegand reader.
+
+

Miscellaneous related code

+The following code examples do not use pigpio.
+
+
ADXL345
2014-03-12
This C program reads x, y, and z accelerations from the ADXL345 via I2C address 0x53.
+
+
DS18B20 Temperature Sensor
2016-04-25
This Python script reads the temperature from any DS18B20 sensors connected to the 1-wire bus.
+
+To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
+
+dtoverlay=w1-gpio
+
+By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
+
+Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
+
+
Easy as Pi Server
2014-09-15
This Python class implements a simple server which allows broswer commands to be executed on the Pi.
+
+
Minimal Clock Access
2015-05-20
This C code sets GPIO 4 to a specified clock frequency. The frequency can be set between 4.6875 kHz and 500 MHz (untested). The clock can be preferentially set from one of the sources OSC (19.2MHz), HDMI (216MHz), PLLD (500MHz), or PLLC (1000MHz). MASH can be set between 0 and 3. MASH may not work properly for clock dividers less than 5.
+
+
Minimal GPIO Access
2019-07-03
This C code has a minimal set of functions needed to control the GPIO and other Broadcom peripherals. The program requires root privileges to run. See Tiny GPIO access for an alternative which controls the GPIO (but not the other peripherals) and does not require root access.
+
+The code has been updated for the BCM2711 (Pi4B).
+
+The following functions are provided.
+
+gpioInitialise
+gpioSetMode
+gpioGetMode
+gpioSetPullUpDown
+gpioRead
+gpioWrite
+gpioTrigger
+gpioReadBank1
+gpioReadBank2
+gpioClearBank1
+gpioClearBank2
+gpioSetBank1
+gpioSetBank2
+gpioHardwareRevision
+gpioTick
+
+
Nanosecond Pulse Generation
2014-01-29
This C program uses the PWM peripheral to generate precisely timed pulses of very short duration. Pulses as short as 4 nano seconds can be generated.
+
+
PCF8591 YL-40
2014-08-26
C and Python code to read the (I2C) PCF8591.
+
+
SPI Linux driver speed test
2016-11-06
This C code is used to benchmark the Linux SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
+
+
Tiny GPIO Access
2016-04-30
This C code has a minimal set of functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO).
+
+You may need to change the permissions and ownership of /dev/gpiomem if they have not been correctly set up.
+
+sudo chown root:gpio /dev/gpiomem
+sudo chmod g+rw /dev/gpiomem
+
+The user (default pi) needs to be in the gpio group.
+
+sudo adduser pi gpio
+
+The following functions are provided.
+
+gpioInitialise
+gpioSetMode
+gpioGetMode
+gpioSetPullUpDown
+gpioRead
+gpioWrite
+gpioTrigger
+gpioReadBank1
+gpioReadBank2
+gpioClearBank1
+gpioClearBank2
+gpioSetBank1
+gpioSetBank2
+gpioHardwareRevision
+
+

External links

+Related code.
+
+
Stepper Motor
2016-08-12
Stepper motor code.
+
+
Parallax ActivityBot 360
2018-11-03
Python 3 implementation for programming a Parallax ActivityBot 360 Robot Kit with a Raspberry Pi.
+
+

Index

+ +
433MHz Keyfob RX/TX pdif2 + Python +
7-Segment LED Display Multiplexing Python +
ADXL345 Misc +
APA102 LED strip driver Python +
BME280 Sensor Python +
DHT11/21/22/33/44 Sensor pdif2 + Python +
DHT22 AM2302 Sensor Python +
DS18B20 Temperature Sensor Python + Misc +
Dust Sensor Python +
Easy as Pi Server Misc +
Frequency Counter 1 C +
Frequency Counter 2 C +
GPIO Status Python +
GPIO test Shell +
Hall Effect Sensor C + Python +
HX711 24-bit ADC Python +
I2C ADXL345 Accelerometer Python +
I2C HMC5883L Magnetometer Python +
I2C ITG3205 Gyroscope Python +
I2C LCD Display Python +
I2C slave device Python +
I2C Sniffer C + Python +
I2C Sonar Python +
IR Receiver Hardware + C + C++ + Python +
IR Record and Playback Python +
Kivy GPIO control Python +
Light Dependent Resistor Hardware +
MAX6675 SPI Temperature Sensor Python +
Minimal Clock Access Misc +
Minimal GPIO Access Misc +
Monitor GPIO Python +
Morse Code Python +
Motor Shield Hardware +
Nanosecond Pulse Generation Misc +
NRF24 radio transceiver Python +
Parallax ActivityBot 360 External +
PCA9685 16 Channel PWM Python +
PCF8591 YL-40 C + Python + Misc +
pigpio Benchmark Python +
pigpio CGI Python +
Playback piscope recordings Python +
Pot + Capacitor Recharge Timing C + Python +
PPM (Pulse Position Modulation) generation Python +
PPM (Pulse Position Modulation) to servo pulses Python +
PWM Monitor Python +
Rotary Encoder Hardware + C + C++ + pdif2 + Python +
RPM Monitor Python +
Servo Pulse Generator C + pdif2 + Python +
Si7021 I2C Temperature and Humidity Sensor Python +
Sonar Ranger Hardware + pdif2 + Python +
SPI bit bang MCP3008 C +
SPI bit bang MCP3008 and MCP3202 C +
SPI bit bang MCP3202 C +
SPI Linux driver speed test Misc +
SPI Monitor Python +
SPI pigpio driver speed test C +
Stepper Motor External +
TCS3200 Colour Sensor Python +
Tiny GPIO Access Misc +
Transmit Rotary Encoder Test Signals pdif2 +
Transmit Wiegand Test Signals pdif2 +
Virtual Wire Python +
Wave create Python +
Wave PWM 1 Python +
Wave PWM 2 Python +
Wiegand Reader C + C++ + pdif2 + Python +
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/faq.html b/DOC/HTML/faq.html new file mode 100644 index 0000000..1286cbe --- /dev/null +++ b/DOC/HTML/faq.html @@ -0,0 +1,516 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Frequently Asked Questions

+Are my GPIO broken?
+
+Audio is broken
+
+Can´t initialise pigpio +library
+
+Can´t lock +var/run/pigpio.pid
+
+Hello World!
+
+Clock skew, make fails
+
+Have I fried my GPIO?
+
+How do I debounce +inputs?
+
+How fast is SPI?
+
+Library update didn't work
+
+make fails with clock skew
+
+Porting pigpio to another CPU/SoC
+
+Sound isn't working
+
+Symbol not found
+
+What is I2C?
+
+What is Serial?
+
+What is SPI?
+
+Which library should I use?
+
+

Are my +GPIO broken?

+

See Have I fried my +GPIO?

+

Audio is +broken

+

See Sound isn't +working

+

Can´t lock +/var/run/pigpio.pid

+

See Can´t_initialise_pigpio_library
+

+

Can´t initialise pigpio +library

+

This message means the pigpio daemon is already running.

+

The default daemon is called pigpiod and may be removed as +follows.

+Check that it is running with the command +

ps aux | grep pigpiod

+

Kill the daemon with

+

sudo killall pigpiod

+

If your own program is acting as the daemon it may be removed as +follows.

+

Find its process id (pid).

+

cat /var/run/pigpio.pid

+

Kill the program with

+

sudo kill -9 pid

+If the above doesn't work do the following and try starting the +daemon again +

sudo rm /var/run/pigpio.pid

+

To start the daemon do

+

sudo pigpiod

+

Have I fried my GPIO?

+

If you think you have damaged one or more GPIO you can carry out +a diagnostic test.

+

The test is a command line script called gpiotest

+For the duration of the test nothing must be connected to the GPIO +(no LEDs, wires, ribbon cables etc.). +

The test checks that each GPIO may be read and written and that +the internal resistor pull-ups and pull-downs are functional.

+

A video +showing what happens to the GPIO during a test.

+

A test with all GPIO okay.

+
This program checks the Pi's (user) gpios.
+
+The program reads and writes all the gpios.  Make sure NOTHING
+is connected to the gpios during this test.
+
+The program uses the pigpio daemon which must be running.
+
+To start the daemon use the command sudo pigpiod.
+
+Press the ENTER key to continue or ctrl-C to abort...
+
+Testing...
+Skipped non-user gpios: 0 1 28 29 30 31 
+Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 +Failed user gpios: None +
+

A test showing failed GPIO.

+
This program checks the Pi's (user) gpios.
+
+The program reads and writes all the gpios. Make sure NOTHING
+is connected to the gpios during this test.
+
+The program uses the pigpio daemon which must be running.
+
+To start the daemon use the command sudo pigpiod.
+
+Press the ENTER key to continue or ctrl-C to abort...
+
+Testing...
+Write 1 to gpio 17 failed.
+Pull up on gpio 17 failed.
+Write 1 to gpio 18 failed.
+Pull up on gpio 18 failed.
+Write 0 to gpio 23 failed.
+Pull down on gpio 23 failed.
+Write 0 to gpio 24 failed.
+Pull down on gpio 24 failed.
+Write 1 to gpio 27 failed.
+Pull up on gpio 27 failed.
+Skipped non-user gpios: 0 1 28 29 30 31
+Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 +Failed user gpios: 17 18 23 24 27 +
+

How do I debounce inputs?

+

Some devices like mechanical switches can generate multiple +interrupts as they bounce between on and off.  It is possible +to debounce the inputs in hardware by the correct use of resistors +and capacitors.

+

In software use the glitch filter which ignores all events +shorter than a set number of microseconds.  C gpioGlitchFilter, Python set_glitch_filter.

+

How fast is +SPI?

+The SPI throughput in samples per second depends on a number of +factors.
+
+
    +
  • The SPI bit rate (transfer rate in bits per second)
  • +
+
    +
  • The number of bytes transferred per sample (a 12 bit ADC sample +may require 3 bytes to transfer)
  • +
+
    +
  • The driver used
  • +
+

Two of those factors are fixed, the variable is the driver +used.

+

The pigpio driver is considerably faster than the Linux SPI +driver as is demonstrated by the following graphs.

+

Each graph shows the SPI bit rate in bits per second along the +horizontal axis.  The samples per second achieved is shown on +the vertical axis.  Each graph contains plots assuming 1 to 5 +bytes per transfer.

+

The source code used for the tests is spi-driver-speed.c and spi-pigpio-speed.c

+

spi-lnx-pibr1.png

+
+

spi-pig-pibr1.png

+
+

spi-lnx-pi3b.png

+
+

spi-pig-pi3b.png

+

Library update didn't work

+

pigpio places files in the following locations

+

/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
+/usr/local/lib (libpigpio.so, libpigpiod_if.so, +libpigpiod_if2.so)
+/usr/local/bin (pig2vcd, pigpiod, pigs)
+/usr/local/man (man pages)

+The raspberrypi.org image containing pigpio uses different +locations.
+

/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
+/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)
+/usr/bin (pig2vcd, pigpiod, pigs)
+/usr/man (man pages)

+

Mostly this doesn't matter as the /usr/local directories will +generally be earlier in the search path.  The pigpio built +includes, binaries, and manuals are normally found first.

+

However the wrong libraries may be linked during the +compilation.  If this is the case remove the /usr/lib entries +for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so

+

Hello World!

+

The following examples show how to use the various components of +the pigpio library.

+

Each example shows how to read the level of a GPIO.

+

C

+read_cif.c +
+#include <stdio.h>
+#include <pigpio.h>
+
+int main(int argc, char *argv[])
+{
+   int GPIO=4;
+   int level;
+
+   if (gpioInitialise() < 0) return 1;
+
+   level = gpioRead(GPIO);
+
+   printf("GPIO %d is %d\n", GPIO, level);
+
+   gpioTerminate();
+}
+    
+

Build

+gcc -pthread -o read_cif read_cif.c -lpigpio +

Run

+sudo ./read_cif +

C via pigpio daemon

+read_pdif.c +
+#include <stdio.h>
+#include <pigpiod_if2.h>
+
+int main(int argc, char *argv[])
+{
+   int pi;
+   int GPIO=4;
+   int level;
+
+   pi = pigpio_start(0, 0); /* Connect to local Pi. */
+
+   if (pi < 0)
+   {
+      printf("Can't connect to pigpio daemon\n");
+      return 1;
+   }
+
+   level = gpio_read(pi, GPIO);
+
+   printf("GPIO %d is %d\n", GPIO, level);
+
+   pigpio_stop(pi); /* Disconnect from local Pi. */
+   
+   return 0;
+}
+
+

Build

+gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2 +

Run

+./read_pdif +

Python

+read_gpio.py +
+#!/usr/bin/env python
+
+import pigpio
+
+GPIO=4
+
+pi = pigpio.pi()
+if not pi.connected:
+   exit()
+
+level = pi.read(GPIO)
+
+print("GPIO {} is {}".format(GPIO, level))
+
+pi.stop()
+    
+

Run

+python read_gpio.py +

pigs

+
+pigs r 4
+    
+

pipe I/F

+
+echo "r 4" >/dev/pigpio
+cat /dev/pigout
+    
+

make fails with clock +skew

+

If make fails with one of the following messages it is probably +because the Pi's clock is wrong.

+

make: Warning: File 'xxx' has modification time x s in the +future
+make: warning: Clock skew detected. Your build may be +incomplete.

+

make uses the current time to work out which files need to be +rebuilt (a file is rebuilt if it depends on other files which have +a later time-stamp).

+

The solution is to make sure the system clock is correct.  +If the Pi is networked this will not normally be a problem.

+

To set the date and time use the date command as in the +following example.

+

sudo date -d "2017-03-01 18:47:00"

+

Porting pigpio +to another CPU/SoC

+

Sound +isn't working

+

The Pi contains two pieces of hardware, a PWM peripheral and a +PCM peripheral, to generate sound.  The PWM peripheral is +normally used and generates medium quality audio out of the +headphone jack.  The PCM peripheral may be used by add-ons +such as HATs and generates high quality audio.

+

pigpio uses at least one of these peripherals during normal +operation (for timing DMA transfers).  pigpio will use both +peripherals if waves or the hardware PWM function is used.

+

By default pigpio uses the PCM peripheral leaving the PWM +peripheral free for medium quality audio.

+

You can change the default with a configuration option.  +For C use gpioCfgClock, for the +pigpio daemon use the -t option.

+

What is I2C?

+

I2C is a data link between the Pi (master) and one or more +slaves.

+

Data may be sent and received but the Pi initiates all +transfers.

+

I2C is a medium speed link.  On the Pi the default speed is +100 kbps, but 400 kbps also works.

+

I2C is implemented as a bus with two lines called

+
    +
  • SDA - for data
  • +
  • SCL - for a clock
  • +
+On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO +3 (pin 5) for SCL.
+
+Only one slave device may be communicated with at a time.  +Each message from the Pi includes the slave to be addressed and +whether a read or write is to be performed.
+
+When the Pi (master) wishes to talk to a slave it begins by issuing +a start sequence on the I2C bus. A start sequence is one of two +special sequences defined for the I2C bus, the other being the stop +sequence. The start sequence and stop sequence are special in that +these are the only places where the SDA (data line) is allowed to +change while the SCL (clock line) is high. When data is being +transferred, SDA must remain stable and not change whilst SCL is +high. The start and stop sequences mark the beginning and end of a +transaction with the slave device.
+
+I2C start and stop sequences
+
+Data is transferred in 8-bit bytes. The bytes are placed on the SDA +line starting with the most significant bit. The SCL line is then +pulsed high, then low. For every byte transferred, the device +receiving the data sends back an acknowledge bit, so there are +actually 9 SCL clock pulses to transfer each 8-bit byte of data. If +the receiving device sends back a low ACK bit, then it has received +the data and is ready to accept another byte. If it sends back a +high then it is indicating it cannot accept any further data and +the master should terminate the transfer by sending a stop +sequence.
+
+

I2C waveform

+

What is +Serial?

+

Serial is a data link between the Pi and one other +device.

+

Data may be sent and received.  Either the Pi or the device +can initiate a transfer.

+

Serial is a low to medium speed link.  On the Pi speeds of +50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, +19200, 38400, 57600, 115200, and 230400 bps may be used.

+

Serial is implemented with one line for transmit called TXD and +one line for receive called RXD.

+

If only receive or transmit are required the other line need not +be connected.

+

The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for +RXD.

+

Data is normally transmitted in 8-bit bytes with a start bit, +eight data bits, no parity, and one stop bit.  This is +represented as 8N1.  The number of transmitted bits per second +(bps) is called the baud rate.   The time for each bit, +1 / baud rate seconds, is +referred to as the bit period.

+

The lines are in the high state when no data is being +transmitted.  The start of a byte is signalled by the line +going low for one bit period (the start bit).  The data bits +are then sent least significant bit firsts (low if the bit is 0, +high if the bit is 1).  The data bits are followed by the +optional parity bit.  Finally the line is set high for at +least the number of stop bit periods.  The line will stay high +if there are no more bytes to be transmitted.

+

Serial waveform

+

What is SPI?

+

SPI is a data link between the Pi (master) and one or more +slaves.

+

Data may be sent and received but the Pi initiates all +transfers.

+

SPI is a medium to high speed link.  On the Pi speeds of 32 +kbps to 8 Mbps may be used.

+

SPI is implemented as a bus with three lines called

+
    +
  • MOSI - for data from the Pi to the slave
  • +
  • MISO - for data from the slave to the Pi
  • +
  • SCLK - for a clock
  • +
+Only one slave device may be communicated with at a time.  An +additional line per slave called slave select is used to identify +the slave to be addressed. +

The Pi has two SPI buses

+
    +
  1. the main SPI bus +
      +
    • MOSI GPIO 10 (pin 19)
    • +
    • MISO GPIO 9 (pin 21)
    • +
    • SCLK GPIO 11 (pin 23)
    • +
    • Slave selects
    • +
    • +
        +
      • CE0 GPIO 8 (pin 24)
      • +
      • CE1 GPIO 7 (pin 26)
      • +
      +
    • +
    +
  2. +
  3. the auxiliary SPI bus +
      +
    • MOSI GPIO 20 (pin 38)
    • +
    • MISO GPIO 19 (pin 35)
    • +
    • SCLK GPIO 21 (pin 40)
    • +
    • Slave selects
    • +
    • +
        +
      • CE0 GPIO 18 (pin 12)
      • +
      • CE1 GPIO 17 (pin 11)
      • +
      • CE2 GPIO 16 (pin 36)
      • +
      +
    • +
    +
  4. +
+

SPI waveform

+


+

Which library +should I use?

+


+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/index.html b/DOC/HTML/index.html new file mode 100644 index 0000000..2606ba4 --- /dev/null +++ b/DOC/HTML/index.html @@ -0,0 +1,716 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

The pigpio library

+pigpio is a library for the Raspberry which allows control of the +General Purpose Input Outputs (GPIO).  pigpio works on all +versions of the Pi. +

At the moment pigpio on the Pi4B is experimental. I am not +sure if the DMA channels being used are safe. The Pi4B defaults are +primary channel 7, secondary channel 6. If these channels do not +work you will have to experiment. You can set the channels used by +the pigpio daemon by invoking it with the -d and -e options, e.g. +sudo pigpiod -d 5 -e 8 to specify primary 5, +secondary 8.

+

Download

+

Features

+
    +
  • +

    hardware timed sampling and time-stamping of GPIO 0-31 every 5 +us

    +
  • +
  • +

    hardware timed PWM on all of GPIO 0-31

    +
  • +
  • +

    hardware timed servo pulses on all of GPIO 0-31

    +
  • +
  • +

    callbacks on GPIO 0-31 level change (time accurate to a few +us)

    +
  • +
  • +

    notifications via pipe on GPIO 0-31 level change

    +
  • +
  • +

    callbacks at timed intervals

    +
  • +
  • +

    reading/writing all of the GPIO in a bank (0-31, 32-53) as a +single operation

    +
  • +
  • +

    GPIO reading, writing, modes, and internal pulls

    +
  • +
  • +

    socket and pipe interfaces for the bulk of the functionality

    +
  • +
  • +

    waveforms to generate GPIO level changes (time accurate to a few +us)

    +
  • +
  • +

    software serial links using any user GPIO

    +
  • +
  • +

    rudimentary permission control through the socket and pipe +interfaces

    +
  • +
  • creating and running scripts on the pigpio daemon
  • +
+

General

+The pigpio library is written in the C +programming language.
+
+The pigpio daemon offers a socket and pipe interface to +the underlying C library.
+
+A C library and a Python module allow control of the GPIO via the +pigpio daemon.
+
+There is third party support for a number of other languages.  +

piscope

+

piscope is a logic analyser (digital +waveform viewer).

+piscope is a GTK+3 application and uses pigpio to provide raw GPIO +level data.  piscope may be run on a Pi or on any machine +capable of compiling a GTK+3 application. +

GPIO

+

ALL GPIO are identified +by their Broadcom +number.  See +elinux.org

+There are 54 GPIO in total, arranged in two banks.
+

Bank 1 contains GPIO 0-31.  Bank 2 contains GPIO +32-53.

+For all types of Pi it is safe to read all the GPIO. If you try to +write a system GPIO or change its mode you can crash the Pi or +corrupt the data on the SD card.
+
+There are several types of board, each with different expansion +headers, giving physical access to different GPIO.  + +

Type 1 - Model B (original +model)

+
    +
  • 26 pin header (P1).
  • +
+
    +
  • Hardware revision numbers of 2 and 3.
  • +
+
    +
  • User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA0
34-5V
SCL1
56-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

211314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
+
+

Type 2 - Model A, B (revision +2)

+26 pin header (P1) and an additional 8 pin header (P5). +
    +
  • Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13, +14, 15 (B).
  • +
+
    +
  • User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
5V
-12-3V3
SDA
283429SCL

305631
Ground
-
78-
Ground
+
+

Type 3 - Model A+, B+, Pi +Zero, Pi Zero W, Pi2B, Pi3B, Pi4B

+
    +
  • 40 pin expansion header (J8).
  • +
+
    +
  • Hardware revision numbers of 16 or greater.
  • +
+
    +
  • User GPIO 2-27 (0 and 1 are reserved).
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
ID_SD027281ID_SC

52930-Ground

6313212

133334-Ground
miso19353616ce2

26373820mosi
Ground-394021sclk
+
+

Compute Module

+

All 54 GPIO may be physically accessed.  Some are reserved +for system use - refer to the Compute Module documentation.

+

Only GPIO 0-31 are supported for hardware timed sampling, PWM, +servo pulses, alert callbacks, waves, and software serial +links.

+

Other +Languages

+

There are several third party projects which provide wrappers +for pigpio.

+

Some I am aware of are:

+
    +
  • Erlang +(skvamme)
  • +
  • Java JNI +wrapper around the pigpio C library (mattlewis)
  • +
  • Java via +diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc +(mattlewis)
  • +
  • Java +(nkolban)
  • +
  • .NET/mono +(unosquare)
  • +
  • Node.js +(fivdi)
  • +
  • Perl (Gligan +Calin Horea)
  • +
  • Ruby +(Nak)
  • +
  • Smalltalk(Instantiations)
  • +
  • Xojo(UBogun)
  • +
+
+

The PWM and servo pulses are timed using the DMA +and PWM/PCM peripherals.  This use was inspired by Richard +Hirst's servoblaster kernel module.

+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/misc.html b/DOC/HTML/misc.html new file mode 100644 index 0000000..a6179f4 --- /dev/null +++ b/DOC/HTML/misc.html @@ -0,0 +1,88 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Miscellaneous

+There are two C libraries which provide a socket interface to the +pigpio daemon.  They provide an interface very similar to the +pigpio Python module.
+
    +
  • The original pigpiod_if library is +now deprecated and will no longer be updated.  This library is +limited to controlling one Pi at a time.
  • +
+
    +
  • The new pigpiod_if2 library which +should be used for new code.  This library allows multiple Pis +to be controlled at one time.
  • +
+Additional details of the pigpio socket +interface.
+
+Additional details of the pigpio pipe +interface.
+
+pig2vcd is a utility which converts +pigpio notifications into the VCD (Value Change Dump) format.  +VCD can be read by many programs, in particular GTKWave. +
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/pdif.html b/DOC/HTML/pdif.html new file mode 100644 index 0000000..8084e94 --- /dev/null +++ b/DOC/HTML/pdif.html @@ -0,0 +1,1168 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

pigpiod_if



THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO +USE THE MORE VERSATILE pigpiod_if2 LIBRARY. +

pigpiod_if is a C library for the Raspberry which allows control +of the GPIO via the socket interface to the pigpio daemon.
+

Features

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o callbacks when any of GPIO 0-31 change state +

o callbacks at timed intervals +

o reading/writing all of the GPIO in a bank as one operation +

o individually setting GPIO modes, reading and writing +

o notifications when any of GPIO 0-31 change state +

o the construction of output waveforms with microsecond timing +

o rudimentary permission control over GPIO +

o a simple interface to start and stop new threads +

o I2C, SPI, and serial link wrappers +

o creating and running scripts on the pigpio daemon +

GPIO

ALL GPIO are identified by their Broadcom number. +

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. +

Usage

Include <pigpiod_if.h> in your source files. +

Assuming your source is in prog.c use the following command to build +

gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt


to run make sure the pigpio daemon is running +

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if


For examples see x_pigpiod_if.c within the pigpio archive file. +

Notes

All the functions which return an int return < 0 on error +

OVERVIEW

ESSENTIAL +
pigpio_start Connects to the pigpio daemon +
pigpio_stop Disconnects from the pigpio daemon +
BEGINNER +
set_mode Set a GPIO mode +
get_mode Get a GPIO mode +
set_pull_up_down Set/clear GPIO pull up/down resistor +
gpio_read Read a GPIO +
gpio_write Write a GPIO +
set_PWM_dutycycle Start/stop PWM pulses on a GPIO +
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +
set_servo_pulsewidth Start/stop servo pulses on a GPIO +
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO +
callback Create GPIO level change callback +
callback_ex Create GPIO level change callback +
callback_cancel Cancel a callback +
wait_for_edge Wait for GPIO level change +
INTERMEDIATE +
gpio_trigger Send a trigger pulse to a GPIO. +
set_watchdog Set a watchdog on a GPIO. +
set_PWM_range Configure PWM range for a GPIO +
get_PWM_range Get configured PWM range for a GPIO +
set_PWM_frequency Configure PWM frequency for a GPIO +
get_PWM_frequency Get configured PWM frequency for a GPIO +
read_bank_1 Read all GPIO in bank 1 +
read_bank_2 Read all GPIO in bank 2 +
clear_bank_1 Clear selected GPIO in bank 1 +
clear_bank_2 Clear selected GPIO in bank 2 +
set_bank_1 Set selected GPIO in bank 1 +
set_bank_2 Set selected GPIO in bank 2 +
start_thread Start a new thread +
stop_thread Stop a previously started thread +
ADVANCED +
get_PWM_real_range Get underlying PWM range for a GPIO +
notify_open Request a notification handle +
notify_begin Start notifications for selected GPIO +
notify_pause Pause notifications +
notify_close Close a notification +
bb_serial_read_open Opens a GPIO for bit bang serial reads +
bb_serial_read Reads bit bang serial data from a GPIO +
bb_serial_read_close Closes a GPIO for bit bang serial reads +
bb_serial_invert Invert serial logic (1 invert, 0 normal) +
hardware_clock Start hardware clock on supported GPIO +
hardware_PWM Start hardware PWM on supported GPIO +
set_glitch_filter Set a glitch filter on a GPIO +
set_noise_filter Set a noise filter on a GPIO +
SCRIPTS +
store_script Store a script +
run_script Run a stored script +
script_status Get script status and parameters +
stop_script Stop a running script +
delete_script Delete a stored script +
WAVES +
wave_clear Deletes all waveforms +
wave_add_new Starts a new waveform +
wave_add_generic Adds a series of pulses to the waveform +
wave_add_serial Adds serial data to the waveform +
wave_create Creates a waveform from added data +
wave_delete Deletes one or more waveforms +
wave_send_once Transmits a waveform once +
wave_send_repeat Transmits a waveform repeatedly +
wave_chain Transmits a chain of waveforms +
wave_tx_busy Checks to see if the waveform has ended +
wave_tx_stop Aborts the current waveform +
wave_get_micros Length in microseconds of the current waveform +
wave_get_high_micros Length of longest waveform so far +
wave_get_max_micros Absolute maximum allowed micros +
wave_get_pulses Length in pulses of the current waveform +
wave_get_high_pulses Length of longest waveform so far +
wave_get_max_pulses Absolute maximum allowed pulses +
wave_get_cbs Length in cbs of the current waveform +
wave_get_high_cbs Length of longest waveform so far +
wave_get_max_cbs Absolute maximum allowed cbs +
I2C +
i2c_open Opens an I2C device +
i2c_close Closes an I2C device +
i2c_write_quick smbus write quick +
i2c_write_byte smbus write byte +
i2c_read_byte smbus read byte +
i2c_write_byte_data smbus write byte data +
i2c_write_word_data smbus write word data +
i2c_read_byte_data smbus read byte data +
i2c_read_word_data smbus read word data +
i2c_process_call smbus process call +
i2c_write_block_data smbus write block data +
i2c_read_block_data smbus read block data +
i2c_block_process_call smbus block process call +
i2c_write_i2c_block_data smbus write I2C block data +
i2c_read_i2c_block_data smbus read I2C block data +
i2c_read_device Reads the raw I2C device +
i2c_write_device Writes the raw I2C device +
i2c_zip Performs multiple I2C transactions +
bb_i2c_open Opens GPIO for bit banging I2C +
bb_i2c_close Closes GPIO for bit banging I2C +
bb_i2c_zip Performs multiple bit banged I2C transactions +
SPI +
spi_open Opens a SPI device +
spi_close Closes a SPI device +
spi_read Reads bytes from a SPI device +
spi_write Writes bytes to a SPI device +
spi_xfer Transfers bytes with a SPI device +
SERIAL +
serial_open Opens a serial device +
serial_close Closes a serial device +
serial_write_byte Writes a byte to a serial device +
serial_read_byte Reads a byte from a serial device +
serial_write Writes bytes to a serial device +
serial_read Reads bytes from a serial device +
serial_data_available Returns number of bytes ready to be read +
CUSTOM +
custom_1 User custom function 1 +
custom_2 User custom function 2 +
UTILITIES +
get_current_tick Get current tick (microseconds) +
get_hardware_revision Get hardware revision +
get_pigpio_version Get the pigpio version +
pigpiod_if_version Get the pigpiod_if version +
pigpio_error Get a text description of an error code. +
time_sleep Sleeps for a float number of seconds +
time_time Float number of seconds since the epoch +

FUNCTIONS

double time_time(void)

+Return the current time in seconds since the Epoch. +

void time_sleep(double seconds)

+Delay execution for a given number of seconds. +

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

+Return a text description for an error code. +

errnum: the error code.

unsigned pigpiod_if_version(void)

+Return the pigpiod_if version. +

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

+Starts a new thread of execution with thread_func as the main routine. +

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. +

The function is passed the single argument userdata. +

The thread can be cancelled by passing the pointer to pthread_t to +stop_thread. +

void stop_thread(pthread_t *pth)

+Cancels the thread pointed at by pth. +

pth: the thread to be stopped.


No value is returned. +

The thread to be stopped should have been started with start_thread. +

int pigpio_start(char *addrStr, char *portStr)

+Connect to the pigpio daemon. Reserving command and +notification streams. +

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.

void pigpio_stop(void)

+Terminates the connection to the pigpio daemon and releases +resources used by the library. +

int set_mode(unsigned gpio, unsigned mode)

+Set the GPIO mode. +

gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, +or PI_NOT_PERMITTED. +

int get_mode(unsigned gpio)

+Get the GPIO mode. +

gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. +

int set_pull_up_down(unsigned gpio, unsigned pud)

+Set or clear the GPIO pull-up/down resistor. +

gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, +or PI_NOT_PERMITTED. +

int gpio_read(unsigned gpio)

+Read the GPIO level. +

gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. +

int gpio_write(unsigned gpio, unsigned level)

+Write the GPIO level. +

 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, +or PI_NOT_PERMITTED. +

Notes +

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

int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)

+Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. +

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


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, +or PI_NOT_PERMITTED. +Notes +

The set_PWM_range function may be used to change the +default range of 255. +

int get_PWM_dutycycle(unsigned user_gpio)

+Return the PWM dutycycle in use on a GPIO. +

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. +

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

If a hardware clock is active on the GPIO the reported dutycycle +will be 500000 (500k) out of 1000000 (1M). +

If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). +

int set_PWM_range(unsigned user_gpio, unsigned range)

+Set the range of PWM values to be used on the GPIO. +

user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, +or PI_NOT_PERMITTED. +

Notes +

If PWM is currently active on the GPIO its dutycycle will be +scaled to reflect the new range. +

The real range, the number of steps between fully off and fully on +for each of the 18 available GPIO frequencies is +

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


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

int get_PWM_range(unsigned user_gpio)

+Get the range of PWM values being used on the GPIO. +

user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

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

int get_PWM_real_range(unsigned user_gpio)

+Get the real underlying range of PWM values being used on the GPIO. +

user_gpio: 0-31.


Returns the real range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

int set_PWM_frequency(unsigned user_gpio, unsigned frequency)

+Set the frequency (in Hz) of the PWM to be used on the GPIO. +

user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PERMITTED. +

If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. +

Each GPIO can be independently set to one of 18 different +PWM frequencies. +

The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. +

The frequencies for each sample rate are: +

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(unsigned user_gpio)

+Get the frequency of PWM being used on the GPIO. +

user_gpio: 0-31.


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

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

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

Returns the frequency (in hertz) used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)

+Start (500-2500) or stop (0) servo pulses on the GPIO. +

 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or +PI_NOT_PERMITTED. +

The selected pulsewidth will continue to be transmitted until +changed by a subsequent call to set_servo_pulsewidth. +

The pulsewidths supported by servos varies and should probably be +determined by experiment. A value of 1500 should always be safe and +represents the mid-point of rotation. +

You can DAMAGE a servo if you command it to move beyond its limits. +

OTHER UPDATE RATES: +

This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. +

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. +

Then set the PWM range using set_PWM_range to 1E6/Hz. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. +

E.g. If you want to update a servo connected to GPIO 25 at 400Hz +

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, +e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
+

int get_servo_pulsewidth(unsigned user_gpio)

+Return the servo pulsewidth in use on a GPIO. +

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. +

int notify_open(void)

+Get a free notification handle. +

Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. +

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

Pipes are only accessible from the local machine so this function +serves no purpose if you are using the library from a remote machine. +The in-built (socket) notifications provided by callback +should be used instead. +

Notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). +E.g. if the function returns 15 then the notifications must be +read from /dev/pigpio15. +

int notify_begin(unsigned handle, uint32_t bits)

+Start notifications on a previously opened handle. +

handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

The notification sends state changes for each GPIO whose +corresponding bit in bits is set. +

Each notification occupies 12 bytes in the fifo as follows: +

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. +

PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. +

PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. +

tick: the number of microseconds since system boot. It wraps around +after 1h12m. +

level: indicates the level of each GPIO. If bit 1<<x is set then +GPIO x is high. +

int notify_pause(unsigned handle)

+Pause notifications on a previously opened handle. +

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Notifications for the handle are suspended until +notify_begin is called again. +

int notify_close(unsigned handle)

+Stop notifications on a previously opened handle and +release the handle for reuse. +

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int set_watchdog(unsigned user_gpio, unsigned timeout)

+Sets a watchdog for a GPIO. +

user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO +or PI_BAD_WDOG_TIMEOUT. +

The watchdog is nominally in milliseconds. +

Only one watchdog may be registered per GPIO. +

The watchdog may be cancelled by setting timeout to 0. +

Once a watchdog has been started callbacks for the GPIO will be +triggered every timeout interval after the last GPIO activity. +

The callback will receive the special level PI_TIMEOUT. +

int set_glitch_filter(unsigned user_gpio, unsigned steady)

+Sets a glitch filter on a GPIO. +

Level changes on the GPIO are not reported unless the level +has been stable for at least steady microseconds. The +level is then reported. Level changes of less than steady +microseconds are ignored. +

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback, callback_ex and wait_for_edge. +

It does not affect levels read by gpio_read, +read_bank_1, or read_bank_2. +Each (stable) edge will be timestamped steady microseconds +after it was first detected. +

int set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active)

+Sets a noise filter on a GPIO. +

Level changes on the GPIO are ignored until a level which has +been stable for steady microseconds is detected. Level changes +on the GPIO are then reported for active microseconds after +which the process repeats. +

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback, callback_ex and wait_for_edge. +

It does not affect levels read by gpio_read, +read_bank_1, or read_bank_2. +

Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

uint32_t read_bank_1(void)

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

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

uint32_t read_bank_2(void)

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

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

int clear_bank_1(uint32_t bits)

+Clears GPIO 0-31 if the corresponding bit in bits is set. +

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int clear_bank_2(uint32_t bits)

+Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int set_bank_1(uint32_t bits)

+Sets GPIO 0-31 if the corresponding bit in bits is set. +

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int set_bank_2(uint32_t bits)

+Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int hardware_clock(unsigned gpio, unsigned clkfreq)

+Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. +

     gpio: see description
frequency: 0 (off) or 4689-250000000 (250M)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. +

The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. +

The GPIO must be one of the following. +

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely +crash the Pi. The password is given by or'ing 0x5A000000 with the +GPIO number. +

int hardware_PWM(unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

+Starts hardware PWM on a GPIO at the specified frequency and dutycycle. +Frequencies above 30MHz are unlikely to work. +

NOTE: Any waveform started by wave_send_once, wave_send_repeat, +or wave_chain will be cancelled. +

This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). +

   gpio: see descripton
PWMfreq: 0 (off) or 1-125000000 (125M)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, +or PI_HPWM_ILLEGAL. +

The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. +

The GPIO must be one of the following. +

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only

uint32_t get_current_tick(void)

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

uint32_t get_hardware_revision(void)

+Get the Pi's hardware revision number. +

The hardware revision is the last few characters on the Revision line +of /proc/cpuinfo. +

If the hardware revision can not be found or is not a valid +hexadecimal number the function returns 0. +

The revision number can be used to determine the assignment of GPIO +to pins (see gpio). +

There are at least three types of board. +

Type 1 boards have hardware revision numbers of 2 and 3. +

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. +

Type 3 boards have hardware revision numbers of 16 or greater. +

uint32_t get_pigpio_version(void)

+Returns the pigpio version. +

int wave_clear(void)

+This function clears all waveforms and any data added by calls to the +wave_add_* functions. +

Returns 0 if OK. +

int wave_add_new(void)

+This function starts a new empty waveform. You wouldn't normally need +to call this function as it is automatically called after a waveform is +created with the wave_create function. +

Returns 0 if OK. +

int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)

+This function adds a number of pulses to the current waveform. +

numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. +

The pulses are interleaved in time order within the existing waveform +(if any). +

Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist solely of a delay. +

int wave_add_serial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

+This function adds a waveform representing serial data to the +existing waveform (if any). The serial data starts offset +microseconds from the start of the waveform. +

user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. +

NOTES: +

The serial data is formatted as one start bit, data_bits data bits, +and stop_bits/2 stop bits. +

It is legal to add serial data streams with different baud rates to +the same waveform. +

numBytes is the number of bytes of data in str. +

The bytes required for each character depend upon data_bits. +

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

int wave_create(void)

+This function creates a waveform from the data provided by the prior +calls to the wave_add_* functions. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

The data provided by the wave_add_* functions is consumed by this +function. +

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

Normal usage would be +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create to create the waveform and get a unique id +

Repeat steps 2 and 3 as needed. +

Step 4. wave_send_* with the id of the waveform to transmit. +

A waveform comprises one or more pulses. Each pulse consists of a +gpioPulse_t structure. +

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify +

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +

int wave_delete(unsigned wave_id)

+This function deletes the waveform with id wave_id. +

wave_id: >=0, as returned by wave_create.


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

The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. +

- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. +

- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). +

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. +

int wave_send_once(unsigned wave_id)

+This function transmits the waveform with id wave_id. The waveform +is sent once. +

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

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_send_repeat(unsigned wave_id)

+This function transmits the waveform with id wave_id. The waveform +cycles until cancelled (either by the sending of a new waveform or +by wave_tx_stop). +

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

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_chain(char *buf, unsigned bufSize)

+This function transmits a chain of waveforms. +

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

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

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. +

Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. +

A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. +

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (pigpio_start(0, 0)<0) return -1;

   set_mode(GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create();
   }

   wave_chain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(wid[i]);

   pigpio_stop();
}

int wave_tx_busy(void)

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

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

int wave_tx_stop(void)

+This function stops the transmission of the current waveform. +

Returns 0 if OK. +

This function is intended to stop a waveform started with the repeat mode. +

int wave_get_micros(void)

+This function returns the length in microseconds of the current +waveform. +

int wave_get_high_micros(void)

+This function returns the length in microseconds of the longest waveform +created since the pigpio daemon was started. +

int wave_get_max_micros(void)

+This function returns the maximum possible size of a waveform in
+microseconds. +

int wave_get_pulses(void)

+This function returns the length in pulses of the current waveform. +

int wave_get_high_pulses(void)

+This function returns the length in pulses of the longest waveform +created since the pigpio daemon was started. +

int wave_get_max_pulses(void)

+This function returns the maximum possible size of a waveform in pulses. +

int wave_get_cbs(void)

+This function returns the length in DMA control blocks of the current +waveform. +

int wave_get_high_cbs(void)

+This function returns the length in DMA control blocks of the longest +waveform created since the pigpio daemon was started. +

int wave_get_max_cbs(void)

+This function returns the maximum possible size of a waveform in DMA +control blocks. +

int gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

+This function sends a trigger pulse to a GPIO. The GPIO is set to +level for pulseLen microseconds and then reset to not level. +

user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, +PI_BAD_PULSELEN, or PI_NOT_PERMITTED. +

int store_script(char *script)

+This function stores a script for later execution. +

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. +

script: the text of the script.


The function returns a script id if the script is valid, +otherwise PI_BAD_SCRIPT. +

int run_script(unsigned script_id, unsigned numPar, uint32_t *param)

+This function runs a stored script. +

script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int script_status(unsigned script_id, uint32_t *param)

+This function returns the run status of a stored script as well +as the current values of parameters 0 to 9. +

script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. +

The run status may be +

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. +

int stop_script(unsigned script_id)

+This function stops a running script. +

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int delete_script(unsigned script_id)

+This function deletes a stored script. +

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)

+This function opens a GPIO for bit bang reading of serial data. +

user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, +or PI_GPIO_IN_USE. +

The serial data is returned in a cyclic buffer and is read using +bb_serial_read. +

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

int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)

+This function copies up to bufSize bytes of data read from the +bit bang serial cyclic buffer to the buffer starting at buf. +

user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. +

The bytes returned for each character depend upon the number of +data bits data_bits specified in the bb_serial_read_open command. +

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

int bb_serial_read_close(unsigned user_gpio)

+This function closes a GPIO for bit bang reading of serial data. +

user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. +

int bb_serial_invert(unsigned user_gpio, unsigned invert)

+This function inverts serial logic for big bang serial reads. +

user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. +

int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

+This returns a handle for the device at address i2c_addr on bus i2c_bus. +

  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. +

Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. +

For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. +

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.

Addr  (7 bits): I2C 7 bit address.
Comm  (8 bits): Command byte, a data byte which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A data byte containing the length of a block operation.

[..]: Data sent by the device.

int i2c_close(unsigned handle)

+This closes the I2C device associated with the handle. +

handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int i2c_write_quick(unsigned handle, unsigned bit)

+This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. +

handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Quick command. SMBus 2.0 5.5.1 +S Addr Rd/Wr [A] P

int i2c_write_byte(unsigned handle, unsigned bVal)

+This sends a single byte to the device associated with handle. +

handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Send byte. SMBus 2.0 5.5.2 +S Addr Wr [A] Data [A] P

int i2c_read_byte(unsigned handle)

+This reads a single byte from the device associated with handle. +

handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. +

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

int i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)

+This writes a single byte to the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write byte. SMBus 2.0 5.5.4 +S Addr Wr [A] Comm [A] Data [A] P

int i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)

+This writes a single 16 bit word to the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write word. SMBus 2.0 5.5.4 +S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P

int i2c_read_byte_data(unsigned handle, unsigned i2c_reg)

+This reads a single byte from the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read byte. SMBus 2.0 5.5.5 +S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(unsigned handle, unsigned i2c_reg)

+This reads a single 16 bit word from the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read word. SMBus 2.0 5.5.5 +S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)

+This writes 16 bits of data to the specified register of the device +associated with handle and and reads 16 bits of data in return. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Process call. SMBus 2.0 5.5.6 +S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes up to 32 bytes to the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Block write. SMBus 2.0 5.5.7 +S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)

+This reads a block of up to 32 bytes from the specified register of +the device associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. +

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Block read. SMBus 2.0 5.5.7 +S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

int i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

The smbus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. +

Block write-block read. SMBus 2.0 5.5.8 +S Addr Wr [A] Comm [A] Count [A] Data [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

int i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes 1 to 32 bytes to the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_device(unsigned handle, char *buf, unsigned count)

+This reads count bytes from the raw device into buf. +

handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. +

int i2c_write_device(unsigned handle, char *buf, unsigned count)

+This writes count bytes from buf to the raw device. +

handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

int i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)

+This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. +

Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. +

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

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. +

NOTE: +

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. +

int bb_i2c_close(unsigned SDA)

+This function stops bit banging I2C on a pair of GPIO previously +opened with bb_i2c_open. +

SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +

int bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)

+This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. +

spi_flags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. +

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. +

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 spi_read, spi_write, and spi_xfer functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. +

For bits 1-8 there will be one byte per word.
+For bits 9-16 there will be two bytes per word.
+For bits 17-32 there will be four bytes per word. +

Multi-byte transfers are made in least significant byte first order. +

E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. +

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

int spi_close(unsigned handle)

+This functions closes the SPI device identified by the handle. +

handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int spi_read(unsigned handle, char *buf, unsigned count)

+This function reads count bytes of data from the SPI +device associated with the handle. +

handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spi_write(unsigned handle, char *buf, unsigned count)

+This function writes count bytes of data from buf to the SPI +device associated with the handle. +

handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

+This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. +

handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)

+This function opens a serial device at a specified baud rate +with specified flags. The device name must start with +/dev/tty or /dev/serial. +

  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. +

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

No flags are currently defined. This parameter should be set to zero. +

int serial_close(unsigned handle)

+This function closes the serial device associated with handle. +

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int serial_write_byte(unsigned handle, unsigned bVal)

+This function writes bVal to the serial port associated with handle. +

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serial_read_byte(unsigned handle)

+This function reads a byte from the serial port associated with handle. +

handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. +

If no data is ready PI_SER_READ_NO_DATA is returned. +

int serial_write(unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the serial port +associated with handle. +

handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serial_read(unsigned handle, char *buf, unsigned count)

+This function reads up to count bytes from the the serial port +associated with handle and writes them to buf. +

handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. +

If no data is ready zero is returned. +

int serial_data_available(unsigned handle)

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

handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. +

int custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

+This function is available for user customisation. +

It returns a single integer value. +

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. +

int custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

+This function is available for user customisation. +

It differs from custom_1 in that it returns an array of bytes +rather than just an integer. +

The return value is an integer indicating the number of returned bytes. +  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. +

Note, the number of returned bytes will be retMax or less. +

int callback(unsigned user_gpio, unsigned edge, CBFunc_t f)

+This function initialises a new callback. +

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the GPIO, edge, and tick, whenever the +GPIO has the identified edge. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

int callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

+This function initialises a new callback. +

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the GPIO, edge, tick, and user, whenever +the GPIO has the identified edge. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

+This function cancels a callback identified by its id. +

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. +

int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)

+This function waits for edge on the GPIO for up to timeout +seconds. +

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns 1 if the edge occurred, otherwise 0. +

The function returns when the edge occurs or after the timeout. +

PARAMETERS

active: 0-1000000

+The number of microseconds level changes are reported for once +a noise filter has been triggered (by steady microseconds of +a stable level). +

*addrStr

+A string specifying the host or IP address of the Pi running +the pigpio daemon. It may be NULL in which case localhost +is used unless overridden by the PIGPIO_ADDR environment +variable. +

arg1

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

arg2

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

argc

+The count of bytes passed to a user customised function. +

*argx

+A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. +

baud

+The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. +

bit

+A value of 0 or 1. +

bits

+A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. +

A convenient way to set bit n is to or in (1<<n). +

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). +

*buf

+A buffer to hold data being sent or being received. +

bufSize

+The size in bytes of a buffer. +

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

+An 8-bit byte value. +

callback_id

+A >=0, as returned by a call to callback or callback_ex. This is +passed to callback_cancel to cancel the callback. +

CBFunc_t

+typedef void (*CBFunc_t)
   (unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

+typedef void (*CBFuncEx_t)
   (unsigned user_gpio, unsigned level, uint32_t tick, void * user);

char

+A single character, an 8 bit quantity able to store 0-255. +

clkfreq: 4689-250000000 (250M)

+The hardware clock frequency. +

count

+The number of bytes to be transferred in an I2C, SPI, or Serial +command. +

data_bits: 1-32

+The number of data bits in each character of serial data. +

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

+A floating point number. +

dutycycle: 0-range

+A number representing the ratio of on time to off time for PWM. +

The number may vary between 0 and range (default 255) where +0 is off and range is fully on. +

edge

+Used to identify a GPIO level transition of interest. A rising edge is +a level change from 0 to 1. A falling edge is a level change from 1 to 0. +

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

+A negative number indicating a function call failed and the nature +of the error. +

f

+A function. +

frequency: >=0

+The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. +

gpio

+A Broadcom numbered GPIO, in the range 0-53. +

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

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

gpioPulse_t

+typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

+typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

+A number referencing an object opened by one of i2c_open, notify_open, +serial_open, and spi_open. +

i2c_addr: 0-0x7F

+The address of a device on the I2C bus. +

i2c_bus: >=0

+An I2C bus number. +

i2c_flags: 0

+Flags which modify an I2C open command. None are currently defined. +

i2c_reg: 0-255

+A register of an I2C device. +

*inBuf

+A buffer used to pass data to a function. +

inLen

+The number of bytes of data in a buffer. +

int

+A whole number, negative or positive. +

invert

+A flag used to set normal or inverted bit bang serial data level logic. +

level

+The level of a GPIO. Low or High. +

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See set_watchdog. +

PI_TIMEOUT 2

mode: 0-7

+The operational mode of a GPIO, normally INPUT or OUTPUT. +

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2

numBytes

+The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. +

numPar: 0-10

+The number of parameters passed to a script. +

numPulses

+The number of pulses to be added to a waveform. +

offset

+The associated data starts this number of microseconds from the start of +the waveform. +

*outBuf

+A buffer used to return data from a function. +

outLen

+The size in bytes of an output buffer. +

*param

+An array of script parameters. +

*portStr

+A string specifying the port address used by the Pi running +the pigpio daemon. It may be NULL in which case "8888" +is used unless overridden by the PIGPIO_PORT environment +variable. +

*pth

+A thread identifier, returned by start_thread. +

pthread_t

+A thread identifier. +

pud: 0-2

+The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. +PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

+1-100, the length of a trigger pulse in microseconds. +

*pulses

+An array of pulses to be added to a waveform. +

pulsewidth: 0, 500-2500

+PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

+The hardware PWM dutycycle. +

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125000000 (125M)

+The hardware PWM frequency. +

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000

range: 25-40000

+The permissible dutycycle values are 0-range. +PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

+A buffer to hold a number of bytes returned to a used customised function, +

retMax

+The maximum number of bytes a user customised function should return. +

*rxBuf

+A pointer to a buffer to receive data. +

SCL

+The user GPIO to use for the clock when bit banging I2C. +

*script

+A pointer to the text of a script. +

script_id

+An id of a stored script as returned by store_script. +

SDA

+The user GPIO to use for data when bit banging I2C. +

seconds

+The number of seconds. +

ser_flags

+Flags which modify a serial open command. None are currently defined. +

*ser_tty

+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. +

size_t

+A standard type used to indicate the size of an object in bytes. +

spi_channel

+A SPI channel, 0-2. +

spi_flags

+See spi_open. +

steady: 0-300000

+The number of microseconds level changes must be stable for +before reporting the level changed (set_glitch_filter) or triggering +the active part of a noise filter (set_noise_filter). +

stop_bits: 2-8

+The number of (half) stop bits to be used when adding serial data +to a waveform. +

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

+ An array of characters. +

thread_func

+A function of type gpioThreadFunc_t used as the main function of a +thread. +

timeout

+A GPIO watchdog timeout in milliseconds. +PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

+An array of bytes to transmit. +

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

+A 32-bit unsigned value. +

unsigned

+A whole number >= 0. +

user_gpio

+0-31, a Broadcom numbered GPIO. +

See gpio. +

*userdata

+A pointer to arbitrary user data. This may be used to identify the instance. +

void

+Denoting no parameter is required +

wave_add_*

+One of wave_add_new, wave_add_generic, wave_add_serial. +

wave_id

+A number representing a waveform created by wave_create. +

wave_send_*

+One of wave_send_once, wave_send_repeat. +

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

+A 16-bit word value. +

pigpiod_if Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
} pigifError_t;

+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/pdif2.html b/DOC/HTML/pdif2.html new file mode 100644 index 0000000..fad8bdb --- /dev/null +++ b/DOC/HTML/pdif2.html @@ -0,0 +1,1523 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

pigpiod C Interface



pigpiod_if2 is a C library for the Raspberry which allows control +of the GPIO via the socket interface to the pigpio daemon.
+

Features

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o callbacks when any of GPIO 0-31 change state +

o callbacks at timed intervals +

o reading/writing all of the GPIO in a bank as one operation +

o individually setting GPIO modes, reading and writing +

o notifications when any of GPIO 0-31 change state +

o the construction of output waveforms with microsecond timing +

o rudimentary permission control over GPIO +

o a simple interface to start and stop new threads +

o I2C, SPI, and serial link wrappers +

o creating and running scripts on the pigpio daemon +

GPIO

ALL GPIO are identified by their Broadcom number. +

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. +

Usage

Include <pigpiod_if2.h> in your source files. +

Assuming your source is in prog.c use the following command to build +

gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt


to run make sure the pigpio daemon is running +

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if2


For examples see x_pigpiod_if2.c within the pigpio archive file. +

Notes

All the functions which return an int return < 0 on error +

OVERVIEW

ESSENTIAL +
pigpio_start Connects to a pigpio daemon +
pigpio_stop Disconnects from a pigpio daemon +
BASIC +
set_mode Set a GPIO mode +
get_mode Get a GPIO mode +
set_pull_up_down Set/clear GPIO pull up/down resistor +
gpio_read Read a GPIO +
gpio_write Write a GPIO +
PWM (overrides servo commands on same GPIO) +
set_PWM_dutycycle Start/stop PWM pulses on a GPIO +
set_PWM_frequency Configure PWM frequency for a GPIO +
set_PWM_range Configure PWM range for a GPIO +
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +
get_PWM_frequency Get configured PWM frequency for a GPIO +
get_PWM_range Get configured PWM range for a GPIO +
get_PWM_real_range Get underlying PWM range for a GPIO +
Servo (overrides PWM commands on same GPIO) +
set_servo_pulsewidth Start/stop servo pulses on a GPIO +
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO +
INTERMEDIATE +
gpio_trigger Send a trigger pulse to a GPIO. +
set_watchdog Set a watchdog on a GPIO. +
read_bank_1 Read all GPIO in bank 1 +
read_bank_2 Read all GPIO in bank 2 +
clear_bank_1 Clear selected GPIO in bank 1 +
clear_bank_2 Clear selected GPIO in bank 2 +
set_bank_1 Set selected GPIO in bank 1 +
set_bank_2 Set selected GPIO in bank 2 +
callback Create GPIO level change callback +
callback_ex Create GPIO level change callback, extended +
callback_cancel Cancel a callback +
wait_for_edge Wait for GPIO level change +
start_thread Start a new thread +
stop_thread Stop a previously started thread +
ADVANCED +
notify_open Request a notification handle +
notify_begin Start notifications for selected GPIO +
notify_pause Pause notifications +
notify_close Close a notification +
hardware_clock Start hardware clock on supported GPIO +
hardware_PWM Start hardware PWM on supported GPIO +
set_glitch_filter Set a glitch filter on a GPIO +
set_noise_filter Set a noise filter on a GPIO +
set_pad_strength Sets a pads drive strength +
get_pad_strength Gets a pads drive strength +
shell_ Executes a shell command +
Custom +
custom_1 User custom function 1 +
custom_2 User custom function 2 +
Events +
event_callback Sets a callback for an event +
event_callback_ex Sets a callback for an event, extended +
event_callback_cancel Cancel an event callback +
event_trigger Triggers an event +
wait_for_event Wait for an event +
Scripts +
store_script Store a script +
run_script Run a stored script +
update_script Set a scripts parameters +
script_status Get script status and parameters +
stop_script Stop a running script +
delete_script Delete a stored script +
I2C +
i2c_open Opens an I2C device +
i2c_close Closes an I2C device +
i2c_write_quick smbus write quick +
i2c_read_byte smbus read byte +
i2c_write_byte smbus write byte +
i2c_read_byte_data smbus read byte data +
i2c_write_byte_data smbus write byte data +
i2c_read_word_data smbus read word data +
i2c_write_word_data smbus write word data +
i2c_read_block_data smbus read block data +
i2c_write_block_data smbus write block data +
i2c_read_i2c_block_data smbus read I2C block data +
i2c_write_i2c_block_data smbus write I2C block data +
i2c_read_device Reads the raw I2C device +
i2c_write_device Writes the raw I2C device +
i2c_process_call smbus process call +
i2c_block_process_call smbus block process call +
i2c_zip Performs multiple I2C transactions +
I2C BIT BANG +
bb_i2c_open Opens GPIO for bit banging I2C +
bb_i2c_close Closes GPIO for bit banging I2C +
bb_i2c_zip Performs bit banged I2C transactions +
I2C/SPI SLAVE +
bsc_xfer I2C/SPI as slave transfer +
bsc_i2c I2C as slave transfer +
SERIAL +
serial_open Opens a serial device +
serial_close Closes a serial device +
serial_read_byte Reads a byte from a serial device +
serial_write_byte Writes a byte to a serial device +
serial_read Reads bytes from a serial device +
serial_write Writes bytes to a serial device +
serial_data_available Returns number of bytes ready to be read +
SERIAL BIT BANG (read only) +
bb_serial_read_open Opens a GPIO for bit bang serial reads +
bb_serial_read_close Closes a GPIO for bit bang serial reads +
bb_serial_invert Invert serial logic (1 invert, 0 normal) +
bb_serial_read Reads bit bang serial data from a GPIO +
SPI +
spi_open Opens a SPI device +
spi_close Closes a SPI device +
spi_read Reads bytes from a SPI device +
spi_write Writes bytes to a SPI device +
spi_xfer Transfers bytes with a SPI device +
SPI BIT BANG +
bb_spi_open Opens GPIO for bit banging SPI +
bb_spi_close Closes GPIO for bit banging SPI +
bb_spi_xfer Transfers bytes with bit banging SPI +
FILES +
file_open Opens a file +
file_close Closes a file +
file_read Reads bytes from a file +
file_write Writes bytes to a file +
file_seek Seeks to a position within a file +
file_list List files which match a pattern +
WAVES +
wave_clear Deletes all waveforms +
wave_add_new Starts a new waveform +
wave_add_generic Adds a series of pulses to the waveform +
wave_add_serial Adds serial data to the waveform +
wave_create Creates a waveform from added data +
wave_create_and_pad Creates a waveform of fixed size from added data +
wave_delete Deletes one or more waveforms +
wave_send_once Transmits a waveform once +
wave_send_repeat Transmits a waveform repeatedly +
wave_send_using_mode Transmits a waveform in the chosen mode +
wave_chain Transmits a chain of waveforms +
wave_tx_at Returns the current transmitting waveform +
wave_tx_busy Checks to see if the waveform has ended +
wave_tx_stop Aborts the current waveform +
wave_get_cbs Length in cbs of the current waveform +
wave_get_high_cbs Length of longest waveform so far +
wave_get_max_cbs Absolute maximum allowed cbs +
wave_get_micros Length in micros of the current waveform +
wave_get_high_micros Length of longest waveform so far +
wave_get_max_micros Absolute maximum allowed micros +
wave_get_pulses Length in pulses of the current waveform +
wave_get_high_pulses Length of longest waveform so far +
wave_get_max_pulses Absolute maximum allowed pulses +
UTILITIES +
get_current_tick Get current tick (microseconds) +
get_hardware_revision Get hardware revision +
get_pigpio_version Get the pigpio version +
pigpiod_if_version Get the pigpiod_if2 version +
pigpio_error Get a text description of an error code. +
time_sleep Sleeps for a float number of seconds +
time_time Float number of seconds since the epoch +

FUNCTIONS

double time_time(void)

+Return the current time in seconds since the Epoch. +

void time_sleep(double seconds)

+Delay execution for a given number of seconds. +

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

+Return a text description for an error code. +

errnum: the error code.

unsigned pigpiod_if_version(void)

+Return the pigpiod_if2 version. +

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

+Starts a new thread of execution with thread_func as the main routine. +

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. +

The function is passed the single argument userdata. +

The thread can be cancelled by passing the pointer to pthread_t to +stop_thread. +

void stop_thread(pthread_t *pth)

+Cancels the thread pointed at by pth. +

pth: the thread to be stopped.


No value is returned. +

The thread to be stopped should have been started with start_thread. +

int pigpio_start(char *addrStr, char *portStr)

+Connect to the pigpio daemon. Reserving command and +notification streams. +

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.


Returns an integer value greater than or equal to zero if OK. +

This value is passed to the GPIO routines to specify the Pi +to be operated on. +

void pigpio_stop(int pi)

+Terminates the connection to a pigpio daemon and releases +resources used by the library. +

pi: >=0 (as returned by pigpio_start).

int set_mode(int pi, unsigned gpio, unsigned mode)

+Set the GPIO mode. +

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, +or PI_NOT_PERMITTED. +

int get_mode(int pi, unsigned gpio)

+Get the GPIO mode. +

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. +

int set_pull_up_down(int pi, unsigned gpio, unsigned pud)

+Set or clear the GPIO pull-up/down resistor. +

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, +or PI_NOT_PERMITTED. +

int gpio_read(int pi, unsigned gpio)

+Read the GPIO level. +

  pi: >=0 (as returned by pigpio_start).
gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. +

int gpio_write(int pi, unsigned gpio, unsigned level)

+Write the GPIO level. +

   pi: >=0 (as returned by pigpio_start).
 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, +or PI_NOT_PERMITTED. +

Notes +

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

int set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)

+Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, +or PI_NOT_PERMITTED. +Notes +

The set_PWM_range function may be used to change the +default range of 255. +

int get_PWM_dutycycle(int pi, unsigned user_gpio)

+Return the PWM dutycycle in use on a GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. +

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

If a hardware clock is active on the GPIO the reported dutycycle +will be 500000 (500k) out of 1000000 (1M). +

If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). +

int set_PWM_range(int pi, unsigned user_gpio, unsigned range)

+Set the range of PWM values to be used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, +or PI_NOT_PERMITTED. +

Notes +

If PWM is currently active on the GPIO its dutycycle will be +scaled to reflect the new range. +

The real range, the number of steps between fully off and fully on +for each of the 18 available GPIO frequencies is +

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


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

int get_PWM_range(int pi, unsigned user_gpio)

+Get the range of PWM values being used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

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

int get_PWM_real_range(int pi, unsigned user_gpio)

+Get the real underlying range of PWM values being used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the real range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

int set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)

+Set the frequency (in Hz) of the PWM to be used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PERMITTED. +

If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. +

Each GPIO can be independently set to one of 18 different +PWM frequencies. +

The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. +

The frequencies for each sample rate are: +

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(int pi, unsigned user_gpio)

+Get the frequency of PWM being used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


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

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

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

Returns the frequency (in hertz) used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

int set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)

+Start (500-2500) or stop (0) servo pulses on the GPIO. +

        pi: >=0 (as returned by pigpio_start).
 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or +PI_NOT_PERMITTED. +

The selected pulsewidth will continue to be transmitted until +changed by a subsequent call to set_servo_pulsewidth. +

The pulsewidths supported by servos varies and should probably be +determined by experiment. A value of 1500 should always be safe and +represents the mid-point of rotation. +

You can DAMAGE a servo if you command it to move beyond its limits. +

OTHER UPDATE RATES: +

This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. +

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. +

Then set the PWM range using set_PWM_range to 1E6/Hz. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. +

E.g. If you want to update a servo connected to GPIO 25 at 400Hz +

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, +e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
+

int get_servo_pulsewidth(int pi, unsigned user_gpio)

+Return the servo pulsewidth in use on a GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. +

int notify_open(int pi)

+Get a free notification handle. +

pi: >=0 (as returned by pigpio_start).


Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. +

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

Pipes are only accessible from the local machine so this function +serves no purpose if you are using the library from a remote machine. +The in-built (socket) notifications provided by callback +should be used instead. +

Notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). +E.g. if the function returns 15 then the notifications must be +read from /dev/pigpio15. +

int notify_begin(int pi, unsigned handle, uint32_t bits)

+Start notifications on a previously opened handle. +

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

The notification sends state changes for each GPIO whose +corresponding bit in bits is set. +

Each notification occupies 12 bytes in the fifo as follows: +

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, +PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. +

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. +

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. +

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags +indicate an event which has been triggered. +

tick: the number of microseconds since system boot. It wraps around +after 1h12m. +

level: indicates the level of each GPIO. If bit 1<<x is set then +GPIO x is high. +

int notify_pause(int pi, unsigned handle)

+Pause notifications on a previously opened handle. +

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Notifications for the handle are suspended until +notify_begin is called again. +

int notify_close(int pi, unsigned handle)

+Stop notifications on a previously opened handle and +release the handle for reuse. +

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int set_watchdog(int pi, unsigned user_gpio, unsigned timeout)

+Sets a watchdog for a GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO +or PI_BAD_WDOG_TIMEOUT. +

The watchdog is nominally in milliseconds. +

Only one watchdog may be registered per GPIO. +

The watchdog may be cancelled by setting timeout to 0. +

Once a watchdog has been started callbacks for the GPIO will be +triggered every timeout interval after the last GPIO activity. +

The callback will receive the special level PI_TIMEOUT. +

int set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)

+Sets a glitch filter on a GPIO. +

Level changes on the GPIO are not reported unless the level +has been stable for at least steady microseconds. The +level is then reported. Level changes of less than +steady microseconds are ignored. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback, callback_ex and wait_for_edge. +

It does not affect levels read by gpio_read, +read_bank_1, or read_bank_2. +

Each (stable) edge will be timestamped steady microseconds +after it was first detected. +

int set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)

+Sets a noise filter on a GPIO. +

Level changes on the GPIO are ignored until a level which has +been stable for steady microseconds is detected. Level changes +on the GPIO are then reported for active microseconds after +which the process repeats. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback, callback_ex and wait_for_edge. +

It does not affect levels read by gpio_read, +read_bank_1, or read_bank_2. +

Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

uint32_t read_bank_1(int pi)

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

pi: >=0 (as returned by pigpio_start).


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

uint32_t read_bank_2(int pi)

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

pi: >=0 (as returned by pigpio_start).


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

int clear_bank_1(int pi, uint32_t bits)

+Clears GPIO 0-31 if the corresponding bit in bits is set. +

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int clear_bank_2(int pi, uint32_t bits)

+Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int set_bank_1(int pi, uint32_t bits)

+Sets GPIO 0-31 if the corresponding bit in bits is set. +

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int set_bank_2(int pi, uint32_t bits)

+Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int hardware_clock(int pi, unsigned gpio, unsigned clkfreq)

+Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. +

       pi: >=0 (as returned by pigpio_start).
     gpio: see description
frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. +

The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. +

The GPIO must be one of the following. +

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely +crash the Pi. The password is given by or'ing 0x5A000000 with the +GPIO number. +

int hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

+Starts hardware PWM on a GPIO at the specified frequency and dutycycle. +Frequencies above 30MHz are unlikely to work. +

NOTE: Any waveform started by wave_send_* or wave_chain +will be cancelled. +

This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). +

     pi: >=0 (as returned by pigpio_start).
   gpio: see descripton
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, +or PI_HPWM_ILLEGAL. +

The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. +

The GPIO must be one of the following. +

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). +

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

There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. PWMduty is +automatically scaled to take this into account. +

uint32_t get_current_tick(int pi)

+Gets the current system tick. +

pi: >=0 (as returned by pigpio_start).


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

uint32_t get_hardware_revision(int pi)

+Get the Pi's hardware revision number. +

pi: >=0 (as returned by pigpio_start).


The hardware revision is the last few characters on the Revision line +of /proc/cpuinfo. +

If the hardware revision can not be found or is not a valid +hexadecimal number the function returns 0. +

The revision number can be used to determine the assignment of GPIO +to pins (see gpio). +

There are at least three types of board. +

Type 1 boards have hardware revision numbers of 2 and 3. +

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. +

Type 3 boards have hardware revision numbers of 16 or greater. +

uint32_t get_pigpio_version(int pi)

+Returns the pigpio version. +

pi: >=0 (as returned by pigpio_start).

int wave_clear(int pi)

+This function clears all waveforms and any data added by calls to the +wave_add_* functions. +

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. +

int wave_add_new(int pi)

+This function starts a new empty waveform. You wouldn't normally need +to call this function as it is automatically called after a waveform is +created with the wave_create function. +

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. +

int wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)

+This function adds a number of pulses to the current waveform. +

       pi: >=0 (as returned by pigpio_start).
numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. +

The pulses are interleaved in time order within the existing waveform +(if any). +

Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist solely of a delay. +

int wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

+This function adds a waveform representing serial data to the +existing waveform (if any). The serial data starts offset +microseconds from the start of the waveform. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. +

NOTES: +

The serial data is formatted as one start bit, data_bits data bits, +and stop_bits/2 stop bits. +

It is legal to add serial data streams with different baud rates to +the same waveform. +

numBytes is the number of bytes of data in str. +

The bytes required for each character depend upon data_bits. +

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

int wave_create(int pi)

+This function creates a waveform from the data provided by the prior +calls to the wave_add_* functions. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions is consumed by this +function. +

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

Normal usage would be +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create to create the waveform and get a unique id +

Repeat steps 2 and 3 as needed. +

Step 4. wave_send_* with the id of the waveform to transmit. +

A waveform comprises one or more pulses. Each pulse consists of a +gpioPulse_t structure. +

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify +

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +

int wave_create_and_pad(int pi, int percent)

+This function creates a waveform like wave_create but pads the consumed +resources. Where percent gives the percentage of the resources to use (in terms +of the theoretical maximum, not the current amount free). This allows the reuse
+of deleted waves while a transmission is active. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions are consumed by this +function. +

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

A usage would be the creation of two waves where one is filled while the other +is beeing transmitted. Each wave is assigned 50% of the available resources. +This buffer structure allows the transmission of infinite wave sequences. +

Normal usage: +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create_and_pad to create a waveform of uniform size. +

Step 4. wave_send_* with the id of the waveform to transmit. +

Repeat steps 2-4 as needed. +

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +

int wave_delete(int pi, unsigned wave_id)

+This function deletes the waveform with id wave_id. +

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


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

The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. +

- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. +

- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). +

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. +

int wave_send_once(int pi, unsigned wave_id)

+This function transmits the waveform with id wave_id. The waveform +is sent once. +

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

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_send_repeat(int pi, unsigned wave_id)

+This function transmits the waveform with id wave_id. The waveform +cycles until cancelled (either by the sending of a new waveform or +by wave_tx_stop). +

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

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)

+Transmits the waveform with id wave_id using mode mode. +

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.
   mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
         PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC.


PI_WAVE_MODE_ONE_SHOT: same as wave_send_once. +

PI_WAVE_MODE_REPEAT same as wave_send_repeat. +

PI_WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries +to sync with the previous waveform. +

PI_WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries +to sync with the previous waveform. +

WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. +

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

Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_chain(int pi, char *buf, unsigned bufSize)

+This function transmits a chain of waveforms. +

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

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

     pi: >=0 (as returned by pigpio_start).
    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. +

Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. +

A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. +

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if2.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, pi, wid[WAVES];

   pi = pigpio_start(0, 0);
   if (pi<0) return -1;

   set_mode(pi, GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(pi, 2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create(pi);
   }

   wave_chain(pi, (char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy(pi)) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(pi, wid[i]);

   pigpio_stop(pi);
}

int wave_tx_at(int pi)

+This function returns the id of the waveform currently being +transmitted. +

pi: >=0 (as returned by pigpio_start).


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

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
+PI_NO_TX_WAVE (9999) - no wave being transmitted. +

int wave_tx_busy(int pi)

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

pi: >=0 (as returned by pigpio_start).


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

int wave_tx_stop(int pi)

+This function stops the transmission of the current waveform. +

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. +

This function is intended to stop a waveform started with the repeat mode. +

int wave_get_micros(int pi)

+This function returns the length in microseconds of the current +waveform. +

pi: >=0 (as returned by pigpio_start).

int wave_get_high_micros(int pi)

+This function returns the length in microseconds of the longest waveform +created since the pigpio daemon was started. +

pi: >=0 (as returned by pigpio_start).

int wave_get_max_micros(int pi)

+This function returns the maximum possible size of a waveform in
+microseconds. +

pi: >=0 (as returned by pigpio_start).

int wave_get_pulses(int pi)

+This function returns the length in pulses of the current waveform. +

pi: >=0 (as returned by pigpio_start).

int wave_get_high_pulses(int pi)

+This function returns the length in pulses of the longest waveform +created since the pigpio daemon was started. +

pi: >=0 (as returned by pigpio_start).

int wave_get_max_pulses(int pi)

+This function returns the maximum possible size of a waveform in pulses. +

pi: >=0 (as returned by pigpio_start).

int wave_get_cbs(int pi)

+This function returns the length in DMA control blocks of the current +waveform. +

pi: >=0 (as returned by pigpio_start).

int wave_get_high_cbs(int pi)

+This function returns the length in DMA control blocks of the longest +waveform created since the pigpio daemon was started. +

pi: >=0 (as returned by pigpio_start).

int wave_get_max_cbs(int pi)

+This function returns the maximum possible size of a waveform in DMA +control blocks. +

pi: >=0 (as returned by pigpio_start).

int gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)

+This function sends a trigger pulse to a GPIO. The GPIO is set to +level for pulseLen microseconds and then reset to not level. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, +PI_BAD_PULSELEN, or PI_NOT_PERMITTED. +

int store_script(int pi, char *script)

+This function stores a script for later execution. +

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. +

    pi: >=0 (as returned by pigpio_start).
script: the text of the script.


The function returns a script id if the script is valid, +otherwise PI_BAD_SCRIPT. +

int run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

+This function runs a stored script. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

+This function sets the parameters of a script. The script may or +may not be running. The first numPar parameters of the script are +overwritten with the new values. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int script_status(int pi, unsigned script_id, uint32_t *param)

+This function returns the run status of a stored script as well +as the current values of parameters 0 to 9. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. +

The run status may be +

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. +

int stop_script(int pi, unsigned script_id)

+This function stops a running script. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int delete_script(int pi, unsigned script_id)

+This function deletes a stored script. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)

+This function opens a GPIO for bit bang reading of serial data. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, +or PI_GPIO_IN_USE. +

The serial data is returned in a cyclic buffer and is read using +bb_serial_read. +

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

int bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)

+This function copies up to bufSize bytes of data read from the +bit bang serial cyclic buffer to the buffer starting at buf. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. +

The bytes returned for each character depend upon the number of +data bits data_bits specified in the bb_serial_read_open command. +

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

int bb_serial_read_close(int pi, unsigned user_gpio)

+This function closes a GPIO for bit bang reading of serial data. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. +

int bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)

+This function inverts serial logic for big bang serial reads. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. +

int i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

+This returns a handle for the device at address i2c_addr on bus i2c_bus. +

       pi: >=0 (as returned by pigpio_start).
  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. +

Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. +

For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. +

S       (1 bit) : Start bit
P       (1 bit) : Stop bit
Rd/Wr   (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA   (1 bit) : Accept and not accept bit.

Addr    (7 bits): I2C 7 bit address.
i2c_reg (8 bits): A byte which often selects a register.
Data    (8 bits): A data byte.
Count   (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2c_close(int pi, unsigned handle)

+This closes the I2C device associated with the handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int i2c_write_quick(int pi, unsigned handle, unsigned bit)

+This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Quick command. SMBus 2.0 5.5.1 +S Addr bit [A] P

int i2c_write_byte(int pi, unsigned handle, unsigned bVal)

+This sends a single byte to the device associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Send byte. SMBus 2.0 5.5.2 +S Addr Wr [A] bVal [A] P

int i2c_read_byte(int pi, unsigned handle)

+This reads a single byte from the device associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. +

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

int i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)

+This writes a single byte to the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write byte. SMBus 2.0 5.5.4 +S Addr Wr [A] i2c_reg [A] bVal [A] P

int i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

+This writes a single 16 bit word to the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write word. SMBus 2.0 5.5.4 +S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P

int i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)

+This reads a single byte from the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read byte. SMBus 2.0 5.5.5 +S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)

+This reads a single 16 bit word from the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read word. SMBus 2.0 5.5.5 +S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

+This writes 16 bits of data to the specified register of the device +associated with handle and and reads 16 bits of data in return. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Process call. SMBus 2.0 5.5.6 +S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes up to 32 bytes to the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Block write. SMBus 2.0 5.5.7 +S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ...
   [A] bufn [A] P

int i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)

+This reads a block of up to 32 bytes from the specified register of +the device associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. +

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Block read. SMBus 2.0 5.5.7 +S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

The smbus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. +

Block write-block read. SMBus 2.0 5.5.8 +S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes 1 to 32 bytes to the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)

+This reads count bytes from the raw device into buf. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. +

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)

+This writes count bytes from buf to the raw device. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)

+This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. +

Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. +

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

  pi: >=0 (as returned by pigpio_start).
 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. +

NOTE: +

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. +

int bb_i2c_close(int pi, unsigned SDA)

+This function stops bit banging I2C on a pair of GPIO previously +opened with bb_i2c_open. +

 pi: >=0 (as returned by pigpio_start).
SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +

int bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

    pi: >=0 (as returned by pigpio_start).
   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)

+This function selects a set of GPIO for bit banging SPI at a +specified baud rate. +

       pi: >=0 (as returned by pigpio_start).
       CS: 0-31
     MISO: 0-31
     MOSI: 0-31
     SCLK: 0-31
     baud: 50-250000
spi_flags: see below


spi_flags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 +

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. +

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or +PI_GPIO_IN_USE. +

If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. +

Example

bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bb_spi_close(int pi, unsigned CS)

+This function stops bit banging SPI on a set of GPIO +opened with bbSPIOpen. +

pi: >=0 (as returned by pigpio_start).
CS: 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. +

int bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)

+This function executes a bit banged SPI transfer. +

   pi: >=0 (as returned by pigpio_start).
   CS: 0-31 (as used in a prior call to bb_spi_open)
txBuf: pointer to buffer to hold data to be sent
rxBuf: pointer to buffer to hold returned data
count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. +

Example

// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2
// ./bb_spi_x_test

#include <stdio.h>

#include "pigpiod_if2.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, pi, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if ((pi = pigpio_start(0, 0)) < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bb_spi_close(pi, CE0);
   bb_spi_close(pi, CE1);

   pigpio_stop(pi);
}

int spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)

+This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


         pi: >=0 (as returned by pigpio_start).
spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. +

spi_flags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. +

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. +

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 spi_read, spi_write, and spi_xfer functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. +

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

Multi-byte transfers are made in least significant byte first order. +

E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. +

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

int spi_close(int pi, unsigned handle)

+This functions closes the SPI device identified by the handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int spi_read(int pi, unsigned handle, char *buf, unsigned count)

+This function reads count bytes of data from the SPI +device associated with the handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spi_write(int pi, unsigned handle, char *buf, unsigned count)

+This function writes count bytes of data from buf to the SPI +device associated with the handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)

+This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)

+This function opens a serial device at a specified baud rate +with specified flags. The device name must start with +/dev/tty or /dev/serial. +

       pi: >=0 (as returned by pigpio_start).
  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. +

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

No flags are currently defined. This parameter should be set to zero. +

int serial_close(int pi, unsigned handle)

+This function closes the serial device associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int serial_write_byte(int pi, unsigned handle, unsigned bVal)

+This function writes bVal to the serial port associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serial_read_byte(int pi, unsigned handle)

+This function reads a byte from the serial port associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. +

If no data is ready PI_SER_READ_NO_DATA is returned. +

int serial_write(int pi, unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the serial port +associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serial_read(int pi, unsigned handle, char *buf, unsigned count)

+This function reads up to count bytes from the the serial port +associated with handle and writes them to buf. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. +

If no data is ready zero is returned. +

int serial_data_available(int pi, unsigned handle)

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

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. +

int custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)

+This function is available for user customisation. +

It returns a single integer value. +

  pi: >=0 (as returned by pigpio_start).
arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. +

int custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

+This function is available for user customisation. +

It differs from custom_1 in that it returns an array of bytes +rather than just an integer. +

The return value is an integer indicating the number of returned bytes. +    pi: >=0 (as returned by pigpio_start).
  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. +

Note, the number of returned bytes will be retMax or less. +

int get_pad_strength(int pi, unsigned pad)

+This function returns the pad drive strength in mA. +

 pi: >=0 (as returned by pigpio_start).
pad: 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. +

PadGPIO
00-27
128-45
246-53


Example

strength = get_pad_strength(pi, 0); //  get pad 0 strength

int set_pad_strength(int pi, unsigned pad, unsigned padStrength)

+This function sets the pad drive strength in mA. +

         pi: >=0 (as returned by pigpio_start).
        pad: 0-2, the pad to set.
padStrength: 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. +

PadGPIO
00-27
128-45
246-53


Example

set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA

int shell_(int pi, char *scriptName, char *scriptString)

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

          pi: >=0 (as returned by pigpio_start).
  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name.
scriptString: the string to pass to the script.


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

scriptName must exist in /opt/pigpio/cgi and must be executable. +

The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. +

The following table gives some example returned statuses. +

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell_(pi, "scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell_(pi, "scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell_(pi, "scr1", "\"hello string with spaces world\"");

int file_open(int pi, char *file, unsigned mode)

+This function returns a handle to a file opened in a specified mode. +

  pi: >=0 (as returned by pigpio_start).
file: the file to open.
mode: the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. +

File +

A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. +

Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. +

Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. +

Suppose /opt/pigpio/access contains the following entries +

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception +of file.txt. +

Files may be read in directory dir_2. +

Files may be read and written in directory dir_3. +

If a directory allows read, write, or read/write access then files may +be created in that directory. +

In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. +

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode +

The mode may have the following values. +

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


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

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. +

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

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

   handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=file_read(pi, handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      file_close(pi, handle);
   }

   pigpio_stop(pi);
}

int file_close(int pi, unsigned handle)

+This function closes the file associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Example

file_close(pi, handle);

int file_write(int pi, unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the file +associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. +

Example

if (file_write(pi, handle, buf, 100) == 0)
{
   // file written okay
}
else
{
   // error
}

int file_read(int pi, unsigned handle, char *buf, unsigned count)

+This function reads up to count bytes from the the file +associated with handle and writes them to buf. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. +

Example

   bytes = file_read(pi, handle, buf, sizeof(buf));

   if (bytes >= 0)
   {
      // process read data
   }

int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)

+This function seeks to a position within the file associated +with handle. +

        pi: >=0 (as returned by pigpio_start).
    handle: >=0 (as returned by file_open).
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2).


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. +

Example

file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123

size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size

pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position

int file_list(int pi, char *fpat, char *buf, unsigned count)

+This function returns a list of files which match a pattern. +

   pi: >=0 (as returned by pigpio_start).
 fpat: file pattern to match.
  buf: an array to receive the matching file names.
count: the maximum number of bytes to read.


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. +

The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See file_open. +

NOTE +

The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. +

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

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

   c = file_list(pi, "/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      buf[c] = 0;
      printf("%s", buf);
   }

   pigpio_stop(pi);
}

int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)

+This function initialises a new callback. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the GPIO, edge, and tick, whenever the +GPIO has the identified edge. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). +

The number of samples per second is given in the following table. +

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. +

The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. +

If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use gpio_read. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. +

int callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

+This function initialises a new callback. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the GPIO, edge, tick, and the userdata +pointer, whenever the GPIO has the identified edge. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

+This function cancels a callback identified by its id. +

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. +

int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)

+This function waits for an edge on the GPIO for up to timeout +seconds. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns when the edge occurs or after the timeout. +

Do not use this function for precise timing purposes, +the edge is only checked 20 times a second. Whenever +you need to know the accurate time of GPIO events use +a callback function. +

The function returns 1 if the edge occurred, otherwise 0. +

int bsc_xfer(int pi, bsc_xfer_t *bscxfer)

+This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. +

This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. +

This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. +

The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. +

I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. +

The function sets the BSC mode, writes any data in +the transmit buffer to the BSC transmit FIFO, and +copies any data in the BSC receive FIFO to the +receive buffer. +

     pi: >=0 (as returned by pigpio_start).
bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. +

Upon return rxCnt will be set to the number of received bytes placed +in rxBuf. +

The returned function value is the status of the transfer (see below). +

If there was an error the status will be less than zero +(and will contain the error code). +

The most significant word of the returned status contains the number +of bytes actually copied from txBuf to the BSC transmit FIFO (may be +less than requested if the FIFO already contained untransmitted data). +

Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. +

GPIO used for models other than those based on the BCM2711. +

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset +to INPUT mode. +

control consists of the following bits. +

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. +

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. +

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as +an I2C slave with address 0x13 and send four bytes. +

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bsc_xfer(pi, &xfer);

if (status >= 0)
{
   // process transfer
}

int bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)

+This function allows the Pi to act as a slave I2C device. +

This function is not available on the BCM2711 (e.g.as +used in the Pi4B). +

The data bytes (if any) are written to the BSC transmit +FIFO and the bytes in the BSC receive FIFO are returned. +

      pi: >=0 (as returned by pigpio_start).
i2c_addr: 0-0x7F.
 bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // N/A
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


txCnt is set to the number of bytes to be transmitted, possibly +zero. The data itself should be copied to txBuf. +

Any received data will be written to rxBuf with rxCnt set. +

See bsc_xfer for details of the returned status value. +

If there was an error the status will be less than zero +(and will contain the error code). +

Note that an i2c_address of 0 may be used to close +the BSC device and reassign the used GPIO as inputs. +

int event_callback(int pi, unsigned event, evtCBFunc_t f)

+This function initialises an event callback. +

   pi: >=0 (as returned by pigpio_start).
event: 0-31.
    f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the event id, and tick, whenever the +event occurs. +

int event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)

+This function initialises an event callback. +

      pi: >=0 (as returned by pigpio_start).
   event: 0-31.
       f: the callback function.
userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the event id, the tick, and the userdata +pointer whenever the event occurs. +

int event_callback_cancel(unsigned callback_id)

+This function cancels an event callback identified by its id. +

callback_id: >=0, as returned by a call to event_callback or
event_callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. +

int wait_for_event(int pi, unsigned event, double timeout)

+This function waits for an event for up to timeout seconds. +

     pi: >=0 (as returned by pigpio_start).
  event: 0-31.
timeout: >=0.


The function returns when the event occurs or after the timeout. +

The function returns 1 if the event occurred, otherwise 0. +

int event_trigger(int pi, unsigned event)

+This function signals the occurrence of an event. +

   pi: >=0 (as returned by pigpio_start).
event: 0-31.


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

An event is a signal used to inform one or more consumers +to start an action. Each consumer which has registered an interest +in the event (e.g. by calling event_callback) will be informed by +a callback. +

One event, PI_EVENT_BSC (31) is predefined. This event is +auto generated on BSC slave activity. +

The meaning of other events is arbitrary. +

Note that other than its id and its tick there is no data associated +with an event. +

PARAMETERS

active: 0-1000000

+The number of microseconds level changes are reported for once +a noise filter has been triggered (by steady microseconds of +a stable level). +

*addrStr

+A string specifying the host or IP address of the Pi running +the pigpio daemon. It may be NULL in which case localhost +is used unless overridden by the PIGPIO_ADDR environment +variable. +

arg1

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

arg2

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

argc

+The count of bytes passed to a user customised function. +

*argx

+A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. +

baud

+The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. +

bit

+A value of 0 or 1. +

bits

+A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. +

A convenient way to set bit n is to or in (1<<n). +

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). +

bsc_xfer_t

+typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*bscxfer

+A pointer to a bsc_xfer_t object used to control a BSC transfer. +

*buf

+A buffer to hold data being sent or being received. +

bufSize

+The size in bytes of a buffer. +

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

+An 8-bit byte value. +

callback_id

+A value >=0, as returned by a call to a callback function, one of +

callback
+callback_ex
+event_callback
+event_callback_ex +

The id is passed to callback_cancel or event_callback_cancel +to cancel the callback. +

CBFunc_t

+typedef void (*CBFunc_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

+typedef void (*CBFuncEx_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata);

char

+A single character, an 8 bit quantity able to store 0-255. +

clkfreq: 4689-250M (13184-375M for the BCM2711)

+The hardware clock frequency. +

count

+The number of bytes to be transferred in a file, I2C, SPI, or serial +command. +

CS

+The GPIO used for the slave select signal when bit banging SPI. +

data_bits: 1-32

+The number of data bits in each character of serial data. +

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

+A floating point number. +

dutycycle: 0-range

+A number representing the ratio of on time to off time for PWM. +

The number may vary between 0 and range (default 255) where +0 is off and range is fully on. +

edge

+Used to identify a GPIO level transition of interest. A rising edge is +a level change from 0 to 1. A falling edge is a level change from 1 to 0. +

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

+A negative number indicating a function call failed and the nature +of the error. +

event: 0-31

+An event is a signal used to inform one or more consumers +to start an action. +

evtCBFunc_t

+typedef void (*evtCBFunc_t)
   (int pi, unsigned event, uint32_t tick);

evtCBFuncEx_t

+typedef void (*evtCBFuncEx_t)
   (int pi, unsigned event, uint32_t tick, void *userdata);

f

+A function. +

*file

+A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. +

*fpat

+A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. +

frequency: >=0

+The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. +

gpio

+A Broadcom numbered GPIO, in the range 0-53. +

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

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

gpioPulse_t

+typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

+typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

+A number referencing an object opened by one of +

file_open
+i2c_open
+notify_open
+serial_open
+spi_open +

i2c_addr: 0-0x7F

+The address of a device on the I2C bus. +

i2c_bus: >=0

+An I2C bus number. +

i2c_flags: 0

+Flags which modify an I2C open command. None are currently defined. +

i2c_reg: 0-255

+A register of an I2C device. +

*inBuf

+A buffer used to pass data to a function. +

inLen

+The number of bytes of data in a buffer. +

int

+A whole number, negative or positive. +

int32_t

+A 32-bit signed value. +

invert

+A flag used to set normal or inverted bit bang serial data level logic. +

level

+The level of a GPIO. Low or High. +

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See set_watchdog. +

PI_TIMEOUT 2

MISO

+The GPIO used for the MISO signal when bit banging SPI. +

mode

+1. The operational mode of a GPIO, normally INPUT or OUTPUT. +

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. The mode of waveform transmission. +

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3


3. A file open mode. +

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


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

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

+The GPIO used for the MOSI signal when bit banging SPI. +

numBytes

+The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. +

numPar: 0-10

+The number of parameters passed to a script. +

numPulses

+The number of pulses to be added to a waveform. +

offset

+The associated data starts this number of microseconds from the start of +the waveform. +

*outBuf

+A buffer used to return data from a function. +

outLen

+The size in bytes of an output buffer. +

pad: 0-2

+A set of GPIO which share common drivers. +

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

+The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. +

*param

+An array of script parameters. +

pi

+An integer defining a connected Pi. The value is returned by +pigpio_start upon success. +

*portStr

+A string specifying the port address used by the Pi running +the pigpio daemon. It may be NULL in which case "8888" +is used unless overridden by the PIGPIO_PORT environment +variable. +

*pth

+A thread identifier, returned by start_thread. +

pthread_t

+A thread identifier. +

pud: 0-2

+The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. +PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

+1-100, the length of a trigger pulse in microseconds. +

*pulses

+An array of pulses to be added to a waveform. +

pulsewidth: 0, 500-2500

+PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

+The hardware PWM dutycycle. +

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

+The hardware PWM frequency. +

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000
#define PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

+The permissible dutycycle values are 0-range. +

PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

+A buffer to hold a number of bytes returned to a used customised function, +

retMax

+The maximum number of bytes a user customised function should return. +

*rxBuf

+A pointer to a buffer to receive data. +

SCL

+The user GPIO to use for the clock when bit banging I2C. +

SCLK

+The GPIO used for the SCLK signal when bit banging SPI. +

*script

+A pointer to the text of a script. +

script_id

+An id of a stored script as returned by store_script. +

*scriptName

+The name of a shell_ script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. +

*scriptString

+The string to be passed to a shell_ script to be executed. +

SDA

+The user GPIO to use for data when bit banging I2C. +

seconds

+The number of seconds. +

seekFrom

+PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

+The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). +

ser_flags

+Flags which modify a serial open command. None are currently defined. +

*ser_tty

+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. +

size_t

+A standard type used to indicate the size of an object in bytes. +

spi_channel

+A SPI channel, 0-2. +

spi_flags

+See spi_open and bb_spi_open. +

steady: 0-300000

+The number of microseconds level changes must be stable for +before reporting the level changed (set_glitch_filter) or triggering +the active part of a noise filter (set_noise_filter). +

stop_bits: 2-8

+The number of (half) stop bits to be used when adding serial data +to a waveform. +

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

+ An array of characters. +

thread_func

+A function of type gpioThreadFunc_t used as the main function of a +thread. +

timeout

+A GPIO watchdog timeout in milliseconds. +

PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

+An array of bytes to transmit. +

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

+A 32-bit unsigned value. +

unsigned

+A whole number >= 0. +

user_gpio

+0-31, a Broadcom numbered GPIO. +

See gpio. +

*userdata

+A pointer to arbitrary user data. This may be used to identify the instance. +

You must ensure that the pointer is in scope at the time it is processed. If +it is a pointer to a global this is automatic. Do not pass the address of a +local variable. If you want to pass a transient object then use the +following technique. +

In the calling function: +

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: +

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

+Denoting no parameter is required +

wave_add_*

+One of +

wave_add_new
+wave_add_generic
+wave_add_serial +

wave_id

+A number representing a waveform created by wave_create. +

wave_send_*

+One of +

wave_send_once
+wave_send_repeat +

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

+A 16-bit word value. +

pigpiod_if2 Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
   pigif_unconnected_pi     = -2011,
   pigif_too_many_pis       = -2012,
} pigifError_t;

+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/pif.html b/DOC/HTML/pif.html new file mode 100644 index 0000000..6ed3739 --- /dev/null +++ b/DOC/HTML/pif.html @@ -0,0 +1,85 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Pipe Interface

+pigpio provides a pipe interface to many of its functions.
+
+The pipe interface is available whenever pigpio is running, either +because it has been started as a daemon, or it has been linked in +to a running user program.  The pipe interface can be disabled +by the program which initialises the library.  pigpiod offers +the -f option to disable the pipe interface.  User programs +should call gpioCfgInterfaces +if they wish to disable the pipe interface.
+
+pigpio listens for commands on pipe /dev/pigpio.  The commands +consist of a command identifier with, depending on the command, +zero, one, or two parameters.  The result, if any, may be read +from pipe /dev/pigout.  If any errors are detected a message +will be written to pipe /dev/pigerr.
+
+
+The format of the commands is identical to those used by pigs. +
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/pig2vcd.html b/DOC/HTML/pig2vcd.html new file mode 100644 index 0000000..8797c15 --- /dev/null +++ b/DOC/HTML/pig2vcd.html @@ -0,0 +1,83 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

pig2vcd

pig2vcd is a utility which reads notifications on stdin and writes the +output as a Value Change Dump (VCD) file on stdout. +

The VCD file can be viewed using GTKWave. +

Notifications

Notifications consist of 12 bytes with the following binary format. +

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

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

tick: the number of microseconds since system boot. It wraps around after 1h12m. +

level: indicates the level of each gpio. If bit 1<<x is set then gpio x is high. pig2vcd takes these notifications and outputs a text format VCD. +

VCD format

The VCD starts with a header. +

$date 2013-05-31 18:49:36 $end
$version pig2vcd V1 $end
$timescale 1 us $end
$scope module top $end
$var wire 1 A 0 $end
$var wire 1 B 1 $end
$var wire 1 C 2 $end
$var wire 1 D 3 $end
$var wire 1 E 4 $end
$var wire 1 F 5 $end
$var wire 1 G 6 $end
$var wire 1 H 7 $end
$var wire 1 I 8 $end
$var wire 1 J 9 $end
$var wire 1 K 10 $end
$var wire 1 L 11 $end
$var wire 1 M 12 $end
$var wire 1 N 13 $end
$var wire 1 O 14 $end
$var wire 1 P 15 $end
$var wire 1 Q 16 $end
$var wire 1 R 17 $end
$var wire 1 S 18 $end
$var wire 1 T 19 $end
$var wire 1 U 20 $end
$var wire 1 V 21 $end
$var wire 1 W 22 $end
$var wire 1 X 23 $end
$var wire 1 Y 24 $end
$var wire 1 Z 25 $end
$var wire 1 a 26 $end
$var wire 1 b 27 $end
$var wire 1 c 28 $end
$var wire 1 d 29 $end
$var wire 1 e 30 $end
$var wire 1 f 31 $end
$upscope $end
$enddefinitions $end


The header defines gpio identifiers and their name. Each gpio identifier +must be unique. pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0 +through 25, and 'a' through 'f' for gpios 26 through 31. +The corresponding names are 0 through 31.
+

The VCD file may be edited to give a frendlier name, e.g. 8 could be +changed to ENCODER_A if an encoder switch A is connected to gpio 8. +

Following the header pig2vcd takes notifications and outputs a timestamp +followed by a list of one or more gpios which have changed state. +The timestamp consists of a '#' followed by the microsecond tick. +The state lines contain the new state followed by the gpio identifier. +

#1058747
0H
0I
#1059012
1H
#1079777
1I
#1079782
0I
#1079852
1I
#1079857
0I
0H
#1165113
1H
#1165118
0H
#1165153
1H
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/pigpiod.html b/DOC/HTML/pigpiod.html new file mode 100644 index 0000000..b40a71e --- /dev/null +++ b/DOC/HTML/pigpiod.html @@ -0,0 +1,114 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

pigpio Daemon

pigpiod is a utility which launches the pigpio library as a daemon.
+
+Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.
+
+The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.
+
+pigpiod accepts the following configuration options
+
+
-a valueDMA memory allocation mode0=AUTO, 1=PMAP, 2=MBOXDefault AUTO +
-b valueGPIO sample buffer size in milliseconds100-10000Default 120 +
-c valueLibrary internal settingsDefault 0 +
-d valuePrimary DMA channel0-14Default 14 +
-e valueSecondary DMA channel0-14Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel +
-fDisable fifo interfaceDefault enabled +
-gRun in foreground (do not fork)Default disabled +
-kDisable local and remote socket interfaceDefault enabled +
-lDisable remote socket interfaceDefault enabled +
-mDisable alerts (sampling)Default enabled +
-n IP addressAllow IP address to use the socket interfaceName (e.g. paul) or dotted quad (e.g. 192.168.1.66)If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect +
-p valueSocket port1024-32000Default 8888 +
-s valueSample rate1, 2, 4, 5, 8, or 10 microsecondsDefault 5 +
-t valueClock peripheral0=PWM 1=PCMDefault PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. +
-v -VDisplay pigpio version and exit +
-x maskGPIO which may be updatedA 54 bit mask with (1<<n) set if the user may update GPIO #nDefault is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO +

Example

sudo pigpiod -s 2 -b 200 -f


Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer. Disable the fifo interface. +

Permissions

pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces. +

All GPIO may be read. +

Only the user GPIO for the board type or those specified by the -x option may be updated. +

Type 1 boards 0x03E6CF93 (26 pin header)
Type 2 boards 0xFBC6CF9C (26 pin + 8 pin header)
Type 3 boards 0x0FFFFFFC (40 pin header)


In this context an update includes the following: +

GPIO mode set
+GPIO pull/up down
+GPIO write
+GPIO set PWM (including range and frequency)
+GPIO set servo +

In addition the bank clear and set commands, and the wave commands will only +affect updateable GPIO. +

Exceptions

The following exceptions are made for particular models. +

Models A and B

The green activity LED (GPIO 16) may be written.
+
Models A+ and B+

The green activity LED (GPIO 47) may be written.
+The red power LED (GPIO 35) may be written.
+The high USB power mode (GPIO 38) may be written.
+
Pi Zero

The green activity LED (GPIO 47) may be written.
+
Pi2B

The green activity LED (GPIO 47) may be written.
+The red power LED (GPIO 35) may be written.
+The high USB power mode (GPIO 38) may be written.
+
Pi3B

The green activity LED and the red power LED are not writable.
+The USB power mode is fixed at 1.2 amps (high power).
+

DMA Channels

The secondary channel is only used for the transmission of waves. +

If possible use one of channels 0 to 6 for the secondary channel (a full channel). +

A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel. +

+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/pigs.html b/DOC/HTML/pigs.html new file mode 100644 index 0000000..3aaeaf9 --- /dev/null +++ b/DOC/HTML/pigs.html @@ -0,0 +1,1268 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

pigs

Introduction

+The socket and pipe interfaces allow control of the Pi's GPIO by +passing messages to the running pigpio library. +

The normal way to start the pigpio library would be as a daemon during boot. +

sudo pigpiod

Features

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o reading/writing all of the GPIO in a bank as one operation +

o individually setting GPIO modes, reading and writing +

o notifications when any of GPIO 0-31 change state +

o the construction of output waveforms with microsecond timing +

o I2C, SPI, and serial link wrappers +

o creating and running scripts on the pigpio daemon +

GPIO

ALL GPIO are identified by their Broadcom number. +

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

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 $?). +

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

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

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

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 mSet GPIO mode gpioSetMode
MG/MODEG gGet GPIO mode gpioGetMode
PUD g pSet GPIO pull up/down gpioSetPullUpDown
R/READ gRead GPIO level gpioRead
W/WRITE g LWrite GPIO level gpioWrite
PWM (overrides servo commands on same GPIO) +
P/PWM u vSet GPIO PWM value gpioPWM
PFS u vSet GPIO PWM frequency gpioSetPWMfrequency
PRS u vSet GPIO PWM range gpioSetPWMrange
GDC uGet GPIO PWM dutycycle gpioGetPWMdutycycle
PFG uGet GPIO PWM frequency gpioGetPWMfrequency
PRG uGet GPIO PWM range gpioGetPWMrange
PRRG uGet GPIO PWM real range gpioGetPWMrealRange
Servo (overrides PWM commands on same GPIO) +
S/SERVO u vSet GPIO servo pulsewidth gpioServo
GPW uGet GPIO servo pulsewidth gpioGetServoPulsewidth
INTERMEDIATE +
TRIG u pl LSend a trigger pulse gpioTrigger
WDOG u vSet GPIO watchdog gpioSetWatchdog
BR1Read bank 1 GPIO gpioRead_Bits_0_31
BR2Read bank 2 GPIO gpioRead_Bits_32_53
BC1 bitsClear specified GPIO in bank 1 gpioWrite_Bits_0_31_Clear
BC2 bitsClear specified GPIO in bank 2 gpioWrite_Bits_32_53_Clear
BS1 bitsSet specified GPIO in bank 1 gpioWrite_Bits_0_31_Set
BS2 bitsSet specified GPIO in bank 2 gpioWrite_Bits_32_53_Set
ADVANCED +
NORequest a notification gpioNotifyOpen
NC hClose notification gpioNotifyClose
NB h bitsStart notification gpioNotifyBegin
NP hPause notification gpioNotifyPause
HC g cfSet hardware clock frequency gpioHardwareClock
HP g pf pdcSet hardware PWM frequency and dutycycle gpioHardwarePWM
FG u stdySet a glitch filter on a GPIO gpioGlitchFilter
FN u stdy actvSet a noise filter on a GPIO gpioNoiseFilter
PADS pad padmaSet pad drive strength gpioSetPad
PADG padGet pad drive strength gpioGetPad
SHELL name strExecute a shell command shell
Custom +
CF1 uvsCustom function 1 gpioCustom1
CF2 uvsCustom function 2 gpioCustom1
Events +
EVM h bitsSet events to monitor eventMonitor
EVT eventTrigger event eventTrigger
Scripts +
PROC tStore script gpioStoreScript
PROCR sid parsRun script gpioRunScript
PROCU sid parsSet script parameters gpioUpdateScript
PROCP sidGet script status and parameters gpioScriptStatus
PROCS sidStop script gpioStopScript
PROCD sidDelete script gpioDeleteScript
PARSE tValidate script gpioParseScript
I2C +
I2CO ib id ifOpen I2C bus and device with flags i2cOpen
I2CC hClose I2C handle i2cClose
I2CWQ h bitsmb Write Quick: write bit i2cWriteQuick
I2CRS hsmb Read Byte: read byte i2cReadByte
I2CWS h bvsmb Write Byte: write byte i2cWriteByte
I2CRB h rsmb Read Byte Data: read byte from register i2cReadByteData
I2CWB h r bvsmb Write Byte Data: write byte to register i2cWriteByteData
I2CRW h rsmb Read Word Data: read word from register i2cReadWordData
I2CWW h r wvsmb Write Word Data: write word to register i2cWriteWordData
I2CRK h rsmb Read Block Data: read data from register i2cReadBlockData
I2CWK h r bvssmb Write Block Data: write data to register i2cWriteBlockData
I2CWI h r bvssmb Write I2C Block Data i2cWriteI2CBlockData
I2CRI h r numsmb Read I2C Block Data: read bytes from register i2cReadI2CBlockData
I2CRD h numi2c Read device i2cReadDevice
I2CWD h bvsi2c Write device i2cWriteDevice
I2CPC h r wvsmb Process Call: exchange register with word i2cProcessCall
I2CPK h r bvssmb Block Process Call: exchange data bytes with register i2cBlockProcessCall
I2CZ h bvsPerforms multiple I2C transactions i2cZip
I2C BIT BANG +
BI2CO sda scl bOpen bit bang I2C bbI2COpen
BI2CC sdaClose bit bang I2C bbI2CClose
BI2CZ sda bvsI2C bit bang multiple transactions bbI2CZip
I2C/SPI SLAVE +
BSCX bctl bvsBSC I2C/SPI transfer bscXfer
SERIAL +
SERO dev b sefOpen serial device dev at baud b with flags serOpen
SERC hClose serial handle serClose
SERRBRead byte from serial handle serReadByte
SERWB h bvWrite byte to serial handle serWriteByte
SERR h numRead bytes from serial handle serRead
SERW h bvsWrite bytes to serial handle serWrite
SERDA hCheck for serial data ready to read serDataAvailable
SERIAL BIT BANG (read only) +
SLRO u b dbOpen GPIO for bit bang serial data gpioSerialReadOpen
SLRC uClose GPIO for bit bang serial data gpioSerialReadClose
SLRI u vSets bit bang serial data logic levels gpioSerialReadInvert
SLR u numRead bit bang serial data from GPIO gpioSerialRead
SPI +
SPIO c b spfSPI open channel at baud b with flags spiOpen
SPIC hSPI close handle spiClose
SPIR h numSPI read bytes from handle spiRead
SPIW h bvsSPI write bytes to handle spiWrite
SPIX h bvsSPI transfer bytes to handle spiXfer
SPI BIT BANG +
BSPIO cs miso mosi sclk b spfOpen bit bang SPI bbSPIOpen
BSPIC csClose bit bang SPI bbSPIClose
BSPIX cs bvsSPI bit bang transfer bbSPIXfer
FILES +
FO file modeOpen a file in mode fileOpen
FC hClose file handle fileClose
FR h numRead bytes from file handle fileRead
FW h bvsWrite bytes to file handle fileWrite
FS h num fromSeek to file handle position fileSeek
FL pat numList files which match pattern fileList
WAVES +
WVCLRClear all waveforms gpioWaveClear
WVNEWInitialise a new waveform gpioWaveAddNew
WVAG tripsAdd generic pulses to waveform gpioWaveAddGeneric
WVAS u b db sb o bvsAdd serial data to waveform gpioWaveAddSerial
WVCRECreate a waveform gpioWaveCreate
WVCAPCreate a waveform of fixed size gpioWaveCreatePad
WVDEL widDelete selected waveform gpioWaveDelete
WVTX widTransmits waveform once gpioWaveTxSend
WVTXM wid wmdeTransmits waveform using mode gpioWaveTxSend
WVTXR widTransmits waveform repeatedly gpioWaveTxSend
WVCHA bvsTransmits a chain of waveforms gpioWaveChain
WVTATReturns the current transmitting waveform gpioWaveTxAt
WVBSYCheck if waveform is being transmitted gpioWaveTxBusy
WVHLTStop waveform gpioWaveTxStop
WVSC wsGet waveform DMA CB stats gpioWaveGetCbs
WVSM wsGet waveform time stats gpioWaveGetMicros
WVSP wsGet waveform pulse stats gpioWaveGetPulses
UTILITIES +
H/HELPDisplay command help
HWVERGet hardware version gpioHardwareRevision
MICS vMicroseconds delay gpioDelay
MILS vMilliseconds delay gpioDelay
PIGPVGet pigpio library version gpioVersion
T/TICKGet current tick gpioTick
CONFIGURATION +
CGIConfiguration get internals gpioCfgGetInternals
CSI vConfiguration set internals gpioCfgSetInternals

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

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

o baud rates as low as 50
+o repeated starts
+o clock stretching
+o 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. +

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: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

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 read GPIO 0-31 (bank 1) and returns the levels as a +32-bit hexadecimal value. +

Example

$ pigs br1
1001C1CF

BR2 + - Read bank 2 GPIO

This command read 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 (sets high) 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 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

This command sets (sets high) 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 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

This command performs a BSC I2C/SPI slave transfer as defined by +bctl with data bvs. +

This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. +

This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. +

This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. +

The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. +

I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. +

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, followed by any data bytes +read from the BSC receive FIFO. +

Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. +

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

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

GPIO used for models other than those based on the BCM2711. +

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset +to INPUT mode. +

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

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. +

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit 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 +opened with BSPIO. +

The set of GPIO is specifed by cs. +

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

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 command starts bit banging SPI on a group of GPIO with slave +select cs, MISO miso, MOSI mosi, and clock sclk. +

Data will be transferred at baud b bits per second (which may +be set in the range 50-250000). +

The flags spf may be used to modify the default behaviour of +mode 0, active low chip select. +

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

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

If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. +

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. It returns the same +number of bytes read from the device. +

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

This command calls a user customised function. The meaning of +any paramaters and the returned value is defined by the +customiser. +

CF2 + uvs - Custom function 2

This command calls a user customised function. The meaning of +any paramaters and the returned value is defined by the +customiser. +

CGI + - Configuration get internals

This command returns the value of the internal library +configuration settings. +

CSI + v - Configuration set internals

This command sets the value of the internal library +configuration settings to v. +

EVM + h bits - Set events to monitor

This command starts event reporting 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 reports for each 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

This command triggers event event. +

One event, number 31, is predefined. This event is +auto generated on BSC slave activity. +

Example

$ pigs evt 12
$ pigs evt 5

$ pigs evt 32
-143
ERROR: bad event id

FC + h - Close file handle

This command closes a file handle h previously opened with FO. +

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

Example

$ pigs fc 0 # First close okay.

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

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. The +level is then reported. Level changes of less than stdy +microseconds are ignored. +

The filter only affects callbacks (including pipe notifications). +

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

Note, each (stable) edge will be timestamped stdy microseconds +after it was first detected. +

Example

$ pigs fg 4 250

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

FL + pat num - List files which match pattern

This command returns a list of the files matching pat. Up +to num bytes may be returned. +

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

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 are ignored until a level which has +been stable for stdy microseconds is detected. Level +changes on the GPIO are then reported for actv microseconds +after which the process repeats. +

The filter only affects callbacks (including pipe notifications). +

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

Note, level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

Example

$ pigs fn 7 250 1000

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

FO + file mode - Open a file in mode

This function 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 +will be returned. +

File +

A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. +

Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. +

Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. +

Suppose /opt/pigpio/access contains the following entries +

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception +of file.txt. +

Files may be read in directory dir_2. +

Files may be read and written in directory dir_3. +

If a directory allows read, write, or read/write access then files may +be created in that directory. +

In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. +

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode +

The mode may have the following values. +

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


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

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. +

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

This command 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 will be returned. +

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

This command 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 backwards. The move start +position is determined by from as follows. +

From
0start
1current position
2end


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

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

This command writes bytes bvs to the file +associated with handle h. +

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

Example

$ pigs fw 0 23 45 67 89

GDC + u - Get GPIO PWM dutycycle

This command returns the PWM dutycycle in use on GPIO u. +

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

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

This command returns the servo pulsewidth in use on GPIO u. +

Upon success the servo pulsewidth is returned. On error a negative +status code will be returned. +

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

This command displays a brief list of the commands and their parameters. +

Example

$ pigs h

$ pigs help

HC + g cf - Set hardware clock frequency

This command sets the hardware clock associated with GPIO g to +frequency cf. Frequencies above 30MHz are unlikely to work. +

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

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

The GPIO must be one of the following. +

4clock 0All models
5clock 1All models but A and B (reserved for system use)
6clock 2All models but A and B
20clock 0All models but A and B
21clock 1All models but A and B Rev.2 (reserved for system use)


32clock 0Compute module only
34clock 0Compute module only
42clock 1Compute module only (reserved for system use)
43clock 2Compute module only
44clock 1Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will +likely crash the Pi. The password is given by or'ing 0x5A000000 +with the GPIO number. +

HP + g pf pdc - Set hardware PWM frequency and dutycycle

This command sets the hardware PWM associated with GPIO g to +frequency pf with dutycycle pdc. Frequencies above 30MHz +are unlikely to work. +

NOTE: Any waveform started by WVTX, WVTXR, or WVCHA +will be cancelled. +

This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). +

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

$ 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


The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. +

The GPIO must be one of the following. +

12PWM channel 0All models but A and B
13PWM channel 1All models but A and B
18PWM channel 0All models
19PWM channel 1All models but A and B


40PWM channel 0Compute module only
41PWM channel 1Compute module only
45PWM channel 1Compute module only
52PWM channel 0Compute module only
53PWM channel 1Compute module only


The actual number of steps beween off and fully on is the +integral part of 250M/pf (375M/pf for the BCM2711). +

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

There will only be a million steps for a pf of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. pdc is +automatically scaled to take this into account. +

HWVER + - Get hardware version

This command returns the hardware revision of the Pi. +

The hardware revision is found in the last 4 characters on the revision +line of /proc/cpuinfo. +

If the hardware revision can not be found or is not a valid hexadecimal +number the command returns 0. +

The revision number can be used to determine the assignment of GPIO +to pins (see g). +

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

This command closes an I2C handle h previously opened with I2CO. +

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

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 command returns a handle to access device id on I2C bus ib. +The device is opened with flags if. +

Physically buses 0 and 1 are available on the Pi. Higher +numbered buses will be available if a kernel supported bus +multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


No flags are currently defined. The parameter if should be 0. +

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

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

This command writes wv to register r of the I2C device +associated with handle h and returns a 16-bit word read from the +device. +

Upon success a value between 0 and 65535 will be returned. On error +a negative status code will be returned. +

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

This command writes the data bytes bvs to register r of the I2C device +associated with handle h and returns a device specific number of 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 i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0

I2CRB + h r - smb Read Byte Data: read byte from register

This command returns a single byte read from register r of the I2C device +associated with handle h. +

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

Example

$ pigs i2crb 0 0
6

I2CRD + h num - i2c Read device

This command returns num bytes read from the I2C 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. +

This command operates on the raw I2C device. The maximum value of the +parameter num is dependent on the I2C drivers and the device +itself. pigs imposes a limit of 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

This command returns num bytes from register r of the I2C 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. +

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

This command returns between 1 and 32 bytes read from register r of +the I2C 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. +

The number of bytes of returned data is specific to the device and +register. +

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

This command returns a single byte read from the I2C device +associated with handle h. +

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

Example

$ pigs i2crs 0
0

I2CRW + h r - smb Read Word Data: read word from register

This command returns a single 16 bit word read from register r of +the I2C device associated with handle h. +

Upon success a value between 0 and 65535 will be returned. On error +a negative status code will be returned. +

Example

$ pigs i2crw 0 0
6150

I2CWB + h r bv - smb Write Byte Data: write byte to register

This command writes a single byte bv to register r of the +I2C device associated with handle h. +

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

Example

$ pigs i2cwb 0 10 0x54

I2CWD + h bvs - i2c Write device

This command writes a block of bytes bvs to the I2C device +associated with handle h. +

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

The number of bytes which may be written in one transaction is +dependent on the I2C drivers and the device itself. pigs imposes +a limit of about 500 bytes. +

This command operates on the raw I2C device. +

Example

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

I2CWI + h r bvs - smb Write I2C Block Data

This command writes between 1 and 32 bytes bvs to register r of +the I2C device associated with handle h. +

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

Example

$ pigs i2cwi 0 4 0x01 0x04 0xc0

I2CWK + h r bvs - smb Write Block Data: write data to register

This command writes between 1 and 32 bytes bvs to register r of +the I2C device associated with handle h. +

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

Example

pigs i2cwk 0 4 0x01 0x04 0xc0

I2CWQ + h bit - smb Write Quick: write bit

This command writes a single bit to the I2C device associated +with handle h. +

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

Example

$ pigs i2cwq 0 1

I2CWS + h bv - smb Write Byte: write byte

This command writes a single byte bv to the I2C device associated +with handle h. +

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

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

This command writes a single 16 bit word wv to register r of +the I2C device associated with handle h. +

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

Example

$ pigs i2cww 0 0 0xffff

I2CZ + h bvs - Performs multiple I2C transactions

This command executes a sequence of 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: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle h. +The flags default to 0. The address and flags maintain their +previous value until updated. +

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/MODES + g m - Set GPIO mode

This command sets GPIO g to mode m, typically input (read) +or output (write). +

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

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

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345


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

Value01234567
ModeInputOutputALT5ALT4ALT0ALT1ALT2ALT3


Example

$ pigs mg 4
1

MICS + v - Microseconds delay

This command delays execution for v microseconds. +

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

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

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

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

PadGPIO
00-27
128-45
246-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. +

PadGPIO
00-27
128-45
246-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. +

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

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

       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


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

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

Upon success the script status and parameters are returned. +On error a negative status code will be returned. +

The script status may be one of +

0being initialised
1halted
2running
3waiting
4failed


See Scripts. +

Example

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

PROCR + sid pars - Run script

This command runs stored script sid passing it up to 10 optional +parameters. +

Upon success nothing is returned. 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 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

This command stops a running script sid. +

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

This command sets the parameters of a stored script sid passing +it up to 10 parameters. +

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 used by GPIO u. +

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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

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 command sets the dutycycle range v to be used for GPIO u. +Subsequent uses of command P/PWM will use a dutycycle between 0 (off) +and v (fully on). +

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 will be scaled to +reflect the new range. +

The real range, the number of steps between fully off and fully on +for each frequency, is given in the following table. +

#1#2#3#4#5#6#7#8#9
2550100125200250400500625
#10#11#12#13#14#15#16#17#18
8001000125020002500400050001000020000


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

This command 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 may 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

This 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

This command 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 may be 0 (off), 500 (most anti-clockwise) +to 2500 (most clockwise). +

The range supported by servos varies and should probably be determined +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. +

You can DAMAGE a servo if you command it to move beyond its limits. +

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

This command closes a serial handle h 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

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

This command 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. +

Example

$ pigs sero /dev/ttyAMA0 9600 0
0

$ pigs sero /dev/tty1 38400 0
1

SERR + h num - Read bytes from serial handle

This command 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

This command 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

This command 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

This command 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 command 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. +

The returned exit status is normally 256 times that set +by the shell script exit function. If the script can't +be found 32512 will be returned. +

The following table gives some example returned statuses. +

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


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 "\"hello string with spaces world\""
256

# non-existent script
$ pigs shell scr78 par1
32512

SLR + u num - Read bit bang serial data from GPIO

This command 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. +

The GPIO u should have been initialised with the SLRO command. +

The bytes returned for each character depend upon the number of +data bits db 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

This command 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

This command 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

This command 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 may be between 50 and 250000 bits per second. +

The received data is held in a cyclic buffer. +

It is the user's responsibility to read the data (with SLR) +in a timely fashion. +

Example

$ pigs slro 23 19200 8

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

SPIC + h - SPI close handle

This command closes the SPI handle h returned by a prior +call to SPIO. +

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

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

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

Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps +are unlikely to work. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


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

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

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

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

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

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

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

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

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

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

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

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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 \
   ${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

WVCLR + - Clear all waveforms

This command clears all waveforms. +

Nothing is returned. +

Example

$ pigs wvclr

WVCRE + - Create a waveform

This command creates a waveform from the data provided by the prior +calls to the WVAG and WVAS commands. +

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

The data provided by the WVAG and WVAS commands is +consumed by this command. +

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 +

Step 1. WVCLR to clear all waveforms and added data. +

Step 2. WVAG/WVAS calls to supply the waveform data. +

Step 3. WVCRE to create the waveform and get a unique id. +

Repeat steps 2 and 3 as needed. +

Step 4. WVTX or WVTXR with the id of the waveform to transmit. +

A waveform comprises of one or more pulses. +

A pulse specifies +

1) the GPIO to be switched on at the start of the pulse.
+2) the GPIO to be switched off at the start of the pulse.
+3) the delay in microseconds before the next pulse. +

Any or all the fields can be zero. It doesn't make any sense to +set all the fields to zero (the pulse will be ignored). +

When a waveform is started each pulse is executed in order with +the specified delay between the pulse and the next. +

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

WVCAP + - 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 total resource. +Padded waves of equal size can be re-cycled efficiently allowing newly +created waves to re-use the resources of deleted waves of the same dimension. +

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

The data provided by the WVAG and WVAS commands are +consumed by this command. +

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 +

Step 1. WVCLR to clear all waveforms and added data. +

Step 2. WVAG/WVAS calls to supply the waveform data. +

Step 3. WVCAP to create a waveform of a uniform size. +

Step 4. WVTX or WVTXR with the id of the waveform to transmit. +

Repeat steps 2 - 4 as needed. +

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

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

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

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

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

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

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), or 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. +

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

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

+

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

From
0start
1current position
2end

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

0123456789101112131415
Type 1XX--X--XXXXX--XX
Type 2--XXX--XXXXX--XX
Type 3XXXXXXXXXXXXXX
16171819202122232425262728293031
Type 1-XX--XXXXX------
Type 2-XX---XXXX-XXXXX
Type 3XXXXXXXXXXXX----


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

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345
Value01456732

miso - GPIO (0-31)

+The GPIO used for the MISO signal when bit banging SPI. +

mode - file open mode

+One of the following values. +

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


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

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The 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 DownOffPull DownPull Up
Command CharacterODU


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

pad - 0-2

+A set of GPIO which share common drivers. +

PadGPIO
00-27
128-45
246-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. +

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 onGPIO offdelay
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

+Scripts are programs to be stored and executed by the pigpio daemon. +They are intended to mitigate any performance problems associated with +the pigpio daemon server/client model. +

Example

A trivial example might be useful. Suppose you want to toggle a GPIO +on and off as fast as possible. +

From the command line you could write +

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


Timing that you will see it takes about 14 seconds, or roughly +70 toggles per second. +

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

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

Let's time the script running. +

Again, ignore the details for now. +

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


The script takes roughly 12 seconds to complete, or 800,000 toggles per second. +

That is the advantage of a stored script. +

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 ]];\
 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. +

Virtual machine

A script runs within a virtual machine with +

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

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: +

CommandDescriptionDefinition
ADD xAdd x to accumulatorA+=x; F=A
AND xAnd x with accumulatorA&=x; F=A
CALL LCall subroutine at tag Lpush(PC+1); PC=L
CMP xCompare x with accumulatorF=A-x
DCR yDecrement register--*y; F=*y
DCRADecrement accumulator--A; F=A
DIV xDivide x into accumulatorA/=x; F=A
EVTWTWait for an event to occurA=wait(x); F=A
HALTHaltHalt
INR yIncrement register++*y; F=*y
INRAIncrement accumulator++A; F=A
JM LJump if minus to tag Lif (F<0) PC=L
JMP LJump to tag LPC=L
JNZ LJump if non-zero to tag Lif (F) PC=L
JP LJump if positive to tag Lif (F>=0) PC=L
JZ LJump if zero to tag Lif (!F) PC=L
LD y xLoad register with x*y=x
LDA xLoad accumulator with xA=x
MLT xMultiply x with accumulatorA*=x; F=A
MOD xModulus x with accumulatorA%=x; F=A
OR xOr x with accumulatorA|=x; F=A
POP yPop registery=pop()
POPAPop accumulatorA=pop()
PUSH yPush registerpush(y)
PUSHAPush accumulatorpush(A)
RETReturn from subroutinePC=pop()
RL y xRotate left register x bits*y<<=x; F=*y
RLA xRotate left accumulator x bitsA<<=x; F=A
RR y xRotate right register x bits*y>>=x; F=*y
RRA xRotate right accumulator x bitsA>>=x; F=A
STA yStore accumulator in registery=A
SUB xSubtract x from accumulatorA-=x; F=A
SYS strRun external script (/opt/pigpio/cgi/str)system(str); F=A
TAG LLabel the current script positionN/A
WAIT xWait for a GPIO in x to change stateA=wait(x); F=A
X y1 y2Exchange contents of registers y1 and y2t=*y1;*y1=*y2;*y2=t
XA yExchange contents of accumulator and registert=A;A=*y;*y=t
XOR xXor x with accumulatorA^=x; F=A


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

+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/piscope.html b/DOC/HTML/piscope.html new file mode 100644 index 0000000..643cd03 --- /dev/null +++ b/DOC/HTML/piscope.html @@ -0,0 +1,269 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

piscope

+

Introduction

+piscope is a logic analyser (digital +waveform viewer) for the Raspberry.  It shows the state (high +or low) of selected GPIO in real-time.
+
+See video.
+
+piscope uses the services of the pigpio library.  pigpio needs to be running on +the Pi whose GPIO are to be monitored.
+
+The pigpio library may be started as a daemon (background process) +by the following command.
+
+sudo pigpiod

+piscope may be invoked in several different ways
+
+ + + + + + + + + + + + + + + + + + + + + + + +
Pi
pi_host ~ $ piscope +&
Pi captures +data
+Pi processes data
+Pi displays data
Pi plus Linux PC
+
+(with the
+display on a remote
+  Linux PC)
remote_host ~ $ ssh -X pi_host
pi_host ~ $ piscope +&
Pi captures data
+Pi processes data
+Remote Linux PC displays data
Pi plus Windows PC
+
+(with the
+display on a remote
+  Windows PC)
You need to install an SSH +client (putty suggested) and a X11 server (xming suggested).
+
+Run Program Files -> Xming -> XLaunch and accept the +defaults.
+
+Run putty and enter the Pi's host name or IP address.  Click +on SSH X11 and tick Enable X11 forwarding and then select +Open.

+
pi_host ~ $ piscope +&
Pi captures data
+Pi processes data
+Remote Windows PC displays data
Pi plus Linux PC
+
+(with the display and processing on a remote Linux +PC)
remote_host ~ $ export +PIGPIO_ADDR=pi_host
+remote_host ~ $ piscope +&
Pi captures data
+Remote processes data
+Remote displays data
+
+piscope operates in one of three modes
+
+ + + + + + + + + + + + + + + + + + +
Live
The latest GPIO samples are +displayed.
+
+The mode will automatically change to Pause if a sampling trigger +is detected.
+
+There are four triggers.  Each trigger is made up of a +combination of GPIO states (one of don't care, low, high, edge, +falling, or rising per GPIO).  Triggers are always +counted.  In addition a trigger may be sample to, sample +around, or sample from, a so called sampling trigger.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full the oldest samples are discarded.
Play
Recorded GPIO samples are +displayed.
+
+The play speed may be varied between 64 times real-time to 1/32768 +of real-time.
+
+The page up key increases the play speed by a factor of 2.  +The page down key decreases the play speed by a factor of 2.  +The home key sets the play speed to 1X.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full new samples are discarded.
Pause
Recorded GPIO samples are +displayed.
+
+The left and right cursor keys move the blue marker to the previous +or next edge.  By default all GPIO edges are considered.  +Clicking on a GPIO name will limit edge searches to the highlighted +GPIO only.
+
+The left and right square bracket keys move the blue marker to the +previous or next trigger.
+
+The time between the blue and gold markers is displayed.  The +gold marker is set to the blue marker by a press of the 'g' +key.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full new samples are discarded.
+
+In all modes the down and up cursor keys zoom the time scale in and +out.
+
+Samples can be saved with File Save All Samples or File Save +Selected Samples. +

To select samples enter pause mode. Press 1 to specify the start +of the samples (green marker) and 2 to specify the end of the +samples (red marker).

+

The samples may be saved in the native piscope format or in VCD +format.

+

Data saved in VCD format may be viewed and further processed +with GTKWave.

+

Data saved in the native piscope format may be restored later +with File Restore Saved Data.

+

Installation

+

To download and install piscope.

+

Pi (pre-built image)

+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make hf
+make install

+

Linux 64 bit X86/AMD (pre-built image)

+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make x86_64
+make install
+

All machines (building from source)

+You only need to perform this step if you want to build the +executable from the source files.  This is not needed if you +use a pre-built image.
+
+WARNING
: Installing gtk+-3.0 uses a lot of SD card +space.
+
+Most of the space used by gtk+-3.0 is taken up by unneeded *-dbg +packages.
+
+With *-dbg packages an additional 3753MB SD space is required.
+
+If you edit the list of packages to be downloaded and remove the +*-dbg packages only 134MB of additional SD space is needed (as at +the time of writing).
+
+#
# *** This may take a lot of time and use +a lot of SD card space ***
#
+sudo apt-get install gtk+-3.0
#
+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make
+make install

+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/python.html b/DOC/HTML/python.html new file mode 100644 index 0000000..8b3b013 --- /dev/null +++ b/DOC/HTML/python.html @@ -0,0 +1,1293 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Python Interface

pigpio is a Python module for the Raspberry which talks to +the pigpio daemon to allow control of the general purpose +input outputs (GPIO). +

Features

o the pigpio Python module can run on Windows, Macs, or Linux +

o controls one or more Pi's +

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o callbacks when any of GPIO 0-31 change state +

o creating and transmitting precisely timed waveforms +

o reading/writing GPIO and setting their modes +

o wrappers for I2C, SPI, and serial links +

o creating and running scripts on the pigpio daemon +

GPIO

ALL GPIO are identified by their Broadcom number. +

Notes

Transmitted waveforms are accurate to a microsecond. +

Callback level changes are time-stamped and will be +accurate to within a few microseconds. +

Settings

A number of settings are determined when the pigpio daemon is started. +

o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). +

o the set of GPIO which may be updated (generally written to). The + default set is those available on the Pi board revision. +

o the available PWM frequencies (see set_PWM_frequency). +

Exceptions

By default a fatal exception is raised if you pass an invalid +argument to a pigpio function. +

If you wish to handle the returned status yourself you should set +pigpio.exceptions to False. +

You may prefer to check the returned status in only a few parts +of your code. In that case do the following: +

Example

pigpio.exceptions = False

# Code where you want to test the error status.

pigpio.exceptions = True

Usage

This module uses the services of the C pigpio library. pigpio +must be running on the Pi(s) whose GPIO are to be manipulated. +

The normal way to start pigpio is as a daemon (during system +start). +

sudo pigpiod +

Your Python program must import pigpio and create one or more +instances of the pigpio.pi class. This class gives access to +a specified Pi's GPIO. +

Example

pi1 = pigpio.pi()       # pi1 accesses the local Pi's GPIO
pi2 = pigpio.pi('tom')  # pi2 accesses tom's GPIO
pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO

pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4)     # get level of dick's GPIO 4


The later example code snippets assume that pi is an instance of +the pigpio.pi class. +

OVERVIEW

ESSENTIAL +
pigpio.pi Initialise Pi connection +
stop Stop a Pi connection +
BASIC +
set_mode Set a GPIO mode +
get_mode Get a GPIO mode +
set_pull_up_down Set/clear GPIO pull up/down resistor +
read Read a GPIO +
write Write a GPIO +
PWM (overrides servo commands on same GPIO) +
set_PWM_dutycycle Start/stop PWM pulses on a GPIO +
set_PWM_frequency Set PWM frequency of a GPIO +
set_PWM_range Configure PWM range of a GPIO +
get_PWM_dutycycle Get PWM dutycycle set on a GPIO +
get_PWM_frequency Get PWM frequency of a GPIO +
get_PWM_range Get configured PWM range of a GPIO +
get_PWM_real_range Get underlying PWM range for a GPIO +
Servo (overrides PWM commands on same GPIO) +
set_servo_pulsewidth Start/Stop servo pulses on a GPIO +
get_servo_pulsewidth Get servo pulsewidth set on a GPIO +
INTERMEDIATE +
gpio_trigger Send a trigger pulse to a GPIO +
set_watchdog Set a watchdog on a GPIO +
read_bank_1 Read all bank 1 GPIO +
read_bank_2 Read all bank 2 GPIO +
clear_bank_1 Clear selected GPIO in bank 1 +
clear_bank_2 Clear selected GPIO in bank 2 +
set_bank_1 Set selected GPIO in bank 1 +
set_bank_2 Set selected GPIO in bank 2 +
callback Create GPIO level change callback +
wait_for_edge Wait for GPIO level change +
ADVANCED +
notify_open Request a notification handle +
notify_begin Start notifications for selected GPIO +
notify_pause Pause notifications +
notify_close Close a notification +
hardware_clock Start hardware clock on supported GPIO +
hardware_PWM Start hardware PWM on supported GPIO +
set_glitch_filter Set a glitch filter on a GPIO +
set_noise_filter Set a noise filter on a GPIO +
set_pad_strength Sets a pads drive strength +
get_pad_strength Gets a pads drive strength +
shell Executes a shell command +
Custom +
custom_1 User custom function 1 +
custom_2 User custom function 2 +
Events +
event_callback Sets a callback for an event +
event_trigger Triggers an event +
wait_for_event Wait for an event +
Scripts +
store_script Store a script +
run_script Run a stored script +
update_script Set a scripts parameters +
script_status Get script status and parameters +
stop_script Stop a running script +
delete_script Delete a stored script +
I2C +
i2c_open Opens an I2C device +
i2c_close Closes an I2C device +
i2c_write_quick SMBus write quick +
i2c_read_byte SMBus read byte +
i2c_write_byte SMBus write byte +
i2c_read_byte_data SMBus read byte data +
i2c_write_byte_data SMBus write byte data +
i2c_read_word_data SMBus read word data +
i2c_write_word_data SMBus write word data +
i2c_read_block_data SMBus read block data +
i2c_write_block_data SMBus write block data +
i2c_read_i2c_block_data SMBus read I2C block data +
i2c_write_i2c_block_data SMBus write I2C block data +
i2c_read_device Reads the raw I2C device +
i2c_write_device Writes the raw I2C device +
i2c_process_call SMBus process call +
i2c_block_process_call SMBus block process call +
i2c_zip Performs multiple I2C transactions +
I2C BIT BANG +
bb_i2c_open Opens GPIO for bit banging I2C +
bb_i2c_close Closes GPIO for bit banging I2C +
bb_i2c_zip Performs multiple bit banged I2C transactions +
I2C/SPI SLAVE +
bsc_xfer I2C/SPI as slave transfer +
bsc_i2c I2C as slave transfer +
SERIAL +
serial_open Opens a serial device +
serial_close Closes a serial device +
serial_read_byte Reads a byte from a serial device +
serial_write_byte Writes a byte to a serial device +
serial_read Reads bytes from a serial device +
serial_write Writes bytes to a serial device +
serial_data_available Returns number of bytes ready to be read +
SERIAL BIT BANG (read only) +
bb_serial_read_open Open a GPIO for bit bang serial reads +
bb_serial_read_close Close a GPIO for bit bang serial reads +
bb_serial_invert Invert serial logic (1 invert, 0 normal) +
bb_serial_read Read bit bang serial data from a GPIO +
SPI +
spi_open Opens a SPI device +
spi_close Closes a SPI device +
spi_read Reads bytes from a SPI device +
spi_write Writes bytes to a SPI device +
spi_xfer Transfers bytes with a SPI device +
SPI BIT BANG +
bb_spi_open Opens GPIO for bit banging SPI +
bb_spi_close Closes GPIO for bit banging SPI +
bb_spi_xfer Transfers bytes with bit banging SPI +
FILES +
file_open Opens a file +
file_close Closes a file +
file_read Reads bytes from a file +
file_write Writes bytes to a file +
file_seek Seeks to a position within a file +
file_list List files which match a pattern +
WAVES +
wave_clear Deletes all waveforms +
wave_add_new Starts a new waveform +
wave_add_generic Adds a series of pulses to the waveform +
wave_add_serial Adds serial data to the waveform +
wave_create Creates a waveform from added data +
wave_create_and_pad Creates a waveform of fixed size from added data +
wave_delete Deletes a waveform +
wave_send_once Transmits a waveform once +
wave_send_repeat Transmits a waveform repeatedly +
wave_send_using_mode Transmits a waveform in the chosen mode +
wave_chain Transmits a chain of waveforms +
wave_tx_at Returns the current transmitting waveform +
wave_tx_busy Checks to see if a waveform has ended +
wave_tx_stop Aborts the current waveform +
wave_get_cbs Length in cbs of the current waveform +
wave_get_max_cbs Absolute maximum allowed cbs +
wave_get_micros Length in microseconds of the current waveform +
wave_get_max_micros Absolute maximum allowed micros +
wave_get_pulses Length in pulses of the current waveform +
wave_get_max_pulses Absolute maximum allowed pulses +
UTILITIES +
get_current_tick Get current tick (microseconds) +
get_hardware_revision Get hardware revision +
get_pigpio_version Get the pigpio version +
pigpio.error_text Gets error text from error number +
pigpio.tickDiff Returns difference between two ticks +

class pi +

pigpio.pi(host, port, show_errors)

+Grants access to a Pi's GPIO. +

Parameters

host:= the host name of the Pi on which the pigpio daemon is
       running.  The default is localhost unless overridden by
       the PIGPIO_ADDR environment variable.


Parameters

port:= the port number on which the pigpio daemon is listening.
       The default is 8888 unless overridden by the PIGPIO_PORT
       environment variable.  The pigpio daemon must have been
       started with the same port number.


This connects to the pigpio daemon and reserves resources +to be used for sending commands and receiving notifications. +

An instance attribute connected may be used to check the +success of the connection. If the connection is established +successfully connected will be True, otherwise False. +

Example

pi = pigio.pi()              # use defaults
pi = pigpio.pi('mypi')       # specify host, default port
pi = pigpio.pi('mypi', 7777) # specify host and port

pi = pigpio.pi()             # exit script if no connection
if not pi.connected:
   exit()

__repr__()

+

bb_i2c_close(SDA)

+This function stops bit banging I2C on a pair of GPIO +previously opened with bb_i2c_open. +

Parameters

SDA:= 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +

Example

pi.bb_i2c_close(SDA)

bb_i2c_open(SDA, SCL, baud)

+This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. +

Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. +

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

Parameters

 SDA:= 0-31
 SCL:= 0-31
baud:= 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. +

NOTE: +

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. +As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. +

Example

h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps

bb_i2c_zip(SDA, data)

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

Parameters

 SDA:= 0-31 (as used in a prior call to bb_i2c_open)
data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(count, data) = pi.bb_i2c_zip(
                   SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0])


The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

Any read I2C data is concatenated in the returned bytearray. +

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

bb_serial_invert(user_gpio, invert)

+Invert serial logic. +

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)
    invert:= 0-1 (1 invert, 0 normal)


Example

status = pi.bb_serial_invert(17, 1)

bb_serial_read(user_gpio)

+Returns data from the bit bang serial cyclic buffer. +

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

The bytes returned for each character depend upon the number of +data bits bb_bits specified in the bb_serial_read_open +command. +

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

Example

(count, data) = pi.bb_serial_read(4)

bb_serial_read_close(user_gpio)

+Closes a GPIO for bit bang reading of serial data. +

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


Example

status = pi.bb_serial_read_close(17)

bb_serial_read_open(user_gpio, baud, bb_bits)

+Opens a GPIO for bit bang reading of serial data. +

Parameters

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


The serial data is held in a cyclic buffer and is read using +bb_serial_read. +

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

Example

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

bb_spi_close(CS)

+This function stops bit banging SPI on a set of GPIO +opened with bb_spi_open. +

Parameters

CS:= 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. +

Example

pi.bb_spi_close(CS)

bb_spi_open(CS, MISO, MOSI, SCLK, baud, spi_flags)

+This function selects a set of GPIO for bit banging SPI at a +specified baud rate. +

Parameters

      CS := 0-31
    MISO := 0-31
    MOSI := 0-31
    SCLK := 0-31
    baud := 50-250000
spiFlags := see below


spiFlags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 +

Mode CPOL CPHA
 0     0    0
 1     0    1
 2     1    0
 3     1    1


The following constants may be used to set the mode: +

pigpio.SPI_MODE_0
pigpio.SPI_MODE_1
pigpio.SPI_MODE_2
pigpio.SPI_MODE_3


Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA +may be used. +

p is 0 if CS is active low (default) and 1 for active high. +pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag. +

T is 1 if the least significant bit is transmitted on MOSI first, +the default (0) shifts the most significant bit out first. +pigpio.SPI_TX_LSBFIRST may be used to set this flag. +

R is 1 if the least significant bit is received on MISO first, +the default (0) receives the most significant bit first. +pigpio.SPI_RX_LSBFIRST may be used to set this flag. +

The other bits in spiFlags should be set to zero. +

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or +PI_GPIO_IN_USE. +

If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. +

Example

bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2

bb_spi_xfer(CS, data)

+This function executes a bit banged SPI transfer. +

Parameters

  CS:= 0-31 (as used in a prior call to bb_spi_open)
data:= data to be sent


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

#!/usr/bin/env python

import pigpio

CE0=5
CE1=6
MISO=13
MOSI=19
SCLK=12

pi = pigpio.pi()
if not pi.connected:
   exit()

pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC
pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC

for i in range(256):

   count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value

   if count == 2:

      count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC

      if count == 2:

         set_val = data[1]

         count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC

         if count == 3:

            read_val = ((data[1]&3)<<8) | data[2]

            print("{} {}".format(set_val, read_val))

pi.bb_spi_close(CE0)
pi.bb_spi_close(CE1)

pi.stop()

bsc_i2c(i2c_address, data)

+This function allows the Pi to act as a slave I2C device. +

This function is not available on the BCM2711 (e.g. as +used in the Pi4B). +

The data bytes (if any) are written to the BSC transmit +FIFO and the bytes in the BSC receive FIFO are returned. +

Parameters

i2c_address:= the I2C slave address.
       data:= the data bytes to transmit.


The returned value is a tuple of the status, the number +of bytes read, and a bytearray containing the read bytes. +

See bsc_xfer for details of the status value. +

If there was an error the status will be less than zero +(and will contain the error code). +

Note that an i2c_address of 0 may be used to close +the BSC device and reassign the used GPIO as inputs. +

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

Example

#!/usr/bin/env python
import time
import pigpio

I2C_ADDR=0x13

def i2c(id, tick):
    global pi

    s, b, d = pi.bsc_i2c(I2C_ADDR)
    if b:
        if d[0] == ord('t'): # 116 send 'HH:MM:SS*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[11:19]))

        elif d[0] == ord('d'): # 100 send 'Sun Oct 30*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[:10]))

pi = pigpio.pi()

if not pi.connected:
    exit()

# Respond to BSC slave activity

e = pi.event_callback(pigpio.EVENT_BSC, i2c)

pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave

time.sleep(600)

e.cancel()

pi.bsc_i2c(0) # Disable BSC peripheral

pi.stop()


While running the above. +

$ i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

$ pigs i2co 1 0x13 0
0

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:13:58*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:14:29*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:23:16*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

bsc_xfer(bsc_control, data)

+This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. +

This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. +

This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. +

The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. +

I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. +

The function sets the BSC mode, writes any data in +the transmit buffer to the BSC transmit FIFO, and +copies any data in the BSC receive FIFO to the +receive buffer. +

Parameters

bsc_control:= see below
       data:= the data bytes to place in the transmit FIFO.


The returned value is a tuple of the status (see below), +the number of bytes read, and a bytearray containing the +read bytes. If there was an error the status will be less +than zero (and will contain the error code). +

Note that the control word sets the BSC mode. The BSC will +stay in that mode until a different control word is sent. +

GPIO used for models other than those based on the BCM2711. +

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset +to INPUT mode. +

bsc_control consists of the following bits: +

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. +

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable BSC peripheral


The status has the following format: +

20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 S  S  S  S  S  R  R  R  R  R  T  T  T  T  T RB TE RF TF RE TB


Bits 0-15 are copied unchanged from the BSC FR register. See +pages 165-166 of the Broadcom peripherals document for full +details. +

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


Example

(status, count, data) = pi.bsc_xfer(0x330305, "Hello!")

callback(user_gpio, edge, func)

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

Parameters

user_gpio:= 0-31.
     edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.
     func:= user supplied callback function.


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

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


If a user callback is not specified a default tally callback is +provided which simply counts edges. The count may be retrieved +by calling the tally function. The count may be reset to zero +by calling the reset_tally function. +

The callback may be cancelled by calling the cancel function. +

A GPIO may have multiple callbacks (although I can't think of +a reason to do so). +

The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). +

The number of samples per second is given in the following table. +

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. +

The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. +

If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use read. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. +

Example

def cbf(gpio, level, tick):
   print(gpio, level, tick)

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

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

cb3 = pi.callback(17)

print(cb3.tally())

cb3.reset_tally()

cb1.cancel() # To cancel callback cb1.

clear_bank_1(bits)

+Clears GPIO 0-31 if the corresponding bit in bits is set. +

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user +is not allowed to write to one or more of the GPIO. +

Example

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

clear_bank_2(bits)

+Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user +is not allowed to write to one or more of the GPIO. +

Example

pi.clear_bank_2(0x1010)

custom_1(arg1, arg2, argx)

+Calls a pigpio function customised by the user. +

Parameters

arg1:= >=0, default 0.
arg2:= >=0, default 0.
argx:= extra arguments (each 0-255), default empty.


The returned value is an integer which by convention +should be >=0 for OK and <0 for error. +

Example

value = pi.custom_1()

value = pi.custom_1(23)

value = pi.custom_1(0, 55)

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

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

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

custom_2(arg1, argx, retMax)

+Calls a pigpio function customised by the user. +

Parameters

  arg1:= >=0, default 0.
  argx:= extra arguments (each 0-255), default empty.
retMax:= >=0, maximum number of bytes to return, default 8192.


The returned value is a tuple of the number of bytes +returned and a bytearray containing the bytes. If +there was an error the number of bytes read will be +less than zero (and will contain the error code). +

Example

(count, data) = pi.custom_2()

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

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

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

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

delete_script(script_id)

+Deletes a stored script. +

Parameters

script_id:= id of stored script.


Example

status = pi.delete_script(sid)

event_callback(event, func)

+Calls a user supplied function (a callback) whenever the +specified event is signalled. +

Parameters

event:= 0-31.
 func:= user supplied callback function.


The user supplied callback receives two parameters, the event id, +and the tick. +

If a user callback is not specified a default tally callback is +provided which simply counts events. The count may be retrieved +by calling the tally function. The count may be reset to zero +by calling the reset_tally function. +

The callback may be cancelled by calling the event_cancel function. +

An event may have multiple callbacks (although I can't think of +a reason to do so). +

Example

def cbf(event, tick):
   print(event, tick)

cb1 = pi.event_callback(22, cbf)

cb2 = pi.event_callback(4)

print(cb2.tally())

cb2.reset_tally()

cb1.event_cancel() # To cancel callback cb1.

event_trigger(event)

+This function signals the occurrence of an event. +

Parameters

event:= 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

An event is a signal used to inform one or more consumers +to start an action. Each consumer which has registered an +interest in the event (e.g. by calling event_callback) will +be informed by a callback. +

One event, EVENT_BSC (31) is predefined. This event is +auto generated on BSC slave activity. +

The meaning of other events is arbitrary. +

Note that other than its id and its tick there is no data associated +with an event. +

Example

pi.event_trigger(23)

file_close(handle)

+Closes the file associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to file_open).


Example

pi.file_close(handle)

file_list(fpattern)

+Returns a list of files which match a pattern. +

Parameters

fpattern:= file pattern to match.


Returns the number of returned bytes if OK, otherwise +PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. +

The pattern must match an entry in /opt/pigpio/access. The +pattern may contain wildcards. See file_open. +

NOTE +

The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. +

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

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

c, d = pi.file_list("/ram/p*.c")
if c > 0:
   print(d)

pi.stop()

file_open(file_name, file_mode)

+This function returns a handle to a file opened in a specified mode. +

Parameters

file_name:= the file to open.
file_mode:= the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, +PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE, +PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. +

Example

h = pi.file_open("/home/pi/shared/dir_3/file.txt",
        pigpio.FILE_WRITE | pigpio.FILE_CREATE)

pi.file_write(h, "Hello world")

pi.file_close(h)


File +

A file may only be opened if permission is granted by an entry +in /opt/pigpio/access. This is intended to allow remote access +to files in a more or less controlled manner. +

Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. +

Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. +

Suppose /opt/pigpio/access contains the following entries: +

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception +of file.txt. +

Files may be read in directory dir_2. +

Files may be read and written in directory dir_3. +

If a directory allows read, write, or read/write access then files +may be created in that directory. +

In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access: +

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode +

The mode may have the following values: +

ConstantValueMeaning
FILE_READ1open file for reading
FILE_WRITE2open file for writing
FILE_RW3open file for reading and writing


The following values may be or'd into the mode: +

NameValueMeaning
FILE_APPEND4All writes append data to the end of the file
FILE_CREATE8The file is created if it doesn't exist
FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner +read and write. +

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

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

handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ)

done = False

while not done:
   c, d = pi.file_read(handle, 60000)
   if c > 0:
      print(d)
   else:
      done = True

pi.file_close(handle)

pi.stop()

file_read(handle, count)

+Reads up to count bytes from the file associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to file_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.file_read(h2, 100)
if b > 0:
   # process read data

file_seek(handle, seek_offset, seek_from)

+Seeks to a position relative to the start, current position, +or end of the file. Returns the new position. +

Parameters

     handle:= >=0 (as returned by a prior call to file_open).
seek_offset:= byte offset.
  seek_from:= FROM_START, FROM_CURRENT, or FROM_END.


Example

new_pos = pi.file_seek(h, 100, pigpio.FROM_START)

cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT)

file_size = pi.file_seek(h, 0, pigpio.FROM_END)

file_write(handle, data)

+Writes the data bytes to the file associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to file_open).
  data:= the bytes to write.


Example

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

pi.file_write(h2, b'help')

pi.file_write(h2, "hello")

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

get_PWM_dutycycle(user_gpio)

+Returns the PWM dutycycle being used on the GPIO. +

Parameters

user_gpio:= 0-31.


Returns the PWM dutycycle. +

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

If a hardware clock is active on the GPIO the reported +dutycycle will be 500000 (500k) out of 1000000 (1M). +

If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). +

Example

pi.set_PWM_dutycycle(4, 25)
print(pi.get_PWM_dutycycle(4))
25

pi.set_PWM_dutycycle(4, 203)
print(pi.get_PWM_dutycycle(4))
203

get_PWM_frequency(user_gpio)

+Returns the frequency of PWM being used on the GPIO. +

Parameters

user_gpio:= 0-31.


Returns the frequency (in Hz) used for the GPIO. +

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

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

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

Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_frequency(4))
800

get_PWM_range(user_gpio)

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

Parameters

user_gpio:= 0-31.


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

Example

pi.set_PWM_range(9, 500)
print(pi.get_PWM_range(9))
500

get_PWM_real_range(user_gpio)

+Returns the real (underlying) range of PWM values being +used on the GPIO. +

Parameters

user_gpio:= 0-31.


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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

Example

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_real_range(4))
250

get_current_tick()

+Returns the current system tick. +

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

Example

t1 = pi.get_current_tick()
time.sleep(1)
t2 = pi.get_current_tick()

get_hardware_revision()

+Returns the Pi's hardware revision number. +

The hardware revision is the last few characters on the +Revision line of /proc/cpuinfo. +

The revision number can be used to determine the assignment +of GPIO to pins (see
gpio). +

There are at least three types of board. +

Type 1 boards have hardware revision numbers of 2 and 3. +

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. +

Type 3 boards have hardware revision numbers of 16 or greater. +

If the hardware revision can not be found or is not a valid +hexadecimal number the function returns 0. +

Example

print(pi.get_hardware_revision())
2

get_mode(gpio)

+Returns the GPIO mode. +

Parameters

gpio:= 0-53.


Returns a value as follows +

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


Example

print(pi.get_mode(0))
4

get_pad_strength(pad)

+This function returns the pad drive strength in mA. +

Parameters

pad:= 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. +

PadGPIO
00-27
128-45
246-53


Example

strength = pi.get_pad_strength(0) # Get pad 0 strength.

get_pigpio_version()

+Returns the pigpio software version. +

Example

v = pi.get_pigpio_version()

get_servo_pulsewidth(user_gpio)

+Returns the servo pulsewidth being used on the GPIO. +

Parameters

user_gpio:= 0-31.


Returns the servo pulsewidth. +

Example

pi.set_servo_pulsewidth(4, 525)
print(pi.get_servo_pulsewidth(4))
525

pi.set_servo_pulsewidth(4, 2130)
print(pi.get_servo_pulsewidth(4))
2130

gpio_trigger(user_gpio, pulse_len, level)

+Send a trigger pulse to a GPIO. The GPIO is set to +level for pulse_len microseconds and then reset to not level. +

Parameters

user_gpio:= 0-31
pulse_len:= 1-100
    level:= 0-1


Example

pi.gpio_trigger(23, 10, 1)

hardware_PWM(gpio, PWMfreq, PWMduty)

+Starts hardware PWM on a GPIO at the specified frequency +and dutycycle. Frequencies above 30MHz are unlikely to work. +

NOTE: Any waveform started by wave_send_once, +wave_send_repeat, or wave_chain will be cancelled. +

This function is only valid if the pigpio main clock is PCM. +The main clock defaults to PCM but may be overridden when the +pigpio daemon is started (option -t). +

Parameters

   gpio:= see descripton
PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711).
PWMduty:= 0 (off) to 1000000 (1M)(fully on).


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. +

The same PWM channel is available on multiple GPIO. +The latest frequency and dutycycle setting will be used +by all GPIO which share a PWM channel. +

The GPIO must be one of the following: +

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). +

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

There will only be a million steps for a PWMfreq of 250 +(375 for the BCM2711). Lower frequencies will have more +steps and higher frequencies will have fewer steps. +PWMduty is automatically scaled to take this into account. +

Example

pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle

pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle

hardware_clock(gpio, clkfreq)

+Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. +

Parameters

   gpio:= see description
clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. +

The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. +

The GPIO must be one of the following: +

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will +likely crash the Pi. The password is given by or'ing 0x5A000000 +with the GPIO number. +

Example

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

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

i2c_block_process_call(handle, reg, data)

+Writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


The SMBus 2.0 documentation states that a minimum of 1 byte may +be sent and a minimum of 1 byte may be received. The total +number of bytes sent/received must be 32 or less. +

SMBus 2.0 5.5.8 - Block write-block read. +S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A]
   S Addr Rd [A] [Count] A [Data] ... A P


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00')

(b, d) = pi.i2c_block_process_call(h, 10, b'abcdr')

(b, d) = pi.i2c_block_process_call(h, 10, "abracad")

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

i2c_close(handle)

+Closes the I2C device associated with handle. +

Parameters

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


Example

pi.i2c_close(h)

i2c_open(i2c_bus, i2c_address, i2c_flags)

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

Parameters

    i2c_bus:= >=0.
i2c_address:= 0-0x7F.
  i2c_flags:= 0, no flags are currently defined.


Physically buses 0 and 1 are available on the Pi. Higher +numbered buses will be available if a kernel supported bus +multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


For the SMBus commands the low level transactions are shown +at the end of the function description. The following +abbreviations are used: +

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.
Addr  (7 bits): I2C 7 bit address.
reg   (8 bits): Command byte, which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.


Example

h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1

i2c_process_call(handle, reg, word_val)

+Writes 16 bits of data to the specified register of the device +associated with handle and reads 16 bits of data in return. +

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.6 - Process call. +S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

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

i2c_read_block_data(handle, reg)

+Reads a block of up to 32 bytes from the specified register of +the device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.7 - Block read. +S Addr Wr [A] reg [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P


The amount of returned data is set by the device. +

The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.i2c_read_block_data(h, 10)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_byte(handle)

+Reads a single byte from the device associated with handle. +

Parameters

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


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


Example

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

i2c_read_byte_data(handle, reg)

+Reads a single byte from the specified register of the device +associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read byte. +S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P


Example

# read byte from reg 17 of device 2
b = pi.i2c_read_byte_data(2, 17)

# read byte from reg  1 of device 0
b = pi.i2c_read_byte_data(0, 1)

i2c_read_device(handle, count)

+Returns count bytes read from the raw device associated +with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
 count:= >0, the number of bytes to read.


S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(count, data) = pi.i2c_read_device(h, 12)

i2c_read_i2c_block_data(handle, reg, count)

+Reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
 count:= >0, the number of bytes to read.


S Addr Wr [A] reg [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.i2c_read_i2c_block_data(h, 4, 32)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_word_data(handle, reg)

+Reads a single 16 bit word from the specified register of the +device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read word. +S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

# read word from reg 2 of device 3
w = pi.i2c_read_word_data(3, 2)

# read word from reg 7 of device 2
w = pi.i2c_read_word_data(2, 7)

i2c_write_block_data(handle, reg, data)

+Writes up to 32 bytes to the specified register of the device +associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


SMBus 2.0 5.5.7 - Block write. +S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A]
   datan [A] P


Example

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

pi.i2c_write_block_data(4, 5, "data bytes")

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

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

i2c_write_byte(handle, byte_val)

+Sends a single byte to the device associated with handle. +

Parameters

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


SMBus 2.0 5.5.2 - Send byte. +S Addr Wr [A] byte_val [A] P


Example

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

i2c_write_byte_data(handle, reg, byte_val)

+Writes a single byte to the specified register of the device +associated with handle. +

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.4 - Write byte. +S Addr Wr [A] reg [A] byte_val [A] P


Example

# send byte 0xC5 to reg 2 of device 1
pi.i2c_write_byte_data(1, 2, 0xC5)

# send byte 9 to reg 4 of device 2
pi.i2c_write_byte_data(2, 4, 9)

i2c_write_device(handle, data)

+Writes the data bytes to the raw device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the bytes to write.


S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P


Example

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

pi.i2c_write_device(h, b"help")

pi.i2c_write_device(h, 'help')

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

i2c_write_i2c_block_data(handle, reg, data)

+Writes data bytes to the specified register of the device +associated with handle . 1-32 bytes may be written. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P


Example

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

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

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

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

i2c_write_quick(handle, bit)

+Sends a single bit to the device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   bit:= 0 or 1, the value to write.


SMBus 2.0 5.5.1 - Quick command. +S Addr bit [A] P


Example

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

i2c_write_word_data(handle, reg, word_val)

+Writes a single 16 bit word to the specified register of the +device associated with handle. +

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.4 - Write word. +S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P


Example

# send word 0xA0C5 to reg 5 of device 4
pi.i2c_write_word_data(4, 5, 0xA0C5)

# send word 2 to reg 2 of device 5
pi.i2c_write_word_data(5, 2, 23)

i2c_zip(handle, data)

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

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0])


The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. +

Any read I2C data is concatenated in the returned bytearray. +

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

notify_begin(handle, bits)

+Starts notifications on a handle. +

Parameters

handle:= >=0 (as returned by a prior call to notify_open)
  bits:= a 32 bit mask indicating the GPIO to be notified.


The notification sends state changes for each GPIO whose +corresponding bit in bits is set. +

The following code starts notifications for GPIO 1, 4, +6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). +

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_close(handle)

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

Parameters

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


Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_close(h)
   ...

notify_open()

+Returns a notification handle (>=0). +

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

Pipes are only accessible from the local machine so this +function serves no purpose if you are using Python from a +remote machine. The in-built (socket) notifications +provided by
callback should be used instead. +

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

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

Notifications have the following structure: +

H seqno
H flags
I tick
I level


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

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, +PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. +

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the +flags indicate a GPIO which has had a watchdog timeout. +

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep +alive signal on the pipe/socket and is sent once a minute +in the absence of other notification activity. +

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the +flags indicate an event which has been triggered. +

tick: the number of microseconds since system boot. It wraps +around after 1h12m. +

level: indicates the level of each GPIO. If bit 1<<x is set +then GPIO x is high. +

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_pause(handle)

+Pauses notifications on a handle. +

Parameters

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


Notifications for the handle are suspended until +notify_begin is called again. +

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_pause(h)
   ...
   pi.notify_begin(h, 1234)
   ...

read(gpio)

+Returns the GPIO level. +

Parameters

gpio:= 0-53.


Example

pi.set_mode(23, pigpio.INPUT)

pi.set_pull_up_down(23, pigpio.PUD_DOWN)
print(pi.read(23))
0

pi.set_pull_up_down(23, pigpio.PUD_UP)
print(pi.read(23))
1

read_bank_1()

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

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

Example

print(bin(pi.read_bank_1()))
0b10010100000011100100001001111

read_bank_2()

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

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

Example

print(bin(pi.read_bank_2()))
0b1111110000000000000000

run_script(script_id, params)

+Runs a stored script. +

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.run_script(sid, [par1, par2])

s = pi.run_script(sid)

s = pi.run_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

script_status(script_id)

+Returns the run status of a stored script as well as the +current values of parameters 0 to 9. +

Parameters

script_id:= id of stored script.


The run status may be +

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The return value is a tuple of run status and a list of +the 10 parameters. On error the run status will be negative +and the parameter list will be empty. +

Example

(s, pars) = pi.script_status(sid)

serial_close(handle)

+Closes the serial device associated with handle. +

Parameters

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


Example

pi.serial_close(h1)

serial_data_available(handle)

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

Parameters

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


Example

rdy = pi.serial_data_available(h1)

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

serial_open(tty, baud, ser_flags)

+Returns a handle for the serial tty device opened +at baud bits per second. The device name must start +with /dev/tty or /dev/serial. +

Parameters

      tty:= the serial device to open.
     baud:= baud rate in bits per second, see below.
ser_flags:= 0, no flags are currently defined.


Normally you would only use the serial_* functions if +you are or will be connecting to the Pi over a network. If +you will always run on the local Pi use the standard serial +module instead. +

The baud rate must be one of 50, 75, 110, 134, 150, +200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, +38400, 57600, 115200, or 230400. +

Example

h1 = pi.serial_open("/dev/ttyAMA0", 300)

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

h3 = pi.serial_open("/dev/serial0", 9600)

serial_read(handle, count)

+Reads up to count bytes from the device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
 count:= >0, the number of bytes to read (defaults to 1000).


The returned value is a tuple of the number of bytes read and +a bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

If no data is ready a bytes read of zero is returned. +Example

(b, d) = pi.serial_read(h2, 100)
if b > 0:
   # process read data

serial_read_byte(handle)

+Returns a single byte from the device associated with handle. +

Parameters

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


If no data is ready a negative error code will be returned. +

Example

b = pi.serial_read_byte(h1)

serial_write(handle, data)

+Writes the data bytes to the device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
  data:= the bytes to write.


Example

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

pi.serial_write(h2, b'help')

pi.serial_write(h2, "hello")

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

serial_write_byte(handle, byte_val)

+Writes a single byte to the device associated with handle. +

Parameters

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


Example

pi.serial_write_byte(h1, 23)

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

set_PWM_dutycycle(user_gpio, dutycycle)

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

Parameters

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


The set_PWM_range function can change the default range of 255. +

Example

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

set_PWM_frequency(user_gpio, frequency)

+Sets the frequency (in Hz) of the PWM to be used on the GPIO. +

Parameters

user_gpio:= 0-31.
frequency:= >=0 Hz


Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PERMITTED. +

If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. +

Each GPIO can be independently set to one of 18 different +PWM frequencies. +

The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. +

The frequencies for each sample rate are: +

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4,100000)
print(pi.get_PWM_frequency(4))
8000

set_PWM_range(user_gpio, range_)

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

Parameters

user_gpio:= 0-31.
   range_:= 25-40000.


Example

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

set_bank_1(bits)

+Sets GPIO 0-31 if the corresponding bit in bits is set. +

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user +is not allowed to write to one or more of the GPIO. +

Example

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

set_bank_2(bits)

+Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user +is not allowed to write to one or more of the GPIO. +

Example

pi.set_bank_2(0x303)

set_glitch_filter(user_gpio, steady)

+Sets a glitch filter on a GPIO. +

Level changes on the GPIO are not reported unless the level +has been stable for at least steady microseconds. The +level is then reported. Level changes of less than steady +microseconds are ignored. +

Parameters

user_gpio:= 0-31
   steady:= 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback and wait_for_edge. +

It does not affect levels read by read, +read_bank_1, or read_bank_2. +

Each (stable) edge will be timestamped steady +microseconds after it was first detected. +

Example

pi.set_glitch_filter(23, 100)

set_mode(gpio, mode)

+Sets the GPIO mode. +

Parameters

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


Example

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

set_noise_filter(user_gpio, steady, active)

+Sets a noise filter on a GPIO. +

Level changes on the GPIO are ignored until a level which has +been stable for steady microseconds is detected. Level +changes on the GPIO are then reported for active +microseconds after which the process repeats. +

Parameters

user_gpio:= 0-31
   steady:= 0-300000
   active:= 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback and wait_for_edge. +

It does not affect levels read by read, +read_bank_1, or read_bank_2. +

Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

Example

pi.set_noise_filter(23, 1000, 5000)

set_pad_strength(pad, pad_strength)

+This function sets the pad drive strength in mA. +

Parameters

         pad:= 0-2, the pad to set.
pad_strength:= 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. +

PadGPIO
00-27
128-45
246-53


Example

pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA.

set_pull_up_down(gpio, pud)

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

Parameters

gpio:= 0-53.
 pud:= PUD_UP, PUD_DOWN, PUD_OFF.


Example

pi.set_pull_up_down(17, pigpio.PUD_OFF)
pi.set_pull_up_down(23, pigpio.PUD_UP)
pi.set_pull_up_down(24, pigpio.PUD_DOWN)

set_servo_pulsewidth(user_gpio, pulsewidth)

+Starts (500-2500) or stops (0) servo pulses on the GPIO. +

Parameters

 user_gpio:= 0-31.
pulsewidth:= 0 (off),
             500 (most anti-clockwise) - 2500 (most clockwise).


The selected pulsewidth will continue to be transmitted until +changed by a subsequent call to set_servo_pulsewidth. +

The pulsewidths supported by servos varies and should probably +be determined by experiment. A value of 1500 should always be +safe and represents the mid-point of rotation. +

You can DAMAGE a servo if you command it to move beyond its +limits. +

Example

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

set_watchdog(user_gpio, wdog_timeout)

+Sets a watchdog timeout for a GPIO. +

Parameters

   user_gpio:= 0-31.
wdog_timeout:= 0-60000.


The watchdog is nominally in milliseconds. +

Only one watchdog may be registered per GPIO. +

The watchdog may be cancelled by setting timeout to 0. +

Once a watchdog has been started callbacks for the GPIO +will be triggered every timeout interval after the last +GPIO activity. +

The callback will receive the special level TIMEOUT. +

Example

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

shell(shellscr, pstring)

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

Parameters

shellscr:= the name of the script, only alphanumerics,
              '-' and '_' are allowed in the name
pstring := the parameter string to pass to the script


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

shellscr must exist in /opt/pigpio/cgi and must be executable. +

The returned exit status is normally 256 times that set by +the shell script exit function. If the script can't be +found 32512 will be returned. +

The following table gives some example returned statuses: +

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = pi.shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = pi.shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = pi.shell("scr1", "\"hello string with spaces world\"");

spi_close(handle)

+Closes the SPI device associated with handle. +

Parameters

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


Example

pi.spi_close(h)

spi_open(spi_channel, baud, spi_flags)

+Returns a handle for the SPI device on the channel. Data +will be transferred at baud bits per second. The flags +may be used to modify the default behaviour of 4-wire +operation, mode 0, active low chip select. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


Parameters

spi_channel:= 0-1 (0-2 for the auxiliary SPI).
       baud:= 32K-125M (values above 30M are unlikely to work).
  spi_flags:= see below.


spi_flags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. +

WARNING: modes 1 and 3 do not appear to work on +the auxiliary SPI. +

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 spi_read, spi_write, and spi_xfer functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. +

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

Multi-byte transfers are made in least significant byte +first order. +

E.g. to transfer 32 11-bit words data should +contain 64 bytes. +

E.g. to transfer the 14 bit value 0x1ABC send the +bytes 0xBC followed by 0x1A. +

The other bits in flags should be set to zero. +

Example

# open SPI device on channel 1 in mode 3 at 50000 bits per second

h = pi.spi_open(1, 50000, 3)

spi_read(handle, count)

+Reads count bytes from the SPI device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.spi_read(h, 60) # read 60 bytes from device h
if b == 60:
   # process read data
else:
   # error path

spi_write(handle, data)

+Writes the data bytes to the SPI device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


Example

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

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

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

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

spi_xfer(handle, data)

+Writes the data bytes to the SPI device associated with handle, +returning the data bytes read from the device. +

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00')

(count, rx_data) = pi.spi_xfer(h, [1, 128, 0])

(count, rx_data) = pi.spi_xfer(h, b"hello")

(count, rx_data) = pi.spi_xfer(h, "hello")

stop()

+Release pigpio resources. +

Example

pi.stop()

stop_script(script_id)

+Stops a running script. +

Parameters

script_id:= id of stored script.


Example

status = pi.stop_script(sid)

store_script(script)

+Store a script for later execution. +

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for +details. +

Parameters

script:= the script text as a series of bytes.


Returns a >=0 script id if OK. +

Example

sid = pi.store_script(
   b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0')

update_script(script_id, params)

+Sets the parameters of a script. The script may or +may not be running. The first parameters of the script are +overwritten with the new values. +

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.update_script(sid, [par1, par2])

s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

wait_for_edge(user_gpio, edge, wait_timeout)

+Wait for an edge event on a GPIO. +

Parameters

   user_gpio:= 0-31.
        edge:= EITHER_EDGE, RISING_EDGE (default), or
               FALLING_EDGE.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the edge is detected or after +the number of seconds specified by timeout has expired. +

Do not use this function for precise timing purposes, +the edge is only checked 20 times a second. Whenever +you need to know the accurate time of GPIO events use +a callback function. +

The function returns True if the edge is detected, +otherwise False. +

Example

if pi.wait_for_edge(23):
   print("Rising edge detected")
else:
   print("wait for edge timed out")

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

wait_for_event(event, wait_timeout)

+Wait for an event. +

Parameters

       event:= 0-31.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the event is signalled or after +the number of seconds specified by timeout has expired. +

The function returns True if the event is detected, +otherwise False. +

Example

if pi.wait_for_event(23):
   print("event detected")
else:
   print("wait for event timed out")

wave_add_generic(pulses)

+Adds a list of pulses to the current waveform. +

Parameters

pulses:= list of pulses to add to the waveform.


Returns the new total number of pulses in the current waveform. +

The pulses are interleaved in time order within the existing +waveform (if any). +

Merging allows the waveform to be built in parts, that is the +settings for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within +the existing waveform then the first pulse should consist +solely of a delay. +

Example

G1=4
G2=24

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

flash_500=[] # flash every 500 ms
flash_100=[] # flash every 100 ms

#                              ON     OFF  DELAY

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

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

pi.wave_clear() # clear any existing waveforms

pi.wave_add_generic(flash_500) # 500 ms flashes
f500 = pi.wave_create() # create and save id

pi.wave_add_generic(flash_100) # 100 ms flashes
f100 = pi.wave_create() # create and save id

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_send_repeat(f100)

time.sleep(4)

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_tx_stop() # stop waveform

pi.wave_clear() # clear all waveforms

wave_add_new()

+Starts a new empty waveform. +

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

Example

pi.wave_add_new()

wave_add_serial(user_gpio, baud, data, offset, bb_bits, bb_stop)

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

Parameters

user_gpio:= GPIO to transmit data.  You must set the GPIO mode
            to output.
     baud:= 50-1000000 bits per second.
     data:= the bytes to write.
   offset:= number of microseconds from the start of the
            waveform, default 0.
  bb_bits:= number of data bits, default 8.
  bb_stop:= number of stop half bits, default 2.


Returns the new total number of pulses in the current waveform. +

The serial data is formatted as one start bit, bb_bits +data bits, and bb_stop/2 stop bits. +

It is legal to add serial data streams with different baud +rates to the same waveform. +

The bytes required for each character depend upon bb_bits. +

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

Example

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

pi.wave_add_serial(4, 300, b"Hello world")

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

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

wave_chain(data)

+This function transmits a chain of waveforms. +

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

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

Returns 0 if OK, otherwise PI_CHAIN_NESTING, +PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, +PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, +or PI_BAD_WAVE_ID. +

Each wave is transmitted in the order specified. A wave +may occur multiple times per chain. +

A blocks of waves may be transmitted multiple times by +using the loop commands. The block is bracketed by loop +start and end commands. Loops may be nested. +

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#!/usr/bin/env python

import time
import pigpio

WAVES=5
GPIO=4

wid=[0]*WAVES

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

pi.set_mode(GPIO, pigpio.OUTPUT);

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

   wid[i] = pi.wave_create();

pi.wave_chain([
   wid[4], wid[3], wid[2],       # transmit waves 4+3+2
   255, 0,                       # loop start
      wid[0], wid[0], wid[0],    # transmit waves 0+0+0
      255, 0,                    # loop start
         wid[0], wid[1],         # transmit waves 0+1
         255, 2, 0x88, 0x13,     # delay 5000us
      255, 1, 30, 0,             # loop end (repeat 30 times)
      255, 0,                    # loop start
         wid[2], wid[3], wid[0], # transmit waves 2+3+0
         wid[3], wid[1], wid[2], # transmit waves 3+1+2
      255, 1, 10, 0,             # loop end (repeat 10 times)
   255, 1, 5, 0,                 # loop end (repeat 5 times)
   wid[4], wid[4], wid[4],       # transmit waves 4+4+4
   255, 2, 0x20, 0x4E,           # delay 20000us
   wid[0], wid[0], wid[0],       # transmit waves 0+0+0
   ])

while pi.wave_tx_busy():
   time.sleep(0.1);

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

pi.stop()

wave_clear()

+Clears all waveforms and any data added by calls to the +wave_add_* functions. +

Example

pi.wave_clear()

wave_create()

+Creates a waveform from the data provided by the prior calls +to the wave_add_* functions. +

Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

The data provided by the wave_add_* functions is consumed by +this function. +

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

Normal usage would be +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create to create the waveform and get a unique id +

Repeat steps 2 and 3 as needed. +

Step 4. wave_send_* with the id of the waveform to transmit. +

A waveform comprises one or more pulses. +

A pulse specifies +

1) the GPIO to be switched on at the start of the pulse. +2) the GPIO to be switched off at the start of the pulse. +3) the delay in microseconds before the next pulse. +

Any or all the fields can be zero. It doesn't make any sense +to set all the fields to zero (the pulse will be ignored). +

When a waveform is started each pulse is executed in order with +the specified delay between the pulse and the next. +

Example

wid = pi.wave_create()

wave_create_and_pad(percent)

+This function creates a waveform like wave_create but pads the consumed +resources. Where percent gives the percentage of the resources to use +(in terms of the theoretical maximum, not the current amount free). +This allows the reuse of deleted waves while a transmission is active. +

Upon success a wave id greater than or equal to 0 is returned, otherwise +PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions are consumed by this +function. +

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

A usage would be the creation of two waves where one is filled while the other +is being transmitted. Each wave is assigned 50% of the available resources. +This buffer structure allows the transmission of infinite wave sequences. +

Normal usage: +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create_and_pad to create a waveform of uniform size. +

Step 4. wave_send_* with the id of the waveform to transmit. +

Repeat steps 2-4 as needed. +

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

Example

wid = pi.wave_create(50)

wave_delete(wave_id)

+This function deletes the waveform with id wave_id. +

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. +

- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. +

- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). +

Example

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

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

wave_get_cbs()

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

Example

cbs = pi.wave_get_cbs()

wave_get_max_cbs()

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

Example

cbs = pi.wave_get_max_cbs()

wave_get_max_micros()

+Returns the maximum possible size of a waveform in microseconds. +

Example

micros = pi.wave_get_max_micros()

wave_get_max_pulses()

+Returns the maximum possible size of a waveform in pulses. +

Example

pulses = pi.wave_get_max_pulses()

wave_get_micros()

+Returns the length in microseconds of the current waveform. +

Example

micros = pi.wave_get_micros()

wave_get_pulses()

+Returns the length in pulses of the current waveform. +

Example

pulses = pi.wave_get_pulses()

wave_send_once(wave_id)

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

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

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

Example

cbs = pi.wave_send_once(wid)

wave_send_repeat(wave_id)

+Transmits the waveform with id wave_id. The waveform repeats +until wave_tx_stop is called or another call to wave_send_* +is made. +

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

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

Example

cbs = pi.wave_send_repeat(wid)

wave_send_using_mode(wave_id, mode)

+Transmits the waveform with id wave_id using mode mode. +

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).
   mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT,
          WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC.


WAVE_MODE_ONE_SHOT: same as wave_send_once. +

WAVE_MODE_REPEAT same as wave_send_repeat. +

WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries +to sync with the previous waveform. +

WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries +to sync with the previous waveform. +

WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. +

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

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

Example

cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC)

wave_tx_at()

+Returns the id of the waveform currently being +transmitted. +

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

WAVE_NOT_FOUND (9998) - transmitted wave not found. +NO_TX_WAVE (9999) - no wave being transmitted. +

Example

wid = pi.wave_tx_at()

wave_tx_busy()

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

Example

pi.wave_send_once(0) # send first waveform

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

pi.wave_send_once(1) # send next waveform

wave_tx_repeat()

+This function is deprecated and has beeen removed. +

Use
wave_create/wave_send_* instead. +

wave_tx_start()

+This function is deprecated and has been removed. +

Use
wave_create/wave_send_* instead. +

wave_tx_stop()

+Stops the transmission of the current waveform. +

This function is intended to stop a waveform started with +wave_send_repeat. +

Example

pi.wave_send_repeat(3)

time.sleep(5)

pi.wave_tx_stop()

write(gpio, level)

+Sets the GPIO level. +

Parameters

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


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

Example

pi.set_mode(17, pigpio.OUTPUT)

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

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

class pulse +

pigpio.pulse(gpio_on, gpio_off, delay)

+Initialises a pulse. +

Parameters

 gpio_on:= the GPIO to switch on at the start of the pulse.
gpio_off:= the GPIO to switch off at the start of the pulse.
   delay:= the delay in microseconds before the next pulse.

FUNCTIONS

pigpio.error_text(errnum)

+Returns a text description of a pigpio error. +

Parameters

errnum:= <0, the error number


Example

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

pigpio.tickDiff(t1, t2)

+Returns the microsecond difference between two ticks. +

Parameters

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


Example

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

pigpio.u2i(uint32)

+Converts a 32 bit unsigned number to signed. +

Parameters

uint32:= an unsigned 32 bit number


Example

print(u2i(4294967272))
-24
print(u2i(37))
37

PARAMETERS

active: 0-1000000

The number of microseconds level changes are reported for once +a noise filter has been triggered (by steady microseconds of +a stable level). +

arg1:

An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

arg2:

An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

argx:

An array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. +

baud:

The speed of serial communication (I2C, SPI, serial link, waves) +in bits per second. +

bb_bits: 1-32

The number of data bits to be used when adding serial data to a +waveform. +

bb_stop: 2-8

The number of (half) stop bits to be used when adding serial data +to a waveform. +

bit: 0-1

A value of 0 or 1. +

bits: 32 bit number

A mask used to select GPIO to be operated on. If bit n is set +then GPIO n is selected. A convenient way of setting bit n is to +bit or in the value (1<<n). +

To select GPIO 1, 7, 23 +

bits = (1<<1) | (1<<7) | (1<<23) +

bsc_control:

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

Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document. +

byte_val: 0-255

A whole number. +

clkfreq: 4689-250M (13184-375M for the BCM2711)

The hardware clock frequency. +

connected:

True if a connection was established, False otherwise. +

count:

The number of bytes of data to be transferred. +

CS:

The GPIO used for the slave select signal when bit banging SPI. +

data:

Data to be transmitted, a series of bytes. +

delay: >=1

The length of a pulse in microseconds. +

dutycycle: 0-range_

A number between 0 and range_. +

The dutycycle sets the proportion of time on versus time off during each +PWM cycle. +

DutycycleOn time
0Off
range_ * 0.2525% On
range_ * 0.5050% On
range_ * 0.7575% On
range_Fully On

edge: 0-2

EITHER_EDGE = 2
FALLING_EDGE = 1
RISING_EDGE = 0

errnum: <0

PI_BAD_USER_GPIO = -2
PI_BAD_GPIO = -3
PI_BAD_MODE = -4
PI_BAD_LEVEL = -5
PI_BAD_PUD = -6
PI_BAD_PULSEWIDTH = -7
PI_BAD_DUTYCYCLE = -8
PI_BAD_WDOG_TIMEOUT = -15
PI_BAD_DUTYRANGE = -21
PI_NO_HANDLE = -24
PI_BAD_HANDLE = -25
PI_BAD_WAVE_BAUD = -35
PI_TOO_MANY_PULSES = -36
PI_TOO_MANY_CHARS = -37
PI_NOT_SERIAL_GPIO = -38
PI_NOT_PERMITTED = -41
PI_SOME_PERMITTED = -42
PI_BAD_WVSC_COMMND = -43
PI_BAD_WVSM_COMMND = -44
PI_BAD_WVSP_COMMND = -45
PI_BAD_PULSELEN = -46
PI_BAD_SCRIPT = -47
PI_BAD_SCRIPT_ID = -48
PI_BAD_SER_OFFSET = -49
PI_GPIO_IN_USE = -50
PI_BAD_SERIAL_COUNT = -51
PI_BAD_PARAM_NUM = -52
PI_DUP_TAG = -53
PI_TOO_MANY_TAGS = -54
PI_BAD_SCRIPT_CMD = -55
PI_BAD_VAR_NUM = -56
PI_NO_SCRIPT_ROOM = -57
PI_NO_MEMORY = -58
PI_SOCK_READ_FAILED = -59
PI_SOCK_WRIT_FAILED = -60
PI_TOO_MANY_PARAM = -61
PI_SCRIPT_NOT_READY = -62
PI_BAD_TAG = -63
PI_BAD_MICS_DELAY = -64
PI_BAD_MILS_DELAY = -65
PI_BAD_WAVE_ID = -66
PI_TOO_MANY_CBS = -67
PI_TOO_MANY_OOL = -68
PI_EMPTY_WAVEFORM = -69
PI_NO_WAVEFORM_ID = -70
PI_I2C_OPEN_FAILED = -71
PI_SER_OPEN_FAILED = -72
PI_SPI_OPEN_FAILED = -73
PI_BAD_I2C_BUS = -74
PI_BAD_I2C_ADDR = -75
PI_BAD_SPI_CHANNEL = -76
PI_BAD_FLAGS = -77
PI_BAD_SPI_SPEED = -78
PI_BAD_SER_DEVICE = -79
PI_BAD_SER_SPEED = -80
PI_BAD_PARAM = -81
PI_I2C_WRITE_FAILED = -82
PI_I2C_READ_FAILED = -83
PI_BAD_SPI_COUNT = -84
PI_SER_WRITE_FAILED = -85
PI_SER_READ_FAILED = -86
PI_SER_READ_NO_DATA = -87
PI_UNKNOWN_COMMAND = -88
PI_SPI_XFER_FAILED = -89
PI_NO_AUX_SPI = -91
PI_NOT_PWM_GPIO = -92
PI_NOT_SERVO_GPIO = -93
PI_NOT_HCLK_GPIO = -94
PI_NOT_HPWM_GPIO = -95
PI_BAD_HPWM_FREQ = -96
PI_BAD_HPWM_DUTY = -97
PI_BAD_HCLK_FREQ = -98
PI_BAD_HCLK_PASS = -99
PI_HPWM_ILLEGAL = -100
PI_BAD_DATABITS = -101
PI_BAD_STOPBITS = -102
PI_MSG_TOOBIG = -103
PI_BAD_MALLOC_MODE = -104
PI_BAD_SMBUS_CMD = -107
PI_NOT_I2C_GPIO = -108
PI_BAD_I2C_WLEN = -109
PI_BAD_I2C_RLEN = -110
PI_BAD_I2C_CMD = -111
PI_BAD_I2C_BAUD = -112
PI_CHAIN_LOOP_CNT = -113
PI_BAD_CHAIN_LOOP = -114
PI_CHAIN_COUNTER = -115
PI_BAD_CHAIN_CMD = -116
PI_BAD_CHAIN_DELAY = -117
PI_CHAIN_NESTING = -118
PI_CHAIN_TOO_BIG = -119
PI_DEPRECATED = -120
PI_BAD_SER_INVERT = -121
PI_BAD_FOREVER = -124
PI_BAD_FILTER = -125
PI_BAD_PAD = -126
PI_BAD_STRENGTH = -127
PI_FIL_OPEN_FAILED = -128
PI_BAD_FILE_MODE = -129
PI_BAD_FILE_FLAG = -130
PI_BAD_FILE_READ = -131
PI_BAD_FILE_WRITE = -132
PI_FILE_NOT_ROPEN = -133
PI_FILE_NOT_WOPEN = -134
PI_BAD_FILE_SEEK = -135
PI_NO_FILE_MATCH = -136
PI_NO_FILE_ACCESS = -137
PI_FILE_IS_A_DIR = -138
PI_BAD_SHELL_STATUS = -139
PI_BAD_SCRIPT_NAME = -140
PI_BAD_SPI_BAUD = -141
PI_NOT_SPI_GPIO = -142
PI_BAD_EVENT_ID = -143
PI_CMD_INTERRUPTED = -144
PI_NOT_ON_BCM2711   = -145
PI_ONLY_ON_BCM2711  = -146

event: 0-31

An event is a signal used to inform one or more consumers +to start an action. +

file_mode:

The mode may have the following values +

FILE_READ   1
FILE_WRITE  2
FILE_RW     3


The following values can be or'd into the file open mode +

FILE_APPEND 4
FILE_CREATE 8
FILE_TRUNC  16

file_name:

A full file path. To be accessible the path must match +an entry in /opt/pigpio/access. +

fpattern:

A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. +

frequency: 0-40000

Defines the frequency to be used for PWM on a GPIO. +The closest permitted frequency will be used. +

func:

A user supplied callback function. +

gpio: 0-53

A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. +

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

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

gpio_off:

A mask used to select GPIO to be operated on. See bits. +

This mask selects the GPIO to be switched off at the start +of a pulse. +

gpio_on:

A mask used to select GPIO to be operated on. See bits. +

This mask selects the GPIO to be switched on at the start +of a pulse. +

handle: >=0

A number referencing an object opened by one of the following +

file_open +i2c_open +notify_open +serial_open +spi_open +

host:

The name or IP address of the Pi running the pigpio daemon. +

i2c_address: 0-0x7F

The address of a device on the I2C bus. +

i2c_bus: >=0

An I2C bus number. +

i2c_flags: 0

No I2C flags are currently defined. +

invert: 0-1

A flag used to set normal or inverted bit bang serial data +level logic. +

level: 0-1 (2)

CLEAR = 0
HIGH = 1
LOW = 0
OFF = 0
ON = 1
SET = 1
TIMEOUT = 2 # only returned for a watchdog timeout

MISO:

The GPIO used for the MISO signal when bit banging SPI. +

mode:

1.The operational mode of a GPIO, normally INPUT or OUTPUT. +

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


2. The mode of waveform transmission. +

WAVE_MODE_ONE_SHOT = 0
WAVE_MODE_REPEAT = 1
WAVE_MODE_ONE_SHOT_SYNC = 2
WAVE_MODE_REPEAT_SYNC = 3

MOSI:

The GPIO used for the MOSI signal when bit banging SPI. +

offset: >=0

The offset wave data starts from the beginning of the waveform +being currently defined. +

pad: 0-2

A set of GPIO which share common drivers. +

PadGPIO
00-27
128-45
246-53

pad_strength: 1-16

The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. +

params: 32 bit number

When scripts are started they can receive up to 10 parameters +to define their operation. +

port:

The port used by the pigpio daemon, defaults to 8888. +

pstring:

The string to be passed to a shell script to be executed. +

pud: 0-2

PUD_DOWN = 1
PUD_OFF = 0
PUD_UP = 2

pulse_len: 1-100

The length of the trigger pulse in microseconds. +

pulses:

A list of class pulse objects defining the characteristics of a +waveform. +

pulsewidth:

The servo pulsewidth in microseconds. 0 switches pulses off. +

PWMduty: 0-1000000 (1M)

The hardware PWM dutycycle. +

PWMfreq: 1-125M (1-187.5M for the BCM2711)

The hardware PWM frequency. +

range_: 25-40000

Defines the limits for the dutycycle parameter. +

range_ defaults to 255. +

reg: 0-255

An I2C device register. The usable registers depend on the +actual device. +

retMax: >=0

The maximum number of bytes a user customised function +should return, default 8192. +

SCL:

The user GPIO to use for the clock when bit banging I2C. +

SCLK: :

The GPIO used for the SCLK signal when bit banging SPI. +

script:

The text of a script to store on the pigpio daemon. +

script_id: >=0

A number referencing a script created by store_script. +

SDA:

The user GPIO to use for data when bit banging I2C. +

seek_from: 0-2

Direction to seek for file_seek. +

FROM_START=0
FROM_CURRENT=1
FROM_END=2

seek_offset:

The number of bytes to move forward (positive) or backwards +(negative) from the seek position (start, current, or end of file). +

ser_flags: 32 bit

No serial flags are currently defined. +

serial_*:

One of the serial_ functions. +

shellscr:

The name of a shell script. The script must exist +in /opt/pigpio/cgi and must be executable. +

show_errors:

Controls the display of pigpio daemon connection failures. +The default of True prints the probable failure reasons to +standard output. +

spi_channel: 0-2

A SPI channel. +

spi_flags: 32 bit

See spi_open. +

steady: 0-300000

The number of microseconds level changes must be stable for +before reporting the level changed (set_glitch_filter) +or triggering the active part of a noise filter +(set_noise_filter). +

t1:

A tick (earlier). +

t2:

A tick (later). +

tty:

A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0 +

uint32:

An unsigned 32 bit number. +

user_gpio: 0-31

A Broadcom numbered GPIO. +

All the user GPIO are in the range 0-31. +

Not all the GPIO within this range are usable, some are reserved +for system use. +

See gpio. +

wait_timeout: 0.0 -

The number of seconds to wait in wait_for_edge before timing out. +

wave_add_*:

One of the following +

wave_add_new +wave_add_generic +wave_add_serial +

wave_id: >=0

A number referencing a wave created by wave_create. +

wave_send_*:

One of the following +

wave_send_once +wave_send_repeat +

wdog_timeout: 0-60000

Defines a GPIO watchdog timeout in milliseconds. If no level +change is detected on the GPIO for timeout millisecond a watchdog +timeout report is issued (with level TIMEOUT). +

word_val: 0-65535

A whole number. +

+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/sif.html b/DOC/HTML/sif.html new file mode 100644 index 0000000..f689050 --- /dev/null +++ b/DOC/HTML/sif.html @@ -0,0 +1,2058 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Socket Interface

+pigpio provides a socket interface to many of its functions.
+
+The socket interface is available whenever pigpio is running, +either because it has been started as a daemon, or it has been +linked in to a running user program.
+
+The socket interface can be disabled by the program which +initialises the library.  pigpiod offers the -k option to +disable the socket interface.  User programs should call +gpioCfgInterfaces if they +wish to disable the socket interface.
+
+pigpio listens for connections on port 8888 by default.  This +default may be overridden when pigpio starts by the gpioCfgSocketPort function +call.  The pigpio daemon uses this function to provide an +option to change the port number.
+
+The pigs utility is an example of using the socket interface from +C.
+

Request

+

pigpio expects messages of type cmdCmd_t immediately followed with an +extension for a few commands.
+
+The caller should fill in cmd, p1, p2, p3/res, and any extension as +needed.  p3 will always be zero unless the command requires an +extension in which case p3 will be the length in bytes of the +extension.
+
+The cmdCmd_t is echoed back with +the result, if any, in p3/res, and an extension immediately +afterwards for a few commands.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
COMMANDcmd
p1p2p3Extension
MODES0gpiomode0-
MODEG1gpio00-
PUD2gpiopud0-
READ3gpio00-
WRITE4gpiolevel0-
PWM5gpiodutycycle0-
PRS6gpiorange0-
PFS7gpiofrequency0-
SERVO8gpiopulsewidth0-
WDOG9gpiotimeout0-
BR110000-
BR211000-
BC112bits00-
BC213bits00-
BS114bits00-
BS215bits00-
TICK16000-
HWVER17000-
NO18000-
NB19handlebits0-
NP20handle00-
NC21handle00-
PRG22gpio00-
PFG23gpio00-
PRRG24gpio00-
HELP
25N/A
N/A
N/A
N/A
PIGPV26000-
WVCLR27000-
WVAG280012*XgpioPulse_t pulse[X]
WVAS29gpiobaud12+Xuint32_t databits
+uint32_t stophalfbits
+uint32_t offset
+uint8_t data[X]
N/A
30000-
N/A
31000-
WVBSY32000-
WVHLT33000-
WVSM34subcmd00-
WVSP35subcmd00-
WVSC36subcmd00-
TRIG37gpiopulselen4uint32_t level
PROC3800Xuint8_t text[X]
PROCD39script_id00-
PROCR40script_id04*X
uint32_t pars[X]
PROCS41script_id00-
SLRO42gpiobaud4uint32_t databits
SLR43gpiocount0-
SLRC44gpio00-
PROCP45script_id00-
MICS46micros00-
MILS47millis00-
PARSE48N/AN/A
N/A
N/A
WVCRE49000-
WVDEL50wave_id00-
WVTX51wave_id00-
WVTXR52wave_id00-
WVNEW53000-
I2CO54busdevice4uint32_t flags
I2CC55handle00-
I2CRD56handlecount0-
I2CWD57handle0Xuint8_t data[X]
I2CWQ58handlebit0-
I2CRS59handle00-
I2CWS60handlebyte0-
I2CRB61handleregister0-
I2CWB62handleregister4uint32_t byte
I2CRW63handleregister0-
I2CWW64handleregister4uint32_t word
I2CRK65handleregister
0-
I2CWK66handleregister
Xuint8_t bvs[X]
I2CRI67handleregister
4uint32_t num
I2CWI68handleregister
X
uint8_t bvs[X]
I2CPC69handleregister
4uint32_t word
I2CPK70handleregister
X
uint8_t data[X]
SPIO
71channelbaud4uint32_t flags
SPIC72handle00-
SPIR73handlecount0-
SPIW74handle0Xuint8_t data[X]
SPIX75handle0Xuint8_t data[X]
SERO76baudflagsXuint8_t device[X]
SERC77handle00-
SERRB78handle00-
SERWB79handlebyte0-
SERR80handlecount0-
SERW81handle0Xuint8_t data[X]
SERDA82handle00-
GDC
83
gpio
0
0
-
GPW
84
gpio
0
0
-
HC
85
gpio
frequency
0
-
HP
86
gpio
frequency
4
uint32_t dutycycle
CF1
87
arg1
arg2
X
uint8_t argx[X]
CF2
88
arg1
retMax
X
uint8_t argx[X]
BI2CC
89
sda
0
0
-
BI2CO
90
sda
scl
4
uint32_t baud
BI2CZ
91
sda
0
X
uint8_t data[X]
I2CZ
92
handle
0
X
uint8_t data[X]
WVCHA
93
0
0
X
uint8_t data[X]
SLRI
94
gpio
invert
0
-
CGI
95
0
0
0
-
CSI
96
config
0
0
-
FG
97
gpio
steady
0
-
FN
98
gpio
steady
4
uint32_t active
NOIB99000-
WVTXM
100
wave_id
mode
0
-
WVTAT
101
0
0
0
-
PADS
102
pad
strength
0
-
PADG
103
pad
0
0
-
FO
104
mode
0
X
uint8_t file[X]
FC
105
handle
0
0
-
FR
106
handle
count
0
-
FW
107
handle
0
X
uint8_t data[X]
FS
108
handle
offset
4
uint32_t from
FL
109
count
0
X
uint8_t pattern[X]
SHELL
110
len(name)
0
len(name)+
+1+
+len(string)
uint8_t name[len(name)]
+uint8_t null (0)
+uint8_t string[len(string)]
BSPIC
111
CS
0
0
-
BSPIO
112
CS
0
20
uint32_t MISO
+uint32_t MOSI
+uint32_t SCLK
+uint32_t baud
+uint32_t spi_flags
BSPIX
113
CS
0
X
uint8_t data[X]
BSCX
114
control
0
X
uint8_t data[X]
EVM
115
handle
bits
0
-
EVT
116
event
0
0
-
PROCU
117
script_id
0
4*X
uint32_t pars[X]
+

Response

+

The response has cmd/p1/p2 as in the request.  p3/res holds +the return value.  If the command returns additional values +they will be in the immediately following extension.

+Normally res should be treated as a 32 bit signed value and will be +greater than or equal to zero.  Upon failure res will be less +than 0 and contains an error code.
+

There are a few commands where the returned value should be +treated as a 32 bit unsigned value.  These commands can not +fail.  They are indicated with a * after the command +name.

+

Commands with an extension have the size of the extension in +bytes returned in res (or <0 on error as above).

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
COMMANDcmd
p1
p2
res
Extension
MODES0-
-
0-
MODEG1-
-
mode
-
PUD2-
-
0-
READ3-
-
level
-
WRITE4-
-
0-
PWM5-
-
0-
PRS6-
-
0-
PFS7-
-
0-
SERVO8-
-
0-
WDOG9-
-
0-
BR1 *10-
-
bits
-
BR2 *11-
-
bits
-
BC112-
-
0-
BC213-
-
0-
BS114-
-
0-
BS215-
-
0-
TICK *
16-
-
tick
-
HWVER *
17-
-
version
-
NO18-
-
handle
-
NB19-
-
0-
NP20-
-
0-
NC21-
-
0-
PRG22-
-
range
-
PFG23-
-
frequency
-
PRRG24-
-
real range
-
HELP25-
-
N/A
N/A
PIGPV *
26-
-
version
-
WVCLR27-
-
0-
WVAG28-
-
wave pulses
-
WVAS29-
-
wave pulses
-
N/A
30-
-
-
-
N/A
31-
-
-
-
WVBSY32-
-
busy (1) or not busy (0)
-
WVHLT33-
-
0-
WVSM34-
-
wave micros
+wave micros - high
+wave micros - max
-
WVSP35-
-
wave pulses
+wave pulses - high
+wave pulses - max
-
WVSC36-
-
wave DMA CBs
+wave DMA CBs - high
+wave DMA CBs - max
-
TRIG37-
-
0
-
PROC38-
-
script id
-
PROCD39-
-
0-
PROCR40-
-
script status
-
PROCS41-
-
0-
SLRO42-
-
0
-
SLR43-
-
X
uint8_t data[X]
SLRC44-
-
0-
PROCP45-
-
44uint32_t script_status
+uint32_t pars[10]
MICS46-
-
0-
MILS47-
-
0-
PARSE48-
-
N/A
-
WVCRE49-
-
wave id
-
WVDEL50-
-
0-
WVTX51-
-
wave DMA CBs
-
WVTXR52-
-
wave DMA CBs
-
WVNEW53-
-
0-
I2CO54-
-
handle-
I2CC55-
-
0-
I2CRD56-
-
X
uint8_t data[X]
I2CWD57-
-
0
-
I2CWQ58-
-
0-
I2CRS59-
-
byte value
-
I2CWS60-
-
0-
I2CRB61-
-
byte value
-
I2CWB62-
-
0
-
I2CRW63-
-
word value
-
I2CWW64-
-
0
-
I2CRK65-
-
0-
I2CWK66-
-
0
-
I2CRI67-
-
X
uint8_t data[X]
I2CWI68-
-
0
-
I2CPC69-
-
word value
-
I2CPK70-
-
X
uint8_t data[X]
SPIO
71-
-
handle
-
SPIC72-
-
0-
SPIR73-
-
X
uint8_t data[X]
SPIW74-
-
0
-
SPIX75-
-
Xuint8_t data[X]
SERO76-
-
handle
-
SERC77-
-
0-
SERRB78-
-
byte value
-
SERWB79-
-
0-
SERR80-
-
X
uint8_t data[X]
SERW81-
-
0
-
SERDA82-
-
data ready count
-
GDC
83
-
-
dutycycle
-
GPW
84
-
-
pulsewidth
-
HC
85
-
-
0
-
HP
86
-
-
0
-
CF1
87
-
-
value
-
CF2
88
-
-
X
uint8_t retBuf[X]
BI2CC
89
-
-
0
-
BI2CO
90
-
-
handle
-
BI2CZ
91
-
-
X
uint8_t data[X]
I2CZ
92
-
-
X
uint8_t data[X]
WVCHA
93
-
-
0
-
SLRI
94
-
-
0
-
CGI
95
-
-
config
-
CSI
96
-
-
0
-
FG
97
-
-
0
-
FN
98
-
-
0
-
NOIB99-
-
0-
WVTXM
100
-
-
wave DMA CBs
-
WVTAT
101
-
-
wave id
-
PADS
102
-
-
0
-
PADG
103
-
-
strength
-
FO
104
-
-
handle
-
FC
105
-
-
0
-
FR
106
-
-
X
uint8_t data[X]
FW
107
-
-
0
-
FS
108
-
-
position
-
FL
109
-
-
X
uint8_t filenames[X]
SHELL
110
-
-
exit status
-
BSPIC
111
-
-
0
-
BSPIO
112
-
-
0
-
BSPIX
113
-
-
X
uint8_t data[X]
BSCX
114
-
-
X+4
uint32_t status
+uint8_t data[X]
EVM
115
-
-
0
-
EVT
116
-
-
0
-
PROCU
117
-
-
0
-
+
+

cmdCmd_t

+typedef struct
+{
+   uint32_t cmd;
+   uint32_t p1;
+   uint32_t p2;
+   union
+   {
+      uint32_t p3;
+      uint32_t ext_len;
+      uint32_t res;
+   };
+} cmdCmd_t;

+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/HTML/sitemap.html b/DOC/HTML/sitemap.html new file mode 100644 index 0000000..18ecc75 --- /dev/null +++ b/DOC/HTML/sitemap.html @@ -0,0 +1,85 @@ + + + + + + + + pigpio library + + + + + + + + + +
+ +
pigpio library
+
+
+
+ + +
+ + + +
pigpio +pigpio C I/F +pigpiod +pigpiod C I/F +Python +pigs +piscope +Misc +Examples +Download +FAQ +Site Map +

Site Map

pigpio
+pigpio C I/F
+pigpiod
+pigpiod C I/F
+Python
+pigs
+piscope
+Misc
+----Socket I/F
+----Pipe I/F
+----pigpiod_if
+----pig2vcd
+Examples
+----Rotary Encoder
+----IR Remote
+----Light Dependent Resitor
+----Sonar Ranger
+----Arduino Motor Shield
+Download
+FAQ
+Site Map
+
+ + + + + +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
+
+ + diff --git a/DOC/MAN/pig2vcd.1 b/DOC/MAN/pig2vcd.1 new file mode 100644 index 0000000..eacce19 --- /dev/null +++ b/DOC/MAN/pig2vcd.1 @@ -0,0 +1,246 @@ + +." Process this file with +." groff -man -Tascii pig2vcd.1 +." +.TH pig2vcd 1 2012-2020 Linux "pigpio archive" +.SH NAME +pig2vd - A utility to convert pigpio notifications to VCD. + +.SH SYNOPSIS + +pig2vcd file.VCD +.SH DESCRIPTION + + +.ad l + +.nh +pig2vcd is a utility which reads notifications on stdin and writes the +output as a Value Change Dump (VCD) file on stdout. + +.br + +.br +The VCD file can be viewed using GTKWave. + +.br + +.br +.SS Notifications +.br + +.br +Notifications consist of 12 bytes with the following binary format. + +.br + +.br + +.EX +typedef struct +.br +{ +.br + uint16_t seqno; +.br + uint16_t flags; +.br + uint32_t tick; +.br + uint32_t level; +.br +} gpioReport_t; +.br + +.EE + +.br + +.br +seqno: starts at 0 each time the handle is opened and then increments by one for each report. + +.br + +.br +flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. + +.br + +.br +tick: the number of microseconds since system boot. It wraps around after 1h12m. + +.br + +.br +level: indicates the level of each gpio. If bit 1< + + +gcc -Wall -pthread -o prog prog.c -lpigpio -lrt + +sudo ./prog +.SH DESCRIPTION + + +.ad l + +.nh + +.br + +.br +pigpio is a C library for the Raspberry which allows control of the GPIO. + +.br + +.br +.SS Features +.br + +.br +o hardware timed PWM on any of GPIO 0-31 + +.br + +.br +o hardware timed servo pulses on any of GPIO 0-31 + +.br + +.br +o callbacks when any of GPIO 0-31 change state + +.br + +.br +o callbacks at timed intervals + +.br + +.br +o reading/writing all of the GPIO in a bank as one operation + +.br + +.br +o individually setting GPIO modes, reading and writing + +.br + +.br +o notifications when any of GPIO 0-31 change state + +.br + +.br +o the construction of output waveforms with microsecond timing + +.br + +.br +o rudimentary permission control over GPIO + +.br + +.br +o a simple interface to start and stop new threads + +.br + +.br +o I2C, SPI, and serial link wrappers + +.br + +.br +o creating and running scripts + +.br + +.br +.SS GPIO +.br + +.br +ALL GPIO are identified by their Broadcom number. + +.br + +.br +.SS Credits +.br + +.br +The PWM and servo pulses are timed using the DMA and PWM peripherals. + +.br + +.br +This use was inspired by Richard Hirst's servoblaster kernel module. + +.br + +.br +.SS Usage +.br + +.br +Include in your source files. + +.br + +.br +Assuming your source is in prog.c use the following command to build and +run the executable. + +.br + +.br + +.EX +gcc -Wall -pthread -o prog prog.c -lpigpio -lrt +.br +sudo ./prog +.br + +.EE + +.br + +.br +For examples of usage see the C programs within the pigpio archive file. + +.br + +.br +.SS Notes +.br + +.br +All the functions which return an int return < 0 on error. + +.br + +.br +\fBgpioInitialise\fP must be called before all other library functions +with the following exceptions: + +.br + +.br + +.EX +\fBgpioCfg*\fP +.br +\fBgpioVersion\fP +.br +\fBgpioHardwareRevision\fP +.br + +.EE + +.br + +.br +If the library is not initialised all but the \fBgpioCfg*\fP, +\fBgpioVersion\fP, and \fBgpioHardwareRevision\fP functions will +return error PI_NOT_INITIALISED. + +.br + +.br +If the library is initialised the \fBgpioCfg*\fP functions will return +error PI_INITIALISED. + +.br + +.br + +.SH OVERVIEW + +.br +.SS ESSENTIAL +.br + +.br +gpioInitialise Initialise library +.br +gpioTerminate Stop library +.br +.SS BASIC +.br + +.br +gpioSetMode Set a GPIO mode +.br +gpioGetMode Get a GPIO mode +.br + +.br +gpioSetPullUpDown Set/clear GPIO pull up/down resistor +.br + +.br +gpioRead Read a GPIO +.br +gpioWrite Write a GPIO +.br +.SS PWM (overrides servo commands on same GPIO) +.br + +.br +gpioPWM Start/stop PWM pulses on a GPIO +.br +gpioSetPWMfrequency Configure PWM frequency for a GPIO +.br +gpioSetPWMrange Configure PWM range for a GPIO +.br + +.br +gpioGetPWMdutycycle Get dutycycle setting on a GPIO +.br +gpioGetPWMfrequency Get configured PWM frequency for a GPIO +.br +gpioGetPWMrange Get configured PWM range for a GPIO +.br + +.br +gpioGetPWMrealRange Get underlying PWM range for a GPIO +.br +.SS Servo (overrides PWM commands on same GPIO) +.br + +.br +gpioServo Start/stop servo pulses on a GPIO +.br + +.br +gpioGetServoPulsewidth Get pulsewidth setting on a GPIO +.br +.SS INTERMEDIATE +.br + +.br +gpioTrigger Send a trigger pulse to a GPIO +.br + +.br +gpioSetWatchdog Set a watchdog on a GPIO +.br + +.br +gpioRead_Bits_0_31 Read all GPIO in bank 1 +.br +gpioRead_Bits_32_53 Read all GPIO in bank 2 +.br + +.br +gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 +.br +gpioWrite_Bits_32_53_Clear Clear selected GPIO in bank 2 +.br + +.br +gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 +.br +gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 +.br + +.br +gpioSetAlertFunc Request a GPIO level change callback +.br +gpioSetAlertFuncEx Request a GPIO change callback, extended +.br + +.br +gpioSetTimerFunc Request a regular timed callback +.br +gpioSetTimerFuncEx Request a regular timed callback, extended +.br + +.br +gpioStartThread Start a new thread +.br +gpioStopThread Stop a previously started thread +.br +.SS ADVANCED +.br + +.br +gpioNotifyOpen Request a notification handle +.br +gpioNotifyClose Close a notification +.br +gpioNotifyOpenWithSize Request a notification with sized pipe +.br +gpioNotifyBegin Start notifications for selected GPIO +.br +gpioNotifyPause Pause notifications +.br + +.br +gpioHardwareClock Start hardware clock on supported GPIO +.br + +.br +gpioHardwarePWM Start hardware PWM on supported GPIO +.br + +.br +gpioGlitchFilter Set a glitch filter on a GPIO +.br +gpioNoiseFilter Set a noise filter on a GPIO +.br + +.br +gpioSetPad Sets a pads drive strength +.br +gpioGetPad Gets a pads drive strength +.br + +.br +shell Executes a shell command +.br + +.br +gpioSetISRFunc Request a GPIO interrupt callback +.br +gpioSetISRFuncEx Request a GPIO interrupt callback, extended +.br + +.br +gpioSetSignalFunc Request a signal callback +.br +gpioSetSignalFuncEx Request a signal callback, extended +.br + +.br +gpioSetGetSamplesFunc Requests a GPIO samples callback +.br +gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended +.br +.SS Custom +.br + +.br +gpioCustom1 User custom function 1 +.br +gpioCustom2 User custom function 2 +.br +.SS Events +.br + +.br +eventMonitor Sets the events to monitor +.br +eventSetFunc Request an event callback +.br +eventSetFuncEx Request an event callback, extended +.br + +.br +eventTrigger Trigger an event +.br +.SS Scripts +.br + +.br +gpioStoreScript Store a script +.br +gpioRunScript Run a stored script +.br +gpioUpdateScript Set a scripts parameters +.br +gpioScriptStatus Get script status and parameters +.br +gpioStopScript Stop a running script +.br +gpioDeleteScript Delete a stored script +.br +.SS I2C +.br + +.br +i2cOpen Opens an I2C device +.br +i2cClose Closes an I2C device +.br + +.br +i2cWriteQuick SMBus write quick +.br + +.br +i2cReadByte SMBus read byte +.br +i2cWriteByte SMBus write byte +.br + +.br +i2cReadByteData SMBus read byte data +.br +i2cWriteByteData SMBus write byte data +.br + +.br +i2cReadWordData SMBus read word data +.br +i2cWriteWordData SMBus write word data +.br + +.br +i2cReadBlockData SMBus read block data +.br +i2cWriteBlockData SMBus write block data +.br + +.br +i2cReadI2CBlockData SMBus read I2C block data +.br +i2cWriteI2CBlockData SMBus write I2C block data +.br + +.br +i2cReadDevice Reads the raw I2C device +.br +i2cWriteDevice Writes the raw I2C device +.br + +.br +i2cProcessCall SMBus process call +.br +i2cBlockProcessCall SMBus block process call +.br + +.br +i2cSwitchCombined Sets or clears the combined flag +.br + +.br +i2cSegments Performs multiple I2C transactions +.br + +.br +i2cZip Performs multiple I2C transactions +.br +.SS I2C BIT BANG +.br + +.br +bbI2COpen Opens GPIO for bit banging I2C +.br +bbI2CClose Closes GPIO for bit banging I2C +.br + +.br +bbI2CZip Performs bit banged I2C transactions +.br +.SS I2C/SPI SLAVE +.br + +.br +bscXfer I2C/SPI as slave transfer +.br +.SS SERIAL +.br + +.br +serOpen Opens a serial device +.br +serClose Closes a serial device +.br + +.br +serReadByte Reads a byte from a serial device +.br +serWriteByte Writes a byte to a serial device +.br + +.br +serRead Reads bytes from a serial device +.br +serWrite Writes bytes to a serial device +.br + +.br +serDataAvailable Returns number of bytes ready to be read +.br +.SS SERIAL BIT BANG (read only) +.br + +.br +gpioSerialReadOpen Opens a GPIO for bit bang serial reads +.br +gpioSerialReadClose Closes a GPIO for bit bang serial reads +.br + +.br +gpioSerialReadInvert Configures normal/inverted for serial reads +.br + +.br +gpioSerialRead Reads bit bang serial data from a GPIO +.br +.SS SPI +.br + +.br +spiOpen Opens a SPI device +.br +spiClose Closes a SPI device +.br + +.br +spiRead Reads bytes from a SPI device +.br +spiWrite Writes bytes to a SPI device +.br +spiXfer Transfers bytes with a SPI device +.br +.SS SPI BIT BANG +.br + +.br +bbSPIOpen Opens GPIO for bit banging SPI +.br +bbSPIClose Closes GPIO for bit banging SPI +.br + +.br +bbSPIXfer Performs bit banged SPI transactions +.br +.SS FILES +.br + +.br +fileOpen Opens a file +.br +fileClose Closes a file +.br + +.br +fileRead Reads bytes from a file +.br +fileWrite Writes bytes to a file +.br + +.br +fileSeek Seeks to a position within a file +.br + +.br +fileList List files which match a pattern +.br +.SS WAVES +.br + +.br +gpioWaveClear Deletes all waveforms +.br + +.br +gpioWaveAddNew Starts a new waveform +.br +gpioWaveAddGeneric Adds a series of pulses to the waveform +.br +gpioWaveAddSerial Adds serial data to the waveform +.br + +.br +gpioWaveCreate Creates a waveform from added data +.br +gpioWaveCreatePad Creates a waveform of fixed size from added data +.br +gpioWaveDelete Deletes a waveform +.br + +.br +gpioWaveTxSend Transmits a waveform +.br + +.br +gpioWaveChain Transmits a chain of waveforms +.br + +.br +gpioWaveTxAt Returns the current transmitting waveform +.br + +.br +gpioWaveTxBusy Checks to see if the waveform has ended +.br + +.br +gpioWaveTxStop Aborts the current waveform +.br + +.br +gpioWaveGetCbs Length in CBs of the current waveform +.br +gpioWaveGetHighCbs Length of longest waveform so far +.br +gpioWaveGetMaxCbs Absolute maximum allowed CBs +.br + +.br +gpioWaveGetMicros Length in micros of the current waveform +.br +gpioWaveGetHighMicros Length of longest waveform so far +.br +gpioWaveGetMaxMicros Absolute maximum allowed micros +.br + +.br +gpioWaveGetPulses Length in pulses of the current waveform +.br +gpioWaveGetHighPulses Length of longest waveform so far +.br +gpioWaveGetMaxPulses Absolute maximum allowed pulses +.br +.SS UTILITIES +.br + +.br +gpioDelay Delay for a number of microseconds +.br + +.br +gpioTick Get current tick (microseconds) +.br + +.br +gpioHardwareRevision Get hardware revision +.br +gpioVersion Get the pigpio version +.br + +.br +getBitInBytes Get the value of a bit +.br +putBitInBytes Set the value of a bit +.br + +.br +gpioTime Get current time +.br +gpioSleep Sleep for specified time +.br + +.br +time_sleep Sleeps for a float number of seconds +.br +time_time Float number of seconds since the epoch +.br +.SS CONFIGURATION +.br + +.br +gpioCfgBufferSize Configure the GPIO sample buffer size +.br +gpioCfgClock Configure the GPIO sample rate +.br +gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) +.br +gpioCfgDMAchannels Configure the DMA channels +.br +gpioCfgPermissions Configure the GPIO access permissions +.br +gpioCfgInterfaces Configure user interfaces +.br +gpioCfgSocketPort Configure socket port +.br +gpioCfgMemAlloc Configure DMA memory allocation mode +.br +gpioCfgNetAddr Configure allowed network addresses +.br + +.br +gpioCfgInternals Configure misc. internals (DEPRECATED) +.br +gpioCfgGetInternals Get internal configuration settings +.br +gpioCfgSetInternals Set internal configuration settings +.br +.SS EXPERT +.br + +.br +rawWaveAddSPI Not intended for general use +.br +rawWaveAddGeneric Not intended for general use +.br +rawWaveCB Not intended for general use +.br +rawWaveCBAdr Not intended for general use +.br +rawWaveGetOOL Not intended for general use +.br +rawWaveSetOOL Not intended for general use +.br +rawWaveGetOut Not intended for general use +.br +rawWaveSetOut Not intended for general use +.br +rawWaveGetIn Not intended for general use +.br +rawWaveSetIn Not intended for general use +.br +rawWaveInfo Not intended for general use +.br +rawDumpWave Not intended for general use +.br +rawDumpScript Not intended for general use +.br +.SH FUNCTIONS + +.IP "\fBint gpioInitialise(void)\fP" +.IP "" 4 +Initialises the library. + +.br + +.br +Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. + +.br + +.br +gpioInitialise must be called before using the other library functions +with the following exceptions: + +.br + +.br + +.EX +\fBgpioCfg*\fP +.br +\fBgpioVersion\fP +.br +\fBgpioHardwareRevision\fP +.br + +.EE + +.br + +.br +\fBExample\fP +.br + +.EX +if (gpioInitialise() < 0) +.br +{ +.br + // pigpio initialisation failed. +.br +} +.br +else +.br +{ +.br + // pigpio initialised okay. +.br +} +.br + +.EE + +.IP "\fBvoid gpioTerminate(void)\fP" +.IP "" 4 +Terminates the library. + +.br + +.br +Returns nothing. + +.br + +.br +Call before program exit. + +.br + +.br +This function resets the used DMA channels, releases memory, and +terminates any running threads. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioTerminate(); +.br + +.EE + +.IP "\fBint gpioSetMode(unsigned gpio, unsigned mode)\fP" +.IP "" 4 +Sets the GPIO mode, typically input or output. + +.br + +.br + +.EX +gpio: 0-53 +.br +mode: 0-7 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. + +.br + +.br +Arduino style: pinMode. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioSetMode(17, PI_INPUT); // Set GPIO17 as input. +.br + +.br +gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output. +.br + +.br +gpioSetMode(22,PI_ALT0); // Set GPIO22 to alternative mode 0. +.br + +.EE + +.br + +.br +See \fBhttp://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf\fP page 102 for an overview of the modes. + +.IP "\fBint gpioGetMode(unsigned gpio)\fP" +.IP "" 4 +Gets the GPIO mode. + +.br + +.br + +.EX +gpio: 0-53 +.br + +.EE + +.br + +.br +Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. + +.br + +.br +\fBExample\fP +.br + +.EX +if (gpioGetMode(17) != PI_ALT0) +.br +{ +.br + gpioSetMode(17, PI_ALT0); // set GPIO17 to ALT0 +.br +} +.br + +.EE + +.IP "\fBint gpioSetPullUpDown(unsigned gpio, unsigned pud)\fP" +.IP "" 4 +Sets or clears resistor pull ups or downs on the GPIO. + +.br + +.br + +.EX +gpio: 0-53 +.br + pud: 0-2 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioSetPullUpDown(17, PI_PUD_UP); // Sets a pull-up. +.br + +.br +gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down. +.br + +.br +gpioSetPullUpDown(23, PI_PUD_OFF); // Clear any pull-ups/downs. +.br + +.EE + +.IP "\fBint gpioRead(unsigned gpio)\fP" +.IP "" 4 +Reads the GPIO level, on or off. + +.br + +.br + +.EX +gpio: 0-53 +.br + +.EE + +.br + +.br +Returns the GPIO level if OK, otherwise PI_BAD_GPIO. + +.br + +.br +Arduino style: digitalRead. + +.br + +.br +\fBExample\fP +.br + +.EX +printf("GPIO24 is level %d", gpioRead(24)); +.br + +.EE + +.IP "\fBint gpioWrite(unsigned gpio, unsigned level)\fP" +.IP "" 4 +Sets the GPIO level, on or off. + +.br + +.br + +.EX + gpio: 0-53 +.br +level: 0-1 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. + +.br + +.br +If PWM or servo pulses are active on the GPIO they are switched off. + +.br + +.br +Arduino style: digitalWrite + +.br + +.br +\fBExample\fP +.br + +.EX +gpioWrite(24, 1); // Set GPIO24 high. +.br + +.EE + +.IP "\fBint gpioPWM(unsigned user_gpio, unsigned dutycycle)\fP" +.IP "" 4 +Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). +Range defaults to 255. + +.br + +.br + +.EX +user_gpio: 0-31 +.br +dutycycle: 0-range +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. + +.br + +.br +Arduino style: analogWrite + +.br + +.br +This and the servo functionality use the DMA and PWM or PCM peripherals +to control and schedule the pulse lengths and dutycycles. + +.br + +.br +The \fBgpioSetPWMrange\fP function may be used to change the default +range of 255. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioPWM(17, 255); // Sets GPIO17 full on. +.br + +.br +gpioPWM(18, 128); // Sets GPIO18 half on. +.br + +.br +gpioPWM(23, 0); // Sets GPIO23 full off. +.br + +.EE + +.IP "\fBint gpioGetPWMdutycycle(unsigned user_gpio)\fP" +.IP "" 4 +Returns the PWM dutycycle setting for the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + +.EE + +.br + +.br +Returns between 0 (off) and range (fully on) if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. + +.br + +.br +For normal PWM the dutycycle will be out of the defined range +for the GPIO (see \fBgpioGetPWMrange\fP). + +.br + +.br +If a hardware clock is active on the GPIO the reported dutycycle +will be 500000 (500k) out of 1000000 (1M). + +.br + +.br +If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). + +.br + +.br +Normal PWM range defaults to 255. + +.IP "\fBint gpioSetPWMrange(unsigned user_gpio, unsigned range)\fP" +.IP "" 4 +Selects the dutycycle range to be used for the GPIO. Subsequent calls +to gpioPWM will use a dutycycle between 0 (off) and range (fully on). + +.br + +.br + +.EX +user_gpio: 0-31 +.br + range: 25-40000 +.br + +.EE + +.br + +.br +Returns the real range for the given GPIO's frequency if OK, +otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. + +.br + +.br +If PWM is currently active on the GPIO its dutycycle will be scaled +to reflect the new range. + +.br + +.br +The real range, the number of steps between fully off and fully +on for each frequency, is given in the following table. + +.br + +.br + +.EX + 25, 50, 100, 125, 200, 250, 400, 500, 625, +.br + 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000 +.br + +.EE + +.br + +.br +The real value set by \fBgpioPWM\fP is (dutycycle * real range) / range. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioSetPWMrange(24, 2000); // Now 2000 is fully on +.br + // 1000 is half on +.br + // 500 is quarter on, etc. +.br + +.EE + +.IP "\fBint gpioGetPWMrange(unsigned user_gpio)\fP" +.IP "" 4 +Returns the dutycycle range used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + +.EE + +.br + +.br +If a hardware clock or hardware PWM is active on the GPIO +the reported range will be 1000000 (1M). + +.br + +.br +\fBExample\fP +.br + +.EX +r = gpioGetPWMrange(23); +.br + +.EE + +.IP "\fBint gpioGetPWMrealRange(unsigned user_gpio)\fP" +.IP "" 4 +Returns the real range used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + +.EE + +.br + +.br +If a hardware clock is active on the GPIO the reported real +range will be 1000000 (1M). + +.br + +.br +If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. + +.br + +.br +\fBExample\fP +.br + +.EX +rr = gpioGetPWMrealRange(17); +.br + +.EE + +.IP "\fBint gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)\fP" +.IP "" 4 +Sets the frequency in hertz to be used for the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31 +.br +frequency: >=0 +.br + +.EE + +.br + +.br +Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO. + +.br + +.br +If PWM is currently active on the GPIO it will be +switched off and then back on at the new frequency. + +.br + +.br +Each GPIO can be independently set to one of 18 different PWM +frequencies. + +.br + +.br +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). + +.br + +.br +The frequencies for each sample rate are: + +.br + +.br + +.EX + Hertz +.br + +.br + 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 +.br + 1250 1000 800 500 400 250 200 100 50 +.br + +.br + 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 +.br + 625 500 400 250 200 125 100 50 25 +.br + +.br + 4: 10000 5000 2500 2000 1250 1000 625 500 400 +.br + 313 250 200 125 100 63 50 25 13 +.br +sample +.br + rate +.br + (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 +.br + 250 200 160 100 80 50 40 20 10 +.br + +.br + 8: 5000 2500 1250 1000 625 500 313 250 200 +.br + 156 125 100 63 50 31 25 13 6 +.br + +.br + 10: 4000 2000 1000 800 500 400 250 200 160 +.br + 125 100 80 50 40 25 20 10 5 +.br + +.EE + +.br + +.br +\fBExample\fP +.br + +.EX +gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency. +.br + +.br +gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz. +.br + +.br +gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency. +.br + +.EE + +.IP "\fBint gpioGetPWMfrequency(unsigned user_gpio)\fP" +.IP "" 4 +Returns the frequency (in hertz) used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + +.EE + +.br + +.br +For normal PWM the frequency will be that defined for the GPIO by +\fBgpioSetPWMfrequency\fP. + +.br + +.br +If a hardware clock is active on the GPIO the reported frequency +will be that set by \fBgpioHardwareClock\fP. + +.br + +.br +If hardware PWM is active on the GPIO the reported frequency +will be that set by \fBgpioHardwarePWM\fP. + +.br + +.br +\fBExample\fP +.br + +.EX +f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23. +.br + +.EE + +.IP "\fBint gpioServo(unsigned user_gpio, unsigned pulsewidth)\fP" +.IP "" 4 +Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to +2500 (most clockwise). + +.br + +.br + +.EX + user_gpio: 0-31 +.br +pulsewidth: 0, 500-2500 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. + +.br + +.br +The range supported by servos varies and should probably be determined +by experiment. A value of 1500 should always be safe and represents +the mid-point of rotation. You can DAMAGE a servo if you command it +to move beyond its limits. + +.br + +.br +The following 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. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioServo(17, 1000); // Move servo to safe position anti-clockwise. +.br + +.br +gpioServo(23, 1500); // Move servo to centre position. +.br + +.br +gpioServo(25, 2000); // Move servo to safe position clockwise. +.br + +.EE + +.br + +.br +OTHER UPDATE RATES: + +.br + +.br +This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. + +.br + +.br + +.EX +PWM Hz 50 100 200 400 500 +.br +1E6/Hz 20000 10000 5000 2500 2000 +.br + +.EE + +.br + +.br +Firstly set the desired PWM frequency using \fBgpioSetPWMfrequency\fP. + +.br + +.br +Then set the PWM range using \fBgpioSetPWMrange\fP to 1E6/frequency. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. + +.br + +.br +E.g. If you want to update a servo connected to GPIO25 at 400Hz + +.br + +.br + +.EX +gpioSetPWMfrequency(25, 400); +.br + +.br +gpioSetPWMrange(25, 2500); +.br + +.EE + +.br + +.br +Thereafter use the PWM command to move the servo, +e.g. gpioPWM(25, 1500) will set a 1500 us pulse. + +.IP "\fBint gpioGetServoPulsewidth(unsigned user_gpio)\fP" +.IP "" 4 +Returns the servo pulsewidth setting for the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + +.EE + +.br + +.br +Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) +if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. + +.IP "\fBint gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)\fP" +.IP "" 4 +Registers a function to be called (a callback) when the specified +GPIO changes state. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + f: the callback function +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO. + +.br + +.br +One callback may be registered per GPIO. + +.br + +.br +The callback is passed the GPIO, the new level, and the tick. + +.br + +.br + +.EX +Parameter Value Meaning +.br + +.br +GPIO 0-31 The GPIO which has changed state +.br + +.br +level 0-2 0 = change to low (a falling edge) +.br + 1 = change to high (a rising edge) +.br + 2 = no level change (a watchdog timeout) +.br + +.br +tick 32 bit The number of microseconds since boot +.br + WARNING: this wraps around from +.br + 4294967295 to 0 roughly every 72 minutes +.br + +.EE + +.br + +.br +The alert may be cancelled by passing NULL as the function. + +.br + +.br +The GPIO are sampled at a rate set when the library is started. + +.br + +.br +If a value isn't specifically set the default of 5 us is used. + +.br + +.br +The number of samples per second is given in the following table. + +.br + +.br + +.EX + samples +.br + per sec +.br + +.br + 1 1,000,000 +.br + 2 500,000 +.br +sample 4 250,000 +.br +rate 5 200,000 +.br +(us) 8 125,000 +.br + 10 100,000 +.br + +.EE + +.br + +.br +Level changes shorter than the sample rate may be missed. + +.br + +.br +The thread which calls the alert functions is triggered nominally +1000 times per second. The active alert functions will be called +once per level change since the last time the thread was activated. +i.e. The active alert functions will get all level changes but there +will be a latency. + +.br + +.br +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use \fBgpioRead\fP. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. + +.br + +.br +The tick value is the time stamp of the sample in microseconds, see +\fBgpioTick\fP for more details. + +.br + +.br +\fBExample\fP +.br + +.EX +void aFunction(int gpio, int level, uint32_t tick) +.br +{ +.br + printf("GPIO %d became %d at %d", gpio, level, tick); +.br +} +.br + +.br +// call aFunction whenever GPIO 4 changes state +.br + +.br +gpioSetAlertFunc(4, aFunction); +.br + +.EE + +.IP "\fBint gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)\fP" +.IP "" 4 +Registers a function to be called (a callback) when the specified +GPIO changes state. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + f: the callback function +.br + userdata: pointer to arbitrary user data +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO. + +.br + +.br +One callback may be registered per GPIO. + +.br + +.br +The callback is passed the GPIO, the new level, the tick, and +the userdata pointer. + +.br + +.br + +.EX +Parameter Value Meaning +.br + +.br +GPIO 0-31 The GPIO which has changed state +.br + +.br +level 0-2 0 = change to low (a falling edge) +.br + 1 = change to high (a rising edge) +.br + 2 = no level change (a watchdog timeout) +.br + +.br +tick 32 bit The number of microseconds since boot +.br + WARNING: this wraps around from +.br + 4294967295 to 0 roughly every 72 minutes +.br + +.br +userdata pointer Pointer to an arbitrary object +.br + +.EE + +.br + +.br +See \fBgpioSetAlertFunc\fP for further details. + +.br + +.br +Only one of \fBgpioSetAlertFunc\fP or \fBgpioSetAlertFuncEx\fP can be +registered per GPIO. + +.IP "\fBint gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)\fP" +.IP "" 4 +Registers a function to be called (a callback) whenever the specified +GPIO interrupt occurs. + +.br + +.br + +.EX + gpio: 0-53 +.br + edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE +.br +timeout: interrupt timeout in milliseconds (<=0 to cancel) +.br + f: the callback function +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, +or PI_BAD_ISR_INIT. + +.br + +.br +One function may be registered per GPIO. + +.br + +.br +The function is passed the GPIO, the current level, and the +current tick. The level will be PI_TIMEOUT if the optional +interrupt timeout expires. + +.br + +.br + +.EX +Parameter Value Meaning +.br + +.br +GPIO 0-53 The GPIO which has changed state +.br + +.br +level 0-2 0 = change to low (a falling edge) +.br + 1 = change to high (a rising edge) +.br + 2 = no level change (interrupt timeout) +.br + +.br +tick 32 bit The number of microseconds since boot +.br + WARNING: this wraps around from +.br + 4294967295 to 0 roughly every 72 minutes +.br + +.EE + +.br + +.br +The underlying Linux sysfs GPIO interface is used to provide +the interrupt services. + +.br + +.br +The first time the function is called, with a non-NULL f, the +GPIO is exported, set to be an input, and set to interrupt +on the given edge and timeout. + +.br + +.br +Subsequent calls, with a non-NULL f, can vary one or more of the +edge, timeout, or function. + +.br + +.br +The ISR may be cancelled by passing a NULL f, in which case the +GPIO is unexported. + +.br + +.br +The tick is that read at the time the process was informed of +the interrupt. This will be a variable number of microseconds +after the interrupt occurred. Typically the latency will be of +the order of 50 microseconds. The latency is not guaranteed +and will vary with system load. + +.br + +.br +The level is that read at the time the process was informed of +the interrupt, or PI_TIMEOUT if the optional interrupt timeout +expired. It may not be the same as the expected edge as +interrupts happening in rapid succession may be missed by the +kernel (i.e. this mechanism can not be used to capture several +interrupts only a few microseconds apart). + +.IP "\fBint gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)\fP" +.IP "" 4 +Registers a function to be called (a callback) whenever the specified +GPIO interrupt occurs. + +.br + +.br + +.EX + gpio: 0-53 +.br + edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE +.br + timeout: interrupt timeout in milliseconds (<=0 to cancel) +.br + f: the callback function +.br +userdata: pointer to arbitrary user data +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, +or PI_BAD_ISR_INIT. + +.br + +.br +The function is passed the GPIO, the current level, the +current tick, and the userdata pointer. + +.br + +.br + +.EX +Parameter Value Meaning +.br + +.br +GPIO 0-53 The GPIO which has changed state +.br + +.br +level 0-2 0 = change to low (a falling edge) +.br + 1 = change to high (a rising edge) +.br + 2 = no level change (interrupt timeout) +.br + +.br +tick 32 bit The number of microseconds since boot +.br + WARNING: this wraps around from +.br + 4294967295 to 0 roughly every 72 minutes +.br + +.br +userdata pointer Pointer to an arbitrary object +.br + +.EE + +.br + +.br +Only one of \fBgpioSetISRFunc\fP or \fBgpioSetISRFuncEx\fP can be +registered per GPIO. + +.br + +.br +See \fBgpioSetISRFunc\fP for further details. + +.IP "\fBint gpioNotifyOpen(void)\fP" +.IP "" 4 +This function requests a free notification handle. + +.br + +.br +Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. + +.br + +.br +A notification is a method for being notified of GPIO state changes +via a pipe or socket. + +.br + +.br +Pipe notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). E.g. if the +function returns 15 then the notifications must be read +from /dev/pigpio15. + +.br + +.br +Socket notifications are returned to the socket which requested the +handle. + +.br + +.br +\fBExample\fP +.br + +.EX +h = gpioNotifyOpen(); +.br + +.br +if (h >= 0) +.br +{ +.br + sprintf(str, "/dev/pigpio%d", h); +.br + +.br + fd = open(str, O_RDONLY); +.br + +.br + if (fd >= 0) +.br + { +.br + // Okay. +.br + } +.br + else +.br + { +.br + // Error. +.br + } +.br +} +.br +else +.br +{ +.br + // Error. +.br +} +.br + +.EE + +.IP "\fBint gpioNotifyOpenWithSize(int bufSize)\fP" +.IP "" 4 +This function requests a free notification handle. + +.br + +.br +It differs from \fBgpioNotifyOpen\fP in that the pipe size may be +specified, whereas \fBgpioNotifyOpen\fP uses the default pipe size. + +.br + +.br +See \fBgpioNotifyOpen\fP for further details. + +.IP "\fBint gpioNotifyBegin(unsigned handle, uint32_t bits)\fP" +.IP "" 4 +This function starts notifications on a previously opened handle. + +.br + +.br + +.EX +handle: >=0, as returned by \fBgpioNotifyOpen\fP +.br + bits: a bit mask indicating the GPIO of interest +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +The notification sends state changes for each GPIO whose corresponding +bit in bits is set. + +.br + +.br +Each notification occupies 12 bytes in the fifo and has the +following structure. + +.br + +.br + +.EX +typedef struct +.br +{ +.br + uint16_t seqno; +.br + uint16_t flags; +.br + uint32_t tick; +.br + uint32_t level; +.br +} gpioReport_t; +.br + +.EE + +.br + +.br +seqno: starts at 0 each time the handle is opened and then increments +by one for each report. + +.br + +.br +flags: three flags are defined, PI_NTFY_FLAGS_WDOG, +PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. + +.br + +.br +If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. + +.br + +.br +If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. + +.br + +.br +If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags +indicate an event which has been triggered. + +.br + +.br +tick: the number of microseconds since system boot. It wraps around +after 1h12m. + +.br + +.br +level: indicates the level of each GPIO. If bit 1<=0, as returned by \fBgpioNotifyOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +Notifications for the handle are suspended until \fBgpioNotifyBegin\fP +is called again. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioNotifyPause(h); +.br + +.EE + +.IP "\fBint gpioNotifyClose(unsigned handle)\fP" +.IP "" 4 +This function stops notifications on a previously opened handle +and releases the handle for reuse. + +.br + +.br + +.EX +handle: >=0, as returned by \fBgpioNotifyOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioNotifyClose(h); +.br + +.EE + +.IP "\fBint gpioWaveClear(void)\fP" +.IP "" 4 +This function clears all waveforms and any data added by calls to the +\fBgpioWaveAdd*\fP functions. + +.br + +.br +Returns 0 if OK. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioWaveClear(); +.br + +.EE + +.IP "\fBint gpioWaveAddNew(void)\fP" +.IP "" 4 +This function starts a new empty waveform. + +.br + +.br +You wouldn't normally need to call this function as it is automatically +called after a waveform is created with the \fBgpioWaveCreate\fP function. + +.br + +.br +Returns 0 if OK. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioWaveAddNew(); +.br + +.EE + +.IP "\fBint gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)\fP" +.IP "" 4 +This function adds a number of pulses to the current waveform. + +.br + +.br + +.EX +numPulses: the number of pulses +.br + pulses: an array of pulses +.br + +.EE + +.br + +.br +Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. + +.br + +.br +The pulses are interleaved in time order within the existing waveform +(if any). + +.br + +.br +Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. + +.br + +.br +If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist of a delay. + +.br + +.br +\fBExample\fP +.br + +.EX +// Construct and send a 30 microsecond square wave. +.br + +.br +gpioSetMode(gpio, PI_OUTPUT); +.br + +.br +pulse[0].gpioOn = (1<= 0) +.br +{ +.br + gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT); +.br + +.br + // Transmit for 30 seconds. +.br + +.br + sleep(30); +.br + +.br + gpioWaveTxStop(); +.br +} +.br +else +.br +{ +.br + // Wave create failed. +.br +} +.br + +.EE + +.IP "\fBint gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)\fP" +.IP "" 4 +This function adds a waveform representing serial data to the +existing waveform (if any). The serial data starts offset +microseconds from the start of the waveform. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + baud: 50-1000000 +.br +data_bits: 1-32 +.br +stop_bits: 2-8 +.br + offset: >=0 +.br + numBytes: >=1 +.br + str: an array of chars (which may contain nulls) +.br + +.EE + +.br + +.br +Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. + +.br + +.br +NOTES: + +.br + +.br +The serial data is formatted as one start bit, data_bits data bits, and +stop_bits/2 stop bits. + +.br + +.br +It is legal to add serial data streams with different baud rates to +the same waveform. + +.br + +.br +numBytes is the number of bytes of data in str. + +.br + +.br +The bytes required for each character depend upon data_bits. + +.br + +.br +For data_bits 1-8 there will be one byte per character. +.br +For data_bits 9-16 there will be two bytes per character. +.br +For data_bits 17-32 there will be four bytes per character. + +.br + +.br +\fBExample\fP +.br + +.EX +#define MSG_LEN 8 +.br + +.br +int i; +.br +char *str; +.br +char data[MSG_LEN]; +.br + +.br +str = "Hello world!"; +.br + +.br +gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str); +.br + +.br +for (i=0; i=0, as returned by \fBgpioWaveCreate\fP +.br + +.EE + +.br + +.br +Wave ids are allocated in order, 0, 1, 2, etc. + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_WAVE_ID. + +.IP "\fBint gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)\fP" +.IP "" 4 +This function transmits the waveform with id wave_id. The mode +determines whether the waveform is sent once or cycles endlessly. +The SYNC variants wait for the current waveform to reach the +end of a cycle or finish before starting the new waveform. + +.br + +.br +WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. + +.br + +.br +NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled. + +.br + +.br + +.EX + wave_id: >=0, as returned by \fBgpioWaveCreate\fP +.br +wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT, +.br + PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC +.br + +.EE + +.br + +.br +Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. + +.IP "\fBint gpioWaveChain(char *buf, unsigned bufSize)\fP" +.IP "" 4 +This function transmits a chain of waveforms. + +.br + +.br +NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled. + +.br + +.br +The waves to be transmitted are specified by the contents of buf +which contains an ordered list of \fBwave_id\fPs and optional command +codes and related data. + +.br + +.br + +.EX + buf: pointer to the wave_ids and optional command codes +.br +bufSize: the number of bytes in buf +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. + +.br + +.br +Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. + +.br + +.br +A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. + +.br + +.br +Delays between waves may be added with the delay command. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +Loop Start 255 0 Identify start of a wave block +.br +Loop Repeat 255 1 x y loop x + y*256 times +.br +Delay 255 2 x y delay x + y*256 microseconds +.br +Loop Forever 255 3 loop forever +.br + +.br + +.br +If present Loop Forever must be the last entry in the chain. + +.br + +.br +The code is currently dimensioned to support a chain with roughly +600 entries and 20 loop counters. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +#define WAVES 5 +.br +#define GPIO 4 +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int i, wid[WAVES]; +.br + +.br + if (gpioInitialise()<0) return -1; +.br + +.br + gpioSetMode(GPIO, PI_OUTPUT); +.br + +.br + printf("start piscope, press return"); getchar(); +.br + +.br + for (i=0; i=0 +.br + +.EE + +.br + +.br +Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. + +.br + +.br +The bytes returned for each character depend upon the number of +data bits \fBdata_bits\fP specified in the \fBgpioSerialReadOpen\fP command. + +.br + +.br +For \fBdata_bits\fP 1-8 there will be one byte per character. +.br +For \fBdata_bits\fP 9-16 there will be two bytes per character. +.br +For \fBdata_bits\fP 17-32 there will be four bytes per character. + +.IP "\fBint gpioSerialReadClose(unsigned user_gpio)\fP" +.IP "" 4 +This function closes a GPIO for bit bang reading of serial data. + +.br + +.br + +.EX +user_gpio: 0-31, previously opened with \fBgpioSerialReadOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. + +.IP "\fBint i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)\fP" +.IP "" 4 +This returns a handle for the device at the address on the I2C bus. + +.br + +.br + +.EX + i2cBus: >=0 +.br + i2cAddr: 0-0x7F +.br +i2cFlags: 0 +.br + +.EE + +.br + +.br +No flags are currently defined. This parameter should be set to zero. + +.br + +.br +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + +.br + +.br +The GPIO used are given in the following table. + +.br + +.br + SDA SCL +.br +I2C 0 0 1 +.br +I2C 1 2 3 +.br + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. + +.br + +.br +For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. + +.br + +.br + +.EX +S (1 bit) : Start bit +.br +P (1 bit) : Stop bit +.br +Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. +.br +A, NA (1 bit) : Accept and not accept bit. +.br +.br +.br +Addr (7 bits): I2C 7 bit address. +.br +i2cReg (8 bits): Command byte, a byte which often selects a register. +.br +Data (8 bits): A data byte. +.br +Count (8 bits): A byte defining the length of a block operation. +.br + +.br +[..]: Data sent by the device. +.br + +.EE + +.IP "\fBint i2cClose(unsigned handle)\fP" +.IP "" 4 +This closes the I2C device associated with the handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint i2cWriteQuick(unsigned handle, unsigned bit)\fP" +.IP "" 4 +This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + bit: 0-1, the value to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Quick command. SMBus 2.0 5.5.1 + +.EX +S Addr bit [A] P +.br + +.EE + +.IP "\fBint i2cWriteByte(unsigned handle, unsigned bVal)\fP" +.IP "" 4 +This sends a single byte to the device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + bVal: 0-0xFF, the value to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Send byte. SMBus 2.0 5.5.2 + +.EX +S Addr Wr [A] bVal [A] P +.br + +.EE + +.IP "\fBint i2cReadByte(unsigned handle)\fP" +.IP "" 4 +This reads a single byte from the device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + +.EE + +.br + +.br +Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. + +.br + +.br +Receive byte. SMBus 2.0 5.5.3 + +.EX +S Addr Rd [A] [Data] NA P +.br + +.EE + +.IP "\fBint i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)\fP" +.IP "" 4 +This writes a single byte to the specified register of the device +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to write +.br + bVal: 0-0xFF, the value to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Write byte. SMBus 2.0 5.5.4 + +.EX +S Addr Wr [A] i2cReg [A] bVal [A] P +.br + +.EE + +.IP "\fBint i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)\fP" +.IP "" 4 +This writes a single 16 bit word to the specified register of the device +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to write +.br + wVal: 0-0xFFFF, the value to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Write word. SMBus 2.0 5.5.4 + +.EX +S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P +.br + +.EE + +.IP "\fBint i2cReadByteData(unsigned handle, unsigned i2cReg)\fP" +.IP "" 4 +This reads a single byte from the specified register of the device +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to read +.br + +.EE + +.br + +.br +Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Read byte. SMBus 2.0 5.5.5 + +.EX +S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P +.br + +.EE + +.IP "\fBint i2cReadWordData(unsigned handle, unsigned i2cReg)\fP" +.IP "" 4 +This reads a single 16 bit word from the specified register of the device +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to read +.br + +.EE + +.br + +.br +Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Read word. SMBus 2.0 5.5.5 + +.EX +S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P +.br + +.EE + +.IP "\fBint i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)\fP" +.IP "" 4 +This writes 16 bits of data to the specified register of the device +associated with handle and reads 16 bits of data in return. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to write/read +.br + wVal: 0-0xFFFF, the value to write +.br + +.EE + +.br + +.br +Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Process call. SMBus 2.0 5.5.6 + +.EX +S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] +.br + S Addr Rd [A] [DataLow] A [DataHigh] NA P +.br + +.EE + +.IP "\fBint i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes up to 32 bytes to the specified register of the device +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to write +.br + buf: an array with the data to send +.br + count: 1-32, the number of bytes to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Block write. SMBus 2.0 5.5.7 + +.EX +S Addr Wr [A] i2cReg [A] count [A] +.br + buf0 [A] buf1 [A] ... [A] bufn [A] P +.br + +.EE + +.IP "\fBint i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)\fP" +.IP "" 4 +This reads a block of up to 32 bytes from the specified register of +the device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to read +.br + buf: an array to receive the read data +.br + +.EE + +.br + +.br +The amount of returned data is set by the device. + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Block read. SMBus 2.0 5.5.7 + +.EX +S Addr Wr [A] i2cReg [A] +.br + S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P +.br + +.EE + +.IP "\fBint i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to write/read +.br + buf: an array with the data to send and to receive the read data +.br + count: 1-32, the number of bytes to write +.br + +.EE + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +The SMBus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. + +.br + +.br +Block write-block read. SMBus 2.0 5.5.8 + +.EX +S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A] +.br + S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P +.br + +.EE + +.IP "\fBint i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" +.IP "" 4 +This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to read +.br + buf: an array to receive the read data +.br + count: 1-32, the number of bytes to read +.br + +.EE + +.br + +.br +Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br + +.EX +S Addr Wr [A] i2cReg [A] +.br + S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P +.br + +.EE + +.IP "\fBint i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes 1 to 32 bytes to the specified register of the device +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br +i2cReg: 0-255, the register to write +.br + buf: the data to write +.br + count: 1-32, the number of bytes to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br + +.EX +S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P +.br + +.EE + +.IP "\fBint i2cReadDevice(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This reads count bytes from the raw device into buf. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + buf: an array to receive the read data bytes +.br + count: >0, the number of bytes to read +.br + +.EE + +.br + +.br +Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. + +.br + +.br + +.EX +S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P +.br + +.EE + +.IP "\fBint i2cWriteDevice(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This writes count bytes from buf to the raw device. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + buf: an array containing the data bytes to write +.br + count: >0, the number of bytes to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br + +.EX +S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P +.br + +.EE + +.IP "\fBvoid i2cSwitchCombined(int setting)\fP" +.IP "" 4 +This sets the I2C (i2c-bcm2708) module "use combined transactions" +parameter on or off. + +.br + +.br + +.EX +setting: 0 to set the parameter off, non-zero to set it on +.br + +.EE + +.br + +.br + +.br + +.br +NOTE: when the flag is on a write followed by a read to the same +slave address will use a repeated start (rather than a stop/start). + +.IP "\fBint i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)\fP" +.IP "" 4 +This function executes multiple I2C segments in one transaction by +calling the I2C_RDWR ioctl. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + segs: an array of I2C segments +.br +numSegs: >0, the number of I2C segments +.br + +.EE + +.br + +.br +Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. + +.IP "\fBint i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" +.IP "" 4 +This function executes a sequence of I2C operations. The +operations to be performed are specified by the contents of inBuf +which contains the concatenated command codes and associated data. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + inBuf: pointer to the concatenated I2C commands, see below +.br + inLen: size of command buffer +.br +outBuf: pointer to buffer to hold returned data +.br +outLen: size of output buffer +.br + +.EE + +.br + +.br +Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +End 0 No more commands +.br +Escape 1 Next P is two bytes +.br +On 2 Switch combined flag on +.br +Off 3 Switch combined flag off +.br +Address 4 P Set I2C address to P +.br +Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) +.br +Read 6 P Read P bytes of data +.br +Write 7 P ... Write P bytes of data +.br + +.br + +.br +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +.br + +.br +The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. + +.br + +.br +The returned I2C data is stored in consecutive locations of outBuf. + +.br + +.br +\fBExample\fP +.br + +.EX +Set address 0x53, write 0x32, read 6 bytes +.br +Set address 0x1E, write 0x03, read 6 bytes +.br +Set address 0x68, write 0x1B, read 8 bytes +.br +End +.br + +.br +0x04 0x53 0x07 0x01 0x32 0x06 0x06 +.br +0x04 0x1E 0x07 0x01 0x03 0x06 0x06 +.br +0x04 0x68 0x07 0x01 0x1B 0x06 0x08 +.br +0x00 +.br + +.EE + +.IP "\fBint bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)\fP" +.IP "" 4 +This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. + +.br + +.br +Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. + +.br + +.br +o baud rates as low as 50 +.br +o repeated starts +.br +o clock stretching +.br +o I2C on any pair of spare GPIO + +.br + +.br + +.EX + SDA: 0-31 +.br + SCL: 0-31 +.br +baud: 50-500000 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. + +.br + +.br +NOTE: + +.br + +.br +The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. + +.IP "\fBint bbI2CClose(unsigned SDA)\fP" +.IP "" 4 +This function stops bit banging I2C on a pair of GPIO previously +opened with \fBbbI2COpen\fP. + +.br + +.br + +.EX +SDA: 0-31, the SDA GPIO used in a prior call to \fBbbI2COpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. + +.IP "\fBint bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" +.IP "" 4 +This function executes a sequence of bit banged I2C operations. The +operations to be performed are specified by the contents of inBuf +which contains the concatenated command codes and associated data. + +.br + +.br + +.EX + SDA: 0-31 (as used in a prior call to \fBbbI2COpen\fP) +.br + inBuf: pointer to the concatenated I2C commands, see below +.br + inLen: size of command buffer +.br +outBuf: pointer to buffer to hold returned data +.br +outLen: size of output buffer +.br + +.EE + +.br + +.br +Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +End 0 No more commands +.br +Escape 1 Next P is two bytes +.br +Start 2 Start condition +.br +Stop 3 Stop condition +.br +Address 4 P Set I2C address to P +.br +Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) +.br +Read 6 P Read P bytes of data +.br +Write 7 P ... Write P bytes of data +.br + +.br + +.br +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +.br + +.br +The address and flags default to 0. The address and flags maintain +their previous value until updated. + +.br + +.br +No flags are currently defined. + +.br + +.br +The returned I2C data is stored in consecutive locations of outBuf. + +.br + +.br +\fBExample\fP +.br + +.EX +Set address 0x53 +.br +start, write 0x32, (re)start, read 6 bytes, stop +.br +Set address 0x1E +.br +start, write 0x03, (re)start, read 6 bytes, stop +.br +Set address 0x68 +.br +start, write 0x1B, (re)start, read 8 bytes, stop +.br +End +.br + +.br +0x04 0x53 +.br +0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 +.br + +.br +0x04 0x1E +.br +0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 +.br + +.br +0x04 0x68 +.br +0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 +.br + +.br +0x00 +.br + +.EE + +.IP "\fBint bscXfer(bsc_xfer_t *bsc_xfer)\fP" +.IP "" 4 +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +.br + +.br +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +.br + +.br +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +.br + +.br +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. + +.br + +.br +I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. + +.br + +.br +The function sets the BSC mode, writes any data in +the transmit buffer to the BSC transmit FIFO, and +copies any data in the BSC receive FIFO to the +receive buffer. + +.br + +.br + +.EX +bsc_xfer:= a structure defining the transfer +.br + +.br +typedef struct +.br +{ +.br + uint32_t control; // Write +.br + int rxCnt; // Read only +.br + char rxBuf[BSC_FIFO_SIZE]; // Read only +.br + int txCnt; // Write +.br + char txBuf[BSC_FIFO_SIZE]; // Write +.br +} bsc_xfer_t; +.br + +.EE + +.br + +.br +To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. + +.br + +.br +Upon return rxCnt will be set to the number of received bytes placed +in rxBuf. + +.br + +.br +Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. + +.br + +.br +GPIO used for models other than those based on the BCM2711. + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 18 19 - - - - +.br +SPI - - 18 19 20 21 +.br + +.br + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 10 11 - - - - +.br +SPI - - 10 11 9 8 +.br + +.br + +.br +When a zero control word is received the used GPIO will be reset +to INPUT mode. + +.br + +.br +The returned function value is the status of the transfer (see below). + +.br + +.br +If there was an error the status will be less than zero +(and will contain the error code). + +.br + +.br +The most significant word of the returned status contains the number +of bytes actually copied from txBuf to the BSC transmit FIFO (may be +less than requested if the FIFO already contained untransmitted data). + +.br + +.br +control consists of the following bits. + +.br + +.br + +.EX +22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN +.br + +.EE + +.br + +.br +Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. + +.br + +.br +aaaaaaa defines the I2C slave address (only relevant in I2C mode) +.br +IT invert transmit status flags +.br +HC enable host control +.br +TF enable test FIFO +.br +IR invert receive status flags +.br +RE enable receive +.br +TE enable transmit +.br +BK abort operation and clear FIFOs +.br +EC send control register as first I2C byte +.br +ES send status register as first I2C byte +.br +PL set SPI polarity high +.br +PH set SPI phase high +.br +I2 enable I2C mode +.br +SP enable SPI mode +.br +EN enable BSC peripheral +.br + +.br + +.br +The returned status has the following format + +.br + +.br + +.EX +20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + S S S S S R R R R R T T T T T RB TE RF TF RE TB +.br + +.EE + +.br + +.br +Bits 0-15 are copied unchanged from the BSC FR register. See +pages 165-166 of the Broadcom peripherals document for full +details. + +.br + +.br +SSSSS number of bytes successfully copied to transmit FIFO +.br +RRRRR number of bytes in receieve FIFO +.br +TTTTT number of bytes in transmit FIFO +.br +RB receive busy +.br +TE transmit FIFO empty +.br +RF receive FIFO full +.br +TF transmit FIFO full +.br +RE receive FIFO empty +.br +TB transmit busy +.br + +.br + +.br +The following example shows how to configure the BSC peripheral as +an I2C slave with address 0x13 and send four bytes. + +.br + +.br +\fBExample\fP +.br + +.EX +bsc_xfer_t xfer; +.br + +.br +xfer.control = (0x13<<16) | 0x305; +.br + +.br +memcpy(xfer.txBuf, "ABCD", 4); +.br +xfer.txCnt = 4; +.br + +.br +status = bscXfer(&xfer); +.br + +.br +if (status >= 0) +.br +{ +.br + // process transfer +.br +} +.br + +.EE + +.IP "\fBint bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)\fP" +.IP "" 4 +This function selects a set of GPIO for bit banging SPI with +a specified baud rate and mode. + +.br + +.br + +.EX + CS: 0-31 +.br + MISO: 0-31 +.br + MOSI: 0-31 +.br + SCLK: 0-31 +.br + baud: 50-250000 +.br +spiFlags: see below +.br + +.EE + +.br + +.br +spiFlags consists of the least significant 22 bits. + +.br + +.br + +.EX +21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m +.br + +.EE + +.br + +.br +mm defines the SPI mode, defaults to 0 + +.br + +.br + +.EX +Mode CPOL CPHA +.br + 0 0 0 +.br + 1 0 1 +.br + 2 1 0 +.br + 3 1 1 +.br + +.EE + +.br + +.br +p is 0 if CS is active low (default) and 1 for active high. + +.br + +.br +T is 1 if the least significant bit is transmitted on MOSI first, the +default (0) shifts the most significant bit out first. + +.br + +.br +R is 1 if the least significant bit is received on MISO first, the +default (0) receives the most significant bit first. + +.br + +.br +The other bits in flags should be set to zero. + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or +PI_GPIO_IN_USE. + +.br + +.br +If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. + +.br + +.br +\fBExample\fP +.br + +.EX +bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1 +.br +bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2 +.br + +.EE + +.IP "\fBint bbSPIClose(unsigned CS)\fP" +.IP "" 4 +This function stops bit banging SPI on a set of GPIO +opened with \fBbbSPIOpen\fP. + +.br + +.br + +.EX +CS: 0-31, the CS GPIO used in a prior call to \fBbbSPIOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. + +.IP "\fBint bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)\fP" +.IP "" 4 +This function executes a bit banged SPI transfer. + +.br + +.br + +.EX + CS: 0-31 (as used in a prior call to \fBbbSPIOpen\fP) +.br + inBuf: pointer to buffer to hold data to be sent +.br +outBuf: pointer to buffer to hold returned data +.br + count: size of data transfer +.br + +.EE + +.br + +.br +Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. + +.br + +.br +\fBExample\fP +.br + +.EX +// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio +.br +// sudo ./bbSPIx_test +.br + +.br + +.br +#include +.br + +.br +#include "pigpio.h" +.br + +.br +#define CE0 5 +.br +#define CE1 6 +.br +#define MISO 13 +.br +#define MOSI 19 +.br +#define SCLK 12 +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int i, count, set_val, read_val; +.br + unsigned char inBuf[3]; +.br + char cmd1[] = {0, 0}; +.br + char cmd2[] = {12, 0}; +.br + char cmd3[] = {1, 128, 0}; +.br + +.br + if (gpioInitialise() < 0) +.br + { +.br + fprintf(stderr, "pigpio initialisation failed.\n"); +.br + return 1; +.br + } +.br + +.br + bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC +.br + bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC +.br + +.br + for (i=0; i<256; i++) +.br + { +.br + cmd1[1] = i; +.br + +.br + count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC +.br + +.br + if (count == 2) +.br + { +.br + count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC +.br + +.br + if (count == 2) +.br + { +.br + set_val = inBuf[1]; +.br + +.br + count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC +.br + +.br + if (count == 3) +.br + { +.br + read_val = ((inBuf[1]&3)<<8) | inBuf[2]; +.br + printf("%d %d\n", set_val, read_val); +.br + } +.br + } +.br + } +.br + } +.br + +.br + bbSPIClose(CE0); +.br + bbSPIClose(CE1); +.br + +.br + gpioTerminate(); +.br + +.br + return 0; +.br +} +.br + +.EE + +.IP "\fBint spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)\fP" +.IP "" 4 +This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. + +.br + +.br +The Pi has two SPI peripherals: main and auxiliary. + +.br + +.br +The main SPI has two chip selects (channels), the auxiliary has +three. + +.br + +.br +The auxiliary SPI is available on all models but the A and B. + +.br + +.br +The GPIO used are given in the following table. + +.br + +.br + MISO MOSI SCLK CE0 CE1 CE2 +.br +Main SPI 9 10 11 8 7 - +.br +Aux SPI 19 20 21 18 17 16 +.br + +.br + +.br + +.EX + spiChan: 0-1 (0-2 for the auxiliary SPI) +.br + baud: 32K-125M (values above 30M are unlikely to work) +.br +spiFlags: see below +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. + +.br + +.br +spiFlags consists of the least significant 22 bits. + +.br + +.br + +.EX +21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m +.br + +.EE + +.br + +.br +mm defines the SPI mode. + +.br + +.br +Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. + +.br + +.br + +.EX +Mode POL PHA +.br + 0 0 0 +.br + 1 0 1 +.br + 2 1 0 +.br + 3 1 1 +.br + +.EE + +.br + +.br +px is 0 if CEx is active low (default) and 1 for active high. + +.br + +.br +ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. + +.br + +.br +A is 0 for the main SPI, 1 for the auxiliary SPI. + +.br + +.br +W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main +SPI only. + +.br + +.br +nnnn defines the number of bytes (0-15) to write before switching +the MOSI line to MISO to read data. This field is ignored +if W is not set. Main SPI only. + +.br + +.br +T is 1 if the least significant bit is transmitted on MOSI first, the +default (0) shifts the most significant bit out first. Auxiliary SPI +only. + +.br + +.br +R is 1 if the least significant bit is received on MISO first, the +default (0) receives the most significant bit first. Auxiliary SPI +only. + +.br + +.br +bbbbbb defines the word size in bits (0-32). The default (0) +sets 8 bits per word. Auxiliary SPI only. + +.br + +.br +The \fBspiRead\fP, \fBspiWrite\fP, and \fBspiXfer\fP functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. + +.br + +.br +For bits 1-8 there will be one byte per word. +.br +For bits 9-16 there will be two bytes per word. +.br +For bits 17-32 there will be four bytes per word. + +.br + +.br +Multi-byte transfers are made in least significant byte first order. + +.br + +.br +E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. + +.br + +.br +E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed +by 0x1A. + +.br + +.br +The other bits in flags should be set to zero. + +.IP "\fBint spiClose(unsigned handle)\fP" +.IP "" 4 +This functions closes the SPI device identified by the handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBspiOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint spiRead(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads count bytes of data from the SPI +device associated with the handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBspiOpen\fP +.br + buf: an array to receive the read data bytes +.br + count: the number of bytes to read +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint spiWrite(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes of data from buf to the SPI +device associated with the handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBspiOpen\fP +.br + buf: the data bytes to write +.br + count: the number of bytes to write +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" +.IP "" 4 +This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBspiOpen\fP +.br + txBuf: the data bytes to write +.br + rxBuf: the received data bytes +.br + count: the number of bytes to transfer +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint serOpen(char *sertty, unsigned baud, unsigned serFlags)\fP" +.IP "" 4 +This function opens a serial device at a specified baud rate +and with specified flags. The device name must start with +/dev/tty or /dev/serial. + +.br + +.br + +.EX + sertty: the serial device to open +.br + baud: the baud rate in bits per second, see below +.br +serFlags: 0 +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. + +.br + +.br +The baud rate must be one of 50, 75, 110, 134, 150, +200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, +38400, 57600, 115200, or 230400. + +.br + +.br +No flags are currently defined. This parameter should be set to zero. + +.IP "\fBint serClose(unsigned handle)\fP" +.IP "" 4 +This function closes the serial device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint serWriteByte(unsigned handle, unsigned bVal)\fP" +.IP "" 4 +This function writes bVal to the serial port associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. + +.IP "\fBint serReadByte(unsigned handle)\fP" +.IP "" 4 +This function reads a byte from the serial port associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserOpen\fP +.br + +.EE + +.br + +.br +Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. + +.br + +.br +If no data is ready PI_SER_READ_NO_DATA is returned. + +.IP "\fBint serWrite(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes from buf to the the serial port +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserOpen\fP +.br + buf: the array of bytes to write +.br + count: the number of bytes to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. + +.IP "\fBint serRead(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads up count bytes from the the serial port +associated with handle and writes them to buf. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserOpen\fP +.br + buf: an array to receive the read data +.br + count: the maximum number of bytes to read +.br + +.EE + +.br + +.br +Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_SER_READ_NO_DATA. + +.br + +.br +If no data is ready zero is returned. + +.IP "\fBint serDataAvailable(unsigned handle)\fP" +.IP "" 4 +This function returns the number of bytes available +to be read from the device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserOpen\fP +.br + +.EE + +.br + +.br +Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. + +.IP "\fBint gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)\fP" +.IP "" 4 +This function sends a trigger pulse to a GPIO. The GPIO is set to +level for pulseLen microseconds and then reset to not level. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + pulseLen: 1-100 +.br + level: 0,1 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, +or PI_BAD_PULSELEN. + +.IP "\fBint gpioSetWatchdog(unsigned user_gpio, unsigned timeout)\fP" +.IP "" 4 +Sets a watchdog for a GPIO. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + timeout: 0-60000 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. + +.br + +.br +The watchdog is nominally in milliseconds. + +.br + +.br +One watchdog may be registered per GPIO. + +.br + +.br +The watchdog may be cancelled by setting timeout to 0. + +.br + +.br +Until cancelled a timeout will be reported every timeout milliseconds +after the last GPIO activity. + +.br + +.br +In particular: + +.br + +.br +1) any registered alert function for the GPIO will be called with + the level set to PI_TIMEOUT. + +.br + +.br +2) any notification for the GPIO will have a report written to the + fifo with the flags set to indicate a watchdog timeout. + +.br + +.br +\fBExample\fP +.br + +.EX +void aFunction(int gpio, int level, uint32_t tick) +.br +{ +.br + printf("GPIO %d became %d at %d", gpio, level, tick); +.br +} +.br + +.br +// call aFunction whenever GPIO 4 changes state +.br +gpioSetAlertFunc(4, aFunction); +.br + +.br +// or approximately every 5 millis +.br +gpioSetWatchdog(4, 5); +.br + +.EE + +.IP "\fBint gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)\fP" +.IP "" 4 +Sets a noise filter on a GPIO. + +.br + +.br +Level changes on the GPIO are ignored until a level which has +been stable for \fBsteady\fP microseconds is detected. Level changes +on the GPIO are then reported for \fBactive\fP microseconds after +which the process repeats. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + steady: 0-300000 +.br + active: 0-1000000 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. + +.br + +.br +This filter affects the GPIO samples returned to callbacks set up +with \fBgpioSetAlertFunc\fP, \fBgpioSetAlertFuncEx\fP, \fBgpioSetGetSamplesFunc\fP, +and \fBgpioSetGetSamplesFuncEx\fP. + +.br + +.br +It does not affect interrupts set up with \fBgpioSetISRFunc\fP, +\fBgpioSetISRFuncEx\fP, or levels read by \fBgpioRead\fP, +\fBgpioRead_Bits_0_31\fP, or \fBgpioRead_Bits_32_53\fP. + +.br + +.br +Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. + +.IP "\fBint gpioGlitchFilter(unsigned user_gpio, unsigned steady)\fP" +.IP "" 4 +Sets a glitch filter on a GPIO. + +.br + +.br +Level changes on the GPIO are not reported unless the level +has been stable for at least \fBsteady\fP microseconds. The +level is then reported. Level changes of less than \fBsteady\fP +microseconds are ignored. + +.br + +.br + +.EX +user_gpio: 0-31 +.br + steady: 0-300000 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. + +.br + +.br +This filter affects the GPIO samples returned to callbacks set up +with \fBgpioSetAlertFunc\fP, \fBgpioSetAlertFuncEx\fP, \fBgpioSetGetSamplesFunc\fP, +and \fBgpioSetGetSamplesFuncEx\fP. + +.br + +.br +It does not affect interrupts set up with \fBgpioSetISRFunc\fP, +\fBgpioSetISRFuncEx\fP, or levels read by \fBgpioRead\fP, +\fBgpioRead_Bits_0_31\fP, or \fBgpioRead_Bits_32_53\fP. + +.br + +.br +Each (stable) edge will be timestamped \fBsteady\fP microseconds +after it was first detected. + +.IP "\fBint gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)\fP" +.IP "" 4 +Registers a function to be called (a callback) every millisecond +with the latest GPIO samples. + +.br + +.br + +.EX + f: the function to call +.br +bits: the GPIO of interest +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.br + +.br +The function is passed a pointer to the samples (an array of +\fBgpioSample_t\fP), and the number of samples. + +.br + +.br +Only one function can be registered. + +.br + +.br +The callback may be cancelled by passing NULL as the function. + +.br + +.br +The samples returned will be the union of bits, plus any active alerts, +plus any active notifications. + +.br + +.br +e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO +8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO +7, 8, 9, 10, 17, 23, and 24 will be reported. + +.IP "\fBint gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)\fP" +.IP "" 4 +Registers a function to be called (a callback) every millisecond +with the latest GPIO samples. + +.br + +.br + +.EX + f: the function to call +.br + bits: the GPIO of interest +.br +userdata: a pointer to arbitrary user data +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.br + +.br +The function is passed a pointer to the samples (an array of +\fBgpioSample_t\fP), the number of samples, and the userdata pointer. + +.br + +.br +Only one of \fBgpioGetSamplesFunc\fP or \fBgpioGetSamplesFuncEx\fP can be +registered. + +.br + +.br +See \fBgpioSetGetSamplesFunc\fP for further details. + +.IP "\fBint gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)\fP" +.IP "" 4 +Registers a function to be called (a callback) every millis milliseconds. + +.br + +.br + +.EX + timer: 0-9 +.br +millis: 10-60000 +.br + f: the function to call +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. + +.br + +.br +10 timers are supported numbered 0 to 9. + +.br + +.br +One function may be registered per timer. + +.br + +.br +The timer may be cancelled by passing NULL as the function. + +.br + +.br +\fBExample\fP +.br + +.EX +void bFunction(void) +.br +{ +.br + printf("two seconds have elapsed"); +.br +} +.br + +.br +// call bFunction every 2000 milliseconds +.br +gpioSetTimerFunc(0, 2000, bFunction); +.br + +.EE + +.IP "\fBint gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)\fP" +.IP "" 4 +Registers a function to be called (a callback) every millis milliseconds. + +.br + +.br + +.EX + timer: 0-9. +.br + millis: 10-60000 +.br + f: the function to call +.br +userdata: a pointer to arbitrary user data +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. + +.br + +.br +The function is passed the userdata pointer. + +.br + +.br +Only one of \fBgpioSetTimerFunc\fP or \fBgpioSetTimerFuncEx\fP can be +registered per timer. + +.br + +.br +See \fBgpioSetTimerFunc\fP for further details. + +.IP "\fBpthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)\fP" +.IP "" 4 +Starts a new thread of execution with f as the main routine. + +.br + +.br + +.EX + f: the main function for the new thread +.br +userdata: a pointer to arbitrary user data +.br + +.EE + +.br + +.br +Returns a pointer to pthread_t if OK, otherwise NULL. + +.br + +.br +The function is passed the single argument arg. + +.br + +.br +The thread can be cancelled by passing the pointer to pthread_t to +\fBgpioStopThread\fP. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +void *myfunc(void *arg) +.br +{ +.br + while (1) +.br + { +.br + printf("%s", arg); +.br + sleep(1); +.br + } +.br +} +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + pthread_t *p1, *p2, *p3; +.br + +.br + if (gpioInitialise() < 0) return 1; +.br + +.br + p1 = gpioStartThread(myfunc, "thread 1"); sleep(3); +.br + +.br + p2 = gpioStartThread(myfunc, "thread 2"); sleep(3); +.br + +.br + p3 = gpioStartThread(myfunc, "thread 3"); sleep(3); +.br + +.br + gpioStopThread(p3); sleep(3); +.br + +.br + gpioStopThread(p2); sleep(3); +.br + +.br + gpioStopThread(p1); sleep(3); +.br + +.br + gpioTerminate(); +.br +} +.br + +.EE + +.IP "\fBvoid gpioStopThread(pthread_t *pth)\fP" +.IP "" 4 +Cancels the thread pointed at by pth. + +.br + +.br + +.EX +pth: a thread pointer returned by \fBgpioStartThread\fP +.br + +.EE + +.br + +.br +No value is returned. + +.br + +.br +The thread to be stopped should have been started with \fBgpioStartThread\fP. + +.IP "\fBint gpioStoreScript(char *script)\fP" +.IP "" 4 +This function stores a null terminated script for later execution. + +.br + +.br +See \fBhttp://abyz.me.uk/rpi/pigpio/pigs.html#Scripts\fP for details. + +.br + +.br + +.EX +script: the text of the script +.br + +.EE + +.br + +.br +The function returns a script id if the script is valid, +otherwise PI_BAD_SCRIPT. + +.IP "\fBint gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" +.IP "" 4 +This function runs a stored script. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBgpioStoreScript\fP +.br + numPar: 0-10, the number of parameters +.br + param: an array of parameters +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. + +.br + +.br +param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. + +.IP "\fBint gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" +.IP "" 4 +This function runs a stored script. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBgpioStoreScript\fP +.br + numPar: 0-10, the number of parameters +.br + param: an array of parameters +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. + +.br + +.br +param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. + +.IP "\fBint gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" +.IP "" 4 +This function sets the parameters of a script. The script may or +may not be running. The first numPar parameters of the script are +overwritten with the new values. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBgpioStoreScript\fP +.br + numPar: 0-10, the number of parameters +.br + param: an array of parameters +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. + +.br + +.br +param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. + +.IP "\fBint gpioScriptStatus(unsigned script_id, uint32_t *param)\fP" +.IP "" 4 +This function returns the run status of a stored script as well as +the current values of parameters 0 to 9. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBgpioStoreScript\fP +.br + param: an array to hold the returned 10 parameters +.br + +.EE + +.br + +.br +The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. + +.br + +.br +The run status may be + +.br + +.br + +.EX +PI_SCRIPT_INITING +.br +PI_SCRIPT_HALTED +.br +PI_SCRIPT_RUNNING +.br +PI_SCRIPT_WAITING +.br +PI_SCRIPT_FAILED +.br + +.EE + +.br + +.br +The current value of script parameters 0 to 9 are returned in param. + +.IP "\fBint gpioStopScript(unsigned script_id)\fP" +.IP "" 4 +This function stops a running script. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBgpioStoreScript\fP +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. + +.IP "\fBint gpioDeleteScript(unsigned script_id)\fP" +.IP "" 4 +This function deletes a stored script. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBgpioStoreScript\fP +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. + +.IP "\fBint gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)\fP" +.IP "" 4 +Registers a function to be called (a callback) when a signal occurs. + +.br + +.br + +.EX +signum: 0-63 +.br + f: the callback function +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_SIGNUM. + +.br + +.br +The function is passed the signal number. + +.br + +.br +One function may be registered per signal. + +.br + +.br +The callback may be cancelled by passing NULL. + +.br + +.br +By default all signals are treated as fatal and cause the library +to call gpioTerminate and then exit. + +.IP "\fBint gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)\fP" +.IP "" 4 +Registers a function to be called (a callback) when a signal occurs. + +.br + +.br + +.EX + signum: 0-63 +.br + f: the callback function +.br +userdata: a pointer to arbitrary user data +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_SIGNUM. + +.br + +.br +The function is passed the signal number and the userdata pointer. + +.br + +.br +Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be +registered per signal. + +.br + +.br +See gpioSetSignalFunc for further details. + +.IP "\fBuint32_t gpioRead_Bits_0_31(void)\fP" +.IP "" 4 +Returns the current level of GPIO 0-31. + +.IP "\fBuint32_t gpioRead_Bits_32_53(void)\fP" +.IP "" 4 +Returns the current level of GPIO 32-53. + +.IP "\fBint gpioWrite_Bits_0_31_Clear(uint32_t bits)\fP" +.IP "" 4 +Clears GPIO 0-31 if the corresponding bit in bits is set. + +.br + +.br + +.EX +bits: a bit mask of GPIO to clear +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.br + +.br +\fBExample\fP +.br + +.EX +// To clear (set to 0) GPIO 4, 7, and 15 +.br +gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) ); +.br + +.EE + +.IP "\fBint gpioWrite_Bits_32_53_Clear(uint32_t bits)\fP" +.IP "" 4 +Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. + +.br + +.br + +.EX +bits: a bit mask of GPIO to clear +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.IP "\fBint gpioWrite_Bits_0_31_Set(uint32_t bits)\fP" +.IP "" 4 +Sets GPIO 0-31 if the corresponding bit in bits is set. + +.br + +.br + +.EX +bits: a bit mask of GPIO to set +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.IP "\fBint gpioWrite_Bits_32_53_Set(uint32_t bits)\fP" +.IP "" 4 +Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. + +.br + +.br + +.EX +bits: a bit mask of GPIO to set +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.br + +.br +\fBExample\fP +.br + +.EX +// To set (set to 1) GPIO 32, 40, and 53 +.br +gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32))); +.br + +.EE + +.IP "\fBint gpioHardwareClock(unsigned gpio, unsigned clkfreq)\fP" +.IP "" 4 +Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. + +.br + +.br + +.EX + gpio: see description +.br +clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711) +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, +PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. + +.br + +.br +The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. + +.br + +.br +The GPIO must be one of the following. + +.br + +.br + +.EX +4 clock 0 All models +.br +5 clock 1 All models but A and B (reserved for system use) +.br +6 clock 2 All models but A and B +.br +20 clock 0 All models but A and B +.br +21 clock 1 All models but A and Rev.2 B (reserved for system use) +.br + +.br +32 clock 0 Compute module only +.br +34 clock 0 Compute module only +.br +42 clock 1 Compute module only (reserved for system use) +.br +43 clock 2 Compute module only +.br +44 clock 1 Compute module only (reserved for system use) +.br + +.EE + +.br + +.br +Access to clock 1 is protected by a password as its use will likely +crash the Pi. The password is given by or'ing 0x5A000000 with the +GPIO number. + +.IP "\fBint gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)\fP" +.IP "" 4 +Starts hardware PWM on a GPIO at the specified frequency and dutycycle. +Frequencies above 30MHz are unlikely to work. + +.br + +.br +NOTE: Any waveform started by \fBgpioWaveTxSend\fP, or +\fBgpioWaveChain\fP will be cancelled. + +.br + +.br +This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden by a call to +\fBgpioCfgClock\fP. + +.br + +.br + +.EX + gpio: see description +.br +PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) +.br +PWMduty: 0 (off) to 1000000 (1M)(fully on) +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, +PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. + +.br + +.br +The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. + +.br + +.br +The GPIO must be one of the following. + +.br + +.br + +.EX +12 PWM channel 0 All models but A and B +.br +13 PWM channel 1 All models but A and B +.br +18 PWM channel 0 All models +.br +19 PWM channel 1 All models but A and B +.br + +.br +40 PWM channel 0 Compute module only +.br +41 PWM channel 1 Compute module only +.br +45 PWM channel 1 Compute module only +.br +52 PWM channel 0 Compute module only +.br +53 PWM channel 1 Compute module only +.br + +.EE + +.br + +.br +The actual number of steps beween off and fully on is the +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). + +.br + +.br +The actual frequency set is 250M/steps (375M/steps for the BCM2711). + +.br + +.br +There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. PWMduty is +automatically scaled to take this into account. + +.IP "\fBint gpioTime(unsigned timetype, int *seconds, int *micros)\fP" +.IP "" 4 +Updates the seconds and micros variables with the current time. + +.br + +.br + +.EX +timetype: 0 (relative), 1 (absolute) +.br + seconds: a pointer to an int to hold seconds +.br + micros: a pointer to an int to hold microseconds +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_TIMETYPE. + +.br + +.br +If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the +number of seconds and microseconds since the epoch (1st January 1970). + +.br + +.br +If timetype is PI_TIME_RELATIVE updates seconds and micros with the +number of seconds and microseconds since the library was initialised. + +.br + +.br +\fBExample\fP +.br + +.EX +int secs, mics; +.br + +.br +// print the number of seconds since the library was started +.br +gpioTime(PI_TIME_RELATIVE, &secs, &mics); +.br +printf("library started %d.%03d seconds ago", secs, mics/1000); +.br + +.EE + +.IP "\fBint gpioSleep(unsigned timetype, int seconds, int micros)\fP" +.IP "" 4 +Sleeps for the number of seconds and microseconds specified by seconds +and micros. + +.br + +.br + +.EX +timetype: 0 (relative), 1 (absolute) +.br + seconds: seconds to sleep +.br + micros: microseconds to sleep +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, +or PI_BAD_MICROS. + +.br + +.br +If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds +and microseconds since the epoch (1st January 1970) has elapsed. System +clock changes are taken into account. + +.br + +.br +If timetype is PI_TIME_RELATIVE the sleep is for the specified number +of seconds and microseconds. System clock changes do not effect the +sleep length. + +.br + +.br +For short delays (say, 50 microseonds or less) use \fBgpioDelay\fP. + +.br + +.br +\fBExample\fP +.br + +.EX +gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds +.br + +.br +gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds +.br + +.br +gpioSleep(PI_TIME_RELATIVE, 60, 0); // sleep for one minute +.br + +.EE + +.IP "\fBuint32_t gpioDelay(uint32_t micros)\fP" +.IP "" 4 +Delays for at least the number of microseconds specified by micros. + +.br + +.br + +.EX +micros: the number of microseconds to sleep +.br + +.EE + +.br + +.br +Returns the actual length of the delay in microseconds. + +.br + +.br +Delays of 100 microseconds or less use busy waits. + +.IP "\fBuint32_t gpioTick(void)\fP" +.IP "" 4 +Returns the current system tick. + +.br + +.br +Tick is the number of microseconds since system boot. + +.br + +.br +As tick is an unsigned 32 bit quantity it wraps around after +2^32 microseconds, which is approximately 1 hour 12 minutes. + +.br + +.br +You don't need to worry about the wrap around as long as you +take a tick (uint32_t) from another tick, i.e. the following +code will always provide the correct difference. + +.br + +.br +\fBExample\fP +.br + +.EX +uint32_t startTick, endTick; +.br +int diffTick; +.br + +.br +startTick = gpioTick(); +.br + +.br +// do some processing +.br + +.br +endTick = gpioTick(); +.br + +.br +diffTick = endTick - startTick; +.br + +.br +printf("some processing took %d microseconds", diffTick); +.br + +.EE + +.IP "\fBunsigned gpioHardwareRevision(void)\fP" +.IP "" 4 +Returns the hardware revision. + +.br + +.br +If the hardware revision can not be found or is not a valid hexadecimal +number the function returns 0. + +.br + +.br +The hardware revision is the last few characters on the Revision line of +/proc/cpuinfo. + +.br + +.br +The revision number can be used to determine the assignment of GPIO +to pins (see \fBgpio\fP). + +.br + +.br +There are at least three types of board. + +.br + +.br +Type 1 boards have hardware revision numbers of 2 and 3. + +.br + +.br +Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. + +.br + +.br +Type 3 boards have hardware revision numbers of 16 or greater. + +.br + +.br +for "Revision : 0002" the function returns 2. +.br +for "Revision : 000f" the function returns 15. +.br +for "Revision : 000g" the function returns 0. + +.IP "\fBunsigned gpioVersion(void)\fP" +.IP "" 4 +Returns the pigpio version. + +.IP "\fBint gpioGetPad(unsigned pad)\fP" +.IP "" 4 +This function returns the pad drive strength in mA. + +.br + +.br + +.EX +pad: 0-2, the pad to get +.br + +.EE + +.br + +.br +Returns the pad drive strength if OK, otherwise PI_BAD_PAD. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +strength = gpioGetPad(1); // get pad 1 strength +.br + +.EE + +.IP "\fBint gpioSetPad(unsigned pad, unsigned padStrength)\fP" +.IP "" 4 +This function sets the pad drive strength in mA. + +.br + +.br + +.EX + pad: 0-2, the pad to set +.br +padStrength: 1-16 mA +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +gpioSetPad(0, 16); // set pad 0 strength to 16 mA +.br + +.EE + +.IP "\fBint eventMonitor(unsigned handle, uint32_t bits)\fP" +.IP "" 4 +This function selects the events to be reported on a previously +opened handle. + +.br + +.br + +.EX +handle: >=0, as returned by \fBgpioNotifyOpen\fP +.br + bits: a bit mask indicating the events of interest +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +A report is sent each time an event is triggered providing the +corresponding bit in bits is set. + +.br + +.br +See \fBgpioNotifyBegin\fP for the notification format. + +.br + +.br +\fBExample\fP +.br + +.EX +// Start reporting events 3, 6, and 7. +.br + +.br +// bit 76543210 +.br +// (0xC8 = 0b11001000) +.br + +.br +eventMonitor(h, 0xC8); +.br + +.EE + +.br + +.br + +.IP "\fBint eventSetFunc(unsigned event, eventFunc_t f)\fP" +.IP "" 4 +Registers a function to be called (a callback) when the specified +event occurs. + +.br + +.br + +.EX +event: 0-31 +.br + f: the callback function +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_EVENT_ID. + +.br + +.br +One function may be registered per event. + +.br + +.br +The function is passed the event, and the tick. + +.br + +.br +The callback may be cancelled by passing NULL as the function. + +.IP "\fBint eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)\fP" +.IP "" 4 +Registers a function to be called (a callback) when the specified +event occurs. + +.br + +.br + +.EX + event: 0-31 +.br + f: the callback function +.br +userdata: pointer to arbitrary user data +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_EVENT_ID. + +.br + +.br +One function may be registered per event. + +.br + +.br +The function is passed the event, the tick, and the ueserdata pointer. + +.br + +.br +The callback may be cancelled by passing NULL as the function. + +.br + +.br +Only one of \fBeventSetFunc\fP or \fBeventSetFuncEx\fP can be +registered per event. + +.IP "\fBint eventTrigger(unsigned event)\fP" +.IP "" 4 +This function signals the occurrence of an event. + +.br + +.br + +.EX +event: 0-31, the event +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_EVENT_ID. + +.br + +.br +An event is a signal used to inform one or more consumers +to start an action. Each consumer which has registered an interest +in the event (e.g. by calling \fBeventSetFunc\fP) will be informed by +a callback. + +.br + +.br +One event, PI_EVENT_BSC (31) is predefined. This event is +auto generated on BSC slave activity. + +.br + +.br +The meaning of other events is arbitrary. + +.br + +.br +Note that other than its id and its tick there is no data associated +with an event. + +.IP "\fBint shell(char *scriptName, char *scriptString)\fP" +.IP "" 4 +This function uses the system call to execute a shell script +with the given string as its parameter. + +.br + +.br + +.EX + scriptName: the name of the script, only alphanumeric characters, +.br + '-' and '_' are allowed in the name +.br +scriptString: the string to pass to the script +.br + +.EE + +.br + +.br +The exit status of the system call is returned if OK, otherwise +PI_BAD_SHELL_STATUS. + +.br + +.br +scriptName must exist in /opt/pigpio/cgi and must be executable. + +.br + +.br +The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. + +.br + +.br +The following table gives some example returned statuses. + +.br + +.br +Script exit status Returned system call status +.br +1 256 +.br +5 1280 +.br +10 2560 +.br +200 51200 +.br +script not found 32512 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +// pass two parameters, hello and world +.br +status = shell("scr1", "hello world"); +.br + +.br +// pass three parameters, hello, string with spaces, and world +.br +status = shell("scr1", "hello 'string with spaces' world"); +.br + +.br +// pass one parameter, hello string with spaces world +.br +status = shell("scr1", "\"hello string with spaces world\""); +.br + +.EE + +.IP "\fBint fileOpen(char *file, unsigned mode)\fP" +.IP "" 4 +This function returns a handle to a file opened in a specified mode. + +.br + +.br + +.EX +file: the file to open +.br +mode: the file open mode +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. + +.br + +.br +File + +.br + +.br +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +.br + +.br +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +.br + +.br +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +.br + +.br +Suppose /opt/pigpio/access contains the following entries + +.br + +.br + +.EX +/home/* n +.br +/home/pi/shared/dir_1/* w +.br +/home/pi/shared/dir_2/* r +.br +/home/pi/shared/dir_3/* u +.br +/home/pi/shared/dir_1/file.txt n +.br + +.EE + +.br + +.br +Files may be written in directory dir_1 with the exception +of file.txt. + +.br + +.br +Files may be read in directory dir_2. + +.br + +.br +Files may be read and written in directory dir_3. + +.br + +.br +If a directory allows read, write, or read/write access then files may +be created in that directory. + +.br + +.br +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +.br + +.br + +.EX +a path containing .. +.br +a path containing only wildcards (*?) +.br +a path containing less than two non-wildcard parts +.br + +.EE + +.br + +.br +Mode + +.br + +.br +The mode may have the following values. + +.br + +.br +Macro Value Meaning +.br +PI_FILE_READ 1 open file for reading +.br +PI_FILE_WRITE 2 open file for writing +.br +PI_FILE_RW 3 open file for reading and writing +.br + +.br + +.br +The following values may be or'd into the mode. + +.br + +.br +Macro Value Meaning +.br +PI_FILE_APPEND 4 Writes append data to the end of the file +.br +PI_FILE_CREATE 8 The file is created if it doesn't exist +.br +PI_FILE_TRUNC 16 The file is truncated +.br + +.br + +.br +Newly created files are owned by root with permissions owner read and write. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int handle, c; +.br + char buf[60000]; +.br + +.br + if (gpioInitialise() < 0) return 1; +.br + +.br + // assumes /opt/pigpio/access contains the following line +.br + // /ram/*.c r +.br + +.br + handle = fileOpen("/ram/pigpio.c", PI_FILE_READ); +.br + +.br + if (handle >= 0) +.br + { +.br + while ((c=fileRead(handle, buf, sizeof(buf)-1))) +.br + { +.br + buf[c] = 0; +.br + printf("%s", buf); +.br + } +.br + +.br + fileClose(handle); +.br + } +.br + +.br + gpioTerminate(); +.br +} +.br + +.EE + +.IP "\fBint fileClose(unsigned handle)\fP" +.IP "" 4 +This function closes the file associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBfileOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +\fBExample\fP +.br + +.EX +fileClose(h); +.br + +.EE + +.IP "\fBint fileWrite(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes from buf to the the file +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBfileOpen\fP +.br + buf: the array of bytes to write +.br + count: the number of bytes to write +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. + +.br + +.br +\fBExample\fP +.br + +.EX +status = fileWrite(h, buf, count); +.br +if (status == 0) +.br +{ +.br + // okay +.br +} +.br +else +.br +{ +.br + // error +.br +} +.br + +.EE + +.IP "\fBint fileRead(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads up to count bytes from the the file +associated with handle and writes them to buf. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBfileOpen\fP +.br + buf: an array to receive the read data +.br + count: the maximum number of bytes to read +.br + +.EE + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. + +.br + +.br +\fBExample\fP +.br + +.EX +if (fileRead(h, buf, sizeof(buf)) > 0) +.br +{ +.br + // process read data +.br +} +.br + +.EE + +.IP "\fBint fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)\fP" +.IP "" 4 +This function seeks to a position within the file associated +with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBfileOpen\fP +.br +seekOffset: the number of bytes to move. Positive offsets +.br + move forward, negative offsets backwards. +.br + seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1), +.br + or PI_FROM_END (2) +.br + +.EE + +.br + +.br +Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. + +.br + +.br +\fBExample\fP +.br + +.EX +fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20 +.br + +.br +size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size +.br + +.br +pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position +.br + +.EE + +.IP "\fBint fileList(char *fpat, char *buf, unsigned count)\fP" +.IP "" 4 +This function returns a list of files which match a pattern. The +pattern may contain wildcards. + +.br + +.br + +.EX + fpat: file pattern to match +.br + buf: an array to receive the matching file names +.br +count: the maximum number of bytes to read +.br + +.EE + +.br + +.br +Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. + +.br + +.br +The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See \fBfileOpen\fP. + +.br + +.br +NOTE + +.br + +.br +The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int c; +.br + char buf[1000]; +.br + +.br + if (gpioInitialise() < 0) return 1; +.br + +.br + // assumes /opt/pigpio/access contains the following line +.br + // /ram/*.c r +.br + +.br + c = fileList("/ram/p*.c", buf, sizeof(buf)); +.br + +.br + if (c >= 0) +.br + { +.br + // terminate string +.br + buf[c] = 0; +.br + printf("%s", buf); +.br + } +.br + +.br + gpioTerminate(); +.br +} +.br + +.EE + +.IP "\fBint gpioCfgBufferSize(unsigned cfgMillis)\fP" +.IP "" 4 +Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. + +.br + +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + +.br + +.EX +cfgMillis: 100-10000 +.br + +.EE + +.br + +.br +The default setting is 120 milliseconds. + +.br + +.br +The intention is to allow for bursts of data and protection against +other processes hogging cpu time. + +.br + +.br +I haven't seen a process locked out for more than 100 milliseconds. + +.br + +.br +Making the buffer bigger uses a LOT of memory at the more frequent +sampling rates as shown in the following table in MBs. + +.br + +.br + +.EX + buffer milliseconds +.br + 120 250 500 1sec 2sec 4sec 8sec +.br + +.br + 1 16 31 55 107 --- --- --- +.br + 2 10 18 31 55 107 --- --- +.br +sample 4 8 12 18 31 55 107 --- +.br + rate 5 8 10 14 24 45 87 --- +.br + (us) 8 6 8 12 18 31 55 107 +.br + 10 6 8 10 14 24 45 87 +.br + +.EE + +.IP "\fBint gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)\fP" +.IP "" 4 +Configures pigpio to use a particular sample rate timed by a specified +peripheral. + +.br + +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + +.br + +.EX + cfgMicros: 1, 2, 4, 5, 8, 10 +.br +cfgPeripheral: 0 (PWM), 1 (PCM) +.br + cfgSource: deprecated, value is ignored +.br + +.EE + +.br + +.br +The timings are provided by the specified peripheral (PWM or PCM). + +.br + +.br +The default setting is 5 microseconds using the PCM peripheral. + +.br + +.br +The approximate CPU percentage used for each sample rate is: + +.br + +.br + +.EX +sample cpu +.br + rate % +.br + +.br + 1 25 +.br + 2 16 +.br + 4 11 +.br + 5 10 +.br + 8 15 +.br + 10 14 +.br + +.EE + +.br + +.br +A sample rate of 5 microseconds seeems to be the sweet spot. + +.IP "\fBint gpioCfgDMAchannel(unsigned DMAchannel)\fP" +.IP "" 4 +Configures pigpio to use the specified DMA channel. + +.br + +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + +.br + +.EX +DMAchannel: 0-14 +.br + +.EE + +.br + +.br +The default setting is to use channel 14. + +.IP "\fBint gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)\fP" +.IP "" 4 +Configures pigpio to use the specified DMA channels. + +.br + +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + +.br + +.EX + primaryChannel: 0-14 +.br +secondaryChannel: 0-14 +.br + +.EE + +.br + +.br +The default setting depends on whether the Pi has a BCM2711 chip or +not (currently only the Pi4B has a BCM2711). + +.br + +.br +The default setting for a non-BCM2711 is to use channel 14 for the +primary channel and channel 6 for the secondary channel. + +.br + +.br +The default setting for a BCM2711 is to use channel 7 for the +primary channel and channel 6 for the secondary channel. + +.br + +.br +The secondary channel is only used for the transmission of waves. + +.br + +.br +If possible use one of channels 0 to 6 for the secondary channel +(a full channel). + +.br + +.br +A full channel only requires one DMA control block regardless of the +length of a pulse delay. Channels 7 to 14 (lite channels) require +one DMA control block for each 16383 microseconds of delay. I.e. +a 10 second pulse delay requires one control block on a full channel +and 611 control blocks on a lite channel. + +.IP "\fBint gpioCfgPermissions(uint64_t updateMask)\fP" +.IP "" 4 +Configures pigpio to restrict GPIO updates via the socket or pipe +interfaces to the GPIO specified by the mask. Programs directly +calling the pigpio library (i.e. linked with -lpigpio are not +affected). A GPIO update is a write to a GPIO or a GPIO mode +change or any function which would force such an action. + +.br + +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + +.br + +.EX +updateMask: bit (1<=0 +.br +arg2: >=0 +.br +argx: extra (byte) arguments +.br +argc: number of extra arguments +.br + +.EE + +.br + +.br +Returns >= 0 if OK, less than 0 indicates a user defined error. + +.IP "\fBint gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" +.IP "" 4 +This function is available for user customisation. + +.br + +.br +It differs from gpioCustom1 in that it returns an array of bytes +rather than just an integer. + +.br + +.br +The returned value is an integer indicating the number of returned bytes. + +.EX + arg1: >=0 +.br + argx: extra (byte) arguments +.br + argc: number of extra arguments +.br +retBuf: buffer for returned bytes +.br +retMax: maximum number of bytes to return +.br + +.EE + +.br + +.br +Returns >= 0 if OK, less than 0 indicates a user defined error. + +.br + +.br +The number of returned bytes must be retMax or less. + +.IP "\fBint rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)\fP" +.IP "" 4 +This function adds a waveform representing SPI data to the +existing waveform (if any). + +.br + +.br + +.EX + spi: a pointer to a spi object +.br + offset: microseconds from the start of the waveform +.br + spiSS: the slave select GPIO +.br + buf: the bits to transmit, most significant bit first +.br + spiTxBits: the number of bits to write +.br +spiBitFirst: the first bit to read +.br + spiBitLast: the last bit to read +.br + spiBits: the number of bits to transfer +.br + +.EE + +.br + +.br +Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. + +.br + +.br +Not intended for general use. + +.IP "\fBint rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)\fP" +.IP "" 4 +This function adds a number of pulses to the current waveform. + +.br + +.br + +.EX +numPulses: the number of pulses +.br + pulses: the array containing the pulses +.br + +.EE + +.br + +.br +Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. + +.br + +.br +The advantage of this function over gpioWaveAddGeneric is that it +allows the setting of the flags field. + +.br + +.br +The pulses are interleaved in time order within the existing waveform +(if any). + +.br + +.br +Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. + +.br + +.br +If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist of a delay. + +.br + +.br +Not intended for general use. + +.IP "\fBunsigned rawWaveCB(void)\fP" +.IP "" 4 +Returns the number of the cb being currently output. + +.br + +.br +Not intended for general use. + +.IP "\fBrawCbs_t *rawWaveCBAdr(int cbNum)\fP" +.IP "" 4 +Return the (Linux) address of contol block cbNum. + +.br + +.br + +.EX +cbNum: the cb of interest +.br + +.EE + +.br + +.br +Not intended for general use. + +.IP "\fBuint32_t rawWaveGetOOL(int pos)\fP" +.IP "" 4 +Gets the OOL parameter stored at pos. + +.br + +.br + +.EX +pos: the position of interest. +.br + +.EE + +.br + +.br +Not intended for general use. + +.IP "\fBvoid rawWaveSetOOL(int pos, uint32_t lVal)\fP" +.IP "" 4 +Sets the OOL parameter stored at pos to value. + +.br + +.br + +.EX + pos: the position of interest +.br +lVal: the value to write +.br + +.EE + +.br + +.br +Not intended for general use. + +.IP "\fBuint32_t rawWaveGetOut(int pos)\fP" +.IP "" 4 +Gets the wave output parameter stored at pos. + +.br + +.br +DEPRECATED: use rawWaveGetOOL instead. + +.br + +.br + +.EX +pos: the position of interest. +.br + +.EE + +.br + +.br +Not intended for general use. + +.IP "\fBvoid rawWaveSetOut(int pos, uint32_t lVal)\fP" +.IP "" 4 +Sets the wave output parameter stored at pos to value. + +.br + +.br +DEPRECATED: use rawWaveSetOOL instead. + +.br + +.br + +.EX + pos: the position of interest +.br +lVal: the value to write +.br + +.EE + +.br + +.br +Not intended for general use. + +.IP "\fBuint32_t rawWaveGetIn(int pos)\fP" +.IP "" 4 +Gets the wave input value parameter stored at pos. + +.br + +.br +DEPRECATED: use rawWaveGetOOL instead. + +.br + +.br + +.EX +pos: the position of interest +.br + +.EE + +.br + +.br +Not intended for general use. + +.IP "\fBvoid rawWaveSetIn(int pos, uint32_t lVal)\fP" +.IP "" 4 +Sets the wave input value stored at pos to value. + +.br + +.br +DEPRECATED: use rawWaveSetOOL instead. + +.br + +.br + +.EX + pos: the position of interest +.br +lVal: the value to write +.br + +.EE + +.br + +.br +Not intended for general use. + +.IP "\fBrawWaveInfo_t rawWaveInfo(int wave_id)\fP" +.IP "" 4 +Gets details about the wave with id wave_id. + +.br + +.br + +.EX +wave_id: the wave of interest +.br + +.EE + +.br + +.br +Not intended for general use. + +.IP "\fBint getBitInBytes(int bitPos, char *buf, int numBits)\fP" +.IP "" 4 +Returns the value of the bit bitPos bits from the start of buf. Returns +0 if bitPos is greater than or equal to numBits. + +.br + +.br + +.EX + bitPos: bit index from the start of buf +.br + buf: array of bits +.br +numBits: number of valid bits in buf +.br + +.EE + +.br + +.br + +.IP "\fBvoid putBitInBytes(int bitPos, char *buf, int bit)\fP" +.IP "" 4 +Sets the bit bitPos bits from the start of buf to bit. + +.br + +.br + +.EX +bitPos: bit index from the start of buf +.br + buf: array of bits +.br + bit: 0-1, value to set +.br + +.EE + +.br + +.br + +.IP "\fBdouble time_time(void)\fP" +.IP "" 4 +Return the current time in seconds since the Epoch. + +.IP "\fBvoid time_sleep(double seconds)\fP" +.IP "" 4 +Delay execution for a given number of seconds + +.br + +.br + +.EX +seconds: the number of seconds to sleep +.br + +.EE + +.IP "\fBvoid rawDumpWave(void)\fP" +.IP "" 4 +Used to print a readable version of the current waveform to stderr. + +.br + +.br +Not intended for general use. + +.IP "\fBvoid rawDumpScript(unsigned script_id)\fP" +.IP "" 4 +Used to print a readable version of a script to stderr. + +.br + +.br + +.EX +script_id: >=0, a script_id returned by \fBgpioStoreScript\fP +.br + +.EE + +.br + +.br +Not intended for general use. +.SH PARAMETERS + +.br + +.br + +.IP "\fBactive\fP: 0-1000000" 0 + +.br + +.br +The number of microseconds level changes are reported for once +a noise filter has been triggered (by \fBsteady\fP microseconds of +a stable level). + +.br + +.br + +.IP "\fBarg1\fP" 0 + +.br + +.br +An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. + +.br + +.br + +.IP "\fBarg2\fP" 0 + +.br + +.br +An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. + +.br + +.br + +.IP "\fBargc\fP" 0 +The count of bytes passed to a user customised function. + +.br + +.br + +.IP "\fB*argx\fP" 0 +A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. + +.br + +.br + +.IP "\fBbaud\fP" 0 +The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. + +.br + +.br + +.IP "\fBbit\fP" 0 +A value of 0 or 1. + +.br + +.br + +.IP "\fBbitPos\fP" 0 +A bit position within a byte or word. The least significant bit is +position 0. + +.br + +.br + +.IP "\fBbits\fP" 0 +A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. + +.br + +.br +A convenient way to set bit n is to or in (1<=0" 0 + +.br + +.br +The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. + +.br + +.br + +.IP "\fBgpio\fP" 0 + +.br + +.br +A Broadcom numbered GPIO, in the range 0-53. + +.br + +.br +There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through +GPIO53. + +.br + +.br +They are split into two banks. Bank 1 consists of GPIO0 through +GPIO31. Bank 2 consists of GPIO32 through GPIO53. + +.br + +.br +All the GPIO which are safe for the user to read and write are in +bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards +have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. + +.br + +.br +See \fBgpioHardwareRevision\fP. + +.br + +.br +The user GPIO are marked with an X in the following table. + +.br + +.br + +.EX + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 +.br +Type 1 X X - - X - - X X X X X - - X X +.br +Type 2 - - X X X - - X X X X X - - X X +.br +Type 3 X X X X X X X X X X X X X X +.br + +.br + 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +.br +Type 1 - X X - - X X X X X - - - - - - +.br +Type 2 - X X - - - X X X X - X X X X X +.br +Type 3 X X X X X X X X X X X X - - - - +.br + +.EE + +.br + +.br + +.IP "\fBgpioAlertFunc_t\fP" 0 + +.EX +typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick); +.br + +.EE + +.br + +.br + +.IP "\fBgpioAlertFuncEx_t\fP" 0 + +.EX +typedef void (*eventFuncEx_t) +.br + (int event, int level, uint32_t tick, void *userdata); +.br + +.EE + +.br + +.br + +.IP "\fBgpioCfg*\fP" 0 + +.br + +.br +These functions are only effective if called before \fBgpioInitialise\fP. + +.br + +.br +\fBgpioCfgBufferSize\fP +.br +\fBgpioCfgClock\fP +.br +\fBgpioCfgDMAchannel\fP +.br +\fBgpioCfgDMAchannels\fP +.br +\fBgpioCfgPermissions\fP +.br +\fBgpioCfgInterfaces\fP +.br +\fBgpioCfgSocketPort\fP +.br +\fBgpioCfgMemAlloc\fP + +.br + +.br + +.IP "\fBgpioGetSamplesFunc_t\fP" 0 + +.EX +typedef void (*gpioGetSamplesFunc_t) +.br + (const gpioSample_t *samples, int numSamples); +.br + +.EE + +.br + +.br + +.IP "\fBgpioGetSamplesFuncEx_t\fP" 0 + +.EX +typedef void (*gpioGetSamplesFuncEx_t) +.br + (const gpioSample_t *samples, int numSamples, void *userdata); +.br + +.EE + +.br + +.br + +.IP "\fBgpioISRFunc_t\fP" 0 + +.EX +typedef void (*gpioISRFunc_t) +.br + (int gpio, int level, uint32_t tick); +.br + +.EE + +.br + +.br + +.IP "\fBgpioISRFuncEx_t\fP" 0 + +.EX +typedef void (*gpioISRFuncEx_t) +.br + (int gpio, int level, uint32_t tick, void *userdata); +.br + +.EE + +.br + +.br + +.IP "\fBgpioPulse_t\fP" 0 + +.EX +typedef struct +.br +{ +.br + uint32_t gpioOn; +.br + uint32_t gpioOff; +.br + uint32_t usDelay; +.br +} gpioPulse_t; +.br + +.EE + +.br + +.br + +.IP "\fBgpioSample_t\fP" 0 + +.EX +typedef struct +.br +{ +.br + uint32_t tick; +.br + uint32_t level; +.br +} gpioSample_t; +.br + +.EE + +.br + +.br + +.IP "\fBgpioSignalFunc_t\fP" 0 + +.EX +typedef void (*gpioSignalFunc_t) (int signum); +.br + +.EE + +.br + +.br + +.IP "\fBgpioSignalFuncEx_t\fP" 0 + +.EX +typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata); +.br + +.EE + +.br + +.br + +.IP "\fBgpioThreadFunc_t\fP" 0 + +.EX +typedef void *(gpioThreadFunc_t) (void *); +.br + +.EE + +.br + +.br + +.IP "\fBgpioTimerFunc_t\fP" 0 + +.EX +typedef void (*gpioTimerFunc_t) (void); +.br + +.EE + +.br + +.br + +.IP "\fBgpioTimerFuncEx_t\fP" 0 + +.EX +typedef void (*gpioTimerFuncEx_t) (void *userdata); +.br + +.EE + +.br + +.br + +.IP "\fBgpioWaveAdd*\fP" 0 + +.br + +.br +One of + +.br + +.br +\fBgpioWaveAddNew\fP +.br +\fBgpioWaveAddGeneric\fP +.br +\fBgpioWaveAddSerial\fP + +.br + +.br + +.IP "\fBhandle\fP: >=0" 0 + +.br + +.br +A number referencing an object opened by one of + +.br + +.br +\fBfileOpen\fP +.br +\fBgpioNotifyOpen\fP +.br +\fBi2cOpen\fP +.br +\fBserOpen\fP +.br +\fBspiOpen\fP + +.br + +.br + +.IP "\fBi2cAddr\fP: 0-0x7F" 0 +The address of a device on the I2C bus. + +.br + +.br + +.IP "\fBi2cBus\fP: >=0" 0 + +.br + +.br +An I2C bus number. + +.br + +.br + +.IP "\fBi2cFlags\fP: 0" 0 + +.br + +.br +Flags which modify an I2C open command. None are currently defined. + +.br + +.br + +.IP "\fBi2cReg\fP: 0-255" 0 + +.br + +.br +A register of an I2C device. + +.br + +.br + +.IP "\fBifFlags\fP: 0-3" 0 + +.EX +PI_DISABLE_FIFO_IF 1 +.br +PI_DISABLE_SOCK_IF 2 +.br + +.EE + +.br + +.br + +.IP "\fB*inBuf\fP" 0 +A buffer used to pass data to a function. + +.br + +.br + +.IP "\fBinLen\fP" 0 +The number of bytes of data in a buffer. + +.br + +.br + +.IP "\fBint\fP" 0 +A whole number, negative or positive. + +.br + +.br + +.IP "\fBint32_t\fP" 0 +A 32-bit signed value. + +.br + +.br + +.IP "\fBinvert\fP" 0 +A flag used to set normal or inverted bit bang serial data level logic. + +.br + +.br + +.IP "\fBlevel\fP" 0 +The level of a GPIO. Low or High. + +.br + +.br + +.EX +PI_OFF 0 +.br +PI_ON 1 +.br + +.br +PI_CLEAR 0 +.br +PI_SET 1 +.br + +.br +PI_LOW 0 +.br +PI_HIGH 1 +.br + +.EE + +.br + +.br +There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See \fBgpioSetWatchdog\fP. + +.br + +.br + +.EX +PI_TIMEOUT 2 +.br + +.EE + +.br + +.br + +.br + +.br + +.IP "\fBlVal\fP: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)" 0 + +.br + +.br +A 32-bit word value. + +.br + +.br + +.IP "\fBmemAllocMode\fP: 0-2" 0 + +.br + +.br +The DMA memory allocation mode. + +.br + +.br + +.EX +PI_MEM_ALLOC_AUTO 0 +.br +PI_MEM_ALLOC_PAGEMAP 1 +.br +PI_MEM_ALLOC_MAILBOX 2 +.br + +.EE + +.br + +.br + +.IP "\fB*micros\fP" 0 + +.br + +.br +A value representing microseconds. + +.br + +.br + +.IP "\fBmicros\fP" 0 + +.br + +.br +A value representing microseconds. + +.br + +.br + +.IP "\fBmillis\fP" 0 + +.br + +.br +A value representing milliseconds. + +.br + +.br + +.IP "\fBMISO\fP" 0 +The GPIO used for the MISO signal when bit banging SPI. + +.br + +.br + +.IP "\fBmode\fP" 0 + +.br + +.br +1. The operational mode of a GPIO, normally INPUT or OUTPUT. + +.br + +.br + +.EX +PI_INPUT 0 +.br +PI_OUTPUT 1 +.br +PI_ALT0 4 +.br +PI_ALT1 5 +.br +PI_ALT2 6 +.br +PI_ALT3 7 +.br +PI_ALT4 3 +.br +PI_ALT5 2 +.br + +.EE + +.br + +.br +2. A file open mode. + +.br + +.br + +.EX +PI_FILE_READ 1 +.br +PI_FILE_WRITE 2 +.br +PI_FILE_RW 3 +.br + +.EE + +.br + +.br +The following values can be or'd into the mode. + +.br + +.br + +.EX +PI_FILE_APPEND 4 +.br +PI_FILE_CREATE 8 +.br +PI_FILE_TRUNC 16 +.br + +.EE + +.br + +.br + +.IP "\fBMOSI\fP" 0 +The GPIO used for the MOSI signal when bit banging SPI. + +.br + +.br + +.IP "\fBnumBits\fP" 0 + +.br + +.br +The number of bits stored in a buffer. + +.br + +.br + +.IP "\fBnumBytes\fP" 0 +The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. + +.br + +.br + +.IP "\fBnumPar\fP: 0-10" 0 +The number of parameters passed to a script. + +.br + +.br + +.IP "\fBnumPulses\fP" 0 +The number of pulses to be added to a waveform. + +.br + +.br + +.IP "\fBnumSegs\fP" 0 +The number of segments in a combined I2C transaction. + +.br + +.br + +.IP "\fBnumSockAddr\fP" 0 +The number of network addresses allowed to use the socket interface. + +.br + +.br +0 means all addresses allowed. + +.br + +.br + +.IP "\fBoffset\fP" 0 +The associated data starts this number of microseconds from the start of +the waveform. + +.br + +.br + +.IP "\fB*outBuf\fP" 0 +A buffer used to return data from a function. + +.br + +.br + +.IP "\fBoutLen\fP" 0 +The size in bytes of an output buffer. + +.br + +.br + +.IP "\fBpad\fP: 0-2" 0 +A set of GPIO which share common drivers. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br + +.IP "\fBpadStrength\fP: 1-16" 0 +The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. + +.br + +.br + +.IP "\fB*param\fP" 0 +An array of script parameters. + +.br + +.br + +.IP "\fBpi_i2c_msg_t\fP" 0 + +.EX +typedef struct +.br +{ +.br + uint16_t addr; // slave address +.br + uint16_t flags; +.br + uint16_t len; // msg length +.br + uint8_t *buf; // pointer to msg data +.br +} pi_i2c_msg_t; +.br + +.EE + +.br + +.br + +.IP "\fBport\fP: 1024-32000" 0 +The port used to bind to the pigpio socket. Defaults to 8888. + +.br + +.br + +.IP "\fBpos\fP" 0 +The position of an item. + +.br + +.br + +.IP "\fBprimaryChannel\fP: 0-15" 0 +The DMA channel used to time the sampling of GPIO and to time servo and +PWM pulses. + +.br + +.br + +.IP "\fB*pth\fP" 0 + +.br + +.br +A thread identifier, returned by \fBgpioStartThread\fP. + +.br + +.br + +.IP "\fBpthread_t\fP" 0 + +.br + +.br +A thread identifier. + +.br + +.br + +.IP "\fBpud\fP: 0-2" 0 + +.br + +.br +The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. + +.br + +.br + +.EX +PI_PUD_OFF 0 +.br +PI_PUD_DOWN 1 +.br +PI_PUD_UP 2 +.br + +.EE + +.br + +.br + +.IP "\fBpulseLen\fP" 0 + +.br + +.br +1-100, the length of a trigger pulse in microseconds. + +.br + +.br + +.IP "\fB*pulses\fP" 0 + +.br + +.br +An array of pulses to be added to a waveform. + +.br + +.br + +.IP "\fBpulsewidth\fP: 0, 500-2500" 0 + +.EX +PI_SERVO_OFF 0 +.br +PI_MIN_SERVO_PULSEWIDTH 500 +.br +PI_MAX_SERVO_PULSEWIDTH 2500 +.br + +.EE + +.br + +.br + +.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 +The hardware PWM dutycycle. + +.br + +.br + +.EX +PI_HW_PWM_RANGE 1000000 +.br + +.EE + +.br + +.br + +.IP "\fBPWMfreq\fP: 1-125M (1-187.5M for the BCM2711)" 0 +The hardware PWM frequency. + +.br + +.br + +.EX +PI_HW_PWM_MIN_FREQ 1 +.br +PI_HW_PWM_MAX_FREQ 125000000 +.br +PI_HW_PWM_MAX_FREQ_2711 187500000 +.br + +.EE + +.br + +.br + +.IP "\fBrange\fP: 25-40000" 0 + +.EX +PI_MIN_DUTYCYCLE_RANGE 25 +.br +PI_MAX_DUTYCYCLE_RANGE 40000 +.br + +.EE + +.br + +.br + +.IP "\fBrawCbs_t\fP" 0 + +.EX +typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h +.br +{ +.br + unsigned long info; +.br + unsigned long src; +.br + unsigned long dst; +.br + unsigned long length; +.br + unsigned long stride; +.br + unsigned long next; +.br + unsigned long pad[2]; +.br +} rawCbs_t; +.br + +.EE + +.br + +.br + +.IP "\fBrawSPI_t\fP" 0 + +.EX +typedef struct +.br +{ +.br + int clk; // GPIO for clock +.br + int mosi; // GPIO for MOSI +.br + int miso; // GPIO for MISO +.br + int ss_pol; // slave select off state +.br + int ss_us; // delay after slave select +.br + int clk_pol; // clock off state +.br + int clk_pha; // clock phase +.br + int clk_us; // clock micros +.br +} rawSPI_t; +.br + +.EE + +.br + +.br + +.IP "\fBrawWave_t\fP" 0 + +.EX +typedef struct +.br +{ +.br + uint32_t gpioOn; +.br + uint32_t gpioOff; +.br + uint32_t usDelay; +.br + uint32_t flags; +.br +} rawWave_t; +.br + +.EE + +.br + +.br + +.IP "\fBrawWaveInfo_t\fP" 0 + +.EX +typedef struct +.br +{ +.br + uint16_t botCB; // first CB used by wave +.br + uint16_t topCB; // last CB used by wave +.br + uint16_t botOOL; // last OOL used by wave +.br + uint16_t topOOL; // first OOL used by wave +.br + uint16_t deleted; +.br + uint16_t numCB; +.br + uint16_t numBOOL; +.br + uint16_t numTOOL; +.br +} rawWaveInfo_t; +.br + +.EE + +.br + +.br + +.IP "\fB*retBuf\fP" 0 + +.br + +.br +A buffer to hold a number of bytes returned to a used customised function, + +.br + +.br + +.IP "\fBretMax\fP" 0 + +.br + +.br +The maximum number of bytes a user customised function should return. + +.br + +.br + +.IP "\fB*rxBuf\fP" 0 + +.br + +.br +A pointer to a buffer to receive data. + +.br + +.br + +.IP "\fBSCL\fP" 0 +The user GPIO to use for the clock when bit banging I2C. + +.br + +.br + +.IP "\fBSCLK\fP" 0 +The GPIO used for the SCLK signal when bit banging SPI. + +.br + +.br + +.IP "\fB*script\fP" 0 +A pointer to the text of a script. + +.br + +.br + +.IP "\fBscript_id\fP" 0 +An id of a stored script as returned by \fBgpioStoreScript\fP. + +.br + +.br + +.IP "\fB*scriptName\fP" 0 +The name of a \fBshell\fP script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. + +.br + +.br + +.IP "\fB*scriptString\fP" 0 +The string to be passed to a \fBshell\fP script to be executed. + +.br + +.br + +.IP "\fBSDA\fP" 0 +The user GPIO to use for data when bit banging I2C. + +.br + +.br + +.IP "\fBsecondaryChannel\fP: 0-6" 0 + +.br + +.br +The DMA channel used to time output waveforms. + +.br + +.br + +.IP "\fB*seconds\fP" 0 + +.br + +.br +A pointer to a uint32_t to store the second component of +a returned time. + +.br + +.br + +.IP "\fBseconds\fP" 0 +The number of seconds. + +.br + +.br + +.IP "\fBseekFrom\fP" 0 + +.br + +.br + +.EX +PI_FROM_START 0 +.br +PI_FROM_CURRENT 1 +.br +PI_FROM_END 2 +.br + +.EE + +.br + +.br + +.IP "\fBseekOffset\fP" 0 +The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). + +.br + +.br + +.IP "\fB*segs\fP" 0 +An array of segments which make up a combined I2C transaction. + +.br + +.br + +.IP "\fBserFlags\fP" 0 +Flags which modify a serial open command. None are currently defined. + +.br + +.br + +.IP "\fB*sertty\fP" 0 +The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. + +.br + +.br + +.IP "\fBsetting\fP" 0 +A value used to set a flag, 0 for false, non-zero for true. + +.br + +.br + +.IP "\fBsignum\fP: 0-63" 0 + +.EX +PI_MIN_SIGNUM 0 +.br +PI_MAX_SIGNUM 63 +.br + +.EE + +.br + +.br + +.IP "\fBsize_t\fP" 0 + +.br + +.br +A standard type used to indicate the size of an object in bytes. + +.br + +.br + +.IP "\fB*sockAddr\fP" 0 +An array of network addresses allowed to use the socket interface encoded +as 32 bit numbers. + +.br + +.br +E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. + +.br + +.br + +.IP "\fB*spi\fP" 0 +A pointer to a \fBrawSPI_t\fP structure. + +.br + +.br + +.IP "\fBspiBitFirst\fP" 0 +GPIO reads are made from spiBitFirst to spiBitLast. + +.br + +.br + +.IP "\fBspiBitLast\fP" 0 + +.br + +.br +GPIO reads are made from spiBitFirst to spiBitLast. + +.br + +.br + +.IP "\fBspiBits\fP" 0 +The number of bits to transfer in a raw SPI transaction. + +.br + +.br + +.IP "\fBspiChan\fP" 0 +A SPI channel, 0-2. + +.br + +.br + +.IP "\fBspiFlags\fP" 0 +See \fBspiOpen\fP and \fBbbSPIOpen\fP. + +.br + +.br + +.IP "\fBspiSS\fP" 0 +The SPI slave select GPIO in a raw SPI transaction. + +.br + +.br + +.IP "\fBspiTxBits\fP" 0 +The number of bits to transfer dring a raw SPI transaction + +.br + +.br + +.IP "\fBsteady\fP: 0-300000" 0 + +.br + +.br +The number of microseconds level changes must be stable for +before reporting the level changed (\fBgpioGlitchFilter\fP) or triggering +the active part of a noise filter (\fBgpioNoiseFilter\fP). + +.br + +.br + +.IP "\fBstop_bits\fP: 2-8" 0 +The number of (half) stop bits to be used when adding serial data +to a waveform. + +.br + +.br + +.EX +PI_MIN_WAVE_HALFSTOPBITS 2 +.br +PI_MAX_WAVE_HALFSTOPBITS 8 +.br + +.EE + +.br + +.br + +.IP "\fB*str\fP" 0 +An array of characters. + +.br + +.br + +.IP "\fBtimeout\fP" 0 +A GPIO level change timeout in milliseconds. + +.br + +.br +\fBgpioSetWatchdog\fP + +.EX +PI_MIN_WDOG_TIMEOUT 0 +.br +PI_MAX_WDOG_TIMEOUT 60000 +.br + +.EE + +.br + +.br +\fBgpioSetISRFunc\fP and \fBgpioSetISRFuncEx\fP + +.EX +<=0 cancel timeout +.br +>0 timeout after specified milliseconds +.br + +.EE + +.br + +.br + +.IP "\fBtimer\fP" 0 + +.EX +PI_MIN_TIMER 0 +.br +PI_MAX_TIMER 9 +.br + +.EE + +.br + +.br + +.IP "\fBtimetype\fP" 0 + +.EX +PI_TIME_RELATIVE 0 +.br +PI_TIME_ABSOLUTE 1 +.br + +.EE + +.br + +.br + +.IP "\fB*txBuf\fP" 0 + +.br + +.br +An array of bytes to transmit. + +.br + +.br + +.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 + +.br + +.br +A 32-bit unsigned value. + +.br + +.br + +.IP "\fBuint64_t\fP: 0-(2^64)-1" 0 + +.br + +.br +A 64-bit unsigned value. + +.br + +.br + +.IP "\fBunsigned\fP" 0 + +.br + +.br +A whole number >= 0. + +.br + +.br + +.IP "\fBupdateMask\fP" 0 + +.br + +.br +A 64 bit mask indicating which GPIO may be written to by the user. + +.br + +.br +If GPIO#n may be written then bit (1< 4 +.br +#define PI_BAD_CHANNEL -27 // DMA channel not 0-15 +.br +#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15 +.br +#define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000 +.br +#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command +.br +#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15 +.br +#define PI_NOT_INITIALISED -31 // function called before gpioInitialise +.br +#define PI_INITIALISED -32 // function called after gpioInitialise +.br +#define PI_BAD_WAVE_MODE -33 // waveform mode not 0-3 +.br +#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call +.br +#define PI_BAD_WAVE_BAUD -35 // baud rate not 50-250K(RX)/50-1M(TX) +.br +#define PI_TOO_MANY_PULSES -36 // waveform has too many pulses +.br +#define PI_TOO_MANY_CHARS -37 // waveform has too many chars +.br +#define PI_NOT_SERIAL_GPIO -38 // no bit bang serial read on GPIO +.br +#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter +.br +#define PI_BAD_SERIAL_BUF -40 // bad (null) serial buf parameter +.br +#define PI_NOT_PERMITTED -41 // GPIO operation not permitted +.br +#define PI_SOME_PERMITTED -42 // one or more GPIO not permitted +.br +#define PI_BAD_WVSC_COMMND -43 // bad WVSC subcommand +.br +#define PI_BAD_WVSM_COMMND -44 // bad WVSM subcommand +.br +#define PI_BAD_WVSP_COMMND -45 // bad WVSP subcommand +.br +#define PI_BAD_PULSELEN -46 // trigger pulse length not 1-100 +.br +#define PI_BAD_SCRIPT -47 // invalid script +.br +#define PI_BAD_SCRIPT_ID -48 // unknown script id +.br +#define PI_BAD_SER_OFFSET -49 // add serial data offset > 30 minutes +.br +#define PI_GPIO_IN_USE -50 // GPIO already in use +.br +#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time +.br +#define PI_BAD_PARAM_NUM -52 // script parameter id not 0-9 +.br +#define PI_DUP_TAG -53 // script has duplicate tag +.br +#define PI_TOO_MANY_TAGS -54 // script has too many tags +.br +#define PI_BAD_SCRIPT_CMD -55 // illegal script command +.br +#define PI_BAD_VAR_NUM -56 // script variable id not 0-149 +.br +#define PI_NO_SCRIPT_ROOM -57 // no more room for scripts +.br +#define PI_NO_MEMORY -58 // can't allocate temporary memory +.br +#define PI_SOCK_READ_FAILED -59 // socket read failed +.br +#define PI_SOCK_WRIT_FAILED -60 // socket write failed +.br +#define PI_TOO_MANY_PARAM -61 // too many script parameters (> 10) +.br +#define PI_NOT_HALTED -62 // DEPRECATED +.br +#define PI_SCRIPT_NOT_READY -62 // script initialising +.br +#define PI_BAD_TAG -63 // script has unresolved tag +.br +#define PI_BAD_MICS_DELAY -64 // bad MICS delay (too large) +.br +#define PI_BAD_MILS_DELAY -65 // bad MILS delay (too large) +.br +#define PI_BAD_WAVE_ID -66 // non existent wave id +.br +#define PI_TOO_MANY_CBS -67 // No more CBs for waveform +.br +#define PI_TOO_MANY_OOL -68 // No more OOL for waveform +.br +#define PI_EMPTY_WAVEFORM -69 // attempt to create an empty waveform +.br +#define PI_NO_WAVEFORM_ID -70 // no more waveforms +.br +#define PI_I2C_OPEN_FAILED -71 // can't open I2C device +.br +#define PI_SER_OPEN_FAILED -72 // can't open serial device +.br +#define PI_SPI_OPEN_FAILED -73 // can't open SPI device +.br +#define PI_BAD_I2C_BUS -74 // bad I2C bus +.br +#define PI_BAD_I2C_ADDR -75 // bad I2C address +.br +#define PI_BAD_SPI_CHANNEL -76 // bad SPI channel +.br +#define PI_BAD_FLAGS -77 // bad i2c/spi/ser open flags +.br +#define PI_BAD_SPI_SPEED -78 // bad SPI speed +.br +#define PI_BAD_SER_DEVICE -79 // bad serial device name +.br +#define PI_BAD_SER_SPEED -80 // bad serial baud rate +.br +#define PI_BAD_PARAM -81 // bad i2c/spi/ser parameter +.br +#define PI_I2C_WRITE_FAILED -82 // i2c write failed +.br +#define PI_I2C_READ_FAILED -83 // i2c read failed +.br +#define PI_BAD_SPI_COUNT -84 // bad SPI count +.br +#define PI_SER_WRITE_FAILED -85 // ser write failed +.br +#define PI_SER_READ_FAILED -86 // ser read failed +.br +#define PI_SER_READ_NO_DATA -87 // ser read no data available +.br +#define PI_UNKNOWN_COMMAND -88 // unknown command +.br +#define PI_SPI_XFER_FAILED -89 // spi xfer/read/write failed +.br +#define PI_BAD_POINTER -90 // bad (NULL) pointer +.br +#define PI_NO_AUX_SPI -91 // no auxiliary SPI on Pi A or B +.br +#define PI_NOT_PWM_GPIO -92 // GPIO is not in use for PWM +.br +#define PI_NOT_SERVO_GPIO -93 // GPIO is not in use for servo pulses +.br +#define PI_NOT_HCLK_GPIO -94 // GPIO has no hardware clock +.br +#define PI_NOT_HPWM_GPIO -95 // GPIO has no hardware PWM +.br +#define PI_BAD_HPWM_FREQ -96 // invalid hardware PWM frequency +.br +#define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M +.br +#define PI_BAD_HCLK_FREQ -98 // invalid hardware clock frequency +.br +#define PI_BAD_HCLK_PASS -99 // need password to use hardware clock 1 +.br +#define PI_HPWM_ILLEGAL -100 // illegal, PWM in use for main clock +.br +#define PI_BAD_DATABITS -101 // serial data bits not 1-32 +.br +#define PI_BAD_STOPBITS -102 // serial (half) stop bits not 2-8 +.br +#define PI_MSG_TOOBIG -103 // socket/pipe message too big +.br +#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode +.br +#define PI_TOO_MANY_SEGS -105 // too many I2C transaction segments +.br +#define PI_BAD_I2C_SEG -106 // an I2C transaction segment failed +.br +#define PI_BAD_SMBUS_CMD -107 // SMBus command not supported by driver +.br +#define PI_NOT_I2C_GPIO -108 // no bit bang I2C in progress on GPIO +.br +#define PI_BAD_I2C_WLEN -109 // bad I2C write length +.br +#define PI_BAD_I2C_RLEN -110 // bad I2C read length +.br +#define PI_BAD_I2C_CMD -111 // bad I2C command +.br +#define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k +.br +#define PI_CHAIN_LOOP_CNT -113 // bad chain loop count +.br +#define PI_BAD_CHAIN_LOOP -114 // empty chain loop +.br +#define PI_CHAIN_COUNTER -115 // too many chain counters +.br +#define PI_BAD_CHAIN_CMD -116 // bad chain command +.br +#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros +.br +#define PI_CHAIN_NESTING -118 // chain counters nested too deeply +.br +#define PI_CHAIN_TOO_BIG -119 // chain is too long +.br +#define PI_DEPRECATED -120 // deprecated function removed +.br +#define PI_BAD_SER_INVERT -121 // bit bang serial invert not 0 or 1 +.br +#define PI_BAD_EDGE -122 // bad ISR edge value, not 0-2 +.br +#define PI_BAD_ISR_INIT -123 // bad ISR initialisation +.br +#define PI_BAD_FOREVER -124 // loop forever must be last command +.br +#define PI_BAD_FILTER -125 // bad filter parameter +.br +#define PI_BAD_PAD -126 // bad pad number +.br +#define PI_BAD_STRENGTH -127 // bad pad drive strength +.br +#define PI_FIL_OPEN_FAILED -128 // file open failed +.br +#define PI_BAD_FILE_MODE -129 // bad file mode +.br +#define PI_BAD_FILE_FLAG -130 // bad file flag +.br +#define PI_BAD_FILE_READ -131 // bad file read +.br +#define PI_BAD_FILE_WRITE -132 // bad file write +.br +#define PI_FILE_NOT_ROPEN -133 // file not open for read +.br +#define PI_FILE_NOT_WOPEN -134 // file not open for write +.br +#define PI_BAD_FILE_SEEK -135 // bad file seek +.br +#define PI_NO_FILE_MATCH -136 // no files match pattern +.br +#define PI_NO_FILE_ACCESS -137 // no permission to access file +.br +#define PI_FILE_IS_A_DIR -138 // file is a directory +.br +#define PI_BAD_SHELL_STATUS -139 // bad shell return status +.br +#define PI_BAD_SCRIPT_NAME -140 // bad script name +.br +#define PI_BAD_SPI_BAUD -141 // bad SPI baud rate, not 50-500k +.br +#define PI_NOT_SPI_GPIO -142 // no bit bang SPI in progress on GPIO +.br +#define PI_BAD_EVENT_ID -143 // bad event id +.br +#define PI_CMD_INTERRUPTED -144 // Used by Python +.br +#define PI_NOT_ON_BCM2711 -145 // not available on BCM2711 +.br +#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711 +.br + +.br +#define PI_PIGIF_ERR_0 -2000 +.br +#define PI_PIGIF_ERR_99 -2099 +.br + +.br +#define PI_CUSTOM_ERR_0 -3000 +.br +#define PI_CUSTOM_ERR_999 -3999 +.br + +.br + +.EE +.SH Defaults + +.EX + +.br +#define PI_DEFAULT_BUFFER_MILLIS 120 +.br +#define PI_DEFAULT_CLK_MICROS 5 +.br +#define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM +.br +#define PI_DEFAULT_IF_FLAGS 0 +.br +#define PI_DEFAULT_FOREGROUND 0 +.br +#define PI_DEFAULT_DMA_CHANNEL 14 +.br +#define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14 +.br +#define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6 +.br +#define PI_DEFAULT_DMA_PRIMARY_CH_2711 7 +.br +#define PI_DEFAULT_DMA_SECONDARY_CH_2711 6 +.br +#define PI_DEFAULT_DMA_NOT_SET 15 +.br +#define PI_DEFAULT_SOCKET_PORT 8888 +.br +#define PI_DEFAULT_SOCKET_PORT_STR "8888" +.br +#define PI_DEFAULT_SOCKET_ADDR_STR "localhost" +.br +#define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL +.br +#define PI_DEFAULT_UPDATE_MASK_B1 0x03E7CF93 +.br +#define PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC7CF9C +.br +#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL +.br +#define PI_DEFAULT_UPDATE_MASK_ZERO 0x0080000FFFFFFCLL +.br +#define PI_DEFAULT_UPDATE_MASK_PI2B 0x0080480FFFFFFCLL +.br +#define PI_DEFAULT_UPDATE_MASK_PI3B 0x0000000FFFFFFCLL +.br +#define PI_DEFAULT_UPDATE_MASK_PI4B 0x0000000FFFFFFCLL +.br +#define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL +.br +#define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO +.br + +.br +#define PI_DEFAULT_CFG_INTERNALS 0 +.br + +.br + +.EE + +.SH SEE ALSO + +pigpiod(1), pig2vcd(1), pigs(1), pigpiod_if(3), pigpiod_if2(3) +.SH AUTHOR + +joan@abyz.me.uk diff --git a/DOC/MAN/pigpiod.1 b/DOC/MAN/pigpiod.1 new file mode 100644 index 0000000..29f8326 --- /dev/null +++ b/DOC/MAN/pigpiod.1 @@ -0,0 +1,273 @@ + +." Process this file with +." groff -man -Tascii pigpiod.1 +." +.TH pigpiod 1 2012-2020 Linux "pigpio archive" +.SH NAME +pigpiod - A utility to start the pigpio library as a daemon. + +.SH SYNOPSIS + +sudo pigpiod [OPTION]... +.SH DESCRIPTION + + +.ad l + +.nh +pigpiod is a utility which launches the pigpio library as a daemon. +.br + +.br +Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces. +.br + +.br +The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users. +.br + +.br +pigpiod accepts the following configuration options +.br + +.br +.SH OPTIONS + +.IP "\fB-a value\fP" +DMA memory allocation mode. +0=AUTO, 1=PMAP, 2=MBOX. +Default AUTO +. +.IP "\fB-b value\fP" +GPIO sample buffer size in milliseconds. +100-10000. +Default 120 +. +.IP "\fB-c value\fP" +Library internal settings. +. +Default 0 +. +.IP "\fB-d value\fP" +Primary DMA channel. +0-14. +Default 14 +. +.IP "\fB-e value\fP" +Secondary DMA channel. +0-14. +Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel +. +.IP "\fB-f\fP" +Disable fifo interface. +. +Default enabled +. +.IP "\fB-g\fP" +Run in foreground (do not fork). +. +Default disabled +. +.IP "\fB-k\fP" +Disable local and remote socket interface. +. +Default enabled +. +.IP "\fB-l\fP" +Disable remote socket interface. +. +Default enabled +. +.IP "\fB-m\fP" +Disable alerts (sampling). +. +Default enabled +. +.IP "\fB-n IP address\fP" +Allow IP address to use the socket interface. +Name (e.g. paul) or dotted quad (e.g. 192.168.1.66). +If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect +. +.IP "\fB-p value\fP" +Socket port. +1024-32000. +Default 8888 +. +.IP "\fB-s value\fP" +Sample rate. +1, 2, 4, 5, 8, or 10 microseconds. +Default 5 +. +.IP "\fB-t value\fP" +Clock peripheral. +0=PWM 1=PCM. +Default PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. +. +.IP "\fB-v -V\fP" +Display pigpio version and exit. +. + +. +.IP "\fB-x mask\fP" +GPIO which may be updated. +A 54 bit mask with (1< + + +gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt + + ./prog +.SH DESCRIPTION + + +.ad l + +.nh + +.br + +.br +THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO +USE THE MORE VERSATILE pigpiod_if2 LIBRARY. + +.br + +.br +pigpiod_if is a C library for the Raspberry which allows control +of the GPIO via the socket interface to the pigpio daemon. +.br + +.br + +.br +.SS Features +.br + +.br +o hardware timed PWM on any of GPIO 0-31 + +.br + +.br +o hardware timed servo pulses on any of GPIO 0-31 + +.br + +.br +o callbacks when any of GPIO 0-31 change state + +.br + +.br +o callbacks at timed intervals + +.br + +.br +o reading/writing all of the GPIO in a bank as one operation + +.br + +.br +o individually setting GPIO modes, reading and writing + +.br + +.br +o notifications when any of GPIO 0-31 change state + +.br + +.br +o the construction of output waveforms with microsecond timing + +.br + +.br +o rudimentary permission control over GPIO + +.br + +.br +o a simple interface to start and stop new threads + +.br + +.br +o I2C, SPI, and serial link wrappers + +.br + +.br +o creating and running scripts on the pigpio daemon + +.br + +.br +.SS GPIO +.br + +.br +ALL GPIO are identified by their Broadcom number. + +.br + +.br +.SS Notes +.br + +.br +The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. + +.br + +.br +.SS Usage +.br + +.br +Include in your source files. + +.br + +.br +Assuming your source is in prog.c use the following command to build + +.br + +.br + +.EX +gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt +.br + +.EE + +.br + +.br +to run make sure the pigpio daemon is running + +.br + +.br + +.EX +sudo pigpiod +.br + +.br + ./prog # sudo is not required to run programs linked to pigpiod_if +.br + +.EE + +.br + +.br +For examples see x_pigpiod_if.c within the pigpio archive file. + +.br + +.br +.SS Notes +.br + +.br +All the functions which return an int return < 0 on error + +.br + +.br + +.SH OVERVIEW + +.br +.SS ESSENTIAL +.br + +.br +pigpio_start Connects to the pigpio daemon +.br +pigpio_stop Disconnects from the pigpio daemon +.br +.SS BEGINNER +.br + +.br +set_mode Set a GPIO mode +.br +get_mode Get a GPIO mode +.br + +.br +set_pull_up_down Set/clear GPIO pull up/down resistor +.br + +.br +gpio_read Read a GPIO +.br +gpio_write Write a GPIO +.br + +.br +set_PWM_dutycycle Start/stop PWM pulses on a GPIO +.br +get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +.br + +.br +set_servo_pulsewidth Start/stop servo pulses on a GPIO +.br +get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO +.br + +.br +callback Create GPIO level change callback +.br +callback_ex Create GPIO level change callback +.br +callback_cancel Cancel a callback +.br +wait_for_edge Wait for GPIO level change +.br +.SS INTERMEDIATE +.br + +.br +gpio_trigger Send a trigger pulse to a GPIO. +.br + +.br +set_watchdog Set a watchdog on a GPIO. +.br + +.br +set_PWM_range Configure PWM range for a GPIO +.br +get_PWM_range Get configured PWM range for a GPIO +.br + +.br +set_PWM_frequency Configure PWM frequency for a GPIO +.br +get_PWM_frequency Get configured PWM frequency for a GPIO +.br + +.br +read_bank_1 Read all GPIO in bank 1 +.br +read_bank_2 Read all GPIO in bank 2 +.br + +.br +clear_bank_1 Clear selected GPIO in bank 1 +.br +clear_bank_2 Clear selected GPIO in bank 2 +.br + +.br +set_bank_1 Set selected GPIO in bank 1 +.br +set_bank_2 Set selected GPIO in bank 2 +.br + +.br +start_thread Start a new thread +.br +stop_thread Stop a previously started thread +.br +.SS ADVANCED +.br + +.br +get_PWM_real_range Get underlying PWM range for a GPIO +.br + +.br +notify_open Request a notification handle +.br +notify_begin Start notifications for selected GPIO +.br +notify_pause Pause notifications +.br +notify_close Close a notification +.br + +.br +bb_serial_read_open Opens a GPIO for bit bang serial reads +.br +bb_serial_read Reads bit bang serial data from a GPIO +.br +bb_serial_read_close Closes a GPIO for bit bang serial reads +.br +bb_serial_invert Invert serial logic (1 invert, 0 normal) +.br + +.br +hardware_clock Start hardware clock on supported GPIO +.br +hardware_PWM Start hardware PWM on supported GPIO +.br + +.br +set_glitch_filter Set a glitch filter on a GPIO +.br +set_noise_filter Set a noise filter on a GPIO +.br +.SS SCRIPTS +.br + +.br +store_script Store a script +.br +run_script Run a stored script +.br +script_status Get script status and parameters +.br +stop_script Stop a running script +.br +delete_script Delete a stored script +.br +.SS WAVES +.br + +.br +wave_clear Deletes all waveforms +.br + +.br +wave_add_new Starts a new waveform +.br +wave_add_generic Adds a series of pulses to the waveform +.br +wave_add_serial Adds serial data to the waveform +.br + +.br +wave_create Creates a waveform from added data +.br +wave_delete Deletes one or more waveforms +.br + +.br +wave_send_once Transmits a waveform once +.br +wave_send_repeat Transmits a waveform repeatedly +.br + +.br +wave_chain Transmits a chain of waveforms +.br + +.br +wave_tx_busy Checks to see if the waveform has ended +.br +wave_tx_stop Aborts the current waveform +.br + +.br +wave_get_micros Length in microseconds of the current waveform +.br +wave_get_high_micros Length of longest waveform so far +.br +wave_get_max_micros Absolute maximum allowed micros +.br + +.br +wave_get_pulses Length in pulses of the current waveform +.br +wave_get_high_pulses Length of longest waveform so far +.br +wave_get_max_pulses Absolute maximum allowed pulses +.br + +.br +wave_get_cbs Length in cbs of the current waveform +.br +wave_get_high_cbs Length of longest waveform so far +.br +wave_get_max_cbs Absolute maximum allowed cbs +.br +.SS I2C +.br + +.br +i2c_open Opens an I2C device +.br +i2c_close Closes an I2C device +.br + +.br +i2c_write_quick smbus write quick +.br +i2c_write_byte smbus write byte +.br +i2c_read_byte smbus read byte +.br +i2c_write_byte_data smbus write byte data +.br +i2c_write_word_data smbus write word data +.br +i2c_read_byte_data smbus read byte data +.br +i2c_read_word_data smbus read word data +.br +i2c_process_call smbus process call +.br +i2c_write_block_data smbus write block data +.br +i2c_read_block_data smbus read block data +.br +i2c_block_process_call smbus block process call +.br + +.br +i2c_write_i2c_block_data smbus write I2C block data +.br +i2c_read_i2c_block_data smbus read I2C block data +.br + +.br +i2c_read_device Reads the raw I2C device +.br +i2c_write_device Writes the raw I2C device +.br + +.br +i2c_zip Performs multiple I2C transactions +.br + +.br +bb_i2c_open Opens GPIO for bit banging I2C +.br +bb_i2c_close Closes GPIO for bit banging I2C +.br +bb_i2c_zip Performs multiple bit banged I2C transactions +.br +.SS SPI +.br + +.br +spi_open Opens a SPI device +.br +spi_close Closes a SPI device +.br + +.br +spi_read Reads bytes from a SPI device +.br +spi_write Writes bytes to a SPI device +.br +spi_xfer Transfers bytes with a SPI device +.br +.SS SERIAL +.br + +.br +serial_open Opens a serial device +.br +serial_close Closes a serial device +.br + +.br +serial_write_byte Writes a byte to a serial device +.br +serial_read_byte Reads a byte from a serial device +.br +serial_write Writes bytes to a serial device +.br +serial_read Reads bytes from a serial device +.br + +.br +serial_data_available Returns number of bytes ready to be read +.br +.SS CUSTOM +.br + +.br +custom_1 User custom function 1 +.br +custom_2 User custom function 2 +.br +.SS UTILITIES +.br + +.br +get_current_tick Get current tick (microseconds) +.br + +.br +get_hardware_revision Get hardware revision +.br +get_pigpio_version Get the pigpio version +.br +pigpiod_if_version Get the pigpiod_if version +.br + +.br +pigpio_error Get a text description of an error code. +.br + +.br +time_sleep Sleeps for a float number of seconds +.br +time_time Float number of seconds since the epoch +.br +.SH FUNCTIONS + +.IP "\fBdouble time_time(void)\fP" +.IP "" 4 +Return the current time in seconds since the Epoch. + +.IP "\fBvoid time_sleep(double seconds)\fP" +.IP "" 4 +Delay execution for a given number of seconds. + +.br + +.br + +.EX +seconds: the number of seconds to delay. +.br + +.EE + +.IP "\fBchar *pigpio_error(int errnum)\fP" +.IP "" 4 +Return a text description for an error code. + +.br + +.br + +.EX +errnum: the error code. +.br + +.EE + +.IP "\fBunsigned pigpiod_if_version(void)\fP" +.IP "" 4 +Return the pigpiod_if version. + +.IP "\fBpthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)\fP" +.IP "" 4 +Starts a new thread of execution with thread_func as the main routine. + +.br + +.br + +.EX +thread_func: the main function for the new thread. +.br + userdata: a pointer to an arbitrary argument. +.br + +.EE + +.br + +.br +Returns a pointer to pthread_t if OK, otherwise NULL. + +.br + +.br +The function is passed the single argument userdata. + +.br + +.br +The thread can be cancelled by passing the pointer to pthread_t to +\fBstop_thread\fP. + +.IP "\fBvoid stop_thread(pthread_t *pth)\fP" +.IP "" 4 +Cancels the thread pointed at by pth. + +.br + +.br + +.EX +pth: the thread to be stopped. +.br + +.EE + +.br + +.br +No value is returned. + +.br + +.br +The thread to be stopped should have been started with \fBstart_thread\fP. + +.IP "\fBint pigpio_start(char *addrStr, char *portStr)\fP" +.IP "" 4 +Connect to the pigpio daemon. Reserving command and +notification streams. + +.br + +.br + +.EX +addrStr: specifies the host or IP address of the Pi running the +.br + pigpio daemon. It may be NULL in which case localhost +.br + is used unless overridden by the PIGPIO_ADDR environment +.br + variable. +.br + +.br +portStr: specifies the port address used by the Pi running the +.br + pigpio daemon. It may be NULL in which case "8888" +.br + is used unless overridden by the PIGPIO_PORT environment +.br + variable. +.br + +.EE + +.IP "\fBvoid pigpio_stop(void)\fP" +.IP "" 4 +Terminates the connection to the pigpio daemon and releases +resources used by the library. + +.IP "\fBint set_mode(unsigned gpio, unsigned mode)\fP" +.IP "" 4 +Set the GPIO mode. + +.br + +.br + +.EX +gpio: 0-53. +.br +mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, +.br + PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, +or PI_NOT_PERMITTED. + +.IP "\fBint get_mode(unsigned gpio)\fP" +.IP "" 4 +Get the GPIO mode. + +.br + +.br + +.EX +gpio: 0-53. +.br + +.EE + +.br + +.br +Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. + +.IP "\fBint set_pull_up_down(unsigned gpio, unsigned pud)\fP" +.IP "" 4 +Set or clear the GPIO pull-up/down resistor. + +.br + +.br + +.EX +gpio: 0-53. +.br + pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, +or PI_NOT_PERMITTED. + +.IP "\fBint gpio_read(unsigned gpio)\fP" +.IP "" 4 +Read the GPIO level. + +.br + +.br + +.EX +gpio:0-53. +.br + +.EE + +.br + +.br +Returns the GPIO level if OK, otherwise PI_BAD_GPIO. + +.IP "\fBint gpio_write(unsigned gpio, unsigned level)\fP" +.IP "" 4 +Write the GPIO level. + +.br + +.br + +.EX + gpio: 0-53. +.br +level: 0, 1. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, +or PI_NOT_PERMITTED. + +.br + +.br +Notes + +.br + +.br +If PWM or servo pulses are active on the GPIO they are switched off. + +.IP "\fBint set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)\fP" +.IP "" 4 +Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31. +.br +dutycycle: 0-range (range defaults to 255). +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, +or PI_NOT_PERMITTED. +Notes + +.br + +.br +The \fBset_PWM_range\fP function may be used to change the +default range of 255. + +.IP "\fBint get_PWM_dutycycle(unsigned user_gpio)\fP" +.IP "" 4 +Return the PWM dutycycle in use on a GPIO. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. + +.br + +.br +For normal PWM the dutycycle will be out of the defined range +for the GPIO (see \fBget_PWM_range\fP). + +.br + +.br +If a hardware clock is active on the GPIO the reported dutycycle +will be 500000 (500k) out of 1000000 (1M). + +.br + +.br +If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). + +.IP "\fBint set_PWM_range(unsigned user_gpio, unsigned range)\fP" +.IP "" 4 +Set the range of PWM values to be used on the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + range: 25-40000. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, +or PI_NOT_PERMITTED. + +.br + +.br +Notes + +.br + +.br +If PWM is currently active on the GPIO its dutycycle will be +scaled to reflect the new range. + +.br + +.br +The real range, the number of steps between fully off and fully on +for each of the 18 available GPIO frequencies is + +.br + +.br + +.EX + 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), +.br + 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12), +.br +2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18) +.br + +.EE + +.br + +.br +The real value set by set_PWM_range is (dutycycle * real range) / range. + +.IP "\fBint get_PWM_range(unsigned user_gpio)\fP" +.IP "" 4 +Get the range of PWM values being used on the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + +.EE + +.br + +.br +Returns the dutycycle range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. + +.br + +.br +If a hardware clock or hardware PWM is active on the GPIO the +reported range will be 1000000 (1M). + +.IP "\fBint get_PWM_real_range(unsigned user_gpio)\fP" +.IP "" 4 +Get the real underlying range of PWM values being used on the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + +.EE + +.br + +.br +Returns the real range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. + +.br + +.br +If a hardware clock is active on the GPIO the reported +real range will be 1000000 (1M). + +.br + +.br +If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. + +.br + +.br + +.IP "\fBint set_PWM_frequency(unsigned user_gpio, unsigned frequency)\fP" +.IP "" 4 +Set the frequency (in Hz) of the PWM to be used on the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31. +.br +frequency: >=0 (Hz). +.br + +.EE + +.br + +.br +Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PERMITTED. + +.br + +.br +If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. + +.br + +.br +Each GPIO can be independently set to one of 18 different +PWM frequencies. + +.br + +.br +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. + +.br + +.br +The frequencies for each sample rate are: + +.br + +.br + +.EX + Hertz +.br + +.br + 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 +.br + 1250 1000 800 500 400 250 200 100 50 +.br + +.br + 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 +.br + 625 500 400 250 200 125 100 50 25 +.br + +.br + 4: 10000 5000 2500 2000 1250 1000 625 500 400 +.br + 313 250 200 125 100 63 50 25 13 +.br +sample +.br + rate +.br + (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 +.br + 250 200 160 100 80 50 40 20 10 +.br + +.br + 8: 5000 2500 1250 1000 625 500 313 250 200 +.br + 156 125 100 63 50 31 25 13 6 +.br + +.br + 10: 4000 2000 1000 800 500 400 250 200 160 +.br + 125 100 80 50 40 25 20 10 5 +.br + +.EE + +.IP "\fBint get_PWM_frequency(unsigned user_gpio)\fP" +.IP "" 4 +Get the frequency of PWM being used on the GPIO. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + +.EE + +.br + +.br +For normal PWM the frequency will be that defined for the GPIO by +\fBset_PWM_frequency\fP. + +.br + +.br +If a hardware clock is active on the GPIO the reported frequency +will be that set by \fBhardware_clock\fP. + +.br + +.br +If hardware PWM is active on the GPIO the reported frequency +will be that set by \fBhardware_PWM\fP. + +.br + +.br +Returns the frequency (in hertz) used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. + +.IP "\fBint set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)\fP" +.IP "" 4 +Start (500-2500) or stop (0) servo pulses on the GPIO. + +.br + +.br + +.EX + user_gpio: 0-31. +.br +pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise). +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or +PI_NOT_PERMITTED. + +.br + +.br +The selected pulsewidth will continue to be transmitted until +changed by a subsequent call to set_servo_pulsewidth. + +.br + +.br +The pulsewidths supported by servos varies and should probably be +determined by experiment. A value of 1500 should always be safe and +represents the mid-point of rotation. + +.br + +.br +You can DAMAGE a servo if you command it to move beyond its limits. + +.br + +.br +OTHER UPDATE RATES: + +.br + +.br +This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. + +.br + +.br + +.EX +Update Rate (Hz) 50 100 200 400 500 +.br +1E6/Hz 20000 10000 5000 2500 2000 +.br + +.EE + +.br + +.br +Firstly set the desired PWM frequency using \fBset_PWM_frequency\fP. + +.br + +.br +Then set the PWM range using \fBset_PWM_range\fP to 1E6/Hz. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. + +.br + +.br +E.g. If you want to update a servo connected to GPIO 25 at 400Hz + +.br + +.br + +.EX +set_PWM_frequency(25, 400); +.br +set_PWM_range(25, 2500); +.br + +.EE + +.br + +.br +Thereafter use the \fBset_PWM_dutycycle\fP function to move the servo, +e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse. +.br + +.IP "\fBint get_servo_pulsewidth(unsigned user_gpio)\fP" +.IP "" 4 +Return the servo pulsewidth in use on a GPIO. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. + +.IP "\fBint notify_open(void)\fP" +.IP "" 4 +Get a free notification handle. + +.br + +.br +Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. + +.br + +.br +A notification is a method for being notified of GPIO state +changes via a pipe. + +.br + +.br +Pipes are only accessible from the local machine so this function +serves no purpose if you are using the library from a remote machine. +The in-built (socket) notifications provided by \fBcallback\fP +should be used instead. + +.br + +.br +Notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). +E.g. if the function returns 15 then the notifications must be +read from /dev/pigpio15. + +.IP "\fBint notify_begin(unsigned handle, uint32_t bits)\fP" +.IP "" 4 +Start notifications on a previously opened handle. + +.br + +.br + +.EX +handle: 0-31 (as returned by \fBnotify_open\fP) +.br + bits: a mask indicating the GPIO to be notified. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +The notification sends state changes for each GPIO whose +corresponding bit in bits is set. + +.br + +.br +Each notification occupies 12 bytes in the fifo as follows: + +.br + +.br + +.EX +typedef struct +.br +{ +.br + uint16_t seqno; +.br + uint16_t flags; +.br + uint32_t tick; +.br + uint32_t level; +.br +} gpioReport_t; +.br + +.EE + +.br + +.br +seqno: starts at 0 each time the handle is opened and then increments +by one for each report. + +.br + +.br +flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. + +.br + +.br +PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. + +.br + +.br +PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. + +.br + +.br +tick: the number of microseconds since system boot. It wraps around +after 1h12m. + +.br + +.br +level: indicates the level of each GPIO. If bit 1<=0 +.br + numBytes: >=1 +.br + str: an array of chars. +.br + +.EE + +.br + +.br +Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. + +.br + +.br +NOTES: + +.br + +.br +The serial data is formatted as one start bit, \fBdata_bits\fP data bits, +and \fBstop_bits\fP/2 stop bits. + +.br + +.br +It is legal to add serial data streams with different baud rates to +the same waveform. + +.br + +.br +\fBnumBytes\fP is the number of bytes of data in str. + +.br + +.br +The bytes required for each character depend upon \fBdata_bits\fP. + +.br + +.br +For \fBdata_bits\fP 1-8 there will be one byte per character. +.br +For \fBdata_bits\fP 9-16 there will be two bytes per character. +.br +For \fBdata_bits\fP 17-32 there will be four bytes per character. + +.IP "\fBint wave_create(void)\fP" +.IP "" 4 +This function creates a waveform from the data provided by the prior +calls to the \fBwave_add_*\fP functions. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. + +.br + +.br +The data provided by the \fBwave_add_*\fP functions is consumed by this +function. + +.br + +.br +As many waveforms may be created as there is space available. The +wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. + +.br + +.br +Normal usage would be + +.br + +.br +Step 1. \fBwave_clear\fP to clear all waveforms and added data. + +.br + +.br +Step 2. \fBwave_add_*\fP calls to supply the waveform data. + +.br + +.br +Step 3. \fBwave_create\fP to create the waveform and get a unique id + +.br + +.br +Repeat steps 2 and 3 as needed. + +.br + +.br +Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. + +.br + +.br +A waveform comprises one or more pulses. Each pulse consists of a +\fBgpioPulse_t\fP structure. + +.br + +.br + +.EX +typedef struct +.br +{ +.br + uint32_t gpioOn; +.br + uint32_t gpioOff; +.br + uint32_t usDelay; +.br +} gpioPulse_t; +.br + +.EE + +.br + +.br +The fields specify + +.br + +.br +1) the GPIO to be switched on at the start of the pulse. +.br +2) the GPIO to be switched off at the start of the pulse. +.br +3) the delay in microseconds before the next pulse. +.br + +.br + +.br +Any or all the fields can be zero. It doesn't make any sense to +set all the fields to zero (the pulse will be ignored). + +.br + +.br +When a waveform is started each pulse is executed in order with the +specified delay between the pulse and the next. + +.br + +.br +Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. + +.IP "\fBint wave_delete(unsigned wave_id)\fP" +.IP "" 4 +This function deletes the waveform with id wave_id. + +.br + +.br + +.EX +wave_id: >=0, as returned by \fBwave_create\fP. +.br + +.EE + +.br + +.br +Wave ids are allocated in order, 0, 1, 2, etc. + +.br + +.br +The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. + +.br + +.br +- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. + +.br + +.br +- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_WAVE_ID. + +.IP "\fBint wave_send_once(unsigned wave_id)\fP" +.IP "" 4 +This function transmits the waveform with id wave_id. The waveform +is sent once. + +.br + +.br +NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. + +.br + +.br + +.EX +wave_id: >=0, as returned by \fBwave_create\fP. +.br + +.EE + +.br + +.br +Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. + +.IP "\fBint wave_send_repeat(unsigned wave_id)\fP" +.IP "" 4 +This function transmits the waveform with id wave_id. The waveform +cycles until cancelled (either by the sending of a new waveform or +by \fBwave_tx_stop\fP). + +.br + +.br +NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. + +.br + +.br + +.EX +wave_id: >=0, as returned by \fBwave_create\fP. +.br + +.EE + +.br + +.br +Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. + +.IP "\fBint wave_chain(char *buf, unsigned bufSize)\fP" +.IP "" 4 +This function transmits a chain of waveforms. + +.br + +.br +NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. + +.br + +.br +The waves to be transmitted are specified by the contents of buf +which contains an ordered list of \fBwave_id\fPs and optional command +codes and related data. + +.br + +.br + +.EX + buf: pointer to the wave_ids and optional command codes +.br +bufSize: the number of bytes in buf +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. + +.br + +.br +Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. + +.br + +.br +A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. + +.br + +.br +Delays between waves may be added with the delay command. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +Loop Start 255 0 Identify start of a wave block +.br +Loop Repeat 255 1 x y loop x + y*256 times +.br +Delay 255 2 x y delay x + y*256 microseconds +.br +Loop Forever 255 3 loop forever +.br + +.br + +.br +If present Loop Forever must be the last entry in the chain. + +.br + +.br +The code is currently dimensioned to support a chain with roughly +600 entries and 20 loop counters. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +#define WAVES 5 +.br +#define GPIO 4 +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int i, wid[WAVES]; +.br + +.br + if (pigpio_start(0, 0)<0) return -1; +.br + +.br + set_mode(GPIO, PI_OUTPUT); +.br + +.br + for (i=0; i=0, as returned by \fBstore_script\fP. +.br + numPar: 0-10, the number of parameters. +.br + param: an array of parameters. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM + +.br + +.br +param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. + +.IP "\fBint script_status(unsigned script_id, uint32_t *param)\fP" +.IP "" 4 +This function returns the run status of a stored script as well +as the current values of parameters 0 to 9. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBstore_script\fP. +.br + param: an array to hold the returned 10 parameters. +.br + +.EE + +.br + +.br +The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. + +.br + +.br +The run status may be + +.br + +.br + +.EX +PI_SCRIPT_INITING +.br +PI_SCRIPT_HALTED +.br +PI_SCRIPT_RUNNING +.br +PI_SCRIPT_WAITING +.br +PI_SCRIPT_FAILED +.br + +.EE + +.br + +.br +The current value of script parameters 0 to 9 are returned in param. + +.IP "\fBint stop_script(unsigned script_id)\fP" +.IP "" 4 +This function stops a running script. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBstore_script\fP. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. + +.IP "\fBint delete_script(unsigned script_id)\fP" +.IP "" 4 +This function deletes a stored script. + +.br + +.br + +.EX +script_id: >=0, as returned by \fBstore_script\fP. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. + +.IP "\fBint bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)\fP" +.IP "" 4 +This function opens a GPIO for bit bang reading of serial data. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + baud: 50-250000 +.br +data_bits: 1-32 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, +or PI_GPIO_IN_USE. + +.br + +.br +The serial data is returned in a cyclic buffer and is read using +bb_serial_read. + +.br + +.br +It is the caller's responsibility to read data from the cyclic buffer +in a timely fashion. + +.IP "\fBint bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)\fP" +.IP "" 4 +This function copies up to bufSize bytes of data read from the +bit bang serial cyclic buffer to the buffer starting at buf. + +.br + +.br + +.EX +user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. +.br + buf: an array to receive the read bytes. +.br + bufSize: >=0 +.br + +.EE + +.br + +.br +Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. + +.br + +.br +The bytes returned for each character depend upon the number of +data bits \fBdata_bits\fP specified in the \fBbb_serial_read_open\fP command. + +.br + +.br +For \fBdata_bits\fP 1-8 there will be one byte per character. +.br +For \fBdata_bits\fP 9-16 there will be two bytes per character. +.br +For \fBdata_bits\fP 17-32 there will be four bytes per character. + +.IP "\fBint bb_serial_read_close(unsigned user_gpio)\fP" +.IP "" 4 +This function closes a GPIO for bit bang reading of serial data. + +.br + +.br + +.EX +user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. + +.IP "\fBint bb_serial_invert(unsigned user_gpio, unsigned invert)\fP" +.IP "" 4 +This function inverts serial logic for big bang serial reads. + +.br + +.br + +.EX +user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. +.br + invert: 0-1, 1 invert, 0 normal. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. + +.IP "\fBint i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)\fP" +.IP "" 4 +This returns a handle for the device at address i2c_addr on bus i2c_bus. + +.br + +.br + +.EX + i2c_bus: >=0. +.br + i2c_addr: 0-0x7F. +.br +i2c_flags: 0. +.br + +.EE + +.br + +.br +No flags are currently defined. This parameter should be set to zero. + +.br + +.br +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + +.br + +.br +The GPIO used are given in the following table. + +.br + +.br + SDA SCL +.br +I2C 0 0 1 +.br +I2C 1 2 3 +.br + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. + +.br + +.br +For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. + +.br + +.br + +.EX +S (1 bit) : Start bit +.br +P (1 bit) : Stop bit +.br +Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. +.br +A, NA (1 bit) : Accept and not accept bit. +.br +.br +.br +Addr (7 bits): I2C 7 bit address. +.br +Comm (8 bits): Command byte, a data byte which often selects a register. +.br +Data (8 bits): A data byte. +.br +Count (8 bits): A data byte containing the length of a block operation. +.br + +.br +[..]: Data sent by the device. +.br + +.EE + +.IP "\fBint i2c_close(unsigned handle)\fP" +.IP "" 4 +This closes the I2C device associated with the handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint i2c_write_quick(unsigned handle, unsigned bit)\fP" +.IP "" 4 +This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + bit: 0-1, the value to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Quick command. SMBus 2.0 5.5.1 + +.EX +S Addr Rd/Wr [A] P +.br + +.EE + +.IP "\fBint i2c_write_byte(unsigned handle, unsigned bVal)\fP" +.IP "" 4 +This sends a single byte to the device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + bVal: 0-0xFF, the value to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Send byte. SMBus 2.0 5.5.2 + +.EX +S Addr Wr [A] Data [A] P +.br + +.EE + +.IP "\fBint i2c_read_byte(unsigned handle)\fP" +.IP "" 4 +This reads a single byte from the device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + +.EE + +.br + +.br +Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. + +.br + +.br +Receive byte. SMBus 2.0 5.5.3 + +.EX +S Addr Rd [A] [Data] NA P +.br + +.EE + +.IP "\fBint i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)\fP" +.IP "" 4 +This writes a single byte to the specified register of the device +associated with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write. +.br + bVal: 0-0xFF, the value to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Write byte. SMBus 2.0 5.5.4 + +.EX +S Addr Wr [A] Comm [A] Data [A] P +.br + +.EE + +.IP "\fBint i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" +.IP "" 4 +This writes a single 16 bit word to the specified register of the device +associated with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write. +.br + wVal: 0-0xFFFF, the value to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Write word. SMBus 2.0 5.5.4 + +.EX +S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P +.br + +.EE + +.IP "\fBint i2c_read_byte_data(unsigned handle, unsigned i2c_reg)\fP" +.IP "" 4 +This reads a single byte from the specified register of the device +associated with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to read. +.br + +.EE + +.br + +.br +Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Read byte. SMBus 2.0 5.5.5 + +.EX +S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P +.br + +.EE + +.IP "\fBint i2c_read_word_data(unsigned handle, unsigned i2c_reg)\fP" +.IP "" 4 +This reads a single 16 bit word from the specified register of the device +associated with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to read. +.br + +.EE + +.br + +.br +Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Read word. SMBus 2.0 5.5.5 + +.EX +S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P +.br + +.EE + +.IP "\fBint i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" +.IP "" 4 +This writes 16 bits of data to the specified register of the device +associated with handle and and reads 16 bits of data in return. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write/read. +.br + wVal: 0-0xFFFF, the value to write. +.br + +.EE + +.br + +.br +Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Process call. SMBus 2.0 5.5.6 + +.EX +S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] +.br + S Addr Rd [A] [DataLow] A [DataHigh] NA P +.br + +.EE + +.IP "\fBint i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes up to 32 bytes to the specified register of the device +associated with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write. +.br + buf: an array with the data to send. +.br + count: 1-32, the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Block write. SMBus 2.0 5.5.7 + +.EX +S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P +.br + +.EE + +.IP "\fBint i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)\fP" +.IP "" 4 +This reads a block of up to 32 bytes from the specified register of +the device associated with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to read. +.br + buf: an array to receive the read data. +.br + +.EE + +.br + +.br +The amount of returned data is set by the device. + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Block read. SMBus 2.0 5.5.7 + +.EX +S Addr Wr [A] Comm [A] +.br + S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P +.br + +.EE + +.IP "\fBint i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write/read. +.br + buf: an array with the data to send and to receive the read data. +.br + count: 1-32, the number of bytes to write. +.br + +.EE + +.br + +.br + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +The smbus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. + +.br + +.br +Block write-block read. SMBus 2.0 5.5.8 + +.EX +S Addr Wr [A] Comm [A] Count [A] Data [A] ... +.br + S Addr Rd [A] [Count] A [Data] ... A P +.br + +.EE + +.IP "\fBint i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" +.IP "" 4 +This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to read. +.br + buf: an array to receive the read data. +.br + count: 1-32, the number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br + +.EX +S Addr Wr [A] Comm [A] +.br + S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P +.br + +.EE + +.IP "\fBint i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes 1 to 32 bytes to the specified register of the device +associated with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write. +.br + buf: the data to write. +.br + count: 1-32, the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br + +.EX +S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P +.br + +.EE + +.IP "\fBint i2c_read_device(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This reads count bytes from the raw device into buf. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + buf: an array to receive the read data bytes. +.br + count: >0, the number of bytes to read. +.br + +.EE + +.br + +.br +Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. + +.IP "\fBint i2c_write_device(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This writes count bytes from buf to the raw device. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + buf: an array containing the data bytes to write. +.br + count: >0, the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.IP "\fBint i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" +.IP "" 4 +This function executes a sequence of I2C operations. The +operations to be performed are specified by the contents of inBuf +which contains the concatenated command codes and associated data. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + inBuf: pointer to the concatenated I2C commands, see below +.br + inLen: size of command buffer +.br +outBuf: pointer to buffer to hold returned data +.br +outLen: size of output buffer +.br + +.EE + +.br + +.br +Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +End 0 No more commands +.br +Escape 1 Next P is two bytes +.br +On 2 Switch combined flag on +.br +Off 3 Switch combined flag off +.br +Address 4 P Set I2C address to P +.br +Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) +.br +Read 6 P Read P bytes of data +.br +Write 7 P ... Write P bytes of data +.br + +.br + +.br +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +.br + +.br +The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. + +.br + +.br +The returned I2C data is stored in consecutive locations of outBuf. + +.br + +.br +\fBExample\fP +.br + +.EX +Set address 0x53, write 0x32, read 6 bytes +.br +Set address 0x1E, write 0x03, read 6 bytes +.br +Set address 0x68, write 0x1B, read 8 bytes +.br +End +.br + +.br +0x04 0x53 0x07 0x01 0x32 0x06 0x06 +.br +0x04 0x1E 0x07 0x01 0x03 0x06 0x06 +.br +0x04 0x68 0x07 0x01 0x1B 0x06 0x08 +.br +0x00 +.br + +.EE + +.br + +.br + +.IP "\fBint bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)\fP" +.IP "" 4 +This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. + +.br + +.br +Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. + +.br + +.br +o baud rates as low as 50 +.br +o repeated starts +.br +o clock stretching +.br +o I2C on any pair of spare GPIO + +.br + +.br + +.EX + SDA: 0-31 +.br + SCL: 0-31 +.br +baud: 50-500000 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. + +.br + +.br +NOTE: + +.br + +.br +The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. + +.IP "\fBint bb_i2c_close(unsigned SDA)\fP" +.IP "" 4 +This function stops bit banging I2C on a pair of GPIO previously +opened with \fBbb_i2c_open\fP. + +.br + +.br + +.EX +SDA: 0-31, the SDA GPIO used in a prior call to \fBbb_i2c_open\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. + +.IP "\fBint bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" +.IP "" 4 +This function executes a sequence of bit banged I2C operations. The +operations to be performed are specified by the contents of inBuf +which contains the concatenated command codes and associated data. + +.br + +.br + +.EX + SDA: 0-31 (as used in a prior call to \fBbb_i2c_open\fP) +.br + inBuf: pointer to the concatenated I2C commands, see below +.br + inLen: size of command buffer +.br +outBuf: pointer to buffer to hold returned data +.br +outLen: size of output buffer +.br + +.EE + +.br + +.br +Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +End 0 No more commands +.br +Escape 1 Next P is two bytes +.br +Start 2 Start condition +.br +Stop 3 Stop condition +.br +Address 4 P Set I2C address to P +.br +Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) +.br +Read 6 P Read P bytes of data +.br +Write 7 P ... Write P bytes of data +.br + +.br + +.br +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +.br + +.br +The address and flags default to 0. The address and flags maintain +their previous value until updated. + +.br + +.br +No flags are currently defined. + +.br + +.br +The returned I2C data is stored in consecutive locations of outBuf. + +.br + +.br +\fBExample\fP +.br + +.EX +Set address 0x53 +.br +start, write 0x32, (re)start, read 6 bytes, stop +.br +Set address 0x1E +.br +start, write 0x03, (re)start, read 6 bytes, stop +.br +Set address 0x68 +.br +start, write 0x1B, (re)start, read 8 bytes, stop +.br +End +.br + +.br +0x04 0x53 +.br +0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 +.br + +.br +0x04 0x1E +.br +0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 +.br + +.br +0x04 0x68 +.br +0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 +.br + +.br +0x00 +.br + +.EE + +.IP "\fBint spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)\fP" +.IP "" 4 +This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. + +.br + +.br +The Pi has two SPI peripherals: main and auxiliary. + +.br + +.br +The main SPI has two chip selects (channels), the auxiliary has +three. + +.br + +.br +The auxiliary SPI is available on all models but the A and B. + +.br + +.br +The GPIO used are given in the following table. + +.br + +.br + MISO MOSI SCLK CE0 CE1 CE2 +.br +Main SPI 9 10 11 8 7 - +.br +Aux SPI 19 20 21 18 17 16 +.br + +.br + +.br + +.EX +spi_channel: 0-1 (0-2 for the auxiliary SPI). +.br + baud: 32K-125M (values above 30M are unlikely to work). +.br + spi_flags: see below. +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. + +.br + +.br +spi_flags consists of the least significant 22 bits. + +.br + +.br + +.EX +21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m +.br + +.EE + +.br + +.br +mm defines the SPI mode. + +.br + +.br +Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. + +.br + +.br + +.EX +Mode POL PHA +.br + 0 0 0 +.br + 1 0 1 +.br + 2 1 0 +.br + 3 1 1 +.br + +.EE + +.br + +.br +px is 0 if CEx is active low (default) and 1 for active high. + +.br + +.br +ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. + +.br + +.br +A is 0 for the main SPI, 1 for the auxiliary SPI. + +.br + +.br +W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main +SPI only. + +.br + +.br +nnnn defines the number of bytes (0-15) to write before switching +the MOSI line to MISO to read data. This field is ignored +if W is not set. Main SPI only. + +.br + +.br +T is 1 if the least significant bit is transmitted on MOSI first, the +default (0) shifts the most significant bit out first. Auxiliary SPI +only. + +.br + +.br +R is 1 if the least significant bit is received on MISO first, the +default (0) receives the most significant bit first. Auxiliary SPI +only. + +.br + +.br +bbbbbb defines the word size in bits (0-32). The default (0) +sets 8 bits per word. Auxiliary SPI only. + +.br + +.br +The \fBspi_read\fP, \fBspi_write\fP, and \fBspi_xfer\fP functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. + +.br + +.br +For bits 1-8 there will be one byte per word. +.br +For bits 9-16 there will be two bytes per word. +.br +For bits 17-32 there will be four bytes per word. + +.br + +.br +Multi-byte transfers are made in least significant byte first order. + +.br + +.br +E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. + +.br + +.br +E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed +by 0x1A. + +.br + +.br +The other bits in flags should be set to zero. + +.IP "\fBint spi_close(unsigned handle)\fP" +.IP "" 4 +This functions closes the SPI device identified by the handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBspi_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint spi_read(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads count bytes of data from the SPI +device associated with the handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBspi_open\fP. +.br + buf: an array to receive the read data bytes. +.br + count: the number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint spi_write(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes of data from buf to the SPI +device associated with the handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBspi_open\fP. +.br + buf: the data bytes to write. +.br + count: the number of bytes to write. +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" +.IP "" 4 +This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBspi_open\fP. +.br + txBuf: the data bytes to write. +.br + rxBuf: the received data bytes. +.br + count: the number of bytes to transfer. +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)\fP" +.IP "" 4 +This function opens a serial device at a specified baud rate +with specified flags. The device name must start with +/dev/tty or /dev/serial. + +.br + +.br + +.EX + ser_tty: the serial device to open. +.br + baud: the baud rate in bits per second, see below. +.br +ser_flags: 0. +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. + +.br + +.br +The baud rate must be one of 50, 75, 110, 134, 150, +200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, +38400, 57600, 115200, or 230400. + +.br + +.br +No flags are currently defined. This parameter should be set to zero. + +.IP "\fBint serial_close(unsigned handle)\fP" +.IP "" 4 +This function closes the serial device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint serial_write_byte(unsigned handle, unsigned bVal)\fP" +.IP "" 4 +This function writes bVal to the serial port associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. + +.IP "\fBint serial_read_byte(unsigned handle)\fP" +.IP "" 4 +This function reads a byte from the serial port associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + +.EE + +.br + +.br +Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. + +.br + +.br +If no data is ready PI_SER_READ_NO_DATA is returned. + +.IP "\fBint serial_write(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes from buf to the the serial port +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + buf: the array of bytes to write. +.br + count: the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. + +.IP "\fBint serial_read(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads up to count bytes from the the serial port +associated with handle and writes them to buf. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + buf: an array to receive the read data. +.br + count: the maximum number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. + +.br + +.br +If no data is ready zero is returned. + +.IP "\fBint serial_data_available(unsigned handle)\fP" +.IP "" 4 +Returns the number of bytes available to be read from the +device associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + +.EE + +.br + +.br +Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. + +.IP "\fBint custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)\fP" +.IP "" 4 +This function is available for user customisation. + +.br + +.br +It returns a single integer value. + +.br + +.br + +.EX +arg1: >=0 +.br +arg2: >=0 +.br +argx: extra (byte) arguments +.br +argc: number of extra arguments +.br + +.EE + +.br + +.br +Returns >= 0 if OK, less than 0 indicates a user defined error. + +.IP "\fBint custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" +.IP "" 4 +This function is available for user customisation. + +.br + +.br +It differs from custom_1 in that it returns an array of bytes +rather than just an integer. + +.br + +.br +The return value is an integer indicating the number of returned bytes. + +.EX + arg1: >=0 +.br + argc: extra (byte) arguments +.br + count: number of extra arguments +.br +retBuf: buffer for returned data +.br +retMax: maximum number of bytes to return +.br + +.EE + +.br + +.br +Returns >= 0 if OK, less than 0 indicates a user defined error. + +.br + +.br +Note, the number of returned bytes will be retMax or less. + +.IP "\fBint callback(unsigned user_gpio, unsigned edge, CBFunc_t f)\fP" +.IP "" 4 +This function initialises a new callback. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. +.br + f: the callback function. +.br + +.EE + +.br + +.br +The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. + +.br + +.br +The callback is called with the GPIO, edge, and tick, whenever the +GPIO has the identified edge. + +.br + +.br + +.EX +Parameter Value Meaning +.br + +.br +GPIO 0-31 The GPIO which has changed state +.br + +.br +edge 0-2 0 = change to low (a falling edge) +.br + 1 = change to high (a rising edge) +.br + 2 = no level change (a watchdog timeout) +.br + +.br +tick 32 bit The number of microseconds since boot +.br + WARNING: this wraps around from +.br + 4294967295 to 0 roughly every 72 minutes +.br + +.EE + +.IP "\fBint callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP" +.IP "" 4 +This function initialises a new callback. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. +.br + f: the callback function. +.br + userdata: a pointer to arbitrary user data. +.br + +.EE + +.br + +.br +The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. + +.br + +.br +The callback is called with the GPIO, edge, tick, and user, whenever +the GPIO has the identified edge. + +.br + +.br + +.EX +Parameter Value Meaning +.br + +.br +GPIO 0-31 The GPIO which has changed state +.br + +.br +edge 0-2 0 = change to low (a falling edge) +.br + 1 = change to high (a rising edge) +.br + 2 = no level change (a watchdog timeout) +.br + +.br +tick 32 bit The number of microseconds since boot +.br + WARNING: this wraps around from +.br + 4294967295 to 0 roughly every 72 minutes +.br + +.br +userdata pointer Pointer to an arbitrary object +.br + +.EE + +.IP "\fBint callback_cancel(unsigned callback_id)\fP" +.IP "" 4 +This function cancels a callback identified by its id. + +.br + +.br + +.EX +callback_id: >=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise pigif_callback_not_found. + +.IP "\fBint wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)\fP" +.IP "" 4 +This function waits for edge on the GPIO for up to timeout +seconds. + +.br + +.br + +.EX +user_gpio: 0-31. +.br + edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. +.br + timeout: >=0. +.br + +.EE + +.br + +.br +The function returns 1 if the edge occurred, otherwise 0. + +.br + +.br +The function returns when the edge occurs or after the timeout. +.SH PARAMETERS + +.br + +.br + +.IP "\fBactive\fP: 0-1000000" 0 + +.br + +.br +The number of microseconds level changes are reported for once +a noise filter has been triggered (by \fBsteady\fP microseconds of +a stable level). + +.br + +.br + +.IP "\fB*addrStr\fP" 0 +A string specifying the host or IP address of the Pi running +the pigpio daemon. It may be NULL in which case localhost +is used unless overridden by the PIGPIO_ADDR environment +variable. + +.br + +.br + +.IP "\fBarg1\fP" 0 +An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. + +.br + +.br + +.IP "\fBarg2\fP" 0 +An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. + +.br + +.br + +.IP "\fBargc\fP" 0 +The count of bytes passed to a user customised function. + +.br + +.br + +.IP "\fB*argx\fP" 0 +A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. + +.br + +.br + +.IP "\fBbaud\fP" 0 +The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. + +.br + +.br + +.IP "\fBbit\fP" 0 +A value of 0 or 1. + +.br + +.br + +.IP "\fBbits\fP" 0 +A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. + +.br + +.br +A convenient way to set bit n is to or in (1<=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. This is +passed to \fBcallback_cancel\fP to cancel the callback. + +.br + +.br + +.IP "\fBCBFunc_t\fP" 0 + +.EX +typedef void (*CBFunc_t) +.br + (unsigned user_gpio, unsigned level, uint32_t tick); +.br + +.EE + +.br + +.br + +.IP "\fBCBFuncEx_t\fP" 0 + +.EX +typedef void (*CBFuncEx_t) +.br + (unsigned user_gpio, unsigned level, uint32_t tick, void * user); +.br + +.EE + +.br + +.br + +.IP "\fBchar\fP" 0 +A single character, an 8 bit quantity able to store 0-255. + +.br + +.br + +.IP "\fBclkfreq\fP: 4689-250000000 (250M)" 0 +The hardware clock frequency. + +.br + +.br + +.IP "\fBcount\fP" 0 +The number of bytes to be transferred in an I2C, SPI, or Serial +command. + +.br + +.br + +.IP "\fBdata_bits\fP: 1-32" 0 +The number of data bits in each character of serial data. + +.br + +.br + +.EX +#define PI_MIN_WAVE_DATABITS 1 +.br +#define PI_MAX_WAVE_DATABITS 32 +.br + +.EE + +.br + +.br + +.IP "\fBdouble\fP" 0 +A floating point number. + +.br + +.br + +.IP "\fBdutycycle\fP: 0-range" 0 +A number representing the ratio of on time to off time for PWM. + +.br + +.br +The number may vary between 0 and range (default 255) where +0 is off and range is fully on. + +.br + +.br + +.IP "\fBedge\fP" 0 +Used to identify a GPIO level transition of interest. A rising edge is +a level change from 0 to 1. A falling edge is a level change from 1 to 0. + +.br + +.br + +.EX +RISING_EDGE 0 +.br +FALLING_EDGE 1 +.br +EITHER_EDGE. 2 +.br + +.EE + +.br + +.br + +.IP "\fBerrnum\fP" 0 +A negative number indicating a function call failed and the nature +of the error. + +.br + +.br + +.IP "\fBf\fP" 0 +A function. + +.br + +.br + +.IP "\fBfrequency\fP: >=0" 0 +The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. + +.br + +.br + +.br + +.br + +.IP "\fBgpio\fP" 0 +A Broadcom numbered GPIO, in the range 0-53. + +.br + +.br +There are 54 General Purpose Input Outputs (GPIO) named gpio0 through +gpio53. + +.br + +.br +They are split into two banks. Bank 1 consists of gpio0 through +gpio31. Bank 2 consists of gpio32 through gpio53. + +.br + +.br +All the GPIO which are safe for the user to read and write are in +bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards +have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. + +.br + +.br +See \fBget_hardware_revision\fP. + +.br + +.br +The user GPIO are marked with an X in the following table. + +.br + +.br + +.EX + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 +.br +Type 1 X X - - X - - X X X X X - - X X +.br +Type 2 - - X X X - - X X X X X - - X X +.br +Type 3 X X X X X X X X X X X X X X +.br + +.br + 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +.br +Type 1 - X X - - X X X X X - - - - - - +.br +Type 2 - X X - - - X X X X - X X X X X +.br +Type 3 X X X X X X X X X X X X - - - - +.br + +.EE + +.br + +.br + +.IP "\fBgpioPulse_t\fP" 0 + +.EX +typedef struct +.br +{ +.br +uint32_t gpioOn; +.br +uint32_t gpioOff; +.br +uint32_t usDelay; +.br +} gpioPulse_t; +.br + +.EE + +.br + +.br + +.IP "\fBgpioThreadFunc_t\fP" 0 + +.EX +typedef void *(gpioThreadFunc_t) (void *); +.br + +.EE + +.br + +.br + +.IP "\fBhandle\fP: >=0" 0 +A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\fP, +\fBserial_open\fP, and \fBspi_open\fP. + +.br + +.br + +.IP "\fBi2c_addr\fP: 0-0x7F" 0 +The address of a device on the I2C bus. + +.br + +.br + +.IP "\fBi2c_bus\fP: >=0" 0 +An I2C bus number. + +.br + +.br + +.IP "\fBi2c_flags\fP: 0" 0 +Flags which modify an I2C open command. None are currently defined. + +.br + +.br + +.IP "\fBi2c_reg\fP: 0-255" 0 +A register of an I2C device. + +.br + +.br + +.IP "\fB*inBuf\fP" 0 +A buffer used to pass data to a function. + +.br + +.br + +.IP "\fBinLen\fP" 0 +The number of bytes of data in a buffer. + +.br + +.br + +.IP "\fBint\fP" 0 +A whole number, negative or positive. + +.br + +.br + +.IP "\fBinvert\fP" 0 +A flag used to set normal or inverted bit bang serial data level logic. + +.br + +.br + +.IP "\fBlevel\fP" 0 +The level of a GPIO. Low or High. + +.br + +.br + +.EX +PI_OFF 0 +.br +PI_ON 1 +.br + +.br +PI_CLEAR 0 +.br +PI_SET 1 +.br + +.br +PI_LOW 0 +.br +PI_HIGH 1 +.br + +.EE + +.br + +.br +There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See \fBset_watchdog\fP. + +.br + +.br + +.EX +PI_TIMEOUT 2 +.br + +.EE + +.br + +.br + +.IP "\fBmode\fP: 0-7" 0 +The operational mode of a GPIO, normally INPUT or OUTPUT. + +.br + +.br + +.EX +PI_INPUT 0 +.br +PI_OUTPUT 1 +.br +PI_ALT0 4 +.br +PI_ALT1 5 +.br +PI_ALT2 6 +.br +PI_ALT3 7 +.br +PI_ALT4 3 +.br +PI_ALT5 2 +.br + +.EE + +.br + +.br + +.IP "\fBnumBytes\fP" 0 +The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. + +.br + +.br + +.IP "\fBnumPar\fP: 0-10" 0 +The number of parameters passed to a script. + +.br + +.br + +.IP "\fBnumPulses\fP" 0 +The number of pulses to be added to a waveform. + +.br + +.br + +.IP "\fBoffset\fP" 0 +The associated data starts this number of microseconds from the start of +the waveform. + +.br + +.br + +.IP "\fB*outBuf\fP" 0 +A buffer used to return data from a function. + +.br + +.br + +.IP "\fBoutLen\fP" 0 +The size in bytes of an output buffer. + +.br + +.br + +.IP "\fB*param\fP" 0 +An array of script parameters. + +.br + +.br + +.IP "\fB*portStr\fP" 0 +A string specifying the port address used by the Pi running +the pigpio daemon. It may be NULL in which case "8888" +is used unless overridden by the PIGPIO_PORT environment +variable. + +.br + +.br + +.IP "\fB*pth\fP" 0 +A thread identifier, returned by \fBstart_thread\fP. + +.br + +.br + +.br + +.br + +.IP "\fBpthread_t\fP" 0 +A thread identifier. + +.br + +.br + +.IP "\fBpud\fP: 0-2" 0 +The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. + +.EX +PI_PUD_OFF 0 +.br +PI_PUD_DOWN 1 +.br +PI_PUD_UP 2 +.br + +.EE + +.br + +.br + +.IP "\fBpulseLen\fP" 0 +1-100, the length of a trigger pulse in microseconds. + +.br + +.br + +.IP "\fB*pulses\fP" 0 +An array of pulses to be added to a waveform. + +.br + +.br + +.IP "\fBpulsewidth\fP: 0, 500-2500" 0 + +.EX +PI_SERVO_OFF 0 +.br +PI_MIN_SERVO_PULSEWIDTH 500 +.br +PI_MAX_SERVO_PULSEWIDTH 2500 +.br + +.EE + +.br + +.br + +.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 +The hardware PWM dutycycle. + +.br + +.br + +.EX +#define PI_HW_PWM_RANGE 1000000 +.br + +.EE + +.br + +.br + +.IP "\fBPWMfreq\fP: 1-125000000 (125M)" 0 +The hardware PWM frequency. + +.br + +.br + +.EX +#define PI_HW_PWM_MIN_FREQ 1 +.br +#define PI_HW_PWM_MAX_FREQ 125000000 +.br + +.EE + +.br + +.br + +.IP "\fBrange\fP: 25-40000" 0 +The permissible dutycycle values are 0-range. + +.EX +PI_MIN_DUTYCYCLE_RANGE 25 +.br +PI_MAX_DUTYCYCLE_RANGE 40000 +.br + +.EE + +.br + +.br + +.IP "\fB*retBuf\fP" 0 +A buffer to hold a number of bytes returned to a used customised function, + +.br + +.br + +.IP "\fBretMax\fP" 0 +The maximum number of bytes a user customised function should return. + +.br + +.br + +.br + +.br + +.IP "\fB*rxBuf\fP" 0 +A pointer to a buffer to receive data. + +.br + +.br + +.IP "\fBSCL\fP" 0 +The user GPIO to use for the clock when bit banging I2C. + +.br + +.br + +.IP "\fB*script\fP" 0 +A pointer to the text of a script. + +.br + +.br + +.IP "\fBscript_id\fP" 0 +An id of a stored script as returned by \fBstore_script\fP. + +.br + +.br + +.IP "\fBSDA\fP" 0 +The user GPIO to use for data when bit banging I2C. + +.br + +.br + +.IP "\fBseconds\fP" 0 +The number of seconds. + +.br + +.br + +.IP "\fBser_flags\fP" 0 +Flags which modify a serial open command. None are currently defined. + +.br + +.br + +.IP "\fB*ser_tty\fP" 0 +The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. + +.br + +.br + +.IP "\fBsize_t\fP" 0 +A standard type used to indicate the size of an object in bytes. + +.br + +.br + +.IP "\fBspi_channel\fP" 0 +A SPI channel, 0-2. + +.br + +.br + +.IP "\fBspi_flags\fP" 0 +See \fBspi_open\fP. + +.br + +.br + +.IP "\fBsteady\fP: 0-300000" 0 + +.br + +.br +The number of microseconds level changes must be stable for +before reporting the level changed (\fBset_glitch_filter\fP) or triggering +the active part of a noise filter (\fBset_noise_filter\fP). + +.br + +.br + +.IP "\fBstop_bits\fP: 2-8" 0 +The number of (half) stop bits to be used when adding serial data +to a waveform. + +.br + +.br + +.EX +#define PI_MIN_WAVE_HALFSTOPBITS 2 +.br +#define PI_MAX_WAVE_HALFSTOPBITS 8 +.br + +.EE + +.br + +.br + +.IP "\fB*str\fP" 0 + An array of characters. + +.br + +.br + +.IP "\fBthread_func\fP" 0 +A function of type gpioThreadFunc_t used as the main function of a +thread. + +.br + +.br + +.IP "\fBtimeout\fP" 0 +A GPIO watchdog timeout in milliseconds. + +.EX +PI_MIN_WDOG_TIMEOUT 0 +.br +PI_MAX_WDOG_TIMEOUT 60000 +.br + +.EE + +.br + +.br + +.IP "\fB*txBuf\fP" 0 +An array of bytes to transmit. + +.br + +.br + +.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 +A 32-bit unsigned value. + +.br + +.br + +.IP "\fBunsigned\fP" 0 +A whole number >= 0. + +.br + +.br + +.IP "\fBuser_gpio\fP" 0 +0-31, a Broadcom numbered GPIO. + +.br + +.br +See \fBgpio\fP. + +.br + +.br + +.IP "\fB*userdata\fP" 0 +A pointer to arbitrary user data. This may be used to identify the instance. + +.br + +.br + +.IP "\fBvoid\fP" 0 +Denoting no parameter is required + +.br + +.br + +.IP "\fBwave_add_*\fP" 0 +One of \fBwave_add_new\fP, \fBwave_add_generic\fP, \fBwave_add_serial\fP. + +.br + +.br + +.IP "\fBwave_id\fP" 0 +A number representing a waveform created by \fBwave_create\fP. + +.br + +.br + +.IP "\fBwave_send_*\fP" 0 +One of \fBwave_send_once\fP, \fBwave_send_repeat\fP. + +.br + +.br + +.IP "\fBwVal\fP: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)" 0 +A 16-bit word value. + +.br + +.br +.SH pigpiod_if Error Codes + +.EX + +.br +typedef enum +.br +{ +.br + pigif_bad_send = -2000, +.br + pigif_bad_recv = -2001, +.br + pigif_bad_getaddrinfo = -2002, +.br + pigif_bad_connect = -2003, +.br + pigif_bad_socket = -2004, +.br + pigif_bad_noib = -2005, +.br + pigif_duplicate_callback = -2006, +.br + pigif_bad_malloc = -2007, +.br + pigif_bad_callback = -2008, +.br + pigif_notify_failed = -2009, +.br + pigif_callback_not_found = -2010, +.br +} pigifError_t; +.br + +.br + +.EE + +.SH SEE ALSO + +pigpiod(1), pig2vcd(1), pigs(1), pigpio(3), pigpiod_if2(3) +.SH AUTHOR + +joan@abyz.me.uk diff --git a/DOC/MAN/pigpiod_if2.3 b/DOC/MAN/pigpiod_if2.3 new file mode 100644 index 0000000..b6924c6 --- /dev/null +++ b/DOC/MAN/pigpiod_if2.3 @@ -0,0 +1,8050 @@ + +." Process this file with +." groff -man -Tascii pigpiod_if2.3 +." +.TH pigpiod_if2 3 2012-2020 Linux "pigpio archive" +.SH NAME +pigpiod_if2 - A C library to interface to the pigpio daemon. + +.SH SYNOPSIS + +#include + + +gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt + + ./prog +.SH DESCRIPTION + + +.ad l + +.nh + +.br + +.br +pigpiod_if2 is a C library for the Raspberry which allows control +of the GPIO via the socket interface to the pigpio daemon. +.br + +.br + +.br +.SS Features +.br + +.br +o hardware timed PWM on any of GPIO 0-31 + +.br + +.br +o hardware timed servo pulses on any of GPIO 0-31 + +.br + +.br +o callbacks when any of GPIO 0-31 change state + +.br + +.br +o callbacks at timed intervals + +.br + +.br +o reading/writing all of the GPIO in a bank as one operation + +.br + +.br +o individually setting GPIO modes, reading and writing + +.br + +.br +o notifications when any of GPIO 0-31 change state + +.br + +.br +o the construction of output waveforms with microsecond timing + +.br + +.br +o rudimentary permission control over GPIO + +.br + +.br +o a simple interface to start and stop new threads + +.br + +.br +o I2C, SPI, and serial link wrappers + +.br + +.br +o creating and running scripts on the pigpio daemon + +.br + +.br +.SS GPIO +.br + +.br +ALL GPIO are identified by their Broadcom number. + +.br + +.br +.SS Notes +.br + +.br +The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. + +.br + +.br +.SS Usage +.br + +.br +Include in your source files. + +.br + +.br +Assuming your source is in prog.c use the following command to build + +.br + +.br + +.EX +gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt +.br + +.EE + +.br + +.br +to run make sure the pigpio daemon is running + +.br + +.br + +.EX +sudo pigpiod +.br + +.br + ./prog # sudo is not required to run programs linked to pigpiod_if2 +.br + +.EE + +.br + +.br +For examples see x_pigpiod_if2.c within the pigpio archive file. + +.br + +.br +.SS Notes +.br + +.br +All the functions which return an int return < 0 on error + +.br + +.br + +.SH OVERVIEW + +.br +.SS ESSENTIAL +.br + +.br +pigpio_start Connects to a pigpio daemon +.br +pigpio_stop Disconnects from a pigpio daemon +.br +.SS BASIC +.br + +.br +set_mode Set a GPIO mode +.br +get_mode Get a GPIO mode +.br + +.br +set_pull_up_down Set/clear GPIO pull up/down resistor +.br + +.br +gpio_read Read a GPIO +.br +gpio_write Write a GPIO +.br +.SS PWM (overrides servo commands on same GPIO) +.br + +.br +set_PWM_dutycycle Start/stop PWM pulses on a GPIO +.br +set_PWM_frequency Configure PWM frequency for a GPIO +.br +set_PWM_range Configure PWM range for a GPIO +.br + +.br +get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +.br +get_PWM_frequency Get configured PWM frequency for a GPIO +.br +get_PWM_range Get configured PWM range for a GPIO +.br + +.br +get_PWM_real_range Get underlying PWM range for a GPIO +.br +.SS Servo (overrides PWM commands on same GPIO) +.br + +.br +set_servo_pulsewidth Start/stop servo pulses on a GPIO +.br + +.br +get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO +.br +.SS INTERMEDIATE +.br + +.br +gpio_trigger Send a trigger pulse to a GPIO. +.br + +.br +set_watchdog Set a watchdog on a GPIO. +.br + +.br +read_bank_1 Read all GPIO in bank 1 +.br +read_bank_2 Read all GPIO in bank 2 +.br + +.br +clear_bank_1 Clear selected GPIO in bank 1 +.br +clear_bank_2 Clear selected GPIO in bank 2 +.br + +.br +set_bank_1 Set selected GPIO in bank 1 +.br +set_bank_2 Set selected GPIO in bank 2 +.br + +.br +callback Create GPIO level change callback +.br +callback_ex Create GPIO level change callback, extended +.br + +.br +callback_cancel Cancel a callback +.br + +.br +wait_for_edge Wait for GPIO level change +.br + +.br +start_thread Start a new thread +.br +stop_thread Stop a previously started thread +.br +.SS ADVANCED +.br + +.br +notify_open Request a notification handle +.br +notify_begin Start notifications for selected GPIO +.br +notify_pause Pause notifications +.br +notify_close Close a notification +.br + +.br +hardware_clock Start hardware clock on supported GPIO +.br + +.br +hardware_PWM Start hardware PWM on supported GPIO +.br + +.br +set_glitch_filter Set a glitch filter on a GPIO +.br +set_noise_filter Set a noise filter on a GPIO +.br + +.br +set_pad_strength Sets a pads drive strength +.br +get_pad_strength Gets a pads drive strength +.br + +.br +shell_ Executes a shell command +.br +.SS Custom +.br + +.br +custom_1 User custom function 1 +.br +custom_2 User custom function 2 +.br +.SS Events +.br + +.br +event_callback Sets a callback for an event +.br +event_callback_ex Sets a callback for an event, extended +.br + +.br +event_callback_cancel Cancel an event callback +.br + +.br +event_trigger Triggers an event +.br + +.br +wait_for_event Wait for an event +.br +.SS Scripts +.br + +.br +store_script Store a script +.br +run_script Run a stored script +.br +update_script Set a scripts parameters +.br +script_status Get script status and parameters +.br +stop_script Stop a running script +.br +delete_script Delete a stored script +.br +.SS I2C +.br + +.br +i2c_open Opens an I2C device +.br +i2c_close Closes an I2C device +.br + +.br +i2c_write_quick smbus write quick +.br + +.br +i2c_read_byte smbus read byte +.br +i2c_write_byte smbus write byte +.br + +.br +i2c_read_byte_data smbus read byte data +.br +i2c_write_byte_data smbus write byte data +.br + +.br +i2c_read_word_data smbus read word data +.br +i2c_write_word_data smbus write word data +.br + +.br +i2c_read_block_data smbus read block data +.br +i2c_write_block_data smbus write block data +.br + +.br +i2c_read_i2c_block_data smbus read I2C block data +.br +i2c_write_i2c_block_data smbus write I2C block data +.br + +.br +i2c_read_device Reads the raw I2C device +.br +i2c_write_device Writes the raw I2C device +.br + +.br +i2c_process_call smbus process call +.br +i2c_block_process_call smbus block process call +.br + +.br +i2c_zip Performs multiple I2C transactions +.br +.SS I2C BIT BANG +.br + +.br +bb_i2c_open Opens GPIO for bit banging I2C +.br +bb_i2c_close Closes GPIO for bit banging I2C +.br + +.br +bb_i2c_zip Performs bit banged I2C transactions +.br +.SS I2C/SPI SLAVE +.br + +.br +bsc_xfer I2C/SPI as slave transfer +.br +bsc_i2c I2C as slave transfer +.br +.SS SERIAL +.br + +.br +serial_open Opens a serial device +.br +serial_close Closes a serial device +.br + +.br +serial_read_byte Reads a byte from a serial device +.br +serial_write_byte Writes a byte to a serial device +.br + +.br +serial_read Reads bytes from a serial device +.br +serial_write Writes bytes to a serial device +.br + +.br +serial_data_available Returns number of bytes ready to be read +.br +.SS SERIAL BIT BANG (read only) +.br + +.br +bb_serial_read_open Opens a GPIO for bit bang serial reads +.br +bb_serial_read_close Closes a GPIO for bit bang serial reads +.br + +.br +bb_serial_invert Invert serial logic (1 invert, 0 normal) +.br + +.br +bb_serial_read Reads bit bang serial data from a GPIO +.br +.SS SPI +.br + +.br +spi_open Opens a SPI device +.br +spi_close Closes a SPI device +.br + +.br +spi_read Reads bytes from a SPI device +.br +spi_write Writes bytes to a SPI device +.br +spi_xfer Transfers bytes with a SPI device +.br +.SS SPI BIT BANG +.br + +.br +bb_spi_open Opens GPIO for bit banging SPI +.br +bb_spi_close Closes GPIO for bit banging SPI +.br + +.br +bb_spi_xfer Transfers bytes with bit banging SPI +.br +.SS FILES +.br + +.br +file_open Opens a file +.br +file_close Closes a file +.br + +.br +file_read Reads bytes from a file +.br +file_write Writes bytes to a file +.br + +.br +file_seek Seeks to a position within a file +.br + +.br +file_list List files which match a pattern +.br +.SS WAVES +.br + +.br +wave_clear Deletes all waveforms +.br + +.br +wave_add_new Starts a new waveform +.br +wave_add_generic Adds a series of pulses to the waveform +.br +wave_add_serial Adds serial data to the waveform +.br + +.br +wave_create Creates a waveform from added data +.br +wave_create_and_pad Creates a waveform of fixed size from added data +.br +wave_delete Deletes one or more waveforms +.br + +.br +wave_send_once Transmits a waveform once +.br +wave_send_repeat Transmits a waveform repeatedly +.br +wave_send_using_mode Transmits a waveform in the chosen mode +.br + +.br +wave_chain Transmits a chain of waveforms +.br + +.br +wave_tx_at Returns the current transmitting waveform +.br + +.br +wave_tx_busy Checks to see if the waveform has ended +.br + +.br +wave_tx_stop Aborts the current waveform +.br + +.br +wave_get_cbs Length in cbs of the current waveform +.br +wave_get_high_cbs Length of longest waveform so far +.br +wave_get_max_cbs Absolute maximum allowed cbs +.br + +.br +wave_get_micros Length in micros of the current waveform +.br +wave_get_high_micros Length of longest waveform so far +.br +wave_get_max_micros Absolute maximum allowed micros +.br + +.br +wave_get_pulses Length in pulses of the current waveform +.br +wave_get_high_pulses Length of longest waveform so far +.br +wave_get_max_pulses Absolute maximum allowed pulses +.br +.SS UTILITIES +.br + +.br +get_current_tick Get current tick (microseconds) +.br + +.br +get_hardware_revision Get hardware revision +.br +get_pigpio_version Get the pigpio version +.br +pigpiod_if_version Get the pigpiod_if2 version +.br + +.br +pigpio_error Get a text description of an error code. +.br + +.br +time_sleep Sleeps for a float number of seconds +.br +time_time Float number of seconds since the epoch +.br +.SH FUNCTIONS + +.IP "\fBdouble time_time(void)\fP" +.IP "" 4 +Return the current time in seconds since the Epoch. + +.IP "\fBvoid time_sleep(double seconds)\fP" +.IP "" 4 +Delay execution for a given number of seconds. + +.br + +.br + +.EX +seconds: the number of seconds to delay. +.br + +.EE + +.IP "\fBchar *pigpio_error(int errnum)\fP" +.IP "" 4 +Return a text description for an error code. + +.br + +.br + +.EX +errnum: the error code. +.br + +.EE + +.IP "\fBunsigned pigpiod_if_version(void)\fP" +.IP "" 4 +Return the pigpiod_if2 version. + +.IP "\fBpthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)\fP" +.IP "" 4 +Starts a new thread of execution with thread_func as the main routine. + +.br + +.br + +.EX +thread_func: the main function for the new thread. +.br + userdata: a pointer to an arbitrary argument. +.br + +.EE + +.br + +.br +Returns a pointer to pthread_t if OK, otherwise NULL. + +.br + +.br +The function is passed the single argument userdata. + +.br + +.br +The thread can be cancelled by passing the pointer to pthread_t to +\fBstop_thread\fP. + +.IP "\fBvoid stop_thread(pthread_t *pth)\fP" +.IP "" 4 +Cancels the thread pointed at by pth. + +.br + +.br + +.EX +pth: the thread to be stopped. +.br + +.EE + +.br + +.br +No value is returned. + +.br + +.br +The thread to be stopped should have been started with \fBstart_thread\fP. + +.IP "\fBint pigpio_start(char *addrStr, char *portStr)\fP" +.IP "" 4 +Connect to the pigpio daemon. Reserving command and +notification streams. + +.br + +.br + +.EX +addrStr: specifies the host or IP address of the Pi running the +.br + pigpio daemon. It may be NULL in which case localhost +.br + is used unless overridden by the PIGPIO_ADDR environment +.br + variable. +.br + +.br +portStr: specifies the port address used by the Pi running the +.br + pigpio daemon. It may be NULL in which case "8888" +.br + is used unless overridden by the PIGPIO_PORT environment +.br + variable. +.br + +.EE + +.br + +.br +Returns an integer value greater than or equal to zero if OK. + +.br + +.br +This value is passed to the GPIO routines to specify the Pi +to be operated on. + +.IP "\fBvoid pigpio_stop(int pi)\fP" +.IP "" 4 +Terminates the connection to a pigpio daemon and releases +resources used by the library. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint set_mode(int pi, unsigned gpio, unsigned mode)\fP" +.IP "" 4 +Set the GPIO mode. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +gpio: 0-53. +.br +mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, +.br + PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, +or PI_NOT_PERMITTED. + +.IP "\fBint get_mode(int pi, unsigned gpio)\fP" +.IP "" 4 +Get the GPIO mode. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +gpio: 0-53. +.br + +.EE + +.br + +.br +Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. + +.IP "\fBint set_pull_up_down(int pi, unsigned gpio, unsigned pud)\fP" +.IP "" 4 +Set or clear the GPIO pull-up/down resistor. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +gpio: 0-53. +.br + pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, +or PI_NOT_PERMITTED. + +.IP "\fBint gpio_read(int pi, unsigned gpio)\fP" +.IP "" 4 +Read the GPIO level. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +gpio:0-53. +.br + +.EE + +.br + +.br +Returns the GPIO level if OK, otherwise PI_BAD_GPIO. + +.IP "\fBint gpio_write(int pi, unsigned gpio, unsigned level)\fP" +.IP "" 4 +Write the GPIO level. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + gpio: 0-53. +.br +level: 0, 1. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, +or PI_NOT_PERMITTED. + +.br + +.br +Notes + +.br + +.br +If PWM or servo pulses are active on the GPIO they are switched off. + +.IP "\fBint set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)\fP" +.IP "" 4 +Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br +dutycycle: 0-range (range defaults to 255). +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, +or PI_NOT_PERMITTED. +Notes + +.br + +.br +The \fBset_PWM_range\fP function may be used to change the +default range of 255. + +.IP "\fBint get_PWM_dutycycle(int pi, unsigned user_gpio)\fP" +.IP "" 4 +Return the PWM dutycycle in use on a GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. + +.br + +.br +For normal PWM the dutycycle will be out of the defined range +for the GPIO (see \fBget_PWM_range\fP). + +.br + +.br +If a hardware clock is active on the GPIO the reported dutycycle +will be 500000 (500k) out of 1000000 (1M). + +.br + +.br +If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). + +.IP "\fBint set_PWM_range(int pi, unsigned user_gpio, unsigned range)\fP" +.IP "" 4 +Set the range of PWM values to be used on the GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + range: 25-40000. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, +or PI_NOT_PERMITTED. + +.br + +.br +Notes + +.br + +.br +If PWM is currently active on the GPIO its dutycycle will be +scaled to reflect the new range. + +.br + +.br +The real range, the number of steps between fully off and fully on +for each of the 18 available GPIO frequencies is + +.br + +.br + +.EX + 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), +.br + 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12), +.br +2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18) +.br + +.EE + +.br + +.br +The real value set by set_PWM_range is (dutycycle * real range) / range. + +.IP "\fBint get_PWM_range(int pi, unsigned user_gpio)\fP" +.IP "" 4 +Get the range of PWM values being used on the GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + +.EE + +.br + +.br +Returns the dutycycle range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. + +.br + +.br +If a hardware clock or hardware PWM is active on the GPIO the +reported range will be 1000000 (1M). + +.IP "\fBint get_PWM_real_range(int pi, unsigned user_gpio)\fP" +.IP "" 4 +Get the real underlying range of PWM values being used on the GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + +.EE + +.br + +.br +Returns the real range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. + +.br + +.br +If a hardware clock is active on the GPIO the reported +real range will be 1000000 (1M). + +.br + +.br +If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. + +.br + +.br + +.IP "\fBint set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)\fP" +.IP "" 4 +Set the frequency (in Hz) of the PWM to be used on the GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br +frequency: >=0 (Hz). +.br + +.EE + +.br + +.br +Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PERMITTED. + +.br + +.br +If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. + +.br + +.br +Each GPIO can be independently set to one of 18 different +PWM frequencies. + +.br + +.br +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. + +.br + +.br +The frequencies for each sample rate are: + +.br + +.br + +.EX + Hertz +.br + +.br + 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 +.br + 1250 1000 800 500 400 250 200 100 50 +.br + +.br + 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 +.br + 625 500 400 250 200 125 100 50 25 +.br + +.br + 4: 10000 5000 2500 2000 1250 1000 625 500 400 +.br + 313 250 200 125 100 63 50 25 13 +.br +sample +.br + rate +.br + (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 +.br + 250 200 160 100 80 50 40 20 10 +.br + +.br + 8: 5000 2500 1250 1000 625 500 313 250 200 +.br + 156 125 100 63 50 31 25 13 6 +.br + +.br + 10: 4000 2000 1000 800 500 400 250 200 160 +.br + 125 100 80 50 40 25 20 10 5 +.br + +.EE + +.IP "\fBint get_PWM_frequency(int pi, unsigned user_gpio)\fP" +.IP "" 4 +Get the frequency of PWM being used on the GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + +.EE + +.br + +.br +For normal PWM the frequency will be that defined for the GPIO by +\fBset_PWM_frequency\fP. + +.br + +.br +If a hardware clock is active on the GPIO the reported frequency +will be that set by \fBhardware_clock\fP. + +.br + +.br +If hardware PWM is active on the GPIO the reported frequency +will be that set by \fBhardware_PWM\fP. + +.br + +.br +Returns the frequency (in hertz) used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. + +.IP "\fBint set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)\fP" +.IP "" 4 +Start (500-2500) or stop (0) servo pulses on the GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + user_gpio: 0-31. +.br +pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise). +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or +PI_NOT_PERMITTED. + +.br + +.br +The selected pulsewidth will continue to be transmitted until +changed by a subsequent call to set_servo_pulsewidth. + +.br + +.br +The pulsewidths supported by servos varies and should probably be +determined by experiment. A value of 1500 should always be safe and +represents the mid-point of rotation. + +.br + +.br +You can DAMAGE a servo if you command it to move beyond its limits. + +.br + +.br +OTHER UPDATE RATES: + +.br + +.br +This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. + +.br + +.br + +.EX +Update Rate (Hz) 50 100 200 400 500 +.br +1E6/Hz 20000 10000 5000 2500 2000 +.br + +.EE + +.br + +.br +Firstly set the desired PWM frequency using \fBset_PWM_frequency\fP. + +.br + +.br +Then set the PWM range using \fBset_PWM_range\fP to 1E6/Hz. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. + +.br + +.br +E.g. If you want to update a servo connected to GPIO 25 at 400Hz + +.br + +.br + +.EX +set_PWM_frequency(25, 400); +.br +set_PWM_range(25, 2500); +.br + +.EE + +.br + +.br +Thereafter use the \fBset_PWM_dutycycle\fP function to move the servo, +e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse. +.br + +.IP "\fBint get_servo_pulsewidth(int pi, unsigned user_gpio)\fP" +.IP "" 4 +Return the servo pulsewidth in use on a GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. + +.IP "\fBint notify_open(int pi)\fP" +.IP "" 4 +Get a free notification handle. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. + +.br + +.br +A notification is a method for being notified of GPIO state +changes via a pipe. + +.br + +.br +Pipes are only accessible from the local machine so this function +serves no purpose if you are using the library from a remote machine. +The in-built (socket) notifications provided by \fBcallback\fP +should be used instead. + +.br + +.br +Notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). +E.g. if the function returns 15 then the notifications must be +read from /dev/pigpio15. + +.IP "\fBint notify_begin(int pi, unsigned handle, uint32_t bits)\fP" +.IP "" 4 +Start notifications on a previously opened handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: 0-31 (as returned by \fBnotify_open\fP) +.br + bits: a mask indicating the GPIO to be notified. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +The notification sends state changes for each GPIO whose +corresponding bit in bits is set. + +.br + +.br +Each notification occupies 12 bytes in the fifo as follows: + +.br + +.br + +.EX +typedef struct +.br +{ +.br + uint16_t seqno; +.br + uint16_t flags; +.br + uint32_t tick; +.br + uint32_t level; +.br +} gpioReport_t; +.br + +.EE + +.br + +.br +seqno: starts at 0 each time the handle is opened and then increments +by one for each report. + +.br + +.br +flags: three flags are defined, PI_NTFY_FLAGS_WDOG, +PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. + +.br + +.br +If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. + +.br + +.br +If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. + +.br + +.br +If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags +indicate an event which has been triggered. + +.br + +.br +tick: the number of microseconds since system boot. It wraps around +after 1h12m. + +.br + +.br +level: indicates the level of each GPIO. If bit 1<=0 (as returned by \fBpigpio_start\fP). +.br +handle: 0-31 (as returned by \fBnotify_open\fP) +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +Notifications for the handle are suspended until +\fBnotify_begin\fP is called again. + +.IP "\fBint notify_close(int pi, unsigned handle)\fP" +.IP "" 4 +Stop notifications on a previously opened handle and +release the handle for reuse. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: 0-31 (as returned by \fBnotify_open\fP) +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint set_watchdog(int pi, unsigned user_gpio, unsigned timeout)\fP" +.IP "" 4 +Sets a watchdog for a GPIO. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + timeout: 0-60000. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO +or PI_BAD_WDOG_TIMEOUT. + +.br + +.br +The watchdog is nominally in milliseconds. + +.br + +.br +Only one watchdog may be registered per GPIO. + +.br + +.br +The watchdog may be cancelled by setting timeout to 0. + +.br + +.br +Once a watchdog has been started callbacks for the GPIO will be +triggered every timeout interval after the last GPIO activity. + +.br + +.br +The callback will receive the special level PI_TIMEOUT. + +.IP "\fBint set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)\fP" +.IP "" 4 +Sets a glitch filter on a GPIO. + +.br + +.br +Level changes on the GPIO are not reported unless the level +has been stable for at least \fBsteady\fP microseconds. The +level is then reported. Level changes of less than +\fBsteady\fP microseconds are ignored. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31 +.br + steady: 0-300000 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. + +.br + +.br +This filter affects the GPIO samples returned to callbacks set up +with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP. + +.br + +.br +It does not affect levels read by \fBgpio_read\fP, +\fBread_bank_1\fP, or \fBread_bank_2\fP. + +.br + +.br +Each (stable) edge will be timestamped \fBsteady\fP microseconds +after it was first detected. + +.IP "\fBint set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)\fP" +.IP "" 4 +Sets a noise filter on a GPIO. + +.br + +.br +Level changes on the GPIO are ignored until a level which has +been stable for \fBsteady\fP microseconds is detected. Level changes +on the GPIO are then reported for \fBactive\fP microseconds after +which the process repeats. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31 +.br + steady: 0-300000 +.br + active: 0-1000000 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. + +.br + +.br +This filter affects the GPIO samples returned to callbacks set up +with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP. + +.br + +.br +It does not affect levels read by \fBgpio_read\fP, +\fBread_bank_1\fP, or \fBread_bank_2\fP. + +.br + +.br +Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. + +.IP "\fBuint32_t read_bank_1(int pi)\fP" +.IP "" 4 +Read the levels of the bank 1 GPIO (GPIO 0-31). + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +The returned 32 bit integer has a bit set if the corresponding +GPIO is logic 1. GPIO n has bit value (1<=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +The returned 32 bit integer has a bit set if the corresponding +GPIO is logic 1. GPIO n has bit value (1<<(n-32)). + +.IP "\fBint clear_bank_1(int pi, uint32_t bits)\fP" +.IP "" 4 +Clears GPIO 0-31 if the corresponding bit in bits is set. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +bits: a bit mask with 1 set if the corresponding GPIO is +.br + to be cleared. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_SOME_PERMITTED. + +.br + +.br +A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. + +.IP "\fBint clear_bank_2(int pi, uint32_t bits)\fP" +.IP "" 4 +Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +bits: a bit mask with 1 set if the corresponding GPIO is +.br + to be cleared. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_SOME_PERMITTED. + +.br + +.br +A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. + +.IP "\fBint set_bank_1(int pi, uint32_t bits)\fP" +.IP "" 4 +Sets GPIO 0-31 if the corresponding bit in bits is set. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +bits: a bit mask with 1 set if the corresponding GPIO is +.br + to be set. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_SOME_PERMITTED. + +.br + +.br +A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. + +.IP "\fBint set_bank_2(int pi, uint32_t bits)\fP" +.IP "" 4 +Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +bits: a bit mask with 1 set if the corresponding GPIO is +.br + to be set. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_SOME_PERMITTED. + +.br + +.br +A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. + +.IP "\fBint hardware_clock(int pi, unsigned gpio, unsigned clkfreq)\fP" +.IP "" 4 +Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + gpio: see description +.br +frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711) +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. + +.br + +.br +The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. + +.br + +.br +The GPIO must be one of the following. + +.br + +.br + +.EX +4 clock 0 All models +.br +5 clock 1 All models but A and B (reserved for system use) +.br +6 clock 2 All models but A and B +.br +20 clock 0 All models but A and B +.br +21 clock 1 All models but A and Rev.2 B (reserved for system use) +.br + +.br +32 clock 0 Compute module only +.br +34 clock 0 Compute module only +.br +42 clock 1 Compute module only (reserved for system use) +.br +43 clock 2 Compute module only +.br +44 clock 1 Compute module only (reserved for system use) +.br + +.EE + +.br + +.br +Access to clock 1 is protected by a password as its use will likely +crash the Pi. The password is given by or'ing 0x5A000000 with the +GPIO number. + +.IP "\fBint hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)\fP" +.IP "" 4 +Starts hardware PWM on a GPIO at the specified frequency and dutycycle. +Frequencies above 30MHz are unlikely to work. + +.br + +.br +NOTE: Any waveform started by \fBwave_send_*\fP or \fBwave_chain\fP +will be cancelled. + +.br + +.br +This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + gpio: see descripton +.br +PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) +.br +PWMduty: 0 (off) to 1000000 (1M)(fully on) +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, +or PI_HPWM_ILLEGAL. + +.br + +.br +The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. + +.br + +.br +The GPIO must be one of the following. + +.br + +.br + +.EX +12 PWM channel 0 All models but A and B +.br +13 PWM channel 1 All models but A and B +.br +18 PWM channel 0 All models +.br +19 PWM channel 1 All models but A and B +.br + +.br +40 PWM channel 0 Compute module only +.br +41 PWM channel 1 Compute module only +.br +45 PWM channel 1 Compute module only +.br +52 PWM channel 0 Compute module only +.br +53 PWM channel 1 Compute module only +.br + +.EE + +.br + +.br +The actual number of steps beween off and fully on is the +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). + +.br + +.br +The actual frequency set is 250M/steps (375M/steps for the BCM2711). + +.br + +.br +There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. PWMduty is +automatically scaled to take this into account. + +.IP "\fBuint32_t get_current_tick(int pi)\fP" +.IP "" 4 +Gets the current system tick. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +Tick is the number of microseconds since system boot. + +.br + +.br +As tick is an unsigned 32 bit quantity it wraps around after +2**32 microseconds, which is approximately 1 hour 12 minutes. + +.br + +.br + +.IP "\fBuint32_t get_hardware_revision(int pi)\fP" +.IP "" 4 +Get the Pi's hardware revision number. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +The hardware revision is the last few characters on the Revision line +of /proc/cpuinfo. + +.br + +.br +If the hardware revision can not be found or is not a valid +hexadecimal number the function returns 0. + +.br + +.br +The revision number can be used to determine the assignment of GPIO +to pins (see \fBgpio\fP). + +.br + +.br +There are at least three types of board. + +.br + +.br +Type 1 boards have hardware revision numbers of 2 and 3. + +.br + +.br +Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. + +.br + +.br +Type 3 boards have hardware revision numbers of 16 or greater. + +.IP "\fBuint32_t get_pigpio_version(int pi)\fP" +.IP "" 4 +Returns the pigpio version. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_clear(int pi)\fP" +.IP "" 4 +This function clears all waveforms and any data added by calls to the +\fBwave_add_*\fP functions. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.IP "\fBint wave_add_new(int pi)\fP" +.IP "" 4 +This function starts a new empty waveform. You wouldn't normally need +to call this function as it is automatically called after a waveform is +created with the \fBwave_create\fP function. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.IP "\fBint wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)\fP" +.IP "" 4 +This function adds a number of pulses to the current waveform. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +numPulses: the number of pulses. +.br + pulses: an array of pulses. +.br + +.EE + +.br + +.br +Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. + +.br + +.br +The pulses are interleaved in time order within the existing waveform +(if any). + +.br + +.br +Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. + +.br + +.br +If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist solely of a delay. + +.IP "\fBint wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)\fP" +.IP "" 4 +This function adds a waveform representing serial data to the +existing waveform (if any). The serial data starts offset +microseconds from the start of the waveform. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + baud: 50-1000000 +.br +data_bits: number of data bits (1-32) +.br +stop_bits: number of stop half bits (2-8) +.br + offset: >=0 +.br + numBytes: >=1 +.br + str: an array of chars. +.br + +.EE + +.br + +.br +Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. + +.br + +.br +NOTES: + +.br + +.br +The serial data is formatted as one start bit, \fBdata_bits\fP data bits, +and \fBstop_bits\fP/2 stop bits. + +.br + +.br +It is legal to add serial data streams with different baud rates to +the same waveform. + +.br + +.br +\fBnumBytes\fP is the number of bytes of data in str. + +.br + +.br +The bytes required for each character depend upon \fBdata_bits\fP. + +.br + +.br +For \fBdata_bits\fP 1-8 there will be one byte per character. +.br +For \fBdata_bits\fP 9-16 there will be two bytes per character. +.br +For \fBdata_bits\fP 17-32 there will be four bytes per character. + +.IP "\fBint wave_create(int pi)\fP" +.IP "" 4 +This function creates a waveform from the data provided by the prior +calls to the \fBwave_add_*\fP functions. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +The data provided by the \fBwave_add_*\fP functions is consumed by this +function. + +.br + +.br +As many waveforms may be created as there is space available. The +wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. + +.br + +.br +Normal usage would be + +.br + +.br +Step 1. \fBwave_clear\fP to clear all waveforms and added data. + +.br + +.br +Step 2. \fBwave_add_*\fP calls to supply the waveform data. + +.br + +.br +Step 3. \fBwave_create\fP to create the waveform and get a unique id + +.br + +.br +Repeat steps 2 and 3 as needed. + +.br + +.br +Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. + +.br + +.br +A waveform comprises one or more pulses. Each pulse consists of a +\fBgpioPulse_t\fP structure. + +.br + +.br + +.EX +typedef struct +.br +{ +.br + uint32_t gpioOn; +.br + uint32_t gpioOff; +.br + uint32_t usDelay; +.br +} gpioPulse_t; +.br + +.EE + +.br + +.br +The fields specify + +.br + +.br +1) the GPIO to be switched on at the start of the pulse. +.br +2) the GPIO to be switched off at the start of the pulse. +.br +3) the delay in microseconds before the next pulse. +.br + +.br + +.br +Any or all the fields can be zero. It doesn't make any sense to +set all the fields to zero (the pulse will be ignored). + +.br + +.br +When a waveform is started each pulse is executed in order with the +specified delay between the pulse and the next. + +.br + +.br +Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. + +.IP "\fBint wave_create_and_pad(int pi, int percent)\fP" +.IP "" 4 +This function creates a waveform like wave_create but pads the consumed +resources. Where percent gives the percentage of the resources to use (in terms +of the theoretical maximum, not the current amount free). This allows the reuse +.br +of deleted waves while a transmission is active. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +The data provided by the \fBwave_add_*\fP functions are consumed by this +function. + +.br + +.br +As many waveforms may be created as there is space available. The +wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. + +.br + +.br +A usage would be the creation of two waves where one is filled while the other +is beeing transmitted. Each wave is assigned 50% of the available resources. +This buffer structure allows the transmission of infinite wave sequences. + +.br + +.br +Normal usage: + +.br + +.br +Step 1. \fBwave_clear\fP to clear all waveforms and added data. + +.br + +.br +Step 2. \fBwave_add_*\fP calls to supply the waveform data. + +.br + +.br +Step 3. \fBwave_create_and_pad\fP to create a waveform of uniform size. + +.br + +.br +Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. + +.br + +.br +Repeat steps 2-4 as needed. + +.br + +.br +Step 5. Any wave id can now be deleted and another wave of the same size + can be created in its place. + +.br + +.br +Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. + +.IP "\fBint wave_delete(int pi, unsigned wave_id)\fP" +.IP "" 4 +This function deletes the waveform with id wave_id. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +wave_id: >=0, as returned by \fBwave_create\fP. +.br + +.EE + +.br + +.br +Wave ids are allocated in order, 0, 1, 2, etc. + +.br + +.br +The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. + +.br + +.br +- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. + +.br + +.br +- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_WAVE_ID. + +.IP "\fBint wave_send_once(int pi, unsigned wave_id)\fP" +.IP "" 4 +This function transmits the waveform with id wave_id. The waveform +is sent once. + +.br + +.br +NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +wave_id: >=0, as returned by \fBwave_create\fP. +.br + +.EE + +.br + +.br +Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. + +.IP "\fBint wave_send_repeat(int pi, unsigned wave_id)\fP" +.IP "" 4 +This function transmits the waveform with id wave_id. The waveform +cycles until cancelled (either by the sending of a new waveform or +by \fBwave_tx_stop\fP). + +.br + +.br +NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +wave_id: >=0, as returned by \fBwave_create\fP. +.br + +.EE + +.br + +.br +Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. + +.IP "\fBint wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)\fP" +.IP "" 4 +Transmits the waveform with id wave_id using mode mode. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +wave_id: >=0, as returned by \fBwave_create\fP. +.br + mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT, +.br + PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC. +.br + +.EE + +.br + +.br +PI_WAVE_MODE_ONE_SHOT: same as \fBwave_send_once\fP. + +.br + +.br +PI_WAVE_MODE_REPEAT same as \fBwave_send_repeat\fP. + +.br + +.br +PI_WAVE_MODE_ONE_SHOT_SYNC same as \fBwave_send_once\fP but tries +to sync with the previous waveform. + +.br + +.br +PI_WAVE_MODE_REPEAT_SYNC same as \fBwave_send_repeat\fP but tries +to sync with the previous waveform. + +.br + +.br +WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. + +.br + +.br +NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. + +.br + +.br +Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. + +.IP "\fBint wave_chain(int pi, char *buf, unsigned bufSize)\fP" +.IP "" 4 +This function transmits a chain of waveforms. + +.br + +.br +NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. + +.br + +.br +The waves to be transmitted are specified by the contents of buf +which contains an ordered list of \fBwave_id\fPs and optional command +codes and related data. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + buf: pointer to the wave_ids and optional command codes +.br +bufSize: the number of bytes in buf +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. + +.br + +.br +Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. + +.br + +.br +A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. + +.br + +.br +Delays between waves may be added with the delay command. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +Loop Start 255 0 Identify start of a wave block +.br +Loop Repeat 255 1 x y loop x + y*256 times +.br +Delay 255 2 x y delay x + y*256 microseconds +.br +Loop Forever 255 3 loop forever +.br + +.br + +.br +If present Loop Forever must be the last entry in the chain. + +.br + +.br +The code is currently dimensioned to support a chain with roughly +600 entries and 20 loop counters. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +#define WAVES 5 +.br +#define GPIO 4 +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int i, pi, wid[WAVES]; +.br + +.br + pi = pigpio_start(0, 0); +.br + if (pi<0) return -1; +.br + +.br + set_mode(pi, GPIO, PI_OUTPUT); +.br + +.br + for (i=0; i=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +Returns the waveform id or one of the following special values: + +.br + +.br +PI_WAVE_NOT_FOUND (9998) - transmitted wave not found. +.br +PI_NO_TX_WAVE (9999) - no wave being transmitted. + +.IP "\fBint wave_tx_busy(int pi)\fP" +.IP "" 4 +This function checks to see if a waveform is currently being +transmitted. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +Returns 1 if a waveform is currently being transmitted, otherwise 0. + +.IP "\fBint wave_tx_stop(int pi)\fP" +.IP "" 4 +This function stops the transmission of the current waveform. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.br + +.br +Returns 0 if OK. + +.br + +.br +This function is intended to stop a waveform started with the repeat mode. + +.IP "\fBint wave_get_micros(int pi)\fP" +.IP "" 4 +This function returns the length in microseconds of the current +waveform. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_get_high_micros(int pi)\fP" +.IP "" 4 +This function returns the length in microseconds of the longest waveform +created since the pigpio daemon was started. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_get_max_micros(int pi)\fP" +.IP "" 4 +This function returns the maximum possible size of a waveform in +.br +microseconds. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_get_pulses(int pi)\fP" +.IP "" 4 +This function returns the length in pulses of the current waveform. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_get_high_pulses(int pi)\fP" +.IP "" 4 +This function returns the length in pulses of the longest waveform +created since the pigpio daemon was started. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_get_max_pulses(int pi)\fP" +.IP "" 4 +This function returns the maximum possible size of a waveform in pulses. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_get_cbs(int pi)\fP" +.IP "" 4 +This function returns the length in DMA control blocks of the current +waveform. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_get_high_cbs(int pi)\fP" +.IP "" 4 +This function returns the length in DMA control blocks of the longest +waveform created since the pigpio daemon was started. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint wave_get_max_cbs(int pi)\fP" +.IP "" 4 +This function returns the maximum possible size of a waveform in DMA +control blocks. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br + +.EE + +.IP "\fBint gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)\fP" +.IP "" 4 +This function sends a trigger pulse to a GPIO. The GPIO is set to +level for pulseLen microseconds and then reset to not level. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + pulseLen: 1-100. +.br + level: 0,1. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, +PI_BAD_PULSELEN, or PI_NOT_PERMITTED. + +.IP "\fBint store_script(int pi, char *script)\fP" +.IP "" 4 +This function stores a script for later execution. + +.br + +.br +See \fBhttp://abyz.me.uk/rpi/pigpio/pigs.html#Scripts\fP for details. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +script: the text of the script. +.br + +.EE + +.br + +.br +The function returns a script id if the script is valid, +otherwise PI_BAD_SCRIPT. + +.IP "\fBint run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)\fP" +.IP "" 4 +This function runs a stored script. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +script_id: >=0, as returned by \fBstore_script\fP. +.br + numPar: 0-10, the number of parameters. +.br + param: an array of parameters. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM + +.br + +.br +param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. + +.IP "\fBint update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)\fP" +.IP "" 4 +This function sets the parameters of a script. The script may or +may not be running. The first numPar parameters of the script are +overwritten with the new values. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +script_id: >=0, as returned by \fBstore_script\fP. +.br + numPar: 0-10, the number of parameters. +.br + param: an array of parameters. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. + +.br + +.br +param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. + +.IP "\fBint script_status(int pi, unsigned script_id, uint32_t *param)\fP" +.IP "" 4 +This function returns the run status of a stored script as well +as the current values of parameters 0 to 9. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +script_id: >=0, as returned by \fBstore_script\fP. +.br + param: an array to hold the returned 10 parameters. +.br + +.EE + +.br + +.br +The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. + +.br + +.br +The run status may be + +.br + +.br + +.EX +PI_SCRIPT_INITING +.br +PI_SCRIPT_HALTED +.br +PI_SCRIPT_RUNNING +.br +PI_SCRIPT_WAITING +.br +PI_SCRIPT_FAILED +.br + +.EE + +.br + +.br +The current value of script parameters 0 to 9 are returned in param. + +.IP "\fBint stop_script(int pi, unsigned script_id)\fP" +.IP "" 4 +This function stops a running script. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +script_id: >=0, as returned by \fBstore_script\fP. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. + +.IP "\fBint delete_script(int pi, unsigned script_id)\fP" +.IP "" 4 +This function deletes a stored script. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +script_id: >=0, as returned by \fBstore_script\fP. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. + +.IP "\fBint bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)\fP" +.IP "" 4 +This function opens a GPIO for bit bang reading of serial data. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + baud: 50-250000 +.br +data_bits: 1-32 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, +or PI_GPIO_IN_USE. + +.br + +.br +The serial data is returned in a cyclic buffer and is read using +bb_serial_read. + +.br + +.br +It is the caller's responsibility to read data from the cyclic buffer +in a timely fashion. + +.IP "\fBint bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)\fP" +.IP "" 4 +This function copies up to bufSize bytes of data read from the +bit bang serial cyclic buffer to the buffer starting at buf. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. +.br + buf: an array to receive the read bytes. +.br + bufSize: >=0 +.br + +.EE + +.br + +.br +Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. + +.br + +.br +The bytes returned for each character depend upon the number of +data bits \fBdata_bits\fP specified in the \fBbb_serial_read_open\fP command. + +.br + +.br +For \fBdata_bits\fP 1-8 there will be one byte per character. +.br +For \fBdata_bits\fP 9-16 there will be two bytes per character. +.br +For \fBdata_bits\fP 17-32 there will be four bytes per character. + +.IP "\fBint bb_serial_read_close(int pi, unsigned user_gpio)\fP" +.IP "" 4 +This function closes a GPIO for bit bang reading of serial data. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. + +.IP "\fBint bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)\fP" +.IP "" 4 +This function inverts serial logic for big bang serial reads. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. +.br + invert: 0-1, 1 invert, 0 normal. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. + +.IP "\fBint i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)\fP" +.IP "" 4 +This returns a handle for the device at address i2c_addr on bus i2c_bus. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + i2c_bus: >=0. +.br + i2c_addr: 0-0x7F. +.br +i2c_flags: 0. +.br + +.EE + +.br + +.br +No flags are currently defined. This parameter should be set to zero. + +.br + +.br +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + +.br + +.br +The GPIO used are given in the following table. + +.br + +.br + SDA SCL +.br +I2C 0 0 1 +.br +I2C 1 2 3 +.br + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. + +.br + +.br +For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. + +.br + +.br + +.EX +S (1 bit) : Start bit +.br +P (1 bit) : Stop bit +.br +Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. +.br +A, NA (1 bit) : Accept and not accept bit. +.br +.br +.br +Addr (7 bits): I2C 7 bit address. +.br +i2c_reg (8 bits): A byte which often selects a register. +.br +Data (8 bits): A data byte. +.br +Count (8 bits): A byte defining the length of a block operation. +.br + +.br +[..]: Data sent by the device. +.br + +.EE + +.IP "\fBint i2c_close(int pi, unsigned handle)\fP" +.IP "" 4 +This closes the I2C device associated with the handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint i2c_write_quick(int pi, unsigned handle, unsigned bit)\fP" +.IP "" 4 +This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + bit: 0-1, the value to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Quick command. SMBus 2.0 5.5.1 + +.EX +S Addr bit [A] P +.br + +.EE + +.IP "\fBint i2c_write_byte(int pi, unsigned handle, unsigned bVal)\fP" +.IP "" 4 +This sends a single byte to the device associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + bVal: 0-0xFF, the value to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Send byte. SMBus 2.0 5.5.2 + +.EX +S Addr Wr [A] bVal [A] P +.br + +.EE + +.IP "\fBint i2c_read_byte(int pi, unsigned handle)\fP" +.IP "" 4 +This reads a single byte from the device associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + +.EE + +.br + +.br +Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. + +.br + +.br +Receive byte. SMBus 2.0 5.5.3 + +.EX +S Addr Rd [A] [Data] NA P +.br + +.EE + +.IP "\fBint i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)\fP" +.IP "" 4 +This writes a single byte to the specified register of the device +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write. +.br + bVal: 0-0xFF, the value to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Write byte. SMBus 2.0 5.5.4 + +.EX +S Addr Wr [A] i2c_reg [A] bVal [A] P +.br + +.EE + +.IP "\fBint i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" +.IP "" 4 +This writes a single 16 bit word to the specified register of the device +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write. +.br + wVal: 0-0xFFFF, the value to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Write word. SMBus 2.0 5.5.4 + +.EX +S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P +.br + +.EE + +.IP "\fBint i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)\fP" +.IP "" 4 +This reads a single byte from the specified register of the device +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to read. +.br + +.EE + +.br + +.br +Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Read byte. SMBus 2.0 5.5.5 + +.EX +S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P +.br + +.EE + +.IP "\fBint i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)\fP" +.IP "" 4 +This reads a single 16 bit word from the specified register of the device +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to read. +.br + +.EE + +.br + +.br +Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Read word. SMBus 2.0 5.5.5 + +.EX +S Addr Wr [A] i2c_reg [A] +.br + S Addr Rd [A] [DataLow] A [DataHigh] NA P +.br + +.EE + +.IP "\fBint i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" +.IP "" 4 +This writes 16 bits of data to the specified register of the device +associated with handle and and reads 16 bits of data in return. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write/read. +.br + wVal: 0-0xFFFF, the value to write. +.br + +.EE + +.br + +.br +Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Process call. SMBus 2.0 5.5.6 + +.EX +S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A] +.br + S Addr Rd [A] [DataLow] A [DataHigh] NA P +.br + +.EE + +.IP "\fBint i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes up to 32 bytes to the specified register of the device +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write. +.br + buf: an array with the data to send. +.br + count: 1-32, the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br +Block write. SMBus 2.0 5.5.7 + +.EX +S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ... +.br + [A] bufn [A] P +.br + +.EE + +.IP "\fBint i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)\fP" +.IP "" 4 +This reads a block of up to 32 bytes from the specified register of +the device associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to read. +.br + buf: an array to receive the read data. +.br + +.EE + +.br + +.br +The amount of returned data is set by the device. + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +Block read. SMBus 2.0 5.5.7 + +.EX +S Addr Wr [A] i2c_reg [A] +.br + S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P +.br + +.EE + +.IP "\fBint i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write/read. +.br + buf: an array with the data to send and to receive the read data. +.br + count: 1-32, the number of bytes to write. +.br + +.EE + +.br + +.br + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br +The smbus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. + +.br + +.br +Block write-block read. SMBus 2.0 5.5.8 + +.EX +S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ... +.br + S Addr Rd [A] [Count] A [Data] ... A P +.br + +.EE + +.IP "\fBint i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" +.IP "" 4 +This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to read. +.br + buf: an array to receive the read data. +.br + count: 1-32, the number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. + +.br + +.br + +.EX +S Addr Wr [A] i2c_reg [A] +.br + S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P +.br + +.EE + +.IP "\fBint i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" +.IP "" 4 +This writes 1 to 32 bytes to the specified register of the device +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0, as returned by a call to \fBi2c_open\fP. +.br +i2c_reg: 0-255, the register to write. +.br + buf: the data to write. +.br + count: 1-32, the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br + +.EX +S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P +.br + +.EE + +.IP "\fBint i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This reads count bytes from the raw device into buf. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + buf: an array to receive the read data bytes. +.br + count: >0, the number of bytes to read. +.br + +.EE + +.br + +.br +Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. + +.br + +.br + +.EX +S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P +.br + +.EE + +.IP "\fBint i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This writes count bytes from buf to the raw device. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBi2c_open\fP. +.br + buf: an array containing the data bytes to write. +.br + count: >0, the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. + +.br + +.br + +.EX +S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P +.br + +.EE + +.IP "\fBint i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" +.IP "" 4 +This function executes a sequence of I2C operations. The +operations to be performed are specified by the contents of inBuf +which contains the concatenated command codes and associated data. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBi2cOpen\fP +.br + inBuf: pointer to the concatenated I2C commands, see below +.br + inLen: size of command buffer +.br +outBuf: pointer to buffer to hold returned data +.br +outLen: size of output buffer +.br + +.EE + +.br + +.br +Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +End 0 No more commands +.br +Escape 1 Next P is two bytes +.br +On 2 Switch combined flag on +.br +Off 3 Switch combined flag off +.br +Address 4 P Set I2C address to P +.br +Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) +.br +Read 6 P Read P bytes of data +.br +Write 7 P ... Write P bytes of data +.br + +.br + +.br +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +.br + +.br +The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. + +.br + +.br +The returned I2C data is stored in consecutive locations of outBuf. + +.br + +.br +\fBExample\fP +.br + +.EX +Set address 0x53, write 0x32, read 6 bytes +.br +Set address 0x1E, write 0x03, read 6 bytes +.br +Set address 0x68, write 0x1B, read 8 bytes +.br +End +.br + +.br +0x04 0x53 0x07 0x01 0x32 0x06 0x06 +.br +0x04 0x1E 0x07 0x01 0x03 0x06 0x06 +.br +0x04 0x68 0x07 0x01 0x1B 0x06 0x08 +.br +0x00 +.br + +.EE + +.br + +.br + +.IP "\fBint bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)\fP" +.IP "" 4 +This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. + +.br + +.br +Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. + +.br + +.br +o baud rates as low as 50 +.br +o repeated starts +.br +o clock stretching +.br +o I2C on any pair of spare GPIO + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + SDA: 0-31 +.br + SCL: 0-31 +.br +baud: 50-500000 +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. + +.br + +.br +NOTE: + +.br + +.br +The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. + +.IP "\fBint bb_i2c_close(int pi, unsigned SDA)\fP" +.IP "" 4 +This function stops bit banging I2C on a pair of GPIO previously +opened with \fBbb_i2c_open\fP. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +SDA: 0-31, the SDA GPIO used in a prior call to \fBbb_i2c_open\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. + +.IP "\fBint bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" +.IP "" 4 +This function executes a sequence of bit banged I2C operations. The +operations to be performed are specified by the contents of inBuf +which contains the concatenated command codes and associated data. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + SDA: 0-31 (as used in a prior call to \fBbb_i2c_open\fP) +.br + inBuf: pointer to the concatenated I2C commands, see below +.br + inLen: size of command buffer +.br +outBuf: pointer to buffer to hold returned data +.br +outLen: size of output buffer +.br + +.EE + +.br + +.br +Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. + +.br + +.br +The following command codes are supported: + +.br + +.br +Name Cmd & Data Meaning +.br +End 0 No more commands +.br +Escape 1 Next P is two bytes +.br +Start 2 Start condition +.br +Stop 3 Stop condition +.br +Address 4 P Set I2C address to P +.br +Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) +.br +Read 6 P Read P bytes of data +.br +Write 7 P ... Write P bytes of data +.br + +.br + +.br +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +.br + +.br +The address and flags default to 0. The address and flags maintain +their previous value until updated. + +.br + +.br +No flags are currently defined. + +.br + +.br +The returned I2C data is stored in consecutive locations of outBuf. + +.br + +.br +\fBExample\fP +.br + +.EX +Set address 0x53 +.br +start, write 0x32, (re)start, read 6 bytes, stop +.br +Set address 0x1E +.br +start, write 0x03, (re)start, read 6 bytes, stop +.br +Set address 0x68 +.br +start, write 0x1B, (re)start, read 8 bytes, stop +.br +End +.br + +.br +0x04 0x53 +.br +0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 +.br + +.br +0x04 0x1E +.br +0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 +.br + +.br +0x04 0x68 +.br +0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 +.br + +.br +0x00 +.br + +.EE + +.IP "\fBint bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)\fP" +.IP "" 4 +This function selects a set of GPIO for bit banging SPI at a +specified baud rate. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + CS: 0-31 +.br + MISO: 0-31 +.br + MOSI: 0-31 +.br + SCLK: 0-31 +.br + baud: 50-250000 +.br +spi_flags: see below +.br + +.EE + +.br + +.br +spi_flags consists of the least significant 22 bits. + +.br + +.br + +.EX +21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m +.br + +.EE + +.br + +.br +mm defines the SPI mode, defaults to 0 + +.br + +.br + +.EX +Mode CPOL CPHA +.br + 0 0 0 +.br + 1 0 1 +.br + 2 1 0 +.br + 3 1 1 +.br + +.EE + +.br + +.br +p is 0 if CS is active low (default) and 1 for active high. + +.br + +.br +T is 1 if the least significant bit is transmitted on MOSI first, the +default (0) shifts the most significant bit out first. + +.br + +.br +R is 1 if the least significant bit is received on MISO first, the +default (0) receives the most significant bit first. + +.br + +.br +The other bits in flags should be set to zero. + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or +PI_GPIO_IN_USE. + +.br + +.br +If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. + +.br + +.br +\fBExample\fP +.br + +.EX +bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1 +.br +bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2 +.br + +.EE + +.IP "\fBint bb_spi_close(int pi, unsigned CS)\fP" +.IP "" 4 +This function stops bit banging SPI on a set of GPIO +opened with \fBbbSPIOpen\fP. + +.br + +.br + +.EX +pi: >=0 (as returned by \fBpigpio_start\fP). +.br +CS: 0-31, the CS GPIO used in a prior call to \fBbb_spi_open\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. + +.IP "\fBint bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)\fP" +.IP "" 4 +This function executes a bit banged SPI transfer. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + CS: 0-31 (as used in a prior call to \fBbb_spi_open\fP) +.br +txBuf: pointer to buffer to hold data to be sent +.br +rxBuf: pointer to buffer to hold returned data +.br +count: size of data transfer +.br + +.EE + +.br + +.br +Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. + +.br + +.br +\fBExample\fP +.br + +.EX +// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2 +.br +// ./bb_spi_x_test +.br + +.br +#include +.br + +.br +#include "pigpiod_if2.h" +.br + +.br +#define CE0 5 +.br +#define CE1 6 +.br +#define MISO 13 +.br +#define MOSI 19 +.br +#define SCLK 12 +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int i, pi, count, set_val, read_val; +.br + unsigned char inBuf[3]; +.br + char cmd1[] = {0, 0}; +.br + char cmd2[] = {12, 0}; +.br + char cmd3[] = {1, 128, 0}; +.br + +.br + if ((pi = pigpio_start(0, 0)) < 0) +.br + { +.br + fprintf(stderr, "pigpio initialisation failed (%d).\n", pi); +.br + return 1; +.br + } +.br + +.br + bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC +.br + bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC +.br + +.br + for (i=0; i<256; i++) +.br + { +.br + cmd1[1] = i; +.br + +.br + count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC +.br + +.br + if (count == 2) +.br + { +.br + count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC +.br + +.br + if (count == 2) +.br + { +.br + set_val = inBuf[1]; +.br + +.br + count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC +.br + +.br + if (count == 3) +.br + { +.br + read_val = ((inBuf[1]&3)<<8) | inBuf[2]; +.br + printf("%d %d\n", set_val, read_val); +.br + } +.br + } +.br + } +.br + } +.br + +.br + bb_spi_close(pi, CE0); +.br + bb_spi_close(pi, CE1); +.br + +.br + pigpio_stop(pi); +.br +} +.br + +.EE + +.IP "\fBint spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)\fP" +.IP "" 4 +This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. + +.br + +.br +The Pi has two SPI peripherals: main and auxiliary. + +.br + +.br +The main SPI has two chip selects (channels), the auxiliary has +three. + +.br + +.br +The auxiliary SPI is available on all models but the A and B. + +.br + +.br +The GPIO used are given in the following table. + +.br + +.br + MISO MOSI SCLK CE0 CE1 CE2 +.br +Main SPI 9 10 11 8 7 - +.br +Aux SPI 19 20 21 18 17 16 +.br + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +spi_channel: 0-1 (0-2 for the auxiliary SPI). +.br + baud: 32K-125M (values above 30M are unlikely to work). +.br + spi_flags: see below. +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. + +.br + +.br +spi_flags consists of the least significant 22 bits. + +.br + +.br + +.EX +21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m +.br + +.EE + +.br + +.br +mm defines the SPI mode. + +.br + +.br +Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. + +.br + +.br + +.EX +Mode POL PHA +.br + 0 0 0 +.br + 1 0 1 +.br + 2 1 0 +.br + 3 1 1 +.br + +.EE + +.br + +.br +px is 0 if CEx is active low (default) and 1 for active high. + +.br + +.br +ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. + +.br + +.br +A is 0 for the main SPI, 1 for the auxiliary SPI. + +.br + +.br +W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main +SPI only. + +.br + +.br +nnnn defines the number of bytes (0-15) to write before switching +the MOSI line to MISO to read data. This field is ignored +if W is not set. Main SPI only. + +.br + +.br +T is 1 if the least significant bit is transmitted on MOSI first, the +default (0) shifts the most significant bit out first. Auxiliary SPI +only. + +.br + +.br +R is 1 if the least significant bit is received on MISO first, the +default (0) receives the most significant bit first. Auxiliary SPI +only. + +.br + +.br +bbbbbb defines the word size in bits (0-32). The default (0) +sets 8 bits per word. Auxiliary SPI only. + +.br + +.br +The \fBspi_read\fP, \fBspi_write\fP, and \fBspi_xfer\fP functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. + +.br + +.br +For bits 1-8 there will be one byte per character. +.br +For bits 9-16 there will be two bytes per character. +.br +For bits 17-32 there will be four bytes per character. + +.br + +.br +Multi-byte transfers are made in least significant byte first order. + +.br + +.br +E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. + +.br + +.br +E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed +by 0x1A. + +.br + +.br +The other bits in flags should be set to zero. + +.IP "\fBint spi_close(int pi, unsigned handle)\fP" +.IP "" 4 +This functions closes the SPI device identified by the handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBspi_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint spi_read(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads count bytes of data from the SPI +device associated with the handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBspi_open\fP. +.br + buf: an array to receive the read data bytes. +.br + count: the number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint spi_write(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes of data from buf to the SPI +device associated with the handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBspi_open\fP. +.br + buf: the data bytes to write. +.br + count: the number of bytes to write. +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" +.IP "" 4 +This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBspi_open\fP. +.br + txBuf: the data bytes to write. +.br + rxBuf: the received data bytes. +.br + count: the number of bytes to transfer. +.br + +.EE + +.br + +.br +Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. + +.IP "\fBint serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)\fP" +.IP "" 4 +This function opens a serial device at a specified baud rate +with specified flags. The device name must start with +/dev/tty or /dev/serial. + +.br + +.br + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + ser_tty: the serial device to open. +.br + baud: the baud rate in bits per second, see below. +.br +ser_flags: 0. +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. + +.br + +.br +The baud rate must be one of 50, 75, 110, 134, 150, +200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, +38400, 57600, 115200, or 230400. + +.br + +.br +No flags are currently defined. This parameter should be set to zero. + +.IP "\fBint serial_close(int pi, unsigned handle)\fP" +.IP "" 4 +This function closes the serial device associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.IP "\fBint serial_write_byte(int pi, unsigned handle, unsigned bVal)\fP" +.IP "" 4 +This function writes bVal to the serial port associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. + +.IP "\fBint serial_read_byte(int pi, unsigned handle)\fP" +.IP "" 4 +This function reads a byte from the serial port associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + +.EE + +.br + +.br +Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. + +.br + +.br +If no data is ready PI_SER_READ_NO_DATA is returned. + +.IP "\fBint serial_write(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes from buf to the the serial port +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + buf: the array of bytes to write. +.br + count: the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. + +.IP "\fBint serial_read(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads up to count bytes from the the serial port +associated with handle and writes them to buf. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + buf: an array to receive the read data. +.br + count: the maximum number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. + +.br + +.br +If no data is ready zero is returned. + +.IP "\fBint serial_data_available(int pi, unsigned handle)\fP" +.IP "" 4 +Returns the number of bytes available to be read from the +device associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0, as returned by a call to \fBserial_open\fP. +.br + +.EE + +.br + +.br +Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. + +.IP "\fBint custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)\fP" +.IP "" 4 +This function is available for user customisation. + +.br + +.br +It returns a single integer value. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +arg1: >=0 +.br +arg2: >=0 +.br +argx: extra (byte) arguments +.br +argc: number of extra arguments +.br + +.EE + +.br + +.br +Returns >= 0 if OK, less than 0 indicates a user defined error. + +.IP "\fBint custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" +.IP "" 4 +This function is available for user customisation. + +.br + +.br +It differs from custom_1 in that it returns an array of bytes +rather than just an integer. + +.br + +.br +The return value is an integer indicating the number of returned bytes. + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + arg1: >=0 +.br + argc: extra (byte) arguments +.br + count: number of extra arguments +.br +retBuf: buffer for returned data +.br +retMax: maximum number of bytes to return +.br + +.EE + +.br + +.br +Returns >= 0 if OK, less than 0 indicates a user defined error. + +.br + +.br +Note, the number of returned bytes will be retMax or less. + +.IP "\fBint get_pad_strength(int pi, unsigned pad)\fP" +.IP "" 4 +This function returns the pad drive strength in mA. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +pad: 0-2, the pad to get. +.br + +.EE + +.br + +.br +Returns the pad drive strength if OK, otherwise PI_BAD_PAD. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +strength = get_pad_strength(pi, 0); // get pad 0 strength +.br + +.EE + +.IP "\fBint set_pad_strength(int pi, unsigned pad, unsigned padStrength)\fP" +.IP "" 4 +This function sets the pad drive strength in mA. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + pad: 0-2, the pad to set. +.br +padStrength: 1-16 mA. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA +.br + +.EE + +.IP "\fBint shell_(int pi, char *scriptName, char *scriptString)\fP" +.IP "" 4 +This function uses the system call to execute a shell script +with the given string as its parameter. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + scriptName: the name of the script, only alphanumeric characters, +.br + '-' and '_' are allowed in the name. +.br +scriptString: the string to pass to the script. +.br + +.EE + +.br + +.br +The exit status of the system call is returned if OK, otherwise +PI_BAD_SHELL_STATUS. + +.br + +.br +scriptName must exist in /opt/pigpio/cgi and must be executable. + +.br + +.br +The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. + +.br + +.br +The following table gives some example returned statuses. + +.br + +.br +Script exit status Returned system call status +.br +1 256 +.br +5 1280 +.br +10 2560 +.br +200 51200 +.br +script not found 32512 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +// pass two parameters, hello and world +.br +status = shell_(pi, "scr1", "hello world"); +.br + +.br +// pass three parameters, hello, string with spaces, and world +.br +status = shell_(pi, "scr1", "hello 'string with spaces' world"); +.br + +.br +// pass one parameter, hello string with spaces world +.br +status = shell_(pi, "scr1", "\"hello string with spaces world\""); +.br + +.EE + +.IP "\fBint file_open(int pi, char *file, unsigned mode)\fP" +.IP "" 4 +This function returns a handle to a file opened in a specified mode. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +file: the file to open. +.br +mode: the file open mode. +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. + +.br + +.br +File + +.br + +.br +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +.br + +.br +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +.br + +.br +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +.br + +.br +Suppose /opt/pigpio/access contains the following entries + +.br + +.br + +.EX +/home/* n +.br +/home/pi/shared/dir_1/* w +.br +/home/pi/shared/dir_2/* r +.br +/home/pi/shared/dir_3/* u +.br +/home/pi/shared/dir_1/file.txt n +.br + +.EE + +.br + +.br +Files may be written in directory dir_1 with the exception +of file.txt. + +.br + +.br +Files may be read in directory dir_2. + +.br + +.br +Files may be read and written in directory dir_3. + +.br + +.br +If a directory allows read, write, or read/write access then files may +be created in that directory. + +.br + +.br +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +.br + +.br + +.EX +a path containing .. +.br +a path containing only wildcards (*?) +.br +a path containing less than two non-wildcard parts +.br + +.EE + +.br + +.br +Mode + +.br + +.br +The mode may have the following values. + +.br + +.br +Macro Value Meaning +.br +PI_FILE_READ 1 open file for reading +.br +PI_FILE_WRITE 2 open file for writing +.br +PI_FILE_RW 3 open file for reading and writing +.br + +.br + +.br +The following values may be or'd into the mode. + +.br + +.br +Macro Value Meaning +.br +PI_FILE_APPEND 4 Writes append data to the end of the file +.br +PI_FILE_CREATE 8 The file is created if it doesn't exist +.br +PI_FILE_TRUNC 16 The file is truncated +.br + +.br + +.br +Newly created files are owned by root with permissions owner read and write. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int pi, handle, c; +.br + char buf[60000]; +.br + +.br + pi = pigpio_start(NULL, NULL); +.br + +.br + if (pi < 0) return 1; +.br + +.br + // assumes /opt/pigpio/access contains the following line +.br + // /ram/*.c r +.br + +.br + handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ); +.br + +.br + if (handle >= 0) +.br + { +.br + while ((c=file_read(pi, handle, buf, sizeof(buf)-1))) +.br + { +.br + buf[c] = 0; +.br + printf("%s", buf); +.br + } +.br + +.br + file_close(pi, handle); +.br + } +.br + +.br + pigpio_stop(pi); +.br +} +.br + +.EE + +.IP "\fBint file_close(int pi, unsigned handle)\fP" +.IP "" 4 +This function closes the file associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0 (as returned by \fBfile_open\fP). +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +\fBExample\fP +.br + +.EX +file_close(pi, handle); +.br + +.EE + +.IP "\fBint file_write(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes from buf to the the file +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0 (as returned by \fBfile_open\fP). +.br + buf: the array of bytes to write. +.br + count: the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. + +.br + +.br +\fBExample\fP +.br + +.EX +if (file_write(pi, handle, buf, 100) == 0) +.br +{ +.br + // file written okay +.br +} +.br +else +.br +{ +.br + // error +.br +} +.br + +.EE + +.IP "\fBint file_read(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads up to count bytes from the the file +associated with handle and writes them to buf. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0 (as returned by \fBfile_open\fP). +.br + buf: an array to receive the read data. +.br + count: the maximum number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. + +.br + +.br +\fBExample\fP +.br + +.EX + bytes = file_read(pi, handle, buf, sizeof(buf)); +.br + +.br + if (bytes >= 0) +.br + { +.br + // process read data +.br + } +.br + +.EE + +.IP "\fBint file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)\fP" +.IP "" 4 +This function seeks to a position within the file associated +with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0 (as returned by \fBfile_open\fP). +.br +seekOffset: the number of bytes to move. Positive offsets +.br + move forward, negative offsets backwards. +.br + seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1), +.br + or PI_FROM_END (2). +.br + +.EE + +.br + +.br +Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. + +.br + +.br +\fBExample\fP +.br + +.EX +file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123 +.br + +.br +size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size +.br + +.br +pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position +.br + +.EE + +.IP "\fBint file_list(int pi, char *fpat, char *buf, unsigned count)\fP" +.IP "" 4 +This function returns a list of files which match a pattern. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + fpat: file pattern to match. +.br + buf: an array to receive the matching file names. +.br +count: the maximum number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. + +.br + +.br +The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See \fBfile_open\fP. + +.br + +.br +NOTE + +.br + +.br +The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int pi, handle, c; +.br + char buf[60000]; +.br + +.br + pi = pigpio_start(NULL, NULL); +.br + +.br + if (pi < 0) return 1; +.br + +.br + // assumes /opt/pigpio/access contains the following line +.br + // /ram/*.c r +.br + +.br + c = file_list(pi, "/ram/p*.c", buf, sizeof(buf)); +.br + +.br + if (c >= 0) +.br + { +.br + buf[c] = 0; +.br + printf("%s", buf); +.br + } +.br + +.br + pigpio_stop(pi); +.br +} +.br + +.EE + +.IP "\fBint callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)\fP" +.IP "" 4 +This function initialises a new callback. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. +.br + f: the callback function. +.br + +.EE + +.br + +.br +The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. + +.br + +.br +The callback is called with the GPIO, edge, and tick, whenever the +GPIO has the identified edge. + +.br + +.br + +.EX +Parameter Value Meaning +.br + +.br +GPIO 0-31 The GPIO which has changed state +.br + +.br +edge 0-2 0 = change to low (a falling edge) +.br + 1 = change to high (a rising edge) +.br + 2 = no level change (a watchdog timeout) +.br + +.br +tick 32 bit The number of microseconds since boot +.br + WARNING: this wraps around from +.br + 4294967295 to 0 roughly every 72 minutes +.br + +.EE + +.br + +.br +The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). + +.br + +.br +The number of samples per second is given in the following table. + +.br + +.br + +.EX + samples +.br + per sec +.br + +.br + 1 1,000,000 +.br + 2 500,000 +.br +sample 4 250,000 +.br +rate 5 200,000 +.br +(us) 8 125,000 +.br + 10 100,000 +.br + +.EE + +.br + +.br +GPIO level changes shorter than the sample rate may be missed. + +.br + +.br +The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. + +.br + +.br +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use \fBgpio_read\fP. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. + +.IP "\fBint callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP" +.IP "" 4 +This function initialises a new callback. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. +.br + f: the callback function. +.br + userdata: a pointer to arbitrary user data. +.br + +.EE + +.br + +.br +The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. + +.br + +.br +The callback is called with the GPIO, edge, tick, and the userdata +pointer, whenever the GPIO has the identified edge. + +.br + +.br + +.EX +Parameter Value Meaning +.br + +.br +GPIO 0-31 The GPIO which has changed state +.br + +.br +edge 0-2 0 = change to low (a falling edge) +.br + 1 = change to high (a rising edge) +.br + 2 = no level change (a watchdog timeout) +.br + +.br +tick 32 bit The number of microseconds since boot +.br + WARNING: this wraps around from +.br + 4294967295 to 0 roughly every 72 minutes +.br + +.br +userdata pointer Pointer to an arbitrary object +.br + +.EE + +.IP "\fBint callback_cancel(unsigned callback_id)\fP" +.IP "" 4 +This function cancels a callback identified by its id. + +.br + +.br + +.EX +callback_id: >=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise pigif_callback_not_found. + +.IP "\fBint wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)\fP" +.IP "" 4 +This function waits for an edge on the GPIO for up to timeout +seconds. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +user_gpio: 0-31. +.br + edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. +.br + timeout: >=0. +.br + +.EE + +.br + +.br +The function returns when the edge occurs or after the timeout. + +.br + +.br +Do not use this function for precise timing purposes, +the edge is only checked 20 times a second. Whenever +you need to know the accurate time of GPIO events use +a \fBcallback\fP function. + +.br + +.br +The function returns 1 if the edge occurred, otherwise 0. + +.IP "\fBint bsc_xfer(int pi, bsc_xfer_t *bscxfer)\fP" +.IP "" 4 +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +.br + +.br +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +.br + +.br +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +.br + +.br +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. + +.br + +.br +I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. + +.br + +.br +The function sets the BSC mode, writes any data in +the transmit buffer to the BSC transmit FIFO, and +copies any data in the BSC receive FIFO to the +receive buffer. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +bscxfer: a structure defining the transfer. +.br + +.br +typedef struct +.br +{ +.br + uint32_t control; // Write +.br + int rxCnt; // Read only +.br + char rxBuf[BSC_FIFO_SIZE]; // Read only +.br + int txCnt; // Write +.br + char txBuf[BSC_FIFO_SIZE]; // Write +.br +} bsc_xfer_t; +.br + +.EE + +.br + +.br +To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. + +.br + +.br +Upon return rxCnt will be set to the number of received bytes placed +in rxBuf. + +.br + +.br +The returned function value is the status of the transfer (see below). + +.br + +.br +If there was an error the status will be less than zero +(and will contain the error code). + +.br + +.br +The most significant word of the returned status contains the number +of bytes actually copied from txBuf to the BSC transmit FIFO (may be +less than requested if the FIFO already contained untransmitted data). + +.br + +.br +Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. + +.br + +.br +GPIO used for models other than those based on the BCM2711. + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 18 19 - - - - +.br +SPI - - 18 19 20 21 +.br + +.br + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 10 11 - - - - +.br +SPI - - 10 11 9 8 +.br + +.br + +.br +When a zero control word is received the used GPIO will be reset +to INPUT mode. + +.br + +.br +control consists of the following bits. + +.br + +.br + +.EX +22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN +.br + +.EE + +.br + +.br +Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. + +.br + +.br +aaaaaaa defines the I2C slave address (only relevant in I2C mode) +.br +IT invert transmit status flags +.br +HC enable host control +.br +TF enable test FIFO +.br +IR invert receive status flags +.br +RE enable receive +.br +TE enable transmit +.br +BK abort operation and clear FIFOs +.br +EC send control register as first I2C byte +.br +ES send status register as first I2C byte +.br +PL set SPI polarity high +.br +PH set SPI phase high +.br +I2 enable I2C mode +.br +SP enable SPI mode +.br +EN enable BSC peripheral +.br + +.br + +.br +The returned status has the following format + +.br + +.br + +.EX +20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + S S S S S R R R R R T T T T T RB TE RF TF RE TB +.br + +.EE + +.br + +.br +Bits 0-15 are copied unchanged from the BSC FR register. See +pages 165-166 of the Broadcom peripherals document for full +details. + +.br + +.br +SSSSS number of bytes successfully copied to transmit FIFO +.br +RRRRR number of bytes in receieve FIFO +.br +TTTTT number of bytes in transmit FIFO +.br +RB receive busy +.br +TE transmit FIFO empty +.br +RF receive FIFO full +.br +TF transmit FIFO full +.br +RE receive FIFO empty +.br +TB transmit busy +.br + +.br + +.br +The following example shows how to configure the BSC peripheral as +an I2C slave with address 0x13 and send four bytes. + +.br + +.br +\fBExample\fP +.br + +.EX +bsc_xfer_t xfer; +.br + +.br +xfer.control = (0x13<<16) | 0x305; +.br + +.br +memcpy(xfer.txBuf, "ABCD", 4); +.br +xfer.txCnt = 4; +.br + +.br +status = bsc_xfer(pi, &xfer); +.br + +.br +if (status >= 0) +.br +{ +.br + // process transfer +.br +} +.br + +.EE + +.IP "\fBint bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)\fP" +.IP "" 4 +This function allows the Pi to act as a slave I2C device. + +.br + +.br +This function is not available on the BCM2711 (e.g.as +used in the Pi4B). + +.br + +.br +The data bytes (if any) are written to the BSC transmit +FIFO and the bytes in the BSC receive FIFO are returned. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +i2c_addr: 0-0x7F. +.br + bscxfer: a structure defining the transfer. +.br + +.br +typedef struct +.br +{ +.br + uint32_t control; // N/A +.br + int rxCnt; // Read only +.br + char rxBuf[BSC_FIFO_SIZE]; // Read only +.br + int txCnt; // Write +.br + char txBuf[BSC_FIFO_SIZE]; // Write +.br +} bsc_xfer_t; +.br + +.EE + +.br + +.br +txCnt is set to the number of bytes to be transmitted, possibly +zero. The data itself should be copied to txBuf. + +.br + +.br +Any received data will be written to rxBuf with rxCnt set. + +.br + +.br +See \fBbsc_xfer\fP for details of the returned status value. + +.br + +.br +If there was an error the status will be less than zero +(and will contain the error code). + +.br + +.br +Note that an i2c_address of 0 may be used to close +the BSC device and reassign the used GPIO as inputs. + +.IP "\fBint event_callback(int pi, unsigned event, evtCBFunc_t f)\fP" +.IP "" 4 +This function initialises an event callback. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +event: 0-31. +.br + f: the callback function. +.br + +.EE + +.br + +.br +The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. + +.br + +.br +The callback is called with the event id, and tick, whenever the +event occurs. + +.IP "\fBint event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)\fP" +.IP "" 4 +This function initialises an event callback. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + event: 0-31. +.br + f: the callback function. +.br +userdata: a pointer to arbitrary user data. +.br + +.EE + +.br + +.br +The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. + +.br + +.br +The callback is called with the event id, the tick, and the userdata +pointer whenever the event occurs. + +.IP "\fBint event_callback_cancel(unsigned callback_id)\fP" +.IP "" 4 +This function cancels an event callback identified by its id. + +.br + +.br + +.EX +callback_id: >=0, as returned by a call to \fBevent_callback\fP or +.br +\fBevent_callback_ex\fP. +.br + +.EE + +.br + +.br +The function returns 0 if OK, otherwise pigif_callback_not_found. + +.IP "\fBint wait_for_event(int pi, unsigned event, double timeout)\fP" +.IP "" 4 +This function waits for an event for up to timeout seconds. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + event: 0-31. +.br +timeout: >=0. +.br + +.EE + +.br + +.br +The function returns when the event occurs or after the timeout. + +.br + +.br +The function returns 1 if the event occurred, otherwise 0. + +.IP "\fBint event_trigger(int pi, unsigned event)\fP" +.IP "" 4 +This function signals the occurrence of an event. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +event: 0-31. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_EVENT_ID. + +.br + +.br +An event is a signal used to inform one or more consumers +to start an action. Each consumer which has registered an interest +in the event (e.g. by calling \fBevent_callback\fP) will be informed by +a callback. + +.br + +.br +One event, PI_EVENT_BSC (31) is predefined. This event is +auto generated on BSC slave activity. + +.br + +.br +The meaning of other events is arbitrary. + +.br + +.br +Note that other than its id and its tick there is no data associated +with an event. +.SH PARAMETERS + +.br + +.br + +.IP "\fBactive\fP: 0-1000000" 0 + +.br + +.br +The number of microseconds level changes are reported for once +a noise filter has been triggered (by \fBsteady\fP microseconds of +a stable level). + +.br + +.br + +.IP "\fB*addrStr\fP" 0 +A string specifying the host or IP address of the Pi running +the pigpio daemon. It may be NULL in which case localhost +is used unless overridden by the PIGPIO_ADDR environment +variable. + +.br + +.br + +.IP "\fBarg1\fP" 0 +An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. + +.br + +.br + +.IP "\fBarg2\fP" 0 +An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. + +.br + +.br + +.IP "\fBargc\fP" 0 +The count of bytes passed to a user customised function. + +.br + +.br + +.IP "\fB*argx\fP" 0 +A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. + +.br + +.br + +.IP "\fBbaud\fP" 0 +The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. + +.br + +.br + +.IP "\fBbit\fP" 0 +A value of 0 or 1. + +.br + +.br + +.IP "\fBbits\fP" 0 +A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. + +.br + +.br +A convenient way to set bit n is to or in (1<=0, as returned by a call to a callback function, one of + +.br + +.br +\fBcallback\fP +.br +\fBcallback_ex\fP +.br +\fBevent_callback\fP +.br +\fBevent_callback_ex\fP + +.br + +.br +The id is passed to \fBcallback_cancel\fP or \fBevent_callback_cancel\fP +to cancel the callback. + +.br + +.br + +.IP "\fBCBFunc_t\fP" 0 + +.EX +typedef void (*CBFunc_t) +.br + (int pi, unsigned user_gpio, unsigned level, uint32_t tick); +.br + +.EE + +.br + +.br + +.IP "\fBCBFuncEx_t\fP" 0 + +.EX +typedef void (*CBFuncEx_t) +.br + (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata); +.br + +.EE + +.br + +.br + +.IP "\fBchar\fP" 0 +A single character, an 8 bit quantity able to store 0-255. + +.br + +.br + +.IP "\fBclkfreq\fP: 4689-250M (13184-375M for the BCM2711)" 0 +The hardware clock frequency. + +.br + +.br + +.IP "\fBcount\fP" 0 +The number of bytes to be transferred in a file, I2C, SPI, or serial +command. + +.br + +.br + +.IP "\fBCS\fP" 0 +The GPIO used for the slave select signal when bit banging SPI. + +.br + +.br + +.IP "\fBdata_bits\fP: 1-32" 0 +The number of data bits in each character of serial data. + +.br + +.br + +.EX +#define PI_MIN_WAVE_DATABITS 1 +.br +#define PI_MAX_WAVE_DATABITS 32 +.br + +.EE + +.br + +.br + +.IP "\fBdouble\fP" 0 +A floating point number. + +.br + +.br + +.IP "\fBdutycycle\fP: 0-range" 0 +A number representing the ratio of on time to off time for PWM. + +.br + +.br +The number may vary between 0 and range (default 255) where +0 is off and range is fully on. + +.br + +.br + +.IP "\fBedge\fP" 0 +Used to identify a GPIO level transition of interest. A rising edge is +a level change from 0 to 1. A falling edge is a level change from 1 to 0. + +.br + +.br + +.EX +RISING_EDGE 0 +.br +FALLING_EDGE 1 +.br +EITHER_EDGE. 2 +.br + +.EE + +.br + +.br + +.IP "\fBerrnum\fP" 0 +A negative number indicating a function call failed and the nature +of the error. + +.br + +.br + +.IP "\fBevent\fP: 0-31" 0 +An event is a signal used to inform one or more consumers +to start an action. + +.br + +.br + +.IP "\fBevtCBFunc_t\fP" 0 + +.br + +.br + +.EX +typedef void (*evtCBFunc_t) +.br + (int pi, unsigned event, uint32_t tick); +.br + +.EE + +.br + +.br + +.IP "\fBevtCBFuncEx_t\fP" 0 + +.br + +.br + +.EX +typedef void (*evtCBFuncEx_t) +.br + (int pi, unsigned event, uint32_t tick, void *userdata); +.br + +.EE + +.br + +.br + +.IP "\fBf\fP" 0 +A function. + +.br + +.br + +.IP "\fB*file\fP" 0 +A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. + +.br + +.br + +.IP "\fB*fpat\fP" 0 +A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. + +.br + +.br + +.IP "\fBfrequency\fP: >=0" 0 +The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. + +.br + +.br + +.IP "\fBgpio\fP" 0 +A Broadcom numbered GPIO, in the range 0-53. + +.br + +.br +There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through +GPIO53. + +.br + +.br +They are split into two banks. Bank 1 consists of GPIO0 through +GPIO31. Bank 2 consists of GPIO32 through GPIO53. + +.br + +.br +All the GPIO which are safe for the user to read and write are in +bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards +have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. + +.br + +.br +See \fBget_hardware_revision\fP. + +.br + +.br +The user GPIO are marked with an X in the following table. + +.br + +.br + +.EX + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 +.br +Type 1 X X - - X - - X X X X X - - X X +.br +Type 2 - - X X X - - X X X X X - - X X +.br +Type 3 X X X X X X X X X X X X X X +.br + +.br + 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +.br +Type 1 - X X - - X X X X X - - - - - - +.br +Type 2 - X X - - - X X X X - X X X X X +.br +Type 3 X X X X X X X X X X X X - - - - +.br + +.EE + +.br + +.br + +.IP "\fBgpioPulse_t\fP" 0 + +.EX +typedef struct +.br +{ +.br + uint32_t gpioOn; +.br + uint32_t gpioOff; +.br + uint32_t usDelay; +.br +} gpioPulse_t; +.br + +.EE + +.br + +.br + +.IP "\fBgpioThreadFunc_t\fP" 0 + +.EX +typedef void *(gpioThreadFunc_t) (void *); +.br + +.EE + +.br + +.br + +.IP "\fBhandle\fP: >=0" 0 +A number referencing an object opened by one of + +.br + +.br +\fBfile_open\fP +.br +\fBi2c_open\fP +.br +\fBnotify_open\fP +.br +\fBserial_open\fP +.br +\fBspi_open\fP + +.br + +.br + +.IP "\fBi2c_addr\fP: 0-0x7F" 0 +The address of a device on the I2C bus. + +.br + +.br + +.IP "\fBi2c_bus\fP: >=0" 0 +An I2C bus number. + +.br + +.br + +.IP "\fBi2c_flags\fP: 0" 0 +Flags which modify an I2C open command. None are currently defined. + +.br + +.br + +.IP "\fBi2c_reg\fP: 0-255" 0 +A register of an I2C device. + +.br + +.br + +.IP "\fB*inBuf\fP" 0 +A buffer used to pass data to a function. + +.br + +.br + +.IP "\fBinLen\fP" 0 +The number of bytes of data in a buffer. + +.br + +.br + +.IP "\fBint\fP" 0 +A whole number, negative or positive. + +.br + +.br + +.IP "\fBint32_t\fP" 0 +A 32-bit signed value. + +.br + +.br + +.IP "\fBinvert\fP" 0 +A flag used to set normal or inverted bit bang serial data level logic. + +.br + +.br + +.IP "\fBlevel\fP" 0 +The level of a GPIO. Low or High. + +.br + +.br + +.EX +PI_OFF 0 +.br +PI_ON 1 +.br + +.br +PI_CLEAR 0 +.br +PI_SET 1 +.br + +.br +PI_LOW 0 +.br +PI_HIGH 1 +.br + +.EE + +.br + +.br +There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See \fBset_watchdog\fP. + +.br + +.br + +.EX +PI_TIMEOUT 2 +.br + +.EE + +.br + +.br + +.IP "\fBMISO\fP" 0 +The GPIO used for the MISO signal when bit banging SPI. + +.br + +.br + +.IP "\fBmode\fP" 0 +1. The operational mode of a GPIO, normally INPUT or OUTPUT. + +.br + +.br + +.EX +PI_INPUT 0 +.br +PI_OUTPUT 1 +.br +PI_ALT0 4 +.br +PI_ALT1 5 +.br +PI_ALT2 6 +.br +PI_ALT3 7 +.br +PI_ALT4 3 +.br +PI_ALT5 2 +.br + +.EE + +.br + +.br +2. The mode of waveform transmission. + +.br + +.br + +.EX +PI_WAVE_MODE_ONE_SHOT 0 +.br +PI_WAVE_MODE_REPEAT 1 +.br +PI_WAVE_MODE_ONE_SHOT_SYNC 2 +.br +PI_WAVE_MODE_REPEAT_SYNC 3 +.br + +.EE + +.br + +.br +3. A file open mode. + +.br + +.br + +.EX +PI_FILE_READ 1 +.br +PI_FILE_WRITE 2 +.br +PI_FILE_RW 3 +.br + +.EE + +.br + +.br +The following values can be or'd into the mode. + +.br + +.br + +.EX +PI_FILE_APPEND 4 +.br +PI_FILE_CREATE 8 +.br +PI_FILE_TRUNC 16 +.br + +.EE + +.br + +.br + +.IP "\fBMOSI\fP" 0 +The GPIO used for the MOSI signal when bit banging SPI. + +.br + +.br + +.IP "\fBnumBytes\fP" 0 +The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. + +.br + +.br + +.IP "\fBnumPar\fP: 0-10" 0 +The number of parameters passed to a script. + +.br + +.br + +.IP "\fBnumPulses\fP" 0 +The number of pulses to be added to a waveform. + +.br + +.br + +.IP "\fBoffset\fP" 0 +The associated data starts this number of microseconds from the start of +the waveform. + +.br + +.br + +.IP "\fB*outBuf\fP" 0 +A buffer used to return data from a function. + +.br + +.br + +.IP "\fBoutLen\fP" 0 +The size in bytes of an output buffer. + +.br + +.br + +.IP "\fBpad\fP: 0-2" 0 +A set of GPIO which share common drivers. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br + +.IP "\fBpadStrength\fP: 1-16" 0 +The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. + +.br + +.br + +.IP "\fB*param\fP" 0 +An array of script parameters. + +.br + +.br + +.IP "\fBpi\fP" 0 +An integer defining a connected Pi. The value is returned by +\fBpigpio_start\fP upon success. + +.br + +.br + +.IP "\fB*portStr\fP" 0 +A string specifying the port address used by the Pi running +the pigpio daemon. It may be NULL in which case "8888" +is used unless overridden by the PIGPIO_PORT environment +variable. + +.br + +.br + +.IP "\fB*pth\fP" 0 +A thread identifier, returned by \fBstart_thread\fP. + +.br + +.br + +.br + +.br + +.IP "\fBpthread_t\fP" 0 +A thread identifier. + +.br + +.br + +.IP "\fBpud\fP: 0-2" 0 +The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. + +.EX +PI_PUD_OFF 0 +.br +PI_PUD_DOWN 1 +.br +PI_PUD_UP 2 +.br + +.EE + +.br + +.br + +.IP "\fBpulseLen\fP" 0 +1-100, the length of a trigger pulse in microseconds. + +.br + +.br + +.IP "\fB*pulses\fP" 0 +An array of pulses to be added to a waveform. + +.br + +.br + +.IP "\fBpulsewidth\fP: 0, 500-2500" 0 + +.EX +PI_SERVO_OFF 0 +.br +PI_MIN_SERVO_PULSEWIDTH 500 +.br +PI_MAX_SERVO_PULSEWIDTH 2500 +.br + +.EE + +.br + +.br + +.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 +The hardware PWM dutycycle. + +.br + +.br + +.EX +#define PI_HW_PWM_RANGE 1000000 +.br + +.EE + +.br + +.br + +.IP "\fBPWMfreq\fP: 1-125M (1-187.5M for the BCM2711)" 0 +The hardware PWM frequency. + +.br + +.br + +.EX +#define PI_HW_PWM_MIN_FREQ 1 +.br +#define PI_HW_PWM_MAX_FREQ 125000000 +.br +#define PI_HW_PWM_MAX_FREQ_2711 187500000 +.br + +.EE + +.br + +.br + +.IP "\fBrange\fP: 25-40000" 0 +The permissible dutycycle values are 0-range. + +.br + +.br + +.EX +PI_MIN_DUTYCYCLE_RANGE 25 +.br +PI_MAX_DUTYCYCLE_RANGE 40000 +.br + +.EE + +.br + +.br + +.IP "\fB*retBuf\fP" 0 +A buffer to hold a number of bytes returned to a used customised function, + +.br + +.br + +.IP "\fBretMax\fP" 0 +The maximum number of bytes a user customised function should return. + +.br + +.br + +.br + +.br + +.IP "\fB*rxBuf\fP" 0 +A pointer to a buffer to receive data. + +.br + +.br + +.IP "\fBSCL\fP" 0 +The user GPIO to use for the clock when bit banging I2C. + +.br + +.br + +.IP "\fBSCLK\fP" 0 +The GPIO used for the SCLK signal when bit banging SPI. + +.br + +.br + +.IP "\fB*script\fP" 0 +A pointer to the text of a script. + +.br + +.br + +.IP "\fBscript_id\fP" 0 +An id of a stored script as returned by \fBstore_script\fP. + +.br + +.br + +.IP "\fB*scriptName\fP" 0 +The name of a \fBshell_\fP script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. + +.br + +.br + +.IP "\fB*scriptString\fP" 0 +The string to be passed to a \fBshell_\fP script to be executed. + +.br + +.br + +.IP "\fBSDA\fP" 0 +The user GPIO to use for data when bit banging I2C. + +.br + +.br + +.IP "\fBseconds\fP" 0 +The number of seconds. + +.br + +.br + +.IP "\fBseekFrom\fP" 0 + +.br + +.br + +.EX +PI_FROM_START 0 +.br +PI_FROM_CURRENT 1 +.br +PI_FROM_END 2 +.br + +.EE + +.br + +.br + +.IP "\fBseekOffset\fP" 0 +The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). + +.br + +.br + +.IP "\fBser_flags\fP" 0 +Flags which modify a serial open command. None are currently defined. + +.br + +.br + +.IP "\fB*ser_tty\fP" 0 +The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. + +.br + +.br + +.IP "\fBsize_t\fP" 0 +A standard type used to indicate the size of an object in bytes. + +.br + +.br + +.IP "\fBspi_channel\fP" 0 +A SPI channel, 0-2. + +.br + +.br + +.IP "\fBspi_flags\fP" 0 +See \fBspi_open\fP and \fBbb_spi_open\fP. + +.br + +.br + +.IP "\fBsteady\fP: 0-300000" 0 + +.br + +.br +The number of microseconds level changes must be stable for +before reporting the level changed (\fBset_glitch_filter\fP) or triggering +the active part of a noise filter (\fBset_noise_filter\fP). + +.br + +.br + +.IP "\fBstop_bits\fP: 2-8" 0 +The number of (half) stop bits to be used when adding serial data +to a waveform. + +.br + +.br + +.EX +#define PI_MIN_WAVE_HALFSTOPBITS 2 +.br +#define PI_MAX_WAVE_HALFSTOPBITS 8 +.br + +.EE + +.br + +.br + +.IP "\fB*str\fP" 0 + An array of characters. + +.br + +.br + +.IP "\fBthread_func\fP" 0 +A function of type gpioThreadFunc_t used as the main function of a +thread. + +.br + +.br + +.IP "\fBtimeout\fP" 0 +A GPIO watchdog timeout in milliseconds. + +.br + +.br + +.EX +PI_MIN_WDOG_TIMEOUT 0 +.br +PI_MAX_WDOG_TIMEOUT 60000 +.br + +.EE + +.br + +.br + +.IP "\fB*txBuf\fP" 0 +An array of bytes to transmit. + +.br + +.br + +.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 +A 32-bit unsigned value. + +.br + +.br + +.IP "\fBunsigned\fP" 0 +A whole number >= 0. + +.br + +.br + +.IP "\fBuser_gpio\fP" 0 +0-31, a Broadcom numbered GPIO. + +.br + +.br +See \fBgpio\fP. + +.br + +.br + +.IP "\fB*userdata\fP" 0 + +.br + +.br +A pointer to arbitrary user data. This may be used to identify the instance. + +.br + +.br +You must ensure that the pointer is in scope at the time it is processed. If +it is a pointer to a global this is automatic. Do not pass the address of a +local variable. If you want to pass a transient object then use the +following technique. + +.br + +.br +In the calling function: + +.br + +.br + +.EX +user_type *userdata; +.br +.br +.br +user_type my_userdata; +.br + +.br +userdata = malloc(sizeof(user_type)); +.br +.br +.br +*userdata = my_userdata; +.br + +.EE + +.br + +.br +In the receiving function: + +.br + +.br + +.EX +user_type my_userdata = *(user_type*)userdata; +.br + +.br +free(userdata); +.br + +.EE + +.br + +.br + +.IP "\fBvoid\fP" 0 +Denoting no parameter is required + +.br + +.br + +.IP "\fBwave_add_*\fP" 0 +One of + +.br + +.br +\fBwave_add_new\fP +.br +\fBwave_add_generic\fP +.br +\fBwave_add_serial\fP + +.br + +.br + +.IP "\fBwave_id\fP" 0 +A number representing a waveform created by \fBwave_create\fP. + +.br + +.br + +.IP "\fBwave_send_*\fP" 0 +One of + +.br + +.br +\fBwave_send_once\fP +.br +\fBwave_send_repeat\fP + +.br + +.br + +.IP "\fBwVal\fP: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)" 0 +A 16-bit word value. + +.br + +.br +.SH pigpiod_if2 Error Codes + +.EX + +.br +typedef enum +.br +{ +.br + pigif_bad_send = -2000, +.br + pigif_bad_recv = -2001, +.br + pigif_bad_getaddrinfo = -2002, +.br + pigif_bad_connect = -2003, +.br + pigif_bad_socket = -2004, +.br + pigif_bad_noib = -2005, +.br + pigif_duplicate_callback = -2006, +.br + pigif_bad_malloc = -2007, +.br + pigif_bad_callback = -2008, +.br + pigif_notify_failed = -2009, +.br + pigif_callback_not_found = -2010, +.br + pigif_unconnected_pi = -2011, +.br + pigif_too_many_pis = -2012, +.br +} pigifError_t; +.br + +.br + +.EE + +.SH SEE ALSO + +pigpiod(1), pig2vcd(1), pigs(1), pigpio(3), pigpiod_if(3) +.SH AUTHOR + +joan@abyz.me.uk diff --git a/DOC/MAN/pigs.1 b/DOC/MAN/pigs.1 new file mode 100644 index 0000000..fa99470 --- /dev/null +++ b/DOC/MAN/pigs.1 @@ -0,0 +1,6331 @@ + +." Process this file with +." groff -man -Tascii foo.1 +." +.TH pigs 1 2012-2020 Linux "pigpio archive" +.SH NAME +pigs - command line socket access to the pigpio daemon. + +/dev/pigpio - command line pipe access to the pigpio daemon. + +.SH SYNOPSIS + +.B sudo pigpiod + +then + +.B pigs {command}+ + +or + +.B "echo {command}+ >/dev/pigpio" + +.SH DESCRIPTION + +.ad l + +.nh + + +.br +The socket and pipe interfaces allow control of the Pi's GPIO by +passing messages to the running pigpio library. + +.br +The normal way to start the pigpio library would be as a daemon during boot. + +.br + +.EX +sudo pigpiod +.br + +.EE + +.br +.SS Features +.br +o hardware timed PWM on any of GPIO 0-31 + +.br +o hardware timed servo pulses on any of GPIO 0-31 + +.br +o reading/writing all of the GPIO in a bank as one operation + +.br +o individually setting GPIO modes, reading and writing + +.br +o notifications when any of GPIO 0-31 change state + +.br +o the construction of output waveforms with microsecond timing + +.br +o I2C, SPI, and serial link wrappers + +.br +o creating and running scripts on the pigpio daemon + +.br +.SS GPIO +.br +ALL GPIO are identified by their Broadcom number. + +.br +.SS Usage +.br +pigs is a program and internally uses the socket interface to pigpio +whereas /dev/pigpio uses the pipe interface. + +.br +pigs and the pipe interface share the same commands and are invoked in +a similar fashion from the command line. + +.br +The pigpio library must be running, either by running a program linked +with the library or starting the pigpio daemon (sudo pigpiod). + +.br +pigs {command}+ + +.br +echo "{command}+" >/dev/pigpio + +.br +pigs will show the result of the command on screen. + +.br +The pigs process returns an exit status (which can be displayed with +the command echo $?). + +.br + +.EX +PIGS_OK 0 +.br +PIGS_CONNECT_ERR 255 +.br +PIGS_OPTION_ERR 254 +.br +PIGS_SCRIPT_ERR 253 +.br +.br +.br + +.EE + +.br +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). + +.br +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. + +.br +Several commands may be entered on a line. If present PROC and PARSE must +be the last command on a line. + +.br +E.g. + +.br + +.EX +pigs w 22 1 mils 1000 w 22 0 +.br + +.EE + +.br +is equivalent to + +.br + +.EX +pigs w 22 1 +.br +pigs mils 1000 +.br +pigs w 22 0 +.br + +.EE + +.br +and + +.br + +.EX +echo "m 4 w w 4 0 mils 250 m 4 r r 4" >/dev/pigpio +.br + +.EE + +.br +is equivalent to + +.br + +.EX +echo "m 4 w" >/dev/pigpio +.br +echo "w 4 0" >/dev/pigpio +.br +echo "mils 250" >/dev/pigpio +.br +echo "m 4 r" >/dev/pigpio +.br +echo "r 4" >/dev/pigpio +.br + +.EE + +.br +.SS Notes +.br +The examples from now on will show the pigs interface but the same +commands will also work on the pipe interface. + +.br +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. + +.br +The status/data of each command sent to the pipe interface should +be read from /dev/pigout. + +.br +When a command takes a number as a parameter it may be entered as hex +(precede by 0x), octal (precede by 0), or decimal. + +.br +E.g. 23 is 23 decimal, 0x100 is 256 decimal, 070 is 56 decimal. + +.br +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. + +.br +E.g. assuming the transmitted serial data is the letters ABCDEONM + +.br + +.EX +$ pigs slr 4 100 +.br +8 65 66 67 68 69 79 78 77 +.br + +.br +$ pigs -a slr 4 100 +.br +8 ABCDEONM +.br + +.br +$ pigs -x slr 4 100 +.br +8 41 42 43 44 45 4f 4e 4d +.br + +.EE + +.br + +.SH OVERVIEW +.SS BASIC +.B M/MODES g m +Set GPIO mode +.P +.B MG/MODEG g +Get GPIO mode +.P +.B PUD g p +Set GPIO pull up/down +.P +.B R/READ g +Read GPIO level +.P +.B W/WRITE g L +Write GPIO level +.P +.SS PWM (overrides servo commands on same GPIO) +.B P/PWM u v +Set GPIO PWM value +.P +.B PFS u v +Set GPIO PWM frequency +.P +.B PRS u v +Set GPIO PWM range +.P +.B GDC u +Get GPIO PWM dutycycle +.P +.B PFG u +Get GPIO PWM frequency +.P +.B PRG u +Get GPIO PWM range +.P +.B PRRG u +Get GPIO PWM real range +.P +.SS Servo (overrides PWM commands on same GPIO) +.B S/SERVO u v +Set GPIO servo pulsewidth +.P +.B GPW u +Get GPIO servo pulsewidth +.P +.SS INTERMEDIATE +.B TRIG u pl L +Send a trigger pulse +.P +.B WDOG u v +Set GPIO watchdog +.P +.B BR1 +Read bank 1 GPIO +.P +.B BR2 +Read bank 2 GPIO +.P +.B BC1 bits +Clear specified GPIO in bank 1 +.P +.B BC2 bits +Clear specified GPIO in bank 2 +.P +.B BS1 bits +Set specified GPIO in bank 1 +.P +.B BS2 bits +Set specified GPIO in bank 2 +.P +.SS ADVANCED +.B NO +Request a notification +.P +.B NC h +Close notification +.P +.B NB h bits +Start notification +.P +.B NP h +Pause notification +.P +.B HC g cf +Set hardware clock frequency +.P +.B HP g pf pdc +Set hardware PWM frequency and dutycycle +.P +.B FG u stdy +Set a glitch filter on a GPIO +.P +.B FN u stdy actv +Set a noise filter on a GPIO +.P +.B PADS pad padma +Set pad drive strength +.P +.B PADG pad +Get pad drive strength +.P +.B SHELL name str +Execute a shell command +.P +.SS Custom +.B CF1 uvs +Custom function 1 +.P +.B CF2 uvs +Custom function 2 +.P +.SS Events +.B EVM h bits +Set events to monitor +.P +.B EVT event +Trigger event +.P +.SS Scripts +.B PROC t +Store script +.P +.B PROCR sid pars +Run script +.P +.B PROCU sid pars +Set script parameters +.P +.B PROCP sid +Get script status and parameters +.P +.B PROCS sid +Stop script +.P +.B PROCD sid +Delete script +.P +.B PARSE t +Validate script +.P +.SS I2C +.B I2CO ib id if +Open I2C bus and device with flags +.P +.B I2CC h +Close I2C handle +.P +.B I2CWQ h bit +smb Write Quick: write bit +.P +.B I2CRS h +smb Read Byte: read byte +.P +.B I2CWS h bv +smb Write Byte: write byte +.P +.B I2CRB h r +smb Read Byte Data: read byte from register +.P +.B I2CWB h r bv +smb Write Byte Data: write byte to register +.P +.B I2CRW h r +smb Read Word Data: read word from register +.P +.B I2CWW h r wv +smb Write Word Data: write word to register +.P +.B I2CRK h r +smb Read Block Data: read data from register +.P +.B I2CWK h r bvs +smb Write Block Data: write data to register +.P +.B I2CWI h r bvs +smb Write I2C Block Data +.P +.B I2CRI h r num +smb Read I2C Block Data: read bytes from register +.P +.B I2CRD h num +i2c Read device +.P +.B I2CWD h bvs +i2c Write device +.P +.B I2CPC h r wv +smb Process Call: exchange register with word +.P +.B I2CPK h r bvs +smb Block Process Call: exchange data bytes with register +.P +.B I2CZ h bvs +Performs multiple I2C transactions +.P +.SS I2C BIT BANG +.B BI2CO sda scl b +Open bit bang I2C +.P +.B BI2CC sda +Close bit bang I2C +.P +.B BI2CZ sda bvs +I2C bit bang multiple transactions +.P +.SS I2C/SPI SLAVE +.B BSCX bctl bvs +BSC I2C/SPI transfer +.P +.SS SERIAL +.B SERO dev b sef +Open serial device dev at baud b with flags +.P +.B SERC h +Close serial handle +.P +.B SERRB +Read byte from serial handle +.P +.B SERWB h bv +Write byte to serial handle +.P +.B SERR h num +Read bytes from serial handle +.P +.B SERW h bvs +Write bytes to serial handle +.P +.B SERDA h +Check for serial data ready to read +.P +.SS SERIAL BIT BANG (read only) +.B SLRO u b db +Open GPIO for bit bang serial data +.P +.B SLRC u +Close GPIO for bit bang serial data +.P +.B SLRI u v +Sets bit bang serial data logic levels +.P +.B SLR u num +Read bit bang serial data from GPIO +.P +.SS SPI +.B SPIO c b spf +SPI open channel at baud b with flags +.P +.B SPIC h +SPI close handle +.P +.B SPIR h num +SPI read bytes from handle +.P +.B SPIW h bvs +SPI write bytes to handle +.P +.B SPIX h bvs +SPI transfer bytes to handle +.P +.SS SPI BIT BANG +.B BSPIO cs miso mosi sclk b spf +Open bit bang SPI +.P +.B BSPIC cs +Close bit bang SPI +.P +.B BSPIX cs bvs +SPI bit bang transfer +.P +.SS FILES +.B FO file mode +Open a file in mode +.P +.B FC h +Close file handle +.P +.B FR h num +Read bytes from file handle +.P +.B FW h bvs +Write bytes to file handle +.P +.B FS h num from +Seek to file handle position +.P +.B FL pat num +List files which match pattern +.P +.SS WAVES +.B WVCLR +Clear all waveforms +.P +.B WVNEW +Initialise a new waveform +.P +.B WVAG trips +Add generic pulses to waveform +.P +.B WVAS u b db sb o bvs +Add serial data to waveform +.P +.B WVCRE +Create a waveform +.P +.B WVCAP +Create a waveform of fixed size +.P +.B WVDEL wid +Delete selected waveform +.P +.B WVTX wid +Transmits waveform once +.P +.B WVTXM wid wmde +Transmits waveform using mode +.P +.B WVTXR wid +Transmits waveform repeatedly +.P +.B WVCHA bvs +Transmits a chain of waveforms +.P +.B WVTAT +Returns the current transmitting waveform +.P +.B WVBSY +Check if waveform is being transmitted +.P +.B WVHLT +Stop waveform +.P +.B WVSC ws +Get waveform DMA CB stats +.P +.B WVSM ws +Get waveform time stats +.P +.B WVSP ws +Get waveform pulse stats +.P +.SS UTILITIES +.B H/HELP +Display command help +.P +.B HWVER +Get hardware version +.P +.B MICS v +Microseconds delay +.P +.B MILS v +Milliseconds delay +.P +.B PIGPV +Get pigpio library version +.P +.B T/TICK +Get current tick +.P +.SS CONFIGURATION +.B CGI +Configuration get internals +.P +.B CSI v +Configuration set internals +.P + +.SH COMMANDS + +.br + +.IP "\fBBC1 bits\fP - Clear specified GPIO in bank 1" +.IP "" 4 +This command clears (sets low) the GPIO specified by \fBbits\fP in bank 1. +Bank 1 consists of GPIO 0-31. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs bc1 0x400010 # clear GPIO 4 (1<<4) and 22 (1<<22) +.br + +.br +$ pigs bc1 32 # clear GPIO 5 (1<<5) +.br +-42 +.br +ERROR: no permission to update one or more GPIO +.br + +.EE + +.br + +.IP "\fBBC2 bits\fP - Clear specified GPIO in bank 2" +.IP "" 4 +This command clears (sets low) the GPIO specified by \fBbits\fP in bank 2. +Bank 2 consists of GPIO 32-53. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs bc2 0x8000 # clear GPIO 47 (activity LED on A+/B+/Pi2/Pi3) +.br + +.br +$ pigs bc2 1 # clear GPIO 32 (first in bank 2) +.br +-42 +.br +ERROR: no permission to update one or more GPIO +.br + +.EE + +.br + +.IP "\fBBI2CC sda\fP - Close bit bang I2C" +.IP "" 4 +This command signals that bit banging I2C on \fBsda\fP (and \fBscl\fP) is no +longer required. + +.br + +\fBExample\fP +.br + +.EX +$ pigs bi2cc 5 +.br + +.EE + +.br + +.IP "\fBBI2CO sda scl b\fP - Open bit bang I2C" +.IP "" 4 +This command signals that GPIO \fBsda\fP and \fBscl\fP are to be used +for bit banging I2C at \fBb\fP baud. + +.br +Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. + +.br +o baud rates as low as 50 +.br +o repeated starts +.br +o clock stretching +.br +o I2C on any pair of spare GPIO + +.br +The baud rate may be between 50 and 500000 bits per second. + +.br +The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. + +.br + +.IP "\fBBI2CZ sda bvs\fP - I2C bit bang multiple transactions" +.IP "" 4 +This function executes a sequence of bit banged I2C operations. The +operations to be performed are specified by the contents of \fBbvs\fP +which contains the concatenated command codes and associated data. + +.br +The following command codes are supported: + +.br + +.EX +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 + +.EE + +.br +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +.br +The address and flags default to 0. The address and flags maintain +their previous value until updated. + +.br +No flags are currently defined. + +.br + +\fBExample\fP +.br + +.EX +Set address 0x53 +.br +start, write 0x32, (re)start, read 6 bytes, stop +.br +Set address 0x1E +.br +start, write 0x03, (re)start, read 6 bytes, stop +.br +Set address 0x68 +.br +start, write 0x1B, (re)start, read 8 bytes, stop +.br +End +.br + +.br +0x04 0x53 +.br +0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 +.br + +.br +0x04 0x1E +.br +0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 +.br + +.br +0x04 0x68 +.br +0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 +.br + +.br +0x00 +.br + +.EE + +.br + +.IP "\fBBR1 \fP - Read bank 1 GPIO" +.IP "" 4 +This command read GPIO 0-31 (bank 1) and returns the levels as a +32-bit hexadecimal value. + +.br + +\fBExample\fP +.br + +.EX +$ pigs br1 +.br +1001C1CF +.br + +.EE + +.br + +.IP "\fBBR2 \fP - Read bank 2 GPIO" +.IP "" 4 +This command read GPIO 32-53 (bank 2) and returns the levels as a +32-bit hexadecimal value. + +.br + +\fBExample\fP +.br + +.EX +$ pigs br2 +.br +003F0000 +.br + +.EE + +.br + +.IP "\fBBS1 bits\fP - Set specified GPIO in bank 1" +.IP "" 4 +This command sets (sets high) the GPIO specified by \fBbits\fP in bank 1. +Bank 1 consists of GPIO 0-31. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs bs1 16 # set GPIO 4 (1<<4) +.br + +.br +$ pigs bs1 1 # set GPIO 1 (1<<0) +.br +-42 +.br +ERROR: no permission to update one or more GPIO +.br + +.EE + +.br + +.IP "\fBBS2 bits\fP - Set specified GPIO in bank 2" +.IP "" 4 +This command sets (sets high) the GPIO specified by \fBbits\fP in bank 2. +Bank 2 consists of GPIO 32-53. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs bs2 0x40 # set GPIO 38 (enable high current mode A+/B+/Pi2/Pi3) +.br + +.br +$ pigs bs2 1 # set GPIO 32 (first in bank 2) +.br +-42 +.br +ERROR: no permission to update one or more GPIO +.br + +.EE + +.br + +.IP "\fBBSCX bctl bvs\fP - BSC I2C/SPI transfer" +.IP "" 4 + +.br +This command performs a BSC I2C/SPI slave transfer as defined by +\fBbctl\fP with data \fBbvs\fP. + +.br +This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. + +.br +This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. + +.br +This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. + +.br +The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. + +.br +I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. + +.br +The command sets the BSC mode and writes any data \fBbvs\fP +to the BSC transmit FIFO. It returns the data count (at least 1 +for the status word), the status word, followed by any data bytes +read from the BSC receive FIFO. + +.br +Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. + +.br +For I2C use a control word of (I2C address << 16) + 0x305. + +.br +E.g. to talk as I2C slave with address 0x13 use 0x130305. + +.br +GPIO used for models other than those based on the BCM2711. + +.br + +.EX + SDA SCL MOSI SCLK MISO CE +I2C 18 19 - - - - +SPI - - 18 19 20 21 + +.EE + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.EX + SDA SCL MOSI SCLK MISO CE +I2C 10 11 - - - - +SPI - - 10 11 9 8 + +.EE + +.br +When a zero control word is received the used GPIO will be reset +to INPUT mode. + +.br +The control word consists of the following bits. + +.br + +.EX +22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN +.br + +.EE + +.br +Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. + +.br + +.EX +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 + +.EE + +.br +The returned status has the following format + +.br + +.EX +20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + S S S S S R R R R R T T T T T RB TE RF TF RE TB +.br + +.EE + +.br +Bits 0-15 are copied unchanged from the BSC FR register. See +pages 165-166 of the Broadcom peripherals document for full +details. + +.br + +.EX +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 + +.EE + +.br +This example assumes that GPIO 2/3 are connected to GPIO 18/19 +(GPIO 10/11 on the BCM2711). + +.br + +\fBExample\fP +.br + +.EX +$ pigs bscx 0x130305 # start BSC as I2C slave 0x13 +.br +1 18 +.br + +.br +$ i2cdetect -y 1 +.br + 0 1 2 3 4 5 6 7 8 9 a b c d e f +.br +00: -- -- -- -- -- -- -- -- -- -- -- -- -- +.br +10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- -- +.br +20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +.br +30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +.br +40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +.br +50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +.br +60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +.br +70: -- -- -- -- -- -- -- -- +.br + +.br +$ pigs i2co 1 0x13 0 # get handle for device 0x13 on bus 1 +.br +0 +.br + +.br +$ pigs i2cwd 0 90 87 51 9 23 # write 5 bytes +.br + +.br +$ pigs bscx 0x130305 # check for data +.br +6 18 90 87 51 9 23 +.br + +.br +$ pigs bscx 0x130305 11 13 15 17 # check for data and send 4 bytes +.br +1 262338 +.br + +.br +$ pigs i2crd 0 4 # read 4 bytes +.br +4 11 13 15 17 +.br + +.br +$ pigs i2cwd 0 90 87 51 9 23 # write 5 bytes +.br +$ pigs bscx 0x130305 11 13 15 17 # check for data and send 4 bytes +.br +6 262338 90 87 51 9 23 +.br + +.br +$ pigs i2crd 0 4 +.br +4 11 13 15 17 +.br + +.br +$ pigs bscx 0x130305 22 33 44 55 66 +.br +1 327938 +.br +$ pigs i2crd 0 5 +.br +5 22 33 44 55 66 +.br + +.EE + +.br + +.IP "\fBBSPIC cs\fP - Close bit bang SPI" +.IP "" 4 + +.br +This command stops bit banging SPI on a set of GPIO +opened with \fBBSPIO\fP. + +.br +The set of GPIO is specifed by \fBcs\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs bspic 10 +.br + +.br +$ pigs bspic 10 +.br +-142 +.br +ERROR: no bit bang SPI in progress on GPIO +.br + +.EE + +.br + +.IP "\fBBSPIO cs miso mosi sclk b spf\fP - Open bit bang SPI" +.IP "" 4 + +.br +This command starts bit banging SPI on a group of GPIO with slave +select \fBcs\fP, MISO \fBmiso\fP, MOSI \fBmosi\fP, and clock \fBsclk\fP. + +.br +Data will be transferred at baud \fBb\fP bits per second (which may +be set in the range 50-250000). + +.br +The flags \fBspf\fP may be used to modify the default behaviour of +mode 0, active low chip select. + +.br +The flags consists of the least significant 22 bits. + +.br + +.EX +21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m +.br + +.EE + +.br +mm defines the SPI mode. + +.br + +.EX +Mode POL PHA +.br + 0 0 0 +.br + 1 0 1 +.br + 2 1 0 +.br + 3 1 1 +.br + +.EE + +.br +p is 0 if CS is active low (default) and 1 for active high. + +.br +T is 1 if the least significant bit is transmitted on MOSI first, the +default (0) shifts the most significant bit out first. + +.br +R is 1 if the least significant bit is received on MISO first, the +default (0) receives the most significant bit first. + +.br +The other bits in flags should be set to zero. + +.br +Upon success 0 is returned. On error a negative status code +will be returned. + +.br +If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. + +.br + +\fBExample\fP +.br + +.EX +$ pigs bspio 9 11 12 13 50000 0 +.br + +.br +$ pigs bspio 10 11 12 13 50000 0 +.br + +.br +$ pigs bspio 29 19 20 21 50000 0 # GPIO 29 not avaialble on this Pi +.br +-41 +.br +ERROR: no permission to update GPIO +.br + +.EE + +.br + +.IP "\fBBSPIX cs bvs\fP - SPI bit bang transfer" +.IP "" 4 + +.br +This command writes bytes \fBbvs\fP to the bit bang SPI device +associated with slave select \fBcs\fP. It returns the same +number of bytes read from the device. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs bspio 5 13 19 12 10000 0 # MCP4251 DAC +.br +$ pigs bspio 6 13 19 12 20000 3 # MCP3008 ADC +.br + +.br +$ pigs bspix 5 0 16 # set DAC to 16 +.br +2 255 255 +.br + +.br +$ pigs bspix 5 12 0 # read back DAC +.br +2 254 16 +.br + +.br +$ pigs bspix 6 1 128 0 # read ADC input 0 +.br +3 0 3 184 # 952 +.br + +.br +$ pigs bspix 5 0 240 # set DAC to 240 +.br +2 255 255 +.br + +.br +$ pigs bspix 5 12 0 # read back DAC +.br +2 254 240 +.br + +.br +$ pigs bspix 6 1 128 0 # read ADC input 0 +.br +3 0 0 63 # 63 +.br + +.br +$ pigs bspix 5 0 128 # set DAC to 128 +.br +2 255 255 +.br + +.br +$ pigs bspix 5 12 0 # read back DAC +.br +2 254 128 +.br + +.br +$ pigs bspix 6 1 128 0 # read ADC input 0 +.br +3 0 1 255 # 511 +.br + +.br +$ pigs bspic 5 # close SPI CS 5 +.br +$ pigs bspic 6 # close SPI CS 6 +.br + +.br +$ pigs bspic 5 # try to close SPI CS 5 again +.br +-142 +.br +ERROR: no bit bang SPI in progress on GPIO +.br + +.EE + +.br + +.br + +.IP "\fBCF1 uvs\fP - Custom function 1" +.IP "" 4 + +.br +This command calls a user customised function. The meaning of +any paramaters and the returned value is defined by the +customiser. + +.br + +.IP "\fBCF2 uvs\fP - Custom function 2" +.IP "" 4 + +.br +This command calls a user customised function. The meaning of +any paramaters and the returned value is defined by the +customiser. + +.br + +.IP "\fBCGI \fP - Configuration get internals" +.IP "" 4 +This command returns the value of the internal library +configuration settings. + +.br + +.IP "\fBCSI v\fP - Configuration set internals" +.IP "" 4 +This command sets the value of the internal library +configuration settings to \fBv\fP. + +.br + +.IP "\fBEVM h bits\fP - Set events to monitor" +.IP "" 4 +This command starts event reporting on handle \fBh\fP (returned by +a prior call to \fBNO\fP). + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The notification gets reports for each event specified by \fBbits\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs evm 0 -1 # Shorthand for events 0-31. +.br +$ pigs evm 0 0xf0 # Get notifications for events 4-7. +.br + +.br +$ pigs evm 1 0xf +.br +-25 +.br +ERROR: unknown handle +.br + +.EE + +.br + +.IP "\fBEVT event\fP - Trigger event" +.IP "" 4 +This command triggers event \fBevent\fP. + +.br +One event, number 31, is predefined. This event is +auto generated on BSC slave activity. + +.br + +\fBExample\fP +.br + +.EX +$ pigs evt 12 +.br +$ pigs evt 5 +.br + +.br +$ pigs evt 32 +.br +-143 +.br +ERROR: bad event id +.br + +.EE + +.br + +.IP "\fBFC h\fP - Close file handle" +.IP "" 4 +This command closes a file handle \fBh\fP previously opened with \fBFO\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fc 0 # First close okay. +.br + +.br +$ pigs fc 0 # Second fails. +.br +-25 +.br +ERROR: unknown handle +.br + +.EE + +.br + +.IP "\fBFG u stdy\fP - Set a glitch filter on a GPIO" +.IP "" 4 + +.br +Level changes on the GPIO \fBu\fP are not reported unless the level +has been stable for at least \fBstdy\fP microseconds. The +level is then reported. Level changes of less than \fBstdy\fP +microseconds are ignored. + +.br +The filter only affects callbacks (including pipe notifications). + +.br +The \fBR/READ\fP, \fBBR1\fP, and \fBBR2\fP commands are not affected. + +.br +Note, each (stable) edge will be timestamped \fBstdy\fP microseconds +after it was first detected. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fg 4 250 +.br + +.br +$ pigs fg 4 1000000 +.br +-125 +.br +ERROR: bad filter parameter +.br + +.EE + +.br + +.IP "\fBFL pat num\fP - List files which match pattern" +.IP "" 4 +This command returns a list of the files matching \fBpat\fP. Up +to \fBnum\fP bytes may be returned. + +.br +Upon success the count of returned bytes followed by the matching +files is returned. On error a negative status code will be returned. + +.br +A newline (0x0a) character separates each file name. + +.br +Only files which have a matching entry in /opt/pigpio/access may +be listed. + +.br +Suppose /opt/pigpio/access contains + +.br +/sys/bus/w1/devices/28*/w1_slave r + +.br + +\fBExample\fP +.br + +.EX +$ pigs -a fl "/sys/bus/w1/devices/28*/w1_slave" 5000 +.br +90 /sys/bus/w1/devices/28-000005d34cd2/w1_slave +.br +/sys/bus/w1/devices/28-001414abbeff/w1_slave +.br + +.br +$ pigs -a fl "/sys/bus/*" 5000 +.br +ERROR: no permission to access file +.br +-137 +.br + +.EE + +.br + +.IP "\fBFN u stdy actv\fP - Set a noise filter on a GPIO" +.IP "" 4 + +.br +Level changes on the GPIO \fBu\fP are ignored until a level which has +been stable for \fBstdy\fP microseconds is detected. Level +changes on the GPIO are then reported for \fBactv\fP microseconds +after which the process repeats. + +.br +The filter only affects callbacks (including pipe notifications). + +.br +The \fBR/READ\fP, \fBBR1\fP, and \fBBR2\fP commands are not affected. + +.br +Note, level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fn 7 250 1000 +.br + +.br +$ pigs fn 7 2500000 1000 +.br +-125 +.br +ERROR: bad filter parameter +.br + +.EE + +.br + +.IP "\fBFO file mode\fP - Open a file in mode" +.IP "" 4 +This function returns a handle to a file \fBfile\fP opened +in a specified mode \fBmode\fP. + +.br +Upon success a handle (>=0) is returned. On error a negative status code +will be returned. + +.br +File + +.br +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +.br +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +.br +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +.br +Suppose /opt/pigpio/access contains the following entries + +.br + +.EX +/home/* n +.br +/home/pi/shared/dir_1/* w +.br +/home/pi/shared/dir_2/* r +.br +/home/pi/shared/dir_3/* u +.br +/home/pi/shared/dir_1/file.txt n +.br + +.EE + +.br +Files may be written in directory dir_1 with the exception +of file.txt. + +.br +Files may be read in directory dir_2. + +.br +Files may be read and written in directory dir_3. + +.br +If a directory allows read, write, or read/write access then files may +be created in that directory. + +.br +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +.br + +.EX +a path containing .. +.br +a path containing only wildcards (*?) +.br +a path containing less than two non-wildcard parts +.br + +.EE + +.br +Mode + +.br +The mode may have the following values. + +.br + +.EX + Value Meaning +READ 1 open file for reading +WRITE 2 open file for writing +RW 3 open file for reading and writing + +.EE + +.br +The following values may be or'd into the mode. + +.br + +.EX + 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 + +.EE + +.br +Newly created files are owned by root with permissions owner read and write. + +.br + +\fBExample\fP +.br + +.EX +$ ls /ram/*.c +.br +/ram/command.c /ram/pigpiod.c /ram/pigs.c +.br +/ram/x_pigpiod_if.c /ram/pig2vcd.c /ram/pigpiod_if2.c +.br +/ram/x_pigpio.c /ram/x_repeat.c /ram/pigpio.c +.br +/ram/pigpiod_if.c /ram/x_pigpiod_if2.c +.br + +.br +# assumes /opt/pigpio/access contains the following line +.br +# /ram/*.c r +.br + +.br +$ pigs fo /ram/pigpio.c 1 +.br +0 +.br + +.br +$ pigs fo /ram/new.c 1 +.br +-128 +.br +ERROR: file open failed +.br + +.br +$ pigs fo /ram/new.c 9 +.br +1 +.br + +.br +$ ls /ram/*.c -l +.br +-rw-r--r-- 1 joan joan 42923 Jul 10 11:22 /ram/command.c +.br +-rw------- 1 root root 0 Jul 10 16:54 /ram/new.c +.br +-rw-r--r-- 1 joan joan 2971 Jul 10 11:22 /ram/pig2vcd.c +.br +-rw------- 1 joan joan 296235 Jul 10 11:22 /ram/pigpio.c +.br +-rw-r--r-- 1 joan joan 9266 Jul 10 11:22 /ram/pigpiod.c +.br +-rw-r--r-- 1 joan joan 37331 Jul 10 11:22 /ram/pigpiod_if2.c +.br +-rw-r--r-- 1 joan joan 33088 Jul 10 11:22 /ram/pigpiod_if.c +.br +-rw-r--r-- 1 joan joan 7990 Jul 10 11:22 /ram/pigs.c +.br +-rw-r--r-- 1 joan joan 19970 Jul 10 11:22 /ram/x_pigpio.c +.br +-rw-r--r-- 1 joan joan 20804 Jul 10 11:22 /ram/x_pigpiod_if2.c +.br +-rw-r--r-- 1 joan joan 19844 Jul 10 11:22 /ram/x_pigpiod_if.c +.br +-rw-r--r-- 1 joan joan 19907 Jul 10 11:22 /ram/x_repeat.c +.br + +.EE + +.br + +.IP "\fBFR h num\fP - Read bytes from file handle" +.IP "" 4 +This command returns up to \fBnum\fP bytes of data read from the +file associated with handle \fBh\fP. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fr 0 10 +.br +5 48 49 128 144 255 +.br + +.br +$ pigs fr 0 10 +.br +0 +.br + +.EE + +.br + +.IP "\fBFS h num from\fP - Seek to file handle position" +.IP "" 4 +This command seeks to a position within the file associated +with handle \fBh\fP. + +.br +The number of bytes to move is \fBnum\fP. Positive offsets +move forward, negative offsets backwards. The move start +position is determined by \fBfrom\fP as follows. + +.br + +.EX + From +0 start +1 current position +2 end + +.EE + +.br +Upon success the new byte position within the file (>=0) is +returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fs 0 200 0 # Seek to start of file plus 200 +.br +200 +.br + +.br +$ pigs fs 0 0 1 # Return current position +.br +200 +.br + +.br +$ pigs fs 0 0 2 # Seek to end of file, return size +.br +296235 +.br + +.EE + +.br + +.IP "\fBFW h bvs\fP - Write bytes to file handle" +.IP "" 4 +This command writes bytes \fBbvs\fP to the file +associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fw 0 23 45 67 89 +.br + +.EE + +.br + +.IP "\fBGDC u\fP - Get GPIO PWM dutycycle" +.IP "" 4 + +.br +This command returns the PWM dutycycle in use on GPIO \fBu\fP. + +.br +Upon success the dutycycle is returned. On error a negative +status code will be returned. + +.br +For normal PWM the dutycycle will be out of the defined range +for the GPIO (see \fBPRG\fP). + +.br +If a hardware clock is active on the GPIO the reported +dutycycle will be 500000 (500k) out of 1000000 (1M). + +.br +If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). + +.br + +\fBExample\fP +.br + +.EX +$ pigs p 4 129 +.br +$ pigs gdc 4 +.br +129 +.br + +.br +pigs gdc 5 +.br +-92 +.br +ERROR: GPIO is not in use for PWM +.br + +.EE + +.br + +.IP "\fBGPW u\fP - Get GPIO servo pulsewidth" +.IP "" 4 + +.br +This command returns the servo pulsewidth in use on GPIO \fBu\fP. + +.br +Upon success the servo pulsewidth is returned. On error a negative +status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs s 4 1235 +.br +$ pigs gpw 4 +.br +1235 +.br + +.br +$ pigs gpw 9 +.br +-93 +.br +ERROR: GPIO is not in use for servo pulses +.br + +.EE + +.br + +.IP "\fBH/HELP \fP - Display command help" +.IP "" 4 +This command displays a brief list of the commands and their parameters. + +.br + +\fBExample\fP +.br + +.EX +$ pigs h +.br + +.br +$ pigs help +.br + +.EE + +.br + +.IP "\fBHC g cf\fP - Set hardware clock frequency" +.IP "" 4 +This command sets the hardware clock associated with GPIO \fBg\fP to +frequency \fBcf\fP. Frequencies above 30MHz are unlikely to work. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs hc 4 5000 # start a 5 KHz clock on GPIO 4 (clock 0) +.br + +.br +$ pigs hc 5 5000000 # start a 5 MHz clcok on GPIO 5 (clock 1) +.br +-99 +.br +ERROR: need password to use hardware clock 1 +.br + +.EE + +.br +The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. + +.br +The GPIO must be one of the following. + +.br + +.EX +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) + +.EE + +.br + +.EX +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) + +.EE + +.br +Access to clock 1 is protected by a password as its use will +likely crash the Pi. The password is given by or'ing 0x5A000000 +with the GPIO number. + +.br + +.IP "\fBHP g pf pdc\fP - Set hardware PWM frequency and dutycycle" +.IP "" 4 +This command sets the hardware PWM associated with GPIO \fBg\fP to +frequency \fBpf\fP with dutycycle \fBpdc\fP. Frequencies above 30MHz +are unlikely to work. + +.br +NOTE: Any waveform started by \fBWVTX\fP, \fBWVTXR\fP, or \fBWVCHA\fP +will be cancelled. + +.br +This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +.EX +$ pigs hp 18 100 800000 # 80% dutycycle +.br + +.br +$ pigs hp 19 100 200000 # 20% dutycycle +.br + +.br +$ pigs hp 19 400000000 100000 +.br +-96 +.br +ERROR: invalid hardware PWM frequency +.br + +.EE + +.br +The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. + +.br +The GPIO must be one of the following. + +.br + +.EX +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 + +.EE + +.br + +.EX +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 + +.EE + +.br +The actual number of steps beween off and fully on is the +integral part of 250M/\fBpf\fP (375M/\fBpf\fP for the BCM2711). + +.br +The actual frequency set is 250M/steps (375M/steps for the BCM2711). + +.br +There will only be a million steps for a \fBpf\fP of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. \fBpdc\fP is +automatically scaled to take this into account. + +.br + +.IP "\fBHWVER \fP - Get hardware version" +.IP "" 4 +This command returns the hardware revision of the Pi. + +.br +The hardware revision is found in the last 4 characters on the revision +line of /proc/cpuinfo. + +.br +If the hardware revision can not be found or is not a valid hexadecimal +number the command returns 0. + +.br +The revision number can be used to determine the assignment of GPIO +to pins (see \fBg\fP). + +.br +There are currently three types of board. + +.br +Type 1 boards have hardware revision numbers of 2 and 3. + +.br +Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. + +.br +Type 3 boards have hardware revision numbers of 16 or greater. + +.br +for "Revision : 0002" the command returns 2. + +.br +for "Revision : 000f" the command returns 15. + +.br +for "Revision : 000g" the command returns 0. + +.br + +\fBExample\fP +.br + +.EX +$ pigs hwver # On a B+ +.br +16 +.br + +.EE + +.br + +.IP "\fBI2CC h\fP - Close I2C handle" +.IP "" 4 +This command closes an I2C handle \fBh\fP previously opened with \fBI2CO\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cc 0 # First close okay. +.br + +.br +$ pigs i2cc 0 # Second fails. +.br +-25 +.br +ERROR: unknown handle +.br + +.EE + +.br + +.IP "\fBI2CO ib id if\fP - Open I2C bus and device with flags" +.IP "" 4 +This command returns a handle to access device \fBid\fP on I2C bus \fBib\fP. +The device is opened with flags \fBif\fP. + +.br +Physically buses 0 and 1 are available on the Pi. Higher +numbered buses will be available if a kernel supported bus +multiplexor is being used. + +.br +The GPIO used are given in the following table. + +.br + +.EX + SDA SCL +I2C 0 0 1 +I2C 1 2 3 + +.EE + +.br +No flags are currently defined. The parameter \fBif\fP should be 0. + +.br +Upon success the next free handle (>=0) is returned. On error a +negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2co 1 0x70 0 # Bus 1, device 0x70, flags 0. +.br +0 +.br + +.br +$ pigs i2co 1 0x53 0 # Bus 1, device 0x53, flags 0. +.br +1 +.br + +.EE + +.br + +.IP "\fBI2CPC h r wv\fP - smb Process Call: exchange register with word" +.IP "" 4 +This command writes \fBwv\fP to register \fBr\fP of the I2C device +associated with handle \fBh\fP and returns a 16-bit word read from the +device. + +.br +Upon success a value between 0 and 65535 will be returned. On error +a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cpc 0 37 43210 +.br +39933 +.br + +.br +$ pigs i2cpc 0 256 43210 +.br +ERROR: bad i2c/spi/ser parameter +.br +-81 +.br + +.EE + +.br + +.IP "\fBI2CPK h r bvs\fP - smb Block Process Call: exchange data bytes with register" +.IP "" 4 + +.br +This command writes the data bytes \fBbvs\fP to register \fBr\fP of the I2C device +associated with handle \fBh\fP and returns a device specific number of bytes. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cpk 0 0 0x11 0x12 +.br +6 0 0 0 0 0 0 +.br + +.EE + +.br + +.IP "\fBI2CRB h r\fP - smb Read Byte Data: read byte from register" +.IP "" 4 + +.br +This command returns a single byte read from register \fBr\fP of the I2C device +associated with handle \fBh\fP. + +.br +Upon success a value between 0 and 255 will be returned. On error +a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2crb 0 0 +.br +6 +.br + +.EE + +.br + +.IP "\fBI2CRD h num\fP - i2c Read device" +.IP "" 4 + +.br +This command returns \fBnum\fP bytes read from the I2C device associated with +handle \fBh\fP. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br +This command operates on the raw I2C device. The maximum value of the +parameter \fBnum\fP is dependent on the I2C drivers and the device +itself. pigs imposes a limit of about 8000 bytes. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2crd 0 16 +.br +16 6 24 0 0 0 0 0 0 0 0 0 0 0 0 32 78 +.br + +.EE + +.br + +.IP "\fBI2CRI h r num\fP - smb Read I2C Block Data: read bytes from register" +.IP "" 4 + +.br +This command returns \fBnum\fP bytes from register \fBr\fP of the I2C device +associated with handle \fBh\fP. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br +The parameter \fBnum\fP may be 1-32. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cri 0 0 16 +.br +16 237 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 +.br + +.EE + +.br + +.IP "\fBI2CRK h r\fP - smb Read Block Data: read data from register" +.IP "" 4 + +.br +This command returns between 1 and 32 bytes read from register \fBr\fP of +the I2C device associated with handle \fBh\fP. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br +The number of bytes of returned data is specific to the device and +register. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2crk 0 0 +.br +6 0 0 0 0 0 0 +.br + +.br +$ pigs i2crk 0 1 +.br +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 +.br + +.EE + +.br + +.IP "\fBI2CRS h\fP - smb Read Byte: read byte" +.IP "" 4 + +.br +This command returns a single byte read from the I2C device +associated with handle \fBh\fP. + +.br +Upon success a value between 0 and 255 will be returned. On error +a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2crs 0 +.br +0 +.br + +.EE + +.br + +.IP "\fBI2CRW h r\fP - smb Read Word Data: read word from register" +.IP "" 4 + +.br +This command returns a single 16 bit word read from register \fBr\fP of +the I2C device associated with handle \fBh\fP. + +.br +Upon success a value between 0 and 65535 will be returned. On error +a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2crw 0 0 +.br +6150 +.br + +.EE + +.br + +.IP "\fBI2CWB h r bv\fP - smb Write Byte Data: write byte to register" +.IP "" 4 + +.br +This command writes a single byte \fBbv\fP to register \fBr\fP of the +I2C device associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cwb 0 10 0x54 +.br + +.EE + +.br + +.IP "\fBI2CWD h bvs\fP - i2c Write device" +.IP "" 4 + +.br +This command writes a block of bytes \fBbvs\fP to the I2C device +associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The number of bytes which may be written in one transaction is +dependent on the I2C drivers and the device itself. pigs imposes +a limit of about 500 bytes. + +.br +This command operates on the raw I2C device. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cwd 0 0x01 0x02 0x03 0x04 +.br + +.EE + +.br + +.IP "\fBI2CWI h r bvs\fP - smb Write I2C Block Data" +.IP "" 4 + +.br +This command writes between 1 and 32 bytes \fBbvs\fP to register \fBr\fP of +the I2C device associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cwi 0 4 0x01 0x04 0xc0 +.br + +.EE + +.br + +.IP "\fBI2CWK h r bvs\fP - smb Write Block Data: write data to register" +.IP "" 4 + +.br +This command writes between 1 and 32 bytes \fBbvs\fP to register \fBr\fP of +the I2C device associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +pigs i2cwk 0 4 0x01 0x04 0xc0 +.br + +.EE + +.br + +.IP "\fBI2CWQ h bit\fP - smb Write Quick: write bit" +.IP "" 4 + +.br +This command writes a single \fBbit\fP to the I2C device associated +with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cwq 0 1 +.br + +.EE + +.br + +.IP "\fBI2CWS h bv\fP - smb Write Byte: write byte" +.IP "" 4 + +.br +This command writes a single byte \fBbv\fP to the I2C device associated +with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cws 0 0x12 +.br + +.br +$ pigs i2cws 0 0xff +.br +-82 +.br +ERROR: I2C write failed +.br + +.EE + +.br + +.IP "\fBI2CWW h r wv\fP - smb Write Word Data: write word to register" +.IP "" 4 + +.br +This command writes a single 16 bit word \fBwv\fP to register \fBr\fP of +the I2C device associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs i2cww 0 0 0xffff +.br + +.EE + +.br + +.IP "\fBI2CZ h bvs\fP - Performs multiple I2C transactions" +.IP "" 4 +This command executes a sequence of I2C operations. The +operations to be performed are specified by the contents of \fBbvs\fP +which contains the concatenated command codes and associated data. + +.br +The following command codes are supported: + +.br + +.EX +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 + +.EE + +.br +The address, read, and write commands take a parameter P. +Normally P is one byte (0-255). If the command is preceded by +the Escape command then P is two bytes (0-65535, least significant +byte first). + +.br +The address defaults to that associated with the handle \fBh\fP. +The flags default to 0. The address and flags maintain their +previous value until updated. + +.br + +\fBExample\fP +.br + +.EX +Set address 0x53, write 0x32, read 6 bytes +.br +Set address 0x1E, write 0x03, read 6 bytes +.br +Set address 0x68, write 0x1B, read 8 bytes +.br +End +.br + +.br +0x04 0x53 0x07 0x01 0x32 0x06 0x06 +.br +0x04 0x1E 0x07 0x01 0x03 0x06 0x06 +.br +0x04 0x68 0x07 0x01 0x1B 0x06 0x08 +.br +0x00 +.br + +.EE + +.br + +.br + +.IP "\fBM/MODES g m\fP - Set GPIO mode" +.IP "" 4 + +.br +This command sets GPIO \fBg\fP to mode \fBm\fP, typically input (read) +or output (write). + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +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. + +.br +To set the mode use the code for the mode. + +.br + +.EX +Mode Input Output ALT0 ALT1 ALT2 ALT3 ALT4 ALT5 +Code R W 0 1 2 3 4 5 + +.EE + +.br + +\fBExample\fP +.br + +.EX +$ pigs m 4 r # Input (read) +.br +$ pigs m 4 w # Output (write) +.br +$ pigs m 4 0 # ALT 0 +.br +$ pigs m 4 5 # ALT 5 +.br + +.EE + +.br + +.IP "\fBMG/MODEG g\fP - Get GPIO mode" +.IP "" 4 + +.br +This command returns the current mode of GPIO \fBg\fP. + +.br +Upon success the value of the GPIO mode is returned. +On error a negative status code will be returned. + +.br + +.EX +Value 0 1 2 3 4 5 6 7 +Mode Input Output ALT5 ALT4 ALT0 ALT1 ALT2 ALT3 + +.EE + +.br + +\fBExample\fP +.br + +.EX +$ pigs mg 4 +.br +1 +.br + +.EE + +.br + +.IP "\fBMICS v\fP - Microseconds delay" +.IP "" 4 +This command delays execution for \fBv\fP microseconds. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The main use of this command is expected to be within \fBScripts\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs mics 20 # Delay 20 microseconds. +.br +$ pigs mics 1000000 # Delay 1 second. +.br + +.br +$ pigs mics 2000000 +.br +-64 +.br +ERROR: bad MICS delay (too large) +.br + +.EE + +.br + +.IP "\fBMILS v\fP - Milliseconds delay" +.IP "" 4 + +.br +This command delays execution for \fBv\fP milliseconds. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs mils 2000 # Delay 2 seconds. +.br + +.br +$ pigs mils 61000 +.br +-65 +.br +ERROR: bad MILS delay (too large) +.br + +.EE + +.br + +.IP "\fBNB h bits\fP - Start notification" +.IP "" 4 + +.br +This command starts notifications on handle \fBh\fP returned by +a prior call to \fBNO\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The notification gets state changes for each GPIO specified by \fBbits\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs nb 0 -1 # Shorthand for GPIO 0-31. +.br +$ pigs nb 0 0xf0 # Get notifications for GPIO 4-7. +.br + +.br +$ pigs nb 1 0xf +.br +-25 +.br +ERROR: unknown handle +.br + +.EE + +.br + +.IP "\fBNC h\fP - Close notification" +.IP "" 4 + +.br +This command stops notifications on handle \fBh\fP returned by +a prior call to \fBNO\fP and releases the handle for reuse. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs nc 0 # First call succeeds. +.br + +.br +$ pigs nc 1 # Second call fails. +.br +-25 +.br +ERROR: unknown handle +.br + +.EE + +.br + +.IP "\fBNO \fP - Request a notification" +.IP "" 4 + +.br +This command requests a free notification handle. + +.br +A notification is a method for being notified of GPIO state changes via a pipe. + +.br +Upon success the command returns a handle greater than or equal to zero. +On error a negative status code will be returned. + +.br +Notifications for handle x will be available at the pipe named /dev/pigpiox +(where x is the handle number). + +.br +E.g. if the command returns 15 then the notifications must be read +from /dev/pigpio15. + +.br + +\fBExample\fP +.br + +.EX +$ pigs no +.br +0 +.br + +.EE + +.br + +.IP "\fBNP h\fP - Pause notification" +.IP "" 4 + +.br +This command pauses notifications on handle \fBh\fP returned by +a prior call to \fBNO\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +Notifications for the handle are suspended until a new \fBNB\fP command +is given for the handle. + +.br + +\fBExample\fP +.br + +.EX +$ pigs np 0 +.br + +.EE + +.br + +.IP "\fBP/PWM u v\fP - Set GPIO PWM value" +.IP "" 4 + +.br +This command starts PWM on GPIO \fBu\fP with dutycycle \fBv\fP. The dutycycle +varies from 0 (off) to range (fully on). The range defaults to 255. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +This and the servo functionality use the DMA and PWM or PCM peripherals +to control and schedule the pulsewidths and dutycycles. + +.br +The \fBPRS\fP command may be used to change the default range of 255. + +.br + +\fBExample\fP +.br + +.EX +$ pigs p 4 64 # Start PWM on GPIO 4 with 25% dutycycle +.br +$ pigs p 4 128 # 50% +.br +$ pigs p 4 192 # 75% +.br +$ pigs p 4 255 # 100% +.br + +.EE + +.br + +.IP "\fBPADG pad\fP - Get pad drive strength" +.IP "" 4 + +.br +This command gets the \fBpad\fP drive strength \fBpadma\fP in mA. + +.br +Returns the pad drive strength if OK. On error a negative status code +will be returned. + +.br + +.EX +Pad GPIO +0 0-27 +1 28-45 +2 46-53 + +.EE + +.br + +\fBExample\fP +.br + +.EX +$ pigs padg 0 +.br +8 +.br +$ pigs pads 0 16 +.br +$ pigs padg 0 +.br +16 +.br +pigs padg 3 +.br +-126 +.br +ERROR: bad pad number +.br + +.EE + +.br + +.IP "\fBPADS pad padma\fP - Set pad drive strength" +.IP "" 4 + +.br +This command sets the \fBpad\fP drive strength \fBpadma\fP in mA. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +.EX +Pad GPIO +0 0-27 +1 28-45 +2 46-53 + +.EE + +.br + +\fBExample\fP +.br + +.EX +$ pigs pads 0 16 +.br +$ pigs padg 0 +.br +16 +.br +$ pigs pads 0 17 +.br +-127 +.br +ERROR: bad pad drive strength +.br + +.EE + +.br + +.IP "\fBPARSE t\fP - Validate script" +.IP "" 4 + +.br +Validates the text \fBt\fP of a script without storing the script. + +.br +Upon success nothing is returned. On error a list of detected +script errors will be given. + +.br +See \fBScripts\fP. + +.br +This command may be used to find script syntax faults. + +.br + +\fBExample\fP +.br + +.EX +$ pigs parse tag 100 w 22 1 mils 200 w 22 0 mils 800 jmp 100 +.br + +.br +$ pigs parse tag 0 w 22 1 mills 50 w 22 0 dcr p10 jp 99 +.br +Unknown command: mills +.br +Unknown command: 50 +.br +Bad parameter to dcr +.br +Can't resolve tag 99 +.br + +.EE + +.br + +.IP "\fBPFG u\fP - Get GPIO PWM frequency" +.IP "" 4 + +.br +This command returns the PWM frequency in Hz used for GPIO \fBu\fP. + +.br +Upon success the PWM frequency is returned. On error a negative +status code will be returned. + +.br +For normal PWM the frequency will be that defined for the GPIO +by \fBPFS\fP. + +.br +If a hardware clock is active on the GPIO the reported frequency +will be that set by \fBHC\fP. + +.br +If hardware PWM is active on the GPIO the reported frequency +will be that set by \fBHP\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs pfg 4 +.br +800 +.br + +.br +$ pigs pfg 34 +.br +ERROR: GPIO not 0-31 +.br +-2 +.br + +.EE + +.br + +.IP "\fBPFS u v\fP - Set GPIO PWM frequency" +.IP "" 4 +This command sets the PWM frequency \fBv\fP to be used for GPIO \fBu\fP. + +.br +The numerically closest frequency to \fBv\fP will be selected. + +.br +Upon success the new frequency is returned. On error a negative status code +will be returned. + +.br +If PWM is currently active on the GPIO it will be +switched off and then back on at the new frequency. + +.br +Each GPIO can be independently set to one of 18 different PWM +frequencies. + +.br +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. + +.br +The frequencies for each sample rate are: + +.br + +.EX + Hertz +.br + +.br + 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 +.br + 1250 1000 800 500 400 250 200 100 50 +.br + +.br + 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 +.br + 625 500 400 250 200 125 100 50 25 +.br + +.br + 4: 10000 5000 2500 2000 1250 1000 625 500 400 +.br + 313 250 200 125 100 63 50 25 13 +.br +sample +.br + rate +.br + (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 +.br + 250 200 160 100 80 50 40 20 10 +.br + +.br + 8: 5000 2500 1250 1000 625 500 313 250 200 +.br + 156 125 100 63 50 31 25 13 6 +.br + +.br + 10: 4000 2000 1000 800 500 400 250 200 160 +.br + 125 100 80 50 40 25 20 10 5 +.br + +.EE + +.br + +\fBExample\fP +.br + +.EX +pigs pfs 4 0 # 0 selects the lowest frequency. +.br +10 +.br + +.br +$ pigs pfs 4 1000 # Set 1000Hz PWM. +.br +1000 +.br + +.br +$ pigs pfs 4 100000 # Very big number selects the highest frequency. +.br +8000 +.br + +.EE + +.br + +.IP "\fBPIGPV \fP - Get pigpio library version" +.IP "" 4 + +.br +This command returns the pigpio library version. + +.br + +\fBExample\fP +.br + +.EX +$ pigs pigpv +.br +17 +.br + +.EE + +.br + +.IP "\fBPRG u\fP - Get GPIO PWM range" +.IP "" 4 + +.br +This command returns the dutycycle range for GPIO \fBu\fP. + +.br +Upon success the range is returned. On error a negative status code +will be returned. + +.br +If a hardware clock or hardware PWM is active on the GPIO the reported +range will be 1000000 (1M). + +.br + +\fBExample\fP +.br + +.EX +$ pigs prg 4 +.br +255 +.br + +.EE + +.br + +.IP "\fBPROC t\fP - Store script" +.IP "" 4 + +.br +This command stores a script \fBt\fP for later execution. + +.br +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. + +.br +See \fBScripts\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123 +.br +0 +.br + +.br +$ pigs proc tag 123 w 4 0 mils 5 w 4 1 mils 5 jmp 12 +.br +ERROR: script has unresolved tag +.br +-63 +.br + +.EE + +.br + +.IP "\fBPROCD sid\fP - Delete script" +.IP "" 4 + +.br +This command deletes script \fBsid\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +See \fBScripts\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs procd 1 +.br + +.br +$ pigs procd 1 +.br +ERROR: unknown script id +.br +-48 +.br + +.EE + +.br + +.IP "\fBPROCP sid\fP - Get script status and parameters" +.IP "" 4 + +.br +This command returns the status of script \fBsid\fP as well as the +current value of its 10 parameters. + +.br +Upon success the script status and parameters are returned. +On error a negative status code will be returned. + +.br +The script status may be one of + +.br + +.EX +0 being initialised +1 halted +2 running +3 waiting +4 failed + +.EE + +.br +See \fBScripts\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs procp 0 +.br +1 0 0 0 0 0 0 0 0 0 0 +.br + +.EE + +.br + +.IP "\fBPROCR sid pars\fP - Run script" +.IP "" 4 + +.br +This command runs stored script \fBsid\fP passing it up to 10 optional +parameters. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +See \fBScripts\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123 +.br +0 +.br + +.br +$ pigs procr 0 50 # Run script 0 with parameter 0 of 50. +.br + +.br +$ pigs procp 0 +.br +2 44 0 0 0 0 0 0 0 0 0 +.br +$ pigs procp 0 +.br +2 37 0 0 0 0 0 0 0 0 0 +.br +$ pigs procp 0 +.br +2 10 0 0 0 0 0 0 0 0 0 +.br +$ pigs procp 0 +.br +2 5 0 0 0 0 0 0 0 0 0 +.br +$ pigs procp 0 +.br +2 2 0 0 0 0 0 0 0 0 0 +.br +$ pigs procp 0 +.br +1 -1 0 0 0 0 0 0 0 0 0 +.br + +.EE + +.br + +.IP "\fBPROCS sid\fP - Stop script" +.IP "" 4 + +.br +This command stops a running script \fBsid\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +See \fBScripts\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs procs 0 +.br + +.br +$ pigs procs 1 +.br +-48 +.br +ERROR: unknown script id +.br + +.EE + +.br + +.IP "\fBPROCU sid pars\fP - Set script parameters" +.IP "" 4 + +.br +This command sets the parameters of a stored script \fBsid\fP passing +it up to 10 parameters. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +See \fBScripts\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs proc tag 0 hp 18 p0 p1 mils 1000 jmp 0 +.br +0 +.br +$ pigs procu 0 50 500000 +.br +$ pigs procr 0 +.br +$ pigs procu 0 100 +.br +$ pigs procu 0 200 +.br +$ pigs procu 0 200 100000 +.br + +.EE + +.br + +.IP "\fBPRRG u\fP - Get GPIO PWM real range" +.IP "" 4 + +.br +This command returns the real underlying range used by GPIO \fBu\fP. + +.br +If a hardware clock is active on the GPIO the reported +real range will be 1000000 (1M). + +.br +If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. + +.br +On error a negative status code will be returned. + +.br +See \fBPRS\fP. + +.br + +\fBExample\fP +.br + +.EX +$ pigs prrg 17 +.br +250 +.br + +.br +$ pigs pfs 17 0 +.br +10 +.br +$ pigs prrg 17 +.br +20000 +.br + +.br +$ pigs pfs 17 100000 +.br +8000 +.br +$ pigs prrg 17 +.br +25 +.br + +.EE + +.br + +.IP "\fBPRS u v\fP - Set GPIO PWM range" +.IP "" 4 + +.br +This command sets the dutycycle range \fBv\fP to be used for GPIO \fBu\fP. +Subsequent uses of command \fBP/PWM\fP will use a dutycycle between 0 (off) +and \fBv\fP (fully on). + +.br +Upon success the real underlying range used by the GPIO is returned. +On error a negative status code will be returned. + +.br +If PWM is currently active on the GPIO its dutycycle will be scaled to +reflect the new range. + +.br +The real range, the number of steps between fully off and fully on +for each frequency, is given in the following table. + +.br + +.EX + #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 + +.EE + +.br +The real value set by \fBPRS\fP is (dutycycle * real range) / range. + +.br +See \fBPRRG\fP + +.br + +\fBExample\fP +.br + +.EX +$ pigs prs 18 1000 +.br +250 +.br + +.EE + +.br + +.IP "\fBPUD g p\fP - Set GPIO pull up/down" +.IP "" 4 + +.br +This command sets the internal pull/up down for GPIO \fBg\fP to mode \fBp\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The mode may be pull-down (D), pull-up (U), or off (O). + +.br + +\fBExample\fP +.br + +.EX +$ pigs pud 4 d # Set pull-down on GPIO 4. +.br +$ pigs pud 4 u # Set pull-up on GPIO 4. +.br +$ pigs pud 4 o # No pull-up/down on GPIO 4. +.br + +.EE + +.br + +.IP "\fBR/READ g\fP - Read GPIO level" +.IP "" 4 + +.br +This reads the current level of GPIO \fBg\fP. + +.br +Upon success the current level is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs r 17 # Get level of GPIO 17. +.br +0 +.br + +.br +$ pigs r 4 # Get level of GPIO 4. +.br +1 +.br + +.EE + +.br + +.IP "\fBS/SERVO u v\fP - Set GPIO servo pulsewidth" +.IP "" 4 + +.br +This command starts servo pulses of \fBv\fP microseconds on GPIO \fBu\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The servo pulsewidth may be 0 (off), 500 (most anti-clockwise) +to 2500 (most clockwise). + +.br +The range supported by servos varies and should probably be determined +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. + +.br +You can DAMAGE a servo if you command it to move beyond its limits. + +.br + +\fBExample\fP +.br + +.EX +$ pigs SERVO 17 1500 +.br + +.EE + +.br +This example causes an on pulse of 1500 microseconds duration to be +transmitted on GPIO 17 at a rate of 50 times per second. + +.br +This will command a servo connected to GPIO 17 to rotate to its mid-point. + +.br + +\fBExample\fP +.br + +.EX +pigs s 17 0 # Switch servo pulses off. +.br + +.EE + +.br + +.IP "\fBSERC h\fP - Close serial handle" +.IP "" 4 + +.br +This command closes a serial handle \fBh\fP previously opened with \fBSERO\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs serc 0 # First close okay. +.br + +.br +$ pigs serc 0 # Second close gives error. +.br +-25 +.br +ERROR: unknown handle +.br + +.EE + +.br + +.IP "\fBSERDA h\fP - Check for serial data ready to read" +.IP "" 4 + +.br +This command returns the number of bytes of data available +to be read from the serial device associated with handle \fBh\fP. + +.br +Upon success the count of bytes available to be read is +returned (which may be 0). On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs serda 0 +.br +0 +.br + +.EE + +.br + +.IP "\fBSERO dev b sef\fP - Open serial device dev at baud b with flags" +.IP "" 4 + +.br +This command opens the serial \fBdev\fP at \fBb\fP bits per second. + +.br +No flags are currently defined. \fBsef\fP should be set to zero. + +.br +Upon success a handle (>=0) is returned. On error a negative status code +will be returned. + +.br +The device name must start with /dev/tty or /dev/serial. + +.br + +.br +The baud rate must be one of 50, 75, 110, 134, 150, +200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, +38400, 57600, 115200, or 230400. + +.br + +\fBExample\fP +.br + +.EX +$ pigs sero /dev/ttyAMA0 9600 0 +.br +0 +.br + +.br +$ pigs sero /dev/tty1 38400 0 +.br +1 +.br + +.EE + +.br + +.IP "\fBSERR h num\fP - Read bytes from serial handle" +.IP "" 4 + +.br +This command returns up to \fBnum\fP bytes of data read from the +serial device associated with handle \fBh\fP. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs serr 0 10 +.br +5 48 49 128 144 255 +.br + +.br +$ pigs serr 0 10 +.br +0 +.br + +.EE + +.br + +.IP "\fBSERRB \fP - Read byte from serial handle" +.IP "" 4 + +.br +This command returns a byte of data read from the serial +device associated with handle \fBh\fP. + +.br +Upon success a number between 0 and 255 is returned. +On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs serrb 0 +.br +23 +.br +$ pigs serrb 0 +.br +45 +.br + +.EE + +.br + +.IP "\fBSERW h bvs\fP - Write bytes to serial handle" +.IP "" 4 + +.br +This command writes bytes \fBbvs\fP to the serial device +associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs serw 0 23 45 67 89 +.br + +.EE + +.br + +.IP "\fBSERWB h bv\fP - Write byte to serial handle" +.IP "" 4 + +.br +This command writes a single byte \fBbv\fP to the serial device +associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs serwb 0 23 +.br +$ pigs serwb 0 0xf0 +.br + +.EE + +.br + +.IP "\fBSHELL name str\fP - Execute a shell command" +.IP "" 4 + +.br +This command uses the system call to execute a shell script \fBname\fP +with the given string \fBstr\fP as its parameter. + +.br +The exit status of the system call is returned if OK, otherwise +PI_BAD_SHELL_STATUS. + +.br +\fBname\fP must exist in /opt/pigpio/cgi and must be executable. + +.br +The returned exit status is normally 256 times that set +by the shell script exit function. If the script can't +be found 32512 will be returned. + +.br +The following table gives some example returned statuses. + +.br + +.EX +Script exit status Returned system call status +1 256 +5 1280 +10 2560 +200 51200 +script not found 32512 + +.EE + +.br + +\fBExample\fP +.br + +.EX +# pass two parameters, hello and world +.br +$ pigs shell scr1 hello world +.br +256 +.br + +.br +# pass three parameters, hello, string with spaces, and world +.br +$ pigs shell scr1 "hello 'string with spaces' world" +.br +256 +.br + +.br +# pass one parameter, hello string with spaces world +.br +$ pigs shell scr1 "\"hello string with spaces world\"" +.br +256 +.br + +.br +# non-existent script +.br +$ pigs shell scr78 par1 +.br +32512 +.br + +.EE + +.br + +.IP "\fBSLR u num\fP - Read bit bang serial data from GPIO" +.IP "" 4 + +.br +This command returns up to \fBnum\fP bytes of bit bang serial data +read from GPIO \fBu\fP. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br +The GPIO \fBu\fP should have been initialised with the \fBSLRO\fP command. + +.br +The bytes returned for each character depend upon the number of +data bits \fBdb\fP specified in the \fBSLRO\fP command. + +.br +For \fBdb\fP 1-8 there will be one byte per character. +.br +For \fBdb\fP 9-16 there will be two bytes per character. +.br +For \fBdb\fP 17-32 there will be four bytes per character. + +.br + +\fBExample\fP +.br + +.EX +$ pigs slr 15 20 +.br +6 1 0 23 45 89 0 +.br + +.EE + +.br + +.IP "\fBSLRC u\fP - Close GPIO for bit bang serial data" +.IP "" 4 + +.br +This command closes GPIO \fBu\fP for reading bit bang serial data. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs slrc 23 +.br + +.br +$ pigs slrc 23 +.br +-38 +.br +ERROR: no serial read in progress on GPIO +.br + +.EE + +.br + +.IP "\fBSLRI u v\fP - Sets bit bang serial data logic levels" +.IP "" 4 + +.br +This command sets the logic level for reading bit bang serial data +on GPIO \fBu\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The invert parameter \fBv\fP is 1 for inverted signal, 0 for normal. + +.br + +\fBExample\fP +.br + +.EX +$ pigs slri 17 1 # invert logic on GPIO 17 +.br + +.br +$ pigs slri 23 0 # use normal logic on GPIO 23 +.br + +.EE + +.br + +.IP "\fBSLRO u b db\fP - Open GPIO for bit bang serial data" +.IP "" 4 + +.br +This command opens GPIO \fBu\fP for reading bit bang serial data +at \fBb\fP baud and \fBdb\fP data bits. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The baud rate may be between 50 and 250000 bits per second. + +.br +The received data is held in a cyclic buffer. + +.br +It is the user's responsibility to read the data (with \fBSLR\fP) +in a timely fashion. + +.br + +\fBExample\fP +.br + +.EX +$ pigs slro 23 19200 8 +.br + +.br +$ pigs slro 23 19200 8 +.br +-50 +.br +ERROR: GPIO already in use +.br + +.EE + +.br + +.IP "\fBSPIC h\fP - SPI close handle" +.IP "" 4 + +.br +This command closes the SPI handle \fBh\fP returned by a prior +call to \fBSPIO\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs spic 1 +.br + +.br +$ pigs spic 1 +.br +-25 +.br +ERROR: unknown handle +.br + +.EE + +.br + +.IP "\fBSPIO c b spf\fP - SPI open channel at baud b with flags" +.IP "" 4 + +.br +This command returns a handle to a SPI device on channel \fBc\fP. + +.br +Data will be transferred at \fBb\fP bits per second. The flags \fBspf\fP +may be used to modify the default behaviour of 4-wire operation, +mode 0, active low chip select. + +.br +Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps +are unlikely to work. + +.br +The Pi has two SPI peripherals: main and auxiliary. + +.br +The main SPI has two chip selects (channels), the auxiliary has +three. + +.br +The auxiliary SPI is available on all models but the A and B. + +.br +The GPIO used are given in the following table. + +.br + +.EX + MISO MOSI SCLK CE0 CE1 CE2 +Main SPI 9 10 11 8 7 - +Aux SPI 19 20 21 18 17 16 + +.EE + +.br +The flags consists of the least significant 22 bits. + +.br + +.EX +21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +.br + b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m +.br + +.EE + +.br +mm defines the SPI mode. + +.br +Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. + +.br + +.EX +Mode POL PHA +.br + 0 0 0 +.br + 1 0 1 +.br + 2 1 0 +.br + 3 1 1 +.br + +.EE + +.br +px is 0 if CEx is active low (default) and 1 for active high. + +.br +ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. + +.br +A is 0 for the main SPI, 1 for the auxiliary SPI. + +.br +W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main +SPI only. + +.br +nnnn defines the number of bytes (0-15) to write before switching +the MOSI line to MISO to read data. This field is ignored +if W is not set. Main SPI only. + +.br +T is 1 if the least significant bit is transmitted on MOSI first, the +default (0) shifts the most significant bit out first. Auxiliary SPI +only. + +.br +R is 1 if the least significant bit is received on MISO first, the +default (0) receives the most significant bit first. Auxiliary SPI +only. + +.br +bbbbbb defines the word size in bits (0-32). The default (0) +sets 8 bits per word. Auxiliary SPI only. + +.br +The \fBSPIR\fP, \fBSPIW\fP, and \fBSPIX\fP commands transfer data +packed into 1, 2, or 4 bytes according to the word size in bits. + +.br +For bits 1-8 there will be one byte per character. +.br +For bits 9-16 there will be two bytes per character. +.br +For bits 17-32 there will be four bytes per character. + +.br +Multi-byte transfers are made in least significant byte first order. + +.br +E.g. to transfer 32 11-bit words 64 bytes need to be sent. + +.br +E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed +by 0x1A. + +.br +The other bits in flags should be set to zero. + +.br +Upon success a handle (>=0) is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs spio 0 100000 3 # Open channel 0 at 100kbps in mode 3. +.br +0 +.br + +.br +$ pigs spio 0 32000 256 # Open channel 0 of auxiliary spi at 32kbps. +.br +1 +.br + +.EE + +.br + +.IP "\fBSPIR h num\fP - SPI read bytes from handle" +.IP "" 4 + +.br +This command returns \fBnum\fP bytes read from the SPI device +associated with handle \fBh\fP. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs spir 0 10 # Read 10 bytes from the SPI device. +.br +10 0 0 0 0 0 0 0 0 0 0 +.br + +.EE + +.br + +.IP "\fBSPIW h bvs\fP - SPI write bytes to handle" +.IP "" 4 + +.br +This command writes bytes \fBbvs\fP to the SPI device +associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs spiw 0 0x22 0x33 0xcc 0xff +.br + +.EE + +.br + +.IP "\fBSPIX h bvs\fP - SPI transfer bytes to handle" +.IP "" 4 + +.br +This command writes bytes \fBbvs\fP to the SPI device +associated with handle \fBh\fP. It returns the same +number of bytes read from the device. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs spix 0 0x22 0x33 0xcc 0xff +.br +4 0 0 0 0 +.br + +.EE + +.br + +.IP "\fBT/TICK \fP - Get current tick" +.IP "" 4 + +.br +This command returns the current system tick. + +.br +Tick is the number of microseconds since system boot. + +.br +As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, +which is approximately 1 hour 12 minutes. + +.br + +\fBExample\fP +.br + +.EX +$ pigs t mils 1000 t +.br +3691823946 +.br +3692833987 +.br + +.EE + +.br + +.IP "\fBTRIG u pl L\fP - Send a trigger pulse" +.IP "" 4 + +.br +This command sends a trigger pulse of \fBpl\fP microseconds at level \fBL\fP +to GPIO \fBu\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The GPIO is set to not level at the end of the pulse. + +.br + +\fBExample\fP +.br + +.EX +$ pigs trig 4 10 1 +.br + +.br +$ pigs trig 4 51 1 +.br +-46 +.br +ERROR: trigger pulse > 50 microseconds +.br + +.EE + +.br + +.IP "\fBW/WRITE g L\fP - Write GPIO level" +.IP "" 4 + +.br +This command sets GPIO \fBg\fP to level \fBL\fP. The level may be 0 +(low, off, clear) or 1 (high, on, set). + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs w 23 0 +.br +$ pigs w 23 1 +.br + +.br +$ pigs w 23 2 +.br +-5 +.br +ERROR: level not 0-1 +.br + +.EE + +.br + +.IP "\fBWDOG u v\fP - Set GPIO watchdog" +.IP "" 4 + +.br +This command sets a watchdog of \fBv\fP milliseconds on GPIO \fBu\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br +The watchdog is nominally in milliseconds. + +.br +One watchdog may be registered per GPIO. + +.br +The watchdog may be cancelled by setting timeout to 0. + +.br +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. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wdog 23 90000 +.br +-15 +.br +ERROR: timeout not 0-60000 +.br + +.br +$ pigs wdog 23 9000 +.br + +.EE + +.br +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. + +.br + +.IP "\fBWVAG trips\fP - Add generic pulses to waveform" +.IP "" 4 + +.br +This command adds 1 one or more triplets \fBtrips\fP of GPIO on, GPIO off, +delay to the existing waveform (if any). + +.br +Upon success the total number of pulses in the waveform so far is +returned. On error a negative status code will be returned. + +.br +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. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvag 0x10 0x80 1000 0x80 0x10 9000 +.br +2 +.br + +.br +$ pigs wvag 0 0 10000 0x10 0x80 1000 0x80 0x10 9000 +.br +4 +.br + +.EE + +.br + +.IP "\fBWVAS u b db sb o bvs\fP - Add serial data to waveform" +.IP "" 4 + +.br +This command adds a waveform representing serial data \fBbvs\fP to +GPIO \fBu\fP at \fBb\fP baud to the existing waveform (if any). +The serial data starts \fBo\fP microseconds from the start of the +waveform. + +.br +Upon success the total number of pulses in the waveform so far is +returned. On error a negative status code will be returned. + +.br +The serial data is formatted as one start bit, \fBdb\fP data bits, and +\fBsb\fP/2 stop bits. + +.br +The baud rate may be between 50 and 1000000 bits per second. + +.br +It is legal to add serial data streams with different baud rates to +the same waveform. + +.br +The bytes required for each character depend upon \fBdb\fP. + +.br +For \fBdb\fP 1-8 there will be one byte per character. +.br +For \fBdb\fP 9-16 there will be two bytes per character. +.br +For \fBdb\fP 17-32 there will be four bytes per character. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvas 4 9600 8 2 0 0x30 0x31 0x32 0x33 +.br +23 +.br + +.br +$ pigs wvas 7 38400 8 2 0 0x41 0x42 +.br +35 +.br + +.EE + +.br + +.IP "\fBWVTAT \fP - Returns the current transmitting waveform" +.IP "" 4 + +.br +This command returns the id of the waveform currently +being transmitted. + +.br +Returns the waveform id or one of the following special +values: + +.br +9998 - transmitted wave not found +.br +9999 - no wave being transmitted + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvtat +.br +9999 +.br + +.EE + +.br + +.IP "\fBWVBSY \fP - Check if waveform is being transmitted" +.IP "" 4 + +.br +This command checks to see if a waveform is currently being transmitted. + +.br +Returns 1 if a waveform is currently being transmitted, otherwise 0. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvbsy +.br +0 +.br + +.EE + +.br + +.IP "\fBWVCHA bvs\fP - Transmits a chain of waveforms" +.IP "" 4 + +.br +This command transmits a chain of waveforms. + +.br +NOTE: Any hardware PWM started by \fBHP\fP will +be cancelled. + +.br +The waves to be transmitted are specified by the contents of +\fBbvs\fP which contains an ordered list of wave_ids and optional +command codes and related data. + +.br +Upon success 0 is returned. On error a negative status code +will be returned. + +.br +Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. + +.br +A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. + +.br +Delays between waves may be added with the delay command. + +.br +The following command codes are supported: + +.br + +.EX +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 + +.EE + +.br +If present Loop Forever must be the last entry in the chain. + +.br +The code is currently dimensioned to support a chain with roughly +600 entries and 20 loop counters. + +.br + +\fBExample\fP +.br + +.EX +#!/bin/bash +.br + +.br +GPIO=4 +.br +WAVES=5 +.br + +.br +pigs m $GPIO w +.br + +.br +for ((i=0; i<$WAVES; i++)) +.br +do +.br + pigs wvag $((1<=0) is returned. On error a negative status +code will be returned. + +.br +The data provided by the \fBWVAG\fP and \fBWVAS\fP commands is +consumed by this command. + +.br +As many waveforms may be created as there is space available. +The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the +waveform to transmit. + +.br +Normal usage would be + +.br +Step 1. \fBWVCLR\fP to clear all waveforms and added data. + +.br +Step 2. \fBWVAG\fP/\fBWVAS\fP calls to supply the waveform data. + +.br +Step 3. \fBWVCRE\fP to create the waveform and get a unique id. + +.br +Repeat steps 2 and 3 as needed. + +.br +Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit. + +.br +A waveform comprises of one or more pulses. + +.br +A pulse specifies + +.br +1) the GPIO to be switched on at the start of the pulse. +.br +2) the GPIO to be switched off at the start of the pulse. +.br +3) the delay in microseconds before the next pulse. + +.br +Any or all the fields can be zero. It doesn't make any sense to +set all the fields to zero (the pulse will be ignored). + +.br +When a waveform is started each pulse is executed in order with +the specified delay between the pulse and the next. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvas 4 9600 0 23 45 67 89 90 +.br +37 +.br +$ pigs wvcre +.br +0 +.br + +.br +$ pigs wvcre +.br +-69 +.br +ERROR: attempt to create an empty waveform +.br + +.EE + +.br + +.IP "\fBWVCAP \fP - Create a waveform of fixed size" +.IP "" 4 + +.br +Similar to WVCRE, this command creates a waveform but pads the consumed +resources to a fixed size, specified as a percent of total resource. +Padded waves of equal size can be re-cycled efficiently allowing newly +created waves to re-use the resources of deleted waves of the same dimension. + +.br +Upon success a wave id (>=0) is returned. On error a negative status +code will be returned. + +.br +The data provided by the \fBWVAG\fP and \fBWVAS\fP commands are +consumed by this command. + +.br +As many waveforms may be created as there is space available. +The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the +waveform to transmit. + +.br +Normal usage would be + +.br +Step 1. \fBWVCLR\fP to clear all waveforms and added data. + +.br +Step 2. \fBWVAG\fP/\fBWVAS\fP calls to supply the waveform data. + +.br +Step 3. \fBWVCAP\fP to create a waveform of a uniform size. + +.br +Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit. + +.br +Repeat steps 2 - 4 as needed. + +.br +Step 5. Any wave id can now be deleted and another wave of the same size + can be created in its place. + +.br + +\fBExample\fP +.br + +.EX +# Create a wave that consumes 50% of the total resource: +.br + +.br +$ pigs wvag 16 0 5000000 0 16 5000000 +.br +2 +.br +$ pigs wvcap 50 +.br +0 +.br +$ pigs wvtx 0 +.br +11918 +.br + +.EE + +.br + +.IP "\fBWVDEL wid\fP - Delete selected waveform" +.IP "" 4 + +.br +This command deletes the waveform with id \fBwid\fP. + +.br +The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. + +.br +- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. + +.br +- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvdel 0 +.br + +.br +$ pigs wvdel 0 +.br +-66 +.br +ERROR: non existent wave id +.br + +.EE + +.br + +.IP "\fBWVHLT \fP - Stop waveform" +.IP "" 4 + +.br +This command aborts the transmission of the current waveform. + +.br +Nothing is returned. + +.br +This command is intended to stop a waveform started in the repeat mode. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvhlt +.br + +.EE + +.br + +.IP "\fBWVNEW \fP - Initialise a new waveform" +.IP "" 4 + +.br +This clears any existing waveform data ready for the creation of a new +waveform. + +.br +Nothing is returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvnew +.br + +.EE + +.br + +.IP "\fBWVSC ws\fP - Get waveform DMA CB stats" +.IP "" 4 + +.br +The statistic requested by \fBws\fP is returned. + +.br +\fBws\fP identifies the subcommand as follows. + +.br +0 Get Cbs +.br +1 Get High Cbs +.br +2 Get Max Cbs + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvas 4 9600 0 23 45 67 89 90 +.br +37 +.br + +.br +$ pigs wvsc 0 +.br +74 +.br +$ pigs wvsc 1 +.br +74 +.br +$ pigs wvsc 2 +.br +25016 +.br + +.EE + +.br + +.IP "\fBWVSM ws\fP - Get waveform time stats" +.IP "" 4 + +.br +The statistic requested by \fBws\fP is returned. + +.br +\fBws\fP identifies the subcommand as follows. + +.br +0 Get Micros +.br +1 Get High Micros +.br +2 Get Max Micros + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvsm 0 +.br +5314 +.br +$ pigs wvsm 1 +.br +5314 +.br +$ pigs wvsm 2 +.br +1800000000 +.br + +.EE + +.br + +.IP "\fBWVSP ws\fP - Get waveform pulse stats" +.IP "" 4 + +.br +The statistic requested by \fBws\fP is returned. + +.br +\fBws\fP identifies the subcommand as follows. + +.br +0 Get Pulses +.br +1 Get High Pulses +.br +2 Get Max Pulses + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvsp 0 +.br +37 +.br +$ pigs wvsp 1 +.br +37 +.br +$ pigs wvsp 2 +.br +12000 +.br + +.EE + +.br + +.IP "\fBWVTX wid\fP - Transmits waveform once" +.IP "" 4 + +.br +This command transmits the waveform with id \fBwid\fP once. + +.br +NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. + +.br +Upon success the number of DMA control blocks in the waveform is returned. +On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvtx 1 +.br +75 +.br + +.br +$ pigs wvtx 2 +.br +-66 +.br +ERROR: non existent wave id +.br + +.EE + +.br + +.IP "\fBWVTXM wid wmde\fP - Transmits waveform using mode" +.IP "" 4 + +.br +This command transmits the waveform with id \fBwid\fP using mode \fBwmde\fP. + +.br +The mode may be send once (0), send repeatedly (1), send once but +first sync with previous wave (2), or send repeatedly but first +sync with previous wave (3). + +.br +WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. + +.br +NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. + +.br +Upon success the number of DMA control blocks in the waveform is returned. +On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvtxm 1 3 +.br +75 +.br + +.br +$ pigs wvtxm 2 0 +.br +-66 +.br +ERROR: non existent wave id +.br + +.EE + +.br + +.IP "\fBWVTXR wid\fP - Transmits waveform repeatedly" +.IP "" 4 + +.br +This command transmits the waveform with id \fBwid\fP repeatedly. + +.br +NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. + +.br +Upon success the number of DMA control blocks in the waveform is returned. +On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvtxr 1 +.br +75 +.br + +.br +$ pigs wvtxr 2 +.br +-66 +.br +ERROR: non existent wave id +.br + +.EE + +.br + +.SH PARAMETERS + +.br + +.IP "\fBactv\fP - 0-1000000" 0 + +.br +The number of microseconds level changes are reported for once +a noise filter has been triggered (by \fBstdy\fP microseconds of +a stable level). + +.br + +.IP "\fBb\fP - baud" 0 +The command expects the baud rate in bits per second for +the transmission of serial data (I2C/SPI/serial link, waves). + +.br + +.IP "\fBbctl\fP - BSC control word" 0 +The command expects a BSC control word, see \fBBSCX\fP. + +.br + +.IP "\fBbit\fP - bit value (0-1)" 0 +The command expects 0 or 1. + +.br + +.IP "\fBbits\fP - a bit mask" 0 +A mask is used to select one or more GPIO. A GPIO is selected +if bit (1<=0)" 0 +The command expects a handle. + +.br +A handle is a number referencing an object opened by one of \fBFO\fP, +\fBI2CO\fP, \fBNO\fP, \fBSERO\fP, \fBSPIO\fP. + +.br + +.IP "\fBib\fP - I2C bus (>=0)" 0 +The command expects an I2C bus number. + +.br + +.IP "\fBid\fP - I2C device (0-0x7F)" 0 +The command expects the address of an I2C device. + +.br + +.IP "\fBif\fP - I2C flags (0)" 0 +The command expects an I2C flags value. No flags are currently defined. + +.br + +.IP "\fBL\fP - level (0-1)" 0 +The command expects a GPIO level. + +.br + +.IP "\fBm\fP - mode (RW540123)" 0 +The command expects a mode character. + +.br +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. + +.br +To set the mode use the code for the mode. + +.br +The value is returned by the mode get command. + +.br + +.EX +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 + +.EE + +.br + +.IP "\fBmiso\fP - GPIO (0-31)" 0 +The GPIO used for the MISO signal when bit banging SPI. + +.br + +.IP "\fBmode\fP - file open mode" 0 +One of the following values. + +.br + +.EX + Value Meaning +READ 1 open file for reading +WRITE 2 open file for writing +RW 3 open file for reading and writing + +.EE + +.br +The following values can be or'd into the mode. + +.br + +.EX + 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 + +.EE + +.br + +.IP "\fBmosi\fP - GPIO (0-31)" 0 +The GPIO used for the MOSI signal when bit banging SPI. + +.br + +.IP "\fBname\fP - the name of a script" 0 +Only alphanumeric characters, '-' and '_' are allowed in the name. + +.br + +.IP "\fBnum\fP - maximum number of bytes to return (1-)" 0 +The command expects the maximum number of bytes to return. + +.br +For the I2C and SPI commands the requested number of bytes will always +be returned. + +.br +For the serial and file commands the smaller of the number of +bytes available to be read (which may be zero) and \fBnum\fP bytes +will be returned. + +.br + +.IP "\fBo\fP - offset (>=0)" 0 +Serial data is stored offset microseconds from the start of the waveform. + +.br + +.IP "\fBp\fP - PUD (ODU)" 0 +The command expects a PUD character. + +.br +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. + +.br +A pull up will default the input to 1 (high). + +.br +A pull down will default the input to 0 (low). + +.br +To set the pull up down state use the command character for the state. + +.br + +.EX +Pull Up Down Off Pull Down Pull Up +Command Character O D U + +.EE + +.br +There is no mechanism to read the pull up down state. + +.br + +.IP "\fBpad\fP - 0-2" 0 +A set of GPIO which share common drivers. + +.br + +.EX +Pad GPIO +0 0-27 +1 28-45 +2 46-53 + +.EE + +.br + +.IP "\fBpadma\fP - 1-16" 0 +The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. + +.br + +.IP "\fBpars\fP - script parameters" 0 +The command expects 0 to 10 numbers as parameters to be passed to the script. + +.br + +.IP "\fBpat\fP - a file name pattern" 0 +A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. + +.br + +.IP "\fBpdc\fP - hardware PWM dutycycle (0-1000000)" 0 +The command expects a dutycycle. + +.br + +.IP "\fBpf\fP - hardware PWM frequency (1-125M, 1-187.5M for the BCM2711)" 0 +The command expects a frequency. + +.br + +.IP "\fBpl\fP - pulse length (1-100)" 0 +The command expects a pulse length in microseconds. + +.br + +.IP "\fBr\fP - register (0-255)" 0 +The command expects an I2C register number. + +.br + +.IP "\fBsb\fP - serial stop (half) bits (2-8)" 0 +The command expects the number of stop (half) bits per serial character. + +.br + +.IP "\fBscl\fP - user GPIO (0-31)" 0 +The command expects the number of the GPIO to be used for SCL +when bit banging I2C. + +.br + +.IP "\fBsclk\fP - user GPIO (0-31)" 0 +The GPIO used for the SCLK signal when bit banging SPI. + +.br + +.IP "\fBsda\fP - user GPIO (0-31)" 0 +The command expects the number of the GPIO to be used for SDA +when bit banging I2C. + +.br + +.IP "\fBsef\fP - serial flags (32 bits)" 0 +The command expects a flag value. No serial flags are currently defined. + +.br + +.IP "\fBsid\fP - script id (>= 0)" 0 +The command expects a script id as returned by a call to \fBPROC\fP. + +.br + +.IP "\fBspf\fP - SPI flags (32 bits)" 0 +See \fBSPIO\fP and \fBBSPIO\fP. + +.br + +.IP "\fBstdy\fP - 0-300000" 0 + +.br +The number of microseconds level changes must be stable for +before reporting the level changed (\fBFG\fP) or triggering +the active part of a noise filter (\fBFN\fP). + +.br + +.IP "\fBstr\fP - a string" 0 +The command expects a string. + +.br + +.IP "\fBt\fP - a string" 0 +The command expects a string. + +.br + +.IP "\fBtrips\fP - triplets" 0 +The command expects 1 or more triplets of GPIO on, GPIO off, delay. + +.br +E.g. 0x400000 0 100000 0 0x400000 900000 defines two pulses as follows + +.br + +.EX + GPIO on GPIO off delay +0x400000 (GPIO 22) 0 (None) 100000 (1/10th s) + 0 (None) 0x400000 (GPIO 22) 900000 (9/10th s) + +.EE + +.br + +.IP "\fBu\fP - user GPIO (0-31)" 0 +The command expects the number of a user GPIO. + +.br +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. + +.br +It is your responsibility to ensure that the PWM and servo commands +are only used on safe GPIO. + +.br +See \fBg\fP + +.br + +.IP "\fBuvs\fP - values" 0 +The command expects an arbitrary number of >=0 values (possibly none). +Any after the first two must be <= 255. + +.br + +.IP "\fBv\fP - value" 0 +The command expects a number. + +.br + +.IP "\fBwid\fP - wave id (>=0)" 0 +The command expects a wave id. + +.br +When a waveform is created it is given an id (0, 1, 2, ...). + +.br + +.IP "\fBwmde\fP - mode (0-3)" 0 +The command expects a wave transmission mode. + +.br +0 = send once +.br +1 = send repeatedly +.br +2 = send once but first sync with previous wave +.br +3 = send repeatedly but first sync with previous wave +.br + +.br + +.IP "\fBws\fP - wave stats sucommand (0-2)" 0 +The command expects a subcommand. + +.br +0 = current value. +.br +1 = highest value so far. +.br +2 = maximum possible value. + +.br + +.IP "\fBwv\fP - word value (0-65535)" 0 +The command expects a word value. + +.br + +.SH SCRIPTS + +.br +Scripts are programs to be stored and executed by the pigpio daemon. +They are intended to mitigate any performance problems associated with +the pigpio daemon server/client model. + +.br +.SS Example +.br +A trivial example might be useful. Suppose you want to toggle a GPIO +on and off as fast as possible. + +.br +From the command line you could write + +.br + +.EX +for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done +.br + +.EE + +.br +Timing that you will see it takes about 14 seconds, or roughly +70 toggles per second. + +.br +Using the pigpio Python module you could use code such as + +.br + +.EX +#!/usr/bin/env python +.br + +.br +import time +.br + +.br +import pigpio +.br + +.br +PIN=4 +.br + +.br +TOGGLE=10000 +.br + +.br +pi = pigpio.pi() # Connect to local Pi. +.br + +.br +s = time.time() +.br + +.br +for i in range(TOGGLE): +.br + pi.write(PIN, 1) +.br + pi.write(PIN, 0) +.br + +.br +e = time.time() +.br + +.br +print("pigpio did {} toggles per second".format(int(TOGGLE/(e-s)))) +.br + +.br +pi.stop() +.br + +.EE + +.br +Timing that shows a speed improvement to roughly 800 toggles per second. + +.br +Now let's use a script. + +.br + +.EX +pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999 +.br + +.EE + +.br +Ignore the details for now. + +.br +Let's time the script running. + +.br +Again, ignore the details for now. + +.br + +.EX +time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ +.br + do sleep 0.2; done) +.br + +.EE + +.br +The script takes roughly 12 seconds to complete, or 800,000 toggles per second. + +.br +That is the advantage of a stored script. + +.br +Some details. + +.br + +.EX +pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999 +.br + +.EE + +.br +proc introduces a script. Everything after proc is part of the script. +.br +tag 999 names the current position in the script. +.br +w 22 1 writes 1 to GPIO 22. +.br +w 22 0 writes 0 to GPIO 22. +.br +dcr p0 decrements parameter 0. +.br +jp 999 jumps to tag 999 if the result is positive. + +.br + +.EX +time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ +.br + do sleep 0.2; done) +.br + +.EE + +.br +pigs procr 0 10000000 starts script 0 with parameter 0 of 10 million. + +.br +The rest is bash apart from + +.br +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. + +.br +.SS Virtual machine +.br +A script runs within a virtual machine with + +.br +a 32 bit accumulator A. +.br +a flags register F. +.br +a program counter PC. + +.br +Each script has + +.br +10 parameters named 0 through 9. +.br +150 variables named 0 through 149. +.br +50 labels which are named by any unique number. + +.br +.SS Commands +.br +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. + +.br +The following commands are not permitted within a script: + +.br +File - FL FO FR FW + +.br +I2C - BI2CZ I2CPK I2CRD I2CRI I2CRK I2CWD I2CWI I2CWK I2CZ + +.br +Misc - BSCX CF1 CF2 SHELL + +.br +Script control - PARSE PROC PROCD PROCP PROCR PROCS PROCU + +.br +Serial - SERO SERR SERW SLR + +.br +SPI - BSPIO BSPIX SPIR SPIW SPIX + +.br +Waves - WVAG WVAS WVCHA WVGO WVGOR + +.br +The following commands are only permitted within a script: + +.br + +.EX +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 + +.EE + +.br +x may be a constant, a parameter (p0-p9), or a variable (v0-v149). + +.br +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. + +.br +The EVTWT command parameter is a bit-mask with 1 set for events of interest. + +.br +The WAIT command parameter is a bit-mask with 1 set for GPIO of interest. + +.br +The SYS script receives two unsigned parameters: the accumulator A and +the current GPIO levels. + +.br + +.SH SEE ALSO + +pigpiod(1), pig2vcd(1), pigpio(3), pigpiod_if(3), pigpiod_if2(3) +.SH AUTHOR + +joan@abyz.me.uk diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index 0820b48..98a0cb1 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 b/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 new file mode 100644 index 0000000..0820b48 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 b/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 new file mode 100644 index 0000000..93b1db0 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 b/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 new file mode 100644 index 0000000..d89cd8f Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 b/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 new file mode 100644 index 0000000..79a4182 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 new file mode 100644 index 0000000..07931f1 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 new file mode 100644 index 0000000..c9ca6e2 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 new file mode 100644 index 0000000..1630297 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 new file mode 100644 index 0000000..840f6a8 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 new file mode 100644 index 0000000..ef77c96 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 new file mode 100644 index 0000000..125a0fc Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 new file mode 100644 index 0000000..70b41cd Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 differ diff --git a/DOC/src/defs/pigs.def b/DOC/src/defs/pigs.def index ff5e98d..82fca73 100644 --- a/DOC/src/defs/pigs.def +++ b/DOC/src/defs/pigs.def @@ -320,6 +320,7 @@ 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 @@ -2783,6 +2784,49 @@ $ pigs wvcre ERROR: attempt to create an empty waveform ... +WVCAP :: + +Similar to WVCRE, this command creates a waveform but pads the consumed +resources to a fixed size, specified as a percent of total resource. +Padded waves of equal size can be re-cycled efficiently allowing newly +created waves to re-use the resources of deleted waves of the same dimension. + +Upon success a wave id (>=0) is returned. On error a negative status +code will be returned. + +The data provided by the [*WVAG*] and [*WVAS*] commands are +consumed by this command. + +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 + +Step 1. [*WVCLR*] to clear all waveforms and added data. + +Step 2. [*WVAG*]/[*WVAS*] calls to supply the waveform data. + +Step 3. [*WVCAP*] to create a waveform of a uniform size. + +Step 4. [*WVTX*] or [*WVTXR*] with the id of the waveform to transmit. + +Repeat steps 2 - 4 as needed. + +Step 5. Any wave id can now be deleted and another wave of the same size + can be created in its place. + +... +# 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 +... + WVDEL :: This command deletes the waveform with id [*wid*]. diff --git a/DOC/tmp/body/cif.body b/DOC/tmp/body/cif.body new file mode 100644 index 0000000..28205fd --- /dev/null +++ b/DOC/tmp/body/cif.body @@ -0,0 +1,1818 @@ +

pigpio is a C library for the Raspberry which allows control of the GPIO. +

Features

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o callbacks when any of GPIO 0-31 change state +

o callbacks at timed intervals +

o reading/writing all of the GPIO in a bank as one operation +

o individually setting GPIO modes, reading and writing +

o notifications when any of GPIO 0-31 change state +

o the construction of output waveforms with microsecond timing +

o rudimentary permission control over GPIO +

o a simple interface to start and stop new threads +

o I2C, SPI, and serial link wrappers +

o creating and running scripts +

GPIO

ALL GPIO are identified by their Broadcom number. +

Credits

The PWM and servo pulses are timed using the DMA and PWM peripherals. +

This use was inspired by Richard Hirst's servoblaster kernel module. +

Usage

Include <pigpio.h> in your source files. +

Assuming your source is in prog.c use the following command to build and +run the executable. +

gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
sudo ./prog


For examples of usage see the C programs within the pigpio archive file. +

Notes

All the functions which return an int return < 0 on error. +

gpioInitialise must be called before all other library functions +with the following exceptions: +

gpioCfg*
gpioVersion
gpioHardwareRevision


If the library is not initialised all but the gpioCfg*, +gpioVersion, and gpioHardwareRevision functions will +return error PI_NOT_INITIALISED. +

If the library is initialised the gpioCfg* functions will return +error PI_INITIALISED. +

OVERVIEW

ESSENTIAL +
gpioInitialise Initialise library +
gpioTerminate Stop library +
BASIC +
gpioSetMode Set a GPIO mode +
gpioGetMode Get a GPIO mode +
gpioSetPullUpDown Set/clear GPIO pull up/down resistor +
gpioRead Read a GPIO +
gpioWrite Write a GPIO +
PWM (overrides servo commands on same GPIO) +
gpioPWM Start/stop PWM pulses on a GPIO +
gpioSetPWMfrequency Configure PWM frequency for a GPIO +
gpioSetPWMrange Configure PWM range for a GPIO +
gpioGetPWMdutycycle Get dutycycle setting on a GPIO +
gpioGetPWMfrequency Get configured PWM frequency for a GPIO +
gpioGetPWMrange Get configured PWM range for a GPIO +
gpioGetPWMrealRange Get underlying PWM range for a GPIO +
Servo (overrides PWM commands on same GPIO) +
gpioServo Start/stop servo pulses on a GPIO +
gpioGetServoPulsewidth Get pulsewidth setting on a GPIO +
INTERMEDIATE +
gpioTrigger Send a trigger pulse to a GPIO +
gpioSetWatchdog Set a watchdog on a GPIO +
gpioRead_Bits_0_31 Read all GPIO in bank 1 +
gpioRead_Bits_32_53 Read all GPIO in bank 2 +
gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 +
gpioWrite_Bits_32_53_ClearClear selected GPIO in bank 2 +
gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 +
gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 +
gpioSetAlertFunc Request a GPIO level change callback +
gpioSetAlertFuncEx Request a GPIO change callback, extended +
gpioSetTimerFunc Request a regular timed callback +
gpioSetTimerFuncEx Request a regular timed callback, extended +
gpioStartThread Start a new thread +
gpioStopThread Stop a previously started thread +
ADVANCED +
gpioNotifyOpen Request a notification handle +
gpioNotifyClose Close a notification +
gpioNotifyOpenWithSize Request a notification with sized pipe +
gpioNotifyBegin Start notifications for selected GPIO +
gpioNotifyPause Pause notifications +
gpioHardwareClock Start hardware clock on supported GPIO +
gpioHardwarePWM Start hardware PWM on supported GPIO +
gpioGlitchFilter Set a glitch filter on a GPIO +
gpioNoiseFilter Set a noise filter on a GPIO +
gpioSetPad Sets a pads drive strength +
gpioGetPad Gets a pads drive strength +
shell Executes a shell command +
gpioSetISRFunc Request a GPIO interrupt callback +
gpioSetISRFuncEx Request a GPIO interrupt callback, extended +
gpioSetSignalFunc Request a signal callback +
gpioSetSignalFuncEx Request a signal callback, extended +
gpioSetGetSamplesFunc Requests a GPIO samples callback +
gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended +
Custom +
gpioCustom1 User custom function 1 +
gpioCustom2 User custom function 2 +
Events +
eventMonitor Sets the events to monitor +
eventSetFunc Request an event callback +
eventSetFuncEx Request an event callback, extended +
eventTrigger Trigger an event +
Scripts +
gpioStoreScript Store a script +
gpioRunScript Run a stored script +
gpioUpdateScript Set a scripts parameters +
gpioScriptStatus Get script status and parameters +
gpioStopScript Stop a running script +
gpioDeleteScript Delete a stored script +
I2C +
i2cOpen Opens an I2C device +
i2cClose Closes an I2C device +
i2cWriteQuick SMBus write quick +
i2cReadByte SMBus read byte +
i2cWriteByte SMBus write byte +
i2cReadByteData SMBus read byte data +
i2cWriteByteData SMBus write byte data +
i2cReadWordData SMBus read word data +
i2cWriteWordData SMBus write word data +
i2cReadBlockData SMBus read block data +
i2cWriteBlockData SMBus write block data +
i2cReadI2CBlockData SMBus read I2C block data +
i2cWriteI2CBlockData SMBus write I2C block data +
i2cReadDevice Reads the raw I2C device +
i2cWriteDevice Writes the raw I2C device +
i2cProcessCall SMBus process call +
i2cBlockProcessCall SMBus block process call +
i2cSwitchCombined Sets or clears the combined flag +
i2cSegments Performs multiple I2C transactions +
i2cZip Performs multiple I2C transactions +
I2C BIT BANG +
bbI2COpen Opens GPIO for bit banging I2C +
bbI2CClose Closes GPIO for bit banging I2C +
bbI2CZip Performs bit banged I2C transactions +
I2C/SPI SLAVE +
bscXfer I2C/SPI as slave transfer +
SERIAL +
serOpen Opens a serial device +
serClose Closes a serial device +
serReadByte Reads a byte from a serial device +
serWriteByte Writes a byte to a serial device +
serRead Reads bytes from a serial device +
serWrite Writes bytes to a serial device +
serDataAvailable Returns number of bytes ready to be read +
SERIAL BIT BANG (read only) +
gpioSerialReadOpen Opens a GPIO for bit bang serial reads +
gpioSerialReadClose Closes a GPIO for bit bang serial reads +
gpioSerialReadInvert Configures normal/inverted for serial reads +
gpioSerialRead Reads bit bang serial data from a GPIO +
SPI +
spiOpen Opens a SPI device +
spiClose Closes a SPI device +
spiRead Reads bytes from a SPI device +
spiWrite Writes bytes to a SPI device +
spiXfer Transfers bytes with a SPI device +
SPI BIT BANG +
bbSPIOpen Opens GPIO for bit banging SPI +
bbSPIClose Closes GPIO for bit banging SPI +
bbSPIXfer Performs bit banged SPI transactions +
FILES +
fileOpen Opens a file +
fileClose Closes a file +
fileRead Reads bytes from a file +
fileWrite Writes bytes to a file +
fileSeek Seeks to a position within a file +
fileList List files which match a pattern +
WAVES +
gpioWaveClear Deletes all waveforms +
gpioWaveAddNew Starts a new waveform +
gpioWaveAddGeneric Adds a series of pulses to the waveform +
gpioWaveAddSerial Adds serial data to the waveform +
gpioWaveCreate Creates a waveform from added data +
gpioWaveCreatePad Creates a waveform of fixed size from added data +
gpioWaveDelete Deletes a waveform +
gpioWaveTxSend Transmits a waveform +
gpioWaveChain Transmits a chain of waveforms +
gpioWaveTxAt Returns the current transmitting waveform +
gpioWaveTxBusy Checks to see if the waveform has ended +
gpioWaveTxStop Aborts the current waveform +
gpioWaveGetCbs Length in CBs of the current waveform +
gpioWaveGetHighCbs Length of longest waveform so far +
gpioWaveGetMaxCbs Absolute maximum allowed CBs +
gpioWaveGetMicros Length in micros of the current waveform +
gpioWaveGetHighMicros Length of longest waveform so far +
gpioWaveGetMaxMicros Absolute maximum allowed micros +
gpioWaveGetPulses Length in pulses of the current waveform +
gpioWaveGetHighPulses Length of longest waveform so far +
gpioWaveGetMaxPulses Absolute maximum allowed pulses +
UTILITIES +
gpioDelay Delay for a number of microseconds +
gpioTick Get current tick (microseconds) +
gpioHardwareRevision Get hardware revision +
gpioVersion Get the pigpio version +
getBitInBytes Get the value of a bit +
putBitInBytes Set the value of a bit +
gpioTime Get current time +
gpioSleep Sleep for specified time +
time_sleep Sleeps for a float number of seconds +
time_time Float number of seconds since the epoch +
CONFIGURATION +
gpioCfgBufferSize Configure the GPIO sample buffer size +
gpioCfgClock Configure the GPIO sample rate +
gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) +
gpioCfgDMAchannels Configure the DMA channels +
gpioCfgPermissions Configure the GPIO access permissions +
gpioCfgInterfaces Configure user interfaces +
gpioCfgSocketPort Configure socket port +
gpioCfgMemAlloc Configure DMA memory allocation mode +
gpioCfgNetAddr Configure allowed network addresses +
gpioCfgInternals Configure misc. internals (DEPRECATED) +
gpioCfgGetInternals Get internal configuration settings +
gpioCfgSetInternals Set internal configuration settings +
EXPERT +
rawWaveAddSPI Not intended for general use +
rawWaveAddGeneric Not intended for general use +
rawWaveCB Not intended for general use +
rawWaveCBAdr Not intended for general use +
rawWaveGetOOL Not intended for general use +
rawWaveSetOOL Not intended for general use +
rawWaveGetOut Not intended for general use +
rawWaveSetOut Not intended for general use +
rawWaveGetIn Not intended for general use +
rawWaveSetIn Not intended for general use +
rawWaveInfo Not intended for general use +
rawDumpWave Not intended for general use +
rawDumpScript Not intended for general use +

FUNCTIONS

int gpioInitialise(void)

+Initialises the library. +

Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. +

gpioInitialise must be called before using the other library functions +with the following exceptions: +

gpioCfg*
gpioVersion
gpioHardwareRevision


Example

if (gpioInitialise() < 0)
{
   // pigpio initialisation failed.
}
else
{
   // pigpio initialised okay.
}

void gpioTerminate(void)

+Terminates the library. +

Returns nothing. +

Call before program exit. +

This function resets the used DMA channels, releases memory, and +terminates any running threads. +

Example

gpioTerminate();

int gpioSetMode(unsigned gpio, unsigned mode)

+Sets the GPIO mode, typically input or output. +

gpio: 0-53
mode: 0-7


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. +

Arduino style: pinMode. +

Example

gpioSetMode(17, PI_INPUT);  // Set GPIO17 as input.

gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output.

gpioSetMode(22,PI_ALT0);    // Set GPIO22 to alternative mode 0.


See http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf page 102 for an overview of the modes. +

int gpioGetMode(unsigned gpio)

+Gets the GPIO mode. +

gpio: 0-53


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. +

Example

if (gpioGetMode(17) != PI_ALT0)
{
   gpioSetMode(17, PI_ALT0);  // set GPIO17 to ALT0
}

int gpioSetPullUpDown(unsigned gpio, unsigned pud)

+Sets or clears resistor pull ups or downs on the GPIO. +

gpio: 0-53
 pud: 0-2


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. +

Example

gpioSetPullUpDown(17, PI_PUD_UP);   // Sets a pull-up.

gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.

gpioSetPullUpDown(23, PI_PUD_OFF);  // Clear any pull-ups/downs.

int gpioRead(unsigned gpio)

+Reads the GPIO level, on or off. +

gpio: 0-53


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. +

Arduino style: digitalRead. +

Example

printf("GPIO24 is level %d", gpioRead(24));

int gpioWrite(unsigned gpio, unsigned level)

+Sets the GPIO level, on or off. +

 gpio: 0-53
level: 0-1


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. +

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

Arduino style: digitalWrite +

Example

gpioWrite(24, 1); // Set GPIO24 high.

int gpioPWM(unsigned user_gpio, unsigned dutycycle)

+Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). +Range defaults to 255. +

user_gpio: 0-31
dutycycle: 0-range


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. +

Arduino style: analogWrite +

This and the servo functionality use the DMA and PWM or PCM peripherals +to control and schedule the pulse lengths and dutycycles. +

The gpioSetPWMrange function may be used to change the default +range of 255. +

Example

gpioPWM(17, 255); // Sets GPIO17 full on.

gpioPWM(18, 128); // Sets GPIO18 half on.

gpioPWM(23, 0);   // Sets GPIO23 full off.

int gpioGetPWMdutycycle(unsigned user_gpio)

+Returns the PWM dutycycle setting for the GPIO. +

user_gpio: 0-31


Returns between 0 (off) and range (fully on) if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. +

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

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

Normal PWM range defaults to 255. +

int gpioSetPWMrange(unsigned user_gpio, unsigned range)

+Selects the dutycycle range to be used for the GPIO. Subsequent calls +to gpioPWM will use a dutycycle between 0 (off) and range (fully on). +

user_gpio: 0-31
    range: 25-40000


Returns the real range for the given GPIO's frequency if OK, +otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. +

If PWM is currently active on the GPIO its dutycycle will be scaled +to reflect the new range. +

The real range, the number of steps between fully off and fully +on for each frequency, is given in the following table. +

  25,   50,  100,  125,  200,  250,  400,   500,   625,
 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000


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

Example

gpioSetPWMrange(24, 2000); // Now 2000 is fully on
                           //     1000 is half on
                           //      500 is quarter on, etc.

int gpioGetPWMrange(unsigned user_gpio)

+Returns the dutycycle range used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. +

user_gpio: 0-31


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

Example

r = gpioGetPWMrange(23);

int gpioGetPWMrealRange(unsigned user_gpio)

+Returns the real range used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. +

user_gpio: 0-31


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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

Example

rr = gpioGetPWMrealRange(17);

int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)

+Sets the frequency in hertz to be used for the GPIO. +

user_gpio: 0-31
frequency: >=0


Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO. +

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 frequencies for each sample rate are: +

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency.

gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz.

gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency.

int gpioGetPWMfrequency(unsigned user_gpio)

+Returns the frequency (in hertz) used for the GPIO if OK, otherwise +PI_BAD_USER_GPIO. +

user_gpio: 0-31


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

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

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

Example

f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23.

int gpioServo(unsigned user_gpio, unsigned pulsewidth)

+Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to +2500 (most clockwise). +

 user_gpio: 0-31
pulsewidth: 0, 500-2500


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. +

The range supported by servos varies and should probably be determined +by experiment. A value of 1500 should always be safe and represents +the mid-point of rotation. You can DAMAGE a servo if you command it +to move beyond its limits. +

The following 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

gpioServo(17, 1000); // Move servo to safe position anti-clockwise.

gpioServo(23, 1500); // Move servo to centre position.

gpioServo(25, 2000); // Move servo to safe position clockwise.


OTHER UPDATE RATES: +

This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. +

PWM Hz    50   100  200  400  500
1E6/Hz 20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using gpioSetPWMfrequency. +

Then set the PWM range using gpioSetPWMrange to 1E6/frequency. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. +

E.g. If you want to update a servo connected to GPIO25 at 400Hz +

gpioSetPWMfrequency(25, 400);

gpioSetPWMrange(25, 2500);


Thereafter use the PWM command to move the servo, +e.g. gpioPWM(25, 1500) will set a 1500 us pulse. +

int gpioGetServoPulsewidth(unsigned user_gpio)

+Returns the servo pulsewidth setting for the GPIO. +

user_gpio: 0-31


Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) +if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. +

int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)

+Registers a function to be called (a callback) when the specified +GPIO changes state. +

user_gpio: 0-31
        f: the callback function


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. +

One callback may be registered per GPIO. +

The callback is passed the GPIO, the new level, and the tick. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The alert may be cancelled by passing NULL as the function. +

The GPIO are sampled at a rate set when the library is started. +

If a value isn't specifically set the default of 5 us is used. +

The number of samples per second is given in the following table. +

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


Level changes shorter than the sample rate may be missed. +

The thread which calls the alert functions is triggered nominally +1000 times per second. The active alert functions will be called +once per level change since the last time the thread was activated. +i.e. The active alert functions will get all level changes but there +will be a latency. +

If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use gpioRead. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. +

The tick value is the time stamp of the sample in microseconds, see +gpioTick for more details. +

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state

gpioSetAlertFunc(4, aFunction);

int gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) when the specified +GPIO changes state. +

user_gpio: 0-31
        f: the callback function
 userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. +

One callback may be registered per GPIO. +

The callback is passed the GPIO, the new level, the tick, and +the userdata pointer. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


See gpioSetAlertFunc for further details. +

Only one of gpioSetAlertFunc or gpioSetAlertFuncEx can be +registered per GPIO. +

int gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)

+Registers a function to be called (a callback) whenever the specified +GPIO interrupt occurs. +

   gpio: 0-53
   edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
timeout: interrupt timeout in milliseconds (<=0 to cancel)
      f: the callback function


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, +or PI_BAD_ISR_INIT. +

One function may be registered per GPIO. +

The function is passed the GPIO, the current level, and the +current tick. The level will be PI_TIMEOUT if the optional +interrupt timeout expires. +

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The underlying Linux sysfs GPIO interface is used to provide +the interrupt services. +

The first time the function is called, with a non-NULL f, the +GPIO is exported, set to be an input, and set to interrupt +on the given edge and timeout. +

Subsequent calls, with a non-NULL f, can vary one or more of the +edge, timeout, or function. +

The ISR may be cancelled by passing a NULL f, in which case the +GPIO is unexported. +

The tick is that read at the time the process was informed of +the interrupt. This will be a variable number of microseconds +after the interrupt occurred. Typically the latency will be of +the order of 50 microseconds. The latency is not guaranteed +and will vary with system load. +

The level is that read at the time the process was informed of +the interrupt, or PI_TIMEOUT if the optional interrupt timeout +expired. It may not be the same as the expected edge as +interrupts happening in rapid succession may be missed by the +kernel (i.e. this mechanism can not be used to capture several +interrupts only a few microseconds apart). +

int gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) whenever the specified +GPIO interrupt occurs. +

    gpio: 0-53
    edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 timeout: interrupt timeout in milliseconds (<=0 to cancel)
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, +or PI_BAD_ISR_INIT. +

The function is passed the GPIO, the current level, the +current tick, and the userdata pointer. +

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


Only one of gpioSetISRFunc or gpioSetISRFuncEx can be +registered per GPIO. +

See gpioSetISRFunc for further details. +

int gpioNotifyOpen(void)

+This function requests a free notification handle. +

Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. +

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

Pipe notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). E.g. if the +function returns 15 then the notifications must be read +from /dev/pigpio15. +

Socket notifications are returned to the socket which requested the +handle. +

Example

h = gpioNotifyOpen();

if (h >= 0)
{
   sprintf(str, "/dev/pigpio%d", h);

   fd = open(str, O_RDONLY);

   if (fd >= 0)
   {
      // Okay.
   }
   else
   {
      // Error.
   }
}
else
{
   // Error.
}

int gpioNotifyOpenWithSize(int bufSize)

+This function requests a free notification handle. +

It differs from gpioNotifyOpen in that the pipe size may be +specified, whereas gpioNotifyOpen uses the default pipe size. +

See gpioNotifyOpen for further details. +

int gpioNotifyBegin(unsigned handle, uint32_t bits)

+This function starts notifications on a previously opened handle. +

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the GPIO of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

The notification sends state changes for each GPIO whose corresponding +bit in bits is set. +

Each notification occupies 12 bytes in the fifo and has the +following structure. +

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, +PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. +

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. +

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. +

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags +indicate an event which has been triggered. +

tick: the number of microseconds since system boot. It wraps around +after 1h12m. +

level: indicates the level of each GPIO. If bit 1<<x is set then +GPIO x is high. +

Example

// Start notifications for GPIO 1, 4, 6, 7, 10.

//                         1
//                         0  76 4  1
// (1234 = 0x04D2 = 0b0000010011010010)

gpioNotifyBegin(h, 1234);

int gpioNotifyPause(unsigned handle)

+This function pauses notifications on a previously opened handle. +

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Notifications for the handle are suspended until gpioNotifyBegin +is called again. +

Example

gpioNotifyPause(h);

int gpioNotifyClose(unsigned handle)

+This function stops notifications on a previously opened handle +and releases the handle for reuse. +

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Example

gpioNotifyClose(h);

int gpioWaveClear(void)

+This function clears all waveforms and any data added by calls to the +gpioWaveAdd* functions. +

Returns 0 if OK. +

Example

gpioWaveClear();

int gpioWaveAddNew(void)

+This function starts a new empty waveform. +

You wouldn't normally need to call this function as it is automatically +called after a waveform is created with the gpioWaveCreate function. +

Returns 0 if OK. +

Example

gpioWaveAddNew();

int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)

+This function adds a number of pulses to the current waveform. +

numPulses: the number of pulses
   pulses: an array of pulses


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. +

The pulses are interleaved in time order within the existing waveform +(if any). +

Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist of a delay. +

Example

// Construct and send a 30 microsecond square wave.

gpioSetMode(gpio, PI_OUTPUT);

pulse[0].gpioOn = (1<<gpio);
pulse[0].gpioOff = 0;
pulse[0].usDelay = 15;

pulse[1].gpioOn = 0;
pulse[1].gpioOff = (1<<gpio);
pulse[1].usDelay = 15;

gpioWaveAddNew();

gpioWaveAddGeneric(2, pulse);

wave_id = gpioWaveCreate();

if (wave_id >= 0)
{
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);

   // Transmit for 30 seconds.

   sleep(30);

   gpioWaveTxStop();
}
else
{
   // Wave create failed.
}

int gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

+This function adds a waveform representing serial data to the +existing waveform (if any). The serial data starts offset +microseconds from the start of the waveform. +

user_gpio: 0-31
     baud: 50-1000000
data_bits: 1-32
stop_bits: 2-8
   offset: >=0
 numBytes: >=1
      str: an array of chars (which may contain nulls)


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. +

NOTES: +

The serial data is formatted as one start bit, data_bits data bits, and +stop_bits/2 stop bits. +

It is legal to add serial data streams with different baud rates to +the same waveform. +

numBytes is the number of bytes of data in str. +

The bytes required for each character depend upon data_bits. +

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

Example

#define MSG_LEN 8

int i;
char *str;
char data[MSG_LEN];

str = "Hello world!";

gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str);

for (i=0; i<MSG_LEN; i++) data[i] = i;

// Data added is offset 1 second from the waveform start.
gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);

int gpioWaveCreate(void)

+This function creates a waveform from the data provided by the prior +calls to the gpioWaveAdd* functions. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

The data provided by the gpioWaveAdd* functions is consumed by this +function. +

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

Normal usage would be +

Step 1. gpioWaveClear to clear all waveforms and added data. +

Step 2. gpioWaveAdd* calls to supply the waveform data. +

Step 3. gpioWaveCreate to create the waveform and get a unique id +

Repeat steps 2 and 3 as needed. +

Step 4. gpioWaveTxSend with the id of the waveform to transmit. +

A waveform comprises one of more pulses. Each pulse consists of a +gpioPulse_t structure. +

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify +

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +

int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL)

+Similar to gpioWaveCreate, this function creates a waveform but pads the consumed +resources. Padded waves of equal dimension can be re-cycled efficiently allowing +newly created waves to re-use the resources of deleted waves of the same dimension. +

pctCB: 0-100, the percent of all DMA control blocks to consume.
pctBOOL: 0-100, percent On-Off-Level (OOL) buffer to consume for wave output.
pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags).


Upon success a wave id greater than or equal to 0 is returned, otherwise +PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

Waveform data provided by gpioWaveAdd* and rawWaveAdd* functions are +consumed by this function. +

A usage would be the creation of two waves where one is filled while the other +is being transmitted. Each wave is assigned 50% of the resources. +This buffer structure allows the transmission of infinite wave sequences. +

Example

  // get firstWaveChunk, somehow
  gpioWaveAddGeneric(firstWaveChunk);
  wid = gpioWaveCreatePad(50, 50, 0);
  gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
  // get nextWaveChunk

  while (nextWaveChunk) {
     gpioWaveAddGeneric(nextWaveChunk);
     nextWid = gpioWaveCreatePad(50, 50, 0);
     gpioWaveTxSend(nextWid, PI_WAVE_MODE_ONE_SHOT_SYNC);
     while(gpioWaveTxAt() == wid) time_sleep(0.1);
     gpioWaveDelete(wid);
     wid = nextWid;
     // get nextWaveChunk
  }

int gpioWaveDelete(unsigned wave_id)

+This function deletes the waveform with id wave_id. +

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

wave_id: >=0, as returned by gpioWaveCreate


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

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. +

int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)

+This function transmits the waveform with id wave_id. The mode +determines whether the waveform is sent once or cycles endlessly. +The SYNC variants wait for the current waveform to reach the +end of a cycle or finish before starting the new waveform. +

WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. +

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. +

  wave_id: >=0, as returned by gpioWaveCreate
wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
           PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int gpioWaveChain(char *buf, unsigned bufSize)

+This function transmits a chain of waveforms. +

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. +

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

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. +

Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. +

A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. +

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpio.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (gpioInitialise()<0) return -1;

   gpioSetMode(GPIO, PI_OUTPUT);

   printf("start piscope, press return"); getchar();

   for (i=0; i<WAVES; i++)
   {
      gpioWaveAddGeneric(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = gpioWaveCreate();
   }

   gpioWaveChain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (gpioWaveTxBusy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);

   printf("stop piscope, press return"); getchar();

   gpioTerminate();
}

int gpioWaveTxAt(void)

+This function returns the id of the waveform currently being +transmitted. +

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

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
+PI_NO_TX_WAVE (9999) - no wave being transmitted. +

int gpioWaveTxBusy(void)

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

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

int gpioWaveTxStop(void)

+This function aborts the transmission of the current waveform. +

Returns 0 if OK. +

This function is intended to stop a waveform started in repeat mode. +

int gpioWaveGetMicros(void)

+This function returns the length in microseconds of the current +waveform. +

int gpioWaveGetHighMicros(void)

+This function returns the length in microseconds of the longest waveform +created since gpioInitialise was called. +

int gpioWaveGetMaxMicros(void)

+This function returns the maximum possible size of a waveform in +microseconds. +

int gpioWaveGetPulses(void)

+This function returns the length in pulses of the current waveform. +

int gpioWaveGetHighPulses(void)

+This function returns the length in pulses of the longest waveform +created since gpioInitialise was called. +

int gpioWaveGetMaxPulses(void)

+This function returns the maximum possible size of a waveform in pulses. +

int gpioWaveGetCbs(void)

+This function returns the length in DMA control blocks of the current +waveform. +

int gpioWaveGetHighCbs(void)

+This function returns the length in DMA control blocks of the longest +waveform created since gpioInitialise was called. +

int gpioWaveGetMaxCbs(void)

+This function returns the maximum possible size of a waveform in DMA +control blocks. +

int gpioSerialReadOpen(unsigned user_gpio, unsigned baud, unsigned data_bits)

+This function opens a GPIO for bit bang reading of serial data. +

user_gpio: 0-31
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, +PI_BAD_DATABITS, or PI_GPIO_IN_USE. +

The serial data is returned in a cyclic buffer and is read using +gpioSerialRead. +

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

int gpioSerialReadInvert(unsigned user_gpio, unsigned invert)

+This function configures the level logic for bit bang serial reads. +

Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for +normal logic. Default is PI_BB_SER_NORMAL. +

user_gpio: 0-31
   invert: 0-1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, +PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT. +

The GPIO must be opened for bit bang reading of serial data using +gpioSerialReadOpen prior to calling this function. +

int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize)

+This function copies up to bufSize bytes of data read from the +bit bang serial cyclic buffer to the buffer starting at buf. +

user_gpio: 0-31, previously opened with gpioSerialReadOpen
      buf: an array to receive the read bytes
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. +

The bytes returned for each character depend upon the number of +data bits data_bits specified in the gpioSerialReadOpen command. +

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

int gpioSerialReadClose(unsigned user_gpio)

+This function closes a GPIO for bit bang reading of serial data. +

user_gpio: 0-31, previously opened with gpioSerialReadOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. +

int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)

+This returns a handle for the device at the address on the I2C bus. +

  i2cBus: >=0
 i2cAddr: 0-0x7F
i2cFlags: 0


No flags are currently defined. This parameter should be set to zero. +

Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. +

For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. +

S      (1 bit) : Start bit
P      (1 bit) : Stop bit
Rd/Wr  (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA  (1 bit) : Accept and not accept bit.

Addr   (7 bits): I2C 7 bit address.
i2cReg (8 bits): Command byte, a byte which often selects a register.
Data   (8 bits): A data byte.
Count  (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2cClose(unsigned handle)

+This closes the I2C device associated with the handle. +

handle: >=0, as returned by a call to i2cOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int i2cWriteQuick(unsigned handle, unsigned bit)

+This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. +

handle: >=0, as returned by a call to i2cOpen
   bit: 0-1, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Quick command. SMBus 2.0 5.5.1 +S Addr bit [A] P

int i2cWriteByte(unsigned handle, unsigned bVal)

+This sends a single byte to the device associated with handle. +

handle: >=0, as returned by a call to i2cOpen
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Send byte. SMBus 2.0 5.5.2 +S Addr Wr [A] bVal [A] P

int i2cReadByte(unsigned handle)

+This reads a single byte from the device associated with handle. +

handle: >=0, as returned by a call to i2cOpen


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. +

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

int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)

+This writes a single byte to the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write byte. SMBus 2.0 5.5.4 +S Addr Wr [A] i2cReg [A] bVal [A] P

int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)

+This writes a single 16 bit word to the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  wVal: 0-0xFFFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write word. SMBus 2.0 5.5.4 +S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P

int i2cReadByteData(unsigned handle, unsigned i2cReg)

+This reads a single byte from the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read byte. SMBus 2.0 5.5.5 +S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P

int i2cReadWordData(unsigned handle, unsigned i2cReg)

+This reads a single 16 bit word from the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read word. SMBus 2.0 5.5.5 +S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)

+This writes 16 bits of data to the specified register of the device +associated with handle and reads 16 bits of data in return. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
  wVal: 0-0xFFFF, the value to write


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Process call. SMBus 2.0 5.5.6 +S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

+This writes up to 32 bytes to the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: an array with the data to send
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Block write. SMBus 2.0 5.5.7 +S Addr Wr [A] i2cReg [A] count [A]
   buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)

+This reads a block of up to 32 bytes from the specified register of +the device associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data


The amount of returned data is set by the device. +

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Block read. SMBus 2.0 5.5.7 +S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

+This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
   buf: an array with the data to send and to receive the read data
 count: 1-32, the number of bytes to write


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

The SMBus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. +

Block write-block read. SMBus 2.0 5.5.8 +S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A]
   S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P

int i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

+This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data
 count: 1-32, the number of bytes to read


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

+This writes 1 to 32 bytes to the specified register of the device +associated with handle. +

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: the data to write
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadDevice(unsigned handle, char *buf, unsigned count)

+This reads count bytes from the raw device into buf. +

handle: >=0, as returned by a call to i2cOpen
   buf: an array to receive the read data bytes
 count: >0, the number of bytes to read


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. +

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteDevice(unsigned handle, char *buf, unsigned count)

+This writes count bytes from buf to the raw device. +

handle: >=0, as returned by a call to i2cOpen
   buf: an array containing the data bytes to write
 count: >0, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

void i2cSwitchCombined(int setting)

+This sets the I2C (i2c-bcm2708) module "use combined transactions" +parameter on or off. +

setting: 0 to set the parameter off, non-zero to set it on


NOTE: when the flag is on a write followed by a read to the same +slave address will use a repeated start (rather than a stop/start). +

int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)

+This function executes multiple I2C segments in one transaction by +calling the I2C_RDWR ioctl. +

 handle: >=0, as returned by a call to i2cOpen
   segs: an array of I2C segments
numSegs: >0, the number of I2C segments


Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. +

int i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)

+This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. +

Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. +

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

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. +

NOTE: +

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. +

int bbI2CClose(unsigned SDA)

+This function stops bit banging I2C on a pair of GPIO previously +opened with bbI2COpen. +

SDA: 0-31, the SDA GPIO used in a prior call to bbI2COpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +

int bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

   SDA: 0-31 (as used in a prior call to bbI2COpen)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bscXfer(bsc_xfer_t *bsc_xfer)

+This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. +

This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. +

This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. +

The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. +

I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. +

The function sets the BSC mode, writes any data in +the transmit buffer to the BSC transmit FIFO, and +copies any data in the BSC receive FIFO to the +receive buffer. +

bsc_xfer:= a structure defining the transfer

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. +

Upon return rxCnt will be set to the number of received bytes placed +in rxBuf. +

Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. +

GPIO used for models other than those based on the BCM2711. +

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset +to INPUT mode. +

The returned function value is the status of the transfer (see below). +

If there was an error the status will be less than zero +(and will contain the error code). +

The most significant word of the returned status contains the number +of bytes actually copied from txBuf to the BSC transmit FIFO (may be +less than requested if the FIFO already contained untransmitted data). +

control consists of the following bits. +

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. +

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. +

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as +an I2C slave with address 0x13 and send four bytes. +

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bscXfer(&xfer);

if (status >= 0)
{
   // process transfer
}

int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)

+This function selects a set of GPIO for bit banging SPI with +a specified baud rate and mode. +

      CS: 0-31
    MISO: 0-31
    MOSI: 0-31
    SCLK: 0-31
    baud: 50-250000
spiFlags: see below


spiFlags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 +

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. +

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or +PI_GPIO_IN_USE. +

If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. +

Example

bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bbSPIClose(unsigned CS)

+This function stops bit banging SPI on a set of GPIO +opened with bbSPIOpen. +

CS: 0-31, the CS GPIO used in a prior call to bbSPIOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. +

int bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)

+This function executes a bit banged SPI transfer. +

    CS: 0-31 (as used in a prior call to bbSPIOpen)
 inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
 count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. +

Example

// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
// sudo ./bbSPIx_test

#include <stdio.h>

#include "pigpio.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if (gpioInitialise() < 0)
   {
      fprintf(stderr, "pigpio initialisation failed.\n");
      return 1;
   }

   bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bbSPIClose(CE0);
   bbSPIClose(CE1);

   gpioTerminate();

   return 0;
}

int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)

+This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


 spiChan: 0-1 (0-2 for the auxiliary SPI)
    baud: 32K-125M (values above 30M are unlikely to work)
spiFlags: see below


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. +

spiFlags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 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. +

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 spiRead, spiWrite, and spiXfer functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. +

For bits 1-8 there will be one byte per word.
+For bits 9-16 there will be two bytes per word.
+For bits 17-32 there will be four bytes per word. +

Multi-byte transfers are made in least significant byte first order. +

E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. +

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

int spiClose(unsigned handle)

+This functions closes the SPI device identified by the handle. +

handle: >=0, as returned by a call to spiOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int spiRead(unsigned handle, char *buf, unsigned count)

+This function reads count bytes of data from the SPI +device associated with the handle. +

handle: >=0, as returned by a call to spiOpen
   buf: an array to receive the read data bytes
 count: the number of bytes to read


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spiWrite(unsigned handle, char *buf, unsigned count)

+This function writes count bytes of data from buf to the SPI +device associated with the handle. +

handle: >=0, as returned by a call to spiOpen
   buf: the data bytes to write
 count: the number of bytes to write


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

+This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. +

handle: >=0, as returned by a call to spiOpen
 txBuf: the data bytes to write
 rxBuf: the received data bytes
 count: the number of bytes to transfer


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int serOpen(char *sertty, unsigned baud, unsigned serFlags)

+This function opens a serial device at a specified baud rate +and with specified flags. The device name must start with +/dev/tty or /dev/serial. +

  sertty: the serial device to open
    baud: the baud rate in bits per second, see below
serFlags: 0


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. +

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

No flags are currently defined. This parameter should be set to zero. +

int serClose(unsigned handle)

+This function closes the serial device associated with handle. +

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int serWriteByte(unsigned handle, unsigned bVal)

+This function writes bVal to the serial port associated with handle. +

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serReadByte(unsigned handle)

+This function reads a byte from the serial port associated with handle. +

handle: >=0, as returned by a call to serOpen


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. +

If no data is ready PI_SER_READ_NO_DATA is returned. +

int serWrite(unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the serial port +associated with handle. +

handle: >=0, as returned by a call to serOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serRead(unsigned handle, char *buf, unsigned count)

+This function reads up count bytes from the the serial port +associated with handle and writes them to buf. +

handle: >=0, as returned by a call to serOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_SER_READ_NO_DATA. +

If no data is ready zero is returned. +

int serDataAvailable(unsigned handle)

+This function returns the number of bytes available +to be read from the device associated with handle. +

handle: >=0, as returned by a call to serOpen


Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. +

int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

+This function sends a trigger pulse to a GPIO. The GPIO is set to +level for pulseLen microseconds and then reset to not level. +

user_gpio: 0-31
 pulseLen: 1-100
    level: 0,1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, +or PI_BAD_PULSELEN. +

int gpioSetWatchdog(unsigned user_gpio, unsigned timeout)

+Sets a watchdog for a GPIO. +

user_gpio: 0-31
  timeout: 0-60000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. +

The watchdog is nominally in milliseconds. +

One watchdog may be registered per GPIO. +

The watchdog may be cancelled by setting timeout to 0. +

Until cancelled a timeout will be reported every timeout milliseconds +after the last GPIO activity. +

In particular: +

1) any registered alert function for the GPIO will be called with + the level set to PI_TIMEOUT. +

2) any notification for the GPIO will have a report written to the + fifo with the flags set to indicate a watchdog timeout. +

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state
gpioSetAlertFunc(4, aFunction);

//  or approximately every 5 millis
gpioSetWatchdog(4, 5);

int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)

+Sets a noise filter on a GPIO. +

Level changes on the GPIO are ignored until a level which has +been stable for steady microseconds is detected. Level changes +on the GPIO are then reported for active microseconds after +which the process repeats. +

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, +and gpioSetGetSamplesFuncEx. +

It does not affect interrupts set up with gpioSetISRFunc, +gpioSetISRFuncEx, or levels read by gpioRead, +gpioRead_Bits_0_31, or gpioRead_Bits_32_53. +

Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

int gpioGlitchFilter(unsigned user_gpio, unsigned steady)

+Sets a glitch filter on a GPIO. +

Level changes on the GPIO are not reported unless the level +has been stable for at least steady microseconds. The +level is then reported. Level changes of less than steady +microseconds are ignored. +

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, +and gpioSetGetSamplesFuncEx. +

It does not affect interrupts set up with gpioSetISRFunc, +gpioSetISRFuncEx, or levels read by gpioRead, +gpioRead_Bits_0_31, or gpioRead_Bits_32_53. +

Each (stable) edge will be timestamped steady microseconds +after it was first detected. +

int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)

+Registers a function to be called (a callback) every millisecond +with the latest GPIO samples. +

   f: the function to call
bits: the GPIO of interest


Returns 0 if OK. +

The function is passed a pointer to the samples (an array of +gpioSample_t), and the number of samples. +

Only one function can be registered. +

The callback may be cancelled by passing NULL as the function. +

The samples returned will be the union of bits, plus any active alerts, +plus any active notifications. +

e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO +8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO +7, 8, 9, 10, 17, 23, and 24 will be reported. +

int gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)

+Registers a function to be called (a callback) every millisecond +with the latest GPIO samples. +

       f: the function to call
    bits: the GPIO of interest
userdata: a pointer to arbitrary user data


Returns 0 if OK. +

The function is passed a pointer to the samples (an array of +gpioSample_t), the number of samples, and the userdata pointer. +

Only one of gpioGetSamplesFunc or gpioGetSamplesFuncEx can be +registered. +

See gpioSetGetSamplesFunc for further details. +

int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)

+Registers a function to be called (a callback) every millis milliseconds. +

 timer: 0-9
millis: 10-60000
     f: the function to call


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. +

10 timers are supported numbered 0 to 9. +

One function may be registered per timer. +

The timer may be cancelled by passing NULL as the function. +

Example

void bFunction(void)
{
   printf("two seconds have elapsed");
}

// call bFunction every 2000 milliseconds
gpioSetTimerFunc(0, 2000, bFunction);

int gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) every millis milliseconds. +

   timer: 0-9.
  millis: 10-60000
       f: the function to call
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. +

The function is passed the userdata pointer. +

Only one of gpioSetTimerFunc or gpioSetTimerFuncEx can be +registered per timer. +

See gpioSetTimerFunc for further details. +

pthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)

+Starts a new thread of execution with f as the main routine. +

       f: the main function for the new thread
userdata: a pointer to arbitrary user data


Returns a pointer to pthread_t if OK, otherwise NULL. +

The function is passed the single argument arg. +

The thread can be cancelled by passing the pointer to pthread_t to +gpioStopThread. +

Example

#include <stdio.h>
#include <pigpio.h>

void *myfunc(void *arg)
{
   while (1)
   {
      printf("%s", arg);
      sleep(1);
   }
}

int main(int argc, char *argv[])
{
   pthread_t *p1, *p2, *p3;

   if (gpioInitialise() < 0) return 1;

   p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);

   p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);

   p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);

   gpioStopThread(p3); sleep(3);

   gpioStopThread(p2); sleep(3);

   gpioStopThread(p1); sleep(3);

   gpioTerminate();
}

void gpioStopThread(pthread_t *pth)

+Cancels the thread pointed at by pth. +

pth: a thread pointer returned by gpioStartThread


No value is returned. +

The thread to be stopped should have been started with gpioStartThread. +

int gpioStoreScript(char *script)

+This function stores a null terminated script for later execution. +

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. +

script: the text of the script


The function returns a script id if the script is valid, +otherwise PI_BAD_SCRIPT. +

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

+This function runs a stored script. +

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

+This function runs a stored script. +

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)

+This function sets the parameters of a script. The script may or +may not be running. The first numPar parameters of the script are +overwritten with the new values. +

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int gpioScriptStatus(unsigned script_id, uint32_t *param)

+This function returns the run status of a stored script as well as +the current values of parameters 0 to 9. +

script_id: >=0, as returned by gpioStoreScript
    param: an array to hold the returned 10 parameters


The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. +

The run status may be +

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. +

int gpioStopScript(unsigned script_id)

+This function stops a running script. +

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int gpioDeleteScript(unsigned script_id)

+This function deletes a stored script. +

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)

+Registers a function to be called (a callback) when a signal occurs. +

signum: 0-63
     f: the callback function


Returns 0 if OK, otherwise PI_BAD_SIGNUM. +

The function is passed the signal number. +

One function may be registered per signal. +

The callback may be cancelled by passing NULL. +

By default all signals are treated as fatal and cause the library +to call gpioTerminate and then exit. +

int gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) when a signal occurs. +

  signum: 0-63
       f: the callback function
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_SIGNUM. +

The function is passed the signal number and the userdata pointer. +

Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be +registered per signal. +

See gpioSetSignalFunc for further details. +

uint32_t gpioRead_Bits_0_31(void)

+Returns the current level of GPIO 0-31. +

uint32_t gpioRead_Bits_32_53(void)

+Returns the current level of GPIO 32-53. +

int gpioWrite_Bits_0_31_Clear(uint32_t bits)

+Clears GPIO 0-31 if the corresponding bit in bits is set. +

bits: a bit mask of GPIO to clear


Returns 0 if OK. +

Example

// To clear (set to 0) GPIO 4, 7, and 15
gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );

int gpioWrite_Bits_32_53_Clear(uint32_t bits)

+Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

bits: a bit mask of GPIO to clear


Returns 0 if OK. +

int gpioWrite_Bits_0_31_Set(uint32_t bits)

+Sets GPIO 0-31 if the corresponding bit in bits is set. +

bits: a bit mask of GPIO to set


Returns 0 if OK. +

int gpioWrite_Bits_32_53_Set(uint32_t bits)

+Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

bits: a bit mask of GPIO to set


Returns 0 if OK. +

Example

// To set (set to 1) GPIO 32, 40, and 53
gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));

int gpioHardwareClock(unsigned gpio, unsigned clkfreq)

+Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. +

   gpio: see description
clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, +PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. +

The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. +

The GPIO must be one of the following. +

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely +crash the Pi. The password is given by or'ing 0x5A000000 with the +GPIO number. +

int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)

+Starts hardware PWM on a GPIO at the specified frequency and dutycycle. +Frequencies above 30MHz are unlikely to work. +

NOTE: Any waveform started by gpioWaveTxSend, or +gpioWaveChain will be cancelled. +

This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden by a call to +gpioCfgClock. +

   gpio: see description
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, +PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. +

The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. +

The GPIO must be one of the following. +

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). +

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

There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. PWMduty is +automatically scaled to take this into account. +

int gpioTime(unsigned timetype, int *seconds, int *micros)

+Updates the seconds and micros variables with the current time. +

timetype: 0 (relative), 1 (absolute)
 seconds: a pointer to an int to hold seconds
  micros: a pointer to an int to hold microseconds


Returns 0 if OK, otherwise PI_BAD_TIMETYPE. +

If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the +number of seconds and microseconds since the epoch (1st January 1970). +

If timetype is PI_TIME_RELATIVE updates seconds and micros with the +number of seconds and microseconds since the library was initialised. +

Example

int secs, mics;

// print the number of seconds since the library was started
gpioTime(PI_TIME_RELATIVE, &secs, &mics);
printf("library started %d.%03d seconds ago", secs, mics/1000);

int gpioSleep(unsigned timetype, int seconds, int micros)

+Sleeps for the number of seconds and microseconds specified by seconds +and micros. +

timetype: 0 (relative), 1 (absolute)
 seconds: seconds to sleep
  micros: microseconds to sleep


Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, +or PI_BAD_MICROS. +

If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds +and microseconds since the epoch (1st January 1970) has elapsed. System +clock changes are taken into account. +

If timetype is PI_TIME_RELATIVE the sleep is for the specified number +of seconds and microseconds. System clock changes do not effect the +sleep length. +

For short delays (say, 50 microseonds or less) use gpioDelay. +

Example

gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds

gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds

gpioSleep(PI_TIME_RELATIVE, 60, 0);     // sleep for one minute

uint32_t gpioDelay(uint32_t micros)

+Delays for at least the number of microseconds specified by micros. +

micros: the number of microseconds to sleep


Returns the actual length of the delay in microseconds. +

Delays of 100 microseconds or less use busy waits. +

uint32_t gpioTick(void)

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

You don't need to worry about the wrap around as long as you +take a tick (uint32_t) from another tick, i.e. the following +code will always provide the correct difference. +

Example

uint32_t startTick, endTick;
int diffTick;

startTick = gpioTick();

// do some processing

endTick = gpioTick();

diffTick = endTick - startTick;

printf("some processing took %d microseconds", diffTick);

unsigned gpioHardwareRevision(void)

+Returns the hardware revision. +

If the hardware revision can not be found or is not a valid hexadecimal +number the function returns 0. +

The hardware revision is the last few characters on the Revision line of +/proc/cpuinfo. +

The revision number can be used to determine the assignment of GPIO +to pins (see gpio). +

There are at least three types of board. +

Type 1 boards have hardware revision numbers of 2 and 3. +

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. +

Type 3 boards have hardware revision numbers of 16 or greater. +

for "Revision : 0002" the function returns 2.
+for "Revision : 000f" the function returns 15.
+for "Revision : 000g" the function returns 0. +

unsigned gpioVersion(void)

+Returns the pigpio version. +

int gpioGetPad(unsigned pad)

+This function returns the pad drive strength in mA. +

pad: 0-2, the pad to get


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. +

PadGPIO
00-27
128-45
246-53


Example

strength = gpioGetPad(1); // get pad 1 strength

int gpioSetPad(unsigned pad, unsigned padStrength)

+This function sets the pad drive strength in mA. +

        pad: 0-2, the pad to set
padStrength: 1-16 mA


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. +

PadGPIO
00-27
128-45
246-53


Example

gpioSetPad(0, 16); // set pad 0 strength to 16 mA

int eventMonitor(unsigned handle, uint32_t bits)

+This function selects the events to be reported on a previously +opened handle. +

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the events of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

A report is sent each time an event is triggered providing the +corresponding bit in bits is set. +

See gpioNotifyBegin for the notification format. +

Example

// Start reporting events 3, 6, and 7.

//  bit      76543210
// (0xC8 = 0b11001000)

eventMonitor(h, 0xC8);

int eventSetFunc(unsigned event, eventFunc_t f)

+Registers a function to be called (a callback) when the specified +event occurs. +

event: 0-31
    f: the callback function


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

One function may be registered per event. +

The function is passed the event, and the tick. +

The callback may be cancelled by passing NULL as the function. +

int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)

+Registers a function to be called (a callback) when the specified +event occurs. +

   event: 0-31
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

One function may be registered per event. +

The function is passed the event, the tick, and the ueserdata pointer. +

The callback may be cancelled by passing NULL as the function. +

Only one of eventSetFunc or eventSetFuncEx can be +registered per event. +

int eventTrigger(unsigned event)

+This function signals the occurrence of an event. +

event: 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

An event is a signal used to inform one or more consumers +to start an action. Each consumer which has registered an interest +in the event (e.g. by calling eventSetFunc) will be informed by +a callback. +

One event, PI_EVENT_BSC (31) is predefined. This event is +auto generated on BSC slave activity. +

The meaning of other events is arbitrary. +

Note that other than its id and its tick there is no data associated +with an event. +

int shell(char *scriptName, char *scriptString)

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

  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name
scriptString: the string to pass to the script


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

scriptName must exist in /opt/pigpio/cgi and must be executable. +

The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. +

The following table gives some example returned statuses. +

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell("scr1", "\"hello string with spaces world\"");

int fileOpen(char *file, unsigned mode)

+This function returns a handle to a file opened in a specified mode. +

file: the file to open
mode: the file open mode


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. +

File +

A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. +

Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. +

Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. +

Suppose /opt/pigpio/access contains the following entries +

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception +of file.txt. +

Files may be read in directory dir_2. +

Files may be read and written in directory dir_3. +

If a directory allows read, write, or read/write access then files may +be created in that directory. +

In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. +

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode +

The mode may have the following values. +

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


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

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. +

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int handle, c;
   char buf[60000];

   if (gpioInitialise() < 0) return 1;

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

   handle = fileOpen("/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=fileRead(handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      fileClose(handle);
   }

   gpioTerminate();
}

int fileClose(unsigned handle)

+This function closes the file associated with handle. +

handle: >=0, as returned by a call to fileOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Example

fileClose(h);

int fileWrite(unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the file +associated with handle. +

handle: >=0, as returned by a call to fileOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. +

Example

status = fileWrite(h, buf, count);
if (status == 0)
{
   // okay
}
else
{
   // error
}

int fileRead(unsigned handle, char *buf, unsigned count)

+This function reads up to count bytes from the the file +associated with handle and writes them to buf. +

handle: >=0, as returned by a call to fileOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. +

Example

if (fileRead(h, buf, sizeof(buf)) > 0)
{
   // process read data
}

int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)

+This function seeks to a position within the file associated +with handle. +

    handle: >=0, as returned by a call to fileOpen
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2)


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. +

Example

fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20

size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size

pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position

int fileList(char *fpat, char *buf, unsigned count)

+This function returns a list of files which match a pattern. The +pattern may contain wildcards. +

 fpat: file pattern to match
  buf: an array to receive the matching file names
count: the maximum number of bytes to read


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. +

The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See fileOpen. +

NOTE +

The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. +

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int c;
   char buf[1000];

   if (gpioInitialise() < 0) return 1;

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

   c = fileList("/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      // terminate string
      buf[c] = 0;
      printf("%s", buf);
   }

   gpioTerminate();
}

int gpioCfgBufferSize(unsigned cfgMillis)

+Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. +

This function is only effective if called before gpioInitialise. +

cfgMillis: 100-10000


The default setting is 120 milliseconds. +

The intention is to allow for bursts of data and protection against +other processes hogging cpu time. +

I haven't seen a process locked out for more than 100 milliseconds. +

Making the buffer bigger uses a LOT of memory at the more frequent +sampling rates as shown in the following table in MBs. +

                     buffer milliseconds
               120 250 500 1sec 2sec 4sec 8sec

         1      16  31  55  107  ---  ---  ---
         2      10  18  31   55  107  ---  ---
sample   4       8  12  18   31   55  107  ---
 rate    5       8  10  14   24   45   87  ---
 (us)    8       6   8  12   18   31   55  107
        10       6   8  10   14   24   45   87

int gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)

+Configures pigpio to use a particular sample rate timed by a specified +peripheral. +

This function is only effective if called before gpioInitialise. +

    cfgMicros: 1, 2, 4, 5, 8, 10
cfgPeripheral: 0 (PWM), 1 (PCM)
    cfgSource: deprecated, value is ignored


The timings are provided by the specified peripheral (PWM or PCM). +

The default setting is 5 microseconds using the PCM peripheral. +

The approximate CPU percentage used for each sample rate is: +

sample  cpu
 rate    %

  1     25
  2     16
  4     11
  5     10
  8     15
 10     14


A sample rate of 5 microseconds seeems to be the sweet spot. +

int gpioCfgDMAchannel(unsigned DMAchannel)

+Configures pigpio to use the specified DMA channel. +

This function is only effective if called before gpioInitialise. +

DMAchannel: 0-14


The default setting is to use channel 14. +

int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)

+Configures pigpio to use the specified DMA channels. +

This function is only effective if called before gpioInitialise. +

  primaryChannel: 0-14
secondaryChannel: 0-14


The default setting depends on whether the Pi has a BCM2711 chip or +not (currently only the Pi4B has a BCM2711). +

The default setting for a non-BCM2711 is to use channel 14 for the +primary channel and channel 6 for the secondary channel. +

The default setting for a BCM2711 is to use channel 7 for the +primary channel and channel 6 for the secondary channel. +

The secondary channel is only used for the transmission of waves. +

If possible use one of channels 0 to 6 for the secondary channel +(a full channel). +

A full channel only requires one DMA control block regardless of the +length of a pulse delay. Channels 7 to 14 (lite channels) require +one DMA control block for each 16383 microseconds of delay. I.e. +a 10 second pulse delay requires one control block on a full channel +and 611 control blocks on a lite channel. +

int gpioCfgPermissions(uint64_t updateMask)

+Configures pigpio to restrict GPIO updates via the socket or pipe +interfaces to the GPIO specified by the mask. Programs directly +calling the pigpio library (i.e. linked with -lpigpio are not +affected). A GPIO update is a write to a GPIO or a GPIO mode +change or any function which would force such an action. +

This function is only effective if called before gpioInitialise. +

updateMask: bit (1<<n) is set for each GPIO n which may be updated


The default setting depends upon the Pi model. The user GPIO are +added to the mask. +

If the board revision is not recognised then GPIO 2-27 are allowed. +

Unknown boardPI_DEFAULT_UPDATE_MASK_UNKNOWN0x0FFFFFFC
Type 1 boardPI_DEFAULT_UPDATE_MASK_B10x03E6CF93
Type 2 boardPI_DEFAULT_UPDATE_MASK_A_B20xFBC6CF9C
Type 3 boardPI_DEFAULT_UPDATE_MASK_R30x0FFFFFFC

int gpioCfgSocketPort(unsigned port)

+Configures pigpio to use the specified socket port. +

This function is only effective if called before gpioInitialise. +

port: 1024-32000


The default setting is to use port 8888. +

int gpioCfgInterfaces(unsigned ifFlags)

+Configures pigpio support of the fifo and socket interfaces. +

This function is only effective if called before gpioInitialise. +

ifFlags: 0-7


The default setting (0) is that both interfaces are enabled. +

Or in PI_DISABLE_FIFO_IF to disable the pipe interface. +

Or in PI_DISABLE_SOCK_IF to disable the socket interface. +

Or in PI_LOCALHOST_SOCK_IF to disable remote socket +access (this means that the socket interface is only +usable from the local Pi). +

int gpioCfgMemAlloc(unsigned memAllocMode)

+Selects the method of DMA memory allocation. +

This function is only effective if called before gpioInitialise. +

memAllocMode: 0-2


There are two methods of DMA memory allocation. The original method +uses the /proc/self/pagemap file to allocate bus memory. The new +method uses the mailbox property interface to allocate bus memory. +

Auto will use the mailbox method unless a larger than default buffer +size is requested with gpioCfgBufferSize. +

int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)

+Sets the network addresses which are allowed to talk over the +socket interface. +

This function is only effective if called before gpioInitialise. +

numSockAddr: 0-256 (0 means all addresses allowed)
   sockAddr: an array of permitted network addresses.

int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)

+Used to tune internal settings. +

cfgWhat: see source code
 cfgVal: see source code

uint32_t gpioCfgGetInternals(void)

+This function returns the current library internal configuration +settings. +

int gpioCfgSetInternals(uint32_t cfgVal)

+This function sets the current library internal configuration +settings. +

cfgVal: see source code

int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

+This function is available for user customisation. +

It returns a single integer value. +

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. +

int gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

+This function is available for user customisation. +

It differs from gpioCustom1 in that it returns an array of bytes +rather than just an integer. +

The returned value is an integer indicating the number of returned bytes. +  arg1: >=0
  argx: extra (byte) arguments
  argc: number of extra arguments
retBuf: buffer for returned bytes
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. +

The number of returned bytes must be retMax or less. +

int rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)

+This function adds a waveform representing SPI data to the +existing waveform (if any). +

        spi: a pointer to a spi object
     offset: microseconds from the start of the waveform
      spiSS: the slave select GPIO
        buf: the bits to transmit, most significant bit first
  spiTxBits: the number of bits to write
spiBitFirst: the first bit to read
 spiBitLast: the last bit to read
    spiBits: the number of bits to transfer


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. +

Not intended for general use. +

int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)

+This function adds a number of pulses to the current waveform. +

numPulses: the number of pulses
   pulses: the array containing the pulses


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. +

The advantage of this function over gpioWaveAddGeneric is that it +allows the setting of the flags field. +

The pulses are interleaved in time order within the existing waveform +(if any). +

Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist of a delay. +

Not intended for general use. +

unsigned rawWaveCB(void)

+Returns the number of the cb being currently output. +

Not intended for general use. +

rawCbs_t *rawWaveCBAdr(int cbNum)

+Return the (Linux) address of contol block cbNum. +

cbNum: the cb of interest


Not intended for general use. +

uint32_t rawWaveGetOOL(int pos)

+Gets the OOL parameter stored at pos. +

pos: the position of interest.


Not intended for general use. +

void rawWaveSetOOL(int pos, uint32_t lVal)

+Sets the OOL parameter stored at pos to value. +

 pos: the position of interest
lVal: the value to write


Not intended for general use. +

uint32_t rawWaveGetOut(int pos)

+Gets the wave output parameter stored at pos. +

DEPRECATED: use rawWaveGetOOL instead. +

pos: the position of interest.


Not intended for general use. +

void rawWaveSetOut(int pos, uint32_t lVal)

+Sets the wave output parameter stored at pos to value. +

DEPRECATED: use rawWaveSetOOL instead. +

 pos: the position of interest
lVal: the value to write


Not intended for general use. +

uint32_t rawWaveGetIn(int pos)

+Gets the wave input value parameter stored at pos. +

DEPRECATED: use rawWaveGetOOL instead. +

pos: the position of interest


Not intended for general use. +

void rawWaveSetIn(int pos, uint32_t lVal)

+Sets the wave input value stored at pos to value. +

DEPRECATED: use rawWaveSetOOL instead. +

 pos: the position of interest
lVal: the value to write


Not intended for general use. +

rawWaveInfo_t rawWaveInfo(int wave_id)

+Gets details about the wave with id wave_id. +

wave_id: the wave of interest


Not intended for general use. +

int getBitInBytes(int bitPos, char *buf, int numBits)

+Returns the value of the bit bitPos bits from the start of buf. Returns +0 if bitPos is greater than or equal to numBits. +

 bitPos: bit index from the start of buf
    buf: array of bits
numBits: number of valid bits in buf

void putBitInBytes(int bitPos, char *buf, int bit)

+Sets the bit bitPos bits from the start of buf to bit. +

bitPos: bit index from the start of buf
   buf: array of bits
   bit: 0-1, value to set

double time_time(void)

+Return the current time in seconds since the Epoch. +

void time_sleep(double seconds)

+Delay execution for a given number of seconds +

seconds: the number of seconds to sleep

void rawDumpWave(void)

+Used to print a readable version of the current waveform to stderr. +

Not intended for general use. +

void rawDumpScript(unsigned script_id)

+Used to print a readable version of a script to stderr. +

script_id: >=0, a script_id returned by gpioStoreScript


Not intended for general use. +

PARAMETERS

active: 0-1000000

+The number of microseconds level changes are reported for once +a noise filter has been triggered (by steady microseconds of +a stable level). +

arg1

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

arg2

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

argc

+The count of bytes passed to a user customised function. +

*argx

+A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. +

baud

+The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. +

bit

+A value of 0 or 1. +

bitPos

+A bit position within a byte or word. The least significant bit is +position 0. +

bits

+A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. +

A convenient way to set bit n is to or in (1<<n). +

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). +

*bsc_xfer

+A pointer to a bsc_xfer_t object used to control a BSC transfer. +

bsc_xfer_t

+typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*buf

+A buffer to hold data being sent or being received. +

bufSize

+The size in bytes of a buffer. +

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

+An 8-bit byte value. +

cbNum

+A number identifying a DMA contol block. +

cfgMicros

+The GPIO sample rate in microseconds. The default is 5us, or 200 thousand +samples per second. +

cfgMillis: 100-10000

+The size of the sample buffer in milliseconds. Generally this should be +left at the default of 120ms. If you expect intense bursts of signals it +might be necessary to increase the buffer size. +

cfgPeripheral

+One of the PWM or PCM peripherals used to pace DMA transfers for timing +purposes. +

cfgSource

+Deprecated. +

cfgVal

+A number specifying the value of a configuration item. See cfgWhat. +

cfgWhat

+A number specifying a configuration item. +

562484977: print enhanced statistics at termination.
+984762879: set the initial debug level. +

char

+A single character, an 8 bit quantity able to store 0-255. +

clkfreq: 4689-250M (13184-375M for the BCM2711)

+The hardware clock frequency. +

PI_HW_CLK_MIN_FREQ 4689
PI_HW_CLK_MAX_FREQ 250000000
PI_HW_CLK_MAX_FREQ_2711 375000000

count

+The number of bytes to be transferred in an I2C, SPI, or Serial +command. +

CS

+The GPIO used for the slave select signal when bit banging SPI. +

data_bits: 1-32

+The number of data bits to be used when adding serial data to a +waveform. +

PI_MIN_WAVE_DATABITS 1
PI_MAX_WAVE_DATABITS 32

DMAchannel: 0-15

+PI_MIN_DMA_CHANNEL 0
PI_MAX_DMA_CHANNEL 15

double

+A floating point number. +

dutycycle: 0-range

+A number representing the ratio of on time to off time for PWM. +

The number may vary between 0 and range (default 255) where +0 is off and range is fully on. +

edge: 0-2

+The type of GPIO edge to generate an interrupt. See gpioSetISRFunc +and gpioSetISRFuncEx. +

RISING_EDGE 0
FALLING_EDGE 1
EITHER_EDGE 2

event: 0-31

+An event is a signal used to inform one or more consumers +to start an action. +

eventFunc_t

+typedef void (*eventFunc_t) (int event, uint32_t tick);

eventFuncEx_t

+typedef void (*eventFuncEx_t)
   (int event, uint32_t tick, void *userdata);

f

+A function. +

*file

+A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. +

*fpat

+A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. +

frequency: >=0

+The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. +

gpio

+A Broadcom numbered GPIO, in the range 0-53. +

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

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

gpioAlertFunc_t

+typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);

gpioAlertFuncEx_t

+typedef void (*eventFuncEx_t)
   (int event, int level, uint32_t tick, void *userdata);

gpioCfg*

+These functions are only effective if called before gpioInitialise. +

gpioCfgBufferSize
+gpioCfgClock
+gpioCfgDMAchannel
+gpioCfgDMAchannels
+gpioCfgPermissions
+gpioCfgInterfaces
+gpioCfgSocketPort
+gpioCfgMemAlloc +

gpioGetSamplesFunc_t

+typedef void (*gpioGetSamplesFunc_t)
   (const gpioSample_t *samples, int numSamples);

gpioGetSamplesFuncEx_t

+typedef void (*gpioGetSamplesFuncEx_t)
   (const gpioSample_t *samples, int numSamples, void *userdata);

gpioISRFunc_t

+typedef void (*gpioISRFunc_t)
   (int gpio, int level, uint32_t tick);

gpioISRFuncEx_t

+typedef void (*gpioISRFuncEx_t)
   (int gpio, int level, uint32_t tick, void *userdata);

gpioPulse_t

+typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioSample_t

+typedef struct
{
   uint32_t tick;
   uint32_t level;
} gpioSample_t;

gpioSignalFunc_t

+typedef void (*gpioSignalFunc_t) (int signum);

gpioSignalFuncEx_t

+typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);

gpioThreadFunc_t

+typedef void *(gpioThreadFunc_t) (void *);

gpioTimerFunc_t

+typedef void (*gpioTimerFunc_t) (void);

gpioTimerFuncEx_t

+typedef void (*gpioTimerFuncEx_t) (void *userdata);

gpioWaveAdd*

+One of +

gpioWaveAddNew
+gpioWaveAddGeneric
+gpioWaveAddSerial +

handle: >=0

+A number referencing an object opened by one of +

fileOpen
+gpioNotifyOpen
+i2cOpen
+serOpen
+spiOpen +

i2cAddr: 0-0x7F

+The address of a device on the I2C bus. +

i2cBus: >=0

+An I2C bus number. +

i2cFlags: 0

+Flags which modify an I2C open command. None are currently defined. +

i2cReg: 0-255

+A register of an I2C device. +

ifFlags: 0-3

+PI_DISABLE_FIFO_IF 1
PI_DISABLE_SOCK_IF 2

*inBuf

+A buffer used to pass data to a function. +

inLen

+The number of bytes of data in a buffer. +

int

+A whole number, negative or positive. +

int32_t

+A 32-bit signed value. +

invert

+A flag used to set normal or inverted bit bang serial data level logic. +

level

+The level of a GPIO. Low or High. +

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See gpioSetWatchdog. +

PI_TIMEOUT 2

lVal: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)

+A 32-bit word value. +

memAllocMode: 0-2

+The DMA memory allocation mode. +

PI_MEM_ALLOC_AUTO    0
PI_MEM_ALLOC_PAGEMAP 1
PI_MEM_ALLOC_MAILBOX 2

*micros

+A value representing microseconds. +

micros

+A value representing microseconds. +

millis

+A value representing milliseconds. +

MISO

+The GPIO used for the MISO signal when bit banging SPI. +

mode

+1. The operational mode of a GPIO, normally INPUT or OUTPUT. +

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. A file open mode. +

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


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

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

+The GPIO used for the MOSI signal when bit banging SPI. +

numBits

+The number of bits stored in a buffer. +

numBytes

+The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. +

numPar: 0-10

+The number of parameters passed to a script. +

numPulses

+The number of pulses to be added to a waveform. +

numSegs

+The number of segments in a combined I2C transaction. +

numSockAddr

+The number of network addresses allowed to use the socket interface. +

0 means all addresses allowed. +

offset

+The associated data starts this number of microseconds from the start of +the waveform. +

*outBuf

+A buffer used to return data from a function. +

outLen

+The size in bytes of an output buffer. +

pad: 0-2

+A set of GPIO which share common drivers. +

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

+The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. +

*param

+An array of script parameters. +

pi_i2c_msg_t

+typedef struct
{
   uint16_t addr;  // slave address
   uint16_t flags;
   uint16_t len;   // msg length
   uint8_t  *buf;  // pointer to msg data
} pi_i2c_msg_t;

port: 1024-32000

+The port used to bind to the pigpio socket. Defaults to 8888. +

pos

+The position of an item. +

primaryChannel: 0-15

+The DMA channel used to time the sampling of GPIO and to time servo and +PWM pulses. +

*pth

+A thread identifier, returned by gpioStartThread. +

pthread_t

+A thread identifier. +

pud: 0-2

+The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. +

PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

+1-100, the length of a trigger pulse in microseconds. +

*pulses

+An array of pulses to be added to a waveform. +

pulsewidth: 0, 500-2500

+PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

+The hardware PWM dutycycle. +

PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

+The hardware PWM frequency. +

PI_HW_PWM_MIN_FREQ 1
PI_HW_PWM_MAX_FREQ 125000000
PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

+PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

rawCbs_t

+typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
{
   unsigned long info;
   unsigned long src;
   unsigned long dst;
   unsigned long length;
   unsigned long stride;
   unsigned long next;
   unsigned long pad[2];
} rawCbs_t;

rawSPI_t

+typedef struct
{
   int clk;     // GPIO for clock
   int mosi;    // GPIO for MOSI
   int miso;    // GPIO for MISO
   int ss_pol;  // slave select off state
   int ss_us;   // delay after slave select
   int clk_pol; // clock off state
   int clk_pha; // clock phase
   int clk_us;  // clock micros
} rawSPI_t;

rawWave_t

+typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
   uint32_t flags;
} rawWave_t;

rawWaveInfo_t

+typedef struct
{
   uint16_t botCB;  // first CB used by wave
   uint16_t topCB;  // last CB used by wave
   uint16_t botOOL; // last OOL used by wave
   uint16_t topOOL; // first OOL used by wave
   uint16_t deleted;
   uint16_t numCB;
   uint16_t numBOOL;
   uint16_t numTOOL;
} rawWaveInfo_t;

*retBuf

+A buffer to hold a number of bytes returned to a used customised function, +

retMax

+The maximum number of bytes a user customised function should return. +

*rxBuf

+A pointer to a buffer to receive data. +

SCL

+The user GPIO to use for the clock when bit banging I2C. +

SCLK

+The GPIO used for the SCLK signal when bit banging SPI. +

*script

+A pointer to the text of a script. +

script_id

+An id of a stored script as returned by gpioStoreScript. +

*scriptName

+The name of a shell script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. +

*scriptString

+The string to be passed to a shell script to be executed. +

SDA

+The user GPIO to use for data when bit banging I2C. +

secondaryChannel: 0-6

+The DMA channel used to time output waveforms. +

*seconds

+A pointer to a uint32_t to store the second component of +a returned time. +

seconds

+The number of seconds. +

seekFrom

+PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

+The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). +

*segs

+An array of segments which make up a combined I2C transaction. +

serFlags

+Flags which modify a serial open command. None are currently defined. +

*sertty

+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. +

setting

+A value used to set a flag, 0 for false, non-zero for true. +

signum: 0-63

+PI_MIN_SIGNUM 0
PI_MAX_SIGNUM 63

size_t

+A standard type used to indicate the size of an object in bytes. +

*sockAddr

+An array of network addresses allowed to use the socket interface encoded +as 32 bit numbers. +

E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. +

*spi

+A pointer to a rawSPI_t structure. +

spiBitFirst

+GPIO reads are made from spiBitFirst to spiBitLast. +

spiBitLast

+GPIO reads are made from spiBitFirst to spiBitLast. +

spiBits

+The number of bits to transfer in a raw SPI transaction. +

spiChan

+A SPI channel, 0-2. +

spiFlags

+See spiOpen and bbSPIOpen. +

spiSS

+The SPI slave select GPIO in a raw SPI transaction. +

spiTxBits

+The number of bits to transfer dring a raw SPI transaction +

steady: 0-300000

+The number of microseconds level changes must be stable for +before reporting the level changed (gpioGlitchFilter) or triggering +the active part of a noise filter (gpioNoiseFilter). +

stop_bits: 2-8

+The number of (half) stop bits to be used when adding serial data +to a waveform. +

PI_MIN_WAVE_HALFSTOPBITS 2
PI_MAX_WAVE_HALFSTOPBITS 8

*str

+An array of characters. +

timeout

+A GPIO level change timeout in milliseconds. +

gpioSetWatchdog +PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000


gpioSetISRFunc and gpioSetISRFuncEx +<=0 cancel timeout
>0 timeout after specified milliseconds

timer

+PI_MIN_TIMER 0
PI_MAX_TIMER 9

timetype

+PI_TIME_RELATIVE 0
PI_TIME_ABSOLUTE 1

*txBuf

+An array of bytes to transmit. +

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

+A 32-bit unsigned value. +

uint64_t: 0-(2^64)-1

+A 64-bit unsigned value. +

unsigned

+A whole number >= 0. +

updateMask

+A 64 bit mask indicating which GPIO may be written to by the user. +

If GPIO#n may be written then bit (1<<n) is set. +

user_gpio

+0-31, a Broadcom numbered GPIO. +

See gpio. +

*userdata

+A pointer to arbitrary user data. This may be used to identify the instance. +

You must ensure that the pointer is in scope at the time it is processed. If +it is a pointer to a global this is automatic. Do not pass the address of a +local variable. If you want to pass a transient object then use the +following technique. +

In the calling function: +

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: +

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

+Denoting no parameter is required +

wave_id

+A number identifying a waveform created by gpioWaveCreate. +

wave_mode

+The mode determines if the waveform is sent once or cycles +repeatedly. The SYNC variants wait for the current waveform +to reach the end of a cycle or finish before starting the new +waveform. +

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

+A 16-bit word value. +

Socket Command Codes


#define PI_CMD_MODES  0
#define PI_CMD_MODEG  1
#define PI_CMD_PUD    2
#define PI_CMD_READ   3
#define PI_CMD_WRITE  4
#define PI_CMD_PWM    5
#define PI_CMD_PRS    6
#define PI_CMD_PFS    7
#define PI_CMD_SERVO  8
#define PI_CMD_WDOG   9
#define PI_CMD_BR1   10
#define PI_CMD_BR2   11
#define PI_CMD_BC1   12
#define PI_CMD_BC2   13
#define PI_CMD_BS1   14
#define PI_CMD_BS2   15
#define PI_CMD_TICK  16
#define PI_CMD_HWVER 17
#define PI_CMD_NO    18
#define PI_CMD_NB    19
#define PI_CMD_NP    20
#define PI_CMD_NC    21
#define PI_CMD_PRG   22
#define PI_CMD_PFG   23
#define PI_CMD_PRRG  24
#define PI_CMD_HELP  25
#define PI_CMD_PIGPV 26
#define PI_CMD_WVCLR 27
#define PI_CMD_WVAG  28
#define PI_CMD_WVAS  29
#define PI_CMD_WVGO  30
#define PI_CMD_WVGOR 31
#define PI_CMD_WVBSY 32
#define PI_CMD_WVHLT 33
#define PI_CMD_WVSM  34
#define PI_CMD_WVSP  35
#define PI_CMD_WVSC  36
#define PI_CMD_TRIG  37
#define PI_CMD_PROC  38
#define PI_CMD_PROCD 39
#define PI_CMD_PROCR 40
#define PI_CMD_PROCS 41
#define PI_CMD_SLRO  42
#define PI_CMD_SLR   43
#define PI_CMD_SLRC  44
#define PI_CMD_PROCP 45
#define PI_CMD_MICS  46
#define PI_CMD_MILS  47
#define PI_CMD_PARSE 48
#define PI_CMD_WVCRE 49
#define PI_CMD_WVDEL 50
#define PI_CMD_WVTX  51
#define PI_CMD_WVTXR 52
#define PI_CMD_WVNEW 53

#define PI_CMD_I2CO  54
#define PI_CMD_I2CC  55
#define PI_CMD_I2CRD 56
#define PI_CMD_I2CWD 57
#define PI_CMD_I2CWQ 58
#define PI_CMD_I2CRS 59
#define PI_CMD_I2CWS 60
#define PI_CMD_I2CRB 61
#define PI_CMD_I2CWB 62
#define PI_CMD_I2CRW 63
#define PI_CMD_I2CWW 64
#define PI_CMD_I2CRK 65
#define PI_CMD_I2CWK 66
#define PI_CMD_I2CRI 67
#define PI_CMD_I2CWI 68
#define PI_CMD_I2CPC 69
#define PI_CMD_I2CPK 70

#define PI_CMD_SPIO  71
#define PI_CMD_SPIC  72
#define PI_CMD_SPIR  73
#define PI_CMD_SPIW  74
#define PI_CMD_SPIX  75

#define PI_CMD_SERO  76
#define PI_CMD_SERC  77
#define PI_CMD_SERRB 78
#define PI_CMD_SERWB 79
#define PI_CMD_SERR  80
#define PI_CMD_SERW  81
#define PI_CMD_SERDA 82

#define PI_CMD_GDC   83
#define PI_CMD_GPW   84

#define PI_CMD_HC    85
#define PI_CMD_HP    86

#define PI_CMD_CF1   87
#define PI_CMD_CF2   88

#define PI_CMD_BI2CC 89
#define PI_CMD_BI2CO 90
#define PI_CMD_BI2CZ 91

#define PI_CMD_I2CZ  92

#define PI_CMD_WVCHA 93

#define PI_CMD_SLRI  94

#define PI_CMD_CGI   95
#define PI_CMD_CSI   96

#define PI_CMD_FG    97
#define PI_CMD_FN    98

#define PI_CMD_NOIB  99

#define PI_CMD_WVTXM 100
#define PI_CMD_WVTAT 101

#define PI_CMD_PADS  102
#define PI_CMD_PADG  103

#define PI_CMD_FO    104
#define PI_CMD_FC    105
#define PI_CMD_FR    106
#define PI_CMD_FW    107
#define PI_CMD_FS    108
#define PI_CMD_FL    109

#define PI_CMD_SHELL 110

#define PI_CMD_BSPIC 111
#define PI_CMD_BSPIO 112
#define PI_CMD_BSPIX 113

#define PI_CMD_BSCX  114

#define PI_CMD_EVM   115
#define PI_CMD_EVT   116

#define PI_CMD_PROCU 117
#define PI_CMD_WVCAP 118

Error Codes


#define PI_INIT_FAILED       -1 // gpioInitialise failed
#define PI_BAD_USER_GPIO     -2 // GPIO not 0-31
#define PI_BAD_GPIO          -3 // GPIO not 0-53
#define PI_BAD_MODE          -4 // mode not 0-7
#define PI_BAD_LEVEL         -5 // level not 0-1
#define PI_BAD_PUD           -6 // pud not 0-2
#define PI_BAD_PULSEWIDTH    -7 // pulsewidth not 0 or 500-2500
#define PI_BAD_DUTYCYCLE     -8 // dutycycle outside set range
#define PI_BAD_TIMER         -9 // timer not 0-9
#define PI_BAD_MS           -10 // ms not 10-60000
#define PI_BAD_TIMETYPE     -11 // timetype not 0-1
#define PI_BAD_SECONDS      -12 // seconds < 0
#define PI_BAD_MICROS       -13 // micros not 0-999999
#define PI_TIMER_FAILED     -14 // gpioSetTimerFunc failed
#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
#define PI_NO_ALERT_FUNC    -16 // DEPRECATED
#define PI_BAD_CLK_PERIPH   -17 // clock peripheral not 0-1
#define PI_BAD_CLK_SOURCE   -18 // DEPRECATED
#define PI_BAD_CLK_MICROS   -19 // clock micros not 1, 2, 4, 5, 8, or 10
#define PI_BAD_BUF_MILLIS   -20 // buf millis not 100-10000
#define PI_BAD_DUTYRANGE    -21 // dutycycle range not 25-40000
#define PI_BAD_DUTY_RANGE   -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
#define PI_BAD_SIGNUM       -22 // signum not 0-63
#define PI_BAD_PATHNAME     -23 // can't open pathname
#define PI_NO_HANDLE        -24 // no handle available
#define PI_BAD_HANDLE       -25 // unknown handle
#define PI_BAD_IF_FLAGS     -26 // ifFlags > 4
#define PI_BAD_CHANNEL      -27 // DMA channel not 0-15
#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15
#define PI_BAD_SOCKET_PORT  -28 // socket port not 1024-32000
#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15
#define PI_NOT_INITIALISED  -31 // function called before gpioInitialise
#define PI_INITIALISED      -32 // function called after gpioInitialise
#define PI_BAD_WAVE_MODE    -33 // waveform mode not 0-3
#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
#define PI_BAD_WAVE_BAUD    -35 // baud rate not 50-250K(RX)/50-1M(TX)
#define PI_TOO_MANY_PULSES  -36 // waveform has too many pulses
#define PI_TOO_MANY_CHARS   -37 // waveform has too many chars
#define PI_NOT_SERIAL_GPIO  -38 // no bit bang serial read on GPIO
#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
#define PI_BAD_SERIAL_BUF   -40 // bad (null) serial buf parameter
#define PI_NOT_PERMITTED    -41 // GPIO operation not permitted
#define PI_SOME_PERMITTED   -42 // one or more GPIO not permitted
#define PI_BAD_WVSC_COMMND  -43 // bad WVSC subcommand
#define PI_BAD_WVSM_COMMND  -44 // bad WVSM subcommand
#define PI_BAD_WVSP_COMMND  -45 // bad WVSP subcommand
#define PI_BAD_PULSELEN     -46 // trigger pulse length not 1-100
#define PI_BAD_SCRIPT       -47 // invalid script
#define PI_BAD_SCRIPT_ID    -48 // unknown script id
#define PI_BAD_SER_OFFSET   -49 // add serial data offset > 30 minutes
#define PI_GPIO_IN_USE      -50 // GPIO already in use
#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
#define PI_BAD_PARAM_NUM    -52 // script parameter id not 0-9
#define PI_DUP_TAG          -53 // script has duplicate tag
#define PI_TOO_MANY_TAGS    -54 // script has too many tags
#define PI_BAD_SCRIPT_CMD   -55 // illegal script command
#define PI_BAD_VAR_NUM      -56 // script variable id not 0-149
#define PI_NO_SCRIPT_ROOM   -57 // no more room for scripts
#define PI_NO_MEMORY        -58 // can't allocate temporary memory
#define PI_SOCK_READ_FAILED -59 // socket read failed
#define PI_SOCK_WRIT_FAILED -60 // socket write failed
#define PI_TOO_MANY_PARAM   -61 // too many script parameters (> 10)
#define PI_NOT_HALTED       -62 // DEPRECATED
#define PI_SCRIPT_NOT_READY -62 // script initialising
#define PI_BAD_TAG          -63 // script has unresolved tag
#define PI_BAD_MICS_DELAY   -64 // bad MICS delay (too large)
#define PI_BAD_MILS_DELAY   -65 // bad MILS delay (too large)
#define PI_BAD_WAVE_ID      -66 // non existent wave id
#define PI_TOO_MANY_CBS     -67 // No more CBs for waveform
#define PI_TOO_MANY_OOL     -68 // No more OOL for waveform
#define PI_EMPTY_WAVEFORM   -69 // attempt to create an empty waveform
#define PI_NO_WAVEFORM_ID   -70 // no more waveforms
#define PI_I2C_OPEN_FAILED  -71 // can't open I2C device
#define PI_SER_OPEN_FAILED  -72 // can't open serial device
#define PI_SPI_OPEN_FAILED  -73 // can't open SPI device
#define PI_BAD_I2C_BUS      -74 // bad I2C bus
#define PI_BAD_I2C_ADDR     -75 // bad I2C address
#define PI_BAD_SPI_CHANNEL  -76 // bad SPI channel
#define PI_BAD_FLAGS        -77 // bad i2c/spi/ser open flags
#define PI_BAD_SPI_SPEED    -78 // bad SPI speed
#define PI_BAD_SER_DEVICE   -79 // bad serial device name
#define PI_BAD_SER_SPEED    -80 // bad serial baud rate
#define PI_BAD_PARAM        -81 // bad i2c/spi/ser parameter
#define PI_I2C_WRITE_FAILED -82 // i2c write failed
#define PI_I2C_READ_FAILED  -83 // i2c read failed
#define PI_BAD_SPI_COUNT    -84 // bad SPI count
#define PI_SER_WRITE_FAILED -85 // ser write failed
#define PI_SER_READ_FAILED  -86 // ser read failed
#define PI_SER_READ_NO_DATA -87 // ser read no data available
#define PI_UNKNOWN_COMMAND  -88 // unknown command
#define PI_SPI_XFER_FAILED  -89 // spi xfer/read/write failed
#define PI_BAD_POINTER      -90 // bad (NULL) pointer
#define PI_NO_AUX_SPI       -91 // no auxiliary SPI on Pi A or B
#define PI_NOT_PWM_GPIO     -92 // GPIO is not in use for PWM
#define PI_NOT_SERVO_GPIO   -93 // GPIO is not in use for servo pulses
#define PI_NOT_HCLK_GPIO    -94 // GPIO has no hardware clock
#define PI_NOT_HPWM_GPIO    -95 // GPIO has no hardware PWM
#define PI_BAD_HPWM_FREQ    -96 // invalid hardware PWM frequency
#define PI_BAD_HPWM_DUTY    -97 // hardware PWM dutycycle not 0-1M
#define PI_BAD_HCLK_FREQ    -98 // invalid hardware clock frequency
#define PI_BAD_HCLK_PASS    -99 // need password to use hardware clock 1
#define PI_HPWM_ILLEGAL    -100 // illegal, PWM in use for main clock
#define PI_BAD_DATABITS    -101 // serial data bits not 1-32
#define PI_BAD_STOPBITS    -102 // serial (half) stop bits not 2-8
#define PI_MSG_TOOBIG      -103 // socket/pipe message too big
#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode
#define PI_TOO_MANY_SEGS   -105 // too many I2C transaction segments
#define PI_BAD_I2C_SEG     -106 // an I2C transaction segment failed
#define PI_BAD_SMBUS_CMD   -107 // SMBus command not supported by driver
#define PI_NOT_I2C_GPIO    -108 // no bit bang I2C in progress on GPIO
#define PI_BAD_I2C_WLEN    -109 // bad I2C write length
#define PI_BAD_I2C_RLEN    -110 // bad I2C read length
#define PI_BAD_I2C_CMD     -111 // bad I2C command
#define PI_BAD_I2C_BAUD    -112 // bad I2C baud rate, not 50-500k
#define PI_CHAIN_LOOP_CNT  -113 // bad chain loop count
#define PI_BAD_CHAIN_LOOP  -114 // empty chain loop
#define PI_CHAIN_COUNTER   -115 // too many chain counters
#define PI_BAD_CHAIN_CMD   -116 // bad chain command
#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
#define PI_CHAIN_NESTING   -118 // chain counters nested too deeply
#define PI_CHAIN_TOO_BIG   -119 // chain is too long
#define PI_DEPRECATED      -120 // deprecated function removed
#define PI_BAD_SER_INVERT  -121 // bit bang serial invert not 0 or 1
#define PI_BAD_EDGE        -122 // bad ISR edge value, not 0-2
#define PI_BAD_ISR_INIT    -123 // bad ISR initialisation
#define PI_BAD_FOREVER     -124 // loop forever must be last command
#define PI_BAD_FILTER      -125 // bad filter parameter
#define PI_BAD_PAD         -126 // bad pad number
#define PI_BAD_STRENGTH    -127 // bad pad drive strength
#define PI_FIL_OPEN_FAILED -128 // file open failed
#define PI_BAD_FILE_MODE   -129 // bad file mode
#define PI_BAD_FILE_FLAG   -130 // bad file flag
#define PI_BAD_FILE_READ   -131 // bad file read
#define PI_BAD_FILE_WRITE  -132 // bad file write
#define PI_FILE_NOT_ROPEN  -133 // file not open for read
#define PI_FILE_NOT_WOPEN  -134 // file not open for write
#define PI_BAD_FILE_SEEK   -135 // bad file seek
#define PI_NO_FILE_MATCH   -136 // no files match pattern
#define PI_NO_FILE_ACCESS  -137 // no permission to access file
#define PI_FILE_IS_A_DIR   -138 // file is a directory
#define PI_BAD_SHELL_STATUS -139 // bad shell return status
#define PI_BAD_SCRIPT_NAME -140 // bad script name
#define PI_BAD_SPI_BAUD    -141 // bad SPI baud rate, not 50-500k
#define PI_NOT_SPI_GPIO    -142 // no bit bang SPI in progress on GPIO
#define PI_BAD_EVENT_ID    -143 // bad event id
#define PI_CMD_INTERRUPTED -144 // Used by Python
#define PI_NOT_ON_BCM2711  -145 // not available on BCM2711
#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711

#define PI_PIGIF_ERR_0    -2000
#define PI_PIGIF_ERR_99   -2099

#define PI_CUSTOM_ERR_0   -3000
#define PI_CUSTOM_ERR_999 -3999

Defaults


#define PI_DEFAULT_BUFFER_MILLIS           120
#define PI_DEFAULT_CLK_MICROS              5
#define PI_DEFAULT_CLK_PERIPHERAL          PI_CLOCK_PCM
#define PI_DEFAULT_IF_FLAGS                0
#define PI_DEFAULT_FOREGROUND              0
#define PI_DEFAULT_DMA_CHANNEL             14
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL     14
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL   6
#define PI_DEFAULT_DMA_PRIMARY_CH_2711     7
#define PI_DEFAULT_DMA_SECONDARY_CH_2711   6
#define PI_DEFAULT_DMA_NOT_SET             15
#define PI_DEFAULT_SOCKET_PORT             8888
#define PI_DEFAULT_SOCKET_PORT_STR         "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR         "localhost"
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN     0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_B1          0x03E7CF93
#define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_ZERO        0x0080000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI2B        0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI3B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI4B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_COMPUTE     0x00FFFFFFFFFFFFLL
#define PI_DEFAULT_MEM_ALLOC_MODE          PI_MEM_ALLOC_AUTO

#define PI_DEFAULT_CFG_INTERNALS           0

\ No newline at end of file diff --git a/DOC/tmp/body/download.body b/DOC/tmp/body/download.body new file mode 100644 index 0000000..cdabc9a --- /dev/null +++ b/DOC/tmp/body/download.body @@ -0,0 +1,57 @@ + +If the pigpio daemon is running it should be killed (sudo killall +pigpiod) before make install and restarted afterwards (sudo +pigpiod).
+
+The initial part of the make, the +compilation of pigpio.c, takes 100 seconds on early model +Pis.  Be patient.  The overall install takes just over 3 +minutes.
+

Download and install (V75)

+wget https://github.com/joan2937/pigpio/archive/v75.zip
+unzip v75.zip
+cd pigpio-75
+make
+sudo make install

+
+If the Python part of the install fails it may be because you need +the setup tools.
+
+sudo apt install python-setuptools +python3-setuptools

+
+

To check the library

+These tests make extensive use of GPIO 25 (pin 22).  Make sure +nothing, or only a LED, is connected to the GPIO before running the +tests.  Most tests are statistical in nature and so may on +occasion fail.  Repeated failures on the same test or many +failures in a group of tests indicate a problem.
+
+sudo ./x_pigpio # check C I/F
+
+sudo pigpiod    # start daemon
+
+./x_pigpiod_if2 # check C      I/F to +daemon
+./x_pigpio.py   # check Python I/F to daemon
+./x_pigs        # check +pigs   I/F to daemon
+./x_pipe        # check +pipe   I/F to daemon
+
+
+

To compile, link, and run a C program

+gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
+sudo ./foobar


+

To start the pigpio daemon

+sudo pigpiod
+

To stop the pigpio daemon

+sudo killall pigpiod

+

github

+git clone https://github.com/joan2937/pigpio
+

Raspbian (raspberrypi.org image)

+

This may not be the most recent version.  You can check the +version with the command pigpiod -v.

+sudo apt-get update
+sudo apt-get install pigpio python-pigpio python3-pigpio

+
diff --git a/DOC/tmp/body/ex_LDR.body b/DOC/tmp/body/ex_LDR.body new file mode 100644 index 0000000..1b1911a --- /dev/null +++ b/DOC/tmp/body/ex_LDR.body @@ -0,0 +1,141 @@ + +

The following code shows a method of reading analogue sensors on +the digital input only Pi.  A Light Dependent Resistor (LDR) +varies its resistance according to the incident light +intensisty.

+

SETUP

+fritzing diagramThe LDR +used is a Cadmium Sulphide device with a 1MOhm dark resistance and +2-4KOhm at 100 lux.  The capacitor is a 104 +ceramic.
+
+One end of the capacitor is connected to Pi ground.
+
+One end of the LDR is connected to Pi 3V3.
+
+The other ends of the capacitor and LDR are connected to a spare +gpio.

+

Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18 +(P1-12) is used for the gpio.

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/* +-----------------------------------------------------------------------
+ +
+   3V3 ----- Light Dependent Resistor --+-- Capacitor +----- Ground
+                                        +|
+                                        ++-- gpio
+
+
+  cc -o LDR LDR.c -lpigpio -lpthread -lrt
+  sudo ./LDR
+
+*/
+
+#define LDR 18
+
+/* forward declaration */
+
+void alert(int pin, int level, uint32_t tick);
+
+int main (int argc, char *argv[])
+{
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetAlertFunc(LDR, alert); /* call alert when LDR +changes state */
+    
+   while (1)
+   {
+      gpioSetMode(LDR, PI_OUTPUT); /* +drain capacitor */
+
+      gpioWrite(LDR, PI_OFF);
+
+      gpioDelay(200); /* 50 micros is +enough, 200 is overkill */
+
+      gpioSetMode(LDR, PI_INPUT); /* start +capacitor recharge */
+
+      gpioDelay(10000); /* nominal 100 +readings per second */
+   }
+
+   gpioTerminate();
+}
+
+void alert(int pin, int level, uint32_t tick)
+{
+   static uint32_t inited = 0;
+   static uint32_t lastTick, firstTick;
+
+   uint32_t diffTick;
+
+   if (inited)
+   {
+      diffTick = tick - lastTick;
+      lastTick = tick;
+
+      if (level == 1) printf("%u %d\ ", +tick-firstTick, diffTick);
+   }
+   else
+   {
+      inited = 1;
+      firstTick = tick;
+      lastTick = firstTick;
+   }
+}
+

BUILD

+cc -o LDR LDR.c -lpigpio -lrt -lpthread
+

RUN

+sudo ./LDR >LDR.dat &
+
+While the program is running you can capture the waveform using the +notification feature built in to pigpio.  Issue the following +commands on the Pi.
+
+pigs no
+pig2vcd  </dev/pigpio0 >LDR.vcd &
+pigs nb 0 0x40000 # set bit for gpio 18
+

Change the light falling on the LDR for a few seconds (e.g. +shine a torch on it or shade it with your hands).

+pigs nc 0
+

The file LDR.vcd will contain the captured waveform, which can +be viewed using GTKWave.

+

Overview

+LDR waveform 1
+

Reading circa every 10ms

+LDR waveform 2
+

One reading, circa 400us

+LDR waveform 3
+

The file LDR.dat will contain pairs of timestamps and recharge +time (in us).  The following  script will convert the +timestamps into seconds.

+

awk '{print $1/1000000, $2}' LDR.dat +>LDR-secs.dat

+

Gnuplot is a useful tool to graph data.

+plot [14:24] 'LDR-secs.dat' with lines title 'LDR' +

Gnuplot readings 14-24 seconds

+

gnuplot 1

+plot [18:21] 'LDR-secs.dat' with lines title 'LDR'
+
+Gnuplot readings 18-21 seconds +

Gnuplot 2

diff --git a/DOC/tmp/body/ex_ir_remote.body b/DOC/tmp/body/ex_ir_remote.body new file mode 100644 index 0000000..cebc97f --- /dev/null +++ b/DOC/tmp/body/ex_ir_remote.body @@ -0,0 +1,244 @@ + +

The following code shows one way to read an infrared remote +control device (the sort used in TVs and stereo systems).

+

SETUP

+fritzing diagramThe device used +is a SFH5110 (IR Receiver for remote control, +carrier 38 kHz).
+
Pin 1 (left from front) may be connected to any spare +gpio.  Here it's connected via a 4K7 current limiting +resistor.  This isn't really needed as the device has an +internal 23K resistor in-line.  It does no harm though.
+
+Pin 2 should be connected to a Pi ground pin.
+
+Pin 3 should be connected to a Pi 5V pin.
+

Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground +(P1-14), and pin 3 to 5V (P1-2).

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+#define IR_PIN 7
+
+#define OUTSIDE_CODE 0
+#define INSIDE_CODE  1
+
+#define MIN_MESSAGE_GAP 3000
+#define MAX_MESSAGE_END 3000
+
+#define MAX_TRANSITIONS 500
+
+/*
+   using the FNV-1a +hash                
+ +   from +http://isthe.com/chongo/tech/comp/fnv/#FNV-param
+*/
+
+#define FNV_PRIME_32 16777619
+#define FNV_BASIS_32 2166136261U
+
+static volatile uint32_t ir_hash = 0;
+
+typedef struct
+{
+   int state;
+   int count;
+   int level;
+   uint16_t micros[MAX_TRANSITIONS];
+} decode_t;
+
+/* forward declarations */
+
+void     alert(int gpio, int level, uint32_t +tick);
+uint32_t getHash(decode_t * decode);
+void     updateState(decode_t * decode, int +level, uint32_t micros);
+
+int main(int argc, char * argv[])
+{
+   if (gpioInitialise()<0)
+   {
+      return 1 ;
+   }
+
+   /* IR pin as input */
+
+   gpioSetMode(IR_PIN, PI_INPUT);
+
+   /* 5ms max gap after last pulse */
+
+   gpioSetWatchdog(IR_PIN, 5);
+
+   /* monitor IR level changes */
+
+   gpioSetAlertFunc(IR_PIN, alert);
+
+   while (1)
+   {
+      if (ir_hash)
+      {
+         /* non-zero means +new decode */
+         printf("ir code is +%u\ ", ir_hash);
+         ir_hash = 0;
+      }
+
+      gpioDelay(100000); /* check remote +10 times per second */
+   }
+
+   gpioTerminate();
+}
+
+void alert(int gpio, int level, uint32_t tick)
+{
+   static int inited = 0;
+
+   static decode_t activeHigh, activeLow;
+
+   static uint32_t lastTick;
+
+   uint32_t diffTick;
+
+   if (!inited)
+   {
+      inited = 1;
+
+      activeHigh.state = OUTSIDE_CODE; +activeHigh.level = PI_LOW;
+      activeLow.state  = +OUTSIDE_CODE; activeLow.level  = PI_HIGH;
+
+      lastTick = tick;
+      return;
+   }
+
+   diffTick = tick - lastTick;
+
+   if (level != PI_TIMEOUT) lastTick = tick;
+
+   updateState(&activeHigh, level, diffTick);
+   updateState(&activeLow, level, diffTick);
+}
+
+void updateState(decode_t * decode, int level, uint32_t micros)
+{
+   /*
+      We are dealing with active high as +well as active low
+      remotes.  Abstract the common +functionality.
+   */
+
+   if (decode->state == OUTSIDE_CODE)
+   {
+      if (level == decode->level)
+      {
+         if (micros > +MIN_MESSAGE_GAP)
+         {
+            +decode->state = INSIDE_CODE;
+            +decode->count = 0;
+         }
+      }
+   }
+   else
+   {
+      if (micros > MAX_MESSAGE_END)
+      {
+         /* end of message +*/
+
+         /* ignore if last +code not consumed */
+
+         if (!ir_hash) +ir_hash = getHash(decode);
+
+         decode->state = +OUTSIDE_CODE;
+      }
+      else
+      {
+         if +(decode->count < (MAX_TRANSITIONS-1))
+         {
+            +if (level != PI_TIMEOUT)
+               +decode->micros[decode->count++] = micros;
+         }
+      }
+   }
+}
+
+int compare(unsigned int oldval, unsigned int newval)
+{
+   if      (newval < (oldval +* 0.75)) {return 1;}
+   else if (oldval < (newval * 0.75)) {return 2;}
+   +else                               +{return 4;}
+}
+
+uint32_t getHash(decode_t * decode)
+{
+   /* use FNV-1a */
+
+   uint32_t hash;
+   int i, value;
+
+   if (decode->count < 6) {return 0;}
+
+   hash = FNV_BASIS_32;
+
+   for (i=0; i<(decode->count-2); i++)
+   {
+      value = +compare(decode->micros[i], decode->micros[i+2]);
+
+      hash = hash ^ value;
+      hash = (hash * FNV_PRIME_32);
+   }
+
+   return hash;
+}
+

BUILD

+cc -o ir_remote ir_remote.c -lpigpio -lrt +-lpthread
+

RUN

+sudo ./ir_remote
+

A hash code is formed from the level transitions detected during +a remote key press.  This is likely to be unique over multiple +remotes and keys.

+

While the program is running you can capture the waveform using +the notification feature built in to pigpio.  Issue the +following commands on the Pi.

+pigs no
+pig2vcd  </dev/pigpio0 >ir.vcd &
+pigs nb 0 0x80 # set bits for gpios 7 (0x80)
+

Press a few different remotes and keys.  Then enter

+pigs nc 0
+

The file ir.vcd will contain the captured waveform, which can be +viewed using GTKWave.

+

Overview

+ir remote waveform 1
+

Remote A typical waveform

+ir remote waveform 2
+

Remote B typical waveform

++"ir diff --git a/DOC/tmp/body/ex_motor_shield.body b/DOC/tmp/body/ex_motor_shield.body new file mode 100644 index 0000000..fbadb3a --- /dev/null +++ b/DOC/tmp/body/ex_motor_shield.body @@ -0,0 +1,245 @@ + +The following example demonstrates the use of an Arduino shield +from the Rasperry Pi.
+
+The shield used is a clone of the Adafruit motor shield.  See +shieldlist.org +for details.
+
+For the demonstration DC motors 3 and 4 are being driven forwards +and backwards with changing speeds (speeds are controlled via +PWM).
+
+Seven connections are made between the Pi and the shield.  +Four to latch the motor states (latch, enable, data, clock); Two to +control motor speed (PWM 3 and 4); and ground.
+
+The code used was ported from the Adafruit Arduino code and +converted to use the pigpio library.  Only the DC motor code +was ported.
+
+A video of the shield in use is available at youtube.com
+
+#include <stdio.h>

+
+#include <pigpio.h>
+
+/*
+   This code may be used to drive the Adafruit (or +clones) Motor Shield.
+
+   The code as written only supports DC motors.
+
+   http://shieldlist.org/adafruit/motor
+
+   The shield pinouts are
+
+   D12 MOTORLATCH
+   D11 PMW motor 1
+   D10 Servo 1
+   D9  Servo 2
+   D8  MOTORDATA
+
+   D7  MOTORENABLE
+   D6  PWM motor 4
+   D5  PWM motor 3
+   D4  MOTORCLK
+   D3  PWM motor 2
+
+   The motor states (forward, backward, brake, release) +are encoded using the
+   MOTOR_ latch pins.  This saves four gpios.
+*/
+
+typedef unsigned char uint8_t;
+
+#define BIT(bit) (1 << (bit))
+
+/* assign gpios to drive the shield pins */
+
+/*      +Shield      Pi */
+
+#define MOTORLATCH  14
+#define MOTORCLK    24
+#define MOTORENABLE 25
+#define MOTORDATA   15
+
+#define MOTOR_3_PWM  7
+#define MOTOR_4_PWM  8
+
+/*
+   The only other connection needed between the Pi and +the shield
+   is ground to ground. I used Pi P1-6 to shield gnd +(next to D13).
+*/
+
+/* assignment of motor states to latch */
+
+#define MOTOR1_A 2
+#define MOTOR1_B 3
+#define MOTOR2_A 1
+#define MOTOR2_B 4
+#define MOTOR4_A 0
+#define MOTOR4_B 6
+#define MOTOR3_A 5
+#define MOTOR3_B 7
+
+#define FORWARD  1
+#define BACKWARD 2
+#define BRAKE    3
+#define RELEASE  4
+
+static uint8_t latch_state;
+
+void latch_tx(void)
+{
+   unsigned char i;
+
+   gpioWrite(MOTORLATCH, PI_LOW);
+
+   gpioWrite(MOTORDATA, PI_LOW);
+
+   for (i=0; i<8; i++)
+   {
+      gpioDelay(10);  // 10 micros +delay
+
+      gpioWrite(MOTORCLK, PI_LOW);
+
+      if (latch_state & BIT(7-i)) +gpioWrite(MOTORDATA, PI_HIGH);
+      +else                        +gpioWrite(MOTORDATA, PI_LOW);
+
+      gpioDelay(10);  // 10 micros +delay
+
+      gpioWrite(MOTORCLK, PI_HIGH);
+   }
+
+   gpioWrite(MOTORLATCH, PI_HIGH);
+}
+
+void init(void)
+{
+   latch_state = 0;
+
+   latch_tx();
+
+   gpioWrite(MOTORENABLE, PI_LOW);
+}
+
+void DCMotorInit(uint8_t num)
+{
+   switch (num)
+   {
+      case 1: latch_state &= +~BIT(MOTOR1_A) & ~BIT(MOTOR1_B); break;
+      case 2: latch_state &= +~BIT(MOTOR2_A) & ~BIT(MOTOR2_B); break;
+      case 3: latch_state &= +~BIT(MOTOR3_A) & ~BIT(MOTOR3_B); break;
+      case 4: latch_state &= +~BIT(MOTOR4_A) & ~BIT(MOTOR4_B); break;
+      default: return;
+   }
+
+   latch_tx();
+
+   printf("Latch=%08X\ ", latch_state);
+}
+
+void DCMotorRun(uint8_t motornum, uint8_t cmd)
+{
+   uint8_t a, b;
+
+   switch (motornum)
+   {
+      case 1: a = MOTOR1_A; b = MOTOR1_B; +break;
+      case 2: a = MOTOR2_A; b = MOTOR2_B; +break;
+      case 3: a = MOTOR3_A; b = MOTOR3_B; +break;
+      case 4: a = MOTOR4_A; b = MOTOR4_B; +break;
+      default: return;
+   }

+   switch (cmd)
+   {
+      case FORWARD:  latch_state +|=  BIT(a); latch_state &= ~BIT(b); break;
+      case BACKWARD: latch_state &= +~BIT(a); latch_state |=  BIT(b); break;
+      case RELEASE:  latch_state +&= ~BIT(a); latch_state &= ~BIT(b); break;
+      default: return;
+   }
+
+   latch_tx();
+
+   printf("Latch=%08X\ ", latch_state);
+}
+
+int main (int argc, char *argv[])
+{
+   int i;
+
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(MOTORLATCH,  PI_OUTPUT);
+   gpioSetMode(MOTORENABLE, PI_OUTPUT);
+   gpioSetMode(MOTORDATA,   PI_OUTPUT);
+   gpioSetMode(MOTORCLK,    +PI_OUTPUT);
+
+   gpioSetMode(MOTOR_3_PWM, PI_OUTPUT);
+   gpioSetMode(MOTOR_4_PWM, PI_OUTPUT);
+
+   gpioPWM(MOTOR_3_PWM, 0);
+   gpioPWM(MOTOR_4_PWM, 0);
+
+   init();
+
+   for (i=60; i<160; i+=20)
+   {
+      gpioPWM(MOTOR_3_PWM, i);
+      gpioPWM(MOTOR_4_PWM, 220-i);
+
+      DCMotorRun(3, FORWARD);
+      DCMotorRun(4, BACKWARD);
+
+      sleep(2);
+
+      DCMotorRun(3, RELEASE);
+      DCMotorRun(4, RELEASE);
+
+      sleep(2);
+
+      gpioPWM(MOTOR_4_PWM, i);
+      gpioPWM(MOTOR_3_PWM, 220-i);
+
+      DCMotorRun(3, BACKWARD);
+      DCMotorRun(4, FORWARD);
+
+      sleep(2);
+
+      DCMotorRun(3, RELEASE);
+      DCMotorRun(4, RELEASE);
+
+      sleep(2);
+   }
+
+   gpioPWM(MOTOR_4_PWM, 0);
+   gpioPWM(MOTOR_3_PWM, 0);
+
+   DCMotorRun(3, RELEASE);
+   DCMotorRun(4, RELEASE);
+
+   gpioTerminate();
+}
diff --git a/DOC/tmp/body/ex_rotary_encoder.body b/DOC/tmp/body/ex_rotary_encoder.body new file mode 100644 index 0000000..f399e29 --- /dev/null +++ b/DOC/tmp/body/ex_rotary_encoder.body @@ -0,0 +1,176 @@ + +

The following code shows one way to read an incremental +mechanical rotary enoder (the sort used for volume control in audio +systems).  These rotary encoders have two switches A and B +which return a quadrature output, i.e. they are 90 degrees out of +phase.

+

SETUP

+fritzing diagramThe common +(centre) terminal should be connected to a Pi ground. +

The A and B terminals may be connected to any spare gpios.

+

Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7 +(P1-26).

+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/*
+   Rotary encoder connections:
+
+   Encoder A      - gpio +18   (pin P1-12)
+   Encoder B      - gpio +7    (pin P1-26)
+   Encoder Common - Pi ground (pin P1-20)
+*/
+
+#define ENCODER_A 18
+#define ENCODER_B  7
+
+static volatile int encoderPos;
+
+/* forward declaration */
+
+void encoderPulse(int gpio, int lev, uint32_t tick);
+
+int main(int argc, char * argv[])
+{
+   int pos=0;
+
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(ENCODER_A, PI_INPUT);
+   gpioSetMode(ENCODER_B, PI_INPUT);
+
+   /* pull up is needed as encoder common is grounded +*/
+
+   gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);
+   gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);
+
+   encoderPos = pos;
+
+   /* monitor encoder level changes */
+
+   gpioSetAlertFunc(ENCODER_A, encoderPulse);
+   gpioSetAlertFunc(ENCODER_B, encoderPulse);
+
+   while (1)
+   {
+      if (pos != encoderPos)
+      {
+         pos = +encoderPos;
+         printf("pos=%d\ ", +pos);
+      }
+      gpioDelay(20000); /* check pos 50 +times per second */
+   }
+
+   gpioTerminate();
+}
+
+void encoderPulse(int gpio, int level, uint32_t tick)
+{
+   /*
+
+             ++---------+         ++---------+      0
+             +|         +|         +|         |
+   A         +|         +|         +|         |
+             +|         +|         +|         |
+   ++---------+         ++---------+         +----- +1
+
+       ++---------+         ++---------+            +0
+       +|         +|         +|         |
+   B   +|         +|         +|         |
+       +|         +|         +|         |
+   ----+         ++---------+         ++---------+  1
+
+   */
+
+   static int levA=0, levB=0, lastGpio = -1;
+
+   if (gpio == ENCODER_A) levA = level; else levB = +level;
+
+   if (gpio != lastGpio) /* debounce */
+   {
+      lastGpio = gpio;
+
+      if ((gpio == ENCODER_A) && +(level == 0))
+      {
+         if (!levB) +++encoderPos;
+      }
+      else if ((gpio == ENCODER_B) +&& (level == 1))
+      {
+         if (levA) +--encoderPos;
+      }
+   }
+}
+

BUILD

+cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt +-lpthread
+

RUN

+sudo ./rotary_encoder
+

While the program is running you can capture the waveform using +the notification feature built in to pigpio.  Issue the +following commands on the Pi.

+pigs no
+pig2vcd  </dev/pigpio0 >re.vcd &
+pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18 +(0x40000)
+

Twiddle the rotary encoder forwards and backwards for a few +seconds.  Then enter

+pigs nc 0
+

The file re.vcd will contain the captured waveform, which can be +viewed using GTKWave.

+
+Overview
+
++"rotary
+
+Detail of switch bounce.  Contact A bounces for circa 700 us +before completing the level transition
+
++"rotary
diff --git a/DOC/tmp/body/ex_sonar_ranger.body b/DOC/tmp/body/ex_sonar_ranger.body new file mode 100644 index 0000000..8b3de67 --- /dev/null +++ b/DOC/tmp/body/ex_sonar_ranger.body @@ -0,0 +1,155 @@ + +

The following code shows a method of reading a class of sonar +rangers.  These rangers requires a trigger pulse.  +Shortly after receiving a trigger they transmit a noise pulse and +set the echo line high.  When the echo is received the echo +line is set low.

+

SETUP

+fritzing diagram
+
+
+
+
+The ranger used is a SRF05 (check the pinouts, there are many +variants).
+
+The fritzing diagram shows the back of the ranger, i.e. pin 1 is +the rightmost.
+
+Pin 1 is 5V.
+Pin 2 is the trigger line.
+Pin 3 is the echo line.
+Pin 4 is out (unused).
+Pin 5 is ground.
+
+

photo of set-up

+

CODE

+#include <stdio.h>
+
+#include <pigpio.h>
+
+/*
+
+P1  Name  gpio    used for
+
+ 2  5V    ---     +5V
+ 6  GND   ---     +Ground
+24  CE0   8       +Sonar echo
+26  CE1   7       +Sonar trigger
+
+*/
+
+#define SONAR_TRIGGER 7
+#define SONAR_ECHO    8
+
+/* forward prototypes */
+
+void sonarTrigger(void);
+
+void sonarEcho(int gpio, int level, uint32_t tick);
+
+int main(int argc, char *argv[])
+{
+   if (gpioInitialise()<0) return 1;
+
+   gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);
+   gpioWrite  (SONAR_TRIGGER, PI_OFF);
+
+   gpioSetMode(SONAR_ECHO,    +PI_INPUT);
+
+   /* update sonar 20 times a second, timer #0 */
+
+   gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms +*/
+
+   /* monitor sonar echos */
+
+   gpioSetAlertFunc(SONAR_ECHO, sonarEcho);
+
+   while (1) sleep(1);
+
+   gpioTerminate();
+
+   return 0;
+}
+
+void sonarTrigger(void)
+{
+   /* trigger a sonar reading */
+
+   gpioWrite(SONAR_TRIGGER, PI_ON);
+
+   gpioDelay(10); /* 10us trigger pulse */
+
+   gpioWrite(SONAR_TRIGGER, PI_OFF);
+}
+
+void sonarEcho(int gpio, int level, uint32_t tick)
+{
+   static uint32_t startTick, firstTick=0;
+
+   int diffTick;
+
+   if (!firstTick) firstTick = tick;
+
+   if (level == PI_ON)
+   {
+      startTick = tick;
+   }
+   else if (level == PI_OFF)
+   {
+      diffTick = tick - startTick;
+
+      printf("%u %u\ ", tick-firstTick, +diffTick);
+   }
+}
+

BUILD

+cc -o sonar sonar.c -lpigpio -lrt -lpthread
+

RUN

+sudo ./sonar >sonar.dat &
+
+While the program is running you can capture the waveform using the +notification feature built in to pigpio.  Issue the following +commands on the Pi.
+
+pigs no
+pig2vcd  </dev/pigpio0 >sonar.vcd &
+pigs nb 0 0x180 # set bits for gpios 7 and 8
+

Move an object in front of the sonar ranger for a few +seconds.

+pigs nc 0
+

The file sonar.vcd will contain the captured waveform, which can +be viewed using GTKWave.

+

Overview

+LDR waveform 1
+

Reading circa every 10ms

+Sonar waveform 2
+

One reading, circa 400us

+Sonar waveform 3
+

another

+Sonar waveform 4
+

The file sonar.dat will contain pairs of timestamps and echo +length (in us).  The following  script will convert the +timestamps into seconds.

+

awk '{print $1/1000000, $2}' sonar.dat +>sonar-secs.dat

+

Gnuplot is a useful tool to graph data.

+plot 'sonar-secs.dat' title 'Sonar'
+

gnuplot 1
+ plot [10:25] 'sonar-secs.dat' title 'Sonar'

+

gnuplot 1

diff --git a/DOC/tmp/body/examples.body b/DOC/tmp/body/examples.body new file mode 100644 index 0000000..7df20a8 --- /dev/null +++ b/DOC/tmp/body/examples.body @@ -0,0 +1,495 @@ +The following examples show various ways pigpio may be used to communicate with sensors via the GPIO.
+
+Although many are complete programs they are intended to be a starting point in producing your own code, not an end point.
+
+Index

+Hardware

+Shell code

+C code

+C++ code

+pigpiod_if2 code

+Python code

+Miscellaneous related code

+External links

+

Hardware

+A few practical examples of using pigpio with hardware.
+
+
IR Receiver
2013-06-09
Reading an infrared remote receiver.
+
+
Light Dependent Resistor
2013-06-09
Measuring brightness with a light dependent resistor (LDR). Improved methods of timing the start of the capacitor recharge are given for C and Python.
+
+
Motor Shield
2013-12-15
Using an Arduino motor shield.
+
+
Rotary Encoder
2013-06-09
Reading a rotary encoder.
+
+
Sonar Ranger
2013-06-10
Measuring range with a sonar ranger.
+
+

Shell code

+Examples of using pigpio with shell code.
+
+
GPIO test
2014-08-11
This bash script tests the user GPIO. Video
+
+

C code

+Examples of C pigpio programs.
+
+If your program is called foobar.c then build with
+
+gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
+
+
Frequency Counter 1
2014-08-20
A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs).
+
+
Frequency Counter 2
2014-08-20
A program showing how to use the gpioSetGetSamplesFunc function to set a callback for accumulated GPIO state changes over the last millisecond. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). Generally the method used is more complicated but more efficient than frequency counter 1.
+
+
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
+
+
I2C Sniffer
2014-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results. This C program uses pigpio notifications.
+
+
IR Receiver
2015-02-25
Function to hash a code from an IR receiver (reading an IR remote control).
+
+
PCF8591 YL-40
2014-08-26
A program to display readings from the (I2C) PCF8591.
+
+
Pot + Capacitor Recharge Timing
2014-03-14
Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
+
+
Rotary Encoder
2015-10-03
Function to decode a mechanical rotary encoder.
+
+
SPI bit bang MCP3008
2016-03-20
This program shows how to read multiple MCP3008 ADC simultaneously with accurately timed intervals. One 10-bit channel of each ADC may be sampled at up to 25k samples per second.
+
+
SPI bit bang MCP3202
2016-03-20
This program shows how to read multiple MCP3202 ADC simultaneously with accurately timed intervals. One 12-bit channel of each ADC may be sampled at up to 25k samples per second.
+
+
SPI bit bang MCP3008 and MCP3202
2016-03-20
This program shows how to read multiple MCP3008 and MCP3202 ADC simultaneously with accurately timed intervals. One channel of each ADC may be sampled at up to 25k samples per second. The 10-bit MCP3008 readings are multiplied by 4 so they have the same range (0-4095) as the 12-bit MCP3202.
+
+
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
+
+sudo ./servo_demo # Generate pulses on GPIO 4.
+
+sudo ./servo_demo 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
+
+
SPI pigpio driver speed test
2016-11-06
This C code is used to benchmark the pigpio SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
+
+
Wiegand Reader
2013-12-30
Function to read a Wiegand Reader.
+
+

C++ code

+Examples of C++ pigpio programs.
+
+If your program is called foobar.cpp then build with
+
+g++ -Wall -pthread -o foobar foobar.cpp -lpigpio -lrt
+
+
IR Receiver
2015-02-22
Class to hash a code from an IR receiver (reading an IR remote control).
+
+
Rotary Encoder
2013-12-30
Class to decode a mechanical rotary encoder.
+
+
Wiegand Reader
2013-12-30
Class to read a Wiegand Reader.
+
+

pigpiod_if2 code

The pigpiod_if2 code examples are linked with libpigpiod_if2 and are written in C.
+
+The pigpiod_if2 library may be compiled and run on any Linux machine and allows control of the GPIO on one or more networked Pis.
+
+It should be possible to adapt the library to run on Macs and PCs.
+
+Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
+
+
433MHz Keyfob RX/TX
2015-11-17
Code to read and transmit 313 and 434 MHz key fob codes. The codes to be read must use Manchester encoding. The transmitted codes use Manchester encoding.
+
+./_433D -r10 # Print fob keycodes received on GPIO 10.
+
+./_433D -t5 8246184 # Transmit code on GPIO 5.
+
+./_433D -r10 -t5 8246184 # Transmit code on GPIO 5 then listen for codes
+
+./_433D -? for options.
+
+
DHT11/21/22/33/44 Sensor
2016-02-16
Code to read the DHT temperature and humidity sensors. The sensor may be auto detected. A DHT11 sensor may be read once per second. The other sensors should not be read more often than once every three seconds.
+
+The code auto detects the DHT model and generally only the GPIO needs to be specified.
+
+./DHTXXD -g17 # Read a DHT connected to GPIO 17.
+
+./DHTXXD -g5 -i3 # Read a DHT connected to GPIO 5 every three seconds.
+
+./DHTXXD -? # for options.
+
+
Rotary Encoder
2015-11-18
Code to monitor a rotary encoder and show the position changes. By default the detent changes are shown. There is an option to show the four steps per detent instead.
+
+./RED -a7 -b8 -s30 # Show encoder on 7/8 detent changes for 30 seconds.
+
+./RED -a5 -b6 -m1 # Show encoder on 5/6 step changes forever.
+
+./RED -? # for options.
+
+
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
+
+./servo_demo_D # Generate pulses on GPIO 4.
+
+./servo_demo_D 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
+
+
Sonar Ranger
2015-11-16
Code to read the SRF-04 and SRF-05 type of sonar rangers which use the trigger echo method of operation. A 10 μs trigger pulse initiates a series of high frequency sonar chirps. The echo line then goes high and stays high until an echo from an object is received. The echo high time is used to calculate the distance of the object.
+
+For a one-off reading only the trigger and echo GPIO need to be specified.
+
+./SRTED -t5 -e6 # Read a sonar ranger connected to GPIO 5/6.
+
+./SRTED -t11 -e5 -i0.1 # Read a sonar ranger connected to GPIO 11/5 every 0.1 seconds.
+
+./SRTED -? # for options.
+
+
Transmit Rotary Encoder Test Signals
2015-11-25
Code to transmit quadrature signals to test rotary encoder software.
+
+tx_RED -aGPIO -bGPIO [options]
+
+tx_RED -? for options
+
+E.g.
+
+tx_RED -a5 -b6 -s20 -r-100
+
+
Transmit Wiegand Test Signals
2015-11-25
Code to transmit Wiegand codes to test Wiegand decoder software.
+
+tx_WD -gGPIO -wGPIO [options] {code}+
+
+tx_WD -? for options
+
+E.g.
+
+tx_WD -g5 -w6 -s37 12345 67890 123 899999
+
+
Wiegand Reader
2015-11-25
Code to read a Wiegand Reader.
+
+./WD -g7 -w8 -s30 # Read Wiegand codes from GPIO 7/8 for 30 seconds.
+
+./WD -g5 -w6 # Read Wiegand codes from GPIO 5/6 forever.
+
+./WD -? # for options.
+
+

Python code

The Python code may be run on any Python machine and allows control of the GPIO on one or more networked Pis.
+
+The Python machine need not be a Pi, it may run Windows, Mac, Linux, anything as long as it supports Python.
+
+Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
+
+
433MHz Keyfob RX/TX
2015-10-30
Classes to send and receive 433MHz wireless keyfob codes. These keyfobs are widely used for remote control of devices.
+
+
7-Segment LED Display Multiplexing
2016-12-12
Script to multiplex several 7-segment LED displays. Each display has the segments a-g and the decimal point connected in parallel but has an individual enable GPIO (connected to the common anode or cathode).
+
+
APA102 LED strip driver
2017-03-28
Script to drive an APA102 LED strip. Three different methods are demonstrated - using spidev SPI (only works on the local Pi), pigpio SPI, and pigpio waves. The SPI solutions only work with the dedicated SPI GPIO. Waves may use any spare GPIO. Four different examples are given including a LED strip clock.
+
+
BME280 Sensor
2016-08-05
Class to read the relative humidity, temperature, and pressure from a BME280 sensor. The sensor has both an I2C and a SPI interface which are both
+supported by the class.
+
+
DHT11/21/22/33/44 Sensor
2019-11-07
Class to read the relative humidity and temperature from a DHT sensor. It can automatically recognize the sensor type.
+
+The default script prints the reading from the specified DHT every 2 seconds. E.g. ./DHT.py 22 27 displays the data for DHT connected to GPIO 22 and 27.
+
+The following data is printed for each DHT: timestamp, GPIO, status, temperature, and humidity.
+
+The timestamp is the number of seconds since the epoch (start of 1970).
+
+The status will be one of: 0 - a good reading, 1 - checksum failure, 2 - data had one or more invalid values, 3 - no response from sensor.
+
+
DHT22 AM2302 Sensor
2014-07-11
Class to read the relative humidity and temperature from a DHT22/AM2302 sensor.
+
+
DS18B20 Temperature Sensor
2016-06-29
Script to read the temperature from any DS18B20 sensors connected to the 1-wire bus.
+
+To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
+
+dtoverlay=w1-gpio
+
+By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
+
+Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
+
+This script uses the file features of pigpio to access the remote file system.
+
+The following entry must be in /opt/pigpio/access.
+
+/sys/bus/w1/devices/28*/w1_slave r
+
+
Dust Sensor
2015-11-22
Class to read a Shinyei PPD42NS Dust Sensor, e.g. as used in the Grove dust sensor.
+
+
GPIO Status
2014-06-12
Script to display the status of GPIO 0-31.
+
+
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
+
+
HX711 24-bit ADC
2018-03-05
Class to read the channels of a HX711 24-bit ADC.
+
+
I2C ADXL345 Accelerometer
2015-04-01
Script to display the X, Y, and Z values read from an ADXL345 accelerometer.
+
+
I2C HMC5883L Magnetometer
2015-04-01
Script to display the X, Y, and Z values read from a HMC5883L Magnetometer (compass).
+
+
I2C ITG3205 Gyroscope
2015-04-01
Script to display the X, Y, Z, and temperature values read from an ITG3205 gyroscope.
+
+
I2C LCD Display
2016-04-20
Class to display text on a LCD character display. The class supports the PCF8574T 8-bit I2C port expander connected to a HD44780 based LCD display. These displays are commonly available in 16x2 and 20x4 character formats.
+
+
I2C slave device
2016-10-31
This script demonstrates how to transfer messages from an Arduino acting as the I2C bus master to the Pi acting as an I2C slave device.
+
+
I2C Sniffer
2015-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results.
+
+
I2C Sonar
2016-03-24
A class to read up to 8 HC-SR04 sonar rangers connected to an MCP23017 port expander.
+
+
IR Receiver
2014-06-12
Class to hash a code from an IR receiver (reading an IR remote control).
+
+
IR Record and Playback
2015-12-21
This script may be used to record and play back arbitrary IR codes.
+
+To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given.
+
+E.g. ./irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0
+
+To playback the GPIO connected to the IR transmitter, the file containing the recorded codes, and the codes to be played back are given.
+
+E.g. ./irrp.py -p -g18 -fir-codes 2 3 4
+
+./irrp.py -h # for options
+
+
Kivy GPIO control
2016-12-11
This example shows how to use Kivy to control a Pi's GPIO. The GPIO may be configured as inputs, outputs, or to generate Servo or PWM pulses. Kivy is an Open source Python library for rapid development of applications.
+
+
MAX6675 SPI Temperature Sensor
2016-05-02
A script to read the temperature from a MAX6675 connected to a K-type thermocouple. The MAX6675 supports readings in the range 0 - 1023.75 C. Up to 4 readings may be made per second.
+
+
Monitor GPIO
2016-09-17
Script to monitor GPIO for level changes. By default all GPIO are monitored. At a level change the GPIO, new level, and microseconds since the last change is printed.
+
+
Morse Code
2015-06-17
Script to transmit the morse code corresponding to a text string.
+
+
NRF24 radio transceiver
2018-01-06
Script to transmit and receive messages using the nRF24L01 radio transceiver.
+
+
PCA9685 16 Channel PWM
2016-01-31
Class to control the 16 PWM channels of the I2C PCA9685. All channels use the same frequency. The duty cycle or pulse width may be set independently for each channel.
+
+
PCF8591 YL-40
2014-08-26
Script to display readings from the (I2C) PCF8591.
+
+
PPM (Pulse Position Modulation) generation
2016-02-19
Script to generate PPM signals on a chosen GPIO.
+
+
PPM (Pulse Position Modulation) to servo pulses
2019-10-09
Script to read a PPM signal on a GPIO and generate the corresponding servo signals on chosen GPIO.
+
+
pigpio Benchmark
2014-06-12
Script to benchmark the pigpio Python module's performance.
+
+
pigpio CGI
2015-05-04
Script demonstrating how to access the pigpio daemon using CGI from a browser. Instructions on how to use with Apache2 on the Pi are given in the comments.
+
+
Playback piscope recordings
2016-12-23
Script to playback GPIO data recorded in piscope format.
+
+To playback GPIO 4 to GPIO 4 from file data.piscope
+./playback.py data.piscope 4
+
+To playback GPIO 4 to GPIO 7 from file rec.txt
+./playback.py rec.txt 7=4
+
+
Pot + Capacitor Recharge Timing
2016-09-26
Class to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
+
+
PWM Monitor
2015-12-08
Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle.
+
+
Rotary Encoder
2014-06-12
Class to decode a mechanical rotary encoder.
+
+
RPM Monitor
2016-01-20
Class to monitor speedometer pulses and calculate the RPM (Revolutions Per Minute).
+
+
Si7021 I2C Temperature and Humidity Sensor
2016-05-07
Class to read the temperature and relative humidity from a Si7021.
+
+
SPI Monitor
2016-09-21
A program to passively sniff SPI transactions and display the results. The SPI rate should be limited to about 70kbps if using the default pigpio 5µs sampling rate.
+
+
Servo Pulse Generator
2016-10-07
This script generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
+
+./servo_demo.py # Generate pulses on GPIO 4.
+
+./servo_demo.py 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
+
+
Sonar Ranger
2014-06-12
Class to read sonar rangers with separate trigger and echo pins.
+
+
TCS3200 Colour Sensor
2015-07-03
Class to read the TCS3200 colour sensor
+
+
Virtual Wire
2015-10-31
Class to send and receive radio messages compatible with the Virtual Wire library for Arduinos. This library is commonly used with 313MHz and 434MHz radio tranceivers.
+
+
Wave create
2019-11-18
Script to generate waves from a template defined in a text file.
+
+You can also specify one of py, c, or pdif - the script output will then be a complete program to generate the wave (py for Python script, c for a C program, pdif for a C program using the pigpio daemon I/F).
+
+If none of py, c, or pdif are chosen the waveform will be generated for 30 seconds.
+
+Example text file
+
+# GPIO levels
+23 11000001
+11 01110000
+12 00011100
+4 00000111
+
+To generate a pdif program with a bit time of 100 microseconds
+./create_wave.py wave_file 100 pdif >wave_pdif.c
+
+To just transmit the wave with a bit time of 50 microseconds
+./create_wave.py wave_file 50
+
+
Wave PWM 1
2016-03-19
Script to show how waves may be used to generate PWM at (one) arbitrary frequency on multiple GPIO. For instance PWM at 10kHz may be generated with 100 steps between off and fully on.
+
+
Wave PWM 2
2016-10-06
Class to generate PWM on multiple GPIO. It is more flexible than the Wave PWM 1 example in that the start of the pulse within each cycle may be specified as well as the duty cycle. The start and length of each pulse may be specified on a GPIO by GPIO basis in microseconds or as a fraction of the cycle time. The class includes a __main__ to demostrate its ability to send servo pulses.
+
+
Wiegand Reader
2014-06-12
Class to read a Wiegand reader.
+
+

Miscellaneous related code

+The following code examples do not use pigpio.
+
+
ADXL345
2014-03-12
This C program reads x, y, and z accelerations from the ADXL345 via I2C address 0x53.
+
+
DS18B20 Temperature Sensor
2016-04-25
This Python script reads the temperature from any DS18B20 sensors connected to the 1-wire bus.
+
+To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
+
+dtoverlay=w1-gpio
+
+By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
+
+Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
+
+
Easy as Pi Server
2014-09-15
This Python class implements a simple server which allows broswer commands to be executed on the Pi.
+
+
Minimal Clock Access
2015-05-20
This C code sets GPIO 4 to a specified clock frequency. The frequency can be set between 4.6875 kHz and 500 MHz (untested). The clock can be preferentially set from one of the sources OSC (19.2MHz), HDMI (216MHz), PLLD (500MHz), or PLLC (1000MHz). MASH can be set between 0 and 3. MASH may not work properly for clock dividers less than 5.
+
+
Minimal GPIO Access
2019-07-03
This C code has a minimal set of functions needed to control the GPIO and other Broadcom peripherals. The program requires root privileges to run. See Tiny GPIO access for an alternative which controls the GPIO (but not the other peripherals) and does not require root access.
+
+The code has been updated for the BCM2711 (Pi4B).
+
+The following functions are provided.
+
+gpioInitialise
+gpioSetMode
+gpioGetMode
+gpioSetPullUpDown
+gpioRead
+gpioWrite
+gpioTrigger
+gpioReadBank1
+gpioReadBank2
+gpioClearBank1
+gpioClearBank2
+gpioSetBank1
+gpioSetBank2
+gpioHardwareRevision
+gpioTick
+
+
Nanosecond Pulse Generation
2014-01-29
This C program uses the PWM peripheral to generate precisely timed pulses of very short duration. Pulses as short as 4 nano seconds can be generated.
+
+
PCF8591 YL-40
2014-08-26
C and Python code to read the (I2C) PCF8591.
+
+
SPI Linux driver speed test
2016-11-06
This C code is used to benchmark the Linux SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
+
+
Tiny GPIO Access
2016-04-30
This C code has a minimal set of functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO).
+
+You may need to change the permissions and ownership of /dev/gpiomem if they have not been correctly set up.
+
+sudo chown root:gpio /dev/gpiomem
+sudo chmod g+rw /dev/gpiomem
+
+The user (default pi) needs to be in the gpio group.
+
+sudo adduser pi gpio
+
+The following functions are provided.
+
+gpioInitialise
+gpioSetMode
+gpioGetMode
+gpioSetPullUpDown
+gpioRead
+gpioWrite
+gpioTrigger
+gpioReadBank1
+gpioReadBank2
+gpioClearBank1
+gpioClearBank2
+gpioSetBank1
+gpioSetBank2
+gpioHardwareRevision
+
+

External links

+Related code.
+
+
Stepper Motor
2016-08-12
Stepper motor code.
+
+
Parallax ActivityBot 360
2018-11-03
Python 3 implementation for programming a Parallax ActivityBot 360 Robot Kit with a Raspberry Pi.
+
+

Index

+ +
433MHz Keyfob RX/TX pdif2 + Python +
7-Segment LED Display Multiplexing Python +
ADXL345 Misc +
APA102 LED strip driver Python +
BME280 Sensor Python +
DHT11/21/22/33/44 Sensor pdif2 + Python +
DHT22 AM2302 Sensor Python +
DS18B20 Temperature Sensor Python + Misc +
Dust Sensor Python +
Easy as Pi Server Misc +
Frequency Counter 1 C +
Frequency Counter 2 C +
GPIO Status Python +
GPIO test Shell +
Hall Effect Sensor C + Python +
HX711 24-bit ADC Python +
I2C ADXL345 Accelerometer Python +
I2C HMC5883L Magnetometer Python +
I2C ITG3205 Gyroscope Python +
I2C LCD Display Python +
I2C slave device Python +
I2C Sniffer C + Python +
I2C Sonar Python +
IR Receiver Hardware + C + C++ + Python +
IR Record and Playback Python +
Kivy GPIO control Python +
Light Dependent Resistor Hardware +
MAX6675 SPI Temperature Sensor Python +
Minimal Clock Access Misc +
Minimal GPIO Access Misc +
Monitor GPIO Python +
Morse Code Python +
Motor Shield Hardware +
Nanosecond Pulse Generation Misc +
NRF24 radio transceiver Python +
Parallax ActivityBot 360 External +
PCA9685 16 Channel PWM Python +
PCF8591 YL-40 C + Python + Misc +
pigpio Benchmark Python +
pigpio CGI Python +
Playback piscope recordings Python +
Pot + Capacitor Recharge Timing C + Python +
PPM (Pulse Position Modulation) generation Python +
PPM (Pulse Position Modulation) to servo pulses Python +
PWM Monitor Python +
Rotary Encoder Hardware + C + C++ + pdif2 + Python +
RPM Monitor Python +
Servo Pulse Generator C + pdif2 + Python +
Si7021 I2C Temperature and Humidity Sensor Python +
Sonar Ranger Hardware + pdif2 + Python +
SPI bit bang MCP3008 C +
SPI bit bang MCP3008 and MCP3202 C +
SPI bit bang MCP3202 C +
SPI Linux driver speed test Misc +
SPI Monitor Python +
SPI pigpio driver speed test C +
Stepper Motor External +
TCS3200 Colour Sensor Python +
Tiny GPIO Access Misc +
Transmit Rotary Encoder Test Signals pdif2 +
Transmit Wiegand Test Signals pdif2 +
Virtual Wire Python +
Wave create Python +
Wave PWM 1 Python +
Wave PWM 2 Python +
Wiegand Reader C + C++ + pdif2 + Python +
\ No newline at end of file diff --git a/DOC/tmp/body/faq.body b/DOC/tmp/body/faq.body new file mode 100644 index 0000000..7c505f0 --- /dev/null +++ b/DOC/tmp/body/faq.body @@ -0,0 +1,452 @@ + +Are my GPIO broken?
+
+Audio is broken
+
+Can´t initialise pigpio +library
+
+Can´t lock +var/run/pigpio.pid
+
+Hello World!
+
+Clock skew, make fails
+
+Have I fried my GPIO?
+
+How do I debounce +inputs?
+
+How fast is SPI?
+
+Library update didn't work
+
+make fails with clock skew
+
+Porting pigpio to another CPU/SoC
+
+Sound isn't working
+
+Symbol not found
+
+What is I2C?
+
+What is Serial?
+
+What is SPI?
+
+Which library should I use?
+
+

Are my +GPIO broken?

+

See Have I fried my +GPIO?

+

Audio is +broken

+

See Sound isn't +working

+

Can´t lock +/var/run/pigpio.pid

+

See Can´t_initialise_pigpio_library
+

+

Can´t initialise pigpio +library

+

This message means the pigpio daemon is already running.

+

The default daemon is called pigpiod and may be removed as +follows.

+Check that it is running with the command +

ps aux | grep pigpiod

+

Kill the daemon with

+

sudo killall pigpiod

+

If your own program is acting as the daemon it may be removed as +follows.

+

Find its process id (pid).

+

cat /var/run/pigpio.pid

+

Kill the program with

+

sudo kill -9 pid

+If the above doesn't work do the following and try starting the +daemon again +

sudo rm /var/run/pigpio.pid

+

To start the daemon do

+

sudo pigpiod

+

Have I fried my GPIO?

+

If you think you have damaged one or more GPIO you can carry out +a diagnostic test.

+

The test is a command line script called gpiotest

+For the duration of the test nothing must be connected to the GPIO +(no LEDs, wires, ribbon cables etc.). +

The test checks that each GPIO may be read and written and that +the internal resistor pull-ups and pull-downs are functional.

+

A video +showing what happens to the GPIO during a test.

+

A test with all GPIO okay.

+
This program checks the Pi's (user) gpios.
+
+The program reads and writes all the gpios.  Make sure NOTHING
+is connected to the gpios during this test.
+
+The program uses the pigpio daemon which must be running.
+
+To start the daemon use the command sudo pigpiod.
+
+Press the ENTER key to continue or ctrl-C to abort...
+
+Testing...
+Skipped non-user gpios: 0 1 28 29 30 31 
+Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 +Failed user gpios: None +
+

A test showing failed GPIO.

+
This program checks the Pi's (user) gpios.
+
+The program reads and writes all the gpios. Make sure NOTHING
+is connected to the gpios during this test.
+
+The program uses the pigpio daemon which must be running.
+
+To start the daemon use the command sudo pigpiod.
+
+Press the ENTER key to continue or ctrl-C to abort...
+
+Testing...
+Write 1 to gpio 17 failed.
+Pull up on gpio 17 failed.
+Write 1 to gpio 18 failed.
+Pull up on gpio 18 failed.
+Write 0 to gpio 23 failed.
+Pull down on gpio 23 failed.
+Write 0 to gpio 24 failed.
+Pull down on gpio 24 failed.
+Write 1 to gpio 27 failed.
+Pull up on gpio 27 failed.
+Skipped non-user gpios: 0 1 28 29 30 31
+Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 +Failed user gpios: 17 18 23 24 27 +
+

How do I debounce inputs?

+

Some devices like mechanical switches can generate multiple +interrupts as they bounce between on and off.  It is possible +to debounce the inputs in hardware by the correct use of resistors +and capacitors.

+

In software use the glitch filter which ignores all events +shorter than a set number of microseconds.  C gpioGlitchFilter, Python set_glitch_filter.

+

How fast is +SPI?

+The SPI throughput in samples per second depends on a number of +factors.
+
+
    +
  • The SPI bit rate (transfer rate in bits per second)
  • +
+
    +
  • The number of bytes transferred per sample (a 12 bit ADC sample +may require 3 bytes to transfer)
  • +
+
    +
  • The driver used
  • +
+

Two of those factors are fixed, the variable is the driver +used.

+

The pigpio driver is considerably faster than the Linux SPI +driver as is demonstrated by the following graphs.

+

Each graph shows the SPI bit rate in bits per second along the +horizontal axis.  The samples per second achieved is shown on +the vertical axis.  Each graph contains plots assuming 1 to 5 +bytes per transfer.

+

The source code used for the tests is spi-driver-speed.c and spi-pigpio-speed.c

+

spi-lnx-pibr1.png

+
+

spi-pig-pibr1.png

+
+

spi-lnx-pi3b.png

+
+

spi-pig-pi3b.png

+

Library update didn't work

+

pigpio places files in the following locations

+

/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
+/usr/local/lib (libpigpio.so, libpigpiod_if.so, +libpigpiod_if2.so)
+/usr/local/bin (pig2vcd, pigpiod, pigs)
+/usr/local/man (man pages)

+The raspberrypi.org image containing pigpio uses different +locations.
+

/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
+/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)
+/usr/bin (pig2vcd, pigpiod, pigs)
+/usr/man (man pages)

+

Mostly this doesn't matter as the /usr/local directories will +generally be earlier in the search path.  The pigpio built +includes, binaries, and manuals are normally found first.

+

However the wrong libraries may be linked during the +compilation.  If this is the case remove the /usr/lib entries +for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so

+

Hello World!

+

The following examples show how to use the various components of +the pigpio library.

+

Each example shows how to read the level of a GPIO.

+

C

+read_cif.c +
+#include <stdio.h>
+#include <pigpio.h>
+
+int main(int argc, char *argv[])
+{
+   int GPIO=4;
+   int level;
+
+   if (gpioInitialise() < 0) return 1;
+
+   level = gpioRead(GPIO);
+
+   printf("GPIO %d is %d\n", GPIO, level);
+
+   gpioTerminate();
+}
+    
+

Build

+gcc -pthread -o read_cif read_cif.c -lpigpio +

Run

+sudo ./read_cif +

C via pigpio daemon

+read_pdif.c +
+#include <stdio.h>
+#include <pigpiod_if2.h>
+
+int main(int argc, char *argv[])
+{
+   int pi;
+   int GPIO=4;
+   int level;
+
+   pi = pigpio_start(0, 0); /* Connect to local Pi. */
+
+   if (pi < 0)
+   {
+      printf("Can't connect to pigpio daemon\n");
+      return 1;
+   }
+
+   level = gpio_read(pi, GPIO);
+
+   printf("GPIO %d is %d\n", GPIO, level);
+
+   pigpio_stop(pi); /* Disconnect from local Pi. */
+   
+   return 0;
+}
+
+

Build

+gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2 +

Run

+./read_pdif +

Python

+read_gpio.py +
+#!/usr/bin/env python
+
+import pigpio
+
+GPIO=4
+
+pi = pigpio.pi()
+if not pi.connected:
+   exit()
+
+level = pi.read(GPIO)
+
+print("GPIO {} is {}".format(GPIO, level))
+
+pi.stop()
+    
+

Run

+python read_gpio.py +

pigs

+
+pigs r 4
+    
+

pipe I/F

+
+echo "r 4" >/dev/pigpio
+cat /dev/pigout
+    
+

make fails with clock +skew

+

If make fails with one of the following messages it is probably +because the Pi's clock is wrong.

+

make: Warning: File 'xxx' has modification time x s in the +future
+make: warning: Clock skew detected. Your build may be +incomplete.

+

make uses the current time to work out which files need to be +rebuilt (a file is rebuilt if it depends on other files which have +a later time-stamp).

+

The solution is to make sure the system clock is correct.  +If the Pi is networked this will not normally be a problem.

+

To set the date and time use the date command as in the +following example.

+

sudo date -d "2017-03-01 18:47:00"

+

Porting pigpio +to another CPU/SoC

+

Sound +isn't working

+

The Pi contains two pieces of hardware, a PWM peripheral and a +PCM peripheral, to generate sound.  The PWM peripheral is +normally used and generates medium quality audio out of the +headphone jack.  The PCM peripheral may be used by add-ons +such as HATs and generates high quality audio.

+

pigpio uses at least one of these peripherals during normal +operation (for timing DMA transfers).  pigpio will use both +peripherals if waves or the hardware PWM function is used.

+

By default pigpio uses the PCM peripheral leaving the PWM +peripheral free for medium quality audio.

+

You can change the default with a configuration option.  +For C use gpioCfgClock, for the +pigpio daemon use the -t option.

+

What is I2C?

+

I2C is a data link between the Pi (master) and one or more +slaves.

+

Data may be sent and received but the Pi initiates all +transfers.

+

I2C is a medium speed link.  On the Pi the default speed is +100 kbps, but 400 kbps also works.

+

I2C is implemented as a bus with two lines called

+
    +
  • SDA - for data
  • +
  • SCL - for a clock
  • +
+On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO +3 (pin 5) for SCL.
+
+Only one slave device may be communicated with at a time.  +Each message from the Pi includes the slave to be addressed and +whether a read or write is to be performed.
+
+When the Pi (master) wishes to talk to a slave it begins by issuing +a start sequence on the I2C bus. A start sequence is one of two +special sequences defined for the I2C bus, the other being the stop +sequence. The start sequence and stop sequence are special in that +these are the only places where the SDA (data line) is allowed to +change while the SCL (clock line) is high. When data is being +transferred, SDA must remain stable and not change whilst SCL is +high. The start and stop sequences mark the beginning and end of a +transaction with the slave device.
+
+I2C start and stop sequences
+
+Data is transferred in 8-bit bytes. The bytes are placed on the SDA +line starting with the most significant bit. The SCL line is then +pulsed high, then low. For every byte transferred, the device +receiving the data sends back an acknowledge bit, so there are +actually 9 SCL clock pulses to transfer each 8-bit byte of data. If +the receiving device sends back a low ACK bit, then it has received +the data and is ready to accept another byte. If it sends back a +high then it is indicating it cannot accept any further data and +the master should terminate the transfer by sending a stop +sequence.
+
+

I2C waveform

+

What is +Serial?

+

Serial is a data link between the Pi and one other +device.

+

Data may be sent and received.  Either the Pi or the device +can initiate a transfer.

+

Serial is a low to medium speed link.  On the Pi speeds of +50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, +19200, 38400, 57600, 115200, and 230400 bps may be used.

+

Serial is implemented with one line for transmit called TXD and +one line for receive called RXD.

+

If only receive or transmit are required the other line need not +be connected.

+

The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for +RXD.

+

Data is normally transmitted in 8-bit bytes with a start bit, +eight data bits, no parity, and one stop bit.  This is +represented as 8N1.  The number of transmitted bits per second +(bps) is called the baud rate.   The time for each bit, +1 / baud rate seconds, is +referred to as the bit period.

+

The lines are in the high state when no data is being +transmitted.  The start of a byte is signalled by the line +going low for one bit period (the start bit).  The data bits +are then sent least significant bit firsts (low if the bit is 0, +high if the bit is 1).  The data bits are followed by the +optional parity bit.  Finally the line is set high for at +least the number of stop bit periods.  The line will stay high +if there are no more bytes to be transmitted.

+

Serial waveform

+

What is SPI?

+

SPI is a data link between the Pi (master) and one or more +slaves.

+

Data may be sent and received but the Pi initiates all +transfers.

+

SPI is a medium to high speed link.  On the Pi speeds of 32 +kbps to 8 Mbps may be used.

+

SPI is implemented as a bus with three lines called

+
    +
  • MOSI - for data from the Pi to the slave
  • +
  • MISO - for data from the slave to the Pi
  • +
  • SCLK - for a clock
  • +
+Only one slave device may be communicated with at a time.  An +additional line per slave called slave select is used to identify +the slave to be addressed. +

The Pi has two SPI buses

+
    +
  1. the main SPI bus +
      +
    • MOSI GPIO 10 (pin 19)
    • +
    • MISO GPIO 9 (pin 21)
    • +
    • SCLK GPIO 11 (pin 23)
    • +
    • Slave selects
    • +
    • +
        +
      • CE0 GPIO 8 (pin 24)
      • +
      • CE1 GPIO 7 (pin 26)
      • +
      +
    • +
    +
  2. +
  3. the auxiliary SPI bus +
      +
    • MOSI GPIO 20 (pin 38)
    • +
    • MISO GPIO 19 (pin 35)
    • +
    • SCLK GPIO 21 (pin 40)
    • +
    • Slave selects
    • +
    • +
        +
      • CE0 GPIO 18 (pin 12)
      • +
      • CE1 GPIO 17 (pin 11)
      • +
      • CE2 GPIO 16 (pin 36)
      • +
      +
    • +
    +
  4. +
+

SPI waveform

+


+

Which library +should I use?

+


diff --git a/DOC/tmp/body/index.body b/DOC/tmp/body/index.body new file mode 100644 index 0000000..f8a4d2e --- /dev/null +++ b/DOC/tmp/body/index.body @@ -0,0 +1,652 @@ + +pigpio is a library for the Raspberry which allows control of the +General Purpose Input Outputs (GPIO).  pigpio works on all +versions of the Pi. +

At the moment pigpio on the Pi4B is experimental. I am not +sure if the DMA channels being used are safe. The Pi4B defaults are +primary channel 7, secondary channel 6. If these channels do not +work you will have to experiment. You can set the channels used by +the pigpio daemon by invoking it with the -d and -e options, e.g. +sudo pigpiod -d 5 -e 8 to specify primary 5, +secondary 8.

+

Download

+

Features

+
    +
  • +

    hardware timed sampling and time-stamping of GPIO 0-31 every 5 +us

    +
  • +
  • +

    hardware timed PWM on all of GPIO 0-31

    +
  • +
  • +

    hardware timed servo pulses on all of GPIO 0-31

    +
  • +
  • +

    callbacks on GPIO 0-31 level change (time accurate to a few +us)

    +
  • +
  • +

    notifications via pipe on GPIO 0-31 level change

    +
  • +
  • +

    callbacks at timed intervals

    +
  • +
  • +

    reading/writing all of the GPIO in a bank (0-31, 32-53) as a +single operation

    +
  • +
  • +

    GPIO reading, writing, modes, and internal pulls

    +
  • +
  • +

    socket and pipe interfaces for the bulk of the functionality

    +
  • +
  • +

    waveforms to generate GPIO level changes (time accurate to a few +us)

    +
  • +
  • +

    software serial links using any user GPIO

    +
  • +
  • +

    rudimentary permission control through the socket and pipe +interfaces

    +
  • +
  • creating and running scripts on the pigpio daemon
  • +
+

General

+The pigpio library is written in the C +programming language.
+
+The pigpio daemon offers a socket and pipe interface to +the underlying C library.
+
+A C library and a Python module allow control of the GPIO via the +pigpio daemon.
+
+There is third party support for a number of other languages.  +

piscope

+

piscope is a logic analyser (digital +waveform viewer).

+piscope is a GTK+3 application and uses pigpio to provide raw GPIO +level data.  piscope may be run on a Pi or on any machine +capable of compiling a GTK+3 application. +

GPIO

+

ALL GPIO are identified +by their Broadcom +number.  See +elinux.org

+There are 54 GPIO in total, arranged in two banks.
+

Bank 1 contains GPIO 0-31.  Bank 2 contains GPIO +32-53.

+For all types of Pi it is safe to read all the GPIO. If you try to +write a system GPIO or change its mode you can crash the Pi or +corrupt the data on the SD card.
+
+There are several types of board, each with different expansion +headers, giving physical access to different GPIO.  + +

Type 1 - Model B (original +model)

+
    +
  • 26 pin header (P1).
  • +
+
    +
  • Hardware revision numbers of 2 and 3.
  • +
+
    +
  • User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA0
34-5V
SCL1
56-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

211314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
+
+

Type 2 - Model A, B (revision +2)

+26 pin header (P1) and an additional 8 pin header (P5). +
    +
  • Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13, +14, 15 (B).
  • +
+
    +
  • User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
5V
-12-3V3
SDA
283429SCL

305631
Ground
-
78-
Ground
+
+

Type 3 - Model A+, B+, Pi +Zero, Pi Zero W, Pi2B, Pi3B, Pi4B

+
    +
  • 40 pin expansion header (J8).
  • +
+
    +
  • Hardware revision numbers of 16 or greater.
  • +
+
    +
  • User GPIO 2-27 (0 and 1 are reserved).
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+GPIOpinpin +GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
ID_SD027281ID_SC

52930-Ground

6313212

133334-Ground
miso19353616ce2

26373820mosi
Ground-394021sclk
+
+

Compute Module

+

All 54 GPIO may be physically accessed.  Some are reserved +for system use - refer to the Compute Module documentation.

+

Only GPIO 0-31 are supported for hardware timed sampling, PWM, +servo pulses, alert callbacks, waves, and software serial +links.

+

Other +Languages

+

There are several third party projects which provide wrappers +for pigpio.

+

Some I am aware of are:

+
    +
  • Erlang +(skvamme)
  • +
  • Java JNI +wrapper around the pigpio C library (mattlewis)
  • +
  • Java via +diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc +(mattlewis)
  • +
  • Java +(nkolban)
  • +
  • .NET/mono +(unosquare)
  • +
  • Node.js +(fivdi)
  • +
  • Perl (Gligan +Calin Horea)
  • +
  • Ruby +(Nak)
  • +
  • Smalltalk(Instantiations)
  • +
  • Xojo(UBogun)
  • +
+
+

The PWM and servo pulses are timed using the DMA +and PWM/PCM peripherals.  This use was inspired by Richard +Hirst's servoblaster kernel module.

diff --git a/DOC/tmp/body/misc.body b/DOC/tmp/body/misc.body new file mode 100644 index 0000000..8bb3552 --- /dev/null +++ b/DOC/tmp/body/misc.body @@ -0,0 +1,24 @@ + +There are two C libraries which provide a socket interface to the +pigpio daemon.  They provide an interface very similar to the +pigpio Python module.
+
    +
  • The original pigpiod_if library is +now deprecated and will no longer be updated.  This library is +limited to controlling one Pi at a time.
  • +
+
    +
  • The new pigpiod_if2 library which +should be used for new code.  This library allows multiple Pis +to be controlled at one time.
  • +
+Additional details of the pigpio socket +interface.
+
+Additional details of the pigpio pipe +interface.
+
+pig2vcd is a utility which converts +pigpio notifications into the VCD (Value Change Dump) format.  +VCD can be read by many programs, in particular GTKWave. diff --git a/DOC/tmp/body/pdif.body b/DOC/tmp/body/pdif.body new file mode 100644 index 0000000..238e3f7 --- /dev/null +++ b/DOC/tmp/body/pdif.body @@ -0,0 +1,1105 @@ +

THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO +USE THE MORE VERSATILE pigpiod_if2 LIBRARY. +

pigpiod_if is a C library for the Raspberry which allows control +of the GPIO via the socket interface to the pigpio daemon.
+

Features

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o callbacks when any of GPIO 0-31 change state +

o callbacks at timed intervals +

o reading/writing all of the GPIO in a bank as one operation +

o individually setting GPIO modes, reading and writing +

o notifications when any of GPIO 0-31 change state +

o the construction of output waveforms with microsecond timing +

o rudimentary permission control over GPIO +

o a simple interface to start and stop new threads +

o I2C, SPI, and serial link wrappers +

o creating and running scripts on the pigpio daemon +

GPIO

ALL GPIO are identified by their Broadcom number. +

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. +

Usage

Include <pigpiod_if.h> in your source files. +

Assuming your source is in prog.c use the following command to build +

gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt


to run make sure the pigpio daemon is running +

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if


For examples see x_pigpiod_if.c within the pigpio archive file. +

Notes

All the functions which return an int return < 0 on error +

OVERVIEW

ESSENTIAL +
pigpio_start Connects to the pigpio daemon +
pigpio_stop Disconnects from the pigpio daemon +
BEGINNER +
set_mode Set a GPIO mode +
get_mode Get a GPIO mode +
set_pull_up_down Set/clear GPIO pull up/down resistor +
gpio_read Read a GPIO +
gpio_write Write a GPIO +
set_PWM_dutycycle Start/stop PWM pulses on a GPIO +
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +
set_servo_pulsewidth Start/stop servo pulses on a GPIO +
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO +
callback Create GPIO level change callback +
callback_ex Create GPIO level change callback +
callback_cancel Cancel a callback +
wait_for_edge Wait for GPIO level change +
INTERMEDIATE +
gpio_trigger Send a trigger pulse to a GPIO. +
set_watchdog Set a watchdog on a GPIO. +
set_PWM_range Configure PWM range for a GPIO +
get_PWM_range Get configured PWM range for a GPIO +
set_PWM_frequency Configure PWM frequency for a GPIO +
get_PWM_frequency Get configured PWM frequency for a GPIO +
read_bank_1 Read all GPIO in bank 1 +
read_bank_2 Read all GPIO in bank 2 +
clear_bank_1 Clear selected GPIO in bank 1 +
clear_bank_2 Clear selected GPIO in bank 2 +
set_bank_1 Set selected GPIO in bank 1 +
set_bank_2 Set selected GPIO in bank 2 +
start_thread Start a new thread +
stop_thread Stop a previously started thread +
ADVANCED +
get_PWM_real_range Get underlying PWM range for a GPIO +
notify_open Request a notification handle +
notify_begin Start notifications for selected GPIO +
notify_pause Pause notifications +
notify_close Close a notification +
bb_serial_read_open Opens a GPIO for bit bang serial reads +
bb_serial_read Reads bit bang serial data from a GPIO +
bb_serial_read_close Closes a GPIO for bit bang serial reads +
bb_serial_invert Invert serial logic (1 invert, 0 normal) +
hardware_clock Start hardware clock on supported GPIO +
hardware_PWM Start hardware PWM on supported GPIO +
set_glitch_filter Set a glitch filter on a GPIO +
set_noise_filter Set a noise filter on a GPIO +
SCRIPTS +
store_script Store a script +
run_script Run a stored script +
script_status Get script status and parameters +
stop_script Stop a running script +
delete_script Delete a stored script +
WAVES +
wave_clear Deletes all waveforms +
wave_add_new Starts a new waveform +
wave_add_generic Adds a series of pulses to the waveform +
wave_add_serial Adds serial data to the waveform +
wave_create Creates a waveform from added data +
wave_delete Deletes one or more waveforms +
wave_send_once Transmits a waveform once +
wave_send_repeat Transmits a waveform repeatedly +
wave_chain Transmits a chain of waveforms +
wave_tx_busy Checks to see if the waveform has ended +
wave_tx_stop Aborts the current waveform +
wave_get_micros Length in microseconds of the current waveform +
wave_get_high_micros Length of longest waveform so far +
wave_get_max_micros Absolute maximum allowed micros +
wave_get_pulses Length in pulses of the current waveform +
wave_get_high_pulses Length of longest waveform so far +
wave_get_max_pulses Absolute maximum allowed pulses +
wave_get_cbs Length in cbs of the current waveform +
wave_get_high_cbs Length of longest waveform so far +
wave_get_max_cbs Absolute maximum allowed cbs +
I2C +
i2c_open Opens an I2C device +
i2c_close Closes an I2C device +
i2c_write_quick smbus write quick +
i2c_write_byte smbus write byte +
i2c_read_byte smbus read byte +
i2c_write_byte_data smbus write byte data +
i2c_write_word_data smbus write word data +
i2c_read_byte_data smbus read byte data +
i2c_read_word_data smbus read word data +
i2c_process_call smbus process call +
i2c_write_block_data smbus write block data +
i2c_read_block_data smbus read block data +
i2c_block_process_call smbus block process call +
i2c_write_i2c_block_data smbus write I2C block data +
i2c_read_i2c_block_data smbus read I2C block data +
i2c_read_device Reads the raw I2C device +
i2c_write_device Writes the raw I2C device +
i2c_zip Performs multiple I2C transactions +
bb_i2c_open Opens GPIO for bit banging I2C +
bb_i2c_close Closes GPIO for bit banging I2C +
bb_i2c_zip Performs multiple bit banged I2C transactions +
SPI +
spi_open Opens a SPI device +
spi_close Closes a SPI device +
spi_read Reads bytes from a SPI device +
spi_write Writes bytes to a SPI device +
spi_xfer Transfers bytes with a SPI device +
SERIAL +
serial_open Opens a serial device +
serial_close Closes a serial device +
serial_write_byte Writes a byte to a serial device +
serial_read_byte Reads a byte from a serial device +
serial_write Writes bytes to a serial device +
serial_read Reads bytes from a serial device +
serial_data_available Returns number of bytes ready to be read +
CUSTOM +
custom_1 User custom function 1 +
custom_2 User custom function 2 +
UTILITIES +
get_current_tick Get current tick (microseconds) +
get_hardware_revision Get hardware revision +
get_pigpio_version Get the pigpio version +
pigpiod_if_version Get the pigpiod_if version +
pigpio_error Get a text description of an error code. +
time_sleep Sleeps for a float number of seconds +
time_time Float number of seconds since the epoch +

FUNCTIONS

double time_time(void)

+Return the current time in seconds since the Epoch. +

void time_sleep(double seconds)

+Delay execution for a given number of seconds. +

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

+Return a text description for an error code. +

errnum: the error code.

unsigned pigpiod_if_version(void)

+Return the pigpiod_if version. +

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

+Starts a new thread of execution with thread_func as the main routine. +

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. +

The function is passed the single argument userdata. +

The thread can be cancelled by passing the pointer to pthread_t to +stop_thread. +

void stop_thread(pthread_t *pth)

+Cancels the thread pointed at by pth. +

pth: the thread to be stopped.


No value is returned. +

The thread to be stopped should have been started with start_thread. +

int pigpio_start(char *addrStr, char *portStr)

+Connect to the pigpio daemon. Reserving command and +notification streams. +

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.

void pigpio_stop(void)

+Terminates the connection to the pigpio daemon and releases +resources used by the library. +

int set_mode(unsigned gpio, unsigned mode)

+Set the GPIO mode. +

gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, +or PI_NOT_PERMITTED. +

int get_mode(unsigned gpio)

+Get the GPIO mode. +

gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. +

int set_pull_up_down(unsigned gpio, unsigned pud)

+Set or clear the GPIO pull-up/down resistor. +

gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, +or PI_NOT_PERMITTED. +

int gpio_read(unsigned gpio)

+Read the GPIO level. +

gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. +

int gpio_write(unsigned gpio, unsigned level)

+Write the GPIO level. +

 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, +or PI_NOT_PERMITTED. +

Notes +

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

int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)

+Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. +

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


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, +or PI_NOT_PERMITTED. +Notes +

The set_PWM_range function may be used to change the +default range of 255. +

int get_PWM_dutycycle(unsigned user_gpio)

+Return the PWM dutycycle in use on a GPIO. +

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. +

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

If a hardware clock is active on the GPIO the reported dutycycle +will be 500000 (500k) out of 1000000 (1M). +

If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). +

int set_PWM_range(unsigned user_gpio, unsigned range)

+Set the range of PWM values to be used on the GPIO. +

user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, +or PI_NOT_PERMITTED. +

Notes +

If PWM is currently active on the GPIO its dutycycle will be +scaled to reflect the new range. +

The real range, the number of steps between fully off and fully on +for each of the 18 available GPIO frequencies is +

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


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

int get_PWM_range(unsigned user_gpio)

+Get the range of PWM values being used on the GPIO. +

user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

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

int get_PWM_real_range(unsigned user_gpio)

+Get the real underlying range of PWM values being used on the GPIO. +

user_gpio: 0-31.


Returns the real range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

int set_PWM_frequency(unsigned user_gpio, unsigned frequency)

+Set the frequency (in Hz) of the PWM to be used on the GPIO. +

user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PERMITTED. +

If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. +

Each GPIO can be independently set to one of 18 different +PWM frequencies. +

The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. +

The frequencies for each sample rate are: +

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(unsigned user_gpio)

+Get the frequency of PWM being used on the GPIO. +

user_gpio: 0-31.


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

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

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

Returns the frequency (in hertz) used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)

+Start (500-2500) or stop (0) servo pulses on the GPIO. +

 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or +PI_NOT_PERMITTED. +

The selected pulsewidth will continue to be transmitted until +changed by a subsequent call to set_servo_pulsewidth. +

The pulsewidths supported by servos varies and should probably be +determined by experiment. A value of 1500 should always be safe and +represents the mid-point of rotation. +

You can DAMAGE a servo if you command it to move beyond its limits. +

OTHER UPDATE RATES: +

This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. +

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. +

Then set the PWM range using set_PWM_range to 1E6/Hz. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. +

E.g. If you want to update a servo connected to GPIO 25 at 400Hz +

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, +e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
+

int get_servo_pulsewidth(unsigned user_gpio)

+Return the servo pulsewidth in use on a GPIO. +

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. +

int notify_open(void)

+Get a free notification handle. +

Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. +

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

Pipes are only accessible from the local machine so this function +serves no purpose if you are using the library from a remote machine. +The in-built (socket) notifications provided by callback +should be used instead. +

Notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). +E.g. if the function returns 15 then the notifications must be +read from /dev/pigpio15. +

int notify_begin(unsigned handle, uint32_t bits)

+Start notifications on a previously opened handle. +

handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

The notification sends state changes for each GPIO whose +corresponding bit in bits is set. +

Each notification occupies 12 bytes in the fifo as follows: +

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. +

PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. +

PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. +

tick: the number of microseconds since system boot. It wraps around +after 1h12m. +

level: indicates the level of each GPIO. If bit 1<<x is set then +GPIO x is high. +

int notify_pause(unsigned handle)

+Pause notifications on a previously opened handle. +

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Notifications for the handle are suspended until +notify_begin is called again. +

int notify_close(unsigned handle)

+Stop notifications on a previously opened handle and +release the handle for reuse. +

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int set_watchdog(unsigned user_gpio, unsigned timeout)

+Sets a watchdog for a GPIO. +

user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO +or PI_BAD_WDOG_TIMEOUT. +

The watchdog is nominally in milliseconds. +

Only one watchdog may be registered per GPIO. +

The watchdog may be cancelled by setting timeout to 0. +

Once a watchdog has been started callbacks for the GPIO will be +triggered every timeout interval after the last GPIO activity. +

The callback will receive the special level PI_TIMEOUT. +

int set_glitch_filter(unsigned user_gpio, unsigned steady)

+Sets a glitch filter on a GPIO. +

Level changes on the GPIO are not reported unless the level +has been stable for at least steady microseconds. The +level is then reported. Level changes of less than steady +microseconds are ignored. +

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback, callback_ex and wait_for_edge. +

It does not affect levels read by gpio_read, +read_bank_1, or read_bank_2. +Each (stable) edge will be timestamped steady microseconds +after it was first detected. +

int set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active)

+Sets a noise filter on a GPIO. +

Level changes on the GPIO are ignored until a level which has +been stable for steady microseconds is detected. Level changes +on the GPIO are then reported for active microseconds after +which the process repeats. +

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback, callback_ex and wait_for_edge. +

It does not affect levels read by gpio_read, +read_bank_1, or read_bank_2. +

Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

uint32_t read_bank_1(void)

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

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

uint32_t read_bank_2(void)

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

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

int clear_bank_1(uint32_t bits)

+Clears GPIO 0-31 if the corresponding bit in bits is set. +

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int clear_bank_2(uint32_t bits)

+Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int set_bank_1(uint32_t bits)

+Sets GPIO 0-31 if the corresponding bit in bits is set. +

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int set_bank_2(uint32_t bits)

+Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int hardware_clock(unsigned gpio, unsigned clkfreq)

+Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. +

     gpio: see description
frequency: 0 (off) or 4689-250000000 (250M)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. +

The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. +

The GPIO must be one of the following. +

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely +crash the Pi. The password is given by or'ing 0x5A000000 with the +GPIO number. +

int hardware_PWM(unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

+Starts hardware PWM on a GPIO at the specified frequency and dutycycle. +Frequencies above 30MHz are unlikely to work. +

NOTE: Any waveform started by wave_send_once, wave_send_repeat, +or wave_chain will be cancelled. +

This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). +

   gpio: see descripton
PWMfreq: 0 (off) or 1-125000000 (125M)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, +or PI_HPWM_ILLEGAL. +

The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. +

The GPIO must be one of the following. +

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only

uint32_t get_current_tick(void)

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

uint32_t get_hardware_revision(void)

+Get the Pi's hardware revision number. +

The hardware revision is the last few characters on the Revision line +of /proc/cpuinfo. +

If the hardware revision can not be found or is not a valid +hexadecimal number the function returns 0. +

The revision number can be used to determine the assignment of GPIO +to pins (see gpio). +

There are at least three types of board. +

Type 1 boards have hardware revision numbers of 2 and 3. +

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. +

Type 3 boards have hardware revision numbers of 16 or greater. +

uint32_t get_pigpio_version(void)

+Returns the pigpio version. +

int wave_clear(void)

+This function clears all waveforms and any data added by calls to the +wave_add_* functions. +

Returns 0 if OK. +

int wave_add_new(void)

+This function starts a new empty waveform. You wouldn't normally need +to call this function as it is automatically called after a waveform is +created with the wave_create function. +

Returns 0 if OK. +

int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)

+This function adds a number of pulses to the current waveform. +

numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. +

The pulses are interleaved in time order within the existing waveform +(if any). +

Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist solely of a delay. +

int wave_add_serial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

+This function adds a waveform representing serial data to the +existing waveform (if any). The serial data starts offset +microseconds from the start of the waveform. +

user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. +

NOTES: +

The serial data is formatted as one start bit, data_bits data bits, +and stop_bits/2 stop bits. +

It is legal to add serial data streams with different baud rates to +the same waveform. +

numBytes is the number of bytes of data in str. +

The bytes required for each character depend upon data_bits. +

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

int wave_create(void)

+This function creates a waveform from the data provided by the prior +calls to the wave_add_* functions. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

The data provided by the wave_add_* functions is consumed by this +function. +

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

Normal usage would be +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create to create the waveform and get a unique id +

Repeat steps 2 and 3 as needed. +

Step 4. wave_send_* with the id of the waveform to transmit. +

A waveform comprises one or more pulses. Each pulse consists of a +gpioPulse_t structure. +

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify +

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +

int wave_delete(unsigned wave_id)

+This function deletes the waveform with id wave_id. +

wave_id: >=0, as returned by wave_create.


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

The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. +

- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. +

- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). +

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. +

int wave_send_once(unsigned wave_id)

+This function transmits the waveform with id wave_id. The waveform +is sent once. +

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

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_send_repeat(unsigned wave_id)

+This function transmits the waveform with id wave_id. The waveform +cycles until cancelled (either by the sending of a new waveform or +by wave_tx_stop). +

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

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_chain(char *buf, unsigned bufSize)

+This function transmits a chain of waveforms. +

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

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

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. +

Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. +

A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. +

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (pigpio_start(0, 0)<0) return -1;

   set_mode(GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create();
   }

   wave_chain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(wid[i]);

   pigpio_stop();
}

int wave_tx_busy(void)

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

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

int wave_tx_stop(void)

+This function stops the transmission of the current waveform. +

Returns 0 if OK. +

This function is intended to stop a waveform started with the repeat mode. +

int wave_get_micros(void)

+This function returns the length in microseconds of the current +waveform. +

int wave_get_high_micros(void)

+This function returns the length in microseconds of the longest waveform +created since the pigpio daemon was started. +

int wave_get_max_micros(void)

+This function returns the maximum possible size of a waveform in
+microseconds. +

int wave_get_pulses(void)

+This function returns the length in pulses of the current waveform. +

int wave_get_high_pulses(void)

+This function returns the length in pulses of the longest waveform +created since the pigpio daemon was started. +

int wave_get_max_pulses(void)

+This function returns the maximum possible size of a waveform in pulses. +

int wave_get_cbs(void)

+This function returns the length in DMA control blocks of the current +waveform. +

int wave_get_high_cbs(void)

+This function returns the length in DMA control blocks of the longest +waveform created since the pigpio daemon was started. +

int wave_get_max_cbs(void)

+This function returns the maximum possible size of a waveform in DMA +control blocks. +

int gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

+This function sends a trigger pulse to a GPIO. The GPIO is set to +level for pulseLen microseconds and then reset to not level. +

user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, +PI_BAD_PULSELEN, or PI_NOT_PERMITTED. +

int store_script(char *script)

+This function stores a script for later execution. +

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. +

script: the text of the script.


The function returns a script id if the script is valid, +otherwise PI_BAD_SCRIPT. +

int run_script(unsigned script_id, unsigned numPar, uint32_t *param)

+This function runs a stored script. +

script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int script_status(unsigned script_id, uint32_t *param)

+This function returns the run status of a stored script as well +as the current values of parameters 0 to 9. +

script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. +

The run status may be +

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. +

int stop_script(unsigned script_id)

+This function stops a running script. +

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int delete_script(unsigned script_id)

+This function deletes a stored script. +

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)

+This function opens a GPIO for bit bang reading of serial data. +

user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, +or PI_GPIO_IN_USE. +

The serial data is returned in a cyclic buffer and is read using +bb_serial_read. +

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

int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)

+This function copies up to bufSize bytes of data read from the +bit bang serial cyclic buffer to the buffer starting at buf. +

user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. +

The bytes returned for each character depend upon the number of +data bits data_bits specified in the bb_serial_read_open command. +

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

int bb_serial_read_close(unsigned user_gpio)

+This function closes a GPIO for bit bang reading of serial data. +

user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. +

int bb_serial_invert(unsigned user_gpio, unsigned invert)

+This function inverts serial logic for big bang serial reads. +

user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. +

int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

+This returns a handle for the device at address i2c_addr on bus i2c_bus. +

  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. +

Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. +

For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. +

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.

Addr  (7 bits): I2C 7 bit address.
Comm  (8 bits): Command byte, a data byte which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A data byte containing the length of a block operation.

[..]: Data sent by the device.

int i2c_close(unsigned handle)

+This closes the I2C device associated with the handle. +

handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int i2c_write_quick(unsigned handle, unsigned bit)

+This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. +

handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Quick command. SMBus 2.0 5.5.1 +S Addr Rd/Wr [A] P

int i2c_write_byte(unsigned handle, unsigned bVal)

+This sends a single byte to the device associated with handle. +

handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Send byte. SMBus 2.0 5.5.2 +S Addr Wr [A] Data [A] P

int i2c_read_byte(unsigned handle)

+This reads a single byte from the device associated with handle. +

handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. +

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

int i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)

+This writes a single byte to the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write byte. SMBus 2.0 5.5.4 +S Addr Wr [A] Comm [A] Data [A] P

int i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)

+This writes a single 16 bit word to the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write word. SMBus 2.0 5.5.4 +S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P

int i2c_read_byte_data(unsigned handle, unsigned i2c_reg)

+This reads a single byte from the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read byte. SMBus 2.0 5.5.5 +S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(unsigned handle, unsigned i2c_reg)

+This reads a single 16 bit word from the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read word. SMBus 2.0 5.5.5 +S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)

+This writes 16 bits of data to the specified register of the device +associated with handle and and reads 16 bits of data in return. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Process call. SMBus 2.0 5.5.6 +S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes up to 32 bytes to the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Block write. SMBus 2.0 5.5.7 +S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)

+This reads a block of up to 32 bytes from the specified register of +the device associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. +

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Block read. SMBus 2.0 5.5.7 +S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

int i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

The smbus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. +

Block write-block read. SMBus 2.0 5.5.8 +S Addr Wr [A] Comm [A] Count [A] Data [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

int i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes 1 to 32 bytes to the specified register of the device +associated with handle. +

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_device(unsigned handle, char *buf, unsigned count)

+This reads count bytes from the raw device into buf. +

handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. +

int i2c_write_device(unsigned handle, char *buf, unsigned count)

+This writes count bytes from buf to the raw device. +

handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

int i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)

+This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. +

Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. +

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

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. +

NOTE: +

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. +

int bb_i2c_close(unsigned SDA)

+This function stops bit banging I2C on a pair of GPIO previously +opened with bb_i2c_open. +

SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +

int bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)

+This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. +

spi_flags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. +

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. +

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 spi_read, spi_write, and spi_xfer functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. +

For bits 1-8 there will be one byte per word.
+For bits 9-16 there will be two bytes per word.
+For bits 17-32 there will be four bytes per word. +

Multi-byte transfers are made in least significant byte first order. +

E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. +

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

int spi_close(unsigned handle)

+This functions closes the SPI device identified by the handle. +

handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int spi_read(unsigned handle, char *buf, unsigned count)

+This function reads count bytes of data from the SPI +device associated with the handle. +

handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spi_write(unsigned handle, char *buf, unsigned count)

+This function writes count bytes of data from buf to the SPI +device associated with the handle. +

handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

+This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. +

handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)

+This function opens a serial device at a specified baud rate +with specified flags. The device name must start with +/dev/tty or /dev/serial. +

  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. +

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

No flags are currently defined. This parameter should be set to zero. +

int serial_close(unsigned handle)

+This function closes the serial device associated with handle. +

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int serial_write_byte(unsigned handle, unsigned bVal)

+This function writes bVal to the serial port associated with handle. +

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serial_read_byte(unsigned handle)

+This function reads a byte from the serial port associated with handle. +

handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. +

If no data is ready PI_SER_READ_NO_DATA is returned. +

int serial_write(unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the serial port +associated with handle. +

handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serial_read(unsigned handle, char *buf, unsigned count)

+This function reads up to count bytes from the the serial port +associated with handle and writes them to buf. +

handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. +

If no data is ready zero is returned. +

int serial_data_available(unsigned handle)

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

handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. +

int custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

+This function is available for user customisation. +

It returns a single integer value. +

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. +

int custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

+This function is available for user customisation. +

It differs from custom_1 in that it returns an array of bytes +rather than just an integer. +

The return value is an integer indicating the number of returned bytes. +  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. +

Note, the number of returned bytes will be retMax or less. +

int callback(unsigned user_gpio, unsigned edge, CBFunc_t f)

+This function initialises a new callback. +

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the GPIO, edge, and tick, whenever the +GPIO has the identified edge. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

int callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

+This function initialises a new callback. +

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the GPIO, edge, tick, and user, whenever +the GPIO has the identified edge. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

+This function cancels a callback identified by its id. +

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. +

int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)

+This function waits for edge on the GPIO for up to timeout +seconds. +

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns 1 if the edge occurred, otherwise 0. +

The function returns when the edge occurs or after the timeout. +

PARAMETERS

active: 0-1000000

+The number of microseconds level changes are reported for once +a noise filter has been triggered (by steady microseconds of +a stable level). +

*addrStr

+A string specifying the host or IP address of the Pi running +the pigpio daemon. It may be NULL in which case localhost +is used unless overridden by the PIGPIO_ADDR environment +variable. +

arg1

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

arg2

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

argc

+The count of bytes passed to a user customised function. +

*argx

+A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. +

baud

+The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. +

bit

+A value of 0 or 1. +

bits

+A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. +

A convenient way to set bit n is to or in (1<<n). +

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). +

*buf

+A buffer to hold data being sent or being received. +

bufSize

+The size in bytes of a buffer. +

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

+An 8-bit byte value. +

callback_id

+A >=0, as returned by a call to callback or callback_ex. This is +passed to callback_cancel to cancel the callback. +

CBFunc_t

+typedef void (*CBFunc_t)
   (unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

+typedef void (*CBFuncEx_t)
   (unsigned user_gpio, unsigned level, uint32_t tick, void * user);

char

+A single character, an 8 bit quantity able to store 0-255. +

clkfreq: 4689-250000000 (250M)

+The hardware clock frequency. +

count

+The number of bytes to be transferred in an I2C, SPI, or Serial +command. +

data_bits: 1-32

+The number of data bits in each character of serial data. +

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

+A floating point number. +

dutycycle: 0-range

+A number representing the ratio of on time to off time for PWM. +

The number may vary between 0 and range (default 255) where +0 is off and range is fully on. +

edge

+Used to identify a GPIO level transition of interest. A rising edge is +a level change from 0 to 1. A falling edge is a level change from 1 to 0. +

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

+A negative number indicating a function call failed and the nature +of the error. +

f

+A function. +

frequency: >=0

+The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. +

gpio

+A Broadcom numbered GPIO, in the range 0-53. +

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

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

gpioPulse_t

+typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

+typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

+A number referencing an object opened by one of i2c_open, notify_open, +serial_open, and spi_open. +

i2c_addr: 0-0x7F

+The address of a device on the I2C bus. +

i2c_bus: >=0

+An I2C bus number. +

i2c_flags: 0

+Flags which modify an I2C open command. None are currently defined. +

i2c_reg: 0-255

+A register of an I2C device. +

*inBuf

+A buffer used to pass data to a function. +

inLen

+The number of bytes of data in a buffer. +

int

+A whole number, negative or positive. +

invert

+A flag used to set normal or inverted bit bang serial data level logic. +

level

+The level of a GPIO. Low or High. +

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See set_watchdog. +

PI_TIMEOUT 2

mode: 0-7

+The operational mode of a GPIO, normally INPUT or OUTPUT. +

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2

numBytes

+The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. +

numPar: 0-10

+The number of parameters passed to a script. +

numPulses

+The number of pulses to be added to a waveform. +

offset

+The associated data starts this number of microseconds from the start of +the waveform. +

*outBuf

+A buffer used to return data from a function. +

outLen

+The size in bytes of an output buffer. +

*param

+An array of script parameters. +

*portStr

+A string specifying the port address used by the Pi running +the pigpio daemon. It may be NULL in which case "8888" +is used unless overridden by the PIGPIO_PORT environment +variable. +

*pth

+A thread identifier, returned by start_thread. +

pthread_t

+A thread identifier. +

pud: 0-2

+The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. +PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

+1-100, the length of a trigger pulse in microseconds. +

*pulses

+An array of pulses to be added to a waveform. +

pulsewidth: 0, 500-2500

+PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

+The hardware PWM dutycycle. +

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125000000 (125M)

+The hardware PWM frequency. +

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000

range: 25-40000

+The permissible dutycycle values are 0-range. +PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

+A buffer to hold a number of bytes returned to a used customised function, +

retMax

+The maximum number of bytes a user customised function should return. +

*rxBuf

+A pointer to a buffer to receive data. +

SCL

+The user GPIO to use for the clock when bit banging I2C. +

*script

+A pointer to the text of a script. +

script_id

+An id of a stored script as returned by store_script. +

SDA

+The user GPIO to use for data when bit banging I2C. +

seconds

+The number of seconds. +

ser_flags

+Flags which modify a serial open command. None are currently defined. +

*ser_tty

+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. +

size_t

+A standard type used to indicate the size of an object in bytes. +

spi_channel

+A SPI channel, 0-2. +

spi_flags

+See spi_open. +

steady: 0-300000

+The number of microseconds level changes must be stable for +before reporting the level changed (set_glitch_filter) or triggering +the active part of a noise filter (set_noise_filter). +

stop_bits: 2-8

+The number of (half) stop bits to be used when adding serial data +to a waveform. +

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

+ An array of characters. +

thread_func

+A function of type gpioThreadFunc_t used as the main function of a +thread. +

timeout

+A GPIO watchdog timeout in milliseconds. +PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

+An array of bytes to transmit. +

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

+A 32-bit unsigned value. +

unsigned

+A whole number >= 0. +

user_gpio

+0-31, a Broadcom numbered GPIO. +

See gpio. +

*userdata

+A pointer to arbitrary user data. This may be used to identify the instance. +

void

+Denoting no parameter is required +

wave_add_*

+One of wave_add_new, wave_add_generic, wave_add_serial. +

wave_id

+A number representing a waveform created by wave_create. +

wave_send_*

+One of wave_send_once, wave_send_repeat. +

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

+A 16-bit word value. +

pigpiod_if Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
} pigifError_t;

\ No newline at end of file diff --git a/DOC/tmp/body/pdif2.body b/DOC/tmp/body/pdif2.body new file mode 100644 index 0000000..ecebd36 --- /dev/null +++ b/DOC/tmp/body/pdif2.body @@ -0,0 +1,1460 @@ +

pigpiod_if2 is a C library for the Raspberry which allows control +of the GPIO via the socket interface to the pigpio daemon.
+

Features

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o callbacks when any of GPIO 0-31 change state +

o callbacks at timed intervals +

o reading/writing all of the GPIO in a bank as one operation +

o individually setting GPIO modes, reading and writing +

o notifications when any of GPIO 0-31 change state +

o the construction of output waveforms with microsecond timing +

o rudimentary permission control over GPIO +

o a simple interface to start and stop new threads +

o I2C, SPI, and serial link wrappers +

o creating and running scripts on the pigpio daemon +

GPIO

ALL GPIO are identified by their Broadcom number. +

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. +

Usage

Include <pigpiod_if2.h> in your source files. +

Assuming your source is in prog.c use the following command to build +

gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt


to run make sure the pigpio daemon is running +

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if2


For examples see x_pigpiod_if2.c within the pigpio archive file. +

Notes

All the functions which return an int return < 0 on error +

OVERVIEW

ESSENTIAL +
pigpio_start Connects to a pigpio daemon +
pigpio_stop Disconnects from a pigpio daemon +
BASIC +
set_mode Set a GPIO mode +
get_mode Get a GPIO mode +
set_pull_up_down Set/clear GPIO pull up/down resistor +
gpio_read Read a GPIO +
gpio_write Write a GPIO +
PWM (overrides servo commands on same GPIO) +
set_PWM_dutycycle Start/stop PWM pulses on a GPIO +
set_PWM_frequency Configure PWM frequency for a GPIO +
set_PWM_range Configure PWM range for a GPIO +
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO +
get_PWM_frequency Get configured PWM frequency for a GPIO +
get_PWM_range Get configured PWM range for a GPIO +
get_PWM_real_range Get underlying PWM range for a GPIO +
Servo (overrides PWM commands on same GPIO) +
set_servo_pulsewidth Start/stop servo pulses on a GPIO +
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO +
INTERMEDIATE +
gpio_trigger Send a trigger pulse to a GPIO. +
set_watchdog Set a watchdog on a GPIO. +
read_bank_1 Read all GPIO in bank 1 +
read_bank_2 Read all GPIO in bank 2 +
clear_bank_1 Clear selected GPIO in bank 1 +
clear_bank_2 Clear selected GPIO in bank 2 +
set_bank_1 Set selected GPIO in bank 1 +
set_bank_2 Set selected GPIO in bank 2 +
callback Create GPIO level change callback +
callback_ex Create GPIO level change callback, extended +
callback_cancel Cancel a callback +
wait_for_edge Wait for GPIO level change +
start_thread Start a new thread +
stop_thread Stop a previously started thread +
ADVANCED +
notify_open Request a notification handle +
notify_begin Start notifications for selected GPIO +
notify_pause Pause notifications +
notify_close Close a notification +
hardware_clock Start hardware clock on supported GPIO +
hardware_PWM Start hardware PWM on supported GPIO +
set_glitch_filter Set a glitch filter on a GPIO +
set_noise_filter Set a noise filter on a GPIO +
set_pad_strength Sets a pads drive strength +
get_pad_strength Gets a pads drive strength +
shell_ Executes a shell command +
Custom +
custom_1 User custom function 1 +
custom_2 User custom function 2 +
Events +
event_callback Sets a callback for an event +
event_callback_ex Sets a callback for an event, extended +
event_callback_cancel Cancel an event callback +
event_trigger Triggers an event +
wait_for_event Wait for an event +
Scripts +
store_script Store a script +
run_script Run a stored script +
update_script Set a scripts parameters +
script_status Get script status and parameters +
stop_script Stop a running script +
delete_script Delete a stored script +
I2C +
i2c_open Opens an I2C device +
i2c_close Closes an I2C device +
i2c_write_quick smbus write quick +
i2c_read_byte smbus read byte +
i2c_write_byte smbus write byte +
i2c_read_byte_data smbus read byte data +
i2c_write_byte_data smbus write byte data +
i2c_read_word_data smbus read word data +
i2c_write_word_data smbus write word data +
i2c_read_block_data smbus read block data +
i2c_write_block_data smbus write block data +
i2c_read_i2c_block_data smbus read I2C block data +
i2c_write_i2c_block_data smbus write I2C block data +
i2c_read_device Reads the raw I2C device +
i2c_write_device Writes the raw I2C device +
i2c_process_call smbus process call +
i2c_block_process_call smbus block process call +
i2c_zip Performs multiple I2C transactions +
I2C BIT BANG +
bb_i2c_open Opens GPIO for bit banging I2C +
bb_i2c_close Closes GPIO for bit banging I2C +
bb_i2c_zip Performs bit banged I2C transactions +
I2C/SPI SLAVE +
bsc_xfer I2C/SPI as slave transfer +
bsc_i2c I2C as slave transfer +
SERIAL +
serial_open Opens a serial device +
serial_close Closes a serial device +
serial_read_byte Reads a byte from a serial device +
serial_write_byte Writes a byte to a serial device +
serial_read Reads bytes from a serial device +
serial_write Writes bytes to a serial device +
serial_data_available Returns number of bytes ready to be read +
SERIAL BIT BANG (read only) +
bb_serial_read_open Opens a GPIO for bit bang serial reads +
bb_serial_read_close Closes a GPIO for bit bang serial reads +
bb_serial_invert Invert serial logic (1 invert, 0 normal) +
bb_serial_read Reads bit bang serial data from a GPIO +
SPI +
spi_open Opens a SPI device +
spi_close Closes a SPI device +
spi_read Reads bytes from a SPI device +
spi_write Writes bytes to a SPI device +
spi_xfer Transfers bytes with a SPI device +
SPI BIT BANG +
bb_spi_open Opens GPIO for bit banging SPI +
bb_spi_close Closes GPIO for bit banging SPI +
bb_spi_xfer Transfers bytes with bit banging SPI +
FILES +
file_open Opens a file +
file_close Closes a file +
file_read Reads bytes from a file +
file_write Writes bytes to a file +
file_seek Seeks to a position within a file +
file_list List files which match a pattern +
WAVES +
wave_clear Deletes all waveforms +
wave_add_new Starts a new waveform +
wave_add_generic Adds a series of pulses to the waveform +
wave_add_serial Adds serial data to the waveform +
wave_create Creates a waveform from added data +
wave_create_and_pad Creates a waveform of fixed size from added data +
wave_delete Deletes one or more waveforms +
wave_send_once Transmits a waveform once +
wave_send_repeat Transmits a waveform repeatedly +
wave_send_using_mode Transmits a waveform in the chosen mode +
wave_chain Transmits a chain of waveforms +
wave_tx_at Returns the current transmitting waveform +
wave_tx_busy Checks to see if the waveform has ended +
wave_tx_stop Aborts the current waveform +
wave_get_cbs Length in cbs of the current waveform +
wave_get_high_cbs Length of longest waveform so far +
wave_get_max_cbs Absolute maximum allowed cbs +
wave_get_micros Length in micros of the current waveform +
wave_get_high_micros Length of longest waveform so far +
wave_get_max_micros Absolute maximum allowed micros +
wave_get_pulses Length in pulses of the current waveform +
wave_get_high_pulses Length of longest waveform so far +
wave_get_max_pulses Absolute maximum allowed pulses +
UTILITIES +
get_current_tick Get current tick (microseconds) +
get_hardware_revision Get hardware revision +
get_pigpio_version Get the pigpio version +
pigpiod_if_version Get the pigpiod_if2 version +
pigpio_error Get a text description of an error code. +
time_sleep Sleeps for a float number of seconds +
time_time Float number of seconds since the epoch +

FUNCTIONS

double time_time(void)

+Return the current time in seconds since the Epoch. +

void time_sleep(double seconds)

+Delay execution for a given number of seconds. +

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

+Return a text description for an error code. +

errnum: the error code.

unsigned pigpiod_if_version(void)

+Return the pigpiod_if2 version. +

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

+Starts a new thread of execution with thread_func as the main routine. +

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. +

The function is passed the single argument userdata. +

The thread can be cancelled by passing the pointer to pthread_t to +stop_thread. +

void stop_thread(pthread_t *pth)

+Cancels the thread pointed at by pth. +

pth: the thread to be stopped.


No value is returned. +

The thread to be stopped should have been started with start_thread. +

int pigpio_start(char *addrStr, char *portStr)

+Connect to the pigpio daemon. Reserving command and +notification streams. +

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.


Returns an integer value greater than or equal to zero if OK. +

This value is passed to the GPIO routines to specify the Pi +to be operated on. +

void pigpio_stop(int pi)

+Terminates the connection to a pigpio daemon and releases +resources used by the library. +

pi: >=0 (as returned by pigpio_start).

int set_mode(int pi, unsigned gpio, unsigned mode)

+Set the GPIO mode. +

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, +or PI_NOT_PERMITTED. +

int get_mode(int pi, unsigned gpio)

+Get the GPIO mode. +

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. +

int set_pull_up_down(int pi, unsigned gpio, unsigned pud)

+Set or clear the GPIO pull-up/down resistor. +

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, +or PI_NOT_PERMITTED. +

int gpio_read(int pi, unsigned gpio)

+Read the GPIO level. +

  pi: >=0 (as returned by pigpio_start).
gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. +

int gpio_write(int pi, unsigned gpio, unsigned level)

+Write the GPIO level. +

   pi: >=0 (as returned by pigpio_start).
 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, +or PI_NOT_PERMITTED. +

Notes +

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

int set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)

+Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, +or PI_NOT_PERMITTED. +Notes +

The set_PWM_range function may be used to change the +default range of 255. +

int get_PWM_dutycycle(int pi, unsigned user_gpio)

+Return the PWM dutycycle in use on a GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. +

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

If a hardware clock is active on the GPIO the reported dutycycle +will be 500000 (500k) out of 1000000 (1M). +

If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). +

int set_PWM_range(int pi, unsigned user_gpio, unsigned range)

+Set the range of PWM values to be used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, +or PI_NOT_PERMITTED. +

Notes +

If PWM is currently active on the GPIO its dutycycle will be +scaled to reflect the new range. +

The real range, the number of steps between fully off and fully on +for each of the 18 available GPIO frequencies is +

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


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

int get_PWM_range(int pi, unsigned user_gpio)

+Get the range of PWM values being used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

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

int get_PWM_real_range(int pi, unsigned user_gpio)

+Get the real underlying range of PWM values being used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the real range used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

int set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)

+Set the frequency (in Hz) of the PWM to be used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PERMITTED. +

If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. +

Each GPIO can be independently set to one of 18 different +PWM frequencies. +

The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. +

The frequencies for each sample rate are: +

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(int pi, unsigned user_gpio)

+Get the frequency of PWM being used on the GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


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

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

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

Returns the frequency (in hertz) used for the GPIO if OK, +otherwise PI_BAD_USER_GPIO. +

int set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)

+Start (500-2500) or stop (0) servo pulses on the GPIO. +

        pi: >=0 (as returned by pigpio_start).
 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or +PI_NOT_PERMITTED. +

The selected pulsewidth will continue to be transmitted until +changed by a subsequent call to set_servo_pulsewidth. +

The pulsewidths supported by servos varies and should probably be +determined by experiment. A value of 1500 should always be safe and +represents the mid-point of rotation. +

You can DAMAGE a servo if you command it to move beyond its limits. +

OTHER UPDATE RATES: +

This function updates servos at 50Hz. If you wish to use a different +update frequency you will have to use the PWM functions. +

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. +

Then set the PWM range using set_PWM_range to 1E6/Hz. +Doing this allows you to use units of microseconds when setting +the servo pulsewidth. +

E.g. If you want to update a servo connected to GPIO 25 at 400Hz +

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, +e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
+

int get_servo_pulsewidth(int pi, unsigned user_gpio)

+Return the servo pulsewidth in use on a GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. +

int notify_open(int pi)

+Get a free notification handle. +

pi: >=0 (as returned by pigpio_start).


Returns a handle greater than or equal to zero if OK, +otherwise PI_NO_HANDLE. +

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

Pipes are only accessible from the local machine so this function +serves no purpose if you are using the library from a remote machine. +The in-built (socket) notifications provided by callback +should be used instead. +

Notifications for handle x will be available at the pipe +named /dev/pigpiox (where x is the handle number). +E.g. if the function returns 15 then the notifications must be +read from /dev/pigpio15. +

int notify_begin(int pi, unsigned handle, uint32_t bits)

+Start notifications on a previously opened handle. +

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

The notification sends state changes for each GPIO whose +corresponding bit in bits is set. +

Each notification occupies 12 bytes in the fifo as follows: +

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, +PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. +

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. +

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. +

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags +indicate an event which has been triggered. +

tick: the number of microseconds since system boot. It wraps around +after 1h12m. +

level: indicates the level of each GPIO. If bit 1<<x is set then +GPIO x is high. +

int notify_pause(int pi, unsigned handle)

+Pause notifications on a previously opened handle. +

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Notifications for the handle are suspended until +notify_begin is called again. +

int notify_close(int pi, unsigned handle)

+Stop notifications on a previously opened handle and +release the handle for reuse. +

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int set_watchdog(int pi, unsigned user_gpio, unsigned timeout)

+Sets a watchdog for a GPIO. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO +or PI_BAD_WDOG_TIMEOUT. +

The watchdog is nominally in milliseconds. +

Only one watchdog may be registered per GPIO. +

The watchdog may be cancelled by setting timeout to 0. +

Once a watchdog has been started callbacks for the GPIO will be +triggered every timeout interval after the last GPIO activity. +

The callback will receive the special level PI_TIMEOUT. +

int set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)

+Sets a glitch filter on a GPIO. +

Level changes on the GPIO are not reported unless the level +has been stable for at least steady microseconds. The +level is then reported. Level changes of less than +steady microseconds are ignored. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback, callback_ex and wait_for_edge. +

It does not affect levels read by gpio_read, +read_bank_1, or read_bank_2. +

Each (stable) edge will be timestamped steady microseconds +after it was first detected. +

int set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)

+Sets a noise filter on a GPIO. +

Level changes on the GPIO are ignored until a level which has +been stable for steady microseconds is detected. Level changes +on the GPIO are then reported for active microseconds after +which the process repeats. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback, callback_ex and wait_for_edge. +

It does not affect levels read by gpio_read, +read_bank_1, or read_bank_2. +

Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

uint32_t read_bank_1(int pi)

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

pi: >=0 (as returned by pigpio_start).


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

uint32_t read_bank_2(int pi)

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

pi: >=0 (as returned by pigpio_start).


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

int clear_bank_1(int pi, uint32_t bits)

+Clears GPIO 0-31 if the corresponding bit in bits is set. +

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int clear_bank_2(int pi, uint32_t bits)

+Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int set_bank_1(int pi, uint32_t bits)

+Sets GPIO 0-31 if the corresponding bit in bits is set. +

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int set_bank_2(int pi, uint32_t bits)

+Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. +

A status of PI_SOME_PERMITTED indicates that the user is not +allowed to write to one or more of the GPIO. +

int hardware_clock(int pi, unsigned gpio, unsigned clkfreq)

+Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. +

       pi: >=0 (as returned by pigpio_start).
     gpio: see description
frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. +

The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. +

The GPIO must be one of the following. +

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely +crash the Pi. The password is given by or'ing 0x5A000000 with the +GPIO number. +

int hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

+Starts hardware PWM on a GPIO at the specified frequency and dutycycle. +Frequencies above 30MHz are unlikely to work. +

NOTE: Any waveform started by wave_send_* or wave_chain +will be cancelled. +

This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). +

     pi: >=0 (as returned by pigpio_start).
   gpio: see descripton
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, +or PI_HPWM_ILLEGAL. +

The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. +

The GPIO must be one of the following. +

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). +

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

There will only be a million steps for a PWMfreq of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. PWMduty is +automatically scaled to take this into account. +

uint32_t get_current_tick(int pi)

+Gets the current system tick. +

pi: >=0 (as returned by pigpio_start).


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

uint32_t get_hardware_revision(int pi)

+Get the Pi's hardware revision number. +

pi: >=0 (as returned by pigpio_start).


The hardware revision is the last few characters on the Revision line +of /proc/cpuinfo. +

If the hardware revision can not be found or is not a valid +hexadecimal number the function returns 0. +

The revision number can be used to determine the assignment of GPIO +to pins (see gpio). +

There are at least three types of board. +

Type 1 boards have hardware revision numbers of 2 and 3. +

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. +

Type 3 boards have hardware revision numbers of 16 or greater. +

uint32_t get_pigpio_version(int pi)

+Returns the pigpio version. +

pi: >=0 (as returned by pigpio_start).

int wave_clear(int pi)

+This function clears all waveforms and any data added by calls to the +wave_add_* functions. +

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. +

int wave_add_new(int pi)

+This function starts a new empty waveform. You wouldn't normally need +to call this function as it is automatically called after a waveform is +created with the wave_create function. +

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. +

int wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)

+This function adds a number of pulses to the current waveform. +

       pi: >=0 (as returned by pigpio_start).
numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_TOO_MANY_PULSES. +

The pulses are interleaved in time order within the existing waveform +(if any). +

Merging allows the waveform to be built in parts, that is the settings +for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within the existing +waveform then the first pulse should consist solely of a delay. +

int wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

+This function adds a waveform representing serial data to the +existing waveform (if any). The serial data starts offset +microseconds from the start of the waveform. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, +otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, +PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, +or PI_TOO_MANY_PULSES. +

NOTES: +

The serial data is formatted as one start bit, data_bits data bits, +and stop_bits/2 stop bits. +

It is legal to add serial data streams with different baud rates to +the same waveform. +

numBytes is the number of bytes of data in str. +

The bytes required for each character depend upon data_bits. +

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

int wave_create(int pi)

+This function creates a waveform from the data provided by the prior +calls to the wave_add_* functions. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions is consumed by this +function. +

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

Normal usage would be +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create to create the waveform and get a unique id +

Repeat steps 2 and 3 as needed. +

Step 4. wave_send_* with the id of the waveform to transmit. +

A waveform comprises one or more pulses. Each pulse consists of a +gpioPulse_t structure. +

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify +

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +

int wave_create_and_pad(int pi, int percent)

+This function creates a waveform like wave_create but pads the consumed +resources. Where percent gives the percentage of the resources to use (in terms +of the theoretical maximum, not the current amount free). This allows the reuse
+of deleted waves while a transmission is active. Upon success a wave id +greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions are consumed by this +function. +

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

A usage would be the creation of two waves where one is filled while the other +is beeing transmitted. Each wave is assigned 50% of the available resources. +This buffer structure allows the transmission of infinite wave sequences. +

Normal usage: +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create_and_pad to create a waveform of uniform size. +

Step 4. wave_send_* with the id of the waveform to transmit. +

Repeat steps 2-4 as needed. +

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, +PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. +

int wave_delete(int pi, unsigned wave_id)

+This function deletes the waveform with id wave_id. +

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


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

The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. +

- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. +

- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). +

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. +

int wave_send_once(int pi, unsigned wave_id)

+This function transmits the waveform with id wave_id. The waveform +is sent once. +

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

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_send_repeat(int pi, unsigned wave_id)

+This function transmits the waveform with id wave_id. The waveform +cycles until cancelled (either by the sending of a new waveform or +by wave_tx_stop). +

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

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)

+Transmits the waveform with id wave_id using mode mode. +

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.
   mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
         PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC.


PI_WAVE_MODE_ONE_SHOT: same as wave_send_once. +

PI_WAVE_MODE_REPEAT same as wave_send_repeat. +

PI_WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries +to sync with the previous waveform. +

PI_WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries +to sync with the previous waveform. +

WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. +

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

Returns the number of DMA control blocks in the waveform if OK, +otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. +

int wave_chain(int pi, char *buf, unsigned bufSize)

+This function transmits a chain of waveforms. +

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

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

     pi: >=0 (as returned by pigpio_start).
    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, +PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. +

Each wave is transmitted in the order specified. A wave may +occur multiple times per chain. +

A blocks of waves may be transmitted multiple times by using +the loop commands. The block is bracketed by loop start and +end commands. Loops may be nested. +

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if2.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, pi, wid[WAVES];

   pi = pigpio_start(0, 0);
   if (pi<0) return -1;

   set_mode(pi, GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(pi, 2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create(pi);
   }

   wave_chain(pi, (char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy(pi)) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(pi, wid[i]);

   pigpio_stop(pi);
}

int wave_tx_at(int pi)

+This function returns the id of the waveform currently being +transmitted. +

pi: >=0 (as returned by pigpio_start).


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

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
+PI_NO_TX_WAVE (9999) - no wave being transmitted. +

int wave_tx_busy(int pi)

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

pi: >=0 (as returned by pigpio_start).


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

int wave_tx_stop(int pi)

+This function stops the transmission of the current waveform. +

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. +

This function is intended to stop a waveform started with the repeat mode. +

int wave_get_micros(int pi)

+This function returns the length in microseconds of the current +waveform. +

pi: >=0 (as returned by pigpio_start).

int wave_get_high_micros(int pi)

+This function returns the length in microseconds of the longest waveform +created since the pigpio daemon was started. +

pi: >=0 (as returned by pigpio_start).

int wave_get_max_micros(int pi)

+This function returns the maximum possible size of a waveform in
+microseconds. +

pi: >=0 (as returned by pigpio_start).

int wave_get_pulses(int pi)

+This function returns the length in pulses of the current waveform. +

pi: >=0 (as returned by pigpio_start).

int wave_get_high_pulses(int pi)

+This function returns the length in pulses of the longest waveform +created since the pigpio daemon was started. +

pi: >=0 (as returned by pigpio_start).

int wave_get_max_pulses(int pi)

+This function returns the maximum possible size of a waveform in pulses. +

pi: >=0 (as returned by pigpio_start).

int wave_get_cbs(int pi)

+This function returns the length in DMA control blocks of the current +waveform. +

pi: >=0 (as returned by pigpio_start).

int wave_get_high_cbs(int pi)

+This function returns the length in DMA control blocks of the longest +waveform created since the pigpio daemon was started. +

pi: >=0 (as returned by pigpio_start).

int wave_get_max_cbs(int pi)

+This function returns the maximum possible size of a waveform in DMA +control blocks. +

pi: >=0 (as returned by pigpio_start).

int gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)

+This function sends a trigger pulse to a GPIO. The GPIO is set to +level for pulseLen microseconds and then reset to not level. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, +PI_BAD_PULSELEN, or PI_NOT_PERMITTED. +

int store_script(int pi, char *script)

+This function stores a script for later execution. +

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. +

    pi: >=0 (as returned by pigpio_start).
script: the text of the script.


The function returns a script id if the script is valid, +otherwise PI_BAD_SCRIPT. +

int run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

+This function runs a stored script. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

+This function sets the parameters of a script. The script may or +may not be running. The first numPar parameters of the script are +overwritten with the new values. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or +PI_TOO_MANY_PARAM. +

param is an array of up to 10 parameters which may be referenced in +the script as p0 to p9. +

int script_status(int pi, unsigned script_id, uint32_t *param)

+This function returns the run status of a stored script as well +as the current values of parameters 0 to 9. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, +otherwise PI_BAD_SCRIPT_ID. +

The run status may be +

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. +

int stop_script(int pi, unsigned script_id)

+This function stops a running script. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int delete_script(int pi, unsigned script_id)

+This function deletes a stored script. +

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. +

int bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)

+This function opens a GPIO for bit bang reading of serial data. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, +or PI_GPIO_IN_USE. +

The serial data is returned in a cyclic buffer and is read using +bb_serial_read. +

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

int bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)

+This function copies up to bufSize bytes of data read from the +bit bang serial cyclic buffer to the buffer starting at buf. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO +or PI_NOT_SERIAL_GPIO. +

The bytes returned for each character depend upon the number of +data bits data_bits specified in the bb_serial_read_open command. +

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

int bb_serial_read_close(int pi, unsigned user_gpio)

+This function closes a GPIO for bit bang reading of serial data. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. +

int bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)

+This function inverts serial logic for big bang serial reads. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. +

int i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

+This returns a handle for the device at address i2c_addr on bus i2c_bus. +

       pi: >=0 (as returned by pigpio_start).
  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. +

Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, +PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. +

For the SMBus commands the low level transactions are shown at the end +of the function description. The following abbreviations are used. +

S       (1 bit) : Start bit
P       (1 bit) : Stop bit
Rd/Wr   (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA   (1 bit) : Accept and not accept bit.

Addr    (7 bits): I2C 7 bit address.
i2c_reg (8 bits): A byte which often selects a register.
Data    (8 bits): A data byte.
Count   (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2c_close(int pi, unsigned handle)

+This closes the I2C device associated with the handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int i2c_write_quick(int pi, unsigned handle, unsigned bit)

+This sends a single bit (in the Rd/Wr bit) to the device associated +with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Quick command. SMBus 2.0 5.5.1 +S Addr bit [A] P

int i2c_write_byte(int pi, unsigned handle, unsigned bVal)

+This sends a single byte to the device associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Send byte. SMBus 2.0 5.5.2 +S Addr Wr [A] bVal [A] P

int i2c_read_byte(int pi, unsigned handle)

+This reads a single byte from the device associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +or PI_I2C_READ_FAILED. +

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

int i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)

+This writes a single byte to the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write byte. SMBus 2.0 5.5.4 +S Addr Wr [A] i2c_reg [A] bVal [A] P

int i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

+This writes a single 16 bit word to the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Write word. SMBus 2.0 5.5.4 +S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P

int i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)

+This reads a single byte from the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read byte. SMBus 2.0 5.5.5 +S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)

+This reads a single 16 bit word from the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Read word. SMBus 2.0 5.5.5 +S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

+This writes 16 bits of data to the specified register of the device +associated with handle and and reads 16 bits of data in return. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Process call. SMBus 2.0 5.5.6 +S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes up to 32 bytes to the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

Block write. SMBus 2.0 5.5.7 +S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ...
   [A] bufn [A] P

int i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)

+This reads a block of up to 32 bytes from the specified register of +the device associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. +

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

Block read. SMBus 2.0 5.5.7 +S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

The smbus 2.0 documentation states that a minimum of 1 byte may be +sent and a minimum of 1 byte may be received. The total number of +bytes sent/received must be 32 or less. +

Block write-block read. SMBus 2.0 5.5.8 +S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, or PI_I2C_READ_FAILED. +

S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

+This writes 1 to 32 bytes to the specified register of the device +associated with handle. +

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)

+This reads count bytes from the raw device into buf. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_READ_FAILED. +

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)

+This writes count bytes from buf to the raw device. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_I2C_WRITE_FAILED. +

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. +PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)

+This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. +

Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. +

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

  pi: >=0 (as returned by pigpio_start).
 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. +

NOTE: +

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As +a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. +

int bb_i2c_close(int pi, unsigned SDA)

+This function stops bit banging I2C on a pair of GPIO previously +opened with bb_i2c_open. +

 pi: >=0 (as returned by pigpio_start).
SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +

int bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

    pi: >=0 (as returned by pigpio_start).
   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, +PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, +PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. +

The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

The returned I2C data is stored in consecutive locations of outBuf. +

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

int bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)

+This function selects a set of GPIO for bit banging SPI at a +specified baud rate. +

       pi: >=0 (as returned by pigpio_start).
       CS: 0-31
     MISO: 0-31
     MOSI: 0-31
     SCLK: 0-31
     baud: 50-250000
spi_flags: see below


spi_flags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 +

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. +

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or +PI_GPIO_IN_USE. +

If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. +

Example

bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bb_spi_close(int pi, unsigned CS)

+This function stops bit banging SPI on a set of GPIO +opened with bbSPIOpen. +

pi: >=0 (as returned by pigpio_start).
CS: 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. +

int bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)

+This function executes a bit banged SPI transfer. +

   pi: >=0 (as returned by pigpio_start).
   CS: 0-31 (as used in a prior call to bb_spi_open)
txBuf: pointer to buffer to hold data to be sent
rxBuf: pointer to buffer to hold returned data
count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise +PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. +

Example

// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2
// ./bb_spi_x_test

#include <stdio.h>

#include "pigpiod_if2.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, pi, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if ((pi = pigpio_start(0, 0)) < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bb_spi_close(pi, CE0);
   bb_spi_close(pi, CE1);

   pigpio_stop(pi);
}

int spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)

+This function returns a handle for the SPI device on the channel. +Data will be transferred at baud bits per second. The flags may +be used to modify the default behaviour of 4-wire operation, mode 0, +active low chip select. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


         pi: >=0 (as returned by pigpio_start).
spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, +PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. +

spi_flags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. +

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. +

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 spi_read, spi_write, and spi_xfer functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. +

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

Multi-byte transfers are made in least significant byte first order. +

E.g. to transfer 32 11-bit words buf should contain 64 bytes +and count should be 64. +

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

int spi_close(int pi, unsigned handle)

+This functions closes the SPI device identified by the handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int spi_read(int pi, unsigned handle, char *buf, unsigned count)

+This function reads count bytes of data from the SPI +device associated with the handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spi_write(int pi, unsigned handle, char *buf, unsigned count)

+This function writes count bytes of data from buf to the SPI +device associated with the handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)

+This function transfers count bytes of data from txBuf to the SPI +device associated with the handle. Simultaneously count bytes of +data are read from the device and placed in rxBuf. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise +PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. +

int serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)

+This function opens a serial device at a specified baud rate +with specified flags. The device name must start with +/dev/tty or /dev/serial. +

       pi: >=0 (as returned by pigpio_start).
  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or +PI_SER_OPEN_FAILED. +

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

No flags are currently defined. This parameter should be set to zero. +

int serial_close(int pi, unsigned handle)

+This function closes the serial device associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

int serial_write_byte(int pi, unsigned handle, unsigned bVal)

+This function writes bVal to the serial port associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serial_read_byte(int pi, unsigned handle)

+This function reads a byte from the serial port associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. +

If no data is ready PI_SER_READ_NO_DATA is returned. +

int serial_write(int pi, unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the serial port +associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or +PI_SER_WRITE_FAILED. +

int serial_read(int pi, unsigned handle, char *buf, unsigned count)

+This function reads up to count bytes from the the serial port +associated with handle and writes them to buf. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, +PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. +

If no data is ready zero is returned. +

int serial_data_available(int pi, unsigned handle)

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

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, +otherwise PI_BAD_HANDLE. +

int custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)

+This function is available for user customisation. +

It returns a single integer value. +

  pi: >=0 (as returned by pigpio_start).
arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. +

int custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

+This function is available for user customisation. +

It differs from custom_1 in that it returns an array of bytes +rather than just an integer. +

The return value is an integer indicating the number of returned bytes. +    pi: >=0 (as returned by pigpio_start).
  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. +

Note, the number of returned bytes will be retMax or less. +

int get_pad_strength(int pi, unsigned pad)

+This function returns the pad drive strength in mA. +

 pi: >=0 (as returned by pigpio_start).
pad: 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. +

PadGPIO
00-27
128-45
246-53


Example

strength = get_pad_strength(pi, 0); //  get pad 0 strength

int set_pad_strength(int pi, unsigned pad, unsigned padStrength)

+This function sets the pad drive strength in mA. +

         pi: >=0 (as returned by pigpio_start).
        pad: 0-2, the pad to set.
padStrength: 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. +

PadGPIO
00-27
128-45
246-53


Example

set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA

int shell_(int pi, char *scriptName, char *scriptString)

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

          pi: >=0 (as returned by pigpio_start).
  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name.
scriptString: the string to pass to the script.


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

scriptName must exist in /opt/pigpio/cgi and must be executable. +

The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. +

The following table gives some example returned statuses. +

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell_(pi, "scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell_(pi, "scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell_(pi, "scr1", "\"hello string with spaces world\"");

int file_open(int pi, char *file, unsigned mode)

+This function returns a handle to a file opened in a specified mode. +

  pi: >=0 (as returned by pigpio_start).
file: the file to open.
mode: the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. +

File +

A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. +

Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. +

Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. +

Suppose /opt/pigpio/access contains the following entries +

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception +of file.txt. +

Files may be read in directory dir_2. +

Files may be read and written in directory dir_3. +

If a directory allows read, write, or read/write access then files may +be created in that directory. +

In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. +

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode +

The mode may have the following values. +

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


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

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. +

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

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

   handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=file_read(pi, handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      file_close(pi, handle);
   }

   pigpio_stop(pi);
}

int file_close(int pi, unsigned handle)

+This function closes the file associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).


Returns 0 if OK, otherwise PI_BAD_HANDLE. +

Example

file_close(pi, handle);

int file_write(int pi, unsigned handle, char *buf, unsigned count)

+This function writes count bytes from buf to the the file +associated with handle. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. +

Example

if (file_write(pi, handle, buf, 100) == 0)
{
   // file written okay
}
else
{
   // error
}

int file_read(int pi, unsigned handle, char *buf, unsigned count)

+This function reads up to count bytes from the the file +associated with handle and writes them to buf. +

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. +

Example

   bytes = file_read(pi, handle, buf, sizeof(buf));

   if (bytes >= 0)
   {
      // process read data
   }

int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)

+This function seeks to a position within the file associated +with handle. +

        pi: >=0 (as returned by pigpio_start).
    handle: >=0 (as returned by file_open).
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2).


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. +

Example

file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123

size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size

pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position

int file_list(int pi, char *fpat, char *buf, unsigned count)

+This function returns a list of files which match a pattern. +

   pi: >=0 (as returned by pigpio_start).
 fpat: file pattern to match.
  buf: an array to receive the matching file names.
count: the maximum number of bytes to read.


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. +

The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See file_open. +

NOTE +

The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. +

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

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

   c = file_list(pi, "/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      buf[c] = 0;
      printf("%s", buf);
   }

   pigpio_stop(pi);
}

int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)

+This function initialises a new callback. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the GPIO, edge, and tick, whenever the +GPIO has the identified edge. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). +

The number of samples per second is given in the following table. +

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. +

The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. +

If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use gpio_read. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. +

int callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

+This function initialises a new callback. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the GPIO, edge, tick, and the userdata +pointer, whenever the GPIO has the identified edge. +

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

+This function cancels a callback identified by its id. +

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. +

int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)

+This function waits for an edge on the GPIO for up to timeout +seconds. +

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns when the edge occurs or after the timeout. +

Do not use this function for precise timing purposes, +the edge is only checked 20 times a second. Whenever +you need to know the accurate time of GPIO events use +a callback function. +

The function returns 1 if the edge occurred, otherwise 0. +

int bsc_xfer(int pi, bsc_xfer_t *bscxfer)

+This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. +

This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. +

This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. +

The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. +

I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. +

The function sets the BSC mode, writes any data in +the transmit buffer to the BSC transmit FIFO, and +copies any data in the BSC receive FIFO to the +receive buffer. +

     pi: >=0 (as returned by pigpio_start).
bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to +be added to the transmit FIFO (if any) to txBuf and set txCnt to +the number of copied bytes. +

Upon return rxCnt will be set to the number of received bytes placed +in rxBuf. +

The returned function value is the status of the transfer (see below). +

If there was an error the status will be less than zero +(and will contain the error code). +

The most significant word of the returned status contains the number +of bytes actually copied from txBuf to the BSC transmit FIFO (may be +less than requested if the FIFO already contained untransmitted data). +

Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. +

GPIO used for models other than those based on the BCM2711. +

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset +to INPUT mode. +

control consists of the following bits. +

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. +

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. +

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as +an I2C slave with address 0x13 and send four bytes. +

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bsc_xfer(pi, &xfer);

if (status >= 0)
{
   // process transfer
}

int bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)

+This function allows the Pi to act as a slave I2C device. +

This function is not available on the BCM2711 (e.g.as +used in the Pi4B). +

The data bytes (if any) are written to the BSC transmit +FIFO and the bytes in the BSC receive FIFO are returned. +

      pi: >=0 (as returned by pigpio_start).
i2c_addr: 0-0x7F.
 bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // N/A
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


txCnt is set to the number of bytes to be transmitted, possibly +zero. The data itself should be copied to txBuf. +

Any received data will be written to rxBuf with rxCnt set. +

See bsc_xfer for details of the returned status value. +

If there was an error the status will be less than zero +(and will contain the error code). +

Note that an i2c_address of 0 may be used to close +the BSC device and reassign the used GPIO as inputs. +

int event_callback(int pi, unsigned event, evtCBFunc_t f)

+This function initialises an event callback. +

   pi: >=0 (as returned by pigpio_start).
event: 0-31.
    f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the event id, and tick, whenever the +event occurs. +

int event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)

+This function initialises an event callback. +

      pi: >=0 (as returned by pigpio_start).
   event: 0-31.
       f: the callback function.
userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, +pigif_duplicate_callback, or pigif_bad_callback. +

The callback is called with the event id, the tick, and the userdata +pointer whenever the event occurs. +

int event_callback_cancel(unsigned callback_id)

+This function cancels an event callback identified by its id. +

callback_id: >=0, as returned by a call to event_callback or
event_callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. +

int wait_for_event(int pi, unsigned event, double timeout)

+This function waits for an event for up to timeout seconds. +

     pi: >=0 (as returned by pigpio_start).
  event: 0-31.
timeout: >=0.


The function returns when the event occurs or after the timeout. +

The function returns 1 if the event occurred, otherwise 0. +

int event_trigger(int pi, unsigned event)

+This function signals the occurrence of an event. +

   pi: >=0 (as returned by pigpio_start).
event: 0-31.


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

An event is a signal used to inform one or more consumers +to start an action. Each consumer which has registered an interest +in the event (e.g. by calling event_callback) will be informed by +a callback. +

One event, PI_EVENT_BSC (31) is predefined. This event is +auto generated on BSC slave activity. +

The meaning of other events is arbitrary. +

Note that other than its id and its tick there is no data associated +with an event. +

PARAMETERS

active: 0-1000000

+The number of microseconds level changes are reported for once +a noise filter has been triggered (by steady microseconds of +a stable level). +

*addrStr

+A string specifying the host or IP address of the Pi running +the pigpio daemon. It may be NULL in which case localhost +is used unless overridden by the PIGPIO_ADDR environment +variable. +

arg1

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

arg2

+An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

argc

+The count of bytes passed to a user customised function. +

*argx

+A pointer to an array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. +

baud

+The speed of serial communication (I2C, SPI, serial link, waves) in +bits per second. +

bit

+A value of 0 or 1. +

bits

+A value used to select GPIO. If bit n of bits is set then GPIO n is +selected. +

A convenient way to set bit n is to or in (1<<n). +

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). +

bsc_xfer_t

+typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*bscxfer

+A pointer to a bsc_xfer_t object used to control a BSC transfer. +

*buf

+A buffer to hold data being sent or being received. +

bufSize

+The size in bytes of a buffer. +

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

+An 8-bit byte value. +

callback_id

+A value >=0, as returned by a call to a callback function, one of +

callback
+callback_ex
+event_callback
+event_callback_ex +

The id is passed to callback_cancel or event_callback_cancel +to cancel the callback. +

CBFunc_t

+typedef void (*CBFunc_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

+typedef void (*CBFuncEx_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata);

char

+A single character, an 8 bit quantity able to store 0-255. +

clkfreq: 4689-250M (13184-375M for the BCM2711)

+The hardware clock frequency. +

count

+The number of bytes to be transferred in a file, I2C, SPI, or serial +command. +

CS

+The GPIO used for the slave select signal when bit banging SPI. +

data_bits: 1-32

+The number of data bits in each character of serial data. +

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

+A floating point number. +

dutycycle: 0-range

+A number representing the ratio of on time to off time for PWM. +

The number may vary between 0 and range (default 255) where +0 is off and range is fully on. +

edge

+Used to identify a GPIO level transition of interest. A rising edge is +a level change from 0 to 1. A falling edge is a level change from 1 to 0. +

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

+A negative number indicating a function call failed and the nature +of the error. +

event: 0-31

+An event is a signal used to inform one or more consumers +to start an action. +

evtCBFunc_t

+typedef void (*evtCBFunc_t)
   (int pi, unsigned event, uint32_t tick);

evtCBFuncEx_t

+typedef void (*evtCBFuncEx_t)
   (int pi, unsigned event, uint32_t tick, void *userdata);

f

+A function. +

*file

+A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. +

*fpat

+A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. +

frequency: >=0

+The number of times a GPIO is swiched on and off per second. This +can be set per GPIO and may be as little as 5Hz or as much as +40KHz. The GPIO will be on for a proportion of the time as defined +by its dutycycle. +

gpio

+A Broadcom numbered GPIO, in the range 0-53. +

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

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

gpioPulse_t

+typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

+typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

+A number referencing an object opened by one of +

file_open
+i2c_open
+notify_open
+serial_open
+spi_open +

i2c_addr: 0-0x7F

+The address of a device on the I2C bus. +

i2c_bus: >=0

+An I2C bus number. +

i2c_flags: 0

+Flags which modify an I2C open command. None are currently defined. +

i2c_reg: 0-255

+A register of an I2C device. +

*inBuf

+A buffer used to pass data to a function. +

inLen

+The number of bytes of data in a buffer. +

int

+A whole number, negative or positive. +

int32_t

+A 32-bit signed value. +

invert

+A flag used to set normal or inverted bit bang serial data level logic. +

level

+The level of a GPIO. Low or High. +

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be +reported as PI_TIMEOUT. See set_watchdog. +

PI_TIMEOUT 2

MISO

+The GPIO used for the MISO signal when bit banging SPI. +

mode

+1. The operational mode of a GPIO, normally INPUT or OUTPUT. +

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. The mode of waveform transmission. +

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3


3. A file open mode. +

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


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

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

+The GPIO used for the MOSI signal when bit banging SPI. +

numBytes

+The number of bytes used to store characters in a string. Depending +on the number of bits per character there may be 1, 2, or 4 bytes +per character. +

numPar: 0-10

+The number of parameters passed to a script. +

numPulses

+The number of pulses to be added to a waveform. +

offset

+The associated data starts this number of microseconds from the start of +the waveform. +

*outBuf

+A buffer used to return data from a function. +

outLen

+The size in bytes of an output buffer. +

pad: 0-2

+A set of GPIO which share common drivers. +

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

+The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. +

*param

+An array of script parameters. +

pi

+An integer defining a connected Pi. The value is returned by +pigpio_start upon success. +

*portStr

+A string specifying the port address used by the Pi running +the pigpio daemon. It may be NULL in which case "8888" +is used unless overridden by the PIGPIO_PORT environment +variable. +

*pth

+A thread identifier, returned by start_thread. +

pthread_t

+A thread identifier. +

pud: 0-2

+The setting of the pull up/down resistor for a GPIO, which may be off, +pull-up, or pull-down. +PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

+1-100, the length of a trigger pulse in microseconds. +

*pulses

+An array of pulses to be added to a waveform. +

pulsewidth: 0, 500-2500

+PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

+The hardware PWM dutycycle. +

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

+The hardware PWM frequency. +

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000
#define PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

+The permissible dutycycle values are 0-range. +

PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

+A buffer to hold a number of bytes returned to a used customised function, +

retMax

+The maximum number of bytes a user customised function should return. +

*rxBuf

+A pointer to a buffer to receive data. +

SCL

+The user GPIO to use for the clock when bit banging I2C. +

SCLK

+The GPIO used for the SCLK signal when bit banging SPI. +

*script

+A pointer to the text of a script. +

script_id

+An id of a stored script as returned by store_script. +

*scriptName

+The name of a shell_ script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. +

*scriptString

+The string to be passed to a shell_ script to be executed. +

SDA

+The user GPIO to use for data when bit banging I2C. +

seconds

+The number of seconds. +

seekFrom

+PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

+The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). +

ser_flags

+Flags which modify a serial open command. None are currently defined. +

*ser_tty

+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. +

size_t

+A standard type used to indicate the size of an object in bytes. +

spi_channel

+A SPI channel, 0-2. +

spi_flags

+See spi_open and bb_spi_open. +

steady: 0-300000

+The number of microseconds level changes must be stable for +before reporting the level changed (set_glitch_filter) or triggering +the active part of a noise filter (set_noise_filter). +

stop_bits: 2-8

+The number of (half) stop bits to be used when adding serial data +to a waveform. +

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

+ An array of characters. +

thread_func

+A function of type gpioThreadFunc_t used as the main function of a +thread. +

timeout

+A GPIO watchdog timeout in milliseconds. +

PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

+An array of bytes to transmit. +

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

+A 32-bit unsigned value. +

unsigned

+A whole number >= 0. +

user_gpio

+0-31, a Broadcom numbered GPIO. +

See gpio. +

*userdata

+A pointer to arbitrary user data. This may be used to identify the instance. +

You must ensure that the pointer is in scope at the time it is processed. If +it is a pointer to a global this is automatic. Do not pass the address of a +local variable. If you want to pass a transient object then use the +following technique. +

In the calling function: +

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: +

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

+Denoting no parameter is required +

wave_add_*

+One of +

wave_add_new
+wave_add_generic
+wave_add_serial +

wave_id

+A number representing a waveform created by wave_create. +

wave_send_*

+One of +

wave_send_once
+wave_send_repeat +

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

+A 16-bit word value. +

pigpiod_if2 Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
   pigif_unconnected_pi     = -2011,
   pigif_too_many_pis       = -2012,
} pigifError_t;

\ No newline at end of file diff --git a/DOC/tmp/body/pif.body b/DOC/tmp/body/pif.body new file mode 100644 index 0000000..d72d3f8 --- /dev/null +++ b/DOC/tmp/body/pif.body @@ -0,0 +1,21 @@ + +pigpio provides a pipe interface to many of its functions.
+
+The pipe interface is available whenever pigpio is running, either +because it has been started as a daemon, or it has been linked in +to a running user program.  The pipe interface can be disabled +by the program which initialises the library.  pigpiod offers +the -f option to disable the pipe interface.  User programs +should call gpioCfgInterfaces +if they wish to disable the pipe interface.
+
+pigpio listens for commands on pipe /dev/pigpio.  The commands +consist of a command identifier with, depending on the command, +zero, one, or two parameters.  The result, if any, may be read +from pipe /dev/pigout.  If any errors are detected a message +will be written to pipe /dev/pigerr.
+
+
+The format of the commands is identical to those used by pigs. diff --git a/DOC/tmp/body/pig2vcd.body b/DOC/tmp/body/pig2vcd.body new file mode 100644 index 0000000..a6a7719 --- /dev/null +++ b/DOC/tmp/body/pig2vcd.body @@ -0,0 +1,20 @@ +pig2vcd is a utility which reads notifications on stdin and writes the +output as a Value Change Dump (VCD) file on stdout. +

The VCD file can be viewed using GTKWave. +

Notifications

Notifications consist of 12 bytes with the following binary format. +

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

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

tick: the number of microseconds since system boot. It wraps around after 1h12m. +

level: indicates the level of each gpio. If bit 1<<x is set then gpio x is high. pig2vcd takes these notifications and outputs a text format VCD. +

VCD format

The VCD starts with a header. +

$date 2013-05-31 18:49:36 $end
$version pig2vcd V1 $end
$timescale 1 us $end
$scope module top $end
$var wire 1 A 0 $end
$var wire 1 B 1 $end
$var wire 1 C 2 $end
$var wire 1 D 3 $end
$var wire 1 E 4 $end
$var wire 1 F 5 $end
$var wire 1 G 6 $end
$var wire 1 H 7 $end
$var wire 1 I 8 $end
$var wire 1 J 9 $end
$var wire 1 K 10 $end
$var wire 1 L 11 $end
$var wire 1 M 12 $end
$var wire 1 N 13 $end
$var wire 1 O 14 $end
$var wire 1 P 15 $end
$var wire 1 Q 16 $end
$var wire 1 R 17 $end
$var wire 1 S 18 $end
$var wire 1 T 19 $end
$var wire 1 U 20 $end
$var wire 1 V 21 $end
$var wire 1 W 22 $end
$var wire 1 X 23 $end
$var wire 1 Y 24 $end
$var wire 1 Z 25 $end
$var wire 1 a 26 $end
$var wire 1 b 27 $end
$var wire 1 c 28 $end
$var wire 1 d 29 $end
$var wire 1 e 30 $end
$var wire 1 f 31 $end
$upscope $end
$enddefinitions $end


The header defines gpio identifiers and their name. Each gpio identifier +must be unique. pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0 +through 25, and 'a' through 'f' for gpios 26 through 31. +The corresponding names are 0 through 31.
+

The VCD file may be edited to give a frendlier name, e.g. 8 could be +changed to ENCODER_A if an encoder switch A is connected to gpio 8. +

Following the header pig2vcd takes notifications and outputs a timestamp +followed by a list of one or more gpios which have changed state. +The timestamp consists of a '#' followed by the microsecond tick. +The state lines contain the new state followed by the gpio identifier. +

#1058747
0H
0I
#1059012
1H
#1079777
1I
#1079782
0I
#1079852
1I
#1079857
0I
0H
#1165113
1H
#1165118
0H
#1165153
1H
\ No newline at end of file diff --git a/DOC/tmp/body/pigpiod.body b/DOC/tmp/body/pigpiod.body new file mode 100644 index 0000000..1aed926 --- /dev/null +++ b/DOC/tmp/body/pigpiod.body @@ -0,0 +1,51 @@ +pigpiod is a utility which launches the pigpio library as a daemon.
+
+Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.
+
+The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.
+
+pigpiod accepts the following configuration options
+
+
-a valueDMA memory allocation mode0=AUTO, 1=PMAP, 2=MBOXDefault AUTO +
-b valueGPIO sample buffer size in milliseconds100-10000Default 120 +
-c valueLibrary internal settingsDefault 0 +
-d valuePrimary DMA channel0-14Default 14 +
-e valueSecondary DMA channel0-14Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel +
-fDisable fifo interfaceDefault enabled +
-gRun in foreground (do not fork)Default disabled +
-kDisable local and remote socket interfaceDefault enabled +
-lDisable remote socket interfaceDefault enabled +
-mDisable alerts (sampling)Default enabled +
-n IP addressAllow IP address to use the socket interfaceName (e.g. paul) or dotted quad (e.g. 192.168.1.66)If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect +
-p valueSocket port1024-32000Default 8888 +
-s valueSample rate1, 2, 4, 5, 8, or 10 microsecondsDefault 5 +
-t valueClock peripheral0=PWM 1=PCMDefault PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. +
-v -VDisplay pigpio version and exit +
-x maskGPIO which may be updatedA 54 bit mask with (1<<n) set if the user may update GPIO #nDefault is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO +

Example

sudo pigpiod -s 2 -b 200 -f


Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer. Disable the fifo interface. +

Permissions

pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces. +

All GPIO may be read. +

Only the user GPIO for the board type or those specified by the -x option may be updated. +

Type 1 boards 0x03E6CF93 (26 pin header)
Type 2 boards 0xFBC6CF9C (26 pin + 8 pin header)
Type 3 boards 0x0FFFFFFC (40 pin header)


In this context an update includes the following: +

GPIO mode set
+GPIO pull/up down
+GPIO write
+GPIO set PWM (including range and frequency)
+GPIO set servo +

In addition the bank clear and set commands, and the wave commands will only +affect updateable GPIO. +

Exceptions

The following exceptions are made for particular models. +

Models A and B

The green activity LED (GPIO 16) may be written.
+
Models A+ and B+

The green activity LED (GPIO 47) may be written.
+The red power LED (GPIO 35) may be written.
+The high USB power mode (GPIO 38) may be written.
+
Pi Zero

The green activity LED (GPIO 47) may be written.
+
Pi2B

The green activity LED (GPIO 47) may be written.
+The red power LED (GPIO 35) may be written.
+The high USB power mode (GPIO 38) may be written.
+
Pi3B

The green activity LED and the red power LED are not writable.
+The USB power mode is fixed at 1.2 amps (high power).
+

DMA Channels

The secondary channel is only used for the transmission of waves. +

If possible use one of channels 0 to 6 for the secondary channel (a full channel). +

A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel. +

\ No newline at end of file diff --git a/DOC/tmp/body/pigs.body b/DOC/tmp/body/pigs.body new file mode 100644 index 0000000..f4b7a7e --- /dev/null +++ b/DOC/tmp/body/pigs.body @@ -0,0 +1,1205 @@ +

Introduction

+The socket and pipe interfaces allow control of the Pi's GPIO by +passing messages to the running pigpio library. +

The normal way to start the pigpio library would be as a daemon during boot. +

sudo pigpiod

Features

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o reading/writing all of the GPIO in a bank as one operation +

o individually setting GPIO modes, reading and writing +

o notifications when any of GPIO 0-31 change state +

o the construction of output waveforms with microsecond timing +

o I2C, SPI, and serial link wrappers +

o creating and running scripts on the pigpio daemon +

GPIO

ALL GPIO are identified by their Broadcom number. +

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

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 $?). +

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

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

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

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 mSet GPIO mode gpioSetMode
MG/MODEG gGet GPIO mode gpioGetMode
PUD g pSet GPIO pull up/down gpioSetPullUpDown
R/READ gRead GPIO level gpioRead
W/WRITE g LWrite GPIO level gpioWrite
PWM (overrides servo commands on same GPIO) +
P/PWM u vSet GPIO PWM value gpioPWM
PFS u vSet GPIO PWM frequency gpioSetPWMfrequency
PRS u vSet GPIO PWM range gpioSetPWMrange
GDC uGet GPIO PWM dutycycle gpioGetPWMdutycycle
PFG uGet GPIO PWM frequency gpioGetPWMfrequency
PRG uGet GPIO PWM range gpioGetPWMrange
PRRG uGet GPIO PWM real range gpioGetPWMrealRange
Servo (overrides PWM commands on same GPIO) +
S/SERVO u vSet GPIO servo pulsewidth gpioServo
GPW uGet GPIO servo pulsewidth gpioGetServoPulsewidth
INTERMEDIATE +
TRIG u pl LSend a trigger pulse gpioTrigger
WDOG u vSet GPIO watchdog gpioSetWatchdog
BR1Read bank 1 GPIO gpioRead_Bits_0_31
BR2Read bank 2 GPIO gpioRead_Bits_32_53
BC1 bitsClear specified GPIO in bank 1 gpioWrite_Bits_0_31_Clear
BC2 bitsClear specified GPIO in bank 2 gpioWrite_Bits_32_53_Clear
BS1 bitsSet specified GPIO in bank 1 gpioWrite_Bits_0_31_Set
BS2 bitsSet specified GPIO in bank 2 gpioWrite_Bits_32_53_Set
ADVANCED +
NORequest a notification gpioNotifyOpen
NC hClose notification gpioNotifyClose
NB h bitsStart notification gpioNotifyBegin
NP hPause notification gpioNotifyPause
HC g cfSet hardware clock frequency gpioHardwareClock
HP g pf pdcSet hardware PWM frequency and dutycycle gpioHardwarePWM
FG u stdySet a glitch filter on a GPIO gpioGlitchFilter
FN u stdy actvSet a noise filter on a GPIO gpioNoiseFilter
PADS pad padmaSet pad drive strength gpioSetPad
PADG padGet pad drive strength gpioGetPad
SHELL name strExecute a shell command shell
Custom +
CF1 uvsCustom function 1 gpioCustom1
CF2 uvsCustom function 2 gpioCustom1
Events +
EVM h bitsSet events to monitor eventMonitor
EVT eventTrigger event eventTrigger
Scripts +
PROC tStore script gpioStoreScript
PROCR sid parsRun script gpioRunScript
PROCU sid parsSet script parameters gpioUpdateScript
PROCP sidGet script status and parameters gpioScriptStatus
PROCS sidStop script gpioStopScript
PROCD sidDelete script gpioDeleteScript
PARSE tValidate script gpioParseScript
I2C +
I2CO ib id ifOpen I2C bus and device with flags i2cOpen
I2CC hClose I2C handle i2cClose
I2CWQ h bitsmb Write Quick: write bit i2cWriteQuick
I2CRS hsmb Read Byte: read byte i2cReadByte
I2CWS h bvsmb Write Byte: write byte i2cWriteByte
I2CRB h rsmb Read Byte Data: read byte from register i2cReadByteData
I2CWB h r bvsmb Write Byte Data: write byte to register i2cWriteByteData
I2CRW h rsmb Read Word Data: read word from register i2cReadWordData
I2CWW h r wvsmb Write Word Data: write word to register i2cWriteWordData
I2CRK h rsmb Read Block Data: read data from register i2cReadBlockData
I2CWK h r bvssmb Write Block Data: write data to register i2cWriteBlockData
I2CWI h r bvssmb Write I2C Block Data i2cWriteI2CBlockData
I2CRI h r numsmb Read I2C Block Data: read bytes from register i2cReadI2CBlockData
I2CRD h numi2c Read device i2cReadDevice
I2CWD h bvsi2c Write device i2cWriteDevice
I2CPC h r wvsmb Process Call: exchange register with word i2cProcessCall
I2CPK h r bvssmb Block Process Call: exchange data bytes with register i2cBlockProcessCall
I2CZ h bvsPerforms multiple I2C transactions i2cZip
I2C BIT BANG +
BI2CO sda scl bOpen bit bang I2C bbI2COpen
BI2CC sdaClose bit bang I2C bbI2CClose
BI2CZ sda bvsI2C bit bang multiple transactions bbI2CZip
I2C/SPI SLAVE +
BSCX bctl bvsBSC I2C/SPI transfer bscXfer
SERIAL +
SERO dev b sefOpen serial device dev at baud b with flags serOpen
SERC hClose serial handle serClose
SERRBRead byte from serial handle serReadByte
SERWB h bvWrite byte to serial handle serWriteByte
SERR h numRead bytes from serial handle serRead
SERW h bvsWrite bytes to serial handle serWrite
SERDA hCheck for serial data ready to read serDataAvailable
SERIAL BIT BANG (read only) +
SLRO u b dbOpen GPIO for bit bang serial data gpioSerialReadOpen
SLRC uClose GPIO for bit bang serial data gpioSerialReadClose
SLRI u vSets bit bang serial data logic levels gpioSerialReadInvert
SLR u numRead bit bang serial data from GPIO gpioSerialRead
SPI +
SPIO c b spfSPI open channel at baud b with flags spiOpen
SPIC hSPI close handle spiClose
SPIR h numSPI read bytes from handle spiRead
SPIW h bvsSPI write bytes to handle spiWrite
SPIX h bvsSPI transfer bytes to handle spiXfer
SPI BIT BANG +
BSPIO cs miso mosi sclk b spfOpen bit bang SPI bbSPIOpen
BSPIC csClose bit bang SPI bbSPIClose
BSPIX cs bvsSPI bit bang transfer bbSPIXfer
FILES +
FO file modeOpen a file in mode fileOpen
FC hClose file handle fileClose
FR h numRead bytes from file handle fileRead
FW h bvsWrite bytes to file handle fileWrite
FS h num fromSeek to file handle position fileSeek
FL pat numList files which match pattern fileList
WAVES +
WVCLRClear all waveforms gpioWaveClear
WVNEWInitialise a new waveform gpioWaveAddNew
WVAG tripsAdd generic pulses to waveform gpioWaveAddGeneric
WVAS u b db sb o bvsAdd serial data to waveform gpioWaveAddSerial
WVCRECreate a waveform gpioWaveCreate
WVCAPCreate a waveform of fixed size gpioWaveCreatePad
WVDEL widDelete selected waveform gpioWaveDelete
WVTX widTransmits waveform once gpioWaveTxSend
WVTXM wid wmdeTransmits waveform using mode gpioWaveTxSend
WVTXR widTransmits waveform repeatedly gpioWaveTxSend
WVCHA bvsTransmits a chain of waveforms gpioWaveChain
WVTATReturns the current transmitting waveform gpioWaveTxAt
WVBSYCheck if waveform is being transmitted gpioWaveTxBusy
WVHLTStop waveform gpioWaveTxStop
WVSC wsGet waveform DMA CB stats gpioWaveGetCbs
WVSM wsGet waveform time stats gpioWaveGetMicros
WVSP wsGet waveform pulse stats gpioWaveGetPulses
UTILITIES +
H/HELPDisplay command help
HWVERGet hardware version gpioHardwareRevision
MICS vMicroseconds delay gpioDelay
MILS vMilliseconds delay gpioDelay
PIGPVGet pigpio library version gpioVersion
T/TICKGet current tick gpioTick
CONFIGURATION +
CGIConfiguration get internals gpioCfgGetInternals
CSI vConfiguration set internals gpioCfgSetInternals

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

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

o baud rates as low as 50
+o repeated starts
+o clock stretching
+o 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. +

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: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

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 read GPIO 0-31 (bank 1) and returns the levels as a +32-bit hexadecimal value. +

Example

$ pigs br1
1001C1CF

BR2 + - Read bank 2 GPIO

This command read 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 (sets high) 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 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

This command sets (sets high) 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 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

This command performs a BSC I2C/SPI slave transfer as defined by +bctl with data bvs. +

This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. +

This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. +

This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. +

The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. +

I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. +

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, followed by any data bytes +read from the BSC receive FIFO. +

Note that the control word sets the BSC mode. The BSC will stay in +that mode until a different control word is sent. +

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

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

GPIO used for models other than those based on the BCM2711. +

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset +to INPUT mode. +

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

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. +

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit 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 +opened with BSPIO. +

The set of GPIO is specifed by cs. +

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

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 command starts bit banging SPI on a group of GPIO with slave +select cs, MISO miso, MOSI mosi, and clock sclk. +

Data will be transferred at baud b bits per second (which may +be set in the range 50-250000). +

The flags spf may be used to modify the default behaviour of +mode 0, active low chip select. +

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

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

If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. +

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. It returns the same +number of bytes read from the device. +

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

This command calls a user customised function. The meaning of +any paramaters and the returned value is defined by the +customiser. +

CF2 + uvs - Custom function 2

This command calls a user customised function. The meaning of +any paramaters and the returned value is defined by the +customiser. +

CGI + - Configuration get internals

This command returns the value of the internal library +configuration settings. +

CSI + v - Configuration set internals

This command sets the value of the internal library +configuration settings to v. +

EVM + h bits - Set events to monitor

This command starts event reporting 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 reports for each 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

This command triggers event event. +

One event, number 31, is predefined. This event is +auto generated on BSC slave activity. +

Example

$ pigs evt 12
$ pigs evt 5

$ pigs evt 32
-143
ERROR: bad event id

FC + h - Close file handle

This command closes a file handle h previously opened with FO. +

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

Example

$ pigs fc 0 # First close okay.

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

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. The +level is then reported. Level changes of less than stdy +microseconds are ignored. +

The filter only affects callbacks (including pipe notifications). +

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

Note, each (stable) edge will be timestamped stdy microseconds +after it was first detected. +

Example

$ pigs fg 4 250

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

FL + pat num - List files which match pattern

This command returns a list of the files matching pat. Up +to num bytes may be returned. +

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

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 are ignored until a level which has +been stable for stdy microseconds is detected. Level +changes on the GPIO are then reported for actv microseconds +after which the process repeats. +

The filter only affects callbacks (including pipe notifications). +

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

Note, level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

Example

$ pigs fn 7 250 1000

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

FO + file mode - Open a file in mode

This function 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 +will be returned. +

File +

A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. +

Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. +

Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. +

Suppose /opt/pigpio/access contains the following entries +

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception +of file.txt. +

Files may be read in directory dir_2. +

Files may be read and written in directory dir_3. +

If a directory allows read, write, or read/write access then files may +be created in that directory. +

In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. +

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode +

The mode may have the following values. +

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


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

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. +

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

This command 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 will be returned. +

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

This command 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 backwards. The move start +position is determined by from as follows. +

From
0start
1current position
2end


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

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

This command writes bytes bvs to the file +associated with handle h. +

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

Example

$ pigs fw 0 23 45 67 89

GDC + u - Get GPIO PWM dutycycle

This command returns the PWM dutycycle in use on GPIO u. +

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

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

This command returns the servo pulsewidth in use on GPIO u. +

Upon success the servo pulsewidth is returned. On error a negative +status code will be returned. +

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

This command displays a brief list of the commands and their parameters. +

Example

$ pigs h

$ pigs help

HC + g cf - Set hardware clock frequency

This command sets the hardware clock associated with GPIO g to +frequency cf. Frequencies above 30MHz are unlikely to work. +

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

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

The GPIO must be one of the following. +

4clock 0All models
5clock 1All models but A and B (reserved for system use)
6clock 2All models but A and B
20clock 0All models but A and B
21clock 1All models but A and B Rev.2 (reserved for system use)


32clock 0Compute module only
34clock 0Compute module only
42clock 1Compute module only (reserved for system use)
43clock 2Compute module only
44clock 1Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will +likely crash the Pi. The password is given by or'ing 0x5A000000 +with the GPIO number. +

HP + g pf pdc - Set hardware PWM frequency and dutycycle

This command sets the hardware PWM associated with GPIO g to +frequency pf with dutycycle pdc. Frequencies above 30MHz +are unlikely to work. +

NOTE: Any waveform started by WVTX, WVTXR, or WVCHA +will be cancelled. +

This function is only valid if the pigpio main clock is PCM. The +main clock defaults to PCM but may be overridden when the pigpio +daemon is started (option -t). +

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

$ 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


The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which +share a PWM channel. +

The GPIO must be one of the following. +

12PWM channel 0All models but A and B
13PWM channel 1All models but A and B
18PWM channel 0All models
19PWM channel 1All models but A and B


40PWM channel 0Compute module only
41PWM channel 1Compute module only
45PWM channel 1Compute module only
52PWM channel 0Compute module only
53PWM channel 1Compute module only


The actual number of steps beween off and fully on is the +integral part of 250M/pf (375M/pf for the BCM2711). +

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

There will only be a million steps for a pf of 250 (375 for +the BCM2711). Lower frequencies will have more steps and higher +frequencies will have fewer steps. pdc is +automatically scaled to take this into account. +

HWVER + - Get hardware version

This command returns the hardware revision of the Pi. +

The hardware revision is found in the last 4 characters on the revision +line of /proc/cpuinfo. +

If the hardware revision can not be found or is not a valid hexadecimal +number the command returns 0. +

The revision number can be used to determine the assignment of GPIO +to pins (see g). +

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

This command closes an I2C handle h previously opened with I2CO. +

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

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 command returns a handle to access device id on I2C bus ib. +The device is opened with flags if. +

Physically buses 0 and 1 are available on the Pi. Higher +numbered buses will be available if a kernel supported bus +multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


No flags are currently defined. The parameter if should be 0. +

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

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

This command writes wv to register r of the I2C device +associated with handle h and returns a 16-bit word read from the +device. +

Upon success a value between 0 and 65535 will be returned. On error +a negative status code will be returned. +

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

This command writes the data bytes bvs to register r of the I2C device +associated with handle h and returns a device specific number of 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 i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0

I2CRB + h r - smb Read Byte Data: read byte from register

This command returns a single byte read from register r of the I2C device +associated with handle h. +

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

Example

$ pigs i2crb 0 0
6

I2CRD + h num - i2c Read device

This command returns num bytes read from the I2C 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. +

This command operates on the raw I2C device. The maximum value of the +parameter num is dependent on the I2C drivers and the device +itself. pigs imposes a limit of 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

This command returns num bytes from register r of the I2C 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. +

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

This command returns between 1 and 32 bytes read from register r of +the I2C 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. +

The number of bytes of returned data is specific to the device and +register. +

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

This command returns a single byte read from the I2C device +associated with handle h. +

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

Example

$ pigs i2crs 0
0

I2CRW + h r - smb Read Word Data: read word from register

This command returns a single 16 bit word read from register r of +the I2C device associated with handle h. +

Upon success a value between 0 and 65535 will be returned. On error +a negative status code will be returned. +

Example

$ pigs i2crw 0 0
6150

I2CWB + h r bv - smb Write Byte Data: write byte to register

This command writes a single byte bv to register r of the +I2C device associated with handle h. +

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

Example

$ pigs i2cwb 0 10 0x54

I2CWD + h bvs - i2c Write device

This command writes a block of bytes bvs to the I2C device +associated with handle h. +

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

The number of bytes which may be written in one transaction is +dependent on the I2C drivers and the device itself. pigs imposes +a limit of about 500 bytes. +

This command operates on the raw I2C device. +

Example

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

I2CWI + h r bvs - smb Write I2C Block Data

This command writes between 1 and 32 bytes bvs to register r of +the I2C device associated with handle h. +

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

Example

$ pigs i2cwi 0 4 0x01 0x04 0xc0

I2CWK + h r bvs - smb Write Block Data: write data to register

This command writes between 1 and 32 bytes bvs to register r of +the I2C device associated with handle h. +

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

Example

pigs i2cwk 0 4 0x01 0x04 0xc0

I2CWQ + h bit - smb Write Quick: write bit

This command writes a single bit to the I2C device associated +with handle h. +

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

Example

$ pigs i2cwq 0 1

I2CWS + h bv - smb Write Byte: write byte

This command writes a single byte bv to the I2C device associated +with handle h. +

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

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

This command writes a single 16 bit word wv to register r of +the I2C device associated with handle h. +

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

Example

$ pigs i2cww 0 0 0xffff

I2CZ + h bvs - Performs multiple I2C transactions

This command executes a sequence of 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: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle h. +The flags default to 0. The address and flags maintain their +previous value until updated. +

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/MODES + g m - Set GPIO mode

This command sets GPIO g to mode m, typically input (read) +or output (write). +

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

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

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345


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

Value01234567
ModeInputOutputALT5ALT4ALT0ALT1ALT2ALT3


Example

$ pigs mg 4
1

MICS + v - Microseconds delay

This command delays execution for v microseconds. +

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

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

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

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

PadGPIO
00-27
128-45
246-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. +

PadGPIO
00-27
128-45
246-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. +

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

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

       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


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

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

Upon success the script status and parameters are returned. +On error a negative status code will be returned. +

The script status may be one of +

0being initialised
1halted
2running
3waiting
4failed


See Scripts. +

Example

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

PROCR + sid pars - Run script

This command runs stored script sid passing it up to 10 optional +parameters. +

Upon success nothing is returned. 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 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

This command stops a running script sid. +

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

This command sets the parameters of a stored script sid passing +it up to 10 parameters. +

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 used by GPIO u. +

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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

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 command sets the dutycycle range v to be used for GPIO u. +Subsequent uses of command P/PWM will use a dutycycle between 0 (off) +and v (fully on). +

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 will be scaled to +reflect the new range. +

The real range, the number of steps between fully off and fully on +for each frequency, is given in the following table. +

#1#2#3#4#5#6#7#8#9
2550100125200250400500625
#10#11#12#13#14#15#16#17#18
8001000125020002500400050001000020000


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

This command 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 may 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

This 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

This command 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 may be 0 (off), 500 (most anti-clockwise) +to 2500 (most clockwise). +

The range supported by servos varies and should probably be determined +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. +

You can DAMAGE a servo if you command it to move beyond its limits. +

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

This command closes a serial handle h 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

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

This command 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. +

Example

$ pigs sero /dev/ttyAMA0 9600 0
0

$ pigs sero /dev/tty1 38400 0
1

SERR + h num - Read bytes from serial handle

This command 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

This command 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

This command 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

This command 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 command 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. +

The returned exit status is normally 256 times that set +by the shell script exit function. If the script can't +be found 32512 will be returned. +

The following table gives some example returned statuses. +

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


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 "\"hello string with spaces world\""
256

# non-existent script
$ pigs shell scr78 par1
32512

SLR + u num - Read bit bang serial data from GPIO

This command 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. +

The GPIO u should have been initialised with the SLRO command. +

The bytes returned for each character depend upon the number of +data bits db 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

This command 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

This command 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

This command 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 may be between 50 and 250000 bits per second. +

The received data is held in a cyclic buffer. +

It is the user's responsibility to read the data (with SLR) +in a timely fashion. +

Example

$ pigs slro 23 19200 8

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

SPIC + h - SPI close handle

This command closes the SPI handle h returned by a prior +call to SPIO. +

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

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

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

Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps +are unlikely to work. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


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

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

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

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

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

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

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

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

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

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

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

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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 \
   ${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

WVCLR + - Clear all waveforms

This command clears all waveforms. +

Nothing is returned. +

Example

$ pigs wvclr

WVCRE + - Create a waveform

This command creates a waveform from the data provided by the prior +calls to the WVAG and WVAS commands. +

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

The data provided by the WVAG and WVAS commands is +consumed by this command. +

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 +

Step 1. WVCLR to clear all waveforms and added data. +

Step 2. WVAG/WVAS calls to supply the waveform data. +

Step 3. WVCRE to create the waveform and get a unique id. +

Repeat steps 2 and 3 as needed. +

Step 4. WVTX or WVTXR with the id of the waveform to transmit. +

A waveform comprises of one or more pulses. +

A pulse specifies +

1) the GPIO to be switched on at the start of the pulse.
+2) the GPIO to be switched off at the start of the pulse.
+3) the delay in microseconds before the next pulse. +

Any or all the fields can be zero. It doesn't make any sense to +set all the fields to zero (the pulse will be ignored). +

When a waveform is started each pulse is executed in order with +the specified delay between the pulse and the next. +

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

WVCAP + - 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 total resource. +Padded waves of equal size can be re-cycled efficiently allowing newly +created waves to re-use the resources of deleted waves of the same dimension. +

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

The data provided by the WVAG and WVAS commands are +consumed by this command. +

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 +

Step 1. WVCLR to clear all waveforms and added data. +

Step 2. WVAG/WVAS calls to supply the waveform data. +

Step 3. WVCAP to create a waveform of a uniform size. +

Step 4. WVTX or WVTXR with the id of the waveform to transmit. +

Repeat steps 2 - 4 as needed. +

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

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

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

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

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

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

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), or 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. +

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

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

+

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

From
0start
1current position
2end

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

0123456789101112131415
Type 1XX--X--XXXXX--XX
Type 2--XXX--XXXXX--XX
Type 3XXXXXXXXXXXXXX
16171819202122232425262728293031
Type 1-XX--XXXXX------
Type 2-XX---XXXX-XXXXX
Type 3XXXXXXXXXXXX----


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

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345
Value01456732

miso - GPIO (0-31)

+The GPIO used for the MISO signal when bit banging SPI. +

mode - file open mode

+One of the following values. +

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


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

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The 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 DownOffPull DownPull Up
Command CharacterODU


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

pad - 0-2

+A set of GPIO which share common drivers. +

PadGPIO
00-27
128-45
246-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. +

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 onGPIO offdelay
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

+Scripts are programs to be stored and executed by the pigpio daemon. +They are intended to mitigate any performance problems associated with +the pigpio daemon server/client model. +

Example

A trivial example might be useful. Suppose you want to toggle a GPIO +on and off as fast as possible. +

From the command line you could write +

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


Timing that you will see it takes about 14 seconds, or roughly +70 toggles per second. +

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

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

Let's time the script running. +

Again, ignore the details for now. +

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


The script takes roughly 12 seconds to complete, or 800,000 toggles per second. +

That is the advantage of a stored script. +

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 ]];\
 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. +

Virtual machine

A script runs within a virtual machine with +

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

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: +

CommandDescriptionDefinition
ADD xAdd x to accumulatorA+=x; F=A
AND xAnd x with accumulatorA&=x; F=A
CALL LCall subroutine at tag Lpush(PC+1); PC=L
CMP xCompare x with accumulatorF=A-x
DCR yDecrement register--*y; F=*y
DCRADecrement accumulator--A; F=A
DIV xDivide x into accumulatorA/=x; F=A
EVTWTWait for an event to occurA=wait(x); F=A
HALTHaltHalt
INR yIncrement register++*y; F=*y
INRAIncrement accumulator++A; F=A
JM LJump if minus to tag Lif (F<0) PC=L
JMP LJump to tag LPC=L
JNZ LJump if non-zero to tag Lif (F) PC=L
JP LJump if positive to tag Lif (F>=0) PC=L
JZ LJump if zero to tag Lif (!F) PC=L
LD y xLoad register with x*y=x
LDA xLoad accumulator with xA=x
MLT xMultiply x with accumulatorA*=x; F=A
MOD xModulus x with accumulatorA%=x; F=A
OR xOr x with accumulatorA|=x; F=A
POP yPop registery=pop()
POPAPop accumulatorA=pop()
PUSH yPush registerpush(y)
PUSHAPush accumulatorpush(A)
RETReturn from subroutinePC=pop()
RL y xRotate left register x bits*y<<=x; F=*y
RLA xRotate left accumulator x bitsA<<=x; F=A
RR y xRotate right register x bits*y>>=x; F=*y
RRA xRotate right accumulator x bitsA>>=x; F=A
STA yStore accumulator in registery=A
SUB xSubtract x from accumulatorA-=x; F=A
SYS strRun external script (/opt/pigpio/cgi/str)system(str); F=A
TAG LLabel the current script positionN/A
WAIT xWait for a GPIO in x to change stateA=wait(x); F=A
X y1 y2Exchange contents of registers y1 and y2t=*y1;*y1=*y2;*y2=t
XA yExchange contents of accumulator and registert=A;A=*y;*y=t
XOR xXor x with accumulatorA^=x; F=A


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

\ No newline at end of file diff --git a/DOC/tmp/body/piscope.body b/DOC/tmp/body/piscope.body new file mode 100644 index 0000000..dd0c7ce --- /dev/null +++ b/DOC/tmp/body/piscope.body @@ -0,0 +1,205 @@ + +

Introduction

+piscope is a logic analyser (digital +waveform viewer) for the Raspberry.  It shows the state (high +or low) of selected GPIO in real-time.
+
+See video.
+
+piscope uses the services of the pigpio library.  pigpio needs to be running on +the Pi whose GPIO are to be monitored.
+
+The pigpio library may be started as a daemon (background process) +by the following command.
+
+sudo pigpiod

+piscope may be invoked in several different ways
+
+ + + + + + + + + + + + + + + + + + + + + + + +
Pi
pi_host ~ $ piscope +&
Pi captures +data
+Pi processes data
+Pi displays data
Pi plus Linux PC
+
+(with the
+display on a remote
+  Linux PC)
remote_host ~ $ ssh -X pi_host
pi_host ~ $ piscope +&
Pi captures data
+Pi processes data
+Remote Linux PC displays data
Pi plus Windows PC
+
+(with the
+display on a remote
+  Windows PC)
You need to install an SSH +client (putty suggested) and a X11 server (xming suggested).
+
+Run Program Files -> Xming -> XLaunch and accept the +defaults.
+
+Run putty and enter the Pi's host name or IP address.  Click +on SSH X11 and tick Enable X11 forwarding and then select +Open.

+
pi_host ~ $ piscope +&
Pi captures data
+Pi processes data
+Remote Windows PC displays data
Pi plus Linux PC
+
+(with the display and processing on a remote Linux +PC)
remote_host ~ $ export +PIGPIO_ADDR=pi_host
+remote_host ~ $ piscope +&
Pi captures data
+Remote processes data
+Remote displays data
+
+piscope operates in one of three modes
+
+ + + + + + + + + + + + + + + + + + +
Live
The latest GPIO samples are +displayed.
+
+The mode will automatically change to Pause if a sampling trigger +is detected.
+
+There are four triggers.  Each trigger is made up of a +combination of GPIO states (one of don't care, low, high, edge, +falling, or rising per GPIO).  Triggers are always +counted.  In addition a trigger may be sample to, sample +around, or sample from, a so called sampling trigger.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full the oldest samples are discarded.
Play
Recorded GPIO samples are +displayed.
+
+The play speed may be varied between 64 times real-time to 1/32768 +of real-time.
+
+The page up key increases the play speed by a factor of 2.  +The page down key decreases the play speed by a factor of 2.  +The home key sets the play speed to 1X.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full new samples are discarded.
Pause
Recorded GPIO samples are +displayed.
+
+The left and right cursor keys move the blue marker to the previous +or next edge.  By default all GPIO edges are considered.  +Clicking on a GPIO name will limit edge searches to the highlighted +GPIO only.
+
+The left and right square bracket keys move the blue marker to the +previous or next trigger.
+
+The time between the blue and gold markers is displayed.  The +gold marker is set to the blue marker by a press of the 'g' +key.
New samples are added to the +sample buffer.
+
+Once the sample buffer is full new samples are discarded.
+
+In all modes the down and up cursor keys zoom the time scale in and +out.
+
+Samples can be saved with File Save All Samples or File Save +Selected Samples. +

To select samples enter pause mode. Press 1 to specify the start +of the samples (green marker) and 2 to specify the end of the +samples (red marker).

+

The samples may be saved in the native piscope format or in VCD +format.

+

Data saved in VCD format may be viewed and further processed +with GTKWave.

+

Data saved in the native piscope format may be restored later +with File Restore Saved Data.

+

Installation

+

To download and install piscope.

+

Pi (pre-built image)

+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make hf
+make install

+

Linux 64 bit X86/AMD (pre-built image)

+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make x86_64
+make install
+

All machines (building from source)

+You only need to perform this step if you want to build the +executable from the source files.  This is not needed if you +use a pre-built image.
+
+WARNING
: Installing gtk+-3.0 uses a lot of SD card +space.
+
+Most of the space used by gtk+-3.0 is taken up by unneeded *-dbg +packages.
+
+With *-dbg packages an additional 3753MB SD space is required.
+
+If you edit the list of packages to be downloaded and remove the +*-dbg packages only 134MB of additional SD space is needed (as at +the time of writing).
+
+#
# *** This may take a lot of time and use +a lot of SD card space ***
#
+sudo apt-get install gtk+-3.0
#
+wget abyz.me.uk/rpi/pigpio/piscope.tar
+tar xvf piscope.tar
+cd PISCOPE
+make
+make install

diff --git a/DOC/tmp/body/python.body b/DOC/tmp/body/python.body new file mode 100644 index 0000000..f036866 --- /dev/null +++ b/DOC/tmp/body/python.body @@ -0,0 +1,1230 @@ +pigpio is a Python module for the Raspberry which talks to +the pigpio daemon to allow control of the general purpose +input outputs (GPIO). +

Features

o the pigpio Python module can run on Windows, Macs, or Linux +

o controls one or more Pi's +

o hardware timed PWM on any of GPIO 0-31 +

o hardware timed servo pulses on any of GPIO 0-31 +

o callbacks when any of GPIO 0-31 change state +

o creating and transmitting precisely timed waveforms +

o reading/writing GPIO and setting their modes +

o wrappers for I2C, SPI, and serial links +

o creating and running scripts on the pigpio daemon +

GPIO

ALL GPIO are identified by their Broadcom number. +

Notes

Transmitted waveforms are accurate to a microsecond. +

Callback level changes are time-stamped and will be +accurate to within a few microseconds. +

Settings

A number of settings are determined when the pigpio daemon is started. +

o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). +

o the set of GPIO which may be updated (generally written to). The + default set is those available on the Pi board revision. +

o the available PWM frequencies (see set_PWM_frequency). +

Exceptions

By default a fatal exception is raised if you pass an invalid +argument to a pigpio function. +

If you wish to handle the returned status yourself you should set +pigpio.exceptions to False. +

You may prefer to check the returned status in only a few parts +of your code. In that case do the following: +

Example

pigpio.exceptions = False

# Code where you want to test the error status.

pigpio.exceptions = True

Usage

This module uses the services of the C pigpio library. pigpio +must be running on the Pi(s) whose GPIO are to be manipulated. +

The normal way to start pigpio is as a daemon (during system +start). +

sudo pigpiod +

Your Python program must import pigpio and create one or more +instances of the pigpio.pi class. This class gives access to +a specified Pi's GPIO. +

Example

pi1 = pigpio.pi()       # pi1 accesses the local Pi's GPIO
pi2 = pigpio.pi('tom')  # pi2 accesses tom's GPIO
pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO

pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4)     # get level of dick's GPIO 4


The later example code snippets assume that pi is an instance of +the pigpio.pi class. +

OVERVIEW

ESSENTIAL +
pigpio.pi Initialise Pi connection +
stop Stop a Pi connection +
BASIC +
set_mode Set a GPIO mode +
get_mode Get a GPIO mode +
set_pull_up_down Set/clear GPIO pull up/down resistor +
read Read a GPIO +
write Write a GPIO +
PWM (overrides servo commands on same GPIO) +
set_PWM_dutycycle Start/stop PWM pulses on a GPIO +
set_PWM_frequency Set PWM frequency of a GPIO +
set_PWM_range Configure PWM range of a GPIO +
get_PWM_dutycycle Get PWM dutycycle set on a GPIO +
get_PWM_frequency Get PWM frequency of a GPIO +
get_PWM_range Get configured PWM range of a GPIO +
get_PWM_real_range Get underlying PWM range for a GPIO +
Servo (overrides PWM commands on same GPIO) +
set_servo_pulsewidth Start/Stop servo pulses on a GPIO +
get_servo_pulsewidth Get servo pulsewidth set on a GPIO +
INTERMEDIATE +
gpio_trigger Send a trigger pulse to a GPIO +
set_watchdog Set a watchdog on a GPIO +
read_bank_1 Read all bank 1 GPIO +
read_bank_2 Read all bank 2 GPIO +
clear_bank_1 Clear selected GPIO in bank 1 +
clear_bank_2 Clear selected GPIO in bank 2 +
set_bank_1 Set selected GPIO in bank 1 +
set_bank_2 Set selected GPIO in bank 2 +
callback Create GPIO level change callback +
wait_for_edge Wait for GPIO level change +
ADVANCED +
notify_open Request a notification handle +
notify_begin Start notifications for selected GPIO +
notify_pause Pause notifications +
notify_close Close a notification +
hardware_clock Start hardware clock on supported GPIO +
hardware_PWM Start hardware PWM on supported GPIO +
set_glitch_filter Set a glitch filter on a GPIO +
set_noise_filter Set a noise filter on a GPIO +
set_pad_strength Sets a pads drive strength +
get_pad_strength Gets a pads drive strength +
shell Executes a shell command +
Custom +
custom_1 User custom function 1 +
custom_2 User custom function 2 +
Events +
event_callback Sets a callback for an event +
event_trigger Triggers an event +
wait_for_event Wait for an event +
Scripts +
store_script Store a script +
run_script Run a stored script +
update_script Set a scripts parameters +
script_status Get script status and parameters +
stop_script Stop a running script +
delete_script Delete a stored script +
I2C +
i2c_open Opens an I2C device +
i2c_close Closes an I2C device +
i2c_write_quick SMBus write quick +
i2c_read_byte SMBus read byte +
i2c_write_byte SMBus write byte +
i2c_read_byte_data SMBus read byte data +
i2c_write_byte_data SMBus write byte data +
i2c_read_word_data SMBus read word data +
i2c_write_word_data SMBus write word data +
i2c_read_block_data SMBus read block data +
i2c_write_block_data SMBus write block data +
i2c_read_i2c_block_data SMBus read I2C block data +
i2c_write_i2c_block_data SMBus write I2C block data +
i2c_read_device Reads the raw I2C device +
i2c_write_device Writes the raw I2C device +
i2c_process_call SMBus process call +
i2c_block_process_call SMBus block process call +
i2c_zip Performs multiple I2C transactions +
I2C BIT BANG +
bb_i2c_open Opens GPIO for bit banging I2C +
bb_i2c_close Closes GPIO for bit banging I2C +
bb_i2c_zip Performs multiple bit banged I2C transactions +
I2C/SPI SLAVE +
bsc_xfer I2C/SPI as slave transfer +
bsc_i2c I2C as slave transfer +
SERIAL +
serial_open Opens a serial device +
serial_close Closes a serial device +
serial_read_byte Reads a byte from a serial device +
serial_write_byte Writes a byte to a serial device +
serial_read Reads bytes from a serial device +
serial_write Writes bytes to a serial device +
serial_data_available Returns number of bytes ready to be read +
SERIAL BIT BANG (read only) +
bb_serial_read_open Open a GPIO for bit bang serial reads +
bb_serial_read_close Close a GPIO for bit bang serial reads +
bb_serial_invert Invert serial logic (1 invert, 0 normal) +
bb_serial_read Read bit bang serial data from a GPIO +
SPI +
spi_open Opens a SPI device +
spi_close Closes a SPI device +
spi_read Reads bytes from a SPI device +
spi_write Writes bytes to a SPI device +
spi_xfer Transfers bytes with a SPI device +
SPI BIT BANG +
bb_spi_open Opens GPIO for bit banging SPI +
bb_spi_close Closes GPIO for bit banging SPI +
bb_spi_xfer Transfers bytes with bit banging SPI +
FILES +
file_open Opens a file +
file_close Closes a file +
file_read Reads bytes from a file +
file_write Writes bytes to a file +
file_seek Seeks to a position within a file +
file_list List files which match a pattern +
WAVES +
wave_clear Deletes all waveforms +
wave_add_new Starts a new waveform +
wave_add_generic Adds a series of pulses to the waveform +
wave_add_serial Adds serial data to the waveform +
wave_create Creates a waveform from added data +
wave_create_and_pad Creates a waveform of fixed size from added data +
wave_delete Deletes a waveform +
wave_send_once Transmits a waveform once +
wave_send_repeat Transmits a waveform repeatedly +
wave_send_using_mode Transmits a waveform in the chosen mode +
wave_chain Transmits a chain of waveforms +
wave_tx_at Returns the current transmitting waveform +
wave_tx_busy Checks to see if a waveform has ended +
wave_tx_stop Aborts the current waveform +
wave_get_cbs Length in cbs of the current waveform +
wave_get_max_cbs Absolute maximum allowed cbs +
wave_get_micros Length in microseconds of the current waveform +
wave_get_max_micros Absolute maximum allowed micros +
wave_get_pulses Length in pulses of the current waveform +
wave_get_max_pulses Absolute maximum allowed pulses +
UTILITIES +
get_current_tick Get current tick (microseconds) +
get_hardware_revision Get hardware revision +
get_pigpio_version Get the pigpio version +
pigpio.error_text Gets error text from error number +
pigpio.tickDiff Returns difference between two ticks +

class pi +

pigpio.pi(host, port, show_errors)

+Grants access to a Pi's GPIO. +

Parameters

host:= the host name of the Pi on which the pigpio daemon is
       running.  The default is localhost unless overridden by
       the PIGPIO_ADDR environment variable.


Parameters

port:= the port number on which the pigpio daemon is listening.
       The default is 8888 unless overridden by the PIGPIO_PORT
       environment variable.  The pigpio daemon must have been
       started with the same port number.


This connects to the pigpio daemon and reserves resources +to be used for sending commands and receiving notifications. +

An instance attribute connected may be used to check the +success of the connection. If the connection is established +successfully connected will be True, otherwise False. +

Example

pi = pigio.pi()              # use defaults
pi = pigpio.pi('mypi')       # specify host, default port
pi = pigpio.pi('mypi', 7777) # specify host and port

pi = pigpio.pi()             # exit script if no connection
if not pi.connected:
   exit()

__repr__()

+

bb_i2c_close(SDA)

+This function stops bit banging I2C on a pair of GPIO +previously opened with bb_i2c_open. +

Parameters

SDA:= 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. +

Example

pi.bb_i2c_close(SDA)

bb_i2c_open(SDA, SCL, baud)

+This function selects a pair of GPIO for bit banging I2C at a +specified baud rate. +

Bit banging I2C allows for certain operations which are not possible +with the standard I2C driver. +

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

Parameters

 SDA:= 0-31
 SCL:= 0-31
baud:= 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or +PI_GPIO_IN_USE. +

NOTE: +

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. +As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. +

Example

h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps

bb_i2c_zip(SDA, data)

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

Parameters

 SDA:= 0-31 (as used in a prior call to bb_i2c_open)
data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(count, data) = pi.bb_i2c_zip(
                   SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0])


The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain +their previous value until updated. +

No flags are currently defined. +

Any read I2C data is concatenated in the returned bytearray. +

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

bb_serial_invert(user_gpio, invert)

+Invert serial logic. +

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)
    invert:= 0-1 (1 invert, 0 normal)


Example

status = pi.bb_serial_invert(17, 1)

bb_serial_read(user_gpio)

+Returns data from the bit bang serial cyclic buffer. +

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

The bytes returned for each character depend upon the number of +data bits bb_bits specified in the bb_serial_read_open +command. +

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

Example

(count, data) = pi.bb_serial_read(4)

bb_serial_read_close(user_gpio)

+Closes a GPIO for bit bang reading of serial data. +

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


Example

status = pi.bb_serial_read_close(17)

bb_serial_read_open(user_gpio, baud, bb_bits)

+Opens a GPIO for bit bang reading of serial data. +

Parameters

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


The serial data is held in a cyclic buffer and is read using +bb_serial_read. +

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

Example

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

bb_spi_close(CS)

+This function stops bit banging SPI on a set of GPIO +opened with bb_spi_open. +

Parameters

CS:= 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. +

Example

pi.bb_spi_close(CS)

bb_spi_open(CS, MISO, MOSI, SCLK, baud, spi_flags)

+This function selects a set of GPIO for bit banging SPI at a +specified baud rate. +

Parameters

      CS := 0-31
    MISO := 0-31
    MOSI := 0-31
    SCLK := 0-31
    baud := 50-250000
spiFlags := see below


spiFlags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 +

Mode CPOL CPHA
 0     0    0
 1     0    1
 2     1    0
 3     1    1


The following constants may be used to set the mode: +

pigpio.SPI_MODE_0
pigpio.SPI_MODE_1
pigpio.SPI_MODE_2
pigpio.SPI_MODE_3


Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA +may be used. +

p is 0 if CS is active low (default) and 1 for active high. +pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag. +

T is 1 if the least significant bit is transmitted on MOSI first, +the default (0) shifts the most significant bit out first. +pigpio.SPI_TX_LSBFIRST may be used to set this flag. +

R is 1 if the least significant bit is received on MISO first, +the default (0) receives the most significant bit first. +pigpio.SPI_RX_LSBFIRST may be used to set this flag. +

The other bits in spiFlags should be set to zero. +

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or +PI_GPIO_IN_USE. +

If more than one device is connected to the SPI bus (defined by +SCLK, MOSI, and MISO) each must have its own CS. +

Example

bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2

bb_spi_xfer(CS, data)

+This function executes a bit banged SPI transfer. +

Parameters

  CS:= 0-31 (as used in a prior call to bb_spi_open)
data:= data to be sent


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

#!/usr/bin/env python

import pigpio

CE0=5
CE1=6
MISO=13
MOSI=19
SCLK=12

pi = pigpio.pi()
if not pi.connected:
   exit()

pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC
pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC

for i in range(256):

   count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value

   if count == 2:

      count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC

      if count == 2:

         set_val = data[1]

         count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC

         if count == 3:

            read_val = ((data[1]&3)<<8) | data[2]

            print("{} {}".format(set_val, read_val))

pi.bb_spi_close(CE0)
pi.bb_spi_close(CE1)

pi.stop()

bsc_i2c(i2c_address, data)

+This function allows the Pi to act as a slave I2C device. +

This function is not available on the BCM2711 (e.g. as +used in the Pi4B). +

The data bytes (if any) are written to the BSC transmit +FIFO and the bytes in the BSC receive FIFO are returned. +

Parameters

i2c_address:= the I2C slave address.
       data:= the data bytes to transmit.


The returned value is a tuple of the status, the number +of bytes read, and a bytearray containing the read bytes. +

See bsc_xfer for details of the status value. +

If there was an error the status will be less than zero +(and will contain the error code). +

Note that an i2c_address of 0 may be used to close +the BSC device and reassign the used GPIO as inputs. +

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

Example

#!/usr/bin/env python
import time
import pigpio

I2C_ADDR=0x13

def i2c(id, tick):
    global pi

    s, b, d = pi.bsc_i2c(I2C_ADDR)
    if b:
        if d[0] == ord('t'): # 116 send 'HH:MM:SS*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[11:19]))

        elif d[0] == ord('d'): # 100 send 'Sun Oct 30*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[:10]))

pi = pigpio.pi()

if not pi.connected:
    exit()

# Respond to BSC slave activity

e = pi.event_callback(pigpio.EVENT_BSC, i2c)

pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave

time.sleep(600)

e.cancel()

pi.bsc_i2c(0) # Disable BSC peripheral

pi.stop()


While running the above. +

$ i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

$ pigs i2co 1 0x13 0
0

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:13:58*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:14:29*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:23:16*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

bsc_xfer(bsc_control, data)

+This function provides a low-level interface to the SPI/I2C Slave +peripheral on the BCM chip. +

This peripheral allows the Pi to act as a hardware slave device +on an I2C or SPI bus. +

This is not a bit bang version and as such is OS timing +independent. The bus timing is handled directly by the chip. +

The output process is simple. You simply append data to the FIFO +buffer on the chip. This works like a queue, you add data to the +queue and the master removes it. +

I can't get SPI to work properly. I tried with a +control word of 0x303 and swapped MISO and MOSI. +

The function sets the BSC mode, writes any data in +the transmit buffer to the BSC transmit FIFO, and +copies any data in the BSC receive FIFO to the +receive buffer. +

Parameters

bsc_control:= see below
       data:= the data bytes to place in the transmit FIFO.


The returned value is a tuple of the status (see below), +the number of bytes read, and a bytearray containing the +read bytes. If there was an error the status will be less +than zero (and will contain the error code). +

Note that the control word sets the BSC mode. The BSC will +stay in that mode until a different control word is sent. +

GPIO used for models other than those based on the BCM2711. +

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset +to INPUT mode. +

bsc_control consists of the following bits: +

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document for full +details. +

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable BSC peripheral


The status has the following format: +

20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 S  S  S  S  S  R  R  R  R  R  T  T  T  T  T RB TE RF TF RE TB


Bits 0-15 are copied unchanged from the BSC FR register. See +pages 165-166 of the Broadcom peripherals document for full +details. +

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


Example

(status, count, data) = pi.bsc_xfer(0x330305, "Hello!")

callback(user_gpio, edge, func)

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

Parameters

user_gpio:= 0-31.
     edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.
     func:= user supplied callback function.


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

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


If a user callback is not specified a default tally callback is +provided which simply counts edges. The count may be retrieved +by calling the tally function. The count may be reset to zero +by calling the reset_tally function. +

The callback may be cancelled by calling the cancel function. +

A GPIO may have multiple callbacks (although I can't think of +a reason to do so). +

The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). +

The number of samples per second is given in the following table. +

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. +

The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. +

If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use read. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. +

Example

def cbf(gpio, level, tick):
   print(gpio, level, tick)

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

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

cb3 = pi.callback(17)

print(cb3.tally())

cb3.reset_tally()

cb1.cancel() # To cancel callback cb1.

clear_bank_1(bits)

+Clears GPIO 0-31 if the corresponding bit in bits is set. +

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user +is not allowed to write to one or more of the GPIO. +

Example

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

clear_bank_2(bits)

+Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user +is not allowed to write to one or more of the GPIO. +

Example

pi.clear_bank_2(0x1010)

custom_1(arg1, arg2, argx)

+Calls a pigpio function customised by the user. +

Parameters

arg1:= >=0, default 0.
arg2:= >=0, default 0.
argx:= extra arguments (each 0-255), default empty.


The returned value is an integer which by convention +should be >=0 for OK and <0 for error. +

Example

value = pi.custom_1()

value = pi.custom_1(23)

value = pi.custom_1(0, 55)

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

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

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

custom_2(arg1, argx, retMax)

+Calls a pigpio function customised by the user. +

Parameters

  arg1:= >=0, default 0.
  argx:= extra arguments (each 0-255), default empty.
retMax:= >=0, maximum number of bytes to return, default 8192.


The returned value is a tuple of the number of bytes +returned and a bytearray containing the bytes. If +there was an error the number of bytes read will be +less than zero (and will contain the error code). +

Example

(count, data) = pi.custom_2()

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

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

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

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

delete_script(script_id)

+Deletes a stored script. +

Parameters

script_id:= id of stored script.


Example

status = pi.delete_script(sid)

event_callback(event, func)

+Calls a user supplied function (a callback) whenever the +specified event is signalled. +

Parameters

event:= 0-31.
 func:= user supplied callback function.


The user supplied callback receives two parameters, the event id, +and the tick. +

If a user callback is not specified a default tally callback is +provided which simply counts events. The count may be retrieved +by calling the tally function. The count may be reset to zero +by calling the reset_tally function. +

The callback may be cancelled by calling the event_cancel function. +

An event may have multiple callbacks (although I can't think of +a reason to do so). +

Example

def cbf(event, tick):
   print(event, tick)

cb1 = pi.event_callback(22, cbf)

cb2 = pi.event_callback(4)

print(cb2.tally())

cb2.reset_tally()

cb1.event_cancel() # To cancel callback cb1.

event_trigger(event)

+This function signals the occurrence of an event. +

Parameters

event:= 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. +

An event is a signal used to inform one or more consumers +to start an action. Each consumer which has registered an +interest in the event (e.g. by calling event_callback) will +be informed by a callback. +

One event, EVENT_BSC (31) is predefined. This event is +auto generated on BSC slave activity. +

The meaning of other events is arbitrary. +

Note that other than its id and its tick there is no data associated +with an event. +

Example

pi.event_trigger(23)

file_close(handle)

+Closes the file associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to file_open).


Example

pi.file_close(handle)

file_list(fpattern)

+Returns a list of files which match a pattern. +

Parameters

fpattern:= file pattern to match.


Returns the number of returned bytes if OK, otherwise +PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. +

The pattern must match an entry in /opt/pigpio/access. The +pattern may contain wildcards. See file_open. +

NOTE +

The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. +

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

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

c, d = pi.file_list("/ram/p*.c")
if c > 0:
   print(d)

pi.stop()

file_open(file_name, file_mode)

+This function returns a handle to a file opened in a specified mode. +

Parameters

file_name:= the file to open.
file_mode:= the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, +PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE, +PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. +

Example

h = pi.file_open("/home/pi/shared/dir_3/file.txt",
        pigpio.FILE_WRITE | pigpio.FILE_CREATE)

pi.file_write(h, "Hello world")

pi.file_close(h)


File +

A file may only be opened if permission is granted by an entry +in /opt/pigpio/access. This is intended to allow remote access +to files in a more or less controlled manner. +

Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. +

Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. +

Suppose /opt/pigpio/access contains the following entries: +

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception +of file.txt. +

Files may be read in directory dir_2. +

Files may be read and written in directory dir_3. +

If a directory allows read, write, or read/write access then files +may be created in that directory. +

In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access: +

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode +

The mode may have the following values: +

ConstantValueMeaning
FILE_READ1open file for reading
FILE_WRITE2open file for writing
FILE_RW3open file for reading and writing


The following values may be or'd into the mode: +

NameValueMeaning
FILE_APPEND4All writes append data to the end of the file
FILE_CREATE8The file is created if it doesn't exist
FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner +read and write. +

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

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

handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ)

done = False

while not done:
   c, d = pi.file_read(handle, 60000)
   if c > 0:
      print(d)
   else:
      done = True

pi.file_close(handle)

pi.stop()

file_read(handle, count)

+Reads up to count bytes from the file associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to file_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.file_read(h2, 100)
if b > 0:
   # process read data

file_seek(handle, seek_offset, seek_from)

+Seeks to a position relative to the start, current position, +or end of the file. Returns the new position. +

Parameters

     handle:= >=0 (as returned by a prior call to file_open).
seek_offset:= byte offset.
  seek_from:= FROM_START, FROM_CURRENT, or FROM_END.


Example

new_pos = pi.file_seek(h, 100, pigpio.FROM_START)

cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT)

file_size = pi.file_seek(h, 0, pigpio.FROM_END)

file_write(handle, data)

+Writes the data bytes to the file associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to file_open).
  data:= the bytes to write.


Example

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

pi.file_write(h2, b'help')

pi.file_write(h2, "hello")

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

get_PWM_dutycycle(user_gpio)

+Returns the PWM dutycycle being used on the GPIO. +

Parameters

user_gpio:= 0-31.


Returns the PWM dutycycle. +

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

If a hardware clock is active on the GPIO the reported +dutycycle will be 500000 (500k) out of 1000000 (1M). +

If hardware PWM is active on the GPIO the reported dutycycle +will be out of a 1000000 (1M). +

Example

pi.set_PWM_dutycycle(4, 25)
print(pi.get_PWM_dutycycle(4))
25

pi.set_PWM_dutycycle(4, 203)
print(pi.get_PWM_dutycycle(4))
203

get_PWM_frequency(user_gpio)

+Returns the frequency of PWM being used on the GPIO. +

Parameters

user_gpio:= 0-31.


Returns the frequency (in Hz) used for the GPIO. +

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

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

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

Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_frequency(4))
800

get_PWM_range(user_gpio)

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

Parameters

user_gpio:= 0-31.


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

Example

pi.set_PWM_range(9, 500)
print(pi.get_PWM_range(9))
500

get_PWM_real_range(user_gpio)

+Returns the real (underlying) range of PWM values being +used on the GPIO. +

Parameters

user_gpio:= 0-31.


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

If hardware PWM is active on the GPIO the reported real range +will be approximately 250M divided by the set PWM frequency. +

Example

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_real_range(4))
250

get_current_tick()

+Returns the current system tick. +

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

Example

t1 = pi.get_current_tick()
time.sleep(1)
t2 = pi.get_current_tick()

get_hardware_revision()

+Returns the Pi's hardware revision number. +

The hardware revision is the last few characters on the +Revision line of /proc/cpuinfo. +

The revision number can be used to determine the assignment +of GPIO to pins (see
gpio). +

There are at least three types of board. +

Type 1 boards have hardware revision numbers of 2 and 3. +

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. +

Type 3 boards have hardware revision numbers of 16 or greater. +

If the hardware revision can not be found or is not a valid +hexadecimal number the function returns 0. +

Example

print(pi.get_hardware_revision())
2

get_mode(gpio)

+Returns the GPIO mode. +

Parameters

gpio:= 0-53.


Returns a value as follows +

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


Example

print(pi.get_mode(0))
4

get_pad_strength(pad)

+This function returns the pad drive strength in mA. +

Parameters

pad:= 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. +

PadGPIO
00-27
128-45
246-53


Example

strength = pi.get_pad_strength(0) # Get pad 0 strength.

get_pigpio_version()

+Returns the pigpio software version. +

Example

v = pi.get_pigpio_version()

get_servo_pulsewidth(user_gpio)

+Returns the servo pulsewidth being used on the GPIO. +

Parameters

user_gpio:= 0-31.


Returns the servo pulsewidth. +

Example

pi.set_servo_pulsewidth(4, 525)
print(pi.get_servo_pulsewidth(4))
525

pi.set_servo_pulsewidth(4, 2130)
print(pi.get_servo_pulsewidth(4))
2130

gpio_trigger(user_gpio, pulse_len, level)

+Send a trigger pulse to a GPIO. The GPIO is set to +level for pulse_len microseconds and then reset to not level. +

Parameters

user_gpio:= 0-31
pulse_len:= 1-100
    level:= 0-1


Example

pi.gpio_trigger(23, 10, 1)

hardware_PWM(gpio, PWMfreq, PWMduty)

+Starts hardware PWM on a GPIO at the specified frequency +and dutycycle. Frequencies above 30MHz are unlikely to work. +

NOTE: Any waveform started by wave_send_once, +wave_send_repeat, or wave_chain will be cancelled. +

This function is only valid if the pigpio main clock is PCM. +The main clock defaults to PCM but may be overridden when the +pigpio daemon is started (option -t). +

Parameters

   gpio:= see descripton
PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711).
PWMduty:= 0 (off) to 1000000 (1M)(fully on).


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. +

The same PWM channel is available on multiple GPIO. +The latest frequency and dutycycle setting will be used +by all GPIO which share a PWM channel. +

The GPIO must be one of the following: +

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the +integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). +

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

There will only be a million steps for a PWMfreq of 250 +(375 for the BCM2711). Lower frequencies will have more +steps and higher frequencies will have fewer steps. +PWMduty is automatically scaled to take this into account. +

Example

pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle

pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle

hardware_clock(gpio, clkfreq)

+Starts a hardware clock on a GPIO at the specified frequency. +Frequencies above 30MHz are unlikely to work. +

Parameters

   gpio:= see description
clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, +PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. +

The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. +

The GPIO must be one of the following: +

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will +likely crash the Pi. The password is given by or'ing 0x5A000000 +with the GPIO number. +

Example

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

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

i2c_block_process_call(handle, reg, data)

+Writes data bytes to the specified register of the device +associated with handle and reads a device specified number +of bytes of data in return. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


The SMBus 2.0 documentation states that a minimum of 1 byte may +be sent and a minimum of 1 byte may be received. The total +number of bytes sent/received must be 32 or less. +

SMBus 2.0 5.5.8 - Block write-block read. +S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A]
   S Addr Rd [A] [Count] A [Data] ... A P


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00')

(b, d) = pi.i2c_block_process_call(h, 10, b'abcdr')

(b, d) = pi.i2c_block_process_call(h, 10, "abracad")

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

i2c_close(handle)

+Closes the I2C device associated with handle. +

Parameters

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


Example

pi.i2c_close(h)

i2c_open(i2c_bus, i2c_address, i2c_flags)

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

Parameters

    i2c_bus:= >=0.
i2c_address:= 0-0x7F.
  i2c_flags:= 0, no flags are currently defined.


Physically buses 0 and 1 are available on the Pi. Higher +numbered buses will be available if a kernel supported bus +multiplexor is being used. +

The GPIO used are given in the following table. +

SDASCL
I2C 001
I2C 123


For the SMBus commands the low level transactions are shown +at the end of the function description. The following +abbreviations are used: +

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.
Addr  (7 bits): I2C 7 bit address.
reg   (8 bits): Command byte, which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.


Example

h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1

i2c_process_call(handle, reg, word_val)

+Writes 16 bits of data to the specified register of the device +associated with handle and reads 16 bits of data in return. +

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.6 - Process call. +S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

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

i2c_read_block_data(handle, reg)

+Reads a block of up to 32 bytes from the specified register of +the device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.7 - Block read. +S Addr Wr [A] reg [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P


The amount of returned data is set by the device. +

The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.i2c_read_block_data(h, 10)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_byte(handle)

+Reads a single byte from the device associated with handle. +

Parameters

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


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


Example

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

i2c_read_byte_data(handle, reg)

+Reads a single byte from the specified register of the device +associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read byte. +S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P


Example

# read byte from reg 17 of device 2
b = pi.i2c_read_byte_data(2, 17)

# read byte from reg  1 of device 0
b = pi.i2c_read_byte_data(0, 1)

i2c_read_device(handle, count)

+Returns count bytes read from the raw device associated +with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
 count:= >0, the number of bytes to read.


S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(count, data) = pi.i2c_read_device(h, 12)

i2c_read_i2c_block_data(handle, reg, count)

+Reads count bytes from the specified register of the device +associated with handle . The count may be 1-32. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
 count:= >0, the number of bytes to read.


S Addr Wr [A] reg [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.i2c_read_i2c_block_data(h, 4, 32)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_word_data(handle, reg)

+Reads a single 16 bit word from the specified register of the +device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read word. +S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

# read word from reg 2 of device 3
w = pi.i2c_read_word_data(3, 2)

# read word from reg 7 of device 2
w = pi.i2c_read_word_data(2, 7)

i2c_write_block_data(handle, reg, data)

+Writes up to 32 bytes to the specified register of the device +associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


SMBus 2.0 5.5.7 - Block write. +S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A]
   datan [A] P


Example

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

pi.i2c_write_block_data(4, 5, "data bytes")

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

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

i2c_write_byte(handle, byte_val)

+Sends a single byte to the device associated with handle. +

Parameters

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


SMBus 2.0 5.5.2 - Send byte. +S Addr Wr [A] byte_val [A] P


Example

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

i2c_write_byte_data(handle, reg, byte_val)

+Writes a single byte to the specified register of the device +associated with handle. +

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.4 - Write byte. +S Addr Wr [A] reg [A] byte_val [A] P


Example

# send byte 0xC5 to reg 2 of device 1
pi.i2c_write_byte_data(1, 2, 0xC5)

# send byte 9 to reg 4 of device 2
pi.i2c_write_byte_data(2, 4, 9)

i2c_write_device(handle, data)

+Writes the data bytes to the raw device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the bytes to write.


S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P


Example

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

pi.i2c_write_device(h, b"help")

pi.i2c_write_device(h, 'help')

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

i2c_write_i2c_block_data(handle, reg, data)

+Writes data bytes to the specified register of the device +associated with handle . 1-32 bytes may be written. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P


Example

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

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

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

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

i2c_write_quick(handle, bit)

+Sends a single bit to the device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   bit:= 0 or 1, the value to write.


SMBus 2.0 5.5.1 - Quick command. +S Addr bit [A] P


Example

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

i2c_write_word_data(handle, reg, word_val)

+Writes a single 16 bit word to the specified register of the +device associated with handle. +

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.4 - Write word. +S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P


Example

# send word 0xA0C5 to reg 5 of device 4
pi.i2c_write_word_data(4, 5, 0xA0C5)

# send word 2 to reg 2 of device 5
pi.i2c_write_word_data(5, 2, 23)

i2c_zip(handle, data)

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

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0])


The following command codes are supported: +

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. +The flags default to 0. The address and flags maintain their +previous value until updated. +

Any read I2C data is concatenated in the returned bytearray. +

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

notify_begin(handle, bits)

+Starts notifications on a handle. +

Parameters

handle:= >=0 (as returned by a prior call to notify_open)
  bits:= a 32 bit mask indicating the GPIO to be notified.


The notification sends state changes for each GPIO whose +corresponding bit in bits is set. +

The following code starts notifications for GPIO 1, 4, +6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). +

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_close(handle)

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

Parameters

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


Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_close(h)
   ...

notify_open()

+Returns a notification handle (>=0). +

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

Pipes are only accessible from the local machine so this +function serves no purpose if you are using Python from a +remote machine. The in-built (socket) notifications +provided by
callback should be used instead. +

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

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

Notifications have the following structure: +

H seqno
H flags
I tick
I level


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

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, +PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. +

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the +flags indicate a GPIO which has had a watchdog timeout. +

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep +alive signal on the pipe/socket and is sent once a minute +in the absence of other notification activity. +

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the +flags indicate an event which has been triggered. +

tick: the number of microseconds since system boot. It wraps +around after 1h12m. +

level: indicates the level of each GPIO. If bit 1<<x is set +then GPIO x is high. +

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_pause(handle)

+Pauses notifications on a handle. +

Parameters

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


Notifications for the handle are suspended until +notify_begin is called again. +

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_pause(h)
   ...
   pi.notify_begin(h, 1234)
   ...

read(gpio)

+Returns the GPIO level. +

Parameters

gpio:= 0-53.


Example

pi.set_mode(23, pigpio.INPUT)

pi.set_pull_up_down(23, pigpio.PUD_DOWN)
print(pi.read(23))
0

pi.set_pull_up_down(23, pigpio.PUD_UP)
print(pi.read(23))
1

read_bank_1()

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

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

Example

print(bin(pi.read_bank_1()))
0b10010100000011100100001001111

read_bank_2()

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

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

Example

print(bin(pi.read_bank_2()))
0b1111110000000000000000

run_script(script_id, params)

+Runs a stored script. +

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.run_script(sid, [par1, par2])

s = pi.run_script(sid)

s = pi.run_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

script_status(script_id)

+Returns the run status of a stored script as well as the +current values of parameters 0 to 9. +

Parameters

script_id:= id of stored script.


The run status may be +

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The return value is a tuple of run status and a list of +the 10 parameters. On error the run status will be negative +and the parameter list will be empty. +

Example

(s, pars) = pi.script_status(sid)

serial_close(handle)

+Closes the serial device associated with handle. +

Parameters

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


Example

pi.serial_close(h1)

serial_data_available(handle)

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

Parameters

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


Example

rdy = pi.serial_data_available(h1)

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

serial_open(tty, baud, ser_flags)

+Returns a handle for the serial tty device opened +at baud bits per second. The device name must start +with /dev/tty or /dev/serial. +

Parameters

      tty:= the serial device to open.
     baud:= baud rate in bits per second, see below.
ser_flags:= 0, no flags are currently defined.


Normally you would only use the serial_* functions if +you are or will be connecting to the Pi over a network. If +you will always run on the local Pi use the standard serial +module instead. +

The baud rate must be one of 50, 75, 110, 134, 150, +200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, +38400, 57600, 115200, or 230400. +

Example

h1 = pi.serial_open("/dev/ttyAMA0", 300)

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

h3 = pi.serial_open("/dev/serial0", 9600)

serial_read(handle, count)

+Reads up to count bytes from the device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
 count:= >0, the number of bytes to read (defaults to 1000).


The returned value is a tuple of the number of bytes read and +a bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

If no data is ready a bytes read of zero is returned. +Example

(b, d) = pi.serial_read(h2, 100)
if b > 0:
   # process read data

serial_read_byte(handle)

+Returns a single byte from the device associated with handle. +

Parameters

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


If no data is ready a negative error code will be returned. +

Example

b = pi.serial_read_byte(h1)

serial_write(handle, data)

+Writes the data bytes to the device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
  data:= the bytes to write.


Example

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

pi.serial_write(h2, b'help')

pi.serial_write(h2, "hello")

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

serial_write_byte(handle, byte_val)

+Writes a single byte to the device associated with handle. +

Parameters

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


Example

pi.serial_write_byte(h1, 23)

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

set_PWM_dutycycle(user_gpio, dutycycle)

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

Parameters

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


The set_PWM_range function can change the default range of 255. +

Example

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

set_PWM_frequency(user_gpio, frequency)

+Sets the frequency (in Hz) of the PWM to be used on the GPIO. +

Parameters

user_gpio:= 0-31.
frequency:= >=0 Hz


Returns the numerically closest frequency if OK, otherwise +PI_BAD_USER_GPIO or PI_NOT_PERMITTED. +

If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. +

Each GPIO can be independently set to one of 18 different +PWM frequencies. +

The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. +

The frequencies for each sample rate are: +

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4,100000)
print(pi.get_PWM_frequency(4))
8000

set_PWM_range(user_gpio, range_)

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

Parameters

user_gpio:= 0-31.
   range_:= 25-40000.


Example

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

set_bank_1(bits)

+Sets GPIO 0-31 if the corresponding bit in bits is set. +

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user +is not allowed to write to one or more of the GPIO. +

Example

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

set_bank_2(bits)

+Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. +

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user +is not allowed to write to one or more of the GPIO. +

Example

pi.set_bank_2(0x303)

set_glitch_filter(user_gpio, steady)

+Sets a glitch filter on a GPIO. +

Level changes on the GPIO are not reported unless the level +has been stable for at least steady microseconds. The +level is then reported. Level changes of less than steady +microseconds are ignored. +

Parameters

user_gpio:= 0-31
   steady:= 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback and wait_for_edge. +

It does not affect levels read by read, +read_bank_1, or read_bank_2. +

Each (stable) edge will be timestamped steady +microseconds after it was first detected. +

Example

pi.set_glitch_filter(23, 100)

set_mode(gpio, mode)

+Sets the GPIO mode. +

Parameters

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


Example

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

set_noise_filter(user_gpio, steady, active)

+Sets a noise filter on a GPIO. +

Level changes on the GPIO are ignored until a level which has +been stable for steady microseconds is detected. Level +changes on the GPIO are then reported for active +microseconds after which the process repeats. +

Parameters

user_gpio:= 0-31
   steady:= 0-300000
   active:= 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. +

This filter affects the GPIO samples returned to callbacks set up +with callback and wait_for_edge. +

It does not affect levels read by read, +read_bank_1, or read_bank_2. +

Level changes before and after the active period may +be reported. Your software must be designed to cope with +such reports. +

Example

pi.set_noise_filter(23, 1000, 5000)

set_pad_strength(pad, pad_strength)

+This function sets the pad drive strength in mA. +

Parameters

         pad:= 0-2, the pad to set.
pad_strength:= 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. +

PadGPIO
00-27
128-45
246-53


Example

pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA.

set_pull_up_down(gpio, pud)

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

Parameters

gpio:= 0-53.
 pud:= PUD_UP, PUD_DOWN, PUD_OFF.


Example

pi.set_pull_up_down(17, pigpio.PUD_OFF)
pi.set_pull_up_down(23, pigpio.PUD_UP)
pi.set_pull_up_down(24, pigpio.PUD_DOWN)

set_servo_pulsewidth(user_gpio, pulsewidth)

+Starts (500-2500) or stops (0) servo pulses on the GPIO. +

Parameters

 user_gpio:= 0-31.
pulsewidth:= 0 (off),
             500 (most anti-clockwise) - 2500 (most clockwise).


The selected pulsewidth will continue to be transmitted until +changed by a subsequent call to set_servo_pulsewidth. +

The pulsewidths supported by servos varies and should probably +be determined by experiment. A value of 1500 should always be +safe and represents the mid-point of rotation. +

You can DAMAGE a servo if you command it to move beyond its +limits. +

Example

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

set_watchdog(user_gpio, wdog_timeout)

+Sets a watchdog timeout for a GPIO. +

Parameters

   user_gpio:= 0-31.
wdog_timeout:= 0-60000.


The watchdog is nominally in milliseconds. +

Only one watchdog may be registered per GPIO. +

The watchdog may be cancelled by setting timeout to 0. +

Once a watchdog has been started callbacks for the GPIO +will be triggered every timeout interval after the last +GPIO activity. +

The callback will receive the special level TIMEOUT. +

Example

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

shell(shellscr, pstring)

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

Parameters

shellscr:= the name of the script, only alphanumerics,
              '-' and '_' are allowed in the name
pstring := the parameter string to pass to the script


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

shellscr must exist in /opt/pigpio/cgi and must be executable. +

The returned exit status is normally 256 times that set by +the shell script exit function. If the script can't be +found 32512 will be returned. +

The following table gives some example returned statuses: +

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = pi.shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = pi.shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = pi.shell("scr1", "\"hello string with spaces world\"");

spi_close(handle)

+Closes the SPI device associated with handle. +

Parameters

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


Example

pi.spi_close(h)

spi_open(spi_channel, baud, spi_flags)

+Returns a handle for the SPI device on the channel. Data +will be transferred at baud bits per second. The flags +may be used to modify the default behaviour of 4-wire +operation, mode 0, active low chip select. +

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


Parameters

spi_channel:= 0-1 (0-2 for the auxiliary SPI).
       baud:= 32K-125M (values above 30M are unlikely to work).
  spi_flags:= see below.


spi_flags consists of the least significant 22 bits. +

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. +

WARNING: modes 1 and 3 do not appear to work on +the auxiliary SPI. +

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 spi_read, spi_write, and spi_xfer functions +transfer data packed into 1, 2, or 4 bytes according to +the word size in bits. +

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

Multi-byte transfers are made in least significant byte +first order. +

E.g. to transfer 32 11-bit words data should +contain 64 bytes. +

E.g. to transfer the 14 bit value 0x1ABC send the +bytes 0xBC followed by 0x1A. +

The other bits in flags should be set to zero. +

Example

# open SPI device on channel 1 in mode 3 at 50000 bits per second

h = pi.spi_open(1, 50000, 3)

spi_read(handle, count)

+Reads count bytes from the SPI device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(b, d) = pi.spi_read(h, 60) # read 60 bytes from device h
if b == 60:
   # process read data
else:
   # error path

spi_write(handle, data)

+Writes the data bytes to the SPI device associated with handle. +

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


Example

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

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

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

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

spi_xfer(handle, data)

+Writes the data bytes to the SPI device associated with handle, +returning the data bytes read from the device. +

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


The returned value is a tuple of the number of bytes read and a +bytearray containing the bytes. If there was an error the +number of bytes read will be less than zero (and will contain +the error code). +

Example

(count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00')

(count, rx_data) = pi.spi_xfer(h, [1, 128, 0])

(count, rx_data) = pi.spi_xfer(h, b"hello")

(count, rx_data) = pi.spi_xfer(h, "hello")

stop()

+Release pigpio resources. +

Example

pi.stop()

stop_script(script_id)

+Stops a running script. +

Parameters

script_id:= id of stored script.


Example

status = pi.stop_script(sid)

store_script(script)

+Store a script for later execution. +

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for +details. +

Parameters

script:= the script text as a series of bytes.


Returns a >=0 script id if OK. +

Example

sid = pi.store_script(
   b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0')

update_script(script_id, params)

+Sets the parameters of a script. The script may or +may not be running. The first parameters of the script are +overwritten with the new values. +

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.update_script(sid, [par1, par2])

s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

wait_for_edge(user_gpio, edge, wait_timeout)

+Wait for an edge event on a GPIO. +

Parameters

   user_gpio:= 0-31.
        edge:= EITHER_EDGE, RISING_EDGE (default), or
               FALLING_EDGE.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the edge is detected or after +the number of seconds specified by timeout has expired. +

Do not use this function for precise timing purposes, +the edge is only checked 20 times a second. Whenever +you need to know the accurate time of GPIO events use +a callback function. +

The function returns True if the edge is detected, +otherwise False. +

Example

if pi.wait_for_edge(23):
   print("Rising edge detected")
else:
   print("wait for edge timed out")

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

wait_for_event(event, wait_timeout)

+Wait for an event. +

Parameters

       event:= 0-31.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the event is signalled or after +the number of seconds specified by timeout has expired. +

The function returns True if the event is detected, +otherwise False. +

Example

if pi.wait_for_event(23):
   print("event detected")
else:
   print("wait for event timed out")

wave_add_generic(pulses)

+Adds a list of pulses to the current waveform. +

Parameters

pulses:= list of pulses to add to the waveform.


Returns the new total number of pulses in the current waveform. +

The pulses are interleaved in time order within the existing +waveform (if any). +

Merging allows the waveform to be built in parts, that is the +settings for GPIO#1 can be added, and then GPIO#2 etc. +

If the added waveform is intended to start after or within +the existing waveform then the first pulse should consist +solely of a delay. +

Example

G1=4
G2=24

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

flash_500=[] # flash every 500 ms
flash_100=[] # flash every 100 ms

#                              ON     OFF  DELAY

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

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

pi.wave_clear() # clear any existing waveforms

pi.wave_add_generic(flash_500) # 500 ms flashes
f500 = pi.wave_create() # create and save id

pi.wave_add_generic(flash_100) # 100 ms flashes
f100 = pi.wave_create() # create and save id

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_send_repeat(f100)

time.sleep(4)

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_tx_stop() # stop waveform

pi.wave_clear() # clear all waveforms

wave_add_new()

+Starts a new empty waveform. +

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

Example

pi.wave_add_new()

wave_add_serial(user_gpio, baud, data, offset, bb_bits, bb_stop)

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

Parameters

user_gpio:= GPIO to transmit data.  You must set the GPIO mode
            to output.
     baud:= 50-1000000 bits per second.
     data:= the bytes to write.
   offset:= number of microseconds from the start of the
            waveform, default 0.
  bb_bits:= number of data bits, default 8.
  bb_stop:= number of stop half bits, default 2.


Returns the new total number of pulses in the current waveform. +

The serial data is formatted as one start bit, bb_bits +data bits, and bb_stop/2 stop bits. +

It is legal to add serial data streams with different baud +rates to the same waveform. +

The bytes required for each character depend upon bb_bits. +

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

Example

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

pi.wave_add_serial(4, 300, b"Hello world")

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

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

wave_chain(data)

+This function transmits a chain of waveforms. +

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

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

Returns 0 if OK, otherwise PI_CHAIN_NESTING, +PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, +PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, +or PI_BAD_WAVE_ID. +

Each wave is transmitted in the order specified. A wave +may occur multiple times per chain. +

A blocks of waves may be transmitted multiple times by +using the loop commands. The block is bracketed by loop +start and end commands. Loops may be nested. +

Delays between waves may be added with the delay command. +

The following command codes are supported: +

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#!/usr/bin/env python

import time
import pigpio

WAVES=5
GPIO=4

wid=[0]*WAVES

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

pi.set_mode(GPIO, pigpio.OUTPUT);

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

   wid[i] = pi.wave_create();

pi.wave_chain([
   wid[4], wid[3], wid[2],       # transmit waves 4+3+2
   255, 0,                       # loop start
      wid[0], wid[0], wid[0],    # transmit waves 0+0+0
      255, 0,                    # loop start
         wid[0], wid[1],         # transmit waves 0+1
         255, 2, 0x88, 0x13,     # delay 5000us
      255, 1, 30, 0,             # loop end (repeat 30 times)
      255, 0,                    # loop start
         wid[2], wid[3], wid[0], # transmit waves 2+3+0
         wid[3], wid[1], wid[2], # transmit waves 3+1+2
      255, 1, 10, 0,             # loop end (repeat 10 times)
   255, 1, 5, 0,                 # loop end (repeat 5 times)
   wid[4], wid[4], wid[4],       # transmit waves 4+4+4
   255, 2, 0x20, 0x4E,           # delay 20000us
   wid[0], wid[0], wid[0],       # transmit waves 0+0+0
   ])

while pi.wave_tx_busy():
   time.sleep(0.1);

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

pi.stop()

wave_clear()

+Clears all waveforms and any data added by calls to the +wave_add_* functions. +

Example

pi.wave_clear()

wave_create()

+Creates a waveform from the data provided by the prior calls +to the wave_add_* functions. +

Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, +PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

The data provided by the wave_add_* functions is consumed by +this function. +

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

Normal usage would be +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create to create the waveform and get a unique id +

Repeat steps 2 and 3 as needed. +

Step 4. wave_send_* with the id of the waveform to transmit. +

A waveform comprises one or more pulses. +

A pulse specifies +

1) the GPIO to be switched on at the start of the pulse. +2) the GPIO to be switched off at the start of the pulse. +3) the delay in microseconds before the next pulse. +

Any or all the fields can be zero. It doesn't make any sense +to set all the fields to zero (the pulse will be ignored). +

When a waveform is started each pulse is executed in order with +the specified delay between the pulse and the next. +

Example

wid = pi.wave_create()

wave_create_and_pad(percent)

+This function creates a waveform like wave_create but pads the consumed +resources. Where percent gives the percentage of the resources to use +(in terms of the theoretical maximum, not the current amount free). +This allows the reuse of deleted waves while a transmission is active. +

Upon success a wave id greater than or equal to 0 is returned, otherwise +PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions are consumed by this +function. +

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

A usage would be the creation of two waves where one is filled while the other +is being transmitted. Each wave is assigned 50% of the available resources. +This buffer structure allows the transmission of infinite wave sequences. +

Normal usage: +

Step 1. wave_clear to clear all waveforms and added data. +

Step 2. wave_add_* calls to supply the waveform data. +

Step 3. wave_create_and_pad to create a waveform of uniform size. +

Step 4. wave_send_* with the id of the waveform to transmit. +

Repeat steps 2-4 as needed. +

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

Example

wid = pi.wave_create(50)

wave_delete(wave_id)

+This function deletes the waveform with id wave_id. +

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

The wave is flagged for deletion. The resources used by the wave +will only be reused when either of the following apply. +

- all waves with higher numbered wave ids have been deleted or have +been flagged for deletion. +

- a new wave is created which uses exactly the same resources as +the current wave (see the C source for gpioWaveCreate for details). +

Example

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

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

wave_get_cbs()

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

Example

cbs = pi.wave_get_cbs()

wave_get_max_cbs()

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

Example

cbs = pi.wave_get_max_cbs()

wave_get_max_micros()

+Returns the maximum possible size of a waveform in microseconds. +

Example

micros = pi.wave_get_max_micros()

wave_get_max_pulses()

+Returns the maximum possible size of a waveform in pulses. +

Example

pulses = pi.wave_get_max_pulses()

wave_get_micros()

+Returns the length in microseconds of the current waveform. +

Example

micros = pi.wave_get_micros()

wave_get_pulses()

+Returns the length in pulses of the current waveform. +

Example

pulses = pi.wave_get_pulses()

wave_send_once(wave_id)

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

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

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

Example

cbs = pi.wave_send_once(wid)

wave_send_repeat(wave_id)

+Transmits the waveform with id wave_id. The waveform repeats +until wave_tx_stop is called or another call to wave_send_* +is made. +

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

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

Example

cbs = pi.wave_send_repeat(wid)

wave_send_using_mode(wave_id, mode)

+Transmits the waveform with id wave_id using mode mode. +

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).
   mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT,
          WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC.


WAVE_MODE_ONE_SHOT: same as wave_send_once. +

WAVE_MODE_REPEAT same as wave_send_repeat. +

WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries +to sync with the previous waveform. +

WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries +to sync with the previous waveform. +

WARNING: bad things may happen if you delete the previous +waveform before it has been synced to the new waveform. +

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

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

Example

cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC)

wave_tx_at()

+Returns the id of the waveform currently being +transmitted. +

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

WAVE_NOT_FOUND (9998) - transmitted wave not found. +NO_TX_WAVE (9999) - no wave being transmitted. +

Example

wid = pi.wave_tx_at()

wave_tx_busy()

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

Example

pi.wave_send_once(0) # send first waveform

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

pi.wave_send_once(1) # send next waveform

wave_tx_repeat()

+This function is deprecated and has beeen removed. +

Use
wave_create/wave_send_* instead. +

wave_tx_start()

+This function is deprecated and has been removed. +

Use
wave_create/wave_send_* instead. +

wave_tx_stop()

+Stops the transmission of the current waveform. +

This function is intended to stop a waveform started with +wave_send_repeat. +

Example

pi.wave_send_repeat(3)

time.sleep(5)

pi.wave_tx_stop()

write(gpio, level)

+Sets the GPIO level. +

Parameters

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


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

Example

pi.set_mode(17, pigpio.OUTPUT)

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

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

class pulse +

pigpio.pulse(gpio_on, gpio_off, delay)

+Initialises a pulse. +

Parameters

 gpio_on:= the GPIO to switch on at the start of the pulse.
gpio_off:= the GPIO to switch off at the start of the pulse.
   delay:= the delay in microseconds before the next pulse.

FUNCTIONS

pigpio.error_text(errnum)

+Returns a text description of a pigpio error. +

Parameters

errnum:= <0, the error number


Example

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

pigpio.tickDiff(t1, t2)

+Returns the microsecond difference between two ticks. +

Parameters

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


Example

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

pigpio.u2i(uint32)

+Converts a 32 bit unsigned number to signed. +

Parameters

uint32:= an unsigned 32 bit number


Example

print(u2i(4294967272))
-24
print(u2i(37))
37

PARAMETERS

active: 0-1000000

The number of microseconds level changes are reported for once +a noise filter has been triggered (by steady microseconds of +a stable level). +

arg1:

An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

arg2:

An unsigned argument passed to a user customised function. Its +meaning is defined by the customiser. +

argx:

An array of bytes passed to a user customised function. +Its meaning and content is defined by the customiser. +

baud:

The speed of serial communication (I2C, SPI, serial link, waves) +in bits per second. +

bb_bits: 1-32

The number of data bits to be used when adding serial data to a +waveform. +

bb_stop: 2-8

The number of (half) stop bits to be used when adding serial data +to a waveform. +

bit: 0-1

A value of 0 or 1. +

bits: 32 bit number

A mask used to select GPIO to be operated on. If bit n is set +then GPIO n is selected. A convenient way of setting bit n is to +bit or in the value (1<<n). +

To select GPIO 1, 7, 23 +

bits = (1<<1) | (1<<7) | (1<<23) +

bsc_control:

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

Bits 0-13 are copied unchanged to the BSC CR register. See +pages 163-165 of the Broadcom peripherals document. +

byte_val: 0-255

A whole number. +

clkfreq: 4689-250M (13184-375M for the BCM2711)

The hardware clock frequency. +

connected:

True if a connection was established, False otherwise. +

count:

The number of bytes of data to be transferred. +

CS:

The GPIO used for the slave select signal when bit banging SPI. +

data:

Data to be transmitted, a series of bytes. +

delay: >=1

The length of a pulse in microseconds. +

dutycycle: 0-range_

A number between 0 and range_. +

The dutycycle sets the proportion of time on versus time off during each +PWM cycle. +

DutycycleOn time
0Off
range_ * 0.2525% On
range_ * 0.5050% On
range_ * 0.7575% On
range_Fully On

edge: 0-2

EITHER_EDGE = 2
FALLING_EDGE = 1
RISING_EDGE = 0

errnum: <0

PI_BAD_USER_GPIO = -2
PI_BAD_GPIO = -3
PI_BAD_MODE = -4
PI_BAD_LEVEL = -5
PI_BAD_PUD = -6
PI_BAD_PULSEWIDTH = -7
PI_BAD_DUTYCYCLE = -8
PI_BAD_WDOG_TIMEOUT = -15
PI_BAD_DUTYRANGE = -21
PI_NO_HANDLE = -24
PI_BAD_HANDLE = -25
PI_BAD_WAVE_BAUD = -35
PI_TOO_MANY_PULSES = -36
PI_TOO_MANY_CHARS = -37
PI_NOT_SERIAL_GPIO = -38
PI_NOT_PERMITTED = -41
PI_SOME_PERMITTED = -42
PI_BAD_WVSC_COMMND = -43
PI_BAD_WVSM_COMMND = -44
PI_BAD_WVSP_COMMND = -45
PI_BAD_PULSELEN = -46
PI_BAD_SCRIPT = -47
PI_BAD_SCRIPT_ID = -48
PI_BAD_SER_OFFSET = -49
PI_GPIO_IN_USE = -50
PI_BAD_SERIAL_COUNT = -51
PI_BAD_PARAM_NUM = -52
PI_DUP_TAG = -53
PI_TOO_MANY_TAGS = -54
PI_BAD_SCRIPT_CMD = -55
PI_BAD_VAR_NUM = -56
PI_NO_SCRIPT_ROOM = -57
PI_NO_MEMORY = -58
PI_SOCK_READ_FAILED = -59
PI_SOCK_WRIT_FAILED = -60
PI_TOO_MANY_PARAM = -61
PI_SCRIPT_NOT_READY = -62
PI_BAD_TAG = -63
PI_BAD_MICS_DELAY = -64
PI_BAD_MILS_DELAY = -65
PI_BAD_WAVE_ID = -66
PI_TOO_MANY_CBS = -67
PI_TOO_MANY_OOL = -68
PI_EMPTY_WAVEFORM = -69
PI_NO_WAVEFORM_ID = -70
PI_I2C_OPEN_FAILED = -71
PI_SER_OPEN_FAILED = -72
PI_SPI_OPEN_FAILED = -73
PI_BAD_I2C_BUS = -74
PI_BAD_I2C_ADDR = -75
PI_BAD_SPI_CHANNEL = -76
PI_BAD_FLAGS = -77
PI_BAD_SPI_SPEED = -78
PI_BAD_SER_DEVICE = -79
PI_BAD_SER_SPEED = -80
PI_BAD_PARAM = -81
PI_I2C_WRITE_FAILED = -82
PI_I2C_READ_FAILED = -83
PI_BAD_SPI_COUNT = -84
PI_SER_WRITE_FAILED = -85
PI_SER_READ_FAILED = -86
PI_SER_READ_NO_DATA = -87
PI_UNKNOWN_COMMAND = -88
PI_SPI_XFER_FAILED = -89
PI_NO_AUX_SPI = -91
PI_NOT_PWM_GPIO = -92
PI_NOT_SERVO_GPIO = -93
PI_NOT_HCLK_GPIO = -94
PI_NOT_HPWM_GPIO = -95
PI_BAD_HPWM_FREQ = -96
PI_BAD_HPWM_DUTY = -97
PI_BAD_HCLK_FREQ = -98
PI_BAD_HCLK_PASS = -99
PI_HPWM_ILLEGAL = -100
PI_BAD_DATABITS = -101
PI_BAD_STOPBITS = -102
PI_MSG_TOOBIG = -103
PI_BAD_MALLOC_MODE = -104
PI_BAD_SMBUS_CMD = -107
PI_NOT_I2C_GPIO = -108
PI_BAD_I2C_WLEN = -109
PI_BAD_I2C_RLEN = -110
PI_BAD_I2C_CMD = -111
PI_BAD_I2C_BAUD = -112
PI_CHAIN_LOOP_CNT = -113
PI_BAD_CHAIN_LOOP = -114
PI_CHAIN_COUNTER = -115
PI_BAD_CHAIN_CMD = -116
PI_BAD_CHAIN_DELAY = -117
PI_CHAIN_NESTING = -118
PI_CHAIN_TOO_BIG = -119
PI_DEPRECATED = -120
PI_BAD_SER_INVERT = -121
PI_BAD_FOREVER = -124
PI_BAD_FILTER = -125
PI_BAD_PAD = -126
PI_BAD_STRENGTH = -127
PI_FIL_OPEN_FAILED = -128
PI_BAD_FILE_MODE = -129
PI_BAD_FILE_FLAG = -130
PI_BAD_FILE_READ = -131
PI_BAD_FILE_WRITE = -132
PI_FILE_NOT_ROPEN = -133
PI_FILE_NOT_WOPEN = -134
PI_BAD_FILE_SEEK = -135
PI_NO_FILE_MATCH = -136
PI_NO_FILE_ACCESS = -137
PI_FILE_IS_A_DIR = -138
PI_BAD_SHELL_STATUS = -139
PI_BAD_SCRIPT_NAME = -140
PI_BAD_SPI_BAUD = -141
PI_NOT_SPI_GPIO = -142
PI_BAD_EVENT_ID = -143
PI_CMD_INTERRUPTED = -144
PI_NOT_ON_BCM2711   = -145
PI_ONLY_ON_BCM2711  = -146

event: 0-31

An event is a signal used to inform one or more consumers +to start an action. +

file_mode:

The mode may have the following values +

FILE_READ   1
FILE_WRITE  2
FILE_RW     3


The following values can be or'd into the file open mode +

FILE_APPEND 4
FILE_CREATE 8
FILE_TRUNC  16

file_name:

A full file path. To be accessible the path must match +an entry in /opt/pigpio/access. +

fpattern:

A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. +

frequency: 0-40000

Defines the frequency to be used for PWM on a GPIO. +The closest permitted frequency will be used. +

func:

A user supplied callback function. +

gpio: 0-53

A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. +

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

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

gpio_off:

A mask used to select GPIO to be operated on. See bits. +

This mask selects the GPIO to be switched off at the start +of a pulse. +

gpio_on:

A mask used to select GPIO to be operated on. See bits. +

This mask selects the GPIO to be switched on at the start +of a pulse. +

handle: >=0

A number referencing an object opened by one of the following +

file_open +i2c_open +notify_open +serial_open +spi_open +

host:

The name or IP address of the Pi running the pigpio daemon. +

i2c_address: 0-0x7F

The address of a device on the I2C bus. +

i2c_bus: >=0

An I2C bus number. +

i2c_flags: 0

No I2C flags are currently defined. +

invert: 0-1

A flag used to set normal or inverted bit bang serial data +level logic. +

level: 0-1 (2)

CLEAR = 0
HIGH = 1
LOW = 0
OFF = 0
ON = 1
SET = 1
TIMEOUT = 2 # only returned for a watchdog timeout

MISO:

The GPIO used for the MISO signal when bit banging SPI. +

mode:

1.The operational mode of a GPIO, normally INPUT or OUTPUT. +

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


2. The mode of waveform transmission. +

WAVE_MODE_ONE_SHOT = 0
WAVE_MODE_REPEAT = 1
WAVE_MODE_ONE_SHOT_SYNC = 2
WAVE_MODE_REPEAT_SYNC = 3

MOSI:

The GPIO used for the MOSI signal when bit banging SPI. +

offset: >=0

The offset wave data starts from the beginning of the waveform +being currently defined. +

pad: 0-2

A set of GPIO which share common drivers. +

PadGPIO
00-27
128-45
246-53

pad_strength: 1-16

The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. +

params: 32 bit number

When scripts are started they can receive up to 10 parameters +to define their operation. +

port:

The port used by the pigpio daemon, defaults to 8888. +

pstring:

The string to be passed to a shell script to be executed. +

pud: 0-2

PUD_DOWN = 1
PUD_OFF = 0
PUD_UP = 2

pulse_len: 1-100

The length of the trigger pulse in microseconds. +

pulses:

A list of class pulse objects defining the characteristics of a +waveform. +

pulsewidth:

The servo pulsewidth in microseconds. 0 switches pulses off. +

PWMduty: 0-1000000 (1M)

The hardware PWM dutycycle. +

PWMfreq: 1-125M (1-187.5M for the BCM2711)

The hardware PWM frequency. +

range_: 25-40000

Defines the limits for the dutycycle parameter. +

range_ defaults to 255. +

reg: 0-255

An I2C device register. The usable registers depend on the +actual device. +

retMax: >=0

The maximum number of bytes a user customised function +should return, default 8192. +

SCL:

The user GPIO to use for the clock when bit banging I2C. +

SCLK: :

The GPIO used for the SCLK signal when bit banging SPI. +

script:

The text of a script to store on the pigpio daemon. +

script_id: >=0

A number referencing a script created by store_script. +

SDA:

The user GPIO to use for data when bit banging I2C. +

seek_from: 0-2

Direction to seek for file_seek. +

FROM_START=0
FROM_CURRENT=1
FROM_END=2

seek_offset:

The number of bytes to move forward (positive) or backwards +(negative) from the seek position (start, current, or end of file). +

ser_flags: 32 bit

No serial flags are currently defined. +

serial_*:

One of the serial_ functions. +

shellscr:

The name of a shell script. The script must exist +in /opt/pigpio/cgi and must be executable. +

show_errors:

Controls the display of pigpio daemon connection failures. +The default of True prints the probable failure reasons to +standard output. +

spi_channel: 0-2

A SPI channel. +

spi_flags: 32 bit

See spi_open. +

steady: 0-300000

The number of microseconds level changes must be stable for +before reporting the level changed (set_glitch_filter) +or triggering the active part of a noise filter +(set_noise_filter). +

t1:

A tick (earlier). +

t2:

A tick (later). +

tty:

A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0 +

uint32:

An unsigned 32 bit number. +

user_gpio: 0-31

A Broadcom numbered GPIO. +

All the user GPIO are in the range 0-31. +

Not all the GPIO within this range are usable, some are reserved +for system use. +

See gpio. +

wait_timeout: 0.0 -

The number of seconds to wait in wait_for_edge before timing out. +

wave_add_*:

One of the following +

wave_add_new +wave_add_generic +wave_add_serial +

wave_id: >=0

A number referencing a wave created by wave_create. +

wave_send_*:

One of the following +

wave_send_once +wave_send_repeat +

wdog_timeout: 0-60000

Defines a GPIO watchdog timeout in milliseconds. If no level +change is detected on the GPIO for timeout millisecond a watchdog +timeout report is issued (with level TIMEOUT). +

word_val: 0-65535

A whole number. +

\ No newline at end of file diff --git a/DOC/tmp/body/sif.body b/DOC/tmp/body/sif.body new file mode 100644 index 0000000..1274ee9 --- /dev/null +++ b/DOC/tmp/body/sif.body @@ -0,0 +1,1994 @@ + +pigpio provides a socket interface to many of its functions.
+
+The socket interface is available whenever pigpio is running, +either because it has been started as a daemon, or it has been +linked in to a running user program.
+
+The socket interface can be disabled by the program which +initialises the library.  pigpiod offers the -k option to +disable the socket interface.  User programs should call +gpioCfgInterfaces if they +wish to disable the socket interface.
+
+pigpio listens for connections on port 8888 by default.  This +default may be overridden when pigpio starts by the gpioCfgSocketPort function +call.  The pigpio daemon uses this function to provide an +option to change the port number.
+
+The pigs utility is an example of using the socket interface from +C.
+

Request

+

pigpio expects messages of type cmdCmd_t immediately followed with an +extension for a few commands.
+
+The caller should fill in cmd, p1, p2, p3/res, and any extension as +needed.  p3 will always be zero unless the command requires an +extension in which case p3 will be the length in bytes of the +extension.
+
+The cmdCmd_t is echoed back with +the result, if any, in p3/res, and an extension immediately +afterwards for a few commands.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
COMMANDcmd
p1p2p3Extension
MODES0gpiomode0-
MODEG1gpio00-
PUD2gpiopud0-
READ3gpio00-
WRITE4gpiolevel0-
PWM5gpiodutycycle0-
PRS6gpiorange0-
PFS7gpiofrequency0-
SERVO8gpiopulsewidth0-
WDOG9gpiotimeout0-
BR110000-
BR211000-
BC112bits00-
BC213bits00-
BS114bits00-
BS215bits00-
TICK16000-
HWVER17000-
NO18000-
NB19handlebits0-
NP20handle00-
NC21handle00-
PRG22gpio00-
PFG23gpio00-
PRRG24gpio00-
HELP
25N/A
N/A
N/A
N/A
PIGPV26000-
WVCLR27000-
WVAG280012*XgpioPulse_t pulse[X]
WVAS29gpiobaud12+Xuint32_t databits
+uint32_t stophalfbits
+uint32_t offset
+uint8_t data[X]
N/A
30000-
N/A
31000-
WVBSY32000-
WVHLT33000-
WVSM34subcmd00-
WVSP35subcmd00-
WVSC36subcmd00-
TRIG37gpiopulselen4uint32_t level
PROC3800Xuint8_t text[X]
PROCD39script_id00-
PROCR40script_id04*X
uint32_t pars[X]
PROCS41script_id00-
SLRO42gpiobaud4uint32_t databits
SLR43gpiocount0-
SLRC44gpio00-
PROCP45script_id00-
MICS46micros00-
MILS47millis00-
PARSE48N/AN/A
N/A
N/A
WVCRE49000-
WVDEL50wave_id00-
WVTX51wave_id00-
WVTXR52wave_id00-
WVNEW53000-
I2CO54busdevice4uint32_t flags
I2CC55handle00-
I2CRD56handlecount0-
I2CWD57handle0Xuint8_t data[X]
I2CWQ58handlebit0-
I2CRS59handle00-
I2CWS60handlebyte0-
I2CRB61handleregister0-
I2CWB62handleregister4uint32_t byte
I2CRW63handleregister0-
I2CWW64handleregister4uint32_t word
I2CRK65handleregister
0-
I2CWK66handleregister
Xuint8_t bvs[X]
I2CRI67handleregister
4uint32_t num
I2CWI68handleregister
X
uint8_t bvs[X]
I2CPC69handleregister
4uint32_t word
I2CPK70handleregister
X
uint8_t data[X]
SPIO
71channelbaud4uint32_t flags
SPIC72handle00-
SPIR73handlecount0-
SPIW74handle0Xuint8_t data[X]
SPIX75handle0Xuint8_t data[X]
SERO76baudflagsXuint8_t device[X]
SERC77handle00-
SERRB78handle00-
SERWB79handlebyte0-
SERR80handlecount0-
SERW81handle0Xuint8_t data[X]
SERDA82handle00-
GDC
83
gpio
0
0
-
GPW
84
gpio
0
0
-
HC
85
gpio
frequency
0
-
HP
86
gpio
frequency
4
uint32_t dutycycle
CF1
87
arg1
arg2
X
uint8_t argx[X]
CF2
88
arg1
retMax
X
uint8_t argx[X]
BI2CC
89
sda
0
0
-
BI2CO
90
sda
scl
4
uint32_t baud
BI2CZ
91
sda
0
X
uint8_t data[X]
I2CZ
92
handle
0
X
uint8_t data[X]
WVCHA
93
0
0
X
uint8_t data[X]
SLRI
94
gpio
invert
0
-
CGI
95
0
0
0
-
CSI
96
config
0
0
-
FG
97
gpio
steady
0
-
FN
98
gpio
steady
4
uint32_t active
NOIB99000-
WVTXM
100
wave_id
mode
0
-
WVTAT
101
0
0
0
-
PADS
102
pad
strength
0
-
PADG
103
pad
0
0
-
FO
104
mode
0
X
uint8_t file[X]
FC
105
handle
0
0
-
FR
106
handle
count
0
-
FW
107
handle
0
X
uint8_t data[X]
FS
108
handle
offset
4
uint32_t from
FL
109
count
0
X
uint8_t pattern[X]
SHELL
110
len(name)
0
len(name)+
+1+
+len(string)
uint8_t name[len(name)]
+uint8_t null (0)
+uint8_t string[len(string)]
BSPIC
111
CS
0
0
-
BSPIO
112
CS
0
20
uint32_t MISO
+uint32_t MOSI
+uint32_t SCLK
+uint32_t baud
+uint32_t spi_flags
BSPIX
113
CS
0
X
uint8_t data[X]
BSCX
114
control
0
X
uint8_t data[X]
EVM
115
handle
bits
0
-
EVT
116
event
0
0
-
PROCU
117
script_id
0
4*X
uint32_t pars[X]
+

Response

+

The response has cmd/p1/p2 as in the request.  p3/res holds +the return value.  If the command returns additional values +they will be in the immediately following extension.

+Normally res should be treated as a 32 bit signed value and will be +greater than or equal to zero.  Upon failure res will be less +than 0 and contains an error code.
+

There are a few commands where the returned value should be +treated as a 32 bit unsigned value.  These commands can not +fail.  They are indicated with a * after the command +name.

+

Commands with an extension have the size of the extension in +bytes returned in res (or <0 on error as above).

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
COMMANDcmd
p1
p2
res
Extension
MODES0-
-
0-
MODEG1-
-
mode
-
PUD2-
-
0-
READ3-
-
level
-
WRITE4-
-
0-
PWM5-
-
0-
PRS6-
-
0-
PFS7-
-
0-
SERVO8-
-
0-
WDOG9-
-
0-
BR1 *10-
-
bits
-
BR2 *11-
-
bits
-
BC112-
-
0-
BC213-
-
0-
BS114-
-
0-
BS215-
-
0-
TICK *
16-
-
tick
-
HWVER *
17-
-
version
-
NO18-
-
handle
-
NB19-
-
0-
NP20-
-
0-
NC21-
-
0-
PRG22-
-
range
-
PFG23-
-
frequency
-
PRRG24-
-
real range
-
HELP25-
-
N/A
N/A
PIGPV *
26-
-
version
-
WVCLR27-
-
0-
WVAG28-
-
wave pulses
-
WVAS29-
-
wave pulses
-
N/A
30-
-
-
-
N/A
31-
-
-
-
WVBSY32-
-
busy (1) or not busy (0)
-
WVHLT33-
-
0-
WVSM34-
-
wave micros
+wave micros - high
+wave micros - max
-
WVSP35-
-
wave pulses
+wave pulses - high
+wave pulses - max
-
WVSC36-
-
wave DMA CBs
+wave DMA CBs - high
+wave DMA CBs - max
-
TRIG37-
-
0
-
PROC38-
-
script id
-
PROCD39-
-
0-
PROCR40-
-
script status
-
PROCS41-
-
0-
SLRO42-
-
0
-
SLR43-
-
X
uint8_t data[X]
SLRC44-
-
0-
PROCP45-
-
44uint32_t script_status
+uint32_t pars[10]
MICS46-
-
0-
MILS47-
-
0-
PARSE48-
-
N/A
-
WVCRE49-
-
wave id
-
WVDEL50-
-
0-
WVTX51-
-
wave DMA CBs
-
WVTXR52-
-
wave DMA CBs
-
WVNEW53-
-
0-
I2CO54-
-
handle-
I2CC55-
-
0-
I2CRD56-
-
X
uint8_t data[X]
I2CWD57-
-
0
-
I2CWQ58-
-
0-
I2CRS59-
-
byte value
-
I2CWS60-
-
0-
I2CRB61-
-
byte value
-
I2CWB62-
-
0
-
I2CRW63-
-
word value
-
I2CWW64-
-
0
-
I2CRK65-
-
0-
I2CWK66-
-
0
-
I2CRI67-
-
X
uint8_t data[X]
I2CWI68-
-
0
-
I2CPC69-
-
word value
-
I2CPK70-
-
X
uint8_t data[X]
SPIO
71-
-
handle
-
SPIC72-
-
0-
SPIR73-
-
X
uint8_t data[X]
SPIW74-
-
0
-
SPIX75-
-
Xuint8_t data[X]
SERO76-
-
handle
-
SERC77-
-
0-
SERRB78-
-
byte value
-
SERWB79-
-
0-
SERR80-
-
X
uint8_t data[X]
SERW81-
-
0
-
SERDA82-
-
data ready count
-
GDC
83
-
-
dutycycle
-
GPW
84
-
-
pulsewidth
-
HC
85
-
-
0
-
HP
86
-
-
0
-
CF1
87
-
-
value
-
CF2
88
-
-
X
uint8_t retBuf[X]
BI2CC
89
-
-
0
-
BI2CO
90
-
-
handle
-
BI2CZ
91
-
-
X
uint8_t data[X]
I2CZ
92
-
-
X
uint8_t data[X]
WVCHA
93
-
-
0
-
SLRI
94
-
-
0
-
CGI
95
-
-
config
-
CSI
96
-
-
0
-
FG
97
-
-
0
-
FN
98
-
-
0
-
NOIB99-
-
0-
WVTXM
100
-
-
wave DMA CBs
-
WVTAT
101
-
-
wave id
-
PADS
102
-
-
0
-
PADG
103
-
-
strength
-
FO
104
-
-
handle
-
FC
105
-
-
0
-
FR
106
-
-
X
uint8_t data[X]
FW
107
-
-
0
-
FS
108
-
-
position
-
FL
109
-
-
X
uint8_t filenames[X]
SHELL
110
-
-
exit status
-
BSPIC
111
-
-
0
-
BSPIO
112
-
-
0
-
BSPIX
113
-
-
X
uint8_t data[X]
BSCX
114
-
-
X+4
uint32_t status
+uint8_t data[X]
EVM
115
-
-
0
-
EVT
116
-
-
0
-
PROCU
117
-
-
0
-
+
+

cmdCmd_t

+typedef struct
+{
+   uint32_t cmd;
+   uint32_t p1;
+   uint32_t p2;
+   union
+   {
+      uint32_t p3;
+      uint32_t ext_len;
+      uint32_t res;
+   };
+} cmdCmd_t;

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

*param

An array of script parameters. +

pctBOOL: 0-100

+percent On-Off-Level (OOL) buffer to consume for wave output. +

pctCB: 0-100

+the percent of all DMA control blocks to consume. +

pctTOOL: 0-100

+the percent of OOL buffer to consume for wave input (flags).

pi_i2c_msg_t

typedef struct
{
   uint16_t addr;  // slave address
   uint16_t flags;
   uint16_t len;   // msg length
   uint8_t  *buf;  // pointer to msg data
} pi_i2c_msg_t;

port: 1024-32000

The port used to bind to the pigpio socket. Defaults to 8888. @@ -1873,7 +1879,7 @@ A 16-bit word value. - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/download.html b/DOC/HTML/download.html index 5da5c77..84ec4da 100644 --- a/DOC/HTML/download.html +++ b/DOC/HTML/download.html @@ -113,7 +113,7 @@ sudo apt-get install pigpio python-pigpio python3-pigpio

- +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/ex_LDR.html b/DOC/HTML/ex_LDR.html index 615d9b4..6b1cf23 100644 --- a/DOC/HTML/ex_LDR.html +++ b/DOC/HTML/ex_LDR.html @@ -197,7 +197,7 @@ Gnuplot readings 18-21 seconds - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/ex_ir_remote.html b/DOC/HTML/ex_ir_remote.html index 257d613..5f548cb 100644 --- a/DOC/HTML/ex_ir_remote.html +++ b/DOC/HTML/ex_ir_remote.html @@ -300,7 +300,7 @@ viewed using GTKWave.

- +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/ex_motor_shield.html b/DOC/HTML/ex_motor_shield.html index 8378282..e5d28f0 100644 --- a/DOC/HTML/ex_motor_shield.html +++ b/DOC/HTML/ex_motor_shield.html @@ -301,7 +301,7 @@ PI_OUTPUT);
- +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/ex_rotary_encoder.html b/DOC/HTML/ex_rotary_encoder.html index e6df718..b15b354 100644 --- a/DOC/HTML/ex_rotary_encoder.html +++ b/DOC/HTML/ex_rotary_encoder.html @@ -232,7 +232,7 @@ before completing the level transition
- +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/ex_sonar_ranger.html b/DOC/HTML/ex_sonar_ranger.html index 9e60c39..1db8410 100644 --- a/DOC/HTML/ex_sonar_ranger.html +++ b/DOC/HTML/ex_sonar_ranger.html @@ -211,7 +211,7 @@ plot 'sonar-secs.dat' title 'Sonar'
- +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/examples.html b/DOC/HTML/examples.html index 59e3907..3d82fca 100644 --- a/DOC/HTML/examples.html +++ b/DOC/HTML/examples.html @@ -550,7 +550,7 @@ Related code.
- +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/faq.html b/DOC/HTML/faq.html index 1286cbe..4d06c5e 100644 --- a/DOC/HTML/faq.html +++ b/DOC/HTML/faq.html @@ -508,7 +508,7 @@ should I use? - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/index.html b/DOC/HTML/index.html index 2606ba4..fdaeaa6 100644 --- a/DOC/HTML/index.html +++ b/DOC/HTML/index.html @@ -708,7 +708,7 @@ Hirst's
© 2012-2020
e-mail: pigpio @ abyz.me.uk
-
Updated: 29/04/2020
+
Updated: 30/04/2020
diff --git a/DOC/HTML/misc.html b/DOC/HTML/misc.html index a6179f4..e4db51a 100644 --- a/DOC/HTML/misc.html +++ b/DOC/HTML/misc.html @@ -80,7 +80,7 @@ VCD can be read by many programs, in particular
© 2012-2020
e-mail: pigpio @ abyz.me.uk
-
Updated: 29/04/2020
+
Updated: 30/04/2020
diff --git a/DOC/HTML/pdif.html b/DOC/HTML/pdif.html index 8084e94..2256f61 100644 --- a/DOC/HTML/pdif.html +++ b/DOC/HTML/pdif.html @@ -1160,7 +1160,7 @@ A 16-bit word value. - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/pdif2.html b/DOC/HTML/pdif2.html index fad8bdb..db30a8c 100644 --- a/DOC/HTML/pdif2.html +++ b/DOC/HTML/pdif2.html @@ -568,18 +568,16 @@ specified delay between the pulse and the next.

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.

int wave_create_and_pad(int pi, int percent)

-This function creates a waveform like wave_create but pads the consumed +This function creates a waveform like wave_create but pads the consumed resources. Where percent gives the percentage of the resources to use (in terms of the theoretical maximum, not the current amount free). This allows the reuse
-of deleted waves while a transmission is active. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions are consumed by this +of deleted waves while a transmission is active. +

pi: >=0 (as returned by pigpio_start).
percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this function.

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

A usage would be the creation of two waves where one is filled while the other -is beeing transmitted. Each wave is assigned 50% of the available resources. +is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences.

Normal usage:

Step 1. wave_clear to clear all waveforms and added data. @@ -1388,6 +1386,8 @@ The mA which may be drawn from each GPIO whilst still guaranteeing the high and low levels.

*param

An array of script parameters. +

percent: 0-100

+The size of waveform as percentage of maximum available.

pi

An integer defining a connected Pi. The value is returned by pigpio_start upon success. @@ -1515,7 +1515,7 @@ A 16-bit word value. - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/pif.html b/DOC/HTML/pif.html index 6ed3739..1cc3c17 100644 --- a/DOC/HTML/pif.html +++ b/DOC/HTML/pif.html @@ -77,7 +77,7 @@ The format of the commands is identical to those used by
© 2012-2020
e-mail: pigpio @ abyz.me.uk
-
Updated: 29/04/2020
+
Updated: 30/04/2020
diff --git a/DOC/HTML/pig2vcd.html b/DOC/HTML/pig2vcd.html index 8797c15..e64a2fb 100644 --- a/DOC/HTML/pig2vcd.html +++ b/DOC/HTML/pig2vcd.html @@ -75,7 +75,7 @@ The state lines contain the new state followed by the gpio identifier. - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/pigpiod.html b/DOC/HTML/pigpiod.html index b40a71e..d522889 100644 --- a/DOC/HTML/pigpiod.html +++ b/DOC/HTML/pigpiod.html @@ -106,7 +106,7 @@ The USB power mode is fixed at 1.2 amps (high power).
- +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/pigs.html b/DOC/HTML/pigs.html index 3aaeaf9..d4b4079 100644 --- a/DOC/HTML/pigs.html +++ b/DOC/HTML/pigs.html @@ -944,7 +944,7 @@ 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.

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

WVCAP - - Create a waveform of fixed size

Similar to WVCRE, this command creates a waveform but pads the consumed + - Create a waveform of fixed sizeSimilar to WVCRE, this command creates a waveform but pads the consumed resources to a fixed size, specified as a percent of total resource. Padded waves of equal size can be re-cycled efficiently allowing newly created waves to re-use the resources of deleted waves of the same dimension. @@ -1260,7 +1260,7 @@ the current GPIO levels. - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/piscope.html b/DOC/HTML/piscope.html index 643cd03..9236731 100644 --- a/DOC/HTML/piscope.html +++ b/DOC/HTML/piscope.html @@ -261,7 +261,7 @@ make install

- +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/python.html b/DOC/HTML/python.html index 8b3b013..f6b5f22 100644 --- a/DOC/HTML/python.html +++ b/DOC/HTML/python.html @@ -1029,12 +1029,12 @@ resources. Where percent gives the percentage of the resources to use This allows the reuse of deleted waves while a transmission is active.

Upon success a wave id greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions are consumed by this +

percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this function.

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

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the available resources. +

A usage would be the creation of two waves where one is filled while the +other is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences.

Normal usage:

Step 1. wave_clear to clear all waveforms and added data. @@ -1044,7 +1044,7 @@ This buffer structure allows the transmission of infinite wave sequences.

Repeat steps 2-4 as needed.

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

Example

wid = pi.wave_create(50)

wave_delete(wave_id)

+

Example

wid = pi.wave_create_and_pad(50)

wave_delete(wave_id)

This function deletes the waveform with id wave_id.

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

The wave is flagged for deletion. The resources used by the wave @@ -1210,6 +1210,7 @@ being currently defined. high and low levels.

params: 32 bit number

When scripts are started they can receive up to 10 parameters to define their operation. +

percent: : 0-100

The size of waveform as percentage of maximum available.

port:

The port used by the pigpio daemon, defaults to 8888.

pstring:

The string to be passed to a shell script to be executed.

pud: 0-2

PUD_DOWN = 1
PUD_OFF = 0
PUD_UP = 2

pulse_len: 1-100

The length of the trigger pulse in microseconds. @@ -1285,7 +1286,7 @@ timeout report is issued (with level TIMEOUT). - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/sif.html b/DOC/HTML/sif.html index f689050..bbaa6e1 100644 --- a/DOC/HTML/sif.html +++ b/DOC/HTML/sif.html @@ -2050,7 +2050,7 @@ uint8_t data[X] - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/HTML/sitemap.html b/DOC/HTML/sitemap.html index 18ecc75..b2706b1 100644 --- a/DOC/HTML/sitemap.html +++ b/DOC/HTML/sitemap.html @@ -77,7 +77,7 @@ - +
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 29/04/2020
Updated: 30/04/2020
diff --git a/DOC/MAN/pigpio.3 b/DOC/MAN/pigpio.3 index 7fa74e3..c878cbd 100644 --- a/DOC/MAN/pigpio.3 +++ b/DOC/MAN/pigpio.3 @@ -9569,6 +9569,27 @@ An array of script parameters. .br +.IP "\fBpctBOOL\fP: 0-100" 0 +percent On-Off-Level (OOL) buffer to consume for wave output. + +.br + +.br + +.IP "\fBpctCB\fP: 0-100" 0 +the percent of all DMA control blocks to consume. + +.br + +.br + +.IP "\fBpctTOOL\fP: 0-100" 0 +the percent of OOL buffer to consume for wave input (flags). + +.br + +.br + .IP "\fBpi_i2c_msg_t\fP" 0 .EX diff --git a/DOC/MAN/pigpiod_if2.3 b/DOC/MAN/pigpiod_if2.3 index b6924c6..f07de8d 100644 --- a/DOC/MAN/pigpiod_if2.3 +++ b/DOC/MAN/pigpiod_if2.3 @@ -2395,13 +2395,11 @@ PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. .IP "\fBint wave_create_and_pad(int pi, int percent)\fP" .IP "" 4 -This function creates a waveform like wave_create but pads the consumed +This function creates a waveform like \fBwave_create\fP but pads the consumed resources. Where percent gives the percentage of the resources to use (in terms of the theoretical maximum, not the current amount free). This allows the reuse .br -of deleted waves while a transmission is active. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +of deleted waves while a transmission is active. .br @@ -2410,6 +2408,8 @@ PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. .EX pi: >=0 (as returned by \fBpigpio_start\fP). .br +percent: 0-100, size of waveform as percentage of maximum available. +.br .EE @@ -2429,7 +2429,7 @@ wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. .br A usage would be the creation of two waves where one is filled while the other -is beeing transmitted. Each wave is assigned 50% of the available resources. +is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences. .br @@ -7499,6 +7499,13 @@ An array of script parameters. .br +.IP "\fBpercent\fP: 0-100" 0 +The size of waveform as percentage of maximum available. + +.br + +.br + .IP "\fBpi\fP" 0 An integer defining a connected Pi. The value is returned by \fBpigpio_start\fP upon success. diff --git a/DOC/MAN/pigs.1 b/DOC/MAN/pigs.1 index fa99470..9b6192c 100644 --- a/DOC/MAN/pigs.1 +++ b/DOC/MAN/pigs.1 @@ -5146,7 +5146,7 @@ ERROR: attempt to create an empty waveform .IP "" 4 .br -Similar to WVCRE, this command creates a waveform but pads the consumed +Similar to \fBWVCRE\fP, this command creates a waveform but pads the consumed resources to a fixed size, specified as a percent of total resource. Padded waves of equal size can be re-cycled efficiently allowing newly created waves to re-use the resources of deleted waves of the same dimension. diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index 98a0cb1..531ccfd 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 b/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 new file mode 100644 index 0000000..98a0cb1 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 b/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 new file mode 100644 index 0000000..d763ce9 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 new file mode 100644 index 0000000..23be3f5 Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 new file mode 100644 index 0000000..1dc038e Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 new file mode 100644 index 0000000..03f11ba Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 new file mode 100644 index 0000000..d37369e Binary files /dev/null and b/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 differ diff --git a/DOC/src/defs/pigs.def b/DOC/src/defs/pigs.def index 82fca73..2f6d23c 100644 --- a/DOC/src/defs/pigs.def +++ b/DOC/src/defs/pigs.def @@ -2786,7 +2786,7 @@ ERROR: attempt to create an empty waveform WVCAP :: -Similar to WVCRE, this command creates a waveform but pads the consumed +Similar to [*WVCRE*], this command creates a waveform but pads the consumed resources to a fixed size, specified as a percent of total resource. Padded waves of equal size can be re-cycled efficiently allowing newly created waves to re-use the resources of deleted waves of the same dimension. diff --git a/DOC/tmp/body/cif.body b/DOC/tmp/body/cif.body index 28205fd..f20d1c4 100644 --- a/DOC/tmp/body/cif.body +++ b/DOC/tmp/body/cif.body @@ -1675,6 +1675,12 @@ The mA which may be drawn from each GPIO whilst still guaranteeing the high and low levels.

*param

An array of script parameters. +

pctBOOL: 0-100

+percent On-Off-Level (OOL) buffer to consume for wave output. +

pctCB: 0-100

+the percent of all DMA control blocks to consume. +

pctTOOL: 0-100

+the percent of OOL buffer to consume for wave input (flags).

pi_i2c_msg_t

typedef struct
{
   uint16_t addr;  // slave address
   uint16_t flags;
   uint16_t len;   // msg length
   uint8_t  *buf;  // pointer to msg data
} pi_i2c_msg_t;

port: 1024-32000

The port used to bind to the pigpio socket. Defaults to 8888. diff --git a/DOC/tmp/body/pdif2.body b/DOC/tmp/body/pdif2.body index ecebd36..21d2b4b 100644 --- a/DOC/tmp/body/pdif2.body +++ b/DOC/tmp/body/pdif2.body @@ -528,18 +528,16 @@ specified delay between the pulse and the next.

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.

int wave_create_and_pad(int pi, int percent)

-This function creates a waveform like wave_create but pads the consumed +This function creates a waveform like wave_create but pads the consumed resources. Where percent gives the percentage of the resources to use (in terms of the theoretical maximum, not the current amount free). This allows the reuse
-of deleted waves while a transmission is active. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions are consumed by this +of deleted waves while a transmission is active. +

pi: >=0 (as returned by pigpio_start).
percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this function.

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

A usage would be the creation of two waves where one is filled while the other -is beeing transmitted. Each wave is assigned 50% of the available resources. +is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences.

Normal usage:

Step 1. wave_clear to clear all waveforms and added data. @@ -1348,6 +1346,8 @@ The mA which may be drawn from each GPIO whilst still guaranteeing the high and low levels.

*param

An array of script parameters. +

percent: 0-100

+The size of waveform as percentage of maximum available.

pi

An integer defining a connected Pi. The value is returned by pigpio_start upon success. diff --git a/DOC/tmp/body/pigs.body b/DOC/tmp/body/pigs.body index f4b7a7e..4a88b42 100644 --- a/DOC/tmp/body/pigs.body +++ b/DOC/tmp/body/pigs.body @@ -904,7 +904,7 @@ 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.

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

WVCAP - - Create a waveform of fixed size

Similar to WVCRE, this command creates a waveform but pads the consumed + - Create a waveform of fixed sizeSimilar to WVCRE, this command creates a waveform but pads the consumed resources to a fixed size, specified as a percent of total resource. Padded waves of equal size can be re-cycled efficiently allowing newly created waves to re-use the resources of deleted waves of the same dimension. diff --git a/DOC/tmp/body/python.body b/DOC/tmp/body/python.body index f036866..4f756e4 100644 --- a/DOC/tmp/body/python.body +++ b/DOC/tmp/body/python.body @@ -989,12 +989,12 @@ resources. Where percent gives the percentage of the resources to use This allows the reuse of deleted waves while a transmission is active.

Upon success a wave id greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions are consumed by this +

percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this function.

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

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the available resources. +

A usage would be the creation of two waves where one is filled while the +other is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences.

Normal usage:

Step 1. wave_clear to clear all waveforms and added data. @@ -1004,7 +1004,7 @@ This buffer structure allows the transmission of infinite wave sequences.

Repeat steps 2-4 as needed.

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

Example

wid = pi.wave_create(50)

wave_delete(wave_id)

+

Example

wid = pi.wave_create_and_pad(50)

wave_delete(wave_id)

This function deletes the waveform with id wave_id.

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


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

The wave is flagged for deletion. The resources used by the wave @@ -1170,6 +1170,7 @@ being currently defined. high and low levels.

params: 32 bit number

When scripts are started they can receive up to 10 parameters to define their operation. +

percent: : 0-100

The size of waveform as percentage of maximum available.

port:

The port used by the pigpio daemon, defaults to 8888.

pstring:

The string to be passed to a shell script to be executed.

pud: 0-2

PUD_DOWN = 1
PUD_OFF = 0
PUD_UP = 2

pulse_len: 1-100

The length of the trigger pulse in microseconds. diff --git a/DOC/tmp/pydoc/pigpio.pydoc b/DOC/tmp/pydoc/pigpio.pydoc index 0286caf..c5dbdc2 100644 --- a/DOC/tmp/pydoc/pigpio.pydoc +++ b/DOC/tmp/pydoc/pigpio.pydoc @@ -3174,7 +3174,7 @@ CLASSES | PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. | | . . - | pi: >=0 (as returned by [*pigpio_start*]). + | percent: 0-100, size of waveform as percentage of maximum available. | . . | | The data provided by the [*wave_add_**] functions are consumed by this @@ -3183,8 +3183,8 @@ CLASSES | As many waveforms may be created as there is space available. The | wave id is passed to [*wave_send_**] to specify the waveform to transmit. | - | A usage would be the creation of two waves where one is filled while the other - | is being transmitted. Each wave is assigned 50% of the available resources. + | A usage would be the creation of two waves where one is filled while the + | other is being transmitted. Each wave is assigned 50% of the resources. | This buffer structure allows the transmission of infinite wave sequences. | | Normal usage: @@ -3203,7 +3203,7 @@ CLASSES | can be created in its place. | | ... - | wid = pi.wave_create(50) + | wid = pi.wave_create_and_pad(50) | ... | | wave_delete(self, wave_id) @@ -3834,6 +3834,9 @@ FUNCTIONS When scripts are started they can receive up to 10 parameters to define their operation. + percent:: 0-100 + The size of waveform as percentage of maximum available. + port: The port used by the pigpio daemon, defaults to 8888. diff --git a/pigpio.3 b/pigpio.3 index 7fa74e3..c878cbd 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -9569,6 +9569,27 @@ An array of script parameters. .br +.IP "\fBpctBOOL\fP: 0-100" 0 +percent On-Off-Level (OOL) buffer to consume for wave output. + +.br + +.br + +.IP "\fBpctCB\fP: 0-100" 0 +the percent of all DMA control blocks to consume. + +.br + +.br + +.IP "\fBpctTOOL\fP: 0-100" 0 +the percent of OOL buffer to consume for wave input (flags). + +.br + +.br + .IP "\fBpi_i2c_msg_t\fP" 0 .EX diff --git a/pigpio.h b/pigpio.h index 208c802..5794e4e 100644 --- a/pigpio.h +++ b/pigpio.h @@ -5804,6 +5804,15 @@ high and low levels. *param:: An array of script parameters. +pctBOOL:: 0-100 +percent On-Off-Level (OOL) buffer to consume for wave output. + +pctCB:: 0-100 +the percent of all DMA control blocks to consume. + +pctTOOL:: 0-100 +the percent of OOL buffer to consume for wave input (flags). + pi_i2c_msg_t:: . . typedef struct diff --git a/pigpio.py b/pigpio.py index c913436..978aff2 100644 --- a/pigpio.py +++ b/pigpio.py @@ -2312,12 +2312,12 @@ class pi(): resources. Where percent gives the percentage of the resources to use (in terms of the theoretical maximum, not the current amount free). This allows the reuse of deleted waves while a transmission is active. - + Upon success a wave id greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. . . - pi: >=0 (as returned by [*pigpio_start*]). + percent: 0-100, size of waveform as percentage of maximum available. . . The data provided by the [*wave_add_**] functions are consumed by this @@ -2326,10 +2326,10 @@ class pi(): As many waveforms may be created as there is space available. The wave id is passed to [*wave_send_**] to specify the waveform to transmit. - A usage would be the creation of two waves where one is filled while the other - is being transmitted. Each wave is assigned 50% of the available resources. + A usage would be the creation of two waves where one is filled while the + other is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences. - + Normal usage: Step 1. [*wave_clear*] to clear all waveforms and added data. @@ -2341,12 +2341,12 @@ class pi(): Step 4. [*wave_send_**] with the id of the waveform to transmit. Repeat steps 2-4 as needed. - + Step 5. Any wave id can now be deleted and another wave of the same size can be created in its place. - + ... - wid = pi.wave_create(50) + wid = pi.wave_create_and_pad(50) ... """ return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCAP, percent, 0)) @@ -5629,6 +5629,9 @@ def xref(): When scripts are started they can receive up to 10 parameters to define their operation. + percent:: 0-100 + The size of waveform as percentage of maximum available. + port: The port used by the pigpio daemon, defaults to 8888. diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index b6924c6..f07de8d 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -2395,13 +2395,11 @@ PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. .IP "\fBint wave_create_and_pad(int pi, int percent)\fP" .IP "" 4 -This function creates a waveform like wave_create but pads the consumed +This function creates a waveform like \fBwave_create\fP but pads the consumed resources. Where percent gives the percentage of the resources to use (in terms of the theoretical maximum, not the current amount free). This allows the reuse .br -of deleted waves while a transmission is active. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +of deleted waves while a transmission is active. .br @@ -2410,6 +2408,8 @@ PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. .EX pi: >=0 (as returned by \fBpigpio_start\fP). .br +percent: 0-100, size of waveform as percentage of maximum available. +.br .EE @@ -2429,7 +2429,7 @@ wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. .br A usage would be the creation of two waves where one is filled while the other -is beeing transmitted. Each wave is assigned 50% of the available resources. +is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences. .br @@ -7499,6 +7499,13 @@ An array of script parameters. .br +.IP "\fBpercent\fP: 0-100" 0 +The size of waveform as percentage of maximum available. + +.br + +.br + .IP "\fBpi\fP" 0 An integer defining a connected Pi. The value is returned by \fBpigpio_start\fP upon success. diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 9c55929..79d0223 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -1376,15 +1376,14 @@ D*/ /*F*/ int wave_create_and_pad(int pi, int percent); /*D -This function creates a waveform like wave_create but pads the consumed +This function creates a waveform like [*wave_create*] but pads the consumed resources. Where percent gives the percentage of the resources to use (in terms of the theoretical maximum, not the current amount free). This allows the reuse -of deleted waves while a transmission is active. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. +of deleted waves while a transmission is active. . . pi: >=0 (as returned by [*pigpio_start*]). +percent: 0-100, size of waveform as percentage of maximum available. . . The data provided by the [*wave_add_**] functions are consumed by this @@ -1394,7 +1393,7 @@ As many waveforms may be created as there is space available. The wave id is passed to [*wave_send_**] to specify the waveform to transmit. A usage would be the creation of two waves where one is filled while the other -is beeing transmitted. Each wave is assigned 50% of the available resources. +is being transmitted. Each wave is assigned 50% of the resources. This buffer structure allows the transmission of infinite wave sequences. Normal usage: @@ -4128,6 +4127,9 @@ high and low levels. *param:: An array of script parameters. +percent:: 0-100 +The size of waveform as percentage of maximum available. + pi:: An integer defining a connected Pi. The value is returned by [*pigpio_start*] upon success. diff --git a/pigs.1 b/pigs.1 index fa99470..9b6192c 100644 --- a/pigs.1 +++ b/pigs.1 @@ -5146,7 +5146,7 @@ ERROR: attempt to create an empty waveform .IP "" 4 .br -Similar to WVCRE, this command creates a waveform but pads the consumed +Similar to \fBWVCRE\fP, this command creates a waveform but pads the consumed resources to a fixed size, specified as a percent of total resource. Padded waves of equal size can be re-cycled efficiently allowing newly created waves to re-use the resources of deleted waves of the same dimension. -- cgit v1.2.3 From 67af06f176f90f9321893a784857d02098002902 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 30 Apr 2020 10:04:30 -0500 Subject: Bump revision to v76. --- pigpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.h b/pigpio.h index 5794e4e..059d751 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7600 +#define PIGPIO_VERSION 76 /*TEXT -- cgit v1.2.3 From 348ad4cb25fcaeb867f4386d5d652143d08eeb03 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 30 Apr 2020 12:51:32 -0500 Subject: Update .gitignore and remove cruft from DOC directory. --- .gitignore | 6 +- DOC/HTML/cif.html | 1887 ----- DOC/HTML/download.html | 121 - DOC/HTML/ex_LDR.html | 205 - DOC/HTML/ex_ir_remote.html | 308 - DOC/HTML/ex_motor_shield.html | 309 - DOC/HTML/ex_rotary_encoder.html | 240 - DOC/HTML/ex_sonar_ranger.html | 219 - DOC/HTML/examples.html | 558 -- DOC/HTML/faq.html | 516 -- DOC/HTML/index.html | 716 -- DOC/HTML/misc.html | 88 - DOC/HTML/pdif.html | 1168 --- DOC/HTML/pdif2.html | 1523 ---- DOC/HTML/pif.html | 85 - DOC/HTML/pig2vcd.html | 83 - DOC/HTML/pigpiod.html | 114 - DOC/HTML/pigs.html | 1268 --- DOC/HTML/piscope.html | 269 - DOC/HTML/python.html | 1294 --- DOC/HTML/sif.html | 2058 ----- DOC/HTML/sitemap.html | 85 - DOC/MAN/README | 2 - DOC/MAN/pig2vcd.1 | 246 - DOC/MAN/pigpio.3 | 11137 -------------------------- DOC/MAN/pigpiod.1 | 273 - DOC/MAN/pigpiod_if.3 | 5339 ------------ DOC/MAN/pigpiod_if2.3 | 8057 ------------------- DOC/MAN/pigs.1 | 6331 --------------- DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 | Bin 1433600 -> 0 bytes DOC/tmp/body/cif.body | 1824 ----- DOC/tmp/body/download.body | 57 - DOC/tmp/body/ex_LDR.body | 141 - DOC/tmp/body/ex_ir_remote.body | 244 - DOC/tmp/body/ex_motor_shield.body | 245 - DOC/tmp/body/ex_rotary_encoder.body | 176 - DOC/tmp/body/ex_sonar_ranger.body | 155 - DOC/tmp/body/examples.body | 495 -- DOC/tmp/body/faq.body | 452 -- DOC/tmp/body/index.body | 652 -- DOC/tmp/body/misc.body | 24 - DOC/tmp/body/pdif.body | 1105 --- DOC/tmp/body/pdif2.body | 1460 ---- DOC/tmp/body/pif.body | 21 - DOC/tmp/body/pig2vcd.body | 20 - DOC/tmp/body/pigpiod.body | 51 - DOC/tmp/body/pigs.body | 1205 --- DOC/tmp/body/piscope.body | 205 - DOC/tmp/body/python.body | 1231 --- DOC/tmp/body/sif.body | 1994 ----- DOC/tmp/pydoc/pigpio.pydoc | 4162 ---------- 67 files changed, 5 insertions(+), 60419 deletions(-) delete mode 100644 DOC/HTML/cif.html delete mode 100644 DOC/HTML/download.html delete mode 100644 DOC/HTML/ex_LDR.html delete mode 100644 DOC/HTML/ex_ir_remote.html delete mode 100644 DOC/HTML/ex_motor_shield.html delete mode 100644 DOC/HTML/ex_rotary_encoder.html delete mode 100644 DOC/HTML/ex_sonar_ranger.html delete mode 100644 DOC/HTML/examples.html delete mode 100644 DOC/HTML/faq.html delete mode 100644 DOC/HTML/index.html delete mode 100644 DOC/HTML/misc.html delete mode 100644 DOC/HTML/pdif.html delete mode 100644 DOC/HTML/pdif2.html delete mode 100644 DOC/HTML/pif.html delete mode 100644 DOC/HTML/pig2vcd.html delete mode 100644 DOC/HTML/pigpiod.html delete mode 100644 DOC/HTML/pigs.html delete mode 100644 DOC/HTML/piscope.html delete mode 100644 DOC/HTML/python.html delete mode 100644 DOC/HTML/sif.html delete mode 100644 DOC/HTML/sitemap.html delete mode 100644 DOC/MAN/README delete mode 100644 DOC/MAN/pig2vcd.1 delete mode 100644 DOC/MAN/pigpio.3 delete mode 100644 DOC/MAN/pigpiod.1 delete mode 100644 DOC/MAN/pigpiod_if.3 delete mode 100644 DOC/MAN/pigpiod_if2.3 delete mode 100644 DOC/MAN/pigs.1 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 delete mode 100644 DOC/tmp/body/cif.body delete mode 100644 DOC/tmp/body/download.body delete mode 100644 DOC/tmp/body/ex_LDR.body delete mode 100644 DOC/tmp/body/ex_ir_remote.body delete mode 100644 DOC/tmp/body/ex_motor_shield.body delete mode 100644 DOC/tmp/body/ex_rotary_encoder.body delete mode 100644 DOC/tmp/body/ex_sonar_ranger.body delete mode 100644 DOC/tmp/body/examples.body delete mode 100644 DOC/tmp/body/faq.body delete mode 100644 DOC/tmp/body/index.body delete mode 100644 DOC/tmp/body/misc.body delete mode 100644 DOC/tmp/body/pdif.body delete mode 100644 DOC/tmp/body/pdif2.body delete mode 100644 DOC/tmp/body/pif.body delete mode 100644 DOC/tmp/body/pig2vcd.body delete mode 100644 DOC/tmp/body/pigpiod.body delete mode 100644 DOC/tmp/body/pigs.body delete mode 100644 DOC/tmp/body/piscope.body delete mode 100644 DOC/tmp/body/python.body delete mode 100644 DOC/tmp/body/sif.body delete mode 100644 DOC/tmp/pydoc/pigpio.pydoc diff --git a/.gitignore b/.gitignore index 140d796..7885815 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,9 @@ __pycache__ build dist *.egg-info -wavepad_jitter.py +# DOC files +DOC/dbase/pigpio.sqlite.* +DOC/tmp +DOC/MAN +DOC/HTML/*.html diff --git a/DOC/HTML/cif.html b/DOC/HTML/cif.html deleted file mode 100644 index 58d6eea..0000000 --- a/DOC/HTML/cif.html +++ /dev/null @@ -1,1887 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigpio C Interface



pigpio is a C library for the Raspberry which allows control of the GPIO. -

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts -

GPIO

ALL GPIO are identified by their Broadcom number. -

Credits

The PWM and servo pulses are timed using the DMA and PWM peripherals. -

This use was inspired by Richard Hirst's servoblaster kernel module. -

Usage

Include <pigpio.h> in your source files. -

Assuming your source is in prog.c use the following command to build and -run the executable. -

gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
sudo ./prog


For examples of usage see the C programs within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error. -

gpioInitialise must be called before all other library functions -with the following exceptions: -

gpioCfg*
gpioVersion
gpioHardwareRevision


If the library is not initialised all but the gpioCfg*, -gpioVersion, and gpioHardwareRevision functions will -return error PI_NOT_INITIALISED. -

If the library is initialised the gpioCfg* functions will return -error PI_INITIALISED. -

OVERVIEW

ESSENTIAL -
gpioInitialise Initialise library -
gpioTerminate Stop library -
BASIC -
gpioSetMode Set a GPIO mode -
gpioGetMode Get a GPIO mode -
gpioSetPullUpDown Set/clear GPIO pull up/down resistor -
gpioRead Read a GPIO -
gpioWrite Write a GPIO -
PWM (overrides servo commands on same GPIO) -
gpioPWM Start/stop PWM pulses on a GPIO -
gpioSetPWMfrequency Configure PWM frequency for a GPIO -
gpioSetPWMrange Configure PWM range for a GPIO -
gpioGetPWMdutycycle Get dutycycle setting on a GPIO -
gpioGetPWMfrequency Get configured PWM frequency for a GPIO -
gpioGetPWMrange Get configured PWM range for a GPIO -
gpioGetPWMrealRange Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
gpioServo Start/stop servo pulses on a GPIO -
gpioGetServoPulsewidth Get pulsewidth setting on a GPIO -
INTERMEDIATE -
gpioTrigger Send a trigger pulse to a GPIO -
gpioSetWatchdog Set a watchdog on a GPIO -
gpioRead_Bits_0_31 Read all GPIO in bank 1 -
gpioRead_Bits_32_53 Read all GPIO in bank 2 -
gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 -
gpioWrite_Bits_32_53_ClearClear selected GPIO in bank 2 -
gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 -
gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 -
gpioSetAlertFunc Request a GPIO level change callback -
gpioSetAlertFuncEx Request a GPIO change callback, extended -
gpioSetTimerFunc Request a regular timed callback -
gpioSetTimerFuncEx Request a regular timed callback, extended -
gpioStartThread Start a new thread -
gpioStopThread Stop a previously started thread -
ADVANCED -
gpioNotifyOpen Request a notification handle -
gpioNotifyClose Close a notification -
gpioNotifyOpenWithSize Request a notification with sized pipe -
gpioNotifyBegin Start notifications for selected GPIO -
gpioNotifyPause Pause notifications -
gpioHardwareClock Start hardware clock on supported GPIO -
gpioHardwarePWM Start hardware PWM on supported GPIO -
gpioGlitchFilter Set a glitch filter on a GPIO -
gpioNoiseFilter Set a noise filter on a GPIO -
gpioSetPad Sets a pads drive strength -
gpioGetPad Gets a pads drive strength -
shell Executes a shell command -
gpioSetISRFunc Request a GPIO interrupt callback -
gpioSetISRFuncEx Request a GPIO interrupt callback, extended -
gpioSetSignalFunc Request a signal callback -
gpioSetSignalFuncEx Request a signal callback, extended -
gpioSetGetSamplesFunc Requests a GPIO samples callback -
gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended -
Custom -
gpioCustom1 User custom function 1 -
gpioCustom2 User custom function 2 -
Events -
eventMonitor Sets the events to monitor -
eventSetFunc Request an event callback -
eventSetFuncEx Request an event callback, extended -
eventTrigger Trigger an event -
Scripts -
gpioStoreScript Store a script -
gpioRunScript Run a stored script -
gpioUpdateScript Set a scripts parameters -
gpioScriptStatus Get script status and parameters -
gpioStopScript Stop a running script -
gpioDeleteScript Delete a stored script -
I2C -
i2cOpen Opens an I2C device -
i2cClose Closes an I2C device -
i2cWriteQuick SMBus write quick -
i2cReadByte SMBus read byte -
i2cWriteByte SMBus write byte -
i2cReadByteData SMBus read byte data -
i2cWriteByteData SMBus write byte data -
i2cReadWordData SMBus read word data -
i2cWriteWordData SMBus write word data -
i2cReadBlockData SMBus read block data -
i2cWriteBlockData SMBus write block data -
i2cReadI2CBlockData SMBus read I2C block data -
i2cWriteI2CBlockData SMBus write I2C block data -
i2cReadDevice Reads the raw I2C device -
i2cWriteDevice Writes the raw I2C device -
i2cProcessCall SMBus process call -
i2cBlockProcessCall SMBus block process call -
i2cSwitchCombined Sets or clears the combined flag -
i2cSegments Performs multiple I2C transactions -
i2cZip Performs multiple I2C transactions -
I2C BIT BANG -
bbI2COpen Opens GPIO for bit banging I2C -
bbI2CClose Closes GPIO for bit banging I2C -
bbI2CZip Performs bit banged I2C transactions -
I2C/SPI SLAVE -
bscXfer I2C/SPI as slave transfer -
SERIAL -
serOpen Opens a serial device -
serClose Closes a serial device -
serReadByte Reads a byte from a serial device -
serWriteByte Writes a byte to a serial device -
serRead Reads bytes from a serial device -
serWrite Writes bytes to a serial device -
serDataAvailable Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
gpioSerialReadOpen Opens a GPIO for bit bang serial reads -
gpioSerialReadClose Closes a GPIO for bit bang serial reads -
gpioSerialReadInvert Configures normal/inverted for serial reads -
gpioSerialRead Reads bit bang serial data from a GPIO -
SPI -
spiOpen Opens a SPI device -
spiClose Closes a SPI device -
spiRead Reads bytes from a SPI device -
spiWrite Writes bytes to a SPI device -
spiXfer Transfers bytes with a SPI device -
SPI BIT BANG -
bbSPIOpen Opens GPIO for bit banging SPI -
bbSPIClose Closes GPIO for bit banging SPI -
bbSPIXfer Performs bit banged SPI transactions -
FILES -
fileOpen Opens a file -
fileClose Closes a file -
fileRead Reads bytes from a file -
fileWrite Writes bytes to a file -
fileSeek Seeks to a position within a file -
fileList List files which match a pattern -
WAVES -
gpioWaveClear Deletes all waveforms -
gpioWaveAddNew Starts a new waveform -
gpioWaveAddGeneric Adds a series of pulses to the waveform -
gpioWaveAddSerial Adds serial data to the waveform -
gpioWaveCreate Creates a waveform from added data -
gpioWaveCreatePad Creates a waveform of fixed size from added data -
gpioWaveDelete Deletes a waveform -
gpioWaveTxSend Transmits a waveform -
gpioWaveChain Transmits a chain of waveforms -
gpioWaveTxAt Returns the current transmitting waveform -
gpioWaveTxBusy Checks to see if the waveform has ended -
gpioWaveTxStop Aborts the current waveform -
gpioWaveGetCbs Length in CBs of the current waveform -
gpioWaveGetHighCbs Length of longest waveform so far -
gpioWaveGetMaxCbs Absolute maximum allowed CBs -
gpioWaveGetMicros Length in micros of the current waveform -
gpioWaveGetHighMicros Length of longest waveform so far -
gpioWaveGetMaxMicros Absolute maximum allowed micros -
gpioWaveGetPulses Length in pulses of the current waveform -
gpioWaveGetHighPulses Length of longest waveform so far -
gpioWaveGetMaxPulses Absolute maximum allowed pulses -
UTILITIES -
gpioDelay Delay for a number of microseconds -
gpioTick Get current tick (microseconds) -
gpioHardwareRevision Get hardware revision -
gpioVersion Get the pigpio version -
getBitInBytes Get the value of a bit -
putBitInBytes Set the value of a bit -
gpioTime Get current time -
gpioSleep Sleep for specified time -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -
CONFIGURATION -
gpioCfgBufferSize Configure the GPIO sample buffer size -
gpioCfgClock Configure the GPIO sample rate -
gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) -
gpioCfgDMAchannels Configure the DMA channels -
gpioCfgPermissions Configure the GPIO access permissions -
gpioCfgInterfaces Configure user interfaces -
gpioCfgSocketPort Configure socket port -
gpioCfgMemAlloc Configure DMA memory allocation mode -
gpioCfgNetAddr Configure allowed network addresses -
gpioCfgInternals Configure misc. internals (DEPRECATED) -
gpioCfgGetInternals Get internal configuration settings -
gpioCfgSetInternals Set internal configuration settings -
EXPERT -
rawWaveAddSPI Not intended for general use -
rawWaveAddGeneric Not intended for general use -
rawWaveCB Not intended for general use -
rawWaveCBAdr Not intended for general use -
rawWaveGetOOL Not intended for general use -
rawWaveSetOOL Not intended for general use -
rawWaveGetOut Not intended for general use -
rawWaveSetOut Not intended for general use -
rawWaveGetIn Not intended for general use -
rawWaveSetIn Not intended for general use -
rawWaveInfo Not intended for general use -
rawDumpWave Not intended for general use -
rawDumpScript Not intended for general use -

FUNCTIONS

int gpioInitialise(void)

-Initialises the library. -

Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. -

gpioInitialise must be called before using the other library functions -with the following exceptions: -

gpioCfg*
gpioVersion
gpioHardwareRevision


Example

if (gpioInitialise() < 0)
{
   // pigpio initialisation failed.
}
else
{
   // pigpio initialised okay.
}

void gpioTerminate(void)

-Terminates the library. -

Returns nothing. -

Call before program exit. -

This function resets the used DMA channels, releases memory, and -terminates any running threads. -

Example

gpioTerminate();

int gpioSetMode(unsigned gpio, unsigned mode)

-Sets the GPIO mode, typically input or output. -

gpio: 0-53
mode: 0-7


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. -

Arduino style: pinMode. -

Example

gpioSetMode(17, PI_INPUT);  // Set GPIO17 as input.

gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output.

gpioSetMode(22,PI_ALT0);    // Set GPIO22 to alternative mode 0.


See http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf page 102 for an overview of the modes. -

int gpioGetMode(unsigned gpio)

-Gets the GPIO mode. -

gpio: 0-53


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

Example

if (gpioGetMode(17) != PI_ALT0)
{
   gpioSetMode(17, PI_ALT0);  // set GPIO17 to ALT0
}

int gpioSetPullUpDown(unsigned gpio, unsigned pud)

-Sets or clears resistor pull ups or downs on the GPIO. -

gpio: 0-53
 pud: 0-2


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. -

Example

gpioSetPullUpDown(17, PI_PUD_UP);   // Sets a pull-up.

gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.

gpioSetPullUpDown(23, PI_PUD_OFF);  // Clear any pull-ups/downs.

int gpioRead(unsigned gpio)

-Reads the GPIO level, on or off. -

gpio: 0-53


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

Arduino style: digitalRead. -

Example

printf("GPIO24 is level %d", gpioRead(24));

int gpioWrite(unsigned gpio, unsigned level)

-Sets the GPIO level, on or off. -

 gpio: 0-53
level: 0-1


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. -

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

Arduino style: digitalWrite -

Example

gpioWrite(24, 1); // Set GPIO24 high.

int gpioPWM(unsigned user_gpio, unsigned dutycycle)

-Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). -Range defaults to 255. -

user_gpio: 0-31
dutycycle: 0-range


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. -

Arduino style: analogWrite -

This and the servo functionality use the DMA and PWM or PCM peripherals -to control and schedule the pulse lengths and dutycycles. -

The gpioSetPWMrange function may be used to change the default -range of 255. -

Example

gpioPWM(17, 255); // Sets GPIO17 full on.

gpioPWM(18, 128); // Sets GPIO18 half on.

gpioPWM(23, 0);   // Sets GPIO23 full off.

int gpioGetPWMdutycycle(unsigned user_gpio)

-Returns the PWM dutycycle setting for the GPIO. -

user_gpio: 0-31


Returns between 0 (off) and range (fully on) if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

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

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

Normal PWM range defaults to 255. -

int gpioSetPWMrange(unsigned user_gpio, unsigned range)

-Selects the dutycycle range to be used for the GPIO. Subsequent calls -to gpioPWM will use a dutycycle between 0 (off) and range (fully on). -

user_gpio: 0-31
    range: 25-40000


Returns the real range for the given GPIO's frequency if OK, -otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. -

If PWM is currently active on the GPIO its dutycycle will be scaled -to reflect the new range. -

The real range, the number of steps between fully off and fully -on for each frequency, is given in the following table. -

  25,   50,  100,  125,  200,  250,  400,   500,   625,
 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000


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

Example

gpioSetPWMrange(24, 2000); // Now 2000 is fully on
                           //     1000 is half on
                           //      500 is quarter on, etc.

int gpioGetPWMrange(unsigned user_gpio)

-Returns the dutycycle range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


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

Example

r = gpioGetPWMrange(23);

int gpioGetPWMrealRange(unsigned user_gpio)

-Returns the real range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


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

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

Example

rr = gpioGetPWMrealRange(17);

int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)

-Sets the frequency in hertz to be used for the GPIO. -

user_gpio: 0-31
frequency: >=0


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO. -

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 frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency.

gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz.

gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency.

int gpioGetPWMfrequency(unsigned user_gpio)

-Returns the frequency (in hertz) used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


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

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

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

Example

f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23.

int gpioServo(unsigned user_gpio, unsigned pulsewidth)

-Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to -2500 (most clockwise). -

 user_gpio: 0-31
pulsewidth: 0, 500-2500


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. -

The range supported by servos varies and should probably be determined -by experiment. A value of 1500 should always be safe and represents -the mid-point of rotation. You can DAMAGE a servo if you command it -to move beyond its limits. -

The following 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

gpioServo(17, 1000); // Move servo to safe position anti-clockwise.

gpioServo(23, 1500); // Move servo to centre position.

gpioServo(25, 2000); // Move servo to safe position clockwise.


OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

PWM Hz    50   100  200  400  500
1E6/Hz 20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using gpioSetPWMfrequency. -

Then set the PWM range using gpioSetPWMrange to 1E6/frequency. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO25 at 400Hz -

gpioSetPWMfrequency(25, 400);

gpioSetPWMrange(25, 2500);


Thereafter use the PWM command to move the servo, -e.g. gpioPWM(25, 1500) will set a 1500 us pulse. -

int gpioGetServoPulsewidth(unsigned user_gpio)

-Returns the servo pulsewidth setting for the GPIO. -

user_gpio: 0-31


Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) -if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)

-Registers a function to be called (a callback) when the specified -GPIO changes state. -

user_gpio: 0-31
        f: the callback function


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -

One callback may be registered per GPIO. -

The callback is passed the GPIO, the new level, and the tick. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The alert may be cancelled by passing NULL as the function. -

The GPIO are sampled at a rate set when the library is started. -

If a value isn't specifically set the default of 5 us is used. -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


Level changes shorter than the sample rate may be missed. -

The thread which calls the alert functions is triggered nominally -1000 times per second. The active alert functions will be called -once per level change since the last time the thread was activated. -i.e. The active alert functions will get all level changes but there -will be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use gpioRead. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

The tick value is the time stamp of the sample in microseconds, see -gpioTick for more details. -

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state

gpioSetAlertFunc(4, aFunction);

int gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when the specified -GPIO changes state. -

user_gpio: 0-31
        f: the callback function
 userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -

One callback may be registered per GPIO. -

The callback is passed the GPIO, the new level, the tick, and -the userdata pointer. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


See gpioSetAlertFunc for further details. -

Only one of gpioSetAlertFunc or gpioSetAlertFuncEx can be -registered per GPIO. -

int gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)

-Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. -

   gpio: 0-53
   edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
timeout: interrupt timeout in milliseconds (<=0 to cancel)
      f: the callback function


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. -

One function may be registered per GPIO. -

The function is passed the GPIO, the current level, and the -current tick. The level will be PI_TIMEOUT if the optional -interrupt timeout expires. -

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The underlying Linux sysfs GPIO interface is used to provide -the interrupt services. -

The first time the function is called, with a non-NULL f, the -GPIO is exported, set to be an input, and set to interrupt -on the given edge and timeout. -

Subsequent calls, with a non-NULL f, can vary one or more of the -edge, timeout, or function. -

The ISR may be cancelled by passing a NULL f, in which case the -GPIO is unexported. -

The tick is that read at the time the process was informed of -the interrupt. This will be a variable number of microseconds -after the interrupt occurred. Typically the latency will be of -the order of 50 microseconds. The latency is not guaranteed -and will vary with system load. -

The level is that read at the time the process was informed of -the interrupt, or PI_TIMEOUT if the optional interrupt timeout -expired. It may not be the same as the expected edge as -interrupts happening in rapid succession may be missed by the -kernel (i.e. this mechanism can not be used to capture several -interrupts only a few microseconds apart). -

int gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. -

    gpio: 0-53
    edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 timeout: interrupt timeout in milliseconds (<=0 to cancel)
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. -

The function is passed the GPIO, the current level, the -current tick, and the userdata pointer. -

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


Only one of gpioSetISRFunc or gpioSetISRFuncEx can be -registered per GPIO. -

See gpioSetISRFunc for further details. -

int gpioNotifyOpen(void)

-This function requests a free notification handle. -

Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

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

Pipe notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). E.g. if the -function returns 15 then the notifications must be read -from /dev/pigpio15. -

Socket notifications are returned to the socket which requested the -handle. -

Example

h = gpioNotifyOpen();

if (h >= 0)
{
   sprintf(str, "/dev/pigpio%d", h);

   fd = open(str, O_RDONLY);

   if (fd >= 0)
   {
      // Okay.
   }
   else
   {
      // Error.
   }
}
else
{
   // Error.
}

int gpioNotifyOpenWithSize(int bufSize)

-This function requests a free notification handle. -

It differs from gpioNotifyOpen in that the pipe size may be -specified, whereas gpioNotifyOpen uses the default pipe size. -

See gpioNotifyOpen for further details. -

int gpioNotifyBegin(unsigned handle, uint32_t bits)

-This function starts notifications on a previously opened handle. -

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the GPIO of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose corresponding -bit in bits is set. -

Each notification occupies 12 bytes in the fifo and has the -following structure. -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

Example

// Start notifications for GPIO 1, 4, 6, 7, 10.

//                         1
//                         0  76 4  1
// (1234 = 0x04D2 = 0b0000010011010010)

gpioNotifyBegin(h, 1234);

int gpioNotifyPause(unsigned handle)

-This function pauses notifications on a previously opened handle. -

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until gpioNotifyBegin -is called again. -

Example

gpioNotifyPause(h);

int gpioNotifyClose(unsigned handle)

-This function stops notifications on a previously opened handle -and releases the handle for reuse. -

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

gpioNotifyClose(h);

int gpioWaveClear(void)

-This function clears all waveforms and any data added by calls to the -gpioWaveAdd* functions. -

Returns 0 if OK. -

Example

gpioWaveClear();

int gpioWaveAddNew(void)

-This function starts a new empty waveform. -

You wouldn't normally need to call this function as it is automatically -called after a waveform is created with the gpioWaveCreate function. -

Returns 0 if OK. -

Example

gpioWaveAddNew();

int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses
   pulses: an array of pulses


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. -

Example

// Construct and send a 30 microsecond square wave.

gpioSetMode(gpio, PI_OUTPUT);

pulse[0].gpioOn = (1<<gpio);
pulse[0].gpioOff = 0;
pulse[0].usDelay = 15;

pulse[1].gpioOn = 0;
pulse[1].gpioOff = (1<<gpio);
pulse[1].usDelay = 15;

gpioWaveAddNew();

gpioWaveAddGeneric(2, pulse);

wave_id = gpioWaveCreate();

if (wave_id >= 0)
{
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);

   // Transmit for 30 seconds.

   sleep(30);

   gpioWaveTxStop();
}
else
{
   // Wave create failed.
}

int gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

user_gpio: 0-31
     baud: 50-1000000
data_bits: 1-32
stop_bits: 2-8
   offset: >=0
 numBytes: >=1
      str: an array of chars (which may contain nulls)


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, and -stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

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

Example

#define MSG_LEN 8

int i;
char *str;
char data[MSG_LEN];

str = "Hello world!";

gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str);

for (i=0; i<MSG_LEN; i++) data[i] = i;

// Data added is offset 1 second from the waveform start.
gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);

int gpioWaveCreate(void)

-This function creates a waveform from the data provided by the prior -calls to the gpioWaveAdd* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the gpioWaveAdd* functions is consumed by this -function. -

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

Normal usage would be -

Step 1. gpioWaveClear to clear all waveforms and added data. -

Step 2. gpioWaveAdd* calls to supply the waveform data. -

Step 3. gpioWaveCreate to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. gpioWaveTxSend with the id of the waveform to transmit. -

A waveform comprises one of more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL)

-Similar to gpioWaveCreate, this function creates a waveform but pads the consumed -resources. Padded waves of equal dimension can be re-cycled efficiently allowing -newly created waves to re-use the resources of deleted waves of the same dimension. -

pctCB: 0-100, the percent of all DMA control blocks to consume.
pctBOOL: 0-100, percent On-Off-Level (OOL) buffer to consume for wave output.
pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags).


Upon success a wave id greater than or equal to 0 is returned, otherwise -PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

Waveform data provided by gpioWaveAdd* and rawWaveAdd* functions are -consumed by this function. -

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Example

  // get firstWaveChunk, somehow
  gpioWaveAddGeneric(firstWaveChunk);
  wid = gpioWaveCreatePad(50, 50, 0);
  gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
  // get nextWaveChunk

  while (nextWaveChunk) {
     gpioWaveAddGeneric(nextWaveChunk);
     nextWid = gpioWaveCreatePad(50, 50, 0);
     gpioWaveTxSend(nextWid, PI_WAVE_MODE_ONE_SHOT_SYNC);
     while(gpioWaveTxAt() == wid) time_sleep(0.1);
     gpioWaveDelete(wid);
     wid = nextWid;
     // get nextWaveChunk
  }

int gpioWaveDelete(unsigned wave_id)

-This function deletes the waveform with id wave_id. -

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

wave_id: >=0, as returned by gpioWaveCreate


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

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)

-This function transmits the waveform with id wave_id. The mode -determines whether the waveform is sent once or cycles endlessly. -The SYNC variants wait for the current waveform to reach the -end of a cycle or finish before starting the new waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. -

  wave_id: >=0, as returned by gpioWaveCreate
wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
           PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int gpioWaveChain(char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. -

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

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpio.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (gpioInitialise()<0) return -1;

   gpioSetMode(GPIO, PI_OUTPUT);

   printf("start piscope, press return"); getchar();

   for (i=0; i<WAVES; i++)
   {
      gpioWaveAddGeneric(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = gpioWaveCreate();
   }

   gpioWaveChain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (gpioWaveTxBusy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);

   printf("stop piscope, press return"); getchar();

   gpioTerminate();
}

int gpioWaveTxAt(void)

-This function returns the id of the waveform currently being -transmitted. -

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

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
-PI_NO_TX_WAVE (9999) - no wave being transmitted. -

int gpioWaveTxBusy(void)

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

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

int gpioWaveTxStop(void)

-This function aborts the transmission of the current waveform. -

Returns 0 if OK. -

This function is intended to stop a waveform started in repeat mode. -

int gpioWaveGetMicros(void)

-This function returns the length in microseconds of the current -waveform. -

int gpioWaveGetHighMicros(void)

-This function returns the length in microseconds of the longest waveform -created since gpioInitialise was called. -

int gpioWaveGetMaxMicros(void)

-This function returns the maximum possible size of a waveform in -microseconds. -

int gpioWaveGetPulses(void)

-This function returns the length in pulses of the current waveform. -

int gpioWaveGetHighPulses(void)

-This function returns the length in pulses of the longest waveform -created since gpioInitialise was called. -

int gpioWaveGetMaxPulses(void)

-This function returns the maximum possible size of a waveform in pulses. -

int gpioWaveGetCbs(void)

-This function returns the length in DMA control blocks of the current -waveform. -

int gpioWaveGetHighCbs(void)

-This function returns the length in DMA control blocks of the longest -waveform created since gpioInitialise was called. -

int gpioWaveGetMaxCbs(void)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

int gpioSerialReadOpen(unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

user_gpio: 0-31
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -PI_BAD_DATABITS, or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -gpioSerialRead. -

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

int gpioSerialReadInvert(unsigned user_gpio, unsigned invert)

-This function configures the level logic for bit bang serial reads. -

Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for -normal logic. Default is PI_BB_SER_NORMAL. -

user_gpio: 0-31
   invert: 0-1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, -PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT. -

The GPIO must be opened for bit bang reading of serial data using -gpioSerialReadOpen prior to calling this function. -

int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

user_gpio: 0-31, previously opened with gpioSerialReadOpen
      buf: an array to receive the read bytes
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the gpioSerialReadOpen command. -

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

int gpioSerialReadClose(unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

user_gpio: 0-31, previously opened with gpioSerialReadOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)

-This returns a handle for the device at the address on the I2C bus. -

  i2cBus: >=0
 i2cAddr: 0-0x7F
i2cFlags: 0


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S      (1 bit) : Start bit
P      (1 bit) : Stop bit
Rd/Wr  (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA  (1 bit) : Accept and not accept bit.

Addr   (7 bits): I2C 7 bit address.
i2cReg (8 bits): Command byte, a byte which often selects a register.
Data   (8 bits): A data byte.
Count  (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2cClose(unsigned handle)

-This closes the I2C device associated with the handle. -

handle: >=0, as returned by a call to i2cOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2cWriteQuick(unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

handle: >=0, as returned by a call to i2cOpen
   bit: 0-1, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr bit [A] P

int i2cWriteByte(unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] bVal [A] P

int i2cReadByte(unsigned handle)

-This reads a single byte from the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

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

int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] i2cReg [A] bVal [A] P

int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  wVal: 0-0xFFFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P

int i2cReadByteData(unsigned handle, unsigned i2cReg)

-This reads a single byte from the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P

int i2cReadWordData(unsigned handle, unsigned i2cReg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
  wVal: 0-0xFFFF, the value to write


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: an array with the data to send
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] i2cReg [A] count [A]
   buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
   buf: an array with the data to send and to receive the read data
 count: 1-32, the number of bytes to write


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The SMBus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A]
   S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P

int i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data
 count: 1-32, the number of bytes to read


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: the data to write
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadDevice(unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

handle: >=0, as returned by a call to i2cOpen
   buf: an array to receive the read data bytes
 count: >0, the number of bytes to read


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteDevice(unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

handle: >=0, as returned by a call to i2cOpen
   buf: an array containing the data bytes to write
 count: >0, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

void i2cSwitchCombined(int setting)

-This sets the I2C (i2c-bcm2708) module "use combined transactions" -parameter on or off. -

setting: 0 to set the parameter off, non-zero to set it on


NOTE: when the flag is on a write followed by a read to the same -slave address will use a repeated start (rather than a stop/start). -

int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)

-This function executes multiple I2C segments in one transaction by -calling the I2C_RDWR ioctl. -

 handle: >=0, as returned by a call to i2cOpen
   segs: an array of I2C segments
numSegs: >0, the number of I2C segments


Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. -

int i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

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

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bbI2CClose(unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bbI2COpen. -

SDA: 0-31, the SDA GPIO used in a prior call to bbI2COpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

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

   SDA: 0-31 (as used in a prior call to bbI2COpen)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


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

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bscXfer(bsc_xfer_t *bsc_xfer)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

bsc_xfer:= a structure defining the transfer

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. -

Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


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

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

The returned function value is the status of the transfer (see below). -

If there was an error the status will be less than zero -(and will contain the error code). -

The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). -

control consists of the following bits. -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. -

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bscXfer(&xfer);

if (status >= 0)
{
   // process transfer
}

int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)

-This function selects a set of GPIO for bit banging SPI with -a specified baud rate and mode. -

      CS: 0-31
    MISO: 0-31
    MOSI: 0-31
    SCLK: 0-31
    baud: 50-250000
spiFlags: see below


spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bbSPIClose(unsigned CS)

-This function stops bit banging SPI on a set of GPIO -opened with bbSPIOpen. -

CS: 0-31, the CS GPIO used in a prior call to bbSPIOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

int bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)

-This function executes a bit banged SPI transfer. -

    CS: 0-31 (as used in a prior call to bbSPIOpen)
 inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
 count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. -

Example

// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
// sudo ./bbSPIx_test

#include <stdio.h>

#include "pigpio.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if (gpioInitialise() < 0)
   {
      fprintf(stderr, "pigpio initialisation failed.\n");
      return 1;
   }

   bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bbSPIClose(CE0);
   bbSPIClose(CE1);

   gpioTerminate();

   return 0;
}

int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


 spiChan: 0-1 (0-2 for the auxiliary SPI)
    baud: 32K-125M (values above 30M are unlikely to work)
spiFlags: see below


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 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. -

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 spiRead, spiWrite, and spiXfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per word.
-For bits 9-16 there will be two bytes per word.
-For bits 17-32 there will be four bytes per word. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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

int spiClose(unsigned handle)

-This functions closes the SPI device identified by the handle. -

handle: >=0, as returned by a call to spiOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spiRead(unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spiOpen
   buf: an array to receive the read data bytes
 count: the number of bytes to read


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spiWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spiOpen
   buf: the data bytes to write
 count: the number of bytes to write


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

handle: >=0, as returned by a call to spiOpen
 txBuf: the data bytes to write
 rxBuf: the received data bytes
 count: the number of bytes to transfer


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serOpen(char *sertty, unsigned baud, unsigned serFlags)

-This function opens a serial device at a specified baud rate -and with specified flags. The device name must start with -/dev/tty or /dev/serial. -

  sertty: the serial device to open
    baud: the baud rate in bits per second, see below
serFlags: 0


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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

No flags are currently defined. This parameter should be set to zero. -

int serClose(unsigned handle)

-This function closes the serial device associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serWriteByte(unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serReadByte(unsigned handle)

-This function reads a byte from the serial port associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

handle: >=0, as returned by a call to serOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serRead(unsigned handle, char *buf, unsigned count)

-This function reads up count bytes from the the serial port -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to serOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_SER_READ_NO_DATA. -

If no data is ready zero is returned. -

int serDataAvailable(unsigned handle)

-This function returns the number of bytes available -to be read from the device associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

user_gpio: 0-31
 pulseLen: 1-100
    level: 0,1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -or PI_BAD_PULSELEN. -

int gpioSetWatchdog(unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

user_gpio: 0-31
  timeout: 0-60000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

One watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Until cancelled a timeout will be reported every timeout milliseconds -after the last GPIO activity. -

In particular: -

1) any registered alert function for the GPIO will be called with - the level set to PI_TIMEOUT. -

2) any notification for the GPIO will have a report written to the - fifo with the flags set to indicate a watchdog timeout. -

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state
gpioSetAlertFunc(4, aFunction);

//  or approximately every 5 millis
gpioSetWatchdog(4, 5);

int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, -and gpioSetGetSamplesFuncEx. -

It does not affect interrupts set up with gpioSetISRFunc, -gpioSetISRFuncEx, or levels read by gpioRead, -gpioRead_Bits_0_31, or gpioRead_Bits_32_53. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

int gpioGlitchFilter(unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, -and gpioSetGetSamplesFuncEx. -

It does not affect interrupts set up with gpioSetISRFunc, -gpioSetISRFuncEx, or levels read by gpioRead, -gpioRead_Bits_0_31, or gpioRead_Bits_32_53. -

Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)

-Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. -

   f: the function to call
bits: the GPIO of interest


Returns 0 if OK. -

The function is passed a pointer to the samples (an array of -gpioSample_t), and the number of samples. -

Only one function can be registered. -

The callback may be cancelled by passing NULL as the function. -

The samples returned will be the union of bits, plus any active alerts, -plus any active notifications. -

e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO -8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO -7, 8, 9, 10, 17, 23, and 24 will be reported. -

int gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)

-Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. -

       f: the function to call
    bits: the GPIO of interest
userdata: a pointer to arbitrary user data


Returns 0 if OK. -

The function is passed a pointer to the samples (an array of -gpioSample_t), the number of samples, and the userdata pointer. -

Only one of gpioGetSamplesFunc or gpioGetSamplesFuncEx can be -registered. -

See gpioSetGetSamplesFunc for further details. -

int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)

-Registers a function to be called (a callback) every millis milliseconds. -

 timer: 0-9
millis: 10-60000
     f: the function to call


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. -

10 timers are supported numbered 0 to 9. -

One function may be registered per timer. -

The timer may be cancelled by passing NULL as the function. -

Example

void bFunction(void)
{
   printf("two seconds have elapsed");
}

// call bFunction every 2000 milliseconds
gpioSetTimerFunc(0, 2000, bFunction);

int gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) every millis milliseconds. -

   timer: 0-9.
  millis: 10-60000
       f: the function to call
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. -

The function is passed the userdata pointer. -

Only one of gpioSetTimerFunc or gpioSetTimerFuncEx can be -registered per timer. -

See gpioSetTimerFunc for further details. -

pthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)

-Starts a new thread of execution with f as the main routine. -

       f: the main function for the new thread
userdata: a pointer to arbitrary user data


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument arg. -

The thread can be cancelled by passing the pointer to pthread_t to -gpioStopThread. -

Example

#include <stdio.h>
#include <pigpio.h>

void *myfunc(void *arg)
{
   while (1)
   {
      printf("%s", arg);
      sleep(1);
   }
}

int main(int argc, char *argv[])
{
   pthread_t *p1, *p2, *p3;

   if (gpioInitialise() < 0) return 1;

   p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);

   p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);

   p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);

   gpioStopThread(p3); sleep(3);

   gpioStopThread(p2); sleep(3);

   gpioStopThread(p1); sleep(3);

   gpioTerminate();
}

void gpioStopThread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: a thread pointer returned by gpioStartThread


No value is returned. -

The thread to be stopped should have been started with gpioStartThread. -

int gpioStoreScript(char *script)

-This function stores a null terminated script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

script: the text of the script


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioScriptStatus(unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well as -the current values of parameters 0 to 9. -

script_id: >=0, as returned by gpioStoreScript
    param: an array to hold the returned 10 parameters


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int gpioStopScript(unsigned script_id)

-This function stops a running script. -

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int gpioDeleteScript(unsigned script_id)

-This function deletes a stored script. -

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)

-Registers a function to be called (a callback) when a signal occurs. -

signum: 0-63
     f: the callback function


Returns 0 if OK, otherwise PI_BAD_SIGNUM. -

The function is passed the signal number. -

One function may be registered per signal. -

The callback may be cancelled by passing NULL. -

By default all signals are treated as fatal and cause the library -to call gpioTerminate and then exit. -

int gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when a signal occurs. -

  signum: 0-63
       f: the callback function
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_SIGNUM. -

The function is passed the signal number and the userdata pointer. -

Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be -registered per signal. -

See gpioSetSignalFunc for further details. -

uint32_t gpioRead_Bits_0_31(void)

-Returns the current level of GPIO 0-31. -

uint32_t gpioRead_Bits_32_53(void)

-Returns the current level of GPIO 32-53. -

int gpioWrite_Bits_0_31_Clear(uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask of GPIO to clear


Returns 0 if OK. -

Example

// To clear (set to 0) GPIO 4, 7, and 15
gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );

int gpioWrite_Bits_32_53_Clear(uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask of GPIO to clear


Returns 0 if OK. -

int gpioWrite_Bits_0_31_Set(uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask of GPIO to set


Returns 0 if OK. -

int gpioWrite_Bits_32_53_Set(uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask of GPIO to set


Returns 0 if OK. -

Example

// To set (set to 1) GPIO 32, 40, and 53
gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));

int gpioHardwareClock(unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

   gpio: see description
clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, -PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by gpioWaveTxSend, or -gpioWaveChain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden by a call to -gpioCfgClock. -

   gpio: see description
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, -PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

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

There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. -

int gpioTime(unsigned timetype, int *seconds, int *micros)

-Updates the seconds and micros variables with the current time. -

timetype: 0 (relative), 1 (absolute)
 seconds: a pointer to an int to hold seconds
  micros: a pointer to an int to hold microseconds


Returns 0 if OK, otherwise PI_BAD_TIMETYPE. -

If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the -number of seconds and microseconds since the epoch (1st January 1970). -

If timetype is PI_TIME_RELATIVE updates seconds and micros with the -number of seconds and microseconds since the library was initialised. -

Example

int secs, mics;

// print the number of seconds since the library was started
gpioTime(PI_TIME_RELATIVE, &secs, &mics);
printf("library started %d.%03d seconds ago", secs, mics/1000);

int gpioSleep(unsigned timetype, int seconds, int micros)

-Sleeps for the number of seconds and microseconds specified by seconds -and micros. -

timetype: 0 (relative), 1 (absolute)
 seconds: seconds to sleep
  micros: microseconds to sleep


Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, -or PI_BAD_MICROS. -

If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds -and microseconds since the epoch (1st January 1970) has elapsed. System -clock changes are taken into account. -

If timetype is PI_TIME_RELATIVE the sleep is for the specified number -of seconds and microseconds. System clock changes do not effect the -sleep length. -

For short delays (say, 50 microseonds or less) use gpioDelay. -

Example

gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds

gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds

gpioSleep(PI_TIME_RELATIVE, 60, 0);     // sleep for one minute

uint32_t gpioDelay(uint32_t micros)

-Delays for at least the number of microseconds specified by micros. -

micros: the number of microseconds to sleep


Returns the actual length of the delay in microseconds. -

Delays of 100 microseconds or less use busy waits. -

uint32_t gpioTick(void)

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

You don't need to worry about the wrap around as long as you -take a tick (uint32_t) from another tick, i.e. the following -code will always provide the correct difference. -

Example

uint32_t startTick, endTick;
int diffTick;

startTick = gpioTick();

// do some processing

endTick = gpioTick();

diffTick = endTick - startTick;

printf("some processing took %d microseconds", diffTick);

unsigned gpioHardwareRevision(void)

-Returns the hardware revision. -

If the hardware revision can not be found or is not a valid hexadecimal -number the function returns 0. -

The hardware revision is the last few characters on the Revision line of -/proc/cpuinfo. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

for "Revision : 0002" the function returns 2.
-for "Revision : 000f" the function returns 15.
-for "Revision : 000g" the function returns 0. -

unsigned gpioVersion(void)

-Returns the pigpio version. -

int gpioGetPad(unsigned pad)

-This function returns the pad drive strength in mA. -

pad: 0-2, the pad to get


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = gpioGetPad(1); // get pad 1 strength

int gpioSetPad(unsigned pad, unsigned padStrength)

-This function sets the pad drive strength in mA. -

        pad: 0-2, the pad to set
padStrength: 1-16 mA


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

gpioSetPad(0, 16); // set pad 0 strength to 16 mA

int eventMonitor(unsigned handle, uint32_t bits)

-This function selects the events to be reported on a previously -opened handle. -

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the events of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

A report is sent each time an event is triggered providing the -corresponding bit in bits is set. -

See gpioNotifyBegin for the notification format. -

Example

// Start reporting events 3, 6, and 7.

//  bit      76543210
// (0xC8 = 0b11001000)

eventMonitor(h, 0xC8);

int eventSetFunc(unsigned event, eventFunc_t f)

-Registers a function to be called (a callback) when the specified -event occurs. -

event: 0-31
    f: the callback function


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

One function may be registered per event. -

The function is passed the event, and the tick. -

The callback may be cancelled by passing NULL as the function. -

int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when the specified -event occurs. -

   event: 0-31
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

One function may be registered per event. -

The function is passed the event, the tick, and the ueserdata pointer. -

The callback may be cancelled by passing NULL as the function. -

Only one of eventSetFunc or eventSetFuncEx can be -registered per event. -

int eventTrigger(unsigned event)

-This function signals the occurrence of an event. -

event: 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling eventSetFunc) will be informed by -a callback. -

One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

int shell(char *scriptName, char *scriptString)

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

  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name
scriptString: the string to pass to the script


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

scriptName must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell("scr1", "\"hello string with spaces world\"");

int fileOpen(char *file, unsigned mode)

-This function returns a handle to a file opened in a specified mode. -

file: the file to open
mode: the file open mode


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


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

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int handle, c;
   char buf[60000];

   if (gpioInitialise() < 0) return 1;

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

   handle = fileOpen("/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=fileRead(handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      fileClose(handle);
   }

   gpioTerminate();
}

int fileClose(unsigned handle)

-This function closes the file associated with handle. -

handle: >=0, as returned by a call to fileOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

fileClose(h);

int fileWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the file -associated with handle. -

handle: >=0, as returned by a call to fileOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. -

Example

status = fileWrite(h, buf, count);
if (status == 0)
{
   // okay
}
else
{
   // error
}

int fileRead(unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the file -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to fileOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. -

Example

if (fileRead(h, buf, sizeof(buf)) > 0)
{
   // process read data
}

int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)

-This function seeks to a position within the file associated -with handle. -

    handle: >=0, as returned by a call to fileOpen
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2)


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. -

Example

fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20

size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size

pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position

int fileList(char *fpat, char *buf, unsigned count)

-This function returns a list of files which match a pattern. The -pattern may contain wildcards. -

 fpat: file pattern to match
  buf: an array to receive the matching file names
count: the maximum number of bytes to read


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See fileOpen. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int c;
   char buf[1000];

   if (gpioInitialise() < 0) return 1;

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

   c = fileList("/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      // terminate string
      buf[c] = 0;
      printf("%s", buf);
   }

   gpioTerminate();
}

int gpioCfgBufferSize(unsigned cfgMillis)

-Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. -

This function is only effective if called before gpioInitialise. -

cfgMillis: 100-10000


The default setting is 120 milliseconds. -

The intention is to allow for bursts of data and protection against -other processes hogging cpu time. -

I haven't seen a process locked out for more than 100 milliseconds. -

Making the buffer bigger uses a LOT of memory at the more frequent -sampling rates as shown in the following table in MBs. -

                     buffer milliseconds
               120 250 500 1sec 2sec 4sec 8sec

         1      16  31  55  107  ---  ---  ---
         2      10  18  31   55  107  ---  ---
sample   4       8  12  18   31   55  107  ---
 rate    5       8  10  14   24   45   87  ---
 (us)    8       6   8  12   18   31   55  107
        10       6   8  10   14   24   45   87

int gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)

-Configures pigpio to use a particular sample rate timed by a specified -peripheral. -

This function is only effective if called before gpioInitialise. -

    cfgMicros: 1, 2, 4, 5, 8, 10
cfgPeripheral: 0 (PWM), 1 (PCM)
    cfgSource: deprecated, value is ignored


The timings are provided by the specified peripheral (PWM or PCM). -

The default setting is 5 microseconds using the PCM peripheral. -

The approximate CPU percentage used for each sample rate is: -

sample  cpu
 rate    %

  1     25
  2     16
  4     11
  5     10
  8     15
 10     14


A sample rate of 5 microseconds seeems to be the sweet spot. -

int gpioCfgDMAchannel(unsigned DMAchannel)

-Configures pigpio to use the specified DMA channel. -

This function is only effective if called before gpioInitialise. -

DMAchannel: 0-14


The default setting is to use channel 14. -

int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)

-Configures pigpio to use the specified DMA channels. -

This function is only effective if called before gpioInitialise. -

  primaryChannel: 0-14
secondaryChannel: 0-14


The default setting depends on whether the Pi has a BCM2711 chip or -not (currently only the Pi4B has a BCM2711). -

The default setting for a non-BCM2711 is to use channel 14 for the -primary channel and channel 6 for the secondary channel. -

The default setting for a BCM2711 is to use channel 7 for the -primary channel and channel 6 for the secondary channel. -

The secondary channel is only used for the transmission of waves. -

If possible use one of channels 0 to 6 for the secondary channel -(a full channel). -

A full channel only requires one DMA control block regardless of the -length of a pulse delay. Channels 7 to 14 (lite channels) require -one DMA control block for each 16383 microseconds of delay. I.e. -a 10 second pulse delay requires one control block on a full channel -and 611 control blocks on a lite channel. -

int gpioCfgPermissions(uint64_t updateMask)

-Configures pigpio to restrict GPIO updates via the socket or pipe -interfaces to the GPIO specified by the mask. Programs directly -calling the pigpio library (i.e. linked with -lpigpio are not -affected). A GPIO update is a write to a GPIO or a GPIO mode -change or any function which would force such an action. -

This function is only effective if called before gpioInitialise. -

updateMask: bit (1<<n) is set for each GPIO n which may be updated


The default setting depends upon the Pi model. The user GPIO are -added to the mask. -

If the board revision is not recognised then GPIO 2-27 are allowed. -

Unknown boardPI_DEFAULT_UPDATE_MASK_UNKNOWN0x0FFFFFFC
Type 1 boardPI_DEFAULT_UPDATE_MASK_B10x03E6CF93
Type 2 boardPI_DEFAULT_UPDATE_MASK_A_B20xFBC6CF9C
Type 3 boardPI_DEFAULT_UPDATE_MASK_R30x0FFFFFFC

int gpioCfgSocketPort(unsigned port)

-Configures pigpio to use the specified socket port. -

This function is only effective if called before gpioInitialise. -

port: 1024-32000


The default setting is to use port 8888. -

int gpioCfgInterfaces(unsigned ifFlags)

-Configures pigpio support of the fifo and socket interfaces. -

This function is only effective if called before gpioInitialise. -

ifFlags: 0-7


The default setting (0) is that both interfaces are enabled. -

Or in PI_DISABLE_FIFO_IF to disable the pipe interface. -

Or in PI_DISABLE_SOCK_IF to disable the socket interface. -

Or in PI_LOCALHOST_SOCK_IF to disable remote socket -access (this means that the socket interface is only -usable from the local Pi). -

int gpioCfgMemAlloc(unsigned memAllocMode)

-Selects the method of DMA memory allocation. -

This function is only effective if called before gpioInitialise. -

memAllocMode: 0-2


There are two methods of DMA memory allocation. The original method -uses the /proc/self/pagemap file to allocate bus memory. The new -method uses the mailbox property interface to allocate bus memory. -

Auto will use the mailbox method unless a larger than default buffer -size is requested with gpioCfgBufferSize. -

int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)

-Sets the network addresses which are allowed to talk over the -socket interface. -

This function is only effective if called before gpioInitialise. -

numSockAddr: 0-256 (0 means all addresses allowed)
   sockAddr: an array of permitted network addresses.

int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)

-Used to tune internal settings. -

cfgWhat: see source code
 cfgVal: see source code

uint32_t gpioCfgGetInternals(void)

-This function returns the current library internal configuration -settings. -

int gpioCfgSetInternals(uint32_t cfgVal)

-This function sets the current library internal configuration -settings. -

cfgVal: see source code

int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from gpioCustom1 in that it returns an array of bytes -rather than just an integer. -

The returned value is an integer indicating the number of returned bytes. -  arg1: >=0
  argx: extra (byte) arguments
  argc: number of extra arguments
retBuf: buffer for returned bytes
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

The number of returned bytes must be retMax or less. -

int rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)

-This function adds a waveform representing SPI data to the -existing waveform (if any). -

        spi: a pointer to a spi object
     offset: microseconds from the start of the waveform
      spiSS: the slave select GPIO
        buf: the bits to transmit, most significant bit first
  spiTxBits: the number of bits to write
spiBitFirst: the first bit to read
 spiBitLast: the last bit to read
    spiBits: the number of bits to transfer


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. -

Not intended for general use. -

int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses
   pulses: the array containing the pulses


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The advantage of this function over gpioWaveAddGeneric is that it -allows the setting of the flags field. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. -

Not intended for general use. -

unsigned rawWaveCB(void)

-Returns the number of the cb being currently output. -

Not intended for general use. -

rawCbs_t *rawWaveCBAdr(int cbNum)

-Return the (Linux) address of contol block cbNum. -

cbNum: the cb of interest


Not intended for general use. -

uint32_t rawWaveGetOOL(int pos)

-Gets the OOL parameter stored at pos. -

pos: the position of interest.


Not intended for general use. -

void rawWaveSetOOL(int pos, uint32_t lVal)

-Sets the OOL parameter stored at pos to value. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

uint32_t rawWaveGetOut(int pos)

-Gets the wave output parameter stored at pos. -

DEPRECATED: use rawWaveGetOOL instead. -

pos: the position of interest.


Not intended for general use. -

void rawWaveSetOut(int pos, uint32_t lVal)

-Sets the wave output parameter stored at pos to value. -

DEPRECATED: use rawWaveSetOOL instead. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

uint32_t rawWaveGetIn(int pos)

-Gets the wave input value parameter stored at pos. -

DEPRECATED: use rawWaveGetOOL instead. -

pos: the position of interest


Not intended for general use. -

void rawWaveSetIn(int pos, uint32_t lVal)

-Sets the wave input value stored at pos to value. -

DEPRECATED: use rawWaveSetOOL instead. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

rawWaveInfo_t rawWaveInfo(int wave_id)

-Gets details about the wave with id wave_id. -

wave_id: the wave of interest


Not intended for general use. -

int getBitInBytes(int bitPos, char *buf, int numBits)

-Returns the value of the bit bitPos bits from the start of buf. Returns -0 if bitPos is greater than or equal to numBits. -

 bitPos: bit index from the start of buf
    buf: array of bits
numBits: number of valid bits in buf

void putBitInBytes(int bitPos, char *buf, int bit)

-Sets the bit bitPos bits from the start of buf to bit. -

bitPos: bit index from the start of buf
   buf: array of bits
   bit: 0-1, value to set

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds -

seconds: the number of seconds to sleep

void rawDumpWave(void)

-Used to print a readable version of the current waveform to stderr. -

Not intended for general use. -

void rawDumpScript(unsigned script_id)

-Used to print a readable version of a script to stderr. -

script_id: >=0, a script_id returned by gpioStoreScript


Not intended for general use. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bitPos

-A bit position within a byte or word. The least significant bit is -position 0. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

*bsc_xfer

-A pointer to a bsc_xfer_t object used to control a BSC transfer. -

bsc_xfer_t

-typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

cbNum

-A number identifying a DMA contol block. -

cfgMicros

-The GPIO sample rate in microseconds. The default is 5us, or 200 thousand -samples per second. -

cfgMillis: 100-10000

-The size of the sample buffer in milliseconds. Generally this should be -left at the default of 120ms. If you expect intense bursts of signals it -might be necessary to increase the buffer size. -

cfgPeripheral

-One of the PWM or PCM peripherals used to pace DMA transfers for timing -purposes. -

cfgSource

-Deprecated. -

cfgVal

-A number specifying the value of a configuration item. See cfgWhat. -

cfgWhat

-A number specifying a configuration item. -

562484977: print enhanced statistics at termination.
-984762879: set the initial debug level. -

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

-The hardware clock frequency. -

PI_HW_CLK_MIN_FREQ 4689
PI_HW_CLK_MAX_FREQ 250000000
PI_HW_CLK_MAX_FREQ_2711 375000000

count

-The number of bytes to be transferred in an I2C, SPI, or Serial -command. -

CS

-The GPIO used for the slave select signal when bit banging SPI. -

data_bits: 1-32

-The number of data bits to be used when adding serial data to a -waveform. -

PI_MIN_WAVE_DATABITS 1
PI_MAX_WAVE_DATABITS 32

DMAchannel: 0-15

-PI_MIN_DMA_CHANNEL 0
PI_MAX_DMA_CHANNEL 15

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge: 0-2

-The type of GPIO edge to generate an interrupt. See gpioSetISRFunc -and gpioSetISRFuncEx. -

RISING_EDGE 0
FALLING_EDGE 1
EITHER_EDGE 2

event: 0-31

-An event is a signal used to inform one or more consumers -to start an action. -

eventFunc_t

-typedef void (*eventFunc_t) (int event, uint32_t tick);

eventFuncEx_t

-typedef void (*eventFuncEx_t)
   (int event, uint32_t tick, void *userdata);

f

-A function. -

*file

-A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. -

*fpat

-A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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

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

gpioAlertFunc_t

-typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);

gpioAlertFuncEx_t

-typedef void (*eventFuncEx_t)
   (int event, int level, uint32_t tick, void *userdata);

gpioCfg*

-These functions are only effective if called before gpioInitialise. -

gpioCfgBufferSize
-gpioCfgClock
-gpioCfgDMAchannel
-gpioCfgDMAchannels
-gpioCfgPermissions
-gpioCfgInterfaces
-gpioCfgSocketPort
-gpioCfgMemAlloc -

gpioGetSamplesFunc_t

-typedef void (*gpioGetSamplesFunc_t)
   (const gpioSample_t *samples, int numSamples);

gpioGetSamplesFuncEx_t

-typedef void (*gpioGetSamplesFuncEx_t)
   (const gpioSample_t *samples, int numSamples, void *userdata);

gpioISRFunc_t

-typedef void (*gpioISRFunc_t)
   (int gpio, int level, uint32_t tick);

gpioISRFuncEx_t

-typedef void (*gpioISRFuncEx_t)
   (int gpio, int level, uint32_t tick, void *userdata);

gpioPulse_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioSample_t

-typedef struct
{
   uint32_t tick;
   uint32_t level;
} gpioSample_t;

gpioSignalFunc_t

-typedef void (*gpioSignalFunc_t) (int signum);

gpioSignalFuncEx_t

-typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

gpioTimerFunc_t

-typedef void (*gpioTimerFunc_t) (void);

gpioTimerFuncEx_t

-typedef void (*gpioTimerFuncEx_t) (void *userdata);

gpioWaveAdd*

-One of -

gpioWaveAddNew
-gpioWaveAddGeneric
-gpioWaveAddSerial -

handle: >=0

-A number referencing an object opened by one of -

fileOpen
-gpioNotifyOpen
-i2cOpen
-serOpen
-spiOpen -

i2cAddr: 0-0x7F

-The address of a device on the I2C bus. -

i2cBus: >=0

-An I2C bus number. -

i2cFlags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2cReg: 0-255

-A register of an I2C device. -

ifFlags: 0-3

-PI_DISABLE_FIFO_IF 1
PI_DISABLE_SOCK_IF 2

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

int32_t

-A 32-bit signed value. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See gpioSetWatchdog. -

PI_TIMEOUT 2

lVal: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)

-A 32-bit word value. -

memAllocMode: 0-2

-The DMA memory allocation mode. -

PI_MEM_ALLOC_AUTO    0
PI_MEM_ALLOC_PAGEMAP 1
PI_MEM_ALLOC_MAILBOX 2

*micros

-A value representing microseconds. -

micros

-A value representing microseconds. -

millis

-A value representing milliseconds. -

MISO

-The GPIO used for the MISO signal when bit banging SPI. -

mode

-1. The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. A file open mode. -

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


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

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

-The GPIO used for the MOSI signal when bit banging SPI. -

numBits

-The number of bits stored in a buffer. -

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

numSegs

-The number of segments in a combined I2C transaction. -

numSockAddr

-The number of network addresses allowed to use the socket interface. -

0 means all addresses allowed. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

pad: 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

-The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

*param

-An array of script parameters. -

pctBOOL: 0-100

-percent On-Off-Level (OOL) buffer to consume for wave output. -

pctCB: 0-100

-the percent of all DMA control blocks to consume. -

pctTOOL: 0-100

-the percent of OOL buffer to consume for wave input (flags). -

pi_i2c_msg_t

-typedef struct
{
   uint16_t addr;  // slave address
   uint16_t flags;
   uint16_t len;   // msg length
   uint8_t  *buf;  // pointer to msg data
} pi_i2c_msg_t;

port: 1024-32000

-The port used to bind to the pigpio socket. Defaults to 8888. -

pos

-The position of an item. -

primaryChannel: 0-15

-The DMA channel used to time the sampling of GPIO and to time servo and -PWM pulses. -

*pth

-A thread identifier, returned by gpioStartThread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -

PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

-The hardware PWM frequency. -

PI_HW_PWM_MIN_FREQ 1
PI_HW_PWM_MAX_FREQ 125000000
PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

-PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

rawCbs_t

-typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
{
   unsigned long info;
   unsigned long src;
   unsigned long dst;
   unsigned long length;
   unsigned long stride;
   unsigned long next;
   unsigned long pad[2];
} rawCbs_t;

rawSPI_t

-typedef struct
{
   int clk;     // GPIO for clock
   int mosi;    // GPIO for MOSI
   int miso;    // GPIO for MISO
   int ss_pol;  // slave select off state
   int ss_us;   // delay after slave select
   int clk_pol; // clock off state
   int clk_pha; // clock phase
   int clk_us;  // clock micros
} rawSPI_t;

rawWave_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
   uint32_t flags;
} rawWave_t;

rawWaveInfo_t

-typedef struct
{
   uint16_t botCB;  // first CB used by wave
   uint16_t topCB;  // last CB used by wave
   uint16_t botOOL; // last OOL used by wave
   uint16_t topOOL; // first OOL used by wave
   uint16_t deleted;
   uint16_t numCB;
   uint16_t numBOOL;
   uint16_t numTOOL;
} rawWaveInfo_t;

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

SCLK

-The GPIO used for the SCLK signal when bit banging SPI. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by gpioStoreScript. -

*scriptName

-The name of a shell script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. -

*scriptString

-The string to be passed to a shell script to be executed. -

SDA

-The user GPIO to use for data when bit banging I2C. -

secondaryChannel: 0-6

-The DMA channel used to time output waveforms. -

*seconds

-A pointer to a uint32_t to store the second component of -a returned time. -

seconds

-The number of seconds. -

seekFrom

-PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

-The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). -

*segs

-An array of segments which make up a combined I2C transaction. -

serFlags

-Flags which modify a serial open command. None are currently defined. -

*sertty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

setting

-A value used to set a flag, 0 for false, non-zero for true. -

signum: 0-63

-PI_MIN_SIGNUM 0
PI_MAX_SIGNUM 63

size_t

-A standard type used to indicate the size of an object in bytes. -

*sockAddr

-An array of network addresses allowed to use the socket interface encoded -as 32 bit numbers. -

E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. -

*spi

-A pointer to a rawSPI_t structure. -

spiBitFirst

-GPIO reads are made from spiBitFirst to spiBitLast. -

spiBitLast

-GPIO reads are made from spiBitFirst to spiBitLast. -

spiBits

-The number of bits to transfer in a raw SPI transaction. -

spiChan

-A SPI channel, 0-2. -

spiFlags

-See spiOpen and bbSPIOpen. -

spiSS

-The SPI slave select GPIO in a raw SPI transaction. -

spiTxBits

-The number of bits to transfer dring a raw SPI transaction -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (gpioGlitchFilter) or triggering -the active part of a noise filter (gpioNoiseFilter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

PI_MIN_WAVE_HALFSTOPBITS 2
PI_MAX_WAVE_HALFSTOPBITS 8

*str

-An array of characters. -

timeout

-A GPIO level change timeout in milliseconds. -

gpioSetWatchdog -PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000


gpioSetISRFunc and gpioSetISRFuncEx -<=0 cancel timeout
>0 timeout after specified milliseconds

timer

-PI_MIN_TIMER 0
PI_MAX_TIMER 9

timetype

-PI_TIME_RELATIVE 0
PI_TIME_ABSOLUTE 1

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

uint64_t: 0-(2^64)-1

-A 64-bit unsigned value. -

unsigned

-A whole number >= 0. -

updateMask

-A 64 bit mask indicating which GPIO may be written to by the user. -

If GPIO#n may be written then bit (1<<n) is set. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. -

In the calling function: -

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: -

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

-Denoting no parameter is required -

wave_id

-A number identifying a waveform created by gpioWaveCreate. -

wave_mode

-The mode determines if the waveform is sent once or cycles -repeatedly. The SYNC variants wait for the current waveform -to reach the end of a cycle or finish before starting the new -waveform. -

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

Socket Command Codes


#define PI_CMD_MODES  0
#define PI_CMD_MODEG  1
#define PI_CMD_PUD    2
#define PI_CMD_READ   3
#define PI_CMD_WRITE  4
#define PI_CMD_PWM    5
#define PI_CMD_PRS    6
#define PI_CMD_PFS    7
#define PI_CMD_SERVO  8
#define PI_CMD_WDOG   9
#define PI_CMD_BR1   10
#define PI_CMD_BR2   11
#define PI_CMD_BC1   12
#define PI_CMD_BC2   13
#define PI_CMD_BS1   14
#define PI_CMD_BS2   15
#define PI_CMD_TICK  16
#define PI_CMD_HWVER 17
#define PI_CMD_NO    18
#define PI_CMD_NB    19
#define PI_CMD_NP    20
#define PI_CMD_NC    21
#define PI_CMD_PRG   22
#define PI_CMD_PFG   23
#define PI_CMD_PRRG  24
#define PI_CMD_HELP  25
#define PI_CMD_PIGPV 26
#define PI_CMD_WVCLR 27
#define PI_CMD_WVAG  28
#define PI_CMD_WVAS  29
#define PI_CMD_WVGO  30
#define PI_CMD_WVGOR 31
#define PI_CMD_WVBSY 32
#define PI_CMD_WVHLT 33
#define PI_CMD_WVSM  34
#define PI_CMD_WVSP  35
#define PI_CMD_WVSC  36
#define PI_CMD_TRIG  37
#define PI_CMD_PROC  38
#define PI_CMD_PROCD 39
#define PI_CMD_PROCR 40
#define PI_CMD_PROCS 41
#define PI_CMD_SLRO  42
#define PI_CMD_SLR   43
#define PI_CMD_SLRC  44
#define PI_CMD_PROCP 45
#define PI_CMD_MICS  46
#define PI_CMD_MILS  47
#define PI_CMD_PARSE 48
#define PI_CMD_WVCRE 49
#define PI_CMD_WVDEL 50
#define PI_CMD_WVTX  51
#define PI_CMD_WVTXR 52
#define PI_CMD_WVNEW 53

#define PI_CMD_I2CO  54
#define PI_CMD_I2CC  55
#define PI_CMD_I2CRD 56
#define PI_CMD_I2CWD 57
#define PI_CMD_I2CWQ 58
#define PI_CMD_I2CRS 59
#define PI_CMD_I2CWS 60
#define PI_CMD_I2CRB 61
#define PI_CMD_I2CWB 62
#define PI_CMD_I2CRW 63
#define PI_CMD_I2CWW 64
#define PI_CMD_I2CRK 65
#define PI_CMD_I2CWK 66
#define PI_CMD_I2CRI 67
#define PI_CMD_I2CWI 68
#define PI_CMD_I2CPC 69
#define PI_CMD_I2CPK 70

#define PI_CMD_SPIO  71
#define PI_CMD_SPIC  72
#define PI_CMD_SPIR  73
#define PI_CMD_SPIW  74
#define PI_CMD_SPIX  75

#define PI_CMD_SERO  76
#define PI_CMD_SERC  77
#define PI_CMD_SERRB 78
#define PI_CMD_SERWB 79
#define PI_CMD_SERR  80
#define PI_CMD_SERW  81
#define PI_CMD_SERDA 82

#define PI_CMD_GDC   83
#define PI_CMD_GPW   84

#define PI_CMD_HC    85
#define PI_CMD_HP    86

#define PI_CMD_CF1   87
#define PI_CMD_CF2   88

#define PI_CMD_BI2CC 89
#define PI_CMD_BI2CO 90
#define PI_CMD_BI2CZ 91

#define PI_CMD_I2CZ  92

#define PI_CMD_WVCHA 93

#define PI_CMD_SLRI  94

#define PI_CMD_CGI   95
#define PI_CMD_CSI   96

#define PI_CMD_FG    97
#define PI_CMD_FN    98

#define PI_CMD_NOIB  99

#define PI_CMD_WVTXM 100
#define PI_CMD_WVTAT 101

#define PI_CMD_PADS  102
#define PI_CMD_PADG  103

#define PI_CMD_FO    104
#define PI_CMD_FC    105
#define PI_CMD_FR    106
#define PI_CMD_FW    107
#define PI_CMD_FS    108
#define PI_CMD_FL    109

#define PI_CMD_SHELL 110

#define PI_CMD_BSPIC 111
#define PI_CMD_BSPIO 112
#define PI_CMD_BSPIX 113

#define PI_CMD_BSCX  114

#define PI_CMD_EVM   115
#define PI_CMD_EVT   116

#define PI_CMD_PROCU 117
#define PI_CMD_WVCAP 118

Error Codes


#define PI_INIT_FAILED       -1 // gpioInitialise failed
#define PI_BAD_USER_GPIO     -2 // GPIO not 0-31
#define PI_BAD_GPIO          -3 // GPIO not 0-53
#define PI_BAD_MODE          -4 // mode not 0-7
#define PI_BAD_LEVEL         -5 // level not 0-1
#define PI_BAD_PUD           -6 // pud not 0-2
#define PI_BAD_PULSEWIDTH    -7 // pulsewidth not 0 or 500-2500
#define PI_BAD_DUTYCYCLE     -8 // dutycycle outside set range
#define PI_BAD_TIMER         -9 // timer not 0-9
#define PI_BAD_MS           -10 // ms not 10-60000
#define PI_BAD_TIMETYPE     -11 // timetype not 0-1
#define PI_BAD_SECONDS      -12 // seconds < 0
#define PI_BAD_MICROS       -13 // micros not 0-999999
#define PI_TIMER_FAILED     -14 // gpioSetTimerFunc failed
#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
#define PI_NO_ALERT_FUNC    -16 // DEPRECATED
#define PI_BAD_CLK_PERIPH   -17 // clock peripheral not 0-1
#define PI_BAD_CLK_SOURCE   -18 // DEPRECATED
#define PI_BAD_CLK_MICROS   -19 // clock micros not 1, 2, 4, 5, 8, or 10
#define PI_BAD_BUF_MILLIS   -20 // buf millis not 100-10000
#define PI_BAD_DUTYRANGE    -21 // dutycycle range not 25-40000
#define PI_BAD_DUTY_RANGE   -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
#define PI_BAD_SIGNUM       -22 // signum not 0-63
#define PI_BAD_PATHNAME     -23 // can't open pathname
#define PI_NO_HANDLE        -24 // no handle available
#define PI_BAD_HANDLE       -25 // unknown handle
#define PI_BAD_IF_FLAGS     -26 // ifFlags > 4
#define PI_BAD_CHANNEL      -27 // DMA channel not 0-15
#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15
#define PI_BAD_SOCKET_PORT  -28 // socket port not 1024-32000
#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15
#define PI_NOT_INITIALISED  -31 // function called before gpioInitialise
#define PI_INITIALISED      -32 // function called after gpioInitialise
#define PI_BAD_WAVE_MODE    -33 // waveform mode not 0-3
#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
#define PI_BAD_WAVE_BAUD    -35 // baud rate not 50-250K(RX)/50-1M(TX)
#define PI_TOO_MANY_PULSES  -36 // waveform has too many pulses
#define PI_TOO_MANY_CHARS   -37 // waveform has too many chars
#define PI_NOT_SERIAL_GPIO  -38 // no bit bang serial read on GPIO
#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
#define PI_BAD_SERIAL_BUF   -40 // bad (null) serial buf parameter
#define PI_NOT_PERMITTED    -41 // GPIO operation not permitted
#define PI_SOME_PERMITTED   -42 // one or more GPIO not permitted
#define PI_BAD_WVSC_COMMND  -43 // bad WVSC subcommand
#define PI_BAD_WVSM_COMMND  -44 // bad WVSM subcommand
#define PI_BAD_WVSP_COMMND  -45 // bad WVSP subcommand
#define PI_BAD_PULSELEN     -46 // trigger pulse length not 1-100
#define PI_BAD_SCRIPT       -47 // invalid script
#define PI_BAD_SCRIPT_ID    -48 // unknown script id
#define PI_BAD_SER_OFFSET   -49 // add serial data offset > 30 minutes
#define PI_GPIO_IN_USE      -50 // GPIO already in use
#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
#define PI_BAD_PARAM_NUM    -52 // script parameter id not 0-9
#define PI_DUP_TAG          -53 // script has duplicate tag
#define PI_TOO_MANY_TAGS    -54 // script has too many tags
#define PI_BAD_SCRIPT_CMD   -55 // illegal script command
#define PI_BAD_VAR_NUM      -56 // script variable id not 0-149
#define PI_NO_SCRIPT_ROOM   -57 // no more room for scripts
#define PI_NO_MEMORY        -58 // can't allocate temporary memory
#define PI_SOCK_READ_FAILED -59 // socket read failed
#define PI_SOCK_WRIT_FAILED -60 // socket write failed
#define PI_TOO_MANY_PARAM   -61 // too many script parameters (> 10)
#define PI_NOT_HALTED       -62 // DEPRECATED
#define PI_SCRIPT_NOT_READY -62 // script initialising
#define PI_BAD_TAG          -63 // script has unresolved tag
#define PI_BAD_MICS_DELAY   -64 // bad MICS delay (too large)
#define PI_BAD_MILS_DELAY   -65 // bad MILS delay (too large)
#define PI_BAD_WAVE_ID      -66 // non existent wave id
#define PI_TOO_MANY_CBS     -67 // No more CBs for waveform
#define PI_TOO_MANY_OOL     -68 // No more OOL for waveform
#define PI_EMPTY_WAVEFORM   -69 // attempt to create an empty waveform
#define PI_NO_WAVEFORM_ID   -70 // no more waveforms
#define PI_I2C_OPEN_FAILED  -71 // can't open I2C device
#define PI_SER_OPEN_FAILED  -72 // can't open serial device
#define PI_SPI_OPEN_FAILED  -73 // can't open SPI device
#define PI_BAD_I2C_BUS      -74 // bad I2C bus
#define PI_BAD_I2C_ADDR     -75 // bad I2C address
#define PI_BAD_SPI_CHANNEL  -76 // bad SPI channel
#define PI_BAD_FLAGS        -77 // bad i2c/spi/ser open flags
#define PI_BAD_SPI_SPEED    -78 // bad SPI speed
#define PI_BAD_SER_DEVICE   -79 // bad serial device name
#define PI_BAD_SER_SPEED    -80 // bad serial baud rate
#define PI_BAD_PARAM        -81 // bad i2c/spi/ser parameter
#define PI_I2C_WRITE_FAILED -82 // i2c write failed
#define PI_I2C_READ_FAILED  -83 // i2c read failed
#define PI_BAD_SPI_COUNT    -84 // bad SPI count
#define PI_SER_WRITE_FAILED -85 // ser write failed
#define PI_SER_READ_FAILED  -86 // ser read failed
#define PI_SER_READ_NO_DATA -87 // ser read no data available
#define PI_UNKNOWN_COMMAND  -88 // unknown command
#define PI_SPI_XFER_FAILED  -89 // spi xfer/read/write failed
#define PI_BAD_POINTER      -90 // bad (NULL) pointer
#define PI_NO_AUX_SPI       -91 // no auxiliary SPI on Pi A or B
#define PI_NOT_PWM_GPIO     -92 // GPIO is not in use for PWM
#define PI_NOT_SERVO_GPIO   -93 // GPIO is not in use for servo pulses
#define PI_NOT_HCLK_GPIO    -94 // GPIO has no hardware clock
#define PI_NOT_HPWM_GPIO    -95 // GPIO has no hardware PWM
#define PI_BAD_HPWM_FREQ    -96 // invalid hardware PWM frequency
#define PI_BAD_HPWM_DUTY    -97 // hardware PWM dutycycle not 0-1M
#define PI_BAD_HCLK_FREQ    -98 // invalid hardware clock frequency
#define PI_BAD_HCLK_PASS    -99 // need password to use hardware clock 1
#define PI_HPWM_ILLEGAL    -100 // illegal, PWM in use for main clock
#define PI_BAD_DATABITS    -101 // serial data bits not 1-32
#define PI_BAD_STOPBITS    -102 // serial (half) stop bits not 2-8
#define PI_MSG_TOOBIG      -103 // socket/pipe message too big
#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode
#define PI_TOO_MANY_SEGS   -105 // too many I2C transaction segments
#define PI_BAD_I2C_SEG     -106 // an I2C transaction segment failed
#define PI_BAD_SMBUS_CMD   -107 // SMBus command not supported by driver
#define PI_NOT_I2C_GPIO    -108 // no bit bang I2C in progress on GPIO
#define PI_BAD_I2C_WLEN    -109 // bad I2C write length
#define PI_BAD_I2C_RLEN    -110 // bad I2C read length
#define PI_BAD_I2C_CMD     -111 // bad I2C command
#define PI_BAD_I2C_BAUD    -112 // bad I2C baud rate, not 50-500k
#define PI_CHAIN_LOOP_CNT  -113 // bad chain loop count
#define PI_BAD_CHAIN_LOOP  -114 // empty chain loop
#define PI_CHAIN_COUNTER   -115 // too many chain counters
#define PI_BAD_CHAIN_CMD   -116 // bad chain command
#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
#define PI_CHAIN_NESTING   -118 // chain counters nested too deeply
#define PI_CHAIN_TOO_BIG   -119 // chain is too long
#define PI_DEPRECATED      -120 // deprecated function removed
#define PI_BAD_SER_INVERT  -121 // bit bang serial invert not 0 or 1
#define PI_BAD_EDGE        -122 // bad ISR edge value, not 0-2
#define PI_BAD_ISR_INIT    -123 // bad ISR initialisation
#define PI_BAD_FOREVER     -124 // loop forever must be last command
#define PI_BAD_FILTER      -125 // bad filter parameter
#define PI_BAD_PAD         -126 // bad pad number
#define PI_BAD_STRENGTH    -127 // bad pad drive strength
#define PI_FIL_OPEN_FAILED -128 // file open failed
#define PI_BAD_FILE_MODE   -129 // bad file mode
#define PI_BAD_FILE_FLAG   -130 // bad file flag
#define PI_BAD_FILE_READ   -131 // bad file read
#define PI_BAD_FILE_WRITE  -132 // bad file write
#define PI_FILE_NOT_ROPEN  -133 // file not open for read
#define PI_FILE_NOT_WOPEN  -134 // file not open for write
#define PI_BAD_FILE_SEEK   -135 // bad file seek
#define PI_NO_FILE_MATCH   -136 // no files match pattern
#define PI_NO_FILE_ACCESS  -137 // no permission to access file
#define PI_FILE_IS_A_DIR   -138 // file is a directory
#define PI_BAD_SHELL_STATUS -139 // bad shell return status
#define PI_BAD_SCRIPT_NAME -140 // bad script name
#define PI_BAD_SPI_BAUD    -141 // bad SPI baud rate, not 50-500k
#define PI_NOT_SPI_GPIO    -142 // no bit bang SPI in progress on GPIO
#define PI_BAD_EVENT_ID    -143 // bad event id
#define PI_CMD_INTERRUPTED -144 // Used by Python
#define PI_NOT_ON_BCM2711  -145 // not available on BCM2711
#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711

#define PI_PIGIF_ERR_0    -2000
#define PI_PIGIF_ERR_99   -2099

#define PI_CUSTOM_ERR_0   -3000
#define PI_CUSTOM_ERR_999 -3999

Defaults


#define PI_DEFAULT_BUFFER_MILLIS           120
#define PI_DEFAULT_CLK_MICROS              5
#define PI_DEFAULT_CLK_PERIPHERAL          PI_CLOCK_PCM
#define PI_DEFAULT_IF_FLAGS                0
#define PI_DEFAULT_FOREGROUND              0
#define PI_DEFAULT_DMA_CHANNEL             14
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL     14
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL   6
#define PI_DEFAULT_DMA_PRIMARY_CH_2711     7
#define PI_DEFAULT_DMA_SECONDARY_CH_2711   6
#define PI_DEFAULT_DMA_NOT_SET             15
#define PI_DEFAULT_SOCKET_PORT             8888
#define PI_DEFAULT_SOCKET_PORT_STR         "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR         "localhost"
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN     0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_B1          0x03E7CF93
#define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_ZERO        0x0080000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI2B        0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI3B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI4B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_COMPUTE     0x00FFFFFFFFFFFFLL
#define PI_DEFAULT_MEM_ALLOC_MODE          PI_MEM_ALLOC_AUTO

#define PI_DEFAULT_CFG_INTERNALS           0

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/download.html b/DOC/HTML/download.html deleted file mode 100644 index 84ec4da..0000000 --- a/DOC/HTML/download.html +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Download & Install

-If the pigpio daemon is running it should be killed (sudo killall -pigpiod) before make install and restarted afterwards (sudo -pigpiod).
-
-The initial part of the make, the -compilation of pigpio.c, takes 100 seconds on early model -Pis.  Be patient.  The overall install takes just over 3 -minutes.
-

Download and install (V75)

-wget https://github.com/joan2937/pigpio/archive/v75.zip
-unzip v75.zip
-cd pigpio-75
-make
-sudo make install

-
-If the Python part of the install fails it may be because you need -the setup tools.
-
-sudo apt install python-setuptools -python3-setuptools

-
-

To check the library

-These tests make extensive use of GPIO 25 (pin 22).  Make sure -nothing, or only a LED, is connected to the GPIO before running the -tests.  Most tests are statistical in nature and so may on -occasion fail.  Repeated failures on the same test or many -failures in a group of tests indicate a problem.
-
-sudo ./x_pigpio # check C I/F
-
-sudo pigpiod    # start daemon
-
-./x_pigpiod_if2 # check C      I/F to -daemon
-./x_pigpio.py   # check Python I/F to daemon
-./x_pigs        # check -pigs   I/F to daemon
-./x_pipe        # check -pipe   I/F to daemon
-
-
-

To compile, link, and run a C program

-gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
-sudo ./foobar


-

To start the pigpio daemon

-sudo pigpiod
-

To stop the pigpio daemon

-sudo killall pigpiod

-

github

-git clone https://github.com/joan2937/pigpio
-

Raspbian (raspberrypi.org image)

-

This may not be the most recent version.  You can check the -version with the command pigpiod -v.

-sudo apt-get update
-sudo apt-get install pigpio python-pigpio python3-pigpio

-
-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_LDR.html b/DOC/HTML/ex_LDR.html deleted file mode 100644 index 6b1cf23..0000000 --- a/DOC/HTML/ex_LDR.html +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

LDR Example

-

The following code shows a method of reading analogue sensors on -the digital input only Pi.  A Light Dependent Resistor (LDR) -varies its resistance according to the incident light -intensisty.

-

SETUP

-fritzing diagramThe LDR -used is a Cadmium Sulphide device with a 1MOhm dark resistance and -2-4KOhm at 100 lux.  The capacitor is a 104 -ceramic.
-
-One end of the capacitor is connected to Pi ground.
-
-One end of the LDR is connected to Pi 3V3.
-
-The other ends of the capacitor and LDR are connected to a spare -gpio.

-

Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18 -(P1-12) is used for the gpio.

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/* ------------------------------------------------------------------------
- -
-   3V3 ----- Light Dependent Resistor --+-- Capacitor ------ Ground
-                                        -|
-                                        -+-- gpio
-
-
-  cc -o LDR LDR.c -lpigpio -lpthread -lrt
-  sudo ./LDR
-
-*/
-
-#define LDR 18
-
-/* forward declaration */
-
-void alert(int pin, int level, uint32_t tick);
-
-int main (int argc, char *argv[])
-{
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetAlertFunc(LDR, alert); /* call alert when LDR -changes state */
-    
-   while (1)
-   {
-      gpioSetMode(LDR, PI_OUTPUT); /* -drain capacitor */
-
-      gpioWrite(LDR, PI_OFF);
-
-      gpioDelay(200); /* 50 micros is -enough, 200 is overkill */
-
-      gpioSetMode(LDR, PI_INPUT); /* start -capacitor recharge */
-
-      gpioDelay(10000); /* nominal 100 -readings per second */
-   }
-
-   gpioTerminate();
-}
-
-void alert(int pin, int level, uint32_t tick)
-{
-   static uint32_t inited = 0;
-   static uint32_t lastTick, firstTick;
-
-   uint32_t diffTick;
-
-   if (inited)
-   {
-      diffTick = tick - lastTick;
-      lastTick = tick;
-
-      if (level == 1) printf("%u %d\ ", -tick-firstTick, diffTick);
-   }
-   else
-   {
-      inited = 1;
-      firstTick = tick;
-      lastTick = firstTick;
-   }
-}
-

BUILD

-cc -o LDR LDR.c -lpigpio -lrt -lpthread
-

RUN

-sudo ./LDR >LDR.dat &
-
-While the program is running you can capture the waveform using the -notification feature built in to pigpio.  Issue the following -commands on the Pi.
-
-pigs no
-pig2vcd  </dev/pigpio0 >LDR.vcd &
-pigs nb 0 0x40000 # set bit for gpio 18
-

Change the light falling on the LDR for a few seconds (e.g. -shine a torch on it or shade it with your hands).

-pigs nc 0
-

The file LDR.vcd will contain the captured waveform, which can -be viewed using GTKWave.

-

Overview

-LDR waveform 1
-

Reading circa every 10ms

-LDR waveform 2
-

One reading, circa 400us

-LDR waveform 3
-

The file LDR.dat will contain pairs of timestamps and recharge -time (in us).  The following  script will convert the -timestamps into seconds.

-

awk '{print $1/1000000, $2}' LDR.dat ->LDR-secs.dat

-

Gnuplot is a useful tool to graph data.

-plot [14:24] 'LDR-secs.dat' with lines title 'LDR' -

Gnuplot readings 14-24 seconds

-

gnuplot 1

-plot [18:21] 'LDR-secs.dat' with lines title 'LDR'
-
-Gnuplot readings 18-21 seconds -

Gnuplot 2

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_ir_remote.html b/DOC/HTML/ex_ir_remote.html deleted file mode 100644 index 5f548cb..0000000 --- a/DOC/HTML/ex_ir_remote.html +++ /dev/null @@ -1,308 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

IR Remote Example

-

The following code shows one way to read an infrared remote -control device (the sort used in TVs and stereo systems).

-

SETUP

-fritzing diagramThe device used -is a SFH5110 (IR Receiver for remote control, -carrier 38 kHz).
-
Pin 1 (left from front) may be connected to any spare -gpio.  Here it's connected via a 4K7 current limiting -resistor.  This isn't really needed as the device has an -internal 23K resistor in-line.  It does no harm though.
-
-Pin 2 should be connected to a Pi ground pin.
-
-Pin 3 should be connected to a Pi 5V pin.
-

Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground -(P1-14), and pin 3 to 5V (P1-2).

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-#define IR_PIN 7
-
-#define OUTSIDE_CODE 0
-#define INSIDE_CODE  1
-
-#define MIN_MESSAGE_GAP 3000
-#define MAX_MESSAGE_END 3000
-
-#define MAX_TRANSITIONS 500
-
-/*
-   using the FNV-1a -hash                
- -   from -http://isthe.com/chongo/tech/comp/fnv/#FNV-param
-*/
-
-#define FNV_PRIME_32 16777619
-#define FNV_BASIS_32 2166136261U
-
-static volatile uint32_t ir_hash = 0;
-
-typedef struct
-{
-   int state;
-   int count;
-   int level;
-   uint16_t micros[MAX_TRANSITIONS];
-} decode_t;
-
-/* forward declarations */
-
-void     alert(int gpio, int level, uint32_t -tick);
-uint32_t getHash(decode_t * decode);
-void     updateState(decode_t * decode, int -level, uint32_t micros);
-
-int main(int argc, char * argv[])
-{
-   if (gpioInitialise()<0)
-   {
-      return 1 ;
-   }
-
-   /* IR pin as input */
-
-   gpioSetMode(IR_PIN, PI_INPUT);
-
-   /* 5ms max gap after last pulse */
-
-   gpioSetWatchdog(IR_PIN, 5);
-
-   /* monitor IR level changes */
-
-   gpioSetAlertFunc(IR_PIN, alert);
-
-   while (1)
-   {
-      if (ir_hash)
-      {
-         /* non-zero means -new decode */
-         printf("ir code is -%u\ ", ir_hash);
-         ir_hash = 0;
-      }
-
-      gpioDelay(100000); /* check remote -10 times per second */
-   }
-
-   gpioTerminate();
-}
-
-void alert(int gpio, int level, uint32_t tick)
-{
-   static int inited = 0;
-
-   static decode_t activeHigh, activeLow;
-
-   static uint32_t lastTick;
-
-   uint32_t diffTick;
-
-   if (!inited)
-   {
-      inited = 1;
-
-      activeHigh.state = OUTSIDE_CODE; -activeHigh.level = PI_LOW;
-      activeLow.state  = -OUTSIDE_CODE; activeLow.level  = PI_HIGH;
-
-      lastTick = tick;
-      return;
-   }
-
-   diffTick = tick - lastTick;
-
-   if (level != PI_TIMEOUT) lastTick = tick;
-
-   updateState(&activeHigh, level, diffTick);
-   updateState(&activeLow, level, diffTick);
-}
-
-void updateState(decode_t * decode, int level, uint32_t micros)
-{
-   /*
-      We are dealing with active high as -well as active low
-      remotes.  Abstract the common -functionality.
-   */
-
-   if (decode->state == OUTSIDE_CODE)
-   {
-      if (level == decode->level)
-      {
-         if (micros > -MIN_MESSAGE_GAP)
-         {
-            -decode->state = INSIDE_CODE;
-            -decode->count = 0;
-         }
-      }
-   }
-   else
-   {
-      if (micros > MAX_MESSAGE_END)
-      {
-         /* end of message -*/
-
-         /* ignore if last -code not consumed */
-
-         if (!ir_hash) -ir_hash = getHash(decode);
-
-         decode->state = -OUTSIDE_CODE;
-      }
-      else
-      {
-         if -(decode->count < (MAX_TRANSITIONS-1))
-         {
-            -if (level != PI_TIMEOUT)
-               -decode->micros[decode->count++] = micros;
-         }
-      }
-   }
-}
-
-int compare(unsigned int oldval, unsigned int newval)
-{
-   if      (newval < (oldval -* 0.75)) {return 1;}
-   else if (oldval < (newval * 0.75)) {return 2;}
-   -else                               -{return 4;}
-}
-
-uint32_t getHash(decode_t * decode)
-{
-   /* use FNV-1a */
-
-   uint32_t hash;
-   int i, value;
-
-   if (decode->count < 6) {return 0;}
-
-   hash = FNV_BASIS_32;
-
-   for (i=0; i<(decode->count-2); i++)
-   {
-      value = -compare(decode->micros[i], decode->micros[i+2]);
-
-      hash = hash ^ value;
-      hash = (hash * FNV_PRIME_32);
-   }
-
-   return hash;
-}
-

BUILD

-cc -o ir_remote ir_remote.c -lpigpio -lrt --lpthread
-

RUN

-sudo ./ir_remote
-

A hash code is formed from the level transitions detected during -a remote key press.  This is likely to be unique over multiple -remotes and keys.

-

While the program is running you can capture the waveform using -the notification feature built in to pigpio.  Issue the -following commands on the Pi.

-pigs no
-pig2vcd  </dev/pigpio0 >ir.vcd &
-pigs nb 0 0x80 # set bits for gpios 7 (0x80)
-

Press a few different remotes and keys.  Then enter

-pigs nc 0
-

The file ir.vcd will contain the captured waveform, which can be -viewed using GTKWave.

-

Overview

-ir remote waveform 1
-

Remote A typical waveform

-ir remote waveform 2
-

Remote B typical waveform

--"ir -
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_motor_shield.html b/DOC/HTML/ex_motor_shield.html deleted file mode 100644 index e5d28f0..0000000 --- a/DOC/HTML/ex_motor_shield.html +++ /dev/null @@ -1,309 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Arduino Motor Shield

-The following example demonstrates the use of an Arduino shield -from the Rasperry Pi.
-
-The shield used is a clone of the Adafruit motor shield.  See -shieldlist.org -for details.
-
-For the demonstration DC motors 3 and 4 are being driven forwards -and backwards with changing speeds (speeds are controlled via -PWM).
-
-Seven connections are made between the Pi and the shield.  -Four to latch the motor states (latch, enable, data, clock); Two to -control motor speed (PWM 3 and 4); and ground.
-
-The code used was ported from the Adafruit Arduino code and -converted to use the pigpio library.  Only the DC motor code -was ported.
-
-A video of the shield in use is available at youtube.com
-
-#include <stdio.h>

-
-#include <pigpio.h>
-
-/*
-   This code may be used to drive the Adafruit (or -clones) Motor Shield.
-
-   The code as written only supports DC motors.
-
-   http://shieldlist.org/adafruit/motor
-
-   The shield pinouts are
-
-   D12 MOTORLATCH
-   D11 PMW motor 1
-   D10 Servo 1
-   D9  Servo 2
-   D8  MOTORDATA
-
-   D7  MOTORENABLE
-   D6  PWM motor 4
-   D5  PWM motor 3
-   D4  MOTORCLK
-   D3  PWM motor 2
-
-   The motor states (forward, backward, brake, release) -are encoded using the
-   MOTOR_ latch pins.  This saves four gpios.
-*/
-
-typedef unsigned char uint8_t;
-
-#define BIT(bit) (1 << (bit))
-
-/* assign gpios to drive the shield pins */
-
-/*      -Shield      Pi */
-
-#define MOTORLATCH  14
-#define MOTORCLK    24
-#define MOTORENABLE 25
-#define MOTORDATA   15
-
-#define MOTOR_3_PWM  7
-#define MOTOR_4_PWM  8
-
-/*
-   The only other connection needed between the Pi and -the shield
-   is ground to ground. I used Pi P1-6 to shield gnd -(next to D13).
-*/
-
-/* assignment of motor states to latch */
-
-#define MOTOR1_A 2
-#define MOTOR1_B 3
-#define MOTOR2_A 1
-#define MOTOR2_B 4
-#define MOTOR4_A 0
-#define MOTOR4_B 6
-#define MOTOR3_A 5
-#define MOTOR3_B 7
-
-#define FORWARD  1
-#define BACKWARD 2
-#define BRAKE    3
-#define RELEASE  4
-
-static uint8_t latch_state;
-
-void latch_tx(void)
-{
-   unsigned char i;
-
-   gpioWrite(MOTORLATCH, PI_LOW);
-
-   gpioWrite(MOTORDATA, PI_LOW);
-
-   for (i=0; i<8; i++)
-   {
-      gpioDelay(10);  // 10 micros -delay
-
-      gpioWrite(MOTORCLK, PI_LOW);
-
-      if (latch_state & BIT(7-i)) -gpioWrite(MOTORDATA, PI_HIGH);
-      -else                        -gpioWrite(MOTORDATA, PI_LOW);
-
-      gpioDelay(10);  // 10 micros -delay
-
-      gpioWrite(MOTORCLK, PI_HIGH);
-   }
-
-   gpioWrite(MOTORLATCH, PI_HIGH);
-}
-
-void init(void)
-{
-   latch_state = 0;
-
-   latch_tx();
-
-   gpioWrite(MOTORENABLE, PI_LOW);
-}
-
-void DCMotorInit(uint8_t num)
-{
-   switch (num)
-   {
-      case 1: latch_state &= -~BIT(MOTOR1_A) & ~BIT(MOTOR1_B); break;
-      case 2: latch_state &= -~BIT(MOTOR2_A) & ~BIT(MOTOR2_B); break;
-      case 3: latch_state &= -~BIT(MOTOR3_A) & ~BIT(MOTOR3_B); break;
-      case 4: latch_state &= -~BIT(MOTOR4_A) & ~BIT(MOTOR4_B); break;
-      default: return;
-   }
-
-   latch_tx();
-
-   printf("Latch=%08X\ ", latch_state);
-}
-
-void DCMotorRun(uint8_t motornum, uint8_t cmd)
-{
-   uint8_t a, b;
-
-   switch (motornum)
-   {
-      case 1: a = MOTOR1_A; b = MOTOR1_B; -break;
-      case 2: a = MOTOR2_A; b = MOTOR2_B; -break;
-      case 3: a = MOTOR3_A; b = MOTOR3_B; -break;
-      case 4: a = MOTOR4_A; b = MOTOR4_B; -break;
-      default: return;
-   }

-   switch (cmd)
-   {
-      case FORWARD:  latch_state -|=  BIT(a); latch_state &= ~BIT(b); break;
-      case BACKWARD: latch_state &= -~BIT(a); latch_state |=  BIT(b); break;
-      case RELEASE:  latch_state -&= ~BIT(a); latch_state &= ~BIT(b); break;
-      default: return;
-   }
-
-   latch_tx();
-
-   printf("Latch=%08X\ ", latch_state);
-}
-
-int main (int argc, char *argv[])
-{
-   int i;
-
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(MOTORLATCH,  PI_OUTPUT);
-   gpioSetMode(MOTORENABLE, PI_OUTPUT);
-   gpioSetMode(MOTORDATA,   PI_OUTPUT);
-   gpioSetMode(MOTORCLK,    -PI_OUTPUT);
-
-   gpioSetMode(MOTOR_3_PWM, PI_OUTPUT);
-   gpioSetMode(MOTOR_4_PWM, PI_OUTPUT);
-
-   gpioPWM(MOTOR_3_PWM, 0);
-   gpioPWM(MOTOR_4_PWM, 0);
-
-   init();
-
-   for (i=60; i<160; i+=20)
-   {
-      gpioPWM(MOTOR_3_PWM, i);
-      gpioPWM(MOTOR_4_PWM, 220-i);
-
-      DCMotorRun(3, FORWARD);
-      DCMotorRun(4, BACKWARD);
-
-      sleep(2);
-
-      DCMotorRun(3, RELEASE);
-      DCMotorRun(4, RELEASE);
-
-      sleep(2);
-
-      gpioPWM(MOTOR_4_PWM, i);
-      gpioPWM(MOTOR_3_PWM, 220-i);
-
-      DCMotorRun(3, BACKWARD);
-      DCMotorRun(4, FORWARD);
-
-      sleep(2);
-
-      DCMotorRun(3, RELEASE);
-      DCMotorRun(4, RELEASE);
-
-      sleep(2);
-   }
-
-   gpioPWM(MOTOR_4_PWM, 0);
-   gpioPWM(MOTOR_3_PWM, 0);
-
-   DCMotorRun(3, RELEASE);
-   DCMotorRun(4, RELEASE);
-
-   gpioTerminate();
-}
-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_rotary_encoder.html b/DOC/HTML/ex_rotary_encoder.html deleted file mode 100644 index b15b354..0000000 --- a/DOC/HTML/ex_rotary_encoder.html +++ /dev/null @@ -1,240 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Rotary Encoder Example

-

The following code shows one way to read an incremental -mechanical rotary enoder (the sort used for volume control in audio -systems).  These rotary encoders have two switches A and B -which return a quadrature output, i.e. they are 90 degrees out of -phase.

-

SETUP

-fritzing diagramThe common -(centre) terminal should be connected to a Pi ground. -

The A and B terminals may be connected to any spare gpios.

-

Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7 -(P1-26).

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/*
-   Rotary encoder connections:
-
-   Encoder A      - gpio -18   (pin P1-12)
-   Encoder B      - gpio -7    (pin P1-26)
-   Encoder Common - Pi ground (pin P1-20)
-*/
-
-#define ENCODER_A 18
-#define ENCODER_B  7
-
-static volatile int encoderPos;
-
-/* forward declaration */
-
-void encoderPulse(int gpio, int lev, uint32_t tick);
-
-int main(int argc, char * argv[])
-{
-   int pos=0;
-
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(ENCODER_A, PI_INPUT);
-   gpioSetMode(ENCODER_B, PI_INPUT);
-
-   /* pull up is needed as encoder common is grounded -*/
-
-   gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);
-   gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);
-
-   encoderPos = pos;
-
-   /* monitor encoder level changes */
-
-   gpioSetAlertFunc(ENCODER_A, encoderPulse);
-   gpioSetAlertFunc(ENCODER_B, encoderPulse);
-
-   while (1)
-   {
-      if (pos != encoderPos)
-      {
-         pos = -encoderPos;
-         printf("pos=%d\ ", -pos);
-      }
-      gpioDelay(20000); /* check pos 50 -times per second */
-   }
-
-   gpioTerminate();
-}
-
-void encoderPulse(int gpio, int level, uint32_t tick)
-{
-   /*
-
-             -+---------+         -+---------+      0
-             -|         -|         -|         |
-   A         -|         -|         -|         |
-             -|         -|         -|         |
-   -+---------+         -+---------+         +----- -1
-
-       -+---------+         -+---------+            -0
-       -|         -|         -|         |
-   B   -|         -|         -|         |
-       -|         -|         -|         |
-   ----+         -+---------+         -+---------+  1
-
-   */
-
-   static int levA=0, levB=0, lastGpio = -1;
-
-   if (gpio == ENCODER_A) levA = level; else levB = -level;
-
-   if (gpio != lastGpio) /* debounce */
-   {
-      lastGpio = gpio;
-
-      if ((gpio == ENCODER_A) && -(level == 0))
-      {
-         if (!levB) -++encoderPos;
-      }
-      else if ((gpio == ENCODER_B) -&& (level == 1))
-      {
-         if (levA) ---encoderPos;
-      }
-   }
-}
-

BUILD

-cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt --lpthread
-

RUN

-sudo ./rotary_encoder
-

While the program is running you can capture the waveform using -the notification feature built in to pigpio.  Issue the -following commands on the Pi.

-pigs no
-pig2vcd  </dev/pigpio0 >re.vcd &
-pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18 -(0x40000)
-

Twiddle the rotary encoder forwards and backwards for a few -seconds.  Then enter

-pigs nc 0
-

The file re.vcd will contain the captured waveform, which can be -viewed using GTKWave.

-
-Overview
-
--"rotary
-
-Detail of switch bounce.  Contact A bounces for circa 700 us -before completing the level transition
-
--"rotary
-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_sonar_ranger.html b/DOC/HTML/ex_sonar_ranger.html deleted file mode 100644 index 1db8410..0000000 --- a/DOC/HTML/ex_sonar_ranger.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Sonar Ranger Example

-

The following code shows a method of reading a class of sonar -rangers.  These rangers requires a trigger pulse.  -Shortly after receiving a trigger they transmit a noise pulse and -set the echo line high.  When the echo is received the echo -line is set low.

-

SETUP

-fritzing diagram
-
-
-
-
-The ranger used is a SRF05 (check the pinouts, there are many -variants).
-
-The fritzing diagram shows the back of the ranger, i.e. pin 1 is -the rightmost.
-
-Pin 1 is 5V.
-Pin 2 is the trigger line.
-Pin 3 is the echo line.
-Pin 4 is out (unused).
-Pin 5 is ground.
-
-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/*
-
-P1  Name  gpio    used for
-
- 2  5V    ---     -5V
- 6  GND   ---     -Ground
-24  CE0   8       -Sonar echo
-26  CE1   7       -Sonar trigger
-
-*/
-
-#define SONAR_TRIGGER 7
-#define SONAR_ECHO    8
-
-/* forward prototypes */
-
-void sonarTrigger(void);
-
-void sonarEcho(int gpio, int level, uint32_t tick);
-
-int main(int argc, char *argv[])
-{
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);
-   gpioWrite  (SONAR_TRIGGER, PI_OFF);
-
-   gpioSetMode(SONAR_ECHO,    -PI_INPUT);
-
-   /* update sonar 20 times a second, timer #0 */
-
-   gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms -*/
-
-   /* monitor sonar echos */
-
-   gpioSetAlertFunc(SONAR_ECHO, sonarEcho);
-
-   while (1) sleep(1);
-
-   gpioTerminate();
-
-   return 0;
-}
-
-void sonarTrigger(void)
-{
-   /* trigger a sonar reading */
-
-   gpioWrite(SONAR_TRIGGER, PI_ON);
-
-   gpioDelay(10); /* 10us trigger pulse */
-
-   gpioWrite(SONAR_TRIGGER, PI_OFF);
-}
-
-void sonarEcho(int gpio, int level, uint32_t tick)
-{
-   static uint32_t startTick, firstTick=0;
-
-   int diffTick;
-
-   if (!firstTick) firstTick = tick;
-
-   if (level == PI_ON)
-   {
-      startTick = tick;
-   }
-   else if (level == PI_OFF)
-   {
-      diffTick = tick - startTick;
-
-      printf("%u %u\ ", tick-firstTick, -diffTick);
-   }
-}
-

BUILD

-cc -o sonar sonar.c -lpigpio -lrt -lpthread
-

RUN

-sudo ./sonar >sonar.dat &
-
-While the program is running you can capture the waveform using the -notification feature built in to pigpio.  Issue the following -commands on the Pi.
-
-pigs no
-pig2vcd  </dev/pigpio0 >sonar.vcd &
-pigs nb 0 0x180 # set bits for gpios 7 and 8
-

Move an object in front of the sonar ranger for a few -seconds.

-pigs nc 0
-

The file sonar.vcd will contain the captured waveform, which can -be viewed using GTKWave.

-

Overview

-LDR waveform 1
-

Reading circa every 10ms

-Sonar waveform 2
-

One reading, circa 400us

-Sonar waveform 3
-

another

-Sonar waveform 4
-

The file sonar.dat will contain pairs of timestamps and echo -length (in us).  The following  script will convert the -timestamps into seconds.

-

awk '{print $1/1000000, $2}' sonar.dat ->sonar-secs.dat

-

Gnuplot is a useful tool to graph data.

-plot 'sonar-secs.dat' title 'Sonar'
-

gnuplot 1
- plot [10:25] 'sonar-secs.dat' title 'Sonar'

-

gnuplot 1

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/examples.html b/DOC/HTML/examples.html deleted file mode 100644 index 3d82fca..0000000 --- a/DOC/HTML/examples.html +++ /dev/null @@ -1,558 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Examples

The following examples show various ways pigpio may be used to communicate with sensors via the GPIO.
-
-Although many are complete programs they are intended to be a starting point in producing your own code, not an end point.
-
-Index

-Hardware

-Shell code

-C code

-C++ code

-pigpiod_if2 code

-Python code

-Miscellaneous related code

-External links

-

Hardware

-A few practical examples of using pigpio with hardware.
-
-
IR Receiver
2013-06-09
Reading an infrared remote receiver.
-
-
Light Dependent Resistor
2013-06-09
Measuring brightness with a light dependent resistor (LDR). Improved methods of timing the start of the capacitor recharge are given for C and Python.
-
-
Motor Shield
2013-12-15
Using an Arduino motor shield.
-
-
Rotary Encoder
2013-06-09
Reading a rotary encoder.
-
-
Sonar Ranger
2013-06-10
Measuring range with a sonar ranger.
-
-

Shell code

-Examples of using pigpio with shell code.
-
-
GPIO test
2014-08-11
This bash script tests the user GPIO. Video
-
-

C code

-Examples of C pigpio programs.
-
-If your program is called foobar.c then build with
-
-gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
-
-
Frequency Counter 1
2014-08-20
A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs).
-
-
Frequency Counter 2
2014-08-20
A program showing how to use the gpioSetGetSamplesFunc function to set a callback for accumulated GPIO state changes over the last millisecond. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). Generally the method used is more complicated but more efficient than frequency counter 1.
-
-
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
-
-
I2C Sniffer
2014-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results. This C program uses pigpio notifications.
-
-
IR Receiver
2015-02-25
Function to hash a code from an IR receiver (reading an IR remote control).
-
-
PCF8591 YL-40
2014-08-26
A program to display readings from the (I2C) PCF8591.
-
-
Pot + Capacitor Recharge Timing
2014-03-14
Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
-
-
Rotary Encoder
2015-10-03
Function to decode a mechanical rotary encoder.
-
-
SPI bit bang MCP3008
2016-03-20
This program shows how to read multiple MCP3008 ADC simultaneously with accurately timed intervals. One 10-bit channel of each ADC may be sampled at up to 25k samples per second.
-
-
SPI bit bang MCP3202
2016-03-20
This program shows how to read multiple MCP3202 ADC simultaneously with accurately timed intervals. One 12-bit channel of each ADC may be sampled at up to 25k samples per second.
-
-
SPI bit bang MCP3008 and MCP3202
2016-03-20
This program shows how to read multiple MCP3008 and MCP3202 ADC simultaneously with accurately timed intervals. One channel of each ADC may be sampled at up to 25k samples per second. The 10-bit MCP3008 readings are multiplied by 4 so they have the same range (0-4095) as the 12-bit MCP3202.
-
-
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-sudo ./servo_demo # Generate pulses on GPIO 4.
-
-sudo ./servo_demo 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
SPI pigpio driver speed test
2016-11-06
This C code is used to benchmark the pigpio SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
-
-
Wiegand Reader
2013-12-30
Function to read a Wiegand Reader.
-
-

C++ code

-Examples of C++ pigpio programs.
-
-If your program is called foobar.cpp then build with
-
-g++ -Wall -pthread -o foobar foobar.cpp -lpigpio -lrt
-
-
IR Receiver
2015-02-22
Class to hash a code from an IR receiver (reading an IR remote control).
-
-
Rotary Encoder
2013-12-30
Class to decode a mechanical rotary encoder.
-
-
Wiegand Reader
2013-12-30
Class to read a Wiegand Reader.
-
-

pigpiod_if2 code

The pigpiod_if2 code examples are linked with libpigpiod_if2 and are written in C.
-
-The pigpiod_if2 library may be compiled and run on any Linux machine and allows control of the GPIO on one or more networked Pis.
-
-It should be possible to adapt the library to run on Macs and PCs.
-
-Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
-
-
433MHz Keyfob RX/TX
2015-11-17
Code to read and transmit 313 and 434 MHz key fob codes. The codes to be read must use Manchester encoding. The transmitted codes use Manchester encoding.
-
-./_433D -r10 # Print fob keycodes received on GPIO 10.
-
-./_433D -t5 8246184 # Transmit code on GPIO 5.
-
-./_433D -r10 -t5 8246184 # Transmit code on GPIO 5 then listen for codes
-
-./_433D -? for options.
-
-
DHT11/21/22/33/44 Sensor
2016-02-16
Code to read the DHT temperature and humidity sensors. The sensor may be auto detected. A DHT11 sensor may be read once per second. The other sensors should not be read more often than once every three seconds.
-
-The code auto detects the DHT model and generally only the GPIO needs to be specified.
-
-./DHTXXD -g17 # Read a DHT connected to GPIO 17.
-
-./DHTXXD -g5 -i3 # Read a DHT connected to GPIO 5 every three seconds.
-
-./DHTXXD -? # for options.
-
-
Rotary Encoder
2015-11-18
Code to monitor a rotary encoder and show the position changes. By default the detent changes are shown. There is an option to show the four steps per detent instead.
-
-./RED -a7 -b8 -s30 # Show encoder on 7/8 detent changes for 30 seconds.
-
-./RED -a5 -b6 -m1 # Show encoder on 5/6 step changes forever.
-
-./RED -? # for options.
-
-
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-./servo_demo_D # Generate pulses on GPIO 4.
-
-./servo_demo_D 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
Sonar Ranger
2015-11-16
Code to read the SRF-04 and SRF-05 type of sonar rangers which use the trigger echo method of operation. A 10 μs trigger pulse initiates a series of high frequency sonar chirps. The echo line then goes high and stays high until an echo from an object is received. The echo high time is used to calculate the distance of the object.
-
-For a one-off reading only the trigger and echo GPIO need to be specified.
-
-./SRTED -t5 -e6 # Read a sonar ranger connected to GPIO 5/6.
-
-./SRTED -t11 -e5 -i0.1 # Read a sonar ranger connected to GPIO 11/5 every 0.1 seconds.
-
-./SRTED -? # for options.
-
-
Transmit Rotary Encoder Test Signals
2015-11-25
Code to transmit quadrature signals to test rotary encoder software.
-
-tx_RED -aGPIO -bGPIO [options]
-
-tx_RED -? for options
-
-E.g.
-
-tx_RED -a5 -b6 -s20 -r-100
-
-
Transmit Wiegand Test Signals
2015-11-25
Code to transmit Wiegand codes to test Wiegand decoder software.
-
-tx_WD -gGPIO -wGPIO [options] {code}+
-
-tx_WD -? for options
-
-E.g.
-
-tx_WD -g5 -w6 -s37 12345 67890 123 899999
-
-
Wiegand Reader
2015-11-25
Code to read a Wiegand Reader.
-
-./WD -g7 -w8 -s30 # Read Wiegand codes from GPIO 7/8 for 30 seconds.
-
-./WD -g5 -w6 # Read Wiegand codes from GPIO 5/6 forever.
-
-./WD -? # for options.
-
-

Python code

The Python code may be run on any Python machine and allows control of the GPIO on one or more networked Pis.
-
-The Python machine need not be a Pi, it may run Windows, Mac, Linux, anything as long as it supports Python.
-
-Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
-
-
433MHz Keyfob RX/TX
2015-10-30
Classes to send and receive 433MHz wireless keyfob codes. These keyfobs are widely used for remote control of devices.
-
-
7-Segment LED Display Multiplexing
2016-12-12
Script to multiplex several 7-segment LED displays. Each display has the segments a-g and the decimal point connected in parallel but has an individual enable GPIO (connected to the common anode or cathode).
-
-
APA102 LED strip driver
2017-03-28
Script to drive an APA102 LED strip. Three different methods are demonstrated - using spidev SPI (only works on the local Pi), pigpio SPI, and pigpio waves. The SPI solutions only work with the dedicated SPI GPIO. Waves may use any spare GPIO. Four different examples are given including a LED strip clock.
-
-
BME280 Sensor
2016-08-05
Class to read the relative humidity, temperature, and pressure from a BME280 sensor. The sensor has both an I2C and a SPI interface which are both
-supported by the class.
-
-
DHT11/21/22/33/44 Sensor
2019-11-07
Class to read the relative humidity and temperature from a DHT sensor. It can automatically recognize the sensor type.
-
-The default script prints the reading from the specified DHT every 2 seconds. E.g. ./DHT.py 22 27 displays the data for DHT connected to GPIO 22 and 27.
-
-The following data is printed for each DHT: timestamp, GPIO, status, temperature, and humidity.
-
-The timestamp is the number of seconds since the epoch (start of 1970).
-
-The status will be one of: 0 - a good reading, 1 - checksum failure, 2 - data had one or more invalid values, 3 - no response from sensor.
-
-
DHT22 AM2302 Sensor
2014-07-11
Class to read the relative humidity and temperature from a DHT22/AM2302 sensor.
-
-
DS18B20 Temperature Sensor
2016-06-29
Script to read the temperature from any DS18B20 sensors connected to the 1-wire bus.
-
-To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
-
-dtoverlay=w1-gpio
-
-By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
-
-Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
-
-This script uses the file features of pigpio to access the remote file system.
-
-The following entry must be in /opt/pigpio/access.
-
-/sys/bus/w1/devices/28*/w1_slave r
-
-
Dust Sensor
2015-11-22
Class to read a Shinyei PPD42NS Dust Sensor, e.g. as used in the Grove dust sensor.
-
-
GPIO Status
2014-06-12
Script to display the status of GPIO 0-31.
-
-
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
-
-
HX711 24-bit ADC
2018-03-05
Class to read the channels of a HX711 24-bit ADC.
-
-
I2C ADXL345 Accelerometer
2015-04-01
Script to display the X, Y, and Z values read from an ADXL345 accelerometer.
-
-
I2C HMC5883L Magnetometer
2015-04-01
Script to display the X, Y, and Z values read from a HMC5883L Magnetometer (compass).
-
-
I2C ITG3205 Gyroscope
2015-04-01
Script to display the X, Y, Z, and temperature values read from an ITG3205 gyroscope.
-
-
I2C LCD Display
2016-04-20
Class to display text on a LCD character display. The class supports the PCF8574T 8-bit I2C port expander connected to a HD44780 based LCD display. These displays are commonly available in 16x2 and 20x4 character formats.
-
-
I2C slave device
2016-10-31
This script demonstrates how to transfer messages from an Arduino acting as the I2C bus master to the Pi acting as an I2C slave device.
-
-
I2C Sniffer
2015-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results.
-
-
I2C Sonar
2016-03-24
A class to read up to 8 HC-SR04 sonar rangers connected to an MCP23017 port expander.
-
-
IR Receiver
2014-06-12
Class to hash a code from an IR receiver (reading an IR remote control).
-
-
IR Record and Playback
2015-12-21
This script may be used to record and play back arbitrary IR codes.
-
-To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given.
-
-E.g. ./irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0
-
-To playback the GPIO connected to the IR transmitter, the file containing the recorded codes, and the codes to be played back are given.
-
-E.g. ./irrp.py -p -g18 -fir-codes 2 3 4
-
-./irrp.py -h # for options
-
-
Kivy GPIO control
2016-12-11
This example shows how to use Kivy to control a Pi's GPIO. The GPIO may be configured as inputs, outputs, or to generate Servo or PWM pulses. Kivy is an Open source Python library for rapid development of applications.
-
-
MAX6675 SPI Temperature Sensor
2016-05-02
A script to read the temperature from a MAX6675 connected to a K-type thermocouple. The MAX6675 supports readings in the range 0 - 1023.75 C. Up to 4 readings may be made per second.
-
-
Monitor GPIO
2016-09-17
Script to monitor GPIO for level changes. By default all GPIO are monitored. At a level change the GPIO, new level, and microseconds since the last change is printed.
-
-
Morse Code
2015-06-17
Script to transmit the morse code corresponding to a text string.
-
-
NRF24 radio transceiver
2018-01-06
Script to transmit and receive messages using the nRF24L01 radio transceiver.
-
-
PCA9685 16 Channel PWM
2016-01-31
Class to control the 16 PWM channels of the I2C PCA9685. All channels use the same frequency. The duty cycle or pulse width may be set independently for each channel.
-
-
PCF8591 YL-40
2014-08-26
Script to display readings from the (I2C) PCF8591.
-
-
PPM (Pulse Position Modulation) generation
2016-02-19
Script to generate PPM signals on a chosen GPIO.
-
-
PPM (Pulse Position Modulation) to servo pulses
2019-10-09
Script to read a PPM signal on a GPIO and generate the corresponding servo signals on chosen GPIO.
-
-
pigpio Benchmark
2014-06-12
Script to benchmark the pigpio Python module's performance.
-
-
pigpio CGI
2015-05-04
Script demonstrating how to access the pigpio daemon using CGI from a browser. Instructions on how to use with Apache2 on the Pi are given in the comments.
-
-
Playback piscope recordings
2016-12-23
Script to playback GPIO data recorded in piscope format.
-
-To playback GPIO 4 to GPIO 4 from file data.piscope
-./playback.py data.piscope 4
-
-To playback GPIO 4 to GPIO 7 from file rec.txt
-./playback.py rec.txt 7=4
-
-
Pot + Capacitor Recharge Timing
2016-09-26
Class to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
-
-
PWM Monitor
2015-12-08
Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle.
-
-
Rotary Encoder
2014-06-12
Class to decode a mechanical rotary encoder.
-
-
RPM Monitor
2016-01-20
Class to monitor speedometer pulses and calculate the RPM (Revolutions Per Minute).
-
-
Si7021 I2C Temperature and Humidity Sensor
2016-05-07
Class to read the temperature and relative humidity from a Si7021.
-
-
SPI Monitor
2016-09-21
A program to passively sniff SPI transactions and display the results. The SPI rate should be limited to about 70kbps if using the default pigpio 5µs sampling rate.
-
-
Servo Pulse Generator
2016-10-07
This script generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-./servo_demo.py # Generate pulses on GPIO 4.
-
-./servo_demo.py 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
Sonar Ranger
2014-06-12
Class to read sonar rangers with separate trigger and echo pins.
-
-
TCS3200 Colour Sensor
2015-07-03
Class to read the TCS3200 colour sensor
-
-
Virtual Wire
2015-10-31
Class to send and receive radio messages compatible with the Virtual Wire library for Arduinos. This library is commonly used with 313MHz and 434MHz radio tranceivers.
-
-
Wave create
2019-11-18
Script to generate waves from a template defined in a text file.
-
-You can also specify one of py, c, or pdif - the script output will then be a complete program to generate the wave (py for Python script, c for a C program, pdif for a C program using the pigpio daemon I/F).
-
-If none of py, c, or pdif are chosen the waveform will be generated for 30 seconds.
-
-Example text file
-
-# GPIO levels
-23 11000001
-11 01110000
-12 00011100
-4 00000111
-
-To generate a pdif program with a bit time of 100 microseconds
-./create_wave.py wave_file 100 pdif >wave_pdif.c
-
-To just transmit the wave with a bit time of 50 microseconds
-./create_wave.py wave_file 50
-
-
Wave PWM 1
2016-03-19
Script to show how waves may be used to generate PWM at (one) arbitrary frequency on multiple GPIO. For instance PWM at 10kHz may be generated with 100 steps between off and fully on.
-
-
Wave PWM 2
2016-10-06
Class to generate PWM on multiple GPIO. It is more flexible than the Wave PWM 1 example in that the start of the pulse within each cycle may be specified as well as the duty cycle. The start and length of each pulse may be specified on a GPIO by GPIO basis in microseconds or as a fraction of the cycle time. The class includes a __main__ to demostrate its ability to send servo pulses.
-
-
Wiegand Reader
2014-06-12
Class to read a Wiegand reader.
-
-

Miscellaneous related code

-The following code examples do not use pigpio.
-
-
ADXL345
2014-03-12
This C program reads x, y, and z accelerations from the ADXL345 via I2C address 0x53.
-
-
DS18B20 Temperature Sensor
2016-04-25
This Python script reads the temperature from any DS18B20 sensors connected to the 1-wire bus.
-
-To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
-
-dtoverlay=w1-gpio
-
-By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
-
-Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
-
-
Easy as Pi Server
2014-09-15
This Python class implements a simple server which allows broswer commands to be executed on the Pi.
-
-
Minimal Clock Access
2015-05-20
This C code sets GPIO 4 to a specified clock frequency. The frequency can be set between 4.6875 kHz and 500 MHz (untested). The clock can be preferentially set from one of the sources OSC (19.2MHz), HDMI (216MHz), PLLD (500MHz), or PLLC (1000MHz). MASH can be set between 0 and 3. MASH may not work properly for clock dividers less than 5.
-
-
Minimal GPIO Access
2019-07-03
This C code has a minimal set of functions needed to control the GPIO and other Broadcom peripherals. The program requires root privileges to run. See Tiny GPIO access for an alternative which controls the GPIO (but not the other peripherals) and does not require root access.
-
-The code has been updated for the BCM2711 (Pi4B).
-
-The following functions are provided.
-
-gpioInitialise
-gpioSetMode
-gpioGetMode
-gpioSetPullUpDown
-gpioRead
-gpioWrite
-gpioTrigger
-gpioReadBank1
-gpioReadBank2
-gpioClearBank1
-gpioClearBank2
-gpioSetBank1
-gpioSetBank2
-gpioHardwareRevision
-gpioTick
-
-
Nanosecond Pulse Generation
2014-01-29
This C program uses the PWM peripheral to generate precisely timed pulses of very short duration. Pulses as short as 4 nano seconds can be generated.
-
-
PCF8591 YL-40
2014-08-26
C and Python code to read the (I2C) PCF8591.
-
-
SPI Linux driver speed test
2016-11-06
This C code is used to benchmark the Linux SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
-
-
Tiny GPIO Access
2016-04-30
This C code has a minimal set of functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO).
-
-You may need to change the permissions and ownership of /dev/gpiomem if they have not been correctly set up.
-
-sudo chown root:gpio /dev/gpiomem
-sudo chmod g+rw /dev/gpiomem
-
-The user (default pi) needs to be in the gpio group.
-
-sudo adduser pi gpio
-
-The following functions are provided.
-
-gpioInitialise
-gpioSetMode
-gpioGetMode
-gpioSetPullUpDown
-gpioRead
-gpioWrite
-gpioTrigger
-gpioReadBank1
-gpioReadBank2
-gpioClearBank1
-gpioClearBank2
-gpioSetBank1
-gpioSetBank2
-gpioHardwareRevision
-
-

External links

-Related code.
-
-
Stepper Motor
2016-08-12
Stepper motor code.
-
-
Parallax ActivityBot 360
2018-11-03
Python 3 implementation for programming a Parallax ActivityBot 360 Robot Kit with a Raspberry Pi.
-
-

Index

- -
433MHz Keyfob RX/TX pdif2 - Python -
7-Segment LED Display Multiplexing Python -
ADXL345 Misc -
APA102 LED strip driver Python -
BME280 Sensor Python -
DHT11/21/22/33/44 Sensor pdif2 - Python -
DHT22 AM2302 Sensor Python -
DS18B20 Temperature Sensor Python - Misc -
Dust Sensor Python -
Easy as Pi Server Misc -
Frequency Counter 1 C -
Frequency Counter 2 C -
GPIO Status Python -
GPIO test Shell -
Hall Effect Sensor C - Python -
HX711 24-bit ADC Python -
I2C ADXL345 Accelerometer Python -
I2C HMC5883L Magnetometer Python -
I2C ITG3205 Gyroscope Python -
I2C LCD Display Python -
I2C slave device Python -
I2C Sniffer C - Python -
I2C Sonar Python -
IR Receiver Hardware - C - C++ - Python -
IR Record and Playback Python -
Kivy GPIO control Python -
Light Dependent Resistor Hardware -
MAX6675 SPI Temperature Sensor Python -
Minimal Clock Access Misc -
Minimal GPIO Access Misc -
Monitor GPIO Python -
Morse Code Python -
Motor Shield Hardware -
Nanosecond Pulse Generation Misc -
NRF24 radio transceiver Python -
Parallax ActivityBot 360 External -
PCA9685 16 Channel PWM Python -
PCF8591 YL-40 C - Python - Misc -
pigpio Benchmark Python -
pigpio CGI Python -
Playback piscope recordings Python -
Pot + Capacitor Recharge Timing C - Python -
PPM (Pulse Position Modulation) generation Python -
PPM (Pulse Position Modulation) to servo pulses Python -
PWM Monitor Python -
Rotary Encoder Hardware - C - C++ - pdif2 - Python -
RPM Monitor Python -
Servo Pulse Generator C - pdif2 - Python -
Si7021 I2C Temperature and Humidity Sensor Python -
Sonar Ranger Hardware - pdif2 - Python -
SPI bit bang MCP3008 C -
SPI bit bang MCP3008 and MCP3202 C -
SPI bit bang MCP3202 C -
SPI Linux driver speed test Misc -
SPI Monitor Python -
SPI pigpio driver speed test C -
Stepper Motor External -
TCS3200 Colour Sensor Python -
Tiny GPIO Access Misc -
Transmit Rotary Encoder Test Signals pdif2 -
Transmit Wiegand Test Signals pdif2 -
Virtual Wire Python -
Wave create Python -
Wave PWM 1 Python -
Wave PWM 2 Python -
Wiegand Reader C - C++ - pdif2 - Python -
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/faq.html b/DOC/HTML/faq.html deleted file mode 100644 index 4d06c5e..0000000 --- a/DOC/HTML/faq.html +++ /dev/null @@ -1,516 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Frequently Asked Questions

-Are my GPIO broken?
-
-Audio is broken
-
-Can´t initialise pigpio -library
-
-Can´t lock -var/run/pigpio.pid
-
-Hello World!
-
-Clock skew, make fails
-
-Have I fried my GPIO?
-
-How do I debounce -inputs?
-
-How fast is SPI?
-
-Library update didn't work
-
-make fails with clock skew
-
-Porting pigpio to another CPU/SoC
-
-Sound isn't working
-
-Symbol not found
-
-What is I2C?
-
-What is Serial?
-
-What is SPI?
-
-Which library should I use?
-
-

Are my -GPIO broken?

-

See Have I fried my -GPIO?

-

Audio is -broken

-

See Sound isn't -working

-

Can´t lock -/var/run/pigpio.pid

-

See Can´t_initialise_pigpio_library
-

-

Can´t initialise pigpio -library

-

This message means the pigpio daemon is already running.

-

The default daemon is called pigpiod and may be removed as -follows.

-Check that it is running with the command -

ps aux | grep pigpiod

-

Kill the daemon with

-

sudo killall pigpiod

-

If your own program is acting as the daemon it may be removed as -follows.

-

Find its process id (pid).

-

cat /var/run/pigpio.pid

-

Kill the program with

-

sudo kill -9 pid

-If the above doesn't work do the following and try starting the -daemon again -

sudo rm /var/run/pigpio.pid

-

To start the daemon do

-

sudo pigpiod

-

Have I fried my GPIO?

-

If you think you have damaged one or more GPIO you can carry out -a diagnostic test.

-

The test is a command line script called gpiotest

-For the duration of the test nothing must be connected to the GPIO -(no LEDs, wires, ribbon cables etc.). -

The test checks that each GPIO may be read and written and that -the internal resistor pull-ups and pull-downs are functional.

-

A video -showing what happens to the GPIO during a test.

-

A test with all GPIO okay.

-
This program checks the Pi's (user) gpios.
-
-The program reads and writes all the gpios.  Make sure NOTHING
-is connected to the gpios during this test.
-
-The program uses the pigpio daemon which must be running.
-
-To start the daemon use the command sudo pigpiod.
-
-Press the ENTER key to continue or ctrl-C to abort...
-
-Testing...
-Skipped non-user gpios: 0 1 28 29 30 31 
-Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 -Failed user gpios: None -
-

A test showing failed GPIO.

-
This program checks the Pi's (user) gpios.
-
-The program reads and writes all the gpios. Make sure NOTHING
-is connected to the gpios during this test.
-
-The program uses the pigpio daemon which must be running.
-
-To start the daemon use the command sudo pigpiod.
-
-Press the ENTER key to continue or ctrl-C to abort...
-
-Testing...
-Write 1 to gpio 17 failed.
-Pull up on gpio 17 failed.
-Write 1 to gpio 18 failed.
-Pull up on gpio 18 failed.
-Write 0 to gpio 23 failed.
-Pull down on gpio 23 failed.
-Write 0 to gpio 24 failed.
-Pull down on gpio 24 failed.
-Write 1 to gpio 27 failed.
-Pull up on gpio 27 failed.
-Skipped non-user gpios: 0 1 28 29 30 31
-Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 -Failed user gpios: 17 18 23 24 27 -
-

How do I debounce inputs?

-

Some devices like mechanical switches can generate multiple -interrupts as they bounce between on and off.  It is possible -to debounce the inputs in hardware by the correct use of resistors -and capacitors.

-

In software use the glitch filter which ignores all events -shorter than a set number of microseconds.  C gpioGlitchFilter, Python set_glitch_filter.

-

How fast is -SPI?

-The SPI throughput in samples per second depends on a number of -factors.
-
-
    -
  • The SPI bit rate (transfer rate in bits per second)
  • -
-
    -
  • The number of bytes transferred per sample (a 12 bit ADC sample -may require 3 bytes to transfer)
  • -
-
    -
  • The driver used
  • -
-

Two of those factors are fixed, the variable is the driver -used.

-

The pigpio driver is considerably faster than the Linux SPI -driver as is demonstrated by the following graphs.

-

Each graph shows the SPI bit rate in bits per second along the -horizontal axis.  The samples per second achieved is shown on -the vertical axis.  Each graph contains plots assuming 1 to 5 -bytes per transfer.

-

The source code used for the tests is spi-driver-speed.c and spi-pigpio-speed.c

-

spi-lnx-pibr1.png

-
-

spi-pig-pibr1.png

-
-

spi-lnx-pi3b.png

-
-

spi-pig-pi3b.png

-

Library update didn't work

-

pigpio places files in the following locations

-

/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
-/usr/local/lib (libpigpio.so, libpigpiod_if.so, -libpigpiod_if2.so)
-/usr/local/bin (pig2vcd, pigpiod, pigs)
-/usr/local/man (man pages)

-The raspberrypi.org image containing pigpio uses different -locations.
-

/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
-/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)
-/usr/bin (pig2vcd, pigpiod, pigs)
-/usr/man (man pages)

-

Mostly this doesn't matter as the /usr/local directories will -generally be earlier in the search path.  The pigpio built -includes, binaries, and manuals are normally found first.

-

However the wrong libraries may be linked during the -compilation.  If this is the case remove the /usr/lib entries -for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so

-

Hello World!

-

The following examples show how to use the various components of -the pigpio library.

-

Each example shows how to read the level of a GPIO.

-

C

-read_cif.c -
-#include <stdio.h>
-#include <pigpio.h>
-
-int main(int argc, char *argv[])
-{
-   int GPIO=4;
-   int level;
-
-   if (gpioInitialise() < 0) return 1;
-
-   level = gpioRead(GPIO);
-
-   printf("GPIO %d is %d\n", GPIO, level);
-
-   gpioTerminate();
-}
-    
-

Build

-gcc -pthread -o read_cif read_cif.c -lpigpio -

Run

-sudo ./read_cif -

C via pigpio daemon

-read_pdif.c -
-#include <stdio.h>
-#include <pigpiod_if2.h>
-
-int main(int argc, char *argv[])
-{
-   int pi;
-   int GPIO=4;
-   int level;
-
-   pi = pigpio_start(0, 0); /* Connect to local Pi. */
-
-   if (pi < 0)
-   {
-      printf("Can't connect to pigpio daemon\n");
-      return 1;
-   }
-
-   level = gpio_read(pi, GPIO);
-
-   printf("GPIO %d is %d\n", GPIO, level);
-
-   pigpio_stop(pi); /* Disconnect from local Pi. */
-   
-   return 0;
-}
-
-

Build

-gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2 -

Run

-./read_pdif -

Python

-read_gpio.py -
-#!/usr/bin/env python
-
-import pigpio
-
-GPIO=4
-
-pi = pigpio.pi()
-if not pi.connected:
-   exit()
-
-level = pi.read(GPIO)
-
-print("GPIO {} is {}".format(GPIO, level))
-
-pi.stop()
-    
-

Run

-python read_gpio.py -

pigs

-
-pigs r 4
-    
-

pipe I/F

-
-echo "r 4" >/dev/pigpio
-cat /dev/pigout
-    
-

make fails with clock -skew

-

If make fails with one of the following messages it is probably -because the Pi's clock is wrong.

-

make: Warning: File 'xxx' has modification time x s in the -future
-make: warning: Clock skew detected. Your build may be -incomplete.

-

make uses the current time to work out which files need to be -rebuilt (a file is rebuilt if it depends on other files which have -a later time-stamp).

-

The solution is to make sure the system clock is correct.  -If the Pi is networked this will not normally be a problem.

-

To set the date and time use the date command as in the -following example.

-

sudo date -d "2017-03-01 18:47:00"

-

Porting pigpio -to another CPU/SoC

-

Sound -isn't working

-

The Pi contains two pieces of hardware, a PWM peripheral and a -PCM peripheral, to generate sound.  The PWM peripheral is -normally used and generates medium quality audio out of the -headphone jack.  The PCM peripheral may be used by add-ons -such as HATs and generates high quality audio.

-

pigpio uses at least one of these peripherals during normal -operation (for timing DMA transfers).  pigpio will use both -peripherals if waves or the hardware PWM function is used.

-

By default pigpio uses the PCM peripheral leaving the PWM -peripheral free for medium quality audio.

-

You can change the default with a configuration option.  -For C use gpioCfgClock, for the -pigpio daemon use the -t option.

-

What is I2C?

-

I2C is a data link between the Pi (master) and one or more -slaves.

-

Data may be sent and received but the Pi initiates all -transfers.

-

I2C is a medium speed link.  On the Pi the default speed is -100 kbps, but 400 kbps also works.

-

I2C is implemented as a bus with two lines called

-
    -
  • SDA - for data
  • -
  • SCL - for a clock
  • -
-On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO -3 (pin 5) for SCL.
-
-Only one slave device may be communicated with at a time.  -Each message from the Pi includes the slave to be addressed and -whether a read or write is to be performed.
-
-When the Pi (master) wishes to talk to a slave it begins by issuing -a start sequence on the I2C bus. A start sequence is one of two -special sequences defined for the I2C bus, the other being the stop -sequence. The start sequence and stop sequence are special in that -these are the only places where the SDA (data line) is allowed to -change while the SCL (clock line) is high. When data is being -transferred, SDA must remain stable and not change whilst SCL is -high. The start and stop sequences mark the beginning and end of a -transaction with the slave device.
-
-I2C start and stop sequences
-
-Data is transferred in 8-bit bytes. The bytes are placed on the SDA -line starting with the most significant bit. The SCL line is then -pulsed high, then low. For every byte transferred, the device -receiving the data sends back an acknowledge bit, so there are -actually 9 SCL clock pulses to transfer each 8-bit byte of data. If -the receiving device sends back a low ACK bit, then it has received -the data and is ready to accept another byte. If it sends back a -high then it is indicating it cannot accept any further data and -the master should terminate the transfer by sending a stop -sequence.
-
-

I2C waveform

-

What is -Serial?

-

Serial is a data link between the Pi and one other -device.

-

Data may be sent and received.  Either the Pi or the device -can initiate a transfer.

-

Serial is a low to medium speed link.  On the Pi speeds of -50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, -19200, 38400, 57600, 115200, and 230400 bps may be used.

-

Serial is implemented with one line for transmit called TXD and -one line for receive called RXD.

-

If only receive or transmit are required the other line need not -be connected.

-

The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for -RXD.

-

Data is normally transmitted in 8-bit bytes with a start bit, -eight data bits, no parity, and one stop bit.  This is -represented as 8N1.  The number of transmitted bits per second -(bps) is called the baud rate.   The time for each bit, -1 / baud rate seconds, is -referred to as the bit period.

-

The lines are in the high state when no data is being -transmitted.  The start of a byte is signalled by the line -going low for one bit period (the start bit).  The data bits -are then sent least significant bit firsts (low if the bit is 0, -high if the bit is 1).  The data bits are followed by the -optional parity bit.  Finally the line is set high for at -least the number of stop bit periods.  The line will stay high -if there are no more bytes to be transmitted.

-

Serial waveform

-

What is SPI?

-

SPI is a data link between the Pi (master) and one or more -slaves.

-

Data may be sent and received but the Pi initiates all -transfers.

-

SPI is a medium to high speed link.  On the Pi speeds of 32 -kbps to 8 Mbps may be used.

-

SPI is implemented as a bus with three lines called

-
    -
  • MOSI - for data from the Pi to the slave
  • -
  • MISO - for data from the slave to the Pi
  • -
  • SCLK - for a clock
  • -
-Only one slave device may be communicated with at a time.  An -additional line per slave called slave select is used to identify -the slave to be addressed. -

The Pi has two SPI buses

-
    -
  1. the main SPI bus -
      -
    • MOSI GPIO 10 (pin 19)
    • -
    • MISO GPIO 9 (pin 21)
    • -
    • SCLK GPIO 11 (pin 23)
    • -
    • Slave selects
    • -
    • -
        -
      • CE0 GPIO 8 (pin 24)
      • -
      • CE1 GPIO 7 (pin 26)
      • -
      -
    • -
    -
  2. -
  3. the auxiliary SPI bus -
      -
    • MOSI GPIO 20 (pin 38)
    • -
    • MISO GPIO 19 (pin 35)
    • -
    • SCLK GPIO 21 (pin 40)
    • -
    • Slave selects
    • -
    • -
        -
      • CE0 GPIO 18 (pin 12)
      • -
      • CE1 GPIO 17 (pin 11)
      • -
      • CE2 GPIO 16 (pin 36)
      • -
      -
    • -
    -
  4. -
-

SPI waveform

-


-

Which library -should I use?

-


-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/index.html b/DOC/HTML/index.html deleted file mode 100644 index fdaeaa6..0000000 --- a/DOC/HTML/index.html +++ /dev/null @@ -1,716 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

The pigpio library

-pigpio is a library for the Raspberry which allows control of the -General Purpose Input Outputs (GPIO).  pigpio works on all -versions of the Pi. -

At the moment pigpio on the Pi4B is experimental. I am not -sure if the DMA channels being used are safe. The Pi4B defaults are -primary channel 7, secondary channel 6. If these channels do not -work you will have to experiment. You can set the channels used by -the pigpio daemon by invoking it with the -d and -e options, e.g. -sudo pigpiod -d 5 -e 8 to specify primary 5, -secondary 8.

-

Download

-

Features

-
    -
  • -

    hardware timed sampling and time-stamping of GPIO 0-31 every 5 -us

    -
  • -
  • -

    hardware timed PWM on all of GPIO 0-31

    -
  • -
  • -

    hardware timed servo pulses on all of GPIO 0-31

    -
  • -
  • -

    callbacks on GPIO 0-31 level change (time accurate to a few -us)

    -
  • -
  • -

    notifications via pipe on GPIO 0-31 level change

    -
  • -
  • -

    callbacks at timed intervals

    -
  • -
  • -

    reading/writing all of the GPIO in a bank (0-31, 32-53) as a -single operation

    -
  • -
  • -

    GPIO reading, writing, modes, and internal pulls

    -
  • -
  • -

    socket and pipe interfaces for the bulk of the functionality

    -
  • -
  • -

    waveforms to generate GPIO level changes (time accurate to a few -us)

    -
  • -
  • -

    software serial links using any user GPIO

    -
  • -
  • -

    rudimentary permission control through the socket and pipe -interfaces

    -
  • -
  • creating and running scripts on the pigpio daemon
  • -
-

General

-The pigpio library is written in the C -programming language.
-
-The pigpio daemon offers a socket and pipe interface to -the underlying C library.
-
-A C library and a Python module allow control of the GPIO via the -pigpio daemon.
-
-There is third party support for a number of other languages.  -

piscope

-

piscope is a logic analyser (digital -waveform viewer).

-piscope is a GTK+3 application and uses pigpio to provide raw GPIO -level data.  piscope may be run on a Pi or on any machine -capable of compiling a GTK+3 application. -

GPIO

-

ALL GPIO are identified -by their Broadcom -number.  See -elinux.org

-There are 54 GPIO in total, arranged in two banks.
-

Bank 1 contains GPIO 0-31.  Bank 2 contains GPIO -32-53.

-For all types of Pi it is safe to read all the GPIO. If you try to -write a system GPIO or change its mode you can crash the Pi or -corrupt the data on the SD card.
-
-There are several types of board, each with different expansion -headers, giving physical access to different GPIO.  - -

Type 1 - Model B (original -model)

-
    -
  • 26 pin header (P1).
  • -
-
    -
  • Hardware revision numbers of 2 and 3.
  • -
-
    -
  • User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA0
34-5V
SCL1
56-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

211314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
-
-

Type 2 - Model A, B (revision -2)

-26 pin header (P1) and an additional 8 pin header (P5). -
    -
  • Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13, -14, 15 (B).
  • -
-
    -
  • User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
5V
-12-3V3
SDA
283429SCL

305631
Ground
-
78-
Ground
-
-

Type 3 - Model A+, B+, Pi -Zero, Pi Zero W, Pi2B, Pi3B, Pi4B

-
    -
  • 40 pin expansion header (J8).
  • -
-
    -
  • Hardware revision numbers of 16 or greater.
  • -
-
    -
  • User GPIO 2-27 (0 and 1 are reserved).
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
ID_SD027281ID_SC

52930-Ground

6313212

133334-Ground
miso19353616ce2

26373820mosi
Ground-394021sclk
-
-

Compute Module

-

All 54 GPIO may be physically accessed.  Some are reserved -for system use - refer to the Compute Module documentation.

-

Only GPIO 0-31 are supported for hardware timed sampling, PWM, -servo pulses, alert callbacks, waves, and software serial -links.

-

Other -Languages

-

There are several third party projects which provide wrappers -for pigpio.

-

Some I am aware of are:

-
    -
  • Erlang -(skvamme)
  • -
  • Java JNI -wrapper around the pigpio C library (mattlewis)
  • -
  • Java via -diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc -(mattlewis)
  • -
  • Java -(nkolban)
  • -
  • .NET/mono -(unosquare)
  • -
  • Node.js -(fivdi)
  • -
  • Perl (Gligan -Calin Horea)
  • -
  • Ruby -(Nak)
  • -
  • Smalltalk(Instantiations)
  • -
  • Xojo(UBogun)
  • -
-
-

The PWM and servo pulses are timed using the DMA -and PWM/PCM peripherals.  This use was inspired by Richard -Hirst's servoblaster kernel module.

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/misc.html b/DOC/HTML/misc.html deleted file mode 100644 index e4db51a..0000000 --- a/DOC/HTML/misc.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Miscellaneous

-There are two C libraries which provide a socket interface to the -pigpio daemon.  They provide an interface very similar to the -pigpio Python module.
-
    -
  • The original pigpiod_if library is -now deprecated and will no longer be updated.  This library is -limited to controlling one Pi at a time.
  • -
-
    -
  • The new pigpiod_if2 library which -should be used for new code.  This library allows multiple Pis -to be controlled at one time.
  • -
-Additional details of the pigpio socket -interface.
-
-Additional details of the pigpio pipe -interface.
-
-pig2vcd is a utility which converts -pigpio notifications into the VCD (Value Change Dump) format.  -VCD can be read by many programs, in particular GTKWave. -
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pdif.html b/DOC/HTML/pdif.html deleted file mode 100644 index 2256f61..0000000 --- a/DOC/HTML/pdif.html +++ /dev/null @@ -1,1168 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigpiod_if



THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO -USE THE MORE VERSATILE pigpiod_if2 LIBRARY. -

pigpiod_if is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon.
-

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. -

Usage

Include <pigpiod_if.h> in your source files. -

Assuming your source is in prog.c use the following command to build -

gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt


to run make sure the pigpio daemon is running -

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if


For examples see x_pigpiod_if.c within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error -

OVERVIEW

ESSENTIAL -
pigpio_start Connects to the pigpio daemon -
pigpio_stop Disconnects from the pigpio daemon -
BEGINNER -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
gpio_read Read a GPIO -
gpio_write Write a GPIO -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -
set_servo_pulsewidth Start/stop servo pulses on a GPIO -
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -
callback Create GPIO level change callback -
callback_ex Create GPIO level change callback -
callback_cancel Cancel a callback -
wait_for_edge Wait for GPIO level change -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO. -
set_watchdog Set a watchdog on a GPIO. -
set_PWM_range Configure PWM range for a GPIO -
get_PWM_range Get configured PWM range for a GPIO -
set_PWM_frequency Configure PWM frequency for a GPIO -
get_PWM_frequency Get configured PWM frequency for a GPIO -
read_bank_1 Read all GPIO in bank 1 -
read_bank_2 Read all GPIO in bank 2 -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
start_thread Start a new thread -
stop_thread Stop a previously started thread -
ADVANCED -
get_PWM_real_range Get underlying PWM range for a GPIO -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
bb_serial_read_open Opens a GPIO for bit bang serial reads -
bb_serial_read Reads bit bang serial data from a GPIO -
bb_serial_read_close Closes a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
SCRIPTS -
store_script Store a script -
run_script Run a stored script -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_delete Deletes one or more waveforms -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_chain Transmits a chain of waveforms -
wave_tx_busy Checks to see if the waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_micros Length in microseconds of the current waveform -
wave_get_high_micros Length of longest waveform so far -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_high_pulses Length of longest waveform so far -
wave_get_max_pulses Absolute maximum allowed pulses -
wave_get_cbs Length in cbs of the current waveform -
wave_get_high_cbs Length of longest waveform so far -
wave_get_max_cbs Absolute maximum allowed cbs -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick smbus write quick -
i2c_write_byte smbus write byte -
i2c_read_byte smbus read byte -
i2c_write_byte_data smbus write byte data -
i2c_write_word_data smbus write word data -
i2c_read_byte_data smbus read byte data -
i2c_read_word_data smbus read word data -
i2c_process_call smbus process call -
i2c_write_block_data smbus write block data -
i2c_read_block_data smbus read block data -
i2c_block_process_call smbus block process call -
i2c_write_i2c_block_data smbus write I2C block data -
i2c_read_i2c_block_data smbus read I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_zip Performs multiple I2C transactions -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs multiple bit banged I2C transactions -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write Writes bytes to a serial device -
serial_read Reads bytes from a serial device -
serial_data_available Returns number of bytes ready to be read -
CUSTOM -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpiod_if_version Get the pigpiod_if version -
pigpio_error Get a text description of an error code. -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -

FUNCTIONS

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds. -

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

-Return a text description for an error code. -

errnum: the error code.

unsigned pigpiod_if_version(void)

-Return the pigpiod_if version. -

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

-Starts a new thread of execution with thread_func as the main routine. -

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument userdata. -

The thread can be cancelled by passing the pointer to pthread_t to -stop_thread. -

void stop_thread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: the thread to be stopped.


No value is returned. -

The thread to be stopped should have been started with start_thread. -

int pigpio_start(char *addrStr, char *portStr)

-Connect to the pigpio daemon. Reserving command and -notification streams. -

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.

void pigpio_stop(void)

-Terminates the connection to the pigpio daemon and releases -resources used by the library. -

int set_mode(unsigned gpio, unsigned mode)

-Set the GPIO mode. -

gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. -

int get_mode(unsigned gpio)

-Get the GPIO mode. -

gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

int set_pull_up_down(unsigned gpio, unsigned pud)

-Set or clear the GPIO pull-up/down resistor. -

gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. -

int gpio_read(unsigned gpio)

-Read the GPIO level. -

gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

int gpio_write(unsigned gpio, unsigned level)

-Write the GPIO level. -

 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. -

Notes -

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

int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)

-Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. -

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


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes -

The set_PWM_range function may be used to change the -default range of 255. -

int get_PWM_dutycycle(unsigned user_gpio)

-Return the PWM dutycycle in use on a GPIO. -

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

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

If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

int set_PWM_range(unsigned user_gpio, unsigned range)

-Set the range of PWM values to be used on the GPIO. -

user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. -

Notes -

If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. -

The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is -

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


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

int get_PWM_range(unsigned user_gpio)

-Get the range of PWM values being used on the GPIO. -

user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

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

int get_PWM_real_range(unsigned user_gpio)

-Get the real underlying range of PWM values being used on the GPIO. -

user_gpio: 0-31.


Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

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

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

int set_PWM_frequency(unsigned user_gpio, unsigned frequency)

-Set the frequency (in Hz) of the PWM to be used on the GPIO. -

user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(unsigned user_gpio)

-Get the frequency of PWM being used on the GPIO. -

user_gpio: 0-31.


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

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

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

Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)

-Start (500-2500) or stop (0) servo pulses on the GPIO. -

 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. -

The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its limits. -

OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. -

Then set the PWM range using set_PWM_range to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO 25 at 400Hz -

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-

int get_servo_pulsewidth(unsigned user_gpio)

-Return the servo pulsewidth in use on a GPIO. -

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int notify_open(void)

-Get a free notification handle. -

Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

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

Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by callback -should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

int notify_begin(unsigned handle, uint32_t bits)

-Start notifications on a previously opened handle. -

handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

Each notification occupies 12 bytes in the fifo as follows: -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


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

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. -

PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

int notify_pause(unsigned handle)

-Pause notifications on a previously opened handle. -

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until -notify_begin is called again. -

int notify_close(unsigned handle)

-Stop notifications on a previously opened handle and -release the handle for reuse. -

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int set_watchdog(unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. -

The callback will receive the special level PI_TIMEOUT. -

int set_glitch_filter(unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

uint32_t read_bank_1(void)

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

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

uint32_t read_bank_2(void)

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

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

int clear_bank_1(uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int clear_bank_2(uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_1(uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_2(uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int hardware_clock(unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

     gpio: see description
frequency: 0 (off) or 4689-250000000 (250M)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int hardware_PWM(unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_once, wave_send_repeat, -or wave_chain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

   gpio: see descripton
PWMfreq: 0 (off) or 1-125000000 (125M)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only

uint32_t get_current_tick(void)

-Gets 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. -

uint32_t get_hardware_revision(void)

-Get the Pi's hardware revision number. -

The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

uint32_t get_pigpio_version(void)

-Returns the pigpio version. -

int wave_clear(void)

-This function clears all waveforms and any data added by calls to the -wave_add_* functions. -

Returns 0 if OK. -

int wave_add_new(void)

-This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the wave_create function. -

Returns 0 if OK. -

int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. -

int wave_add_serial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, -and stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int wave_create(void)

-This function creates a waveform from the data provided by the prior -calls to the wave_add_* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the wave_add_* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_delete(unsigned wave_id)

-This function deletes the waveform with id wave_id. -

wave_id: >=0, as returned by wave_create.


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int wave_send_once(unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -is sent once. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_repeat(unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by wave_tx_stop). -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_chain(char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (pigpio_start(0, 0)<0) return -1;

   set_mode(GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create();
   }

   wave_chain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(wid[i]);

   pigpio_stop();
}

int wave_tx_busy(void)

-This function checks to see if a waveform is currently being -transmitted. -

Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int wave_tx_stop(void)

-This function stops the transmission of the current waveform. -

Returns 0 if OK. -

This function is intended to stop a waveform started with the repeat mode. -

int wave_get_micros(void)

-This function returns the length in microseconds of the current -waveform. -

int wave_get_high_micros(void)

-This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. -

int wave_get_max_micros(void)

-This function returns the maximum possible size of a waveform in
-microseconds. -

int wave_get_pulses(void)

-This function returns the length in pulses of the current waveform. -

int wave_get_high_pulses(void)

-This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. -

int wave_get_max_pulses(void)

-This function returns the maximum possible size of a waveform in pulses. -

int wave_get_cbs(void)

-This function returns the length in DMA control blocks of the current -waveform. -

int wave_get_high_cbs(void)

-This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. -

int wave_get_max_cbs(void)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

int gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. -

int store_script(char *script)

-This function stores a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

script: the text of the script.


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int run_script(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int script_status(unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. -

script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int stop_script(unsigned script_id)

-This function stops a running script. -

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int delete_script(unsigned script_id)

-This function deletes a stored script. -

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the bb_serial_read_open command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int bb_serial_read_close(unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int bb_serial_invert(unsigned user_gpio, unsigned invert)

-This function inverts serial logic for big bang serial reads. -

user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. -

int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

-This returns a handle for the device at address i2c_addr on bus i2c_bus. -

  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.

Addr  (7 bits): I2C 7 bit address.
Comm  (8 bits): Command byte, a data byte which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A data byte containing the length of a block operation.

[..]: Data sent by the device.

int i2c_close(unsigned handle)

-This closes the I2C device associated with the handle. -

handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2c_write_quick(unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr Rd/Wr [A] P

int i2c_write_byte(unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] Data [A] P

int i2c_read_byte(unsigned handle)

-This reads a single byte from the device associated with handle. -

handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] Comm [A] Data [A] P

int i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P

int i2c_read_byte_data(unsigned handle, unsigned i2c_reg)

-This reads a single byte from the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(unsigned handle, unsigned i2c_reg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

int i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] Comm [A] Count [A] Data [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

int i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_device(unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

int i2c_write_device(unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

int i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bb_i2c_close(unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bb_i2c_open. -

SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per word.
-For bits 9-16 there will be two bytes per word.
-For bits 17-32 there will be four bytes per word. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spi_close(unsigned handle)

-This functions closes the SPI device identified by the handle. -

handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spi_read(unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_write(unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)

-This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. -

  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serial_close(unsigned handle)

-This function closes the serial device associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serial_write_byte(unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read_byte(unsigned handle)

-This function reads a byte from the serial port associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serial_write(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read(unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. -

If no data is ready zero is returned. -

int serial_data_available(unsigned handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from custom_1 in that it returns an array of bytes -rather than just an integer. -

The return value is an integer indicating the number of returned bytes. -  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

Note, the number of returned bytes will be retMax or less. -

int callback(unsigned user_gpio, unsigned edge, CBFunc_t f)

-This function initialises a new callback. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

int callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

-This function initialises a new callback. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, tick, and user, whenever -the GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

-This function cancels a callback identified by its id. -

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)

-This function waits for edge on the GPIO for up to timeout -seconds. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns 1 if the edge occurred, otherwise 0. -

The function returns when the edge occurs or after the timeout. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

*addrStr

-A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

callback_id

-A >=0, as returned by a call to callback or callback_ex. This is -passed to callback_cancel to cancel the callback. -

CBFunc_t

-typedef void (*CBFunc_t)
   (unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

-typedef void (*CBFuncEx_t)
   (unsigned user_gpio, unsigned level, uint32_t tick, void * user);

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250000000 (250M)

-The hardware clock frequency. -

count

-The number of bytes to be transferred in an I2C, SPI, or Serial -command. -

data_bits: 1-32

-The number of data bits in each character of serial data. -

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge

-Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. -

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

-A negative number indicating a function call failed and the nature -of the error. -

f

-A function. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 get_hardware_revision. -

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  -  -  -  -

gpioPulse_t

-typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

-A number referencing an object opened by one of i2c_open, notify_open, -serial_open, and spi_open. -

i2c_addr: 0-0x7F

-The address of a device on the I2C bus. -

i2c_bus: >=0

-An I2C bus number. -

i2c_flags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2c_reg: 0-255

-A register of an I2C device. -

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See set_watchdog. -

PI_TIMEOUT 2

mode: 0-7

-The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

*param

-An array of script parameters. -

*portStr

-A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. -

*pth

-A thread identifier, returned by start_thread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125000000 (125M)

-The hardware PWM frequency. -

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000

range: 25-40000

-The permissible dutycycle values are 0-range. -PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by store_script. -

SDA

-The user GPIO to use for data when bit banging I2C. -

seconds

-The number of seconds. -

ser_flags

-Flags which modify a serial open command. None are currently defined. -

*ser_tty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

size_t

-A standard type used to indicate the size of an object in bytes. -

spi_channel

-A SPI channel, 0-2. -

spi_flags

-See spi_open. -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) or triggering -the active part of a noise filter (set_noise_filter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

- An array of characters. -

thread_func

-A function of type gpioThreadFunc_t used as the main function of a -thread. -

timeout

-A GPIO watchdog timeout in milliseconds. -PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

unsigned

-A whole number >= 0. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

void

-Denoting no parameter is required -

wave_add_*

-One of wave_add_new, wave_add_generic, wave_add_serial. -

wave_id

-A number representing a waveform created by wave_create. -

wave_send_*

-One of wave_send_once, wave_send_repeat. -

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

pigpiod_if Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
} pigifError_t;

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pdif2.html b/DOC/HTML/pdif2.html deleted file mode 100644 index db30a8c..0000000 --- a/DOC/HTML/pdif2.html +++ /dev/null @@ -1,1523 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigpiod C Interface



pigpiod_if2 is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon.
-

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. -

Usage

Include <pigpiod_if2.h> in your source files. -

Assuming your source is in prog.c use the following command to build -

gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt


to run make sure the pigpio daemon is running -

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if2


For examples see x_pigpiod_if2.c within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error -

OVERVIEW

ESSENTIAL -
pigpio_start Connects to a pigpio daemon -
pigpio_stop Disconnects from a pigpio daemon -
BASIC -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
gpio_read Read a GPIO -
gpio_write Write a GPIO -
PWM (overrides servo commands on same GPIO) -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
set_PWM_frequency Configure PWM frequency for a GPIO -
set_PWM_range Configure PWM range for a GPIO -
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -
get_PWM_frequency Get configured PWM frequency for a GPIO -
get_PWM_range Get configured PWM range for a GPIO -
get_PWM_real_range Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
set_servo_pulsewidth Start/stop servo pulses on a GPIO -
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO. -
set_watchdog Set a watchdog on a GPIO. -
read_bank_1 Read all GPIO in bank 1 -
read_bank_2 Read all GPIO in bank 2 -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
callback Create GPIO level change callback -
callback_ex Create GPIO level change callback, extended -
callback_cancel Cancel a callback -
wait_for_edge Wait for GPIO level change -
start_thread Start a new thread -
stop_thread Stop a previously started thread -
ADVANCED -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
set_pad_strength Sets a pads drive strength -
get_pad_strength Gets a pads drive strength -
shell_ Executes a shell command -
Custom -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
Events -
event_callback Sets a callback for an event -
event_callback_ex Sets a callback for an event, extended -
event_callback_cancel Cancel an event callback -
event_trigger Triggers an event -
wait_for_event Wait for an event -
Scripts -
store_script Store a script -
run_script Run a stored script -
update_script Set a scripts parameters -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick smbus write quick -
i2c_read_byte smbus read byte -
i2c_write_byte smbus write byte -
i2c_read_byte_data smbus read byte data -
i2c_write_byte_data smbus write byte data -
i2c_read_word_data smbus read word data -
i2c_write_word_data smbus write word data -
i2c_read_block_data smbus read block data -
i2c_write_block_data smbus write block data -
i2c_read_i2c_block_data smbus read I2C block data -
i2c_write_i2c_block_data smbus write I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_process_call smbus process call -
i2c_block_process_call smbus block process call -
i2c_zip Performs multiple I2C transactions -
I2C BIT BANG -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs bit banged I2C transactions -
I2C/SPI SLAVE -
bsc_xfer I2C/SPI as slave transfer -
bsc_i2c I2C as slave transfer -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read Reads bytes from a serial device -
serial_write Writes bytes to a serial device -
serial_data_available Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
bb_serial_read_open Opens a GPIO for bit bang serial reads -
bb_serial_read_close Closes a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
bb_serial_read Reads bit bang serial data from a GPIO -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SPI BIT BANG -
bb_spi_open Opens GPIO for bit banging SPI -
bb_spi_close Closes GPIO for bit banging SPI -
bb_spi_xfer Transfers bytes with bit banging SPI -
FILES -
file_open Opens a file -
file_close Closes a file -
file_read Reads bytes from a file -
file_write Writes bytes to a file -
file_seek Seeks to a position within a file -
file_list List files which match a pattern -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_create_and_pad Creates a waveform of fixed size from added data -
wave_delete Deletes one or more waveforms -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_send_using_mode Transmits a waveform in the chosen mode -
wave_chain Transmits a chain of waveforms -
wave_tx_at Returns the current transmitting waveform -
wave_tx_busy Checks to see if the waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_cbs Length in cbs of the current waveform -
wave_get_high_cbs Length of longest waveform so far -
wave_get_max_cbs Absolute maximum allowed cbs -
wave_get_micros Length in micros of the current waveform -
wave_get_high_micros Length of longest waveform so far -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_high_pulses Length of longest waveform so far -
wave_get_max_pulses Absolute maximum allowed pulses -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpiod_if_version Get the pigpiod_if2 version -
pigpio_error Get a text description of an error code. -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -

FUNCTIONS

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds. -

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

-Return a text description for an error code. -

errnum: the error code.

unsigned pigpiod_if_version(void)

-Return the pigpiod_if2 version. -

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

-Starts a new thread of execution with thread_func as the main routine. -

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument userdata. -

The thread can be cancelled by passing the pointer to pthread_t to -stop_thread. -

void stop_thread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: the thread to be stopped.


No value is returned. -

The thread to be stopped should have been started with start_thread. -

int pigpio_start(char *addrStr, char *portStr)

-Connect to the pigpio daemon. Reserving command and -notification streams. -

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.


Returns an integer value greater than or equal to zero if OK. -

This value is passed to the GPIO routines to specify the Pi -to be operated on. -

void pigpio_stop(int pi)

-Terminates the connection to a pigpio daemon and releases -resources used by the library. -

pi: >=0 (as returned by pigpio_start).

int set_mode(int pi, unsigned gpio, unsigned mode)

-Set the GPIO mode. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. -

int get_mode(int pi, unsigned gpio)

-Get the GPIO mode. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

int set_pull_up_down(int pi, unsigned gpio, unsigned pud)

-Set or clear the GPIO pull-up/down resistor. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. -

int gpio_read(int pi, unsigned gpio)

-Read the GPIO level. -

  pi: >=0 (as returned by pigpio_start).
gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

int gpio_write(int pi, unsigned gpio, unsigned level)

-Write the GPIO level. -

   pi: >=0 (as returned by pigpio_start).
 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. -

Notes -

If PWM or servo pulses are active on the GPIO they are switched off. -

int set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)

-Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes -

The set_PWM_range function may be used to change the -default range of 255. -

int get_PWM_dutycycle(int pi, unsigned user_gpio)

-Return the PWM dutycycle in use on a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

int set_PWM_range(int pi, unsigned user_gpio, unsigned range)

-Set the range of PWM values to be used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. -

Notes -

If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. -

The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is -

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


The real value set by set_PWM_range is (dutycycle * real range) / range. -

int get_PWM_range(int pi, unsigned user_gpio)

-Get the range of PWM values being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). -

int get_PWM_real_range(int pi, unsigned user_gpio)

-Get the real underlying range of PWM values being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

int set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)

-Set the frequency (in Hz) of the PWM to be used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(int pi, unsigned user_gpio)

-Get the frequency of PWM being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


For normal PWM the frequency will be that defined for the GPIO by -set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

int set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)

-Start (500-2500) or stop (0) servo pulses on the GPIO. -

        pi: >=0 (as returned by pigpio_start).
 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. -

The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its limits. -

OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. -

Then set the PWM range using set_PWM_range to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO 25 at 400Hz -

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-

int get_servo_pulsewidth(int pi, unsigned user_gpio)

-Return the servo pulsewidth in use on a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int notify_open(int pi)

-Get a free notification handle. -

pi: >=0 (as returned by pigpio_start).


Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by callback -should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

int notify_begin(int pi, unsigned handle, uint32_t bits)

-Start notifications on a previously opened handle. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

Each notification occupies 12 bytes in the fifo as follows: -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

int notify_pause(int pi, unsigned handle)

-Pause notifications on a previously opened handle. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until -notify_begin is called again. -

int notify_close(int pi, unsigned handle)

-Stop notifications on a previously opened handle and -release the handle for reuse. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int set_watchdog(int pi, unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. -

The callback will receive the special level PI_TIMEOUT. -

int set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than -steady microseconds are ignored. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

uint32_t read_bank_1(int pi)

-Read the levels of the bank 1 GPIO (GPIO 0-31). -

pi: >=0 (as returned by pigpio_start).


The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<n). -

uint32_t read_bank_2(int pi)

-Read the levels of the bank 2 GPIO (GPIO 32-53). -

pi: >=0 (as returned by pigpio_start).


The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). -

int clear_bank_1(int pi, uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int clear_bank_2(int pi, uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_1(int pi, uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_2(int pi, uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int hardware_clock(int pi, unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

       pi: >=0 (as returned by pigpio_start).
     gpio: see description
frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_* or wave_chain -will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

     pi: >=0 (as returned by pigpio_start).
   gpio: see descripton
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. -

uint32_t get_current_tick(int pi)

-Gets the current system tick. -

pi: >=0 (as returned by pigpio_start).


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. -

uint32_t get_hardware_revision(int pi)

-Get the Pi's hardware revision number. -

pi: >=0 (as returned by pigpio_start).


The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

uint32_t get_pigpio_version(int pi)

-Returns the pigpio version. -

pi: >=0 (as returned by pigpio_start).

int wave_clear(int pi)

-This function clears all waveforms and any data added by calls to the -wave_add_* functions. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

int wave_add_new(int pi)

-This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the wave_create function. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

int wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

       pi: >=0 (as returned by pigpio_start).
numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. -

int wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, -and stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int wave_create(int pi)

-This function creates a waveform from the data provided by the prior -calls to the wave_add_* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_create_and_pad(int pi, int percent)

-This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use (in terms -of the theoretical maximum, not the current amount free). This allows the reuse
-of deleted waves while a transmission is active. -

pi: >=0 (as returned by pigpio_start).
percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Normal usage: -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create_and_pad to create a waveform of uniform size. -

Step 4. wave_send_* with the id of the waveform to transmit. -

Repeat steps 2-4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_delete(int pi, unsigned wave_id)

-This function deletes the waveform with id wave_id. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int wave_send_once(int pi, unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -is sent once. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_repeat(int pi, unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by wave_tx_stop). -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)

-Transmits the waveform with id wave_id using mode mode. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.
   mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
         PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC.


PI_WAVE_MODE_ONE_SHOT: same as wave_send_once. -

PI_WAVE_MODE_REPEAT same as wave_send_repeat. -

PI_WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries -to sync with the previous waveform. -

PI_WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries -to sync with the previous waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_chain(int pi, char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

     pi: >=0 (as returned by pigpio_start).
    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if2.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, pi, wid[WAVES];

   pi = pigpio_start(0, 0);
   if (pi<0) return -1;

   set_mode(pi, GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(pi, 2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create(pi);
   }

   wave_chain(pi, (char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy(pi)) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(pi, wid[i]);

   pigpio_stop(pi);
}

int wave_tx_at(int pi)

-This function returns the id of the waveform currently being -transmitted. -

pi: >=0 (as returned by pigpio_start).


Returns the waveform id or one of the following special values: -

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
-PI_NO_TX_WAVE (9999) - no wave being transmitted. -

int wave_tx_busy(int pi)

-This function checks to see if a waveform is currently being -transmitted. -

pi: >=0 (as returned by pigpio_start).


Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int wave_tx_stop(int pi)

-This function stops the transmission of the current waveform. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

This function is intended to stop a waveform started with the repeat mode. -

int wave_get_micros(int pi)

-This function returns the length in microseconds of the current -waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_micros(int pi)

-This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_micros(int pi)

-This function returns the maximum possible size of a waveform in
-microseconds. -

pi: >=0 (as returned by pigpio_start).

int wave_get_pulses(int pi)

-This function returns the length in pulses of the current waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_pulses(int pi)

-This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_pulses(int pi)

-This function returns the maximum possible size of a waveform in pulses. -

pi: >=0 (as returned by pigpio_start).

int wave_get_cbs(int pi)

-This function returns the length in DMA control blocks of the current -waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_cbs(int pi)

-This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_cbs(int pi)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

pi: >=0 (as returned by pigpio_start).

int gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. -

int store_script(int pi, char *script)

-This function stores a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

    pi: >=0 (as returned by pigpio_start).
script: the text of the script.


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

-This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int script_status(int pi, unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int stop_script(int pi, unsigned script_id)

-This function stops a running script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int delete_script(int pi, unsigned script_id)

-This function deletes a stored script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the bb_serial_read_open command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int bb_serial_read_close(int pi, unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)

-This function inverts serial logic for big bang serial reads. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. -

int i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

-This returns a handle for the device at address i2c_addr on bus i2c_bus. -

       pi: >=0 (as returned by pigpio_start).
  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S       (1 bit) : Start bit
P       (1 bit) : Stop bit
Rd/Wr   (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA   (1 bit) : Accept and not accept bit.

Addr    (7 bits): I2C 7 bit address.
i2c_reg (8 bits): A byte which often selects a register.
Data    (8 bits): A data byte.
Count   (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2c_close(int pi, unsigned handle)

-This closes the I2C device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2c_write_quick(int pi, unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr bit [A] P

int i2c_write_byte(int pi, unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] bVal [A] P

int i2c_read_byte(int pi, unsigned handle)

-This reads a single byte from the device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] i2c_reg [A] bVal [A] P

int i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P

int i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)

-This reads a single byte from the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ...
   [A] bufn [A] P

int i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

  pi: >=0 (as returned by pigpio_start).
 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bb_i2c_close(int pi, unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bb_i2c_open. -

 pi: >=0 (as returned by pigpio_start).
SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

    pi: >=0 (as returned by pigpio_start).
   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)

-This function selects a set of GPIO for bit banging SPI at a -specified baud rate. -

       pi: >=0 (as returned by pigpio_start).
       CS: 0-31
     MISO: 0-31
     MOSI: 0-31
     SCLK: 0-31
     baud: 50-250000
spi_flags: see below


spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bb_spi_close(int pi, unsigned CS)

-This function stops bit banging SPI on a set of GPIO -opened with bbSPIOpen. -

pi: >=0 (as returned by pigpio_start).
CS: 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

int bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)

-This function executes a bit banged SPI transfer. -

   pi: >=0 (as returned by pigpio_start).
   CS: 0-31 (as used in a prior call to bb_spi_open)
txBuf: pointer to buffer to hold data to be sent
rxBuf: pointer to buffer to hold returned data
count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. -

Example

// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2
// ./bb_spi_x_test

#include <stdio.h>

#include "pigpiod_if2.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, pi, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if ((pi = pigpio_start(0, 0)) < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bb_spi_close(pi, CE0);
   bb_spi_close(pi, CE1);

   pigpio_stop(pi);
}

int spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


         pi: >=0 (as returned by pigpio_start).
spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per character.
-For bits 9-16 there will be two bytes per character.
-For bits 17-32 there will be four bytes per character. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spi_close(int pi, unsigned handle)

-This functions closes the SPI device identified by the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spi_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)

-This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. -

       pi: >=0 (as returned by pigpio_start).
  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serial_close(int pi, unsigned handle)

-This function closes the serial device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serial_write_byte(int pi, unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read_byte(int pi, unsigned handle)

-This function reads a byte from the serial port associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serial_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. -

If no data is ready zero is returned. -

int serial_data_available(int pi, unsigned handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

  pi: >=0 (as returned by pigpio_start).
arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from custom_1 in that it returns an array of bytes -rather than just an integer. -

The return value is an integer indicating the number of returned bytes. -    pi: >=0 (as returned by pigpio_start).
  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

Note, the number of returned bytes will be retMax or less. -

int get_pad_strength(int pi, unsigned pad)

-This function returns the pad drive strength in mA. -

 pi: >=0 (as returned by pigpio_start).
pad: 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = get_pad_strength(pi, 0); //  get pad 0 strength

int set_pad_strength(int pi, unsigned pad, unsigned padStrength)

-This function sets the pad drive strength in mA. -

         pi: >=0 (as returned by pigpio_start).
        pad: 0-2, the pad to set.
padStrength: 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA

int shell_(int pi, char *scriptName, char *scriptString)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

          pi: >=0 (as returned by pigpio_start).
  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name.
scriptString: the string to pass to the script.


The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. -

scriptName must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell_(pi, "scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell_(pi, "scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell_(pi, "scr1", "\"hello string with spaces world\"");

int file_open(int pi, char *file, unsigned mode)

-This function returns a handle to a file opened in a specified mode. -

  pi: >=0 (as returned by pigpio_start).
file: the file to open.
mode: the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


The following values may be or'd into the mode. -

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=file_read(pi, handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      file_close(pi, handle);
   }

   pigpio_stop(pi);
}

int file_close(int pi, unsigned handle)

-This function closes the file associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

file_close(pi, handle);

int file_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the file -associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. -

Example

if (file_write(pi, handle, buf, 100) == 0)
{
   // file written okay
}
else
{
   // error
}

int file_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the file -associated with handle and writes them to buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. -

Example

   bytes = file_read(pi, handle, buf, sizeof(buf));

   if (bytes >= 0)
   {
      // process read data
   }

int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)

-This function seeks to a position within the file associated -with handle. -

        pi: >=0 (as returned by pigpio_start).
    handle: >=0 (as returned by file_open).
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2).


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. -

Example

file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123

size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size

pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position

int file_list(int pi, char *fpat, char *buf, unsigned count)

-This function returns a list of files which match a pattern. -

   pi: >=0 (as returned by pigpio_start).
 fpat: file pattern to match.
  buf: an array to receive the matching file names.
count: the maximum number of bytes to read.


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See file_open. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   c = file_list(pi, "/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      buf[c] = 0;
      printf("%s", buf);
   }

   pigpio_stop(pi);
}

int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)

-This function initialises a new callback. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. -

The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use gpio_read. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

int callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

-This function initialises a new callback. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, tick, and the userdata -pointer, whenever the GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

-This function cancels a callback identified by its id. -

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)

-This function waits for an edge on the GPIO for up to timeout -seconds. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns when the edge occurs or after the timeout. -

Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a callback function. -

The function returns 1 if the edge occurred, otherwise 0. -

int bsc_xfer(int pi, bsc_xfer_t *bscxfer)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

     pi: >=0 (as returned by pigpio_start).
bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. -

Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. -

The returned function value is the status of the transfer (see below). -

If there was an error the status will be less than zero -(and will contain the error code). -

The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

control consists of the following bits. -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. -

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bsc_xfer(pi, &xfer);

if (status >= 0)
{
   // process transfer
}

int bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)

-This function allows the Pi to act as a slave I2C device. -

This function is not available on the BCM2711 (e.g.as -used in the Pi4B). -

The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. -

      pi: >=0 (as returned by pigpio_start).
i2c_addr: 0-0x7F.
 bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // N/A
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


txCnt is set to the number of bytes to be transmitted, possibly -zero. The data itself should be copied to txBuf. -

Any received data will be written to rxBuf with rxCnt set. -

See bsc_xfer for details of the returned status value. -

If there was an error the status will be less than zero -(and will contain the error code). -

Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. -

int event_callback(int pi, unsigned event, evtCBFunc_t f)

-This function initialises an event callback. -

   pi: >=0 (as returned by pigpio_start).
event: 0-31.
    f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the event id, and tick, whenever the -event occurs. -

int event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)

-This function initialises an event callback. -

      pi: >=0 (as returned by pigpio_start).
   event: 0-31.
       f: the callback function.
userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the event id, the tick, and the userdata -pointer whenever the event occurs. -

int event_callback_cancel(unsigned callback_id)

-This function cancels an event callback identified by its id. -

callback_id: >=0, as returned by a call to event_callback or
event_callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_event(int pi, unsigned event, double timeout)

-This function waits for an event for up to timeout seconds. -

     pi: >=0 (as returned by pigpio_start).
  event: 0-31.
timeout: >=0.


The function returns when the event occurs or after the timeout. -

The function returns 1 if the event occurred, otherwise 0. -

int event_trigger(int pi, unsigned event)

-This function signals the occurrence of an event. -

   pi: >=0 (as returned by pigpio_start).
event: 0-31.


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling event_callback) will be informed by -a callback. -

One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

*addrStr

-A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

bsc_xfer_t

-typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*bscxfer

-A pointer to a bsc_xfer_t object used to control a BSC transfer. -

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

callback_id

-A value >=0, as returned by a call to a callback function, one of -

callback
-callback_ex
-event_callback
-event_callback_ex -

The id is passed to callback_cancel or event_callback_cancel -to cancel the callback. -

CBFunc_t

-typedef void (*CBFunc_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

-typedef void (*CBFuncEx_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata);

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

-The hardware clock frequency. -

count

-The number of bytes to be transferred in a file, I2C, SPI, or serial -command. -

CS

-The GPIO used for the slave select signal when bit banging SPI. -

data_bits: 1-32

-The number of data bits in each character of serial data. -

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge

-Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. -

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

-A negative number indicating a function call failed and the nature -of the error. -

event: 0-31

-An event is a signal used to inform one or more consumers -to start an action. -

evtCBFunc_t

-typedef void (*evtCBFunc_t)
   (int pi, unsigned event, uint32_t tick);

evtCBFuncEx_t

-typedef void (*evtCBFuncEx_t)
   (int pi, unsigned event, uint32_t tick, void *userdata);

f

-A function. -

*file

-A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. -

*fpat

-A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 get_hardware_revision. -

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  -  -  -  -

gpioPulse_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

-A number referencing an object opened by one of -

file_open
-i2c_open
-notify_open
-serial_open
-spi_open -

i2c_addr: 0-0x7F

-The address of a device on the I2C bus. -

i2c_bus: >=0

-An I2C bus number. -

i2c_flags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2c_reg: 0-255

-A register of an I2C device. -

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

int32_t

-A 32-bit signed value. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See set_watchdog. -

PI_TIMEOUT 2

MISO

-The GPIO used for the MISO signal when bit banging SPI. -

mode

-1. The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. The mode of waveform transmission. -

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3


3. A file open mode. -

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


The following values can be or'd into the mode. -

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

-The GPIO used for the MOSI signal when bit banging SPI. -

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

pad: 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

-The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

*param

-An array of script parameters. -

percent: 0-100

-The size of waveform as percentage of maximum available. -

pi

-An integer defining a connected Pi. The value is returned by -pigpio_start upon success. -

*portStr

-A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. -

*pth

-A thread identifier, returned by start_thread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

-The hardware PWM frequency. -

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000
#define PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

-The permissible dutycycle values are 0-range. -

PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

SCLK

-The GPIO used for the SCLK signal when bit banging SPI. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by store_script. -

*scriptName

-The name of a shell_ script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. -

*scriptString

-The string to be passed to a shell_ script to be executed. -

SDA

-The user GPIO to use for data when bit banging I2C. -

seconds

-The number of seconds. -

seekFrom

-PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

-The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). -

ser_flags

-Flags which modify a serial open command. None are currently defined. -

*ser_tty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

size_t

-A standard type used to indicate the size of an object in bytes. -

spi_channel

-A SPI channel, 0-2. -

spi_flags

-See spi_open and bb_spi_open. -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) or triggering -the active part of a noise filter (set_noise_filter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

- An array of characters. -

thread_func

-A function of type gpioThreadFunc_t used as the main function of a -thread. -

timeout

-A GPIO watchdog timeout in milliseconds. -

PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

unsigned

-A whole number >= 0. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. -

In the calling function: -

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: -

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

-Denoting no parameter is required -

wave_add_*

-One of -

wave_add_new
-wave_add_generic
-wave_add_serial -

wave_id

-A number representing a waveform created by wave_create. -

wave_send_*

-One of -

wave_send_once
-wave_send_repeat -

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

pigpiod_if2 Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
   pigif_unconnected_pi     = -2011,
   pigif_too_many_pis       = -2012,
} pigifError_t;

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pif.html b/DOC/HTML/pif.html deleted file mode 100644 index 1cc3c17..0000000 --- a/DOC/HTML/pif.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Pipe Interface

-pigpio provides a pipe interface to many of its functions.
-
-The pipe interface is available whenever pigpio is running, either -because it has been started as a daemon, or it has been linked in -to a running user program.  The pipe interface can be disabled -by the program which initialises the library.  pigpiod offers -the -f option to disable the pipe interface.  User programs -should call gpioCfgInterfaces -if they wish to disable the pipe interface.
-
-pigpio listens for commands on pipe /dev/pigpio.  The commands -consist of a command identifier with, depending on the command, -zero, one, or two parameters.  The result, if any, may be read -from pipe /dev/pigout.  If any errors are detected a message -will be written to pipe /dev/pigerr.
-
-
-The format of the commands is identical to those used by pigs. -
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pig2vcd.html b/DOC/HTML/pig2vcd.html deleted file mode 100644 index e64a2fb..0000000 --- a/DOC/HTML/pig2vcd.html +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pig2vcd

pig2vcd is a utility which reads notifications on stdin and writes the -output as a Value Change Dump (VCD) file on stdout. -

The VCD file can be viewed using GTKWave. -

Notifications

Notifications consist of 12 bytes with the following binary format. -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments by one for each report. -

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. -

tick: the number of microseconds since system boot. It wraps around after 1h12m. -

level: indicates the level of each gpio. If bit 1<<x is set then gpio x is high. pig2vcd takes these notifications and outputs a text format VCD. -

VCD format

The VCD starts with a header. -

$date 2013-05-31 18:49:36 $end
$version pig2vcd V1 $end
$timescale 1 us $end
$scope module top $end
$var wire 1 A 0 $end
$var wire 1 B 1 $end
$var wire 1 C 2 $end
$var wire 1 D 3 $end
$var wire 1 E 4 $end
$var wire 1 F 5 $end
$var wire 1 G 6 $end
$var wire 1 H 7 $end
$var wire 1 I 8 $end
$var wire 1 J 9 $end
$var wire 1 K 10 $end
$var wire 1 L 11 $end
$var wire 1 M 12 $end
$var wire 1 N 13 $end
$var wire 1 O 14 $end
$var wire 1 P 15 $end
$var wire 1 Q 16 $end
$var wire 1 R 17 $end
$var wire 1 S 18 $end
$var wire 1 T 19 $end
$var wire 1 U 20 $end
$var wire 1 V 21 $end
$var wire 1 W 22 $end
$var wire 1 X 23 $end
$var wire 1 Y 24 $end
$var wire 1 Z 25 $end
$var wire 1 a 26 $end
$var wire 1 b 27 $end
$var wire 1 c 28 $end
$var wire 1 d 29 $end
$var wire 1 e 30 $end
$var wire 1 f 31 $end
$upscope $end
$enddefinitions $end


The header defines gpio identifiers and their name. Each gpio identifier -must be unique. pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0 -through 25, and 'a' through 'f' for gpios 26 through 31. -The corresponding names are 0 through 31.
-

The VCD file may be edited to give a frendlier name, e.g. 8 could be -changed to ENCODER_A if an encoder switch A is connected to gpio 8. -

Following the header pig2vcd takes notifications and outputs a timestamp -followed by a list of one or more gpios which have changed state. -The timestamp consists of a '#' followed by the microsecond tick. -The state lines contain the new state followed by the gpio identifier. -

#1058747
0H
0I
#1059012
1H
#1079777
1I
#1079782
0I
#1079852
1I
#1079857
0I
0H
#1165113
1H
#1165118
0H
#1165153
1H
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pigpiod.html b/DOC/HTML/pigpiod.html deleted file mode 100644 index d522889..0000000 --- a/DOC/HTML/pigpiod.html +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigpio Daemon

pigpiod is a utility which launches the pigpio library as a daemon.
-
-Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.
-
-The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.
-
-pigpiod accepts the following configuration options
-
-
-a valueDMA memory allocation mode0=AUTO, 1=PMAP, 2=MBOXDefault AUTO -
-b valueGPIO sample buffer size in milliseconds100-10000Default 120 -
-c valueLibrary internal settingsDefault 0 -
-d valuePrimary DMA channel0-14Default 14 -
-e valueSecondary DMA channel0-14Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel -
-fDisable fifo interfaceDefault enabled -
-gRun in foreground (do not fork)Default disabled -
-kDisable local and remote socket interfaceDefault enabled -
-lDisable remote socket interfaceDefault enabled -
-mDisable alerts (sampling)Default enabled -
-n IP addressAllow IP address to use the socket interfaceName (e.g. paul) or dotted quad (e.g. 192.168.1.66)If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect -
-p valueSocket port1024-32000Default 8888 -
-s valueSample rate1, 2, 4, 5, 8, or 10 microsecondsDefault 5 -
-t valueClock peripheral0=PWM 1=PCMDefault PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. -
-v -VDisplay pigpio version and exit -
-x maskGPIO which may be updatedA 54 bit mask with (1<<n) set if the user may update GPIO #nDefault is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO -

Example

sudo pigpiod -s 2 -b 200 -f


Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer. Disable the fifo interface. -

Permissions

pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces. -

All GPIO may be read. -

Only the user GPIO for the board type or those specified by the -x option may be updated. -

Type 1 boards 0x03E6CF93 (26 pin header)
Type 2 boards 0xFBC6CF9C (26 pin + 8 pin header)
Type 3 boards 0x0FFFFFFC (40 pin header)


In this context an update includes the following: -

GPIO mode set
-GPIO pull/up down
-GPIO write
-GPIO set PWM (including range and frequency)
-GPIO set servo -

In addition the bank clear and set commands, and the wave commands will only -affect updateable GPIO. -

Exceptions

The following exceptions are made for particular models. -

Models A and B

The green activity LED (GPIO 16) may be written.
-
Models A+ and B+

The green activity LED (GPIO 47) may be written.
-The red power LED (GPIO 35) may be written.
-The high USB power mode (GPIO 38) may be written.
-
Pi Zero

The green activity LED (GPIO 47) may be written.
-
Pi2B

The green activity LED (GPIO 47) may be written.
-The red power LED (GPIO 35) may be written.
-The high USB power mode (GPIO 38) may be written.
-
Pi3B

The green activity LED and the red power LED are not writable.
-The USB power mode is fixed at 1.2 amps (high power).
-

DMA Channels

The secondary channel is only used for the transmission of waves. -

If possible use one of channels 0 to 6 for the secondary channel (a full channel). -

A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel. -

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pigs.html b/DOC/HTML/pigs.html deleted file mode 100644 index d4b4079..0000000 --- a/DOC/HTML/pigs.html +++ /dev/null @@ -1,1268 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigs

Introduction

-The socket and pipe interfaces allow control of the Pi's GPIO by -passing messages to the running pigpio library. -

The normal way to start the pigpio library would be as a daemon during boot. -

sudo pigpiod

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

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. -

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 $?). -

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). -

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. -

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. -

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 mSet GPIO mode gpioSetMode
MG/MODEG gGet GPIO mode gpioGetMode
PUD g pSet GPIO pull up/down gpioSetPullUpDown
R/READ gRead GPIO level gpioRead
W/WRITE g LWrite GPIO level gpioWrite
PWM (overrides servo commands on same GPIO) -
P/PWM u vSet GPIO PWM value gpioPWM
PFS u vSet GPIO PWM frequency gpioSetPWMfrequency
PRS u vSet GPIO PWM range gpioSetPWMrange
GDC uGet GPIO PWM dutycycle gpioGetPWMdutycycle
PFG uGet GPIO PWM frequency gpioGetPWMfrequency
PRG uGet GPIO PWM range gpioGetPWMrange
PRRG uGet GPIO PWM real range gpioGetPWMrealRange
Servo (overrides PWM commands on same GPIO) -
S/SERVO u vSet GPIO servo pulsewidth gpioServo
GPW uGet GPIO servo pulsewidth gpioGetServoPulsewidth
INTERMEDIATE -
TRIG u pl LSend a trigger pulse gpioTrigger
WDOG u vSet GPIO watchdog gpioSetWatchdog
BR1Read bank 1 GPIO gpioRead_Bits_0_31
BR2Read bank 2 GPIO gpioRead_Bits_32_53
BC1 bitsClear specified GPIO in bank 1 gpioWrite_Bits_0_31_Clear
BC2 bitsClear specified GPIO in bank 2 gpioWrite_Bits_32_53_Clear
BS1 bitsSet specified GPIO in bank 1 gpioWrite_Bits_0_31_Set
BS2 bitsSet specified GPIO in bank 2 gpioWrite_Bits_32_53_Set
ADVANCED -
NORequest a notification gpioNotifyOpen
NC hClose notification gpioNotifyClose
NB h bitsStart notification gpioNotifyBegin
NP hPause notification gpioNotifyPause
HC g cfSet hardware clock frequency gpioHardwareClock
HP g pf pdcSet hardware PWM frequency and dutycycle gpioHardwarePWM
FG u stdySet a glitch filter on a GPIO gpioGlitchFilter
FN u stdy actvSet a noise filter on a GPIO gpioNoiseFilter
PADS pad padmaSet pad drive strength gpioSetPad
PADG padGet pad drive strength gpioGetPad
SHELL name strExecute a shell command shell
Custom -
CF1 uvsCustom function 1 gpioCustom1
CF2 uvsCustom function 2 gpioCustom1
Events -
EVM h bitsSet events to monitor eventMonitor
EVT eventTrigger event eventTrigger
Scripts -
PROC tStore script gpioStoreScript
PROCR sid parsRun script gpioRunScript
PROCU sid parsSet script parameters gpioUpdateScript
PROCP sidGet script status and parameters gpioScriptStatus
PROCS sidStop script gpioStopScript
PROCD sidDelete script gpioDeleteScript
PARSE tValidate script gpioParseScript
I2C -
I2CO ib id ifOpen I2C bus and device with flags i2cOpen
I2CC hClose I2C handle i2cClose
I2CWQ h bitsmb Write Quick: write bit i2cWriteQuick
I2CRS hsmb Read Byte: read byte i2cReadByte
I2CWS h bvsmb Write Byte: write byte i2cWriteByte
I2CRB h rsmb Read Byte Data: read byte from register i2cReadByteData
I2CWB h r bvsmb Write Byte Data: write byte to register i2cWriteByteData
I2CRW h rsmb Read Word Data: read word from register i2cReadWordData
I2CWW h r wvsmb Write Word Data: write word to register i2cWriteWordData
I2CRK h rsmb Read Block Data: read data from register i2cReadBlockData
I2CWK h r bvssmb Write Block Data: write data to register i2cWriteBlockData
I2CWI h r bvssmb Write I2C Block Data i2cWriteI2CBlockData
I2CRI h r numsmb Read I2C Block Data: read bytes from register i2cReadI2CBlockData
I2CRD h numi2c Read device i2cReadDevice
I2CWD h bvsi2c Write device i2cWriteDevice
I2CPC h r wvsmb Process Call: exchange register with word i2cProcessCall
I2CPK h r bvssmb Block Process Call: exchange data bytes with register i2cBlockProcessCall
I2CZ h bvsPerforms multiple I2C transactions i2cZip
I2C BIT BANG -
BI2CO sda scl bOpen bit bang I2C bbI2COpen
BI2CC sdaClose bit bang I2C bbI2CClose
BI2CZ sda bvsI2C bit bang multiple transactions bbI2CZip
I2C/SPI SLAVE -
BSCX bctl bvsBSC I2C/SPI transfer bscXfer
SERIAL -
SERO dev b sefOpen serial device dev at baud b with flags serOpen
SERC hClose serial handle serClose
SERRBRead byte from serial handle serReadByte
SERWB h bvWrite byte to serial handle serWriteByte
SERR h numRead bytes from serial handle serRead
SERW h bvsWrite bytes to serial handle serWrite
SERDA hCheck for serial data ready to read serDataAvailable
SERIAL BIT BANG (read only) -
SLRO u b dbOpen GPIO for bit bang serial data gpioSerialReadOpen
SLRC uClose GPIO for bit bang serial data gpioSerialReadClose
SLRI u vSets bit bang serial data logic levels gpioSerialReadInvert
SLR u numRead bit bang serial data from GPIO gpioSerialRead
SPI -
SPIO c b spfSPI open channel at baud b with flags spiOpen
SPIC hSPI close handle spiClose
SPIR h numSPI read bytes from handle spiRead
SPIW h bvsSPI write bytes to handle spiWrite
SPIX h bvsSPI transfer bytes to handle spiXfer
SPI BIT BANG -
BSPIO cs miso mosi sclk b spfOpen bit bang SPI bbSPIOpen
BSPIC csClose bit bang SPI bbSPIClose
BSPIX cs bvsSPI bit bang transfer bbSPIXfer
FILES -
FO file modeOpen a file in mode fileOpen
FC hClose file handle fileClose
FR h numRead bytes from file handle fileRead
FW h bvsWrite bytes to file handle fileWrite
FS h num fromSeek to file handle position fileSeek
FL pat numList files which match pattern fileList
WAVES -
WVCLRClear all waveforms gpioWaveClear
WVNEWInitialise a new waveform gpioWaveAddNew
WVAG tripsAdd generic pulses to waveform gpioWaveAddGeneric
WVAS u b db sb o bvsAdd serial data to waveform gpioWaveAddSerial
WVCRECreate a waveform gpioWaveCreate
WVCAPCreate a waveform of fixed size gpioWaveCreatePad
WVDEL widDelete selected waveform gpioWaveDelete
WVTX widTransmits waveform once gpioWaveTxSend
WVTXM wid wmdeTransmits waveform using mode gpioWaveTxSend
WVTXR widTransmits waveform repeatedly gpioWaveTxSend
WVCHA bvsTransmits a chain of waveforms gpioWaveChain
WVTATReturns the current transmitting waveform gpioWaveTxAt
WVBSYCheck if waveform is being transmitted gpioWaveTxBusy
WVHLTStop waveform gpioWaveTxStop
WVSC wsGet waveform DMA CB stats gpioWaveGetCbs
WVSM wsGet waveform time stats gpioWaveGetMicros
WVSP wsGet waveform pulse stats gpioWaveGetPulses
UTILITIES -
H/HELPDisplay command help
HWVERGet hardware version gpioHardwareRevision
MICS vMicroseconds delay gpioDelay
MILS vMilliseconds delay gpioDelay
PIGPVGet pigpio library version gpioVersion
T/TICKGet current tick gpioTick
CONFIGURATION -
CGIConfiguration get internals gpioCfgGetInternals
CSI vConfiguration set internals gpioCfgSetInternals

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. -

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. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o 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. -

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: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

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 read GPIO 0-31 (bank 1) and returns the levels as a -32-bit hexadecimal value. -

Example

$ pigs br1
1001C1CF

BR2 - - Read bank 2 GPIO

This command read 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 (sets high) 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 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

This command sets (sets high) 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 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

This command performs a BSC I2C/SPI slave transfer as defined by -bctl with data bvs. -

This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

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, followed by any data bytes -read from the BSC receive FIFO. -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

For I2C use a control word of (I2C address << 16) + 0x305. -

E.g. to talk as I2C slave with address 0x13 use 0x130305. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

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. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit 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 -opened with BSPIO. -

The set of GPIO is specifed by cs. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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 command starts bit banging SPI on a group of GPIO with slave -select cs, MISO miso, MOSI mosi, and clock sclk. -

Data will be transferred at baud b bits per second (which may -be set in the range 50-250000). -

The flags spf may be used to modify the default behaviour of -mode 0, active low chip select. -

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
 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 (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. -

Upon success 0 is returned. On error a negative status code -will be returned. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

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. It returns the same -number of bytes read from the device. -

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 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

This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. -

CF2 - uvs - Custom function 2

This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. -

CGI - - Configuration get internals

This command returns the value of the internal library -configuration settings. -

CSI - v - Configuration set internals

This command sets the value of the internal library -configuration settings to v. -

EVM - h bits - Set events to monitor

This command starts event reporting 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 reports for each 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

This command triggers event event. -

One event, number 31, is predefined. This event is -auto generated on BSC slave activity. -

Example

$ pigs evt 12
$ pigs evt 5

$ pigs evt 32
-143
ERROR: bad event id

FC - h - Close file handle

This command closes a file handle h previously opened with FO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs fc 0 # First close okay.

$ pigs fc 0 # Second fails.
-25
ERROR: unknown handle

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. The -level is then reported. Level changes of less than stdy -microseconds are ignored. -

The filter only affects callbacks (including pipe notifications). -

The R/READ, BR1, and BR2 commands are not affected. -

Note, each (stable) edge will be timestamped stdy microseconds -after it was first detected. -

Example

$ pigs fg 4 250

$ pigs fg 4 1000000
-125
ERROR: bad filter parameter

FL - pat num - List files which match pattern

This command returns a list of the files matching pat. Up -to num bytes may be returned. -

Upon success the count of returned bytes followed by the matching -files is returned. On error a negative status code will be returned. -

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 are ignored until a level which has -been stable for stdy microseconds is detected. Level -changes on the GPIO are then reported for actv microseconds -after which the process repeats. -

The filter only affects callbacks (including pipe notifications). -

The R/READ, BR1, and BR2 commands are not affected. -

Note, level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

Example

$ pigs fn 7 250 1000

$ pigs fn 7 2500000 1000
-125
ERROR: bad filter parameter

FO - file mode - Open a file in mode

This function 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 -will be returned. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


The following values may be or'd into the mode. -

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

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

This command 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 will be returned. -

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

This command 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 backwards. The move start -position is determined by from as follows. -

From
0start
1current position
2end


Upon success the new byte position within the file (>=0) is -returned. On error a negative status code will be returned. -

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

This command writes bytes bvs to the file -associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs fw 0 23 45 67 89

GDC - u - Get GPIO PWM dutycycle

This command returns the PWM dutycycle in use on GPIO u. -

Upon success the dutycycle is returned. On error a negative -status code will be returned. -

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

This command returns the servo pulsewidth in use on GPIO u. -

Upon success the servo pulsewidth is returned. On error a negative -status code will be returned. -

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

This command displays a brief list of the commands and their parameters. -

Example

$ pigs h

$ pigs help

HC - g cf - Set hardware clock frequency

This command sets the hardware clock associated with GPIO g to -frequency cf. Frequencies above 30MHz are unlikely to work. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

The GPIO must be one of the following. -

4clock 0All models
5clock 1All models but A and B (reserved for system use)
6clock 2All models but A and B
20clock 0All models but A and B
21clock 1All models but A and B Rev.2 (reserved for system use)


32clock 0Compute module only
34clock 0Compute module only
42clock 1Compute module only (reserved for system use)
43clock 2Compute module only
44clock 1Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. -

HP - g pf pdc - Set hardware PWM frequency and dutycycle

This command sets the hardware PWM associated with GPIO g to -frequency pf with dutycycle pdc. Frequencies above 30MHz -are unlikely to work. -

NOTE: Any waveform started by WVTX, WVTXR, or WVCHA -will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

Upon success nothing is returned. On error a negative status code -will be returned. -

$ 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


The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12PWM channel 0All models but A and B
13PWM channel 1All models but A and B
18PWM channel 0All models
19PWM channel 1All models but A and B


40PWM channel 0Compute module only
41PWM channel 1Compute module only
45PWM channel 1Compute module only
52PWM channel 0Compute module only
53PWM channel 1Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/pf (375M/pf for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a pf of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. pdc is -automatically scaled to take this into account. -

HWVER - - Get hardware version

This command returns the hardware revision of the Pi. -

The hardware revision is found in the last 4 characters on the revision -line of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid hexadecimal -number the command returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see g). -

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

This command closes an I2C handle h previously opened with I2CO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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 command returns a handle to access device id on I2C bus ib. -The device is opened with flags if. -

Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


No flags are currently defined. The parameter if should be 0. -

Upon success the next free handle (>=0) is returned. On error a -negative status code will be returned. -

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

This command writes wv to register r of the I2C device -associated with handle h and returns a 16-bit word read from the -device. -

Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. -

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

This command writes the data bytes bvs to register r of the I2C device -associated with handle h and returns a device specific number of 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 i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0

I2CRB - h r - smb Read Byte Data: read byte from register

This command returns a single byte read from register r of the I2C device -associated with handle h. -

Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crb 0 0
6

I2CRD - h num - i2c Read device

This command returns num bytes read from the I2C 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. -

This command operates on the raw I2C device. The maximum value of the -parameter num is dependent on the I2C drivers and the device -itself. pigs imposes a limit of 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

This command returns num bytes from register r of the I2C 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. -

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

This command returns between 1 and 32 bytes read from register r of -the I2C 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. -

The number of bytes of returned data is specific to the device and -register. -

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

This command returns a single byte read from the I2C device -associated with handle h. -

Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crs 0
0

I2CRW - h r - smb Read Word Data: read word from register

This command returns a single 16 bit word read from register r of -the I2C device associated with handle h. -

Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crw 0 0
6150

I2CWB - h r bv - smb Write Byte Data: write byte to register

This command writes a single byte bv to register r of the -I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwb 0 10 0x54

I2CWD - h bvs - i2c Write device

This command writes a block of bytes bvs to the I2C device -associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

The number of bytes which may be written in one transaction is -dependent on the I2C drivers and the device itself. pigs imposes -a limit of about 500 bytes. -

This command operates on the raw I2C device. -

Example

$ pigs i2cwd 0 0x01 0x02 0x03 0x04

I2CWI - h r bvs - smb Write I2C Block Data

This command writes between 1 and 32 bytes bvs to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwi 0 4 0x01 0x04 0xc0

I2CWK - h r bvs - smb Write Block Data: write data to register

This command writes between 1 and 32 bytes bvs to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

pigs i2cwk 0 4 0x01 0x04 0xc0

I2CWQ - h bit - smb Write Quick: write bit

This command writes a single bit to the I2C device associated -with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwq 0 1

I2CWS - h bv - smb Write Byte: write byte

This command writes a single byte bv to the I2C device associated -with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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

This command writes a single 16 bit word wv to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cww 0 0 0xffff

I2CZ - h bvs - Performs multiple I2C transactions

This command executes a sequence of 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: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle h. -The flags default to 0. The address and flags maintain their -previous value until updated. -

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/MODES - g m - Set GPIO mode

This command sets GPIO g to mode m, typically input (read) -or output (write). -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345


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. -

Value01234567
ModeInputOutputALT5ALT4ALT0ALT1ALT2ALT3


Example

$ pigs mg 4
1

MICS - v - Microseconds delay

This command delays execution for v microseconds. -

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. -

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. -

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. -

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. -

PadGPIO
00-27
128-45
246-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. -

PadGPIO
00-27
128-45
246-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. -

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. -

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

       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


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). -

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. -

Upon success the script status and parameters are returned. -On error a negative status code will be returned. -

The script status may be one of -

0being initialised
1halted
2running
3waiting
4failed


See Scripts. -

Example

$ pigs procp 0
1 0 0 0 0 0 0 0 0 0 0

PROCR - sid pars - Run script

This command runs stored script sid passing it up to 10 optional -parameters. -

Upon success nothing is returned. 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 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

This command stops a running script sid. -

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

This command sets the parameters of a stored script sid passing -it up to 10 parameters. -

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 used by GPIO u. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

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 command sets the dutycycle range v to be used for GPIO u. -Subsequent uses of command P/PWM will use a dutycycle between 0 (off) -and v (fully on). -

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 will be scaled to -reflect the new range. -

The real range, the number of steps between fully off and fully on -for each frequency, is given in the following table. -

#1#2#3#4#5#6#7#8#9
2550100125200250400500625
#10#11#12#13#14#15#16#17#18
8001000125020002500400050001000020000


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

This command 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 may 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

This 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

This command 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 may be 0 (off), 500 (most anti-clockwise) -to 2500 (most clockwise). -

The range supported by servos varies and should probably be determined -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. -

You can DAMAGE a servo if you command it to move beyond its limits. -

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

This command closes a serial handle h 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

This command 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). 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

This command 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. -

Example

$ pigs sero /dev/ttyAMA0 9600 0
0

$ pigs sero /dev/tty1 38400 0
1

SERR - h num - Read bytes from serial handle

This command 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

This command 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

This command 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

This command 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 command 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. -

The returned exit status is normally 256 times that set -by the shell script exit function. If the script can't -be found 32512 will be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


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 "\"hello string with spaces world\""
256

# non-existent script
$ pigs shell scr78 par1
32512

SLR - u num - Read bit bang serial data from GPIO

This command 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. -

The GPIO u should have been initialised with the SLRO command. -

The bytes returned for each character depend upon the number of -data bits db 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

This command 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

This command 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

This command 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 may be between 50 and 250000 bits per second. -

The received data is held in a cyclic buffer. -

It is the user's responsibility to read the data (with SLR) -in a timely fashion. -

Example

$ pigs slro 23 19200 8

$ pigs slro 23 19200 8
-50
ERROR: GPIO already in use

SPIC - h - SPI close handle

This command closes the SPI handle h returned by a prior -call to SPIO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

Data will be transferred at b bits per second. The flags spf -may be used to modify the default behaviour of 4-wire operation, -mode 0, active low chip select. -

Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps -are unlikely to work. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


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. -

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. -

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. -

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. -

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. -

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

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. -

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. -

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. -

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. -

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. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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 \
   ${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

WVCLR - - Clear all waveforms

This command clears all waveforms. -

Nothing is returned. -

Example

$ pigs wvclr

WVCRE - - Create a waveform

This command creates a waveform from the data provided by the prior -calls to the WVAG and WVAS commands. -

Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. -

The data provided by the WVAG and WVAS commands is -consumed by this command. -

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 -

Step 1. WVCLR to clear all waveforms and added data. -

Step 2. WVAG/WVAS calls to supply the waveform data. -

Step 3. WVCRE to create the waveform and get a unique id. -

Repeat steps 2 and 3 as needed. -

Step 4. WVTX or WVTXR with the id of the waveform to transmit. -

A waveform comprises of one or more pulses. -

A pulse specifies -

1) the GPIO to be switched on at the start of the pulse.
-2) the GPIO to be switched off at the start of the pulse.
-3) the delay in microseconds before the next pulse. -

Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). -

When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. -

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

WVCAP - - 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 total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. -

Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. -

The data provided by the WVAG and WVAS commands are -consumed by this command. -

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 -

Step 1. WVCLR to clear all waveforms and added data. -

Step 2. WVAG/WVAS calls to supply the waveform data. -

Step 3. WVCAP to create a waveform of a uniform size. -

Step 4. WVTX or WVTXR with the id of the waveform to transmit. -

Repeat steps 2 - 4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

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

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

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. -

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

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. -

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), or 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. -

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. -

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

-

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. -

From
0start
1current position
2end

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. -

0123456789101112131415
Type 1XX--X--XXXXX--XX
Type 2--XXX--XXXXX--XX
Type 3XXXXXXXXXXXXXX
16171819202122232425262728293031
Type 1-XX--XXXXX------
Type 2-XX---XXXX-XXXXX
Type 3XXXXXXXXXXXX----


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. -

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345
Value01456732

miso - GPIO (0-31)

-The GPIO used for the MISO signal when bit banging SPI. -

mode - file open mode

-One of the following values. -

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


The following values can be or'd into the mode. -

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The 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 DownOffPull DownPull Up
Command CharacterODU


There is no mechanism to read the pull up down state. -

pad - 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-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. -

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 onGPIO offdelay
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

-Scripts are programs to be stored and executed by the pigpio daemon. -They are intended to mitigate any performance problems associated with -the pigpio daemon server/client model. -

Example

A trivial example might be useful. Suppose you want to toggle a GPIO -on and off as fast as possible. -

From the command line you could write -

for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done


Timing that you will see it takes about 14 seconds, or roughly -70 toggles per second. -

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. -

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. -

Let's time the script running. -

Again, ignore the details for now. -

time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
 do sleep 0.2; done)


The script takes roughly 12 seconds to complete, or 800,000 toggles per second. -

That is the advantage of a stored script. -

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 ]];\
 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. -

Virtual machine

A script runs within a virtual machine with -

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. -

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: -

CommandDescriptionDefinition
ADD xAdd x to accumulatorA+=x; F=A
AND xAnd x with accumulatorA&=x; F=A
CALL LCall subroutine at tag Lpush(PC+1); PC=L
CMP xCompare x with accumulatorF=A-x
DCR yDecrement register--*y; F=*y
DCRADecrement accumulator--A; F=A
DIV xDivide x into accumulatorA/=x; F=A
EVTWTWait for an event to occurA=wait(x); F=A
HALTHaltHalt
INR yIncrement register++*y; F=*y
INRAIncrement accumulator++A; F=A
JM LJump if minus to tag Lif (F<0) PC=L
JMP LJump to tag LPC=L
JNZ LJump if non-zero to tag Lif (F) PC=L
JP LJump if positive to tag Lif (F>=0) PC=L
JZ LJump if zero to tag Lif (!F) PC=L
LD y xLoad register with x*y=x
LDA xLoad accumulator with xA=x
MLT xMultiply x with accumulatorA*=x; F=A
MOD xModulus x with accumulatorA%=x; F=A
OR xOr x with accumulatorA|=x; F=A
POP yPop registery=pop()
POPAPop accumulatorA=pop()
PUSH yPush registerpush(y)
PUSHAPush accumulatorpush(A)
RETReturn from subroutinePC=pop()
RL y xRotate left register x bits*y<<=x; F=*y
RLA xRotate left accumulator x bitsA<<=x; F=A
RR y xRotate right register x bits*y>>=x; F=*y
RRA xRotate right accumulator x bitsA>>=x; F=A
STA yStore accumulator in registery=A
SUB xSubtract x from accumulatorA-=x; F=A
SYS strRun external script (/opt/pigpio/cgi/str)system(str); F=A
TAG LLabel the current script positionN/A
WAIT xWait for a GPIO in x to change stateA=wait(x); F=A
X y1 y2Exchange contents of registers y1 and y2t=*y1;*y1=*y2;*y2=t
XA yExchange contents of accumulator and registert=A;A=*y;*y=t
XOR xXor x with accumulatorA^=x; F=A


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. -

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/piscope.html b/DOC/HTML/piscope.html deleted file mode 100644 index 9236731..0000000 --- a/DOC/HTML/piscope.html +++ /dev/null @@ -1,269 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

piscope

-

Introduction

-piscope is a logic analyser (digital -waveform viewer) for the Raspberry.  It shows the state (high -or low) of selected GPIO in real-time.
-
-See video.
-
-piscope uses the services of the pigpio library.  pigpio needs to be running on -the Pi whose GPIO are to be monitored.
-
-The pigpio library may be started as a daemon (background process) -by the following command.
-
-sudo pigpiod

-piscope may be invoked in several different ways
-
- - - - - - - - - - - - - - - - - - - - - - - -
Pi
pi_host ~ $ piscope -&
Pi captures -data
-Pi processes data
-Pi displays data
Pi plus Linux PC
-
-(with the
-display on a remote
-  Linux PC)
remote_host ~ $ ssh -X pi_host
pi_host ~ $ piscope -&
Pi captures data
-Pi processes data
-Remote Linux PC displays data
Pi plus Windows PC
-
-(with the
-display on a remote
-  Windows PC)
You need to install an SSH -client (putty suggested) and a X11 server (xming suggested).
-
-Run Program Files -> Xming -> XLaunch and accept the -defaults.
-
-Run putty and enter the Pi's host name or IP address.  Click -on SSH X11 and tick Enable X11 forwarding and then select -Open.

-
pi_host ~ $ piscope -&
Pi captures data
-Pi processes data
-Remote Windows PC displays data
Pi plus Linux PC
-
-(with the display and processing on a remote Linux -PC)
remote_host ~ $ export -PIGPIO_ADDR=pi_host
-remote_host ~ $ piscope -&
Pi captures data
-Remote processes data
-Remote displays data
-
-piscope operates in one of three modes
-
- - - - - - - - - - - - - - - - - - -
Live
The latest GPIO samples are -displayed.
-
-The mode will automatically change to Pause if a sampling trigger -is detected.
-
-There are four triggers.  Each trigger is made up of a -combination of GPIO states (one of don't care, low, high, edge, -falling, or rising per GPIO).  Triggers are always -counted.  In addition a trigger may be sample to, sample -around, or sample from, a so called sampling trigger.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full the oldest samples are discarded.
Play
Recorded GPIO samples are -displayed.
-
-The play speed may be varied between 64 times real-time to 1/32768 -of real-time.
-
-The page up key increases the play speed by a factor of 2.  -The page down key decreases the play speed by a factor of 2.  -The home key sets the play speed to 1X.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full new samples are discarded.
Pause
Recorded GPIO samples are -displayed.
-
-The left and right cursor keys move the blue marker to the previous -or next edge.  By default all GPIO edges are considered.  -Clicking on a GPIO name will limit edge searches to the highlighted -GPIO only.
-
-The left and right square bracket keys move the blue marker to the -previous or next trigger.
-
-The time between the blue and gold markers is displayed.  The -gold marker is set to the blue marker by a press of the 'g' -key.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full new samples are discarded.
-
-In all modes the down and up cursor keys zoom the time scale in and -out.
-
-Samples can be saved with File Save All Samples or File Save -Selected Samples. -

To select samples enter pause mode. Press 1 to specify the start -of the samples (green marker) and 2 to specify the end of the -samples (red marker).

-

The samples may be saved in the native piscope format or in VCD -format.

-

Data saved in VCD format may be viewed and further processed -with GTKWave.

-

Data saved in the native piscope format may be restored later -with File Restore Saved Data.

-

Installation

-

To download and install piscope.

-

Pi (pre-built image)

-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make hf
-make install

-

Linux 64 bit X86/AMD (pre-built image)

-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make x86_64
-make install
-

All machines (building from source)

-You only need to perform this step if you want to build the -executable from the source files.  This is not needed if you -use a pre-built image.
-
-WARNING
: Installing gtk+-3.0 uses a lot of SD card -space.
-
-Most of the space used by gtk+-3.0 is taken up by unneeded *-dbg -packages.
-
-With *-dbg packages an additional 3753MB SD space is required.
-
-If you edit the list of packages to be downloaded and remove the -*-dbg packages only 134MB of additional SD space is needed (as at -the time of writing).
-
-#
# *** This may take a lot of time and use -a lot of SD card space ***
#
-sudo apt-get install gtk+-3.0
#
-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make
-make install

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/python.html b/DOC/HTML/python.html deleted file mode 100644 index f6b5f22..0000000 --- a/DOC/HTML/python.html +++ /dev/null @@ -1,1294 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Python Interface

pigpio is a Python module for the Raspberry which talks to -the pigpio daemon to allow control of the general purpose -input outputs (GPIO). -

Features

o the pigpio Python module can run on Windows, Macs, or Linux -

o controls one or more Pi's -

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o creating and transmitting precisely timed waveforms -

o reading/writing GPIO and setting their modes -

o wrappers for I2C, SPI, and serial links -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

Transmitted waveforms are accurate to a microsecond. -

Callback level changes are time-stamped and will be -accurate to within a few microseconds. -

Settings

A number of settings are determined when the pigpio daemon is started. -

o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). -

o the set of GPIO which may be updated (generally written to). The - default set is those available on the Pi board revision. -

o the available PWM frequencies (see set_PWM_frequency). -

Exceptions

By default a fatal exception is raised if you pass an invalid -argument to a pigpio function. -

If you wish to handle the returned status yourself you should set -pigpio.exceptions to False. -

You may prefer to check the returned status in only a few parts -of your code. In that case do the following: -

Example

pigpio.exceptions = False

# Code where you want to test the error status.

pigpio.exceptions = True

Usage

This module uses the services of the C pigpio library. pigpio -must be running on the Pi(s) whose GPIO are to be manipulated. -

The normal way to start pigpio is as a daemon (during system -start). -

sudo pigpiod -

Your Python program must import pigpio and create one or more -instances of the pigpio.pi class. This class gives access to -a specified Pi's GPIO. -

Example

pi1 = pigpio.pi()       # pi1 accesses the local Pi's GPIO
pi2 = pigpio.pi('tom')  # pi2 accesses tom's GPIO
pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO

pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4)     # get level of dick's GPIO 4


The later example code snippets assume that pi is an instance of -the pigpio.pi class. -

OVERVIEW

ESSENTIAL -
pigpio.pi Initialise Pi connection -
stop Stop a Pi connection -
BASIC -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
read Read a GPIO -
write Write a GPIO -
PWM (overrides servo commands on same GPIO) -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
set_PWM_frequency Set PWM frequency of a GPIO -
set_PWM_range Configure PWM range of a GPIO -
get_PWM_dutycycle Get PWM dutycycle set on a GPIO -
get_PWM_frequency Get PWM frequency of a GPIO -
get_PWM_range Get configured PWM range of a GPIO -
get_PWM_real_range Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
set_servo_pulsewidth Start/Stop servo pulses on a GPIO -
get_servo_pulsewidth Get servo pulsewidth set on a GPIO -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO -
set_watchdog Set a watchdog on a GPIO -
read_bank_1 Read all bank 1 GPIO -
read_bank_2 Read all bank 2 GPIO -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
callback Create GPIO level change callback -
wait_for_edge Wait for GPIO level change -
ADVANCED -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
set_pad_strength Sets a pads drive strength -
get_pad_strength Gets a pads drive strength -
shell Executes a shell command -
Custom -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
Events -
event_callback Sets a callback for an event -
event_trigger Triggers an event -
wait_for_event Wait for an event -
Scripts -
store_script Store a script -
run_script Run a stored script -
update_script Set a scripts parameters -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick SMBus write quick -
i2c_read_byte SMBus read byte -
i2c_write_byte SMBus write byte -
i2c_read_byte_data SMBus read byte data -
i2c_write_byte_data SMBus write byte data -
i2c_read_word_data SMBus read word data -
i2c_write_word_data SMBus write word data -
i2c_read_block_data SMBus read block data -
i2c_write_block_data SMBus write block data -
i2c_read_i2c_block_data SMBus read I2C block data -
i2c_write_i2c_block_data SMBus write I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_process_call SMBus process call -
i2c_block_process_call SMBus block process call -
i2c_zip Performs multiple I2C transactions -
I2C BIT BANG -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs multiple bit banged I2C transactions -
I2C/SPI SLAVE -
bsc_xfer I2C/SPI as slave transfer -
bsc_i2c I2C as slave transfer -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read Reads bytes from a serial device -
serial_write Writes bytes to a serial device -
serial_data_available Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
bb_serial_read_open Open a GPIO for bit bang serial reads -
bb_serial_read_close Close a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
bb_serial_read Read bit bang serial data from a GPIO -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SPI BIT BANG -
bb_spi_open Opens GPIO for bit banging SPI -
bb_spi_close Closes GPIO for bit banging SPI -
bb_spi_xfer Transfers bytes with bit banging SPI -
FILES -
file_open Opens a file -
file_close Closes a file -
file_read Reads bytes from a file -
file_write Writes bytes to a file -
file_seek Seeks to a position within a file -
file_list List files which match a pattern -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_create_and_pad Creates a waveform of fixed size from added data -
wave_delete Deletes a waveform -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_send_using_mode Transmits a waveform in the chosen mode -
wave_chain Transmits a chain of waveforms -
wave_tx_at Returns the current transmitting waveform -
wave_tx_busy Checks to see if a waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_cbs Length in cbs of the current waveform -
wave_get_max_cbs Absolute maximum allowed cbs -
wave_get_micros Length in microseconds of the current waveform -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_max_pulses Absolute maximum allowed pulses -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpio.error_text Gets error text from error number -
pigpio.tickDiff Returns difference between two ticks -

class pi -

pigpio.pi(host, port, show_errors)

-Grants access to a Pi's GPIO. -

Parameters

host:= the host name of the Pi on which the pigpio daemon is
       running.  The default is localhost unless overridden by
       the PIGPIO_ADDR environment variable.


Parameters

port:= the port number on which the pigpio daemon is listening.
       The default is 8888 unless overridden by the PIGPIO_PORT
       environment variable.  The pigpio daemon must have been
       started with the same port number.


This connects to the pigpio daemon and reserves resources -to be used for sending commands and receiving notifications. -

An instance attribute connected may be used to check the -success of the connection. If the connection is established -successfully connected will be True, otherwise False. -

Example

pi = pigio.pi()              # use defaults
pi = pigpio.pi('mypi')       # specify host, default port
pi = pigpio.pi('mypi', 7777) # specify host and port

pi = pigpio.pi()             # exit script if no connection
if not pi.connected:
   exit()

__repr__()

-

bb_i2c_close(SDA)

-This function stops bit banging I2C on a pair of GPIO -previously opened with bb_i2c_open. -

Parameters

SDA:= 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

Example

pi.bb_i2c_close(SDA)

bb_i2c_open(SDA, SCL, baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50 -o repeated starts -o clock stretching -o I2C on any pair of spare GPIO -

Parameters

 SDA:= 0-31
 SCL:= 0-31
baud:= 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. -As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

Example

h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps

bb_i2c_zip(SDA, data)

-This function executes a sequence of bit banged I2C operations. -The operations to be performed are specified by the contents -of data which contains the concatenated command codes and -associated data. -

Parameters

 SDA:= 0-31 (as used in a prior call to bb_i2c_open)
data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.bb_i2c_zip(
                   SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0])


The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

Any read I2C data is concatenated in the returned bytearray. -

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

bb_serial_invert(user_gpio, invert)

-Invert serial logic. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)
    invert:= 0-1 (1 invert, 0 normal)


Example

status = pi.bb_serial_invert(17, 1)

bb_serial_read(user_gpio)

-Returns data from the bit bang serial cyclic buffer. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

The bytes returned for each character depend upon the number of -data bits bb_bits specified in the bb_serial_read_open -command. -

For bb_bits 1-8 there will be one byte per character. -For bb_bits 9-16 there will be two bytes per character. -For bb_bits 17-32 there will be four bytes per character. -

Example

(count, data) = pi.bb_serial_read(4)

bb_serial_read_close(user_gpio)

-Closes a GPIO for bit bang reading of serial data. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


Example

status = pi.bb_serial_read_close(17)

bb_serial_read_open(user_gpio, baud, bb_bits)

-Opens a GPIO for bit bang reading of serial data. -

Parameters

user_gpio:= 0-31, the GPIO to use.
     baud:= 50-250000, the baud rate.
  bb_bits:= 1-32, the number of bits per word, default 8.


The serial data is held in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic -buffer in a timely fashion. -

Example

status = pi.bb_serial_read_open(4, 19200)
status = pi.bb_serial_read_open(17, 9600)

bb_spi_close(CS)

-This function stops bit banging SPI on a set of GPIO -opened with bb_spi_open. -

Parameters

CS:= 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

Example

pi.bb_spi_close(CS)

bb_spi_open(CS, MISO, MOSI, SCLK, baud, spi_flags)

-This function selects a set of GPIO for bit banging SPI at a -specified baud rate. -

Parameters

      CS := 0-31
    MISO := 0-31
    MOSI := 0-31
    SCLK := 0-31
    baud := 50-250000
spiFlags := see below


spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0     0    0
 1     0    1
 2     1    0
 3     1    1


The following constants may be used to set the mode: -

pigpio.SPI_MODE_0
pigpio.SPI_MODE_1
pigpio.SPI_MODE_2
pigpio.SPI_MODE_3


Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA -may be used. -

p is 0 if CS is active low (default) and 1 for active high. -pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag. -

T is 1 if the least significant bit is transmitted on MOSI first, -the default (0) shifts the most significant bit out first. -pigpio.SPI_TX_LSBFIRST may be used to set this flag. -

R is 1 if the least significant bit is received on MISO first, -the default (0) receives the most significant bit first. -pigpio.SPI_RX_LSBFIRST may be used to set this flag. -

The other bits in spiFlags should be set to zero. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2

bb_spi_xfer(CS, data)

-This function executes a bit banged SPI transfer. -

Parameters

  CS:= 0-31 (as used in a prior call to bb_spi_open)
data:= data to be sent


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

#!/usr/bin/env python

import pigpio

CE0=5
CE1=6
MISO=13
MOSI=19
SCLK=12

pi = pigpio.pi()
if not pi.connected:
   exit()

pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC
pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC

for i in range(256):

   count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value

   if count == 2:

      count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC

      if count == 2:

         set_val = data[1]

         count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC

         if count == 3:

            read_val = ((data[1]&3)<<8) | data[2]

            print("{} {}".format(set_val, read_val))

pi.bb_spi_close(CE0)
pi.bb_spi_close(CE1)

pi.stop()

bsc_i2c(i2c_address, data)

-This function allows the Pi to act as a slave I2C device. -

This function is not available on the BCM2711 (e.g. as -used in the Pi4B). -

The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. -

Parameters

i2c_address:= the I2C slave address.
       data:= the data bytes to transmit.


The returned value is a tuple of the status, the number -of bytes read, and a bytearray containing the read bytes. -

See bsc_xfer for details of the status value. -

If there was an error the status will be less than zero -(and will contain the error code). -

Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. -

This example assumes GPIO 2/3 are connected to GPIO 18/19 -(GPIO 10/11 on the BCM2711). -

Example

#!/usr/bin/env python
import time
import pigpio

I2C_ADDR=0x13

def i2c(id, tick):
    global pi

    s, b, d = pi.bsc_i2c(I2C_ADDR)
    if b:
        if d[0] == ord('t'): # 116 send 'HH:MM:SS*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[11:19]))

        elif d[0] == ord('d'): # 100 send 'Sun Oct 30*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[:10]))

pi = pigpio.pi()

if not pi.connected:
    exit()

# Respond to BSC slave activity

e = pi.event_callback(pigpio.EVENT_BSC, i2c)

pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave

time.sleep(600)

e.cancel()

pi.bsc_i2c(0) # Disable BSC peripheral

pi.stop()


While running the above. -

$ i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

$ pigs i2co 1 0x13 0
0

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:13:58*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:14:29*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:23:16*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

bsc_xfer(bsc_control, data)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

Parameters

bsc_control:= see below
       data:= the data bytes to place in the transmit FIFO.


The returned value is a tuple of the status (see below), -the number of bytes read, and a bytearray containing the -read bytes. If there was an error the status will be less -than zero (and will contain the error code). -

Note that the control word sets the BSC mode. The BSC will -stay in that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

bsc_control consists of the following bits: -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable BSC peripheral


The status has the following format: -

20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 S  S  S  S  S  R  R  R  R  R  T  T  T  T  T RB TE RF TF RE TB


Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


Example

(status, count, data) = pi.bsc_xfer(0x330305, "Hello!")

callback(user_gpio, edge, func)

-Calls a user supplied function (a callback) whenever the -specified GPIO edge is detected. -

Parameters

user_gpio:= 0-31.
     edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.
     func:= user supplied callback function.


The user supplied callback receives three parameters, the GPIO, -the level, and the tick. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


If a user callback is not specified a default tally callback is -provided which simply counts edges. The count may be retrieved -by calling the tally function. The count may be reset to zero -by calling the reset_tally function. -

The callback may be cancelled by calling the cancel function. -

A GPIO may have multiple callbacks (although I can't think of -a reason to do so). -

The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. -

The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use read. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

Example

def cbf(gpio, level, tick):
   print(gpio, level, tick)

cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf)

cb2 = pi.callback(4, pigpio.EITHER_EDGE)

cb3 = pi.callback(17)

print(cb3.tally())

cb3.reset_tally()

cb1.cancel() # To cancel callback cb1.

clear_bank_1(bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.clear_bank_1(int("111110010000",2))

clear_bank_2(bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.clear_bank_2(0x1010)

custom_1(arg1, arg2, argx)

-Calls a pigpio function customised by the user. -

Parameters

arg1:= >=0, default 0.
arg2:= >=0, default 0.
argx:= extra arguments (each 0-255), default empty.


The returned value is an integer which by convention -should be >=0 for OK and <0 for error. -

Example

value = pi.custom_1()

value = pi.custom_1(23)

value = pi.custom_1(0, 55)

value = pi.custom_1(23, 56, [1, 5, 7])

value = pi.custom_1(23, 56, b"hello")

value = pi.custom_1(23, 56, "hello")

custom_2(arg1, argx, retMax)

-Calls a pigpio function customised by the user. -

Parameters

  arg1:= >=0, default 0.
  argx:= extra arguments (each 0-255), default empty.
retMax:= >=0, maximum number of bytes to return, default 8192.


The returned value is a tuple of the number of bytes -returned and a bytearray containing the bytes. If -there was an error the number of bytes read will be -less than zero (and will contain the error code). -

Example

(count, data) = pi.custom_2()

(count, data) = pi.custom_2(23)

(count, data) = pi.custom_2(23, [1, 5, 7])

(count, data) = pi.custom_2(23, b"hello")

(count, data) = pi.custom_2(23, "hello", 128)

delete_script(script_id)

-Deletes a stored script. -

Parameters

script_id:= id of stored script.


Example

status = pi.delete_script(sid)

event_callback(event, func)

-Calls a user supplied function (a callback) whenever the -specified event is signalled. -

Parameters

event:= 0-31.
 func:= user supplied callback function.


The user supplied callback receives two parameters, the event id, -and the tick. -

If a user callback is not specified a default tally callback is -provided which simply counts events. The count may be retrieved -by calling the tally function. The count may be reset to zero -by calling the reset_tally function. -

The callback may be cancelled by calling the event_cancel function. -

An event may have multiple callbacks (although I can't think of -a reason to do so). -

Example

def cbf(event, tick):
   print(event, tick)

cb1 = pi.event_callback(22, cbf)

cb2 = pi.event_callback(4)

print(cb2.tally())

cb2.reset_tally()

cb1.event_cancel() # To cancel callback cb1.

event_trigger(event)

-This function signals the occurrence of an event. -

Parameters

event:= 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an -interest in the event (e.g. by calling event_callback) will -be informed by a callback. -

One event, EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

Example

pi.event_trigger(23)

file_close(handle)

-Closes the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).


Example

pi.file_close(handle)

file_list(fpattern)

-Returns a list of files which match a pattern. -

Parameters

fpattern:= file pattern to match.


Returns the number of returned bytes if OK, otherwise -PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The -pattern may contain wildcards. See file_open. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

# Assumes /opt/pigpio/access contains the following line:
# /ram/*.c r

c, d = pi.file_list("/ram/p*.c")
if c > 0:
   print(d)

pi.stop()

file_open(file_name, file_mode)

-This function returns a handle to a file opened in a specified mode. -

Parameters

file_name:= the file to open.
file_mode:= the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, -PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE, -PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

Example

h = pi.file_open("/home/pi/shared/dir_3/file.txt",
        pigpio.FILE_WRITE | pigpio.FILE_CREATE)

pi.file_write(h, "Hello world")

pi.file_close(h)


File -

A file may only be opened if permission is granted by an entry -in /opt/pigpio/access. This is intended to allow remote access -to files in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries: -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files -may be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access: -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values: -

ConstantValueMeaning
FILE_READ1open file for reading
FILE_WRITE2open file for writing
FILE_RW3open file for reading and writing


The following values may be or'd into the mode: -

NameValueMeaning
FILE_APPEND4All writes append data to the end of the file
FILE_CREATE8The file is created if it doesn't exist
FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner -read and write. -

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

# Assumes /opt/pigpio/access contains the following line:
# /ram/*.c r

handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ)

done = False

while not done:
   c, d = pi.file_read(handle, 60000)
   if c > 0:
      print(d)
   else:
      done = True

pi.file_close(handle)

pi.stop()

file_read(handle, count)

-Reads up to count bytes from the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.file_read(h2, 100)
if b > 0:
   # process read data

file_seek(handle, seek_offset, seek_from)

-Seeks to a position relative to the start, current position, -or end of the file. Returns the new position. -

Parameters

     handle:= >=0 (as returned by a prior call to file_open).
seek_offset:= byte offset.
  seek_from:= FROM_START, FROM_CURRENT, or FROM_END.


Example

new_pos = pi.file_seek(h, 100, pigpio.FROM_START)

cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT)

file_size = pi.file_seek(h, 0, pigpio.FROM_END)

file_write(handle, data)

-Writes the data bytes to the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).
  data:= the bytes to write.


Example

pi.file_write(h1, b'\x02\x03\x04')

pi.file_write(h2, b'help')

pi.file_write(h2, "hello")

pi.file_write(h1, [2, 3, 4])

get_PWM_dutycycle(user_gpio)

-Returns the PWM dutycycle being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the PWM dutycycle. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported -dutycycle will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

Example

pi.set_PWM_dutycycle(4, 25)
print(pi.get_PWM_dutycycle(4))
25

pi.set_PWM_dutycycle(4, 203)
print(pi.get_PWM_dutycycle(4))
203

get_PWM_frequency(user_gpio)

-Returns the frequency of PWM being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the frequency (in Hz) used for the GPIO. -

For normal PWM the frequency will be that defined for the GPIO -by set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_frequency(4))
800

get_PWM_range(user_gpio)

-Returns the range of PWM values being used on the GPIO. -

Parameters

user_gpio:= 0-31.


If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). -

Example

pi.set_PWM_range(9, 500)
print(pi.get_PWM_range(9))
500

get_PWM_real_range(user_gpio)

-Returns the real (underlying) range of PWM values being -used on the GPIO. -

Parameters

user_gpio:= 0-31.


If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

Example

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_real_range(4))
250

get_current_tick()

-Returns the current system tick. -

Tick is the number of microseconds since system boot. As an -unsigned 32 bit quantity tick wraps around approximately -every 71.6 minutes. -

Example

t1 = pi.get_current_tick()
time.sleep(1)
t2 = pi.get_current_tick()

get_hardware_revision()

-Returns the Pi's hardware revision number. -

The hardware revision is the last few characters on the -Revision line of /proc/cpuinfo. -

The revision number can be used to determine the assignment -of GPIO to pins (see
gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

Example

print(pi.get_hardware_revision())
2

get_mode(gpio)

-Returns the GPIO mode. -

Parameters

gpio:= 0-53.


Returns a value as follows -

0 = INPUT
1 = OUTPUT
2 = ALT5
3 = ALT4
4 = ALT0
5 = ALT1
6 = ALT2
7 = ALT3


Example

print(pi.get_mode(0))
4

get_pad_strength(pad)

-This function returns the pad drive strength in mA. -

Parameters

pad:= 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = pi.get_pad_strength(0) # Get pad 0 strength.

get_pigpio_version()

-Returns the pigpio software version. -

Example

v = pi.get_pigpio_version()

get_servo_pulsewidth(user_gpio)

-Returns the servo pulsewidth being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the servo pulsewidth. -

Example

pi.set_servo_pulsewidth(4, 525)
print(pi.get_servo_pulsewidth(4))
525

pi.set_servo_pulsewidth(4, 2130)
print(pi.get_servo_pulsewidth(4))
2130

gpio_trigger(user_gpio, pulse_len, level)

-Send a trigger pulse to a GPIO. The GPIO is set to -level for pulse_len microseconds and then reset to not level. -

Parameters

user_gpio:= 0-31
pulse_len:= 1-100
    level:= 0-1


Example

pi.gpio_trigger(23, 10, 1)

hardware_PWM(gpio, PWMfreq, PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency -and dutycycle. Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_once, -wave_send_repeat, or wave_chain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. -The main clock defaults to PCM but may be overridden when the -pigpio daemon is started (option -t). -

Parameters

   gpio:= see descripton
PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711).
PWMduty:= 0 (off) to 1000000 (1M)(fully on).


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. -

The same PWM channel is available on multiple GPIO. -The latest frequency and dutycycle setting will be used -by all GPIO which share a PWM channel. -

The GPIO must be one of the following: -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps -for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 -(375 for the BCM2711). Lower frequencies will have more -steps and higher frequencies will have fewer steps. -PWMduty is automatically scaled to take this into account. -

Example

pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle

pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle

hardware_clock(gpio, clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

Parameters

   gpio:= see description
clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following: -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. -

Example

pi.hardware_clock(4, 5000) # 5 KHz clock on GPIO 4

pi.hardware_clock(4, 40000000) # 40 MHz clock on GPIO 4

i2c_block_process_call(handle, reg, data)

-Writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


The SMBus 2.0 documentation states that a minimum of 1 byte may -be sent and a minimum of 1 byte may be received. The total -number of bytes sent/received must be 32 or less. -

SMBus 2.0 5.5.8 - Block write-block read. -S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A]
   S Addr Rd [A] [Count] A [Data] ... A P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00')

(b, d) = pi.i2c_block_process_call(h, 10, b'abcdr')

(b, d) = pi.i2c_block_process_call(h, 10, "abracad")

(b, d) = pi.i2c_block_process_call(h, 10, [2, 5, 16])

i2c_close(handle)

-Closes the I2C device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).


Example

pi.i2c_close(h)

i2c_open(i2c_bus, i2c_address, i2c_flags)

-Returns a handle (>=0) for the device at the I2C bus address. -

Parameters

    i2c_bus:= >=0.
i2c_address:= 0-0x7F.
  i2c_flags:= 0, no flags are currently defined.


Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


For the SMBus commands the low level transactions are shown -at the end of the function description. The following -abbreviations are used: -

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.
Addr  (7 bits): I2C 7 bit address.
reg   (8 bits): Command byte, which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.


Example

h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1

i2c_process_call(handle, reg, word_val)

-Writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.6 - Process call. -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

r = pi.i2c_process_call(h, 4, 0x1231)
r = pi.i2c_process_call(h, 6, 0)

i2c_read_block_data(handle, reg)

-Reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.7 - Block read. -S Addr Wr [A] reg [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P


The amount of returned data is set by the device. -

The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_read_block_data(h, 10)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_byte(handle)

-Reads a single byte from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).


SMBus 2.0 5.5.3 - Receive byte. -S Addr Rd [A] [Data] NA P


Example

b = pi.i2c_read_byte(2) # read a byte from device 2

i2c_read_byte_data(handle, reg)

-Reads a single byte from the specified register of the device -associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read byte. -S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P


Example

# read byte from reg 17 of device 2
b = pi.i2c_read_byte_data(2, 17)

# read byte from reg  1 of device 0
b = pi.i2c_read_byte_data(0, 1)

i2c_read_device(handle, count)

-Returns count bytes read from the raw device associated -with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
 count:= >0, the number of bytes to read.


S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.i2c_read_device(h, 12)

i2c_read_i2c_block_data(handle, reg, count)

-Reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
 count:= >0, the number of bytes to read.


S Addr Wr [A] reg [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_read_i2c_block_data(h, 4, 32)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_word_data(handle, reg)

-Reads a single 16 bit word from the specified register of the -device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read word. -S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

# read word from reg 2 of device 3
w = pi.i2c_read_word_data(3, 2)

# read word from reg 7 of device 2
w = pi.i2c_read_word_data(2, 7)

i2c_write_block_data(handle, reg, data)

-Writes up to 32 bytes to the specified register of the device -associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


SMBus 2.0 5.5.7 - Block write. -S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A]
   datan [A] P


Example

pi.i2c_write_block_data(4, 5, b'hello')

pi.i2c_write_block_data(4, 5, "data bytes")

pi.i2c_write_block_data(5, 0, b'\x00\x01\x22')

pi.i2c_write_block_data(6, 2, [0, 1, 0x22])

i2c_write_byte(handle, byte_val)

-Sends a single byte to the device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.2 - Send byte. -S Addr Wr [A] byte_val [A] P


Example

pi.i2c_write_byte(1, 17)   # send byte   17 to device 1
pi.i2c_write_byte(2, 0x23) # send byte 0x23 to device 2

i2c_write_byte_data(handle, reg, byte_val)

-Writes a single byte to the specified register of the device -associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.4 - Write byte. -S Addr Wr [A] reg [A] byte_val [A] P


Example

# send byte 0xC5 to reg 2 of device 1
pi.i2c_write_byte_data(1, 2, 0xC5)

# send byte 9 to reg 4 of device 2
pi.i2c_write_byte_data(2, 4, 9)

i2c_write_device(handle, data)

-Writes the data bytes to the raw device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the bytes to write.


S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P


Example

pi.i2c_write_device(h, b"\x12\x34\xA8")

pi.i2c_write_device(h, b"help")

pi.i2c_write_device(h, 'help')

pi.i2c_write_device(h, [23, 56, 231])

i2c_write_i2c_block_data(handle, reg, data)

-Writes data bytes to the specified register of the device -associated with handle . 1-32 bytes may be written. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P


Example

pi.i2c_write_i2c_block_data(4, 5, 'hello')

pi.i2c_write_i2c_block_data(4, 5, b'hello')

pi.i2c_write_i2c_block_data(5, 0, b'\x00\x01\x22')

pi.i2c_write_i2c_block_data(6, 2, [0, 1, 0x22])

i2c_write_quick(handle, bit)

-Sends a single bit to the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   bit:= 0 or 1, the value to write.


SMBus 2.0 5.5.1 - Quick command. -S Addr bit [A] P


Example

pi.i2c_write_quick(0, 1) # send 1 to device 0
pi.i2c_write_quick(3, 0) # send 0 to device 3

i2c_write_word_data(handle, reg, word_val)

-Writes a single 16 bit word to the specified register of the -device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.4 - Write word. -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P


Example

# send word 0xA0C5 to reg 5 of device 4
pi.i2c_write_word_data(4, 5, 0xA0C5)

# send word 2 to reg 2 of device 5
pi.i2c_write_word_data(5, 2, 23)

i2c_zip(handle, data)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of data -which contains the concatenated command codes and associated data. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0])


The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

Any read I2C data is concatenated in the returned bytearray. -

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

notify_begin(handle, bits)

-Starts notifications on a handle. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)
  bits:= a 32 bit mask indicating the GPIO to be notified.


The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

The following code starts notifications for GPIO 1, 4, -6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_close(handle)

-Stops notifications on a handle and releases the handle for reuse. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)


Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_close(h)
   ...

notify_open()

-Returns a notification handle (>=0). -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this -function serves no purpose if you are using Python from a -remote machine. The in-built (socket) notifications -provided by
callback should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -

E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

Notifications have the following structure: -

H seqno
H flags
I tick
I level


seqno: starts at 0 each time the handle is opened and then -increments by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the -flags indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep -alive signal on the pipe/socket and is sent once a minute -in the absence of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the -flags indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps -around after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set -then GPIO x is high. -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_pause(handle)

-Pauses notifications on a handle. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)


Notifications for the handle are suspended until -notify_begin is called again. -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_pause(h)
   ...
   pi.notify_begin(h, 1234)
   ...

read(gpio)

-Returns the GPIO level. -

Parameters

gpio:= 0-53.


Example

pi.set_mode(23, pigpio.INPUT)

pi.set_pull_up_down(23, pigpio.PUD_DOWN)
print(pi.read(23))
0

pi.set_pull_up_down(23, pigpio.PUD_UP)
print(pi.read(23))
1

read_bank_1()

-Returns the levels of the bank 1 GPIO (GPIO 0-31). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is high. GPIO n has bit value (1<<n). -

Example

print(bin(pi.read_bank_1()))
0b10010100000011100100001001111

read_bank_2()

-Returns the levels of the bank 2 GPIO (GPIO 32-53). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is high. GPIO n has bit value (1<<(n-32)). -

Example

print(bin(pi.read_bank_2()))
0b1111110000000000000000

run_script(script_id, params)

-Runs a stored script. -

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.run_script(sid, [par1, par2])

s = pi.run_script(sid)

s = pi.run_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

script_status(script_id)

-Returns the run status of a stored script as well as the -current values of parameters 0 to 9. -

Parameters

script_id:= id of stored script.


The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The return value is a tuple of run status and a list of -the 10 parameters. On error the run status will be negative -and the parameter list will be empty. -

Example

(s, pars) = pi.script_status(sid)

serial_close(handle)

-Closes the serial device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


Example

pi.serial_close(h1)

serial_data_available(handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


Example

rdy = pi.serial_data_available(h1)

if rdy > 0:
   (b, d) = pi.serial_read(h1, rdy)

serial_open(tty, baud, ser_flags)

-Returns a handle for the serial tty device opened -at baud bits per second. The device name must start -with /dev/tty or /dev/serial. -

Parameters

      tty:= the serial device to open.
     baud:= baud rate in bits per second, see below.
ser_flags:= 0, no flags are currently defined.


Normally you would only use the serial_* functions if -you are or will be connecting to the Pi over a network. If -you will always run on the local Pi use the standard serial -module instead. -

The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. -

Example

h1 = pi.serial_open("/dev/ttyAMA0", 300)

h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0)

h3 = pi.serial_open("/dev/serial0", 9600)

serial_read(handle, count)

-Reads up to count bytes from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
 count:= >0, the number of bytes to read (defaults to 1000).


The returned value is a tuple of the number of bytes read and -a bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

If no data is ready a bytes read of zero is returned. -Example

(b, d) = pi.serial_read(h2, 100)
if b > 0:
   # process read data

serial_read_byte(handle)

-Returns a single byte from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


If no data is ready a negative error code will be returned. -

Example

b = pi.serial_read_byte(h1)

serial_write(handle, data)

-Writes the data bytes to the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
  data:= the bytes to write.


Example

pi.serial_write(h1, b'\x02\x03\x04')

pi.serial_write(h2, b'help')

pi.serial_write(h2, "hello")

pi.serial_write(h1, [2, 3, 4])

serial_write_byte(handle, byte_val)

-Writes a single byte to the device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to serial_open).
byte_val:= 0-255, the value to write.


Example

pi.serial_write_byte(h1, 23)

pi.serial_write_byte(h1, ord('Z'))

set_PWM_dutycycle(user_gpio, dutycycle)

-Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. -

Parameters

user_gpio:= 0-31.
dutycycle:= 0-range (range defaults to 255).


The set_PWM_range function can change the default range of 255. -

Example

pi.set_PWM_dutycycle(4,   0) # PWM off
pi.set_PWM_dutycycle(4,  64) # PWM 1/4 on
pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on
pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on
pi.set_PWM_dutycycle(4, 255) # PWM full on

set_PWM_frequency(user_gpio, frequency)

-Sets the frequency (in Hz) of the PWM to be used on the GPIO. -

Parameters

user_gpio:= 0-31.
frequency:= >=0 Hz


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4,100000)
print(pi.get_PWM_frequency(4))
8000

set_PWM_range(user_gpio, range_)

-Sets the range of PWM values to be used on the GPIO. -

Parameters

user_gpio:= 0-31.
   range_:= 25-40000.


Example

pi.set_PWM_range(9, 100)  # now  25 1/4,   50 1/2,   75 3/4 on
pi.set_PWM_range(9, 500)  # now 125 1/4,  250 1/2,  375 3/4 on
pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on

set_bank_1(bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.set_bank_1(int("111110010000",2))

set_bank_2(bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.set_bank_2(0x303)

set_glitch_filter(user_gpio, steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

Parameters

user_gpio:= 0-31
   steady:= 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback and wait_for_edge. -

It does not affect levels read by read, -read_bank_1, or read_bank_2. -

Each (stable) edge will be timestamped steady -microseconds after it was first detected. -

Example

pi.set_glitch_filter(23, 100)

set_mode(gpio, mode)

-Sets the GPIO mode. -

Parameters

gpio:= 0-53.
mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5.


Example

pi.set_mode( 4, pigpio.INPUT)  # GPIO  4 as input
pi.set_mode(17, pigpio.OUTPUT) # GPIO 17 as output
pi.set_mode(24, pigpio.ALT2)   # GPIO 24 as ALT2

set_noise_filter(user_gpio, steady, active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level -changes on the GPIO are then reported for active -microseconds after which the process repeats. -

Parameters

user_gpio:= 0-31
   steady:= 0-300000
   active:= 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback and wait_for_edge. -

It does not affect levels read by read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

Example

pi.set_noise_filter(23, 1000, 5000)

set_pad_strength(pad, pad_strength)

-This function sets the pad drive strength in mA. -

Parameters

         pad:= 0-2, the pad to set.
pad_strength:= 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA.

set_pull_up_down(gpio, pud)

-Sets or clears the internal GPIO pull-up/down resistor. -

Parameters

gpio:= 0-53.
 pud:= PUD_UP, PUD_DOWN, PUD_OFF.


Example

pi.set_pull_up_down(17, pigpio.PUD_OFF)
pi.set_pull_up_down(23, pigpio.PUD_UP)
pi.set_pull_up_down(24, pigpio.PUD_DOWN)

set_servo_pulsewidth(user_gpio, pulsewidth)

-Starts (500-2500) or stops (0) servo pulses on the GPIO. -

Parameters

 user_gpio:= 0-31.
pulsewidth:= 0 (off),
             500 (most anti-clockwise) - 2500 (most clockwise).


The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably -be determined by experiment. A value of 1500 should always be -safe and represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its -limits. -

Example

pi.set_servo_pulsewidth(17, 0)    # off
pi.set_servo_pulsewidth(17, 1000) # safe anti-clockwise
pi.set_servo_pulsewidth(17, 1500) # centre
pi.set_servo_pulsewidth(17, 2000) # safe clockwise

set_watchdog(user_gpio, wdog_timeout)

-Sets a watchdog timeout for a GPIO. -

Parameters

   user_gpio:= 0-31.
wdog_timeout:= 0-60000.


The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO -will be triggered every timeout interval after the last -GPIO activity. -

The callback will receive the special level TIMEOUT. -

Example

pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23
pi.set_watchdog(23, 0)    # cancel watchdog on GPIO 23

shell(shellscr, pstring)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

Parameters

shellscr:= the name of the script, only alphanumerics,
              '-' and '_' are allowed in the name
pstring := the parameter string to pass to the script


The exit status of the system call is returned if OK, -otherwise PI_BAD_SHELL_STATUS. -

shellscr must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by -the shell script exit function. If the script can't be -found 32512 will be returned. -

The following table gives some example returned statuses: -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = pi.shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = pi.shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = pi.shell("scr1", "\"hello string with spaces world\"");

spi_close(handle)

-Closes the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).


Example

pi.spi_close(h)

spi_open(spi_channel, baud, spi_flags)

-Returns a handle for the SPI device on the channel. Data -will be transferred at baud bits per second. The flags -may be used to modify the default behaviour of 4-wire -operation, mode 0, active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


Parameters

spi_channel:= 0-1 (0-2 for the auxiliary SPI).
       baud:= 32K-125M (values above 30M are unlikely to work).
  spi_flags:= see below.


spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

WARNING: modes 1 and 3 do not appear to work on -the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per character. -For bits 9-16 there will be two bytes per character. -For bits 17-32 there will be four bytes per character. -

Multi-byte transfers are made in least significant byte -first order. -

E.g. to transfer 32 11-bit words data should -contain 64 bytes. -

E.g. to transfer the 14 bit value 0x1ABC send the -bytes 0xBC followed by 0x1A. -

The other bits in flags should be set to zero. -

Example

# open SPI device on channel 1 in mode 3 at 50000 bits per second

h = pi.spi_open(1, 50000, 3)

spi_read(handle, count)

-Reads count bytes from the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.spi_read(h, 60) # read 60 bytes from device h
if b == 60:
   # process read data
else:
   # error path

spi_write(handle, data)

-Writes the data bytes to the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


Example

pi.spi_write(0, b'\x02\xc0\x80') # write 3 bytes to device 0

pi.spi_write(0, b'defgh')        # write 5 bytes to device 0

pi.spi_write(0, "def")           # write 3 bytes to device 0

pi.spi_write(1, [2, 192, 128])   # write 3 bytes to device 1

spi_xfer(handle, data)

-Writes the data bytes to the SPI device associated with handle, -returning the data bytes read from the device. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00')

(count, rx_data) = pi.spi_xfer(h, [1, 128, 0])

(count, rx_data) = pi.spi_xfer(h, b"hello")

(count, rx_data) = pi.spi_xfer(h, "hello")

stop()

-Release pigpio resources. -

Example

pi.stop()

stop_script(script_id)

-Stops a running script. -

Parameters

script_id:= id of stored script.


Example

status = pi.stop_script(sid)

store_script(script)

-Store a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for -details. -

Parameters

script:= the script text as a series of bytes.


Returns a >=0 script id if OK. -

Example

sid = pi.store_script(
   b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0')

update_script(script_id, params)

-Sets the parameters of a script. The script may or -may not be running. The first parameters of the script are -overwritten with the new values. -

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.update_script(sid, [par1, par2])

s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

wait_for_edge(user_gpio, edge, wait_timeout)

-Wait for an edge event on a GPIO. -

Parameters

   user_gpio:= 0-31.
        edge:= EITHER_EDGE, RISING_EDGE (default), or
               FALLING_EDGE.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the edge is detected or after -the number of seconds specified by timeout has expired. -

Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a callback function. -

The function returns True if the edge is detected, -otherwise False. -

Example

if pi.wait_for_edge(23):
   print("Rising edge detected")
else:
   print("wait for edge timed out")

if pi.wait_for_edge(23, pigpio.FALLING_EDGE, 5.0):
   print("Falling edge detected")
else:
   print("wait for falling edge timed out")

wait_for_event(event, wait_timeout)

-Wait for an event. -

Parameters

       event:= 0-31.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the event is signalled or after -the number of seconds specified by timeout has expired. -

The function returns True if the event is detected, -otherwise False. -

Example

if pi.wait_for_event(23):
   print("event detected")
else:
   print("wait for event timed out")

wave_add_generic(pulses)

-Adds a list of pulses to the current waveform. -

Parameters

pulses:= list of pulses to add to the waveform.


Returns the new total number of pulses in the current waveform. -

The pulses are interleaved in time order within the existing -waveform (if any). -

Merging allows the waveform to be built in parts, that is the -settings for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within -the existing waveform then the first pulse should consist -solely of a delay. -

Example

G1=4
G2=24

pi.set_mode(G1, pigpio.OUTPUT)
pi.set_mode(G2, pigpio.OUTPUT)

flash_500=[] # flash every 500 ms
flash_100=[] # flash every 100 ms

#                              ON     OFF  DELAY

flash_500.append(pigpio.pulse(1<<G1, 1<<G2, 500000))
flash_500.append(pigpio.pulse(1<<G2, 1<<G1, 500000))

flash_100.append(pigpio.pulse(1<<G1, 1<<G2, 100000))
flash_100.append(pigpio.pulse(1<<G2, 1<<G1, 100000))

pi.wave_clear() # clear any existing waveforms

pi.wave_add_generic(flash_500) # 500 ms flashes
f500 = pi.wave_create() # create and save id

pi.wave_add_generic(flash_100) # 100 ms flashes
f100 = pi.wave_create() # create and save id

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_send_repeat(f100)

time.sleep(4)

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_tx_stop() # stop waveform

pi.wave_clear() # clear all waveforms

wave_add_new()

-Starts a new empty waveform. -

You would not normally need to call this function as it is -automatically called after a waveform is created with the -
wave_create function. -

Example

pi.wave_add_new()

wave_add_serial(user_gpio, baud, data, offset, bb_bits, bb_stop)

-Adds a waveform representing serial data to the existing -waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

Parameters

user_gpio:= GPIO to transmit data.  You must set the GPIO mode
            to output.
     baud:= 50-1000000 bits per second.
     data:= the bytes to write.
   offset:= number of microseconds from the start of the
            waveform, default 0.
  bb_bits:= number of data bits, default 8.
  bb_stop:= number of stop half bits, default 2.


Returns the new total number of pulses in the current waveform. -

The serial data is formatted as one start bit, bb_bits -data bits, and bb_stop/2 stop bits. -

It is legal to add serial data streams with different baud -rates to the same waveform. -

The bytes required for each character depend upon bb_bits. -

For bb_bits 1-8 there will be one byte per character. -For bb_bits 9-16 there will be two bytes per character. -For bb_bits 17-32 there will be four bytes per character. -

Example

pi.wave_add_serial(4, 300, 'Hello world')

pi.wave_add_serial(4, 300, b"Hello world")

pi.wave_add_serial(4, 300, b'\x23\x01\x00\x45')

pi.wave_add_serial(17, 38400, [23, 128, 234], 5000)

wave_chain(data)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM -will be cancelled. -

The waves to be transmitted are specified by the contents -of data which contains an ordered list of wave_ids -and optional command codes and related data. -

Returns 0 if OK, otherwise PI_CHAIN_NESTING, -PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, -PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, -or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave -may occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by -using the loop commands. The block is bracketed by loop -start and end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#!/usr/bin/env python

import time
import pigpio

WAVES=5
GPIO=4

wid=[0]*WAVES

pi = pigpio.pi() # Connect to local Pi.

pi.set_mode(GPIO, pigpio.OUTPUT);

for i in range(WAVES):
   pi.wave_add_generic([
      pigpio.pulse(1<<GPIO, 0, 20),
      pigpio.pulse(0, 1<<GPIO, (i+1)*200)]);

   wid[i] = pi.wave_create();

pi.wave_chain([
   wid[4], wid[3], wid[2],       # transmit waves 4+3+2
   255, 0,                       # loop start
      wid[0], wid[0], wid[0],    # transmit waves 0+0+0
      255, 0,                    # loop start
         wid[0], wid[1],         # transmit waves 0+1
         255, 2, 0x88, 0x13,     # delay 5000us
      255, 1, 30, 0,             # loop end (repeat 30 times)
      255, 0,                    # loop start
         wid[2], wid[3], wid[0], # transmit waves 2+3+0
         wid[3], wid[1], wid[2], # transmit waves 3+1+2
      255, 1, 10, 0,             # loop end (repeat 10 times)
   255, 1, 5, 0,                 # loop end (repeat 5 times)
   wid[4], wid[4], wid[4],       # transmit waves 4+4+4
   255, 2, 0x20, 0x4E,           # delay 20000us
   wid[0], wid[0], wid[0],       # transmit waves 0+0+0
   ])

while pi.wave_tx_busy():
   time.sleep(0.1);

for i in range(WAVES):
   pi.wave_delete(wid[i])

pi.stop()

wave_clear()

-Clears all waveforms and any data added by calls to the -wave_add_* functions. -

Example

pi.wave_clear()

wave_create()

-Creates a waveform from the data provided by the prior calls -to the wave_add_* functions. -

Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the wave_add_* functions is consumed by -this function. -

As many waveforms may be created as there is space available. -The wave id is passed to wave_send_* to specify the waveform -to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. -

A pulse specifies -

1) the GPIO to be switched on at the start of the pulse. -2) the GPIO to be switched off at the start of the pulse. -3) the delay in microseconds before the next pulse. -

Any or all the fields can be zero. It doesn't make any sense -to set all the fields to zero (the pulse will be ignored). -

When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. -

Example

wid = pi.wave_create()

wave_create_and_pad(percent)

-This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use -(in terms of the theoretical maximum, not the current amount free). -This allows the reuse of deleted waves while a transmission is active. -

Upon success a wave id greater than or equal to 0 is returned, otherwise -PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

A usage would be the creation of two waves where one is filled while the -other is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Normal usage: -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create_and_pad to create a waveform of uniform size. -

Step 4. wave_send_* with the id of the waveform to transmit. -

Repeat steps 2-4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

Example

wid = pi.wave_create_and_pad(50)

wave_delete(wave_id)

-This function deletes the waveform with id wave_id. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Example

pi.wave_delete(6) # delete waveform with id 6

pi.wave_delete(0) # delete waveform with id 0

wave_get_cbs()

-Returns the length in DMA control blocks of the current -waveform. -

Example

cbs = pi.wave_get_cbs()

wave_get_max_cbs()

-Returns the maximum possible size of a waveform in DMA -control blocks. -

Example

cbs = pi.wave_get_max_cbs()

wave_get_max_micros()

-Returns the maximum possible size of a waveform in microseconds. -

Example

micros = pi.wave_get_max_micros()

wave_get_max_pulses()

-Returns the maximum possible size of a waveform in pulses. -

Example

pulses = pi.wave_get_max_pulses()

wave_get_micros()

-Returns the length in microseconds of the current waveform. -

Example

micros = pi.wave_get_micros()

wave_get_pulses()

-Returns the length in pulses of the current waveform. -

Example

pulses = pi.wave_get_pulses()

wave_send_once(wave_id)

-Transmits the waveform with id wave_id. The waveform is sent -once. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_once(wid)

wave_send_repeat(wave_id)

-Transmits the waveform with id wave_id. The waveform repeats -until wave_tx_stop is called or another call to wave_send_* -is made. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_repeat(wid)

wave_send_using_mode(wave_id, mode)

-Transmits the waveform with id wave_id using mode mode. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).
   mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT,
          WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC.


WAVE_MODE_ONE_SHOT: same as wave_send_once. -

WAVE_MODE_REPEAT same as wave_send_repeat. -

WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries -to sync with the previous waveform. -

WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries -to sync with the previous waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC)

wave_tx_at()

-Returns the id of the waveform currently being -transmitted. -

Returns the waveform id or one of the following special -values: -

WAVE_NOT_FOUND (9998) - transmitted wave not found. -NO_TX_WAVE (9999) - no wave being transmitted. -

Example

wid = pi.wave_tx_at()

wave_tx_busy()

-Returns 1 if a waveform is currently being transmitted, -otherwise 0. -

Example

pi.wave_send_once(0) # send first waveform

while pi.wave_tx_busy(): # wait for waveform to be sent
   time.sleep(0.1)

pi.wave_send_once(1) # send next waveform

wave_tx_repeat()

-This function is deprecated and has beeen removed. -

Use
wave_create/wave_send_* instead. -

wave_tx_start()

-This function is deprecated and has been removed. -

Use
wave_create/wave_send_* instead. -

wave_tx_stop()

-Stops the transmission of the current waveform. -

This function is intended to stop a waveform started with -wave_send_repeat. -

Example

pi.wave_send_repeat(3)

time.sleep(5)

pi.wave_tx_stop()

write(gpio, level)

-Sets the GPIO level. -

Parameters

 GPIO:= 0-53.
level:= 0, 1.


If PWM or servo pulses are active on the GPIO they are -switched off. -

Example

pi.set_mode(17, pigpio.OUTPUT)

pi.write(17,0)
print(pi.read(17))
0

pi.write(17,1)
print(pi.read(17))
1

class pulse -

pigpio.pulse(gpio_on, gpio_off, delay)

-Initialises a pulse. -

Parameters

 gpio_on:= the GPIO to switch on at the start of the pulse.
gpio_off:= the GPIO to switch off at the start of the pulse.
   delay:= the delay in microseconds before the next pulse.

FUNCTIONS

pigpio.error_text(errnum)

-Returns a text description of a pigpio error. -

Parameters

errnum:= <0, the error number


Example

print(pigpio.error_text(-5))
level not 0-1

pigpio.tickDiff(t1, t2)

-Returns the microsecond difference between two ticks. -

Parameters

t1:= the earlier tick
t2:= the later tick


Example

print(pigpio.tickDiff(4294967272, 12))
36

pigpio.u2i(uint32)

-Converts a 32 bit unsigned number to signed. -

Parameters

uint32:= an unsigned 32 bit number


Example

print(u2i(4294967272))
-24
print(u2i(37))
37

PARAMETERS

active: 0-1000000

The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

arg1:

An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2:

An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argx:

An array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud:

The speed of serial communication (I2C, SPI, serial link, waves) -in bits per second. -

bb_bits: 1-32

The number of data bits to be used when adding serial data to a -waveform. -

bb_stop: 2-8

The number of (half) stop bits to be used when adding serial data -to a waveform. -

bit: 0-1

A value of 0 or 1. -

bits: 32 bit number

A mask used to select GPIO to be operated on. If bit n is set -then GPIO n is selected. A convenient way of setting bit n is to -bit or in the value (1<<n). -

To select GPIO 1, 7, 23 -

bits = (1<<1) | (1<<7) | (1<<23) -

bsc_control:

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) -

Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document. -

byte_val: 0-255

A whole number. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

The hardware clock frequency. -

connected:

True if a connection was established, False otherwise. -

count:

The number of bytes of data to be transferred. -

CS:

The GPIO used for the slave select signal when bit banging SPI. -

data:

Data to be transmitted, a series of bytes. -

delay: >=1

The length of a pulse in microseconds. -

dutycycle: 0-range_

A number between 0 and range_. -

The dutycycle sets the proportion of time on versus time off during each -PWM cycle. -

DutycycleOn time
0Off
range_ * 0.2525% On
range_ * 0.5050% On
range_ * 0.7575% On
range_Fully On

edge: 0-2

EITHER_EDGE = 2
FALLING_EDGE = 1
RISING_EDGE = 0

errnum: <0

PI_BAD_USER_GPIO = -2
PI_BAD_GPIO = -3
PI_BAD_MODE = -4
PI_BAD_LEVEL = -5
PI_BAD_PUD = -6
PI_BAD_PULSEWIDTH = -7
PI_BAD_DUTYCYCLE = -8
PI_BAD_WDOG_TIMEOUT = -15
PI_BAD_DUTYRANGE = -21
PI_NO_HANDLE = -24
PI_BAD_HANDLE = -25
PI_BAD_WAVE_BAUD = -35
PI_TOO_MANY_PULSES = -36
PI_TOO_MANY_CHARS = -37
PI_NOT_SERIAL_GPIO = -38
PI_NOT_PERMITTED = -41
PI_SOME_PERMITTED = -42
PI_BAD_WVSC_COMMND = -43
PI_BAD_WVSM_COMMND = -44
PI_BAD_WVSP_COMMND = -45
PI_BAD_PULSELEN = -46
PI_BAD_SCRIPT = -47
PI_BAD_SCRIPT_ID = -48
PI_BAD_SER_OFFSET = -49
PI_GPIO_IN_USE = -50
PI_BAD_SERIAL_COUNT = -51
PI_BAD_PARAM_NUM = -52
PI_DUP_TAG = -53
PI_TOO_MANY_TAGS = -54
PI_BAD_SCRIPT_CMD = -55
PI_BAD_VAR_NUM = -56
PI_NO_SCRIPT_ROOM = -57
PI_NO_MEMORY = -58
PI_SOCK_READ_FAILED = -59
PI_SOCK_WRIT_FAILED = -60
PI_TOO_MANY_PARAM = -61
PI_SCRIPT_NOT_READY = -62
PI_BAD_TAG = -63
PI_BAD_MICS_DELAY = -64
PI_BAD_MILS_DELAY = -65
PI_BAD_WAVE_ID = -66
PI_TOO_MANY_CBS = -67
PI_TOO_MANY_OOL = -68
PI_EMPTY_WAVEFORM = -69
PI_NO_WAVEFORM_ID = -70
PI_I2C_OPEN_FAILED = -71
PI_SER_OPEN_FAILED = -72
PI_SPI_OPEN_FAILED = -73
PI_BAD_I2C_BUS = -74
PI_BAD_I2C_ADDR = -75
PI_BAD_SPI_CHANNEL = -76
PI_BAD_FLAGS = -77
PI_BAD_SPI_SPEED = -78
PI_BAD_SER_DEVICE = -79
PI_BAD_SER_SPEED = -80
PI_BAD_PARAM = -81
PI_I2C_WRITE_FAILED = -82
PI_I2C_READ_FAILED = -83
PI_BAD_SPI_COUNT = -84
PI_SER_WRITE_FAILED = -85
PI_SER_READ_FAILED = -86
PI_SER_READ_NO_DATA = -87
PI_UNKNOWN_COMMAND = -88
PI_SPI_XFER_FAILED = -89
PI_NO_AUX_SPI = -91
PI_NOT_PWM_GPIO = -92
PI_NOT_SERVO_GPIO = -93
PI_NOT_HCLK_GPIO = -94
PI_NOT_HPWM_GPIO = -95
PI_BAD_HPWM_FREQ = -96
PI_BAD_HPWM_DUTY = -97
PI_BAD_HCLK_FREQ = -98
PI_BAD_HCLK_PASS = -99
PI_HPWM_ILLEGAL = -100
PI_BAD_DATABITS = -101
PI_BAD_STOPBITS = -102
PI_MSG_TOOBIG = -103
PI_BAD_MALLOC_MODE = -104
PI_BAD_SMBUS_CMD = -107
PI_NOT_I2C_GPIO = -108
PI_BAD_I2C_WLEN = -109
PI_BAD_I2C_RLEN = -110
PI_BAD_I2C_CMD = -111
PI_BAD_I2C_BAUD = -112
PI_CHAIN_LOOP_CNT = -113
PI_BAD_CHAIN_LOOP = -114
PI_CHAIN_COUNTER = -115
PI_BAD_CHAIN_CMD = -116
PI_BAD_CHAIN_DELAY = -117
PI_CHAIN_NESTING = -118
PI_CHAIN_TOO_BIG = -119
PI_DEPRECATED = -120
PI_BAD_SER_INVERT = -121
PI_BAD_FOREVER = -124
PI_BAD_FILTER = -125
PI_BAD_PAD = -126
PI_BAD_STRENGTH = -127
PI_FIL_OPEN_FAILED = -128
PI_BAD_FILE_MODE = -129
PI_BAD_FILE_FLAG = -130
PI_BAD_FILE_READ = -131
PI_BAD_FILE_WRITE = -132
PI_FILE_NOT_ROPEN = -133
PI_FILE_NOT_WOPEN = -134
PI_BAD_FILE_SEEK = -135
PI_NO_FILE_MATCH = -136
PI_NO_FILE_ACCESS = -137
PI_FILE_IS_A_DIR = -138
PI_BAD_SHELL_STATUS = -139
PI_BAD_SCRIPT_NAME = -140
PI_BAD_SPI_BAUD = -141
PI_NOT_SPI_GPIO = -142
PI_BAD_EVENT_ID = -143
PI_CMD_INTERRUPTED = -144
PI_NOT_ON_BCM2711   = -145
PI_ONLY_ON_BCM2711  = -146

event: 0-31

An event is a signal used to inform one or more consumers -to start an action. -

file_mode:

The mode may have the following values -

FILE_READ   1
FILE_WRITE  2
FILE_RW     3


The following values can be or'd into the file open mode -

FILE_APPEND 4
FILE_CREATE 8
FILE_TRUNC  16

file_name:

A full file path. To be accessible the path must match -an entry in /opt/pigpio/access. -

fpattern:

A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: 0-40000

Defines the frequency to be used for PWM on a GPIO. -The closest permitted frequency will be used. -

func:

A user supplied callback function. -

gpio: 0-53

A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. -

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 get_hardware_revision. -

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  -  -  -  -

gpio_off:

A mask used to select GPIO to be operated on. See bits. -

This mask selects the GPIO to be switched off at the start -of a pulse. -

gpio_on:

A mask used to select GPIO to be operated on. See bits. -

This mask selects the GPIO to be switched on at the start -of a pulse. -

handle: >=0

A number referencing an object opened by one of the following -

file_open -i2c_open -notify_open -serial_open -spi_open -

host:

The name or IP address of the Pi running the pigpio daemon. -

i2c_address: 0-0x7F

The address of a device on the I2C bus. -

i2c_bus: >=0

An I2C bus number. -

i2c_flags: 0

No I2C flags are currently defined. -

invert: 0-1

A flag used to set normal or inverted bit bang serial data -level logic. -

level: 0-1 (2)

CLEAR = 0
HIGH = 1
LOW = 0
OFF = 0
ON = 1
SET = 1
TIMEOUT = 2 # only returned for a watchdog timeout

MISO:

The GPIO used for the MISO signal when bit banging SPI. -

mode:

1.The operational mode of a GPIO, normally INPUT or OUTPUT. -

ALT0 = 4
ALT1 = 5
ALT2 = 6
ALT3 = 7
ALT4 = 3
ALT5 = 2
INPUT = 0
OUTPUT = 1


2. The mode of waveform transmission. -

WAVE_MODE_ONE_SHOT = 0
WAVE_MODE_REPEAT = 1
WAVE_MODE_ONE_SHOT_SYNC = 2
WAVE_MODE_REPEAT_SYNC = 3

MOSI:

The GPIO used for the MOSI signal when bit banging SPI. -

offset: >=0

The offset wave data starts from the beginning of the waveform -being currently defined. -

pad: 0-2

A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

pad_strength: 1-16

The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

params: 32 bit number

When scripts are started they can receive up to 10 parameters -to define their operation. -

percent: : 0-100

The size of waveform as percentage of maximum available. -

port:

The port used by the pigpio daemon, defaults to 8888. -

pstring:

The string to be passed to a shell script to be executed. -

pud: 0-2

PUD_DOWN = 1
PUD_OFF = 0
PUD_UP = 2

pulse_len: 1-100

The length of the trigger pulse in microseconds. -

pulses:

A list of class pulse objects defining the characteristics of a -waveform. -

pulsewidth:

The servo pulsewidth in microseconds. 0 switches pulses off. -

PWMduty: 0-1000000 (1M)

The hardware PWM dutycycle. -

PWMfreq: 1-125M (1-187.5M for the BCM2711)

The hardware PWM frequency. -

range_: 25-40000

Defines the limits for the dutycycle parameter. -

range_ defaults to 255. -

reg: 0-255

An I2C device register. The usable registers depend on the -actual device. -

retMax: >=0

The maximum number of bytes a user customised function -should return, default 8192. -

SCL:

The user GPIO to use for the clock when bit banging I2C. -

SCLK: :

The GPIO used for the SCLK signal when bit banging SPI. -

script:

The text of a script to store on the pigpio daemon. -

script_id: >=0

A number referencing a script created by store_script. -

SDA:

The user GPIO to use for data when bit banging I2C. -

seek_from: 0-2

Direction to seek for file_seek. -

FROM_START=0
FROM_CURRENT=1
FROM_END=2

seek_offset:

The number of bytes to move forward (positive) or backwards -(negative) from the seek position (start, current, or end of file). -

ser_flags: 32 bit

No serial flags are currently defined. -

serial_*:

One of the serial_ functions. -

shellscr:

The name of a shell script. The script must exist -in /opt/pigpio/cgi and must be executable. -

show_errors:

Controls the display of pigpio daemon connection failures. -The default of True prints the probable failure reasons to -standard output. -

spi_channel: 0-2

A SPI channel. -

spi_flags: 32 bit

See spi_open. -

steady: 0-300000

The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) -or triggering the active part of a noise filter -(set_noise_filter). -

t1:

A tick (earlier). -

t2:

A tick (later). -

tty:

A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0 -

uint32:

An unsigned 32 bit number. -

user_gpio: 0-31

A Broadcom numbered GPIO. -

All the user GPIO are in the range 0-31. -

Not all the GPIO within this range are usable, some are reserved -for system use. -

See gpio. -

wait_timeout: 0.0 -

The number of seconds to wait in wait_for_edge before timing out. -

wave_add_*:

One of the following -

wave_add_new -wave_add_generic -wave_add_serial -

wave_id: >=0

A number referencing a wave created by wave_create. -

wave_send_*:

One of the following -

wave_send_once -wave_send_repeat -

wdog_timeout: 0-60000

Defines a GPIO watchdog timeout in milliseconds. If no level -change is detected on the GPIO for timeout millisecond a watchdog -timeout report is issued (with level TIMEOUT). -

word_val: 0-65535

A whole number. -

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/sif.html b/DOC/HTML/sif.html deleted file mode 100644 index bbaa6e1..0000000 --- a/DOC/HTML/sif.html +++ /dev/null @@ -1,2058 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Socket Interface

-pigpio provides a socket interface to many of its functions.
-
-The socket interface is available whenever pigpio is running, -either because it has been started as a daemon, or it has been -linked in to a running user program.
-
-The socket interface can be disabled by the program which -initialises the library.  pigpiod offers the -k option to -disable the socket interface.  User programs should call -gpioCfgInterfaces if they -wish to disable the socket interface.
-
-pigpio listens for connections on port 8888 by default.  This -default may be overridden when pigpio starts by the gpioCfgSocketPort function -call.  The pigpio daemon uses this function to provide an -option to change the port number.
-
-The pigs utility is an example of using the socket interface from -C.
-

Request

-

pigpio expects messages of type cmdCmd_t immediately followed with an -extension for a few commands.
-
-The caller should fill in cmd, p1, p2, p3/res, and any extension as -needed.  p3 will always be zero unless the command requires an -extension in which case p3 will be the length in bytes of the -extension.
-
-The cmdCmd_t is echoed back with -the result, if any, in p3/res, and an extension immediately -afterwards for a few commands.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
COMMANDcmd
p1p2p3Extension
MODES0gpiomode0-
MODEG1gpio00-
PUD2gpiopud0-
READ3gpio00-
WRITE4gpiolevel0-
PWM5gpiodutycycle0-
PRS6gpiorange0-
PFS7gpiofrequency0-
SERVO8gpiopulsewidth0-
WDOG9gpiotimeout0-
BR110000-
BR211000-
BC112bits00-
BC213bits00-
BS114bits00-
BS215bits00-
TICK16000-
HWVER17000-
NO18000-
NB19handlebits0-
NP20handle00-
NC21handle00-
PRG22gpio00-
PFG23gpio00-
PRRG24gpio00-
HELP
25N/A
N/A
N/A
N/A
PIGPV26000-
WVCLR27000-
WVAG280012*XgpioPulse_t pulse[X]
WVAS29gpiobaud12+Xuint32_t databits
-uint32_t stophalfbits
-uint32_t offset
-uint8_t data[X]
N/A
30000-
N/A
31000-
WVBSY32000-
WVHLT33000-
WVSM34subcmd00-
WVSP35subcmd00-
WVSC36subcmd00-
TRIG37gpiopulselen4uint32_t level
PROC3800Xuint8_t text[X]
PROCD39script_id00-
PROCR40script_id04*X
uint32_t pars[X]
PROCS41script_id00-
SLRO42gpiobaud4uint32_t databits
SLR43gpiocount0-
SLRC44gpio00-
PROCP45script_id00-
MICS46micros00-
MILS47millis00-
PARSE48N/AN/A
N/A
N/A
WVCRE49000-
WVDEL50wave_id00-
WVTX51wave_id00-
WVTXR52wave_id00-
WVNEW53000-
I2CO54busdevice4uint32_t flags
I2CC55handle00-
I2CRD56handlecount0-
I2CWD57handle0Xuint8_t data[X]
I2CWQ58handlebit0-
I2CRS59handle00-
I2CWS60handlebyte0-
I2CRB61handleregister0-
I2CWB62handleregister4uint32_t byte
I2CRW63handleregister0-
I2CWW64handleregister4uint32_t word
I2CRK65handleregister
0-
I2CWK66handleregister
Xuint8_t bvs[X]
I2CRI67handleregister
4uint32_t num
I2CWI68handleregister
X
uint8_t bvs[X]
I2CPC69handleregister
4uint32_t word
I2CPK70handleregister
X
uint8_t data[X]
SPIO
71channelbaud4uint32_t flags
SPIC72handle00-
SPIR73handlecount0-
SPIW74handle0Xuint8_t data[X]
SPIX75handle0Xuint8_t data[X]
SERO76baudflagsXuint8_t device[X]
SERC77handle00-
SERRB78handle00-
SERWB79handlebyte0-
SERR80handlecount0-
SERW81handle0Xuint8_t data[X]
SERDA82handle00-
GDC
83
gpio
0
0
-
GPW
84
gpio
0
0
-
HC
85
gpio
frequency
0
-
HP
86
gpio
frequency
4
uint32_t dutycycle
CF1
87
arg1
arg2
X
uint8_t argx[X]
CF2
88
arg1
retMax
X
uint8_t argx[X]
BI2CC
89
sda
0
0
-
BI2CO
90
sda
scl
4
uint32_t baud
BI2CZ
91
sda
0
X
uint8_t data[X]
I2CZ
92
handle
0
X
uint8_t data[X]
WVCHA
93
0
0
X
uint8_t data[X]
SLRI
94
gpio
invert
0
-
CGI
95
0
0
0
-
CSI
96
config
0
0
-
FG
97
gpio
steady
0
-
FN
98
gpio
steady
4
uint32_t active
NOIB99000-
WVTXM
100
wave_id
mode
0
-
WVTAT
101
0
0
0
-
PADS
102
pad
strength
0
-
PADG
103
pad
0
0
-
FO
104
mode
0
X
uint8_t file[X]
FC
105
handle
0
0
-
FR
106
handle
count
0
-
FW
107
handle
0
X
uint8_t data[X]
FS
108
handle
offset
4
uint32_t from
FL
109
count
0
X
uint8_t pattern[X]
SHELL
110
len(name)
0
len(name)+
-1+
-len(string)
uint8_t name[len(name)]
-uint8_t null (0)
-uint8_t string[len(string)]
BSPIC
111
CS
0
0
-
BSPIO
112
CS
0
20
uint32_t MISO
-uint32_t MOSI
-uint32_t SCLK
-uint32_t baud
-uint32_t spi_flags
BSPIX
113
CS
0
X
uint8_t data[X]
BSCX
114
control
0
X
uint8_t data[X]
EVM
115
handle
bits
0
-
EVT
116
event
0
0
-
PROCU
117
script_id
0
4*X
uint32_t pars[X]
-

Response

-

The response has cmd/p1/p2 as in the request.  p3/res holds -the return value.  If the command returns additional values -they will be in the immediately following extension.

-Normally res should be treated as a 32 bit signed value and will be -greater than or equal to zero.  Upon failure res will be less -than 0 and contains an error code.
-

There are a few commands where the returned value should be -treated as a 32 bit unsigned value.  These commands can not -fail.  They are indicated with a * after the command -name.

-

Commands with an extension have the size of the extension in -bytes returned in res (or <0 on error as above).

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
COMMANDcmd
p1
p2
res
Extension
MODES0-
-
0-
MODEG1-
-
mode
-
PUD2-
-
0-
READ3-
-
level
-
WRITE4-
-
0-
PWM5-
-
0-
PRS6-
-
0-
PFS7-
-
0-
SERVO8-
-
0-
WDOG9-
-
0-
BR1 *10-
-
bits
-
BR2 *11-
-
bits
-
BC112-
-
0-
BC213-
-
0-
BS114-
-
0-
BS215-
-
0-
TICK *
16-
-
tick
-
HWVER *
17-
-
version
-
NO18-
-
handle
-
NB19-
-
0-
NP20-
-
0-
NC21-
-
0-
PRG22-
-
range
-
PFG23-
-
frequency
-
PRRG24-
-
real range
-
HELP25-
-
N/A
N/A
PIGPV *
26-
-
version
-
WVCLR27-
-
0-
WVAG28-
-
wave pulses
-
WVAS29-
-
wave pulses
-
N/A
30-
-
-
-
N/A
31-
-
-
-
WVBSY32-
-
busy (1) or not busy (0)
-
WVHLT33-
-
0-
WVSM34-
-
wave micros
-wave micros - high
-wave micros - max
-
WVSP35-
-
wave pulses
-wave pulses - high
-wave pulses - max
-
WVSC36-
-
wave DMA CBs
-wave DMA CBs - high
-wave DMA CBs - max
-
TRIG37-
-
0
-
PROC38-
-
script id
-
PROCD39-
-
0-
PROCR40-
-
script status
-
PROCS41-
-
0-
SLRO42-
-
0
-
SLR43-
-
X
uint8_t data[X]
SLRC44-
-
0-
PROCP45-
-
44uint32_t script_status
-uint32_t pars[10]
MICS46-
-
0-
MILS47-
-
0-
PARSE48-
-
N/A
-
WVCRE49-
-
wave id
-
WVDEL50-
-
0-
WVTX51-
-
wave DMA CBs
-
WVTXR52-
-
wave DMA CBs
-
WVNEW53-
-
0-
I2CO54-
-
handle-
I2CC55-
-
0-
I2CRD56-
-
X
uint8_t data[X]
I2CWD57-
-
0
-
I2CWQ58-
-
0-
I2CRS59-
-
byte value
-
I2CWS60-
-
0-
I2CRB61-
-
byte value
-
I2CWB62-
-
0
-
I2CRW63-
-
word value
-
I2CWW64-
-
0
-
I2CRK65-
-
0-
I2CWK66-
-
0
-
I2CRI67-
-
X
uint8_t data[X]
I2CWI68-
-
0
-
I2CPC69-
-
word value
-
I2CPK70-
-
X
uint8_t data[X]
SPIO
71-
-
handle
-
SPIC72-
-
0-
SPIR73-
-
X
uint8_t data[X]
SPIW74-
-
0
-
SPIX75-
-
Xuint8_t data[X]
SERO76-
-
handle
-
SERC77-
-
0-
SERRB78-
-
byte value
-
SERWB79-
-
0-
SERR80-
-
X
uint8_t data[X]
SERW81-
-
0
-
SERDA82-
-
data ready count
-
GDC
83
-
-
dutycycle
-
GPW
84
-
-
pulsewidth
-
HC
85
-
-
0
-
HP
86
-
-
0
-
CF1
87
-
-
value
-
CF2
88
-
-
X
uint8_t retBuf[X]
BI2CC
89
-
-
0
-
BI2CO
90
-
-
handle
-
BI2CZ
91
-
-
X
uint8_t data[X]
I2CZ
92
-
-
X
uint8_t data[X]
WVCHA
93
-
-
0
-
SLRI
94
-
-
0
-
CGI
95
-
-
config
-
CSI
96
-
-
0
-
FG
97
-
-
0
-
FN
98
-
-
0
-
NOIB99-
-
0-
WVTXM
100
-
-
wave DMA CBs
-
WVTAT
101
-
-
wave id
-
PADS
102
-
-
0
-
PADG
103
-
-
strength
-
FO
104
-
-
handle
-
FC
105
-
-
0
-
FR
106
-
-
X
uint8_t data[X]
FW
107
-
-
0
-
FS
108
-
-
position
-
FL
109
-
-
X
uint8_t filenames[X]
SHELL
110
-
-
exit status
-
BSPIC
111
-
-
0
-
BSPIO
112
-
-
0
-
BSPIX
113
-
-
X
uint8_t data[X]
BSCX
114
-
-
X+4
uint32_t status
-uint8_t data[X]
EVM
115
-
-
0
-
EVT
116
-
-
0
-
PROCU
117
-
-
0
-
-
-

cmdCmd_t

-typedef struct
-{
-   uint32_t cmd;
-   uint32_t p1;
-   uint32_t p2;
-   union
-   {
-      uint32_t p3;
-      uint32_t ext_len;
-      uint32_t res;
-   };
-} cmdCmd_t;

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/sitemap.html b/DOC/HTML/sitemap.html deleted file mode 100644 index b2706b1..0000000 --- a/DOC/HTML/sitemap.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Site Map

pigpio
-pigpio C I/F
-pigpiod
-pigpiod C I/F
-Python
-pigs
-piscope
-Misc
-----Socket I/F
-----Pipe I/F
-----pigpiod_if
-----pig2vcd
-Examples
-----Rotary Encoder
-----IR Remote
-----Light Dependent Resitor
-----Sonar Ranger
-----Arduino Motor Shield
-Download
-FAQ
-Site Map
-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/MAN/README b/DOC/MAN/README deleted file mode 100644 index 2a89c86..0000000 --- a/DOC/MAN/README +++ /dev/null @@ -1,2 +0,0 @@ -Placeholder directory for man pages. - diff --git a/DOC/MAN/pig2vcd.1 b/DOC/MAN/pig2vcd.1 deleted file mode 100644 index eacce19..0000000 --- a/DOC/MAN/pig2vcd.1 +++ /dev/null @@ -1,246 +0,0 @@ - -." Process this file with -." groff -man -Tascii pig2vcd.1 -." -.TH pig2vcd 1 2012-2020 Linux "pigpio archive" -.SH NAME -pig2vd - A utility to convert pigpio notifications to VCD. - -.SH SYNOPSIS - -pig2vcd file.VCD -.SH DESCRIPTION - - -.ad l - -.nh -pig2vcd is a utility which reads notifications on stdin and writes the -output as a Value Change Dump (VCD) file on stdout. - -.br - -.br -The VCD file can be viewed using GTKWave. - -.br - -.br -.SS Notifications -.br - -.br -Notifications consist of 12 bytes with the following binary format. - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint16_t seqno; -.br - uint16_t flags; -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioReport_t; -.br - -.EE - -.br - -.br -seqno: starts at 0 each time the handle is opened and then increments by one for each report. - -.br - -.br -flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. - -.br - -.br -tick: the number of microseconds since system boot. It wraps around after 1h12m. - -.br - -.br -level: indicates the level of each gpio. If bit 1< - - -gcc -Wall -pthread -o prog prog.c -lpigpio -lrt - -sudo ./prog -.SH DESCRIPTION - - -.ad l - -.nh - -.br - -.br -pigpio is a C library for the Raspberry which allows control of the GPIO. - -.br - -.br -.SS Features -.br - -.br -o hardware timed PWM on any of GPIO 0-31 - -.br - -.br -o hardware timed servo pulses on any of GPIO 0-31 - -.br - -.br -o callbacks when any of GPIO 0-31 change state - -.br - -.br -o callbacks at timed intervals - -.br - -.br -o reading/writing all of the GPIO in a bank as one operation - -.br - -.br -o individually setting GPIO modes, reading and writing - -.br - -.br -o notifications when any of GPIO 0-31 change state - -.br - -.br -o the construction of output waveforms with microsecond timing - -.br - -.br -o rudimentary permission control over GPIO - -.br - -.br -o a simple interface to start and stop new threads - -.br - -.br -o I2C, SPI, and serial link wrappers - -.br - -.br -o creating and running scripts - -.br - -.br -.SS GPIO -.br - -.br -ALL GPIO are identified by their Broadcom number. - -.br - -.br -.SS Credits -.br - -.br -The PWM and servo pulses are timed using the DMA and PWM peripherals. - -.br - -.br -This use was inspired by Richard Hirst's servoblaster kernel module. - -.br - -.br -.SS Usage -.br - -.br -Include in your source files. - -.br - -.br -Assuming your source is in prog.c use the following command to build and -run the executable. - -.br - -.br - -.EX -gcc -Wall -pthread -o prog prog.c -lpigpio -lrt -.br -sudo ./prog -.br - -.EE - -.br - -.br -For examples of usage see the C programs within the pigpio archive file. - -.br - -.br -.SS Notes -.br - -.br -All the functions which return an int return < 0 on error. - -.br - -.br -\fBgpioInitialise\fP must be called before all other library functions -with the following exceptions: - -.br - -.br - -.EX -\fBgpioCfg*\fP -.br -\fBgpioVersion\fP -.br -\fBgpioHardwareRevision\fP -.br - -.EE - -.br - -.br -If the library is not initialised all but the \fBgpioCfg*\fP, -\fBgpioVersion\fP, and \fBgpioHardwareRevision\fP functions will -return error PI_NOT_INITIALISED. - -.br - -.br -If the library is initialised the \fBgpioCfg*\fP functions will return -error PI_INITIALISED. - -.br - -.br - -.SH OVERVIEW - -.br -.SS ESSENTIAL -.br - -.br -gpioInitialise Initialise library -.br -gpioTerminate Stop library -.br -.SS BASIC -.br - -.br -gpioSetMode Set a GPIO mode -.br -gpioGetMode Get a GPIO mode -.br - -.br -gpioSetPullUpDown Set/clear GPIO pull up/down resistor -.br - -.br -gpioRead Read a GPIO -.br -gpioWrite Write a GPIO -.br -.SS PWM (overrides servo commands on same GPIO) -.br - -.br -gpioPWM Start/stop PWM pulses on a GPIO -.br -gpioSetPWMfrequency Configure PWM frequency for a GPIO -.br -gpioSetPWMrange Configure PWM range for a GPIO -.br - -.br -gpioGetPWMdutycycle Get dutycycle setting on a GPIO -.br -gpioGetPWMfrequency Get configured PWM frequency for a GPIO -.br -gpioGetPWMrange Get configured PWM range for a GPIO -.br - -.br -gpioGetPWMrealRange Get underlying PWM range for a GPIO -.br -.SS Servo (overrides PWM commands on same GPIO) -.br - -.br -gpioServo Start/stop servo pulses on a GPIO -.br - -.br -gpioGetServoPulsewidth Get pulsewidth setting on a GPIO -.br -.SS INTERMEDIATE -.br - -.br -gpioTrigger Send a trigger pulse to a GPIO -.br - -.br -gpioSetWatchdog Set a watchdog on a GPIO -.br - -.br -gpioRead_Bits_0_31 Read all GPIO in bank 1 -.br -gpioRead_Bits_32_53 Read all GPIO in bank 2 -.br - -.br -gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 -.br -gpioWrite_Bits_32_53_Clear Clear selected GPIO in bank 2 -.br - -.br -gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 -.br -gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 -.br - -.br -gpioSetAlertFunc Request a GPIO level change callback -.br -gpioSetAlertFuncEx Request a GPIO change callback, extended -.br - -.br -gpioSetTimerFunc Request a regular timed callback -.br -gpioSetTimerFuncEx Request a regular timed callback, extended -.br - -.br -gpioStartThread Start a new thread -.br -gpioStopThread Stop a previously started thread -.br -.SS ADVANCED -.br - -.br -gpioNotifyOpen Request a notification handle -.br -gpioNotifyClose Close a notification -.br -gpioNotifyOpenWithSize Request a notification with sized pipe -.br -gpioNotifyBegin Start notifications for selected GPIO -.br -gpioNotifyPause Pause notifications -.br - -.br -gpioHardwareClock Start hardware clock on supported GPIO -.br - -.br -gpioHardwarePWM Start hardware PWM on supported GPIO -.br - -.br -gpioGlitchFilter Set a glitch filter on a GPIO -.br -gpioNoiseFilter Set a noise filter on a GPIO -.br - -.br -gpioSetPad Sets a pads drive strength -.br -gpioGetPad Gets a pads drive strength -.br - -.br -shell Executes a shell command -.br - -.br -gpioSetISRFunc Request a GPIO interrupt callback -.br -gpioSetISRFuncEx Request a GPIO interrupt callback, extended -.br - -.br -gpioSetSignalFunc Request a signal callback -.br -gpioSetSignalFuncEx Request a signal callback, extended -.br - -.br -gpioSetGetSamplesFunc Requests a GPIO samples callback -.br -gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended -.br -.SS Custom -.br - -.br -gpioCustom1 User custom function 1 -.br -gpioCustom2 User custom function 2 -.br -.SS Events -.br - -.br -eventMonitor Sets the events to monitor -.br -eventSetFunc Request an event callback -.br -eventSetFuncEx Request an event callback, extended -.br - -.br -eventTrigger Trigger an event -.br -.SS Scripts -.br - -.br -gpioStoreScript Store a script -.br -gpioRunScript Run a stored script -.br -gpioUpdateScript Set a scripts parameters -.br -gpioScriptStatus Get script status and parameters -.br -gpioStopScript Stop a running script -.br -gpioDeleteScript Delete a stored script -.br -.SS I2C -.br - -.br -i2cOpen Opens an I2C device -.br -i2cClose Closes an I2C device -.br - -.br -i2cWriteQuick SMBus write quick -.br - -.br -i2cReadByte SMBus read byte -.br -i2cWriteByte SMBus write byte -.br - -.br -i2cReadByteData SMBus read byte data -.br -i2cWriteByteData SMBus write byte data -.br - -.br -i2cReadWordData SMBus read word data -.br -i2cWriteWordData SMBus write word data -.br - -.br -i2cReadBlockData SMBus read block data -.br -i2cWriteBlockData SMBus write block data -.br - -.br -i2cReadI2CBlockData SMBus read I2C block data -.br -i2cWriteI2CBlockData SMBus write I2C block data -.br - -.br -i2cReadDevice Reads the raw I2C device -.br -i2cWriteDevice Writes the raw I2C device -.br - -.br -i2cProcessCall SMBus process call -.br -i2cBlockProcessCall SMBus block process call -.br - -.br -i2cSwitchCombined Sets or clears the combined flag -.br - -.br -i2cSegments Performs multiple I2C transactions -.br - -.br -i2cZip Performs multiple I2C transactions -.br -.SS I2C BIT BANG -.br - -.br -bbI2COpen Opens GPIO for bit banging I2C -.br -bbI2CClose Closes GPIO for bit banging I2C -.br - -.br -bbI2CZip Performs bit banged I2C transactions -.br -.SS I2C/SPI SLAVE -.br - -.br -bscXfer I2C/SPI as slave transfer -.br -.SS SERIAL -.br - -.br -serOpen Opens a serial device -.br -serClose Closes a serial device -.br - -.br -serReadByte Reads a byte from a serial device -.br -serWriteByte Writes a byte to a serial device -.br - -.br -serRead Reads bytes from a serial device -.br -serWrite Writes bytes to a serial device -.br - -.br -serDataAvailable Returns number of bytes ready to be read -.br -.SS SERIAL BIT BANG (read only) -.br - -.br -gpioSerialReadOpen Opens a GPIO for bit bang serial reads -.br -gpioSerialReadClose Closes a GPIO for bit bang serial reads -.br - -.br -gpioSerialReadInvert Configures normal/inverted for serial reads -.br - -.br -gpioSerialRead Reads bit bang serial data from a GPIO -.br -.SS SPI -.br - -.br -spiOpen Opens a SPI device -.br -spiClose Closes a SPI device -.br - -.br -spiRead Reads bytes from a SPI device -.br -spiWrite Writes bytes to a SPI device -.br -spiXfer Transfers bytes with a SPI device -.br -.SS SPI BIT BANG -.br - -.br -bbSPIOpen Opens GPIO for bit banging SPI -.br -bbSPIClose Closes GPIO for bit banging SPI -.br - -.br -bbSPIXfer Performs bit banged SPI transactions -.br -.SS FILES -.br - -.br -fileOpen Opens a file -.br -fileClose Closes a file -.br - -.br -fileRead Reads bytes from a file -.br -fileWrite Writes bytes to a file -.br - -.br -fileSeek Seeks to a position within a file -.br - -.br -fileList List files which match a pattern -.br -.SS WAVES -.br - -.br -gpioWaveClear Deletes all waveforms -.br - -.br -gpioWaveAddNew Starts a new waveform -.br -gpioWaveAddGeneric Adds a series of pulses to the waveform -.br -gpioWaveAddSerial Adds serial data to the waveform -.br - -.br -gpioWaveCreate Creates a waveform from added data -.br -gpioWaveCreatePad Creates a waveform of fixed size from added data -.br -gpioWaveDelete Deletes a waveform -.br - -.br -gpioWaveTxSend Transmits a waveform -.br - -.br -gpioWaveChain Transmits a chain of waveforms -.br - -.br -gpioWaveTxAt Returns the current transmitting waveform -.br - -.br -gpioWaveTxBusy Checks to see if the waveform has ended -.br - -.br -gpioWaveTxStop Aborts the current waveform -.br - -.br -gpioWaveGetCbs Length in CBs of the current waveform -.br -gpioWaveGetHighCbs Length of longest waveform so far -.br -gpioWaveGetMaxCbs Absolute maximum allowed CBs -.br - -.br -gpioWaveGetMicros Length in micros of the current waveform -.br -gpioWaveGetHighMicros Length of longest waveform so far -.br -gpioWaveGetMaxMicros Absolute maximum allowed micros -.br - -.br -gpioWaveGetPulses Length in pulses of the current waveform -.br -gpioWaveGetHighPulses Length of longest waveform so far -.br -gpioWaveGetMaxPulses Absolute maximum allowed pulses -.br -.SS UTILITIES -.br - -.br -gpioDelay Delay for a number of microseconds -.br - -.br -gpioTick Get current tick (microseconds) -.br - -.br -gpioHardwareRevision Get hardware revision -.br -gpioVersion Get the pigpio version -.br - -.br -getBitInBytes Get the value of a bit -.br -putBitInBytes Set the value of a bit -.br - -.br -gpioTime Get current time -.br -gpioSleep Sleep for specified time -.br - -.br -time_sleep Sleeps for a float number of seconds -.br -time_time Float number of seconds since the epoch -.br -.SS CONFIGURATION -.br - -.br -gpioCfgBufferSize Configure the GPIO sample buffer size -.br -gpioCfgClock Configure the GPIO sample rate -.br -gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) -.br -gpioCfgDMAchannels Configure the DMA channels -.br -gpioCfgPermissions Configure the GPIO access permissions -.br -gpioCfgInterfaces Configure user interfaces -.br -gpioCfgSocketPort Configure socket port -.br -gpioCfgMemAlloc Configure DMA memory allocation mode -.br -gpioCfgNetAddr Configure allowed network addresses -.br - -.br -gpioCfgInternals Configure misc. internals (DEPRECATED) -.br -gpioCfgGetInternals Get internal configuration settings -.br -gpioCfgSetInternals Set internal configuration settings -.br -.SS EXPERT -.br - -.br -rawWaveAddSPI Not intended for general use -.br -rawWaveAddGeneric Not intended for general use -.br -rawWaveCB Not intended for general use -.br -rawWaveCBAdr Not intended for general use -.br -rawWaveGetOOL Not intended for general use -.br -rawWaveSetOOL Not intended for general use -.br -rawWaveGetOut Not intended for general use -.br -rawWaveSetOut Not intended for general use -.br -rawWaveGetIn Not intended for general use -.br -rawWaveSetIn Not intended for general use -.br -rawWaveInfo Not intended for general use -.br -rawDumpWave Not intended for general use -.br -rawDumpScript Not intended for general use -.br -.SH FUNCTIONS - -.IP "\fBint gpioInitialise(void)\fP" -.IP "" 4 -Initialises the library. - -.br - -.br -Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. - -.br - -.br -gpioInitialise must be called before using the other library functions -with the following exceptions: - -.br - -.br - -.EX -\fBgpioCfg*\fP -.br -\fBgpioVersion\fP -.br -\fBgpioHardwareRevision\fP -.br - -.EE - -.br - -.br -\fBExample\fP -.br - -.EX -if (gpioInitialise() < 0) -.br -{ -.br - // pigpio initialisation failed. -.br -} -.br -else -.br -{ -.br - // pigpio initialised okay. -.br -} -.br - -.EE - -.IP "\fBvoid gpioTerminate(void)\fP" -.IP "" 4 -Terminates the library. - -.br - -.br -Returns nothing. - -.br - -.br -Call before program exit. - -.br - -.br -This function resets the used DMA channels, releases memory, and -terminates any running threads. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioTerminate(); -.br - -.EE - -.IP "\fBint gpioSetMode(unsigned gpio, unsigned mode)\fP" -.IP "" 4 -Sets the GPIO mode, typically input or output. - -.br - -.br - -.EX -gpio: 0-53 -.br -mode: 0-7 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. - -.br - -.br -Arduino style: pinMode. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetMode(17, PI_INPUT); // Set GPIO17 as input. -.br - -.br -gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output. -.br - -.br -gpioSetMode(22,PI_ALT0); // Set GPIO22 to alternative mode 0. -.br - -.EE - -.br - -.br -See \fBhttp://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf\fP page 102 for an overview of the modes. - -.IP "\fBint gpioGetMode(unsigned gpio)\fP" -.IP "" 4 -Gets the GPIO mode. - -.br - -.br - -.EX -gpio: 0-53 -.br - -.EE - -.br - -.br -Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. - -.br - -.br -\fBExample\fP -.br - -.EX -if (gpioGetMode(17) != PI_ALT0) -.br -{ -.br - gpioSetMode(17, PI_ALT0); // set GPIO17 to ALT0 -.br -} -.br - -.EE - -.IP "\fBint gpioSetPullUpDown(unsigned gpio, unsigned pud)\fP" -.IP "" 4 -Sets or clears resistor pull ups or downs on the GPIO. - -.br - -.br - -.EX -gpio: 0-53 -.br - pud: 0-2 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetPullUpDown(17, PI_PUD_UP); // Sets a pull-up. -.br - -.br -gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down. -.br - -.br -gpioSetPullUpDown(23, PI_PUD_OFF); // Clear any pull-ups/downs. -.br - -.EE - -.IP "\fBint gpioRead(unsigned gpio)\fP" -.IP "" 4 -Reads the GPIO level, on or off. - -.br - -.br - -.EX -gpio: 0-53 -.br - -.EE - -.br - -.br -Returns the GPIO level if OK, otherwise PI_BAD_GPIO. - -.br - -.br -Arduino style: digitalRead. - -.br - -.br -\fBExample\fP -.br - -.EX -printf("GPIO24 is level %d", gpioRead(24)); -.br - -.EE - -.IP "\fBint gpioWrite(unsigned gpio, unsigned level)\fP" -.IP "" 4 -Sets the GPIO level, on or off. - -.br - -.br - -.EX - gpio: 0-53 -.br -level: 0-1 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. - -.br - -.br -If PWM or servo pulses are active on the GPIO they are switched off. - -.br - -.br -Arduino style: digitalWrite - -.br - -.br -\fBExample\fP -.br - -.EX -gpioWrite(24, 1); // Set GPIO24 high. -.br - -.EE - -.IP "\fBint gpioPWM(unsigned user_gpio, unsigned dutycycle)\fP" -.IP "" 4 -Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). -Range defaults to 255. - -.br - -.br - -.EX -user_gpio: 0-31 -.br -dutycycle: 0-range -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. - -.br - -.br -Arduino style: analogWrite - -.br - -.br -This and the servo functionality use the DMA and PWM or PCM peripherals -to control and schedule the pulse lengths and dutycycles. - -.br - -.br -The \fBgpioSetPWMrange\fP function may be used to change the default -range of 255. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioPWM(17, 255); // Sets GPIO17 full on. -.br - -.br -gpioPWM(18, 128); // Sets GPIO18 half on. -.br - -.br -gpioPWM(23, 0); // Sets GPIO23 full off. -.br - -.EE - -.IP "\fBint gpioGetPWMdutycycle(unsigned user_gpio)\fP" -.IP "" 4 -Returns the PWM dutycycle setting for the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -Returns between 0 (off) and range (fully on) if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. - -.br - -.br -For normal PWM the dutycycle will be out of the defined range -for the GPIO (see \fBgpioGetPWMrange\fP). - -.br - -.br -If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). - -.br - -.br -Normal PWM range defaults to 255. - -.IP "\fBint gpioSetPWMrange(unsigned user_gpio, unsigned range)\fP" -.IP "" 4 -Selects the dutycycle range to be used for the GPIO. Subsequent calls -to gpioPWM will use a dutycycle between 0 (off) and range (fully on). - -.br - -.br - -.EX -user_gpio: 0-31 -.br - range: 25-40000 -.br - -.EE - -.br - -.br -Returns the real range for the given GPIO's frequency if OK, -otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. - -.br - -.br -If PWM is currently active on the GPIO its dutycycle will be scaled -to reflect the new range. - -.br - -.br -The real range, the number of steps between fully off and fully -on for each frequency, is given in the following table. - -.br - -.br - -.EX - 25, 50, 100, 125, 200, 250, 400, 500, 625, -.br - 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000 -.br - -.EE - -.br - -.br -The real value set by \fBgpioPWM\fP is (dutycycle * real range) / range. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetPWMrange(24, 2000); // Now 2000 is fully on -.br - // 1000 is half on -.br - // 500 is quarter on, etc. -.br - -.EE - -.IP "\fBint gpioGetPWMrange(unsigned user_gpio)\fP" -.IP "" 4 -Returns the dutycycle range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). - -.br - -.br -\fBExample\fP -.br - -.EX -r = gpioGetPWMrange(23); -.br - -.EE - -.IP "\fBint gpioGetPWMrealRange(unsigned user_gpio)\fP" -.IP "" 4 -Returns the real range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -If a hardware clock is active on the GPIO the reported real -range will be 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. - -.br - -.br -\fBExample\fP -.br - -.EX -rr = gpioGetPWMrealRange(17); -.br - -.EE - -.IP "\fBint gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)\fP" -.IP "" 4 -Sets the frequency in hertz to be used for the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br -frequency: >=0 -.br - -.EE - -.br - -.br -Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO. - -.br - -.br -If PWM is currently active on the GPIO it will be -switched off and then back on at the new frequency. - -.br - -.br -Each GPIO can be independently set to one of 18 different PWM -frequencies. - -.br - -.br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). - -.br - -.br -The frequencies for each sample rate are: - -.br - -.br - -.EX - Hertz -.br - -.br - 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 -.br - 1250 1000 800 500 400 250 200 100 50 -.br - -.br - 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 -.br - 625 500 400 250 200 125 100 50 25 -.br - -.br - 4: 10000 5000 2500 2000 1250 1000 625 500 400 -.br - 313 250 200 125 100 63 50 25 13 -.br -sample -.br - rate -.br - (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 -.br - 250 200 160 100 80 50 40 20 10 -.br - -.br - 8: 5000 2500 1250 1000 625 500 313 250 200 -.br - 156 125 100 63 50 31 25 13 6 -.br - -.br - 10: 4000 2000 1000 800 500 400 250 200 160 -.br - 125 100 80 50 40 25 20 10 5 -.br - -.EE - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency. -.br - -.br -gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz. -.br - -.br -gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency. -.br - -.EE - -.IP "\fBint gpioGetPWMfrequency(unsigned user_gpio)\fP" -.IP "" 4 -Returns the frequency (in hertz) used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -For normal PWM the frequency will be that defined for the GPIO by -\fBgpioSetPWMfrequency\fP. - -.br - -.br -If a hardware clock is active on the GPIO the reported frequency -will be that set by \fBgpioHardwareClock\fP. - -.br - -.br -If hardware PWM is active on the GPIO the reported frequency -will be that set by \fBgpioHardwarePWM\fP. - -.br - -.br -\fBExample\fP -.br - -.EX -f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23. -.br - -.EE - -.IP "\fBint gpioServo(unsigned user_gpio, unsigned pulsewidth)\fP" -.IP "" 4 -Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to -2500 (most clockwise). - -.br - -.br - -.EX - user_gpio: 0-31 -.br -pulsewidth: 0, 500-2500 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. - -.br - -.br -The range supported by servos varies and should probably be determined -by experiment. A value of 1500 should always be safe and represents -the mid-point of rotation. You can DAMAGE a servo if you command it -to move beyond its limits. - -.br - -.br -The following 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. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioServo(17, 1000); // Move servo to safe position anti-clockwise. -.br - -.br -gpioServo(23, 1500); // Move servo to centre position. -.br - -.br -gpioServo(25, 2000); // Move servo to safe position clockwise. -.br - -.EE - -.br - -.br -OTHER UPDATE RATES: - -.br - -.br -This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. - -.br - -.br - -.EX -PWM Hz 50 100 200 400 500 -.br -1E6/Hz 20000 10000 5000 2500 2000 -.br - -.EE - -.br - -.br -Firstly set the desired PWM frequency using \fBgpioSetPWMfrequency\fP. - -.br - -.br -Then set the PWM range using \fBgpioSetPWMrange\fP to 1E6/frequency. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. - -.br - -.br -E.g. If you want to update a servo connected to GPIO25 at 400Hz - -.br - -.br - -.EX -gpioSetPWMfrequency(25, 400); -.br - -.br -gpioSetPWMrange(25, 2500); -.br - -.EE - -.br - -.br -Thereafter use the PWM command to move the servo, -e.g. gpioPWM(25, 1500) will set a 1500 us pulse. - -.IP "\fBint gpioGetServoPulsewidth(unsigned user_gpio)\fP" -.IP "" 4 -Returns the servo pulsewidth setting for the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) -if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. - -.IP "\fBint gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) when the specified -GPIO changes state. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - f: the callback function -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO. - -.br - -.br -One callback may be registered per GPIO. - -.br - -.br -The callback is passed the GPIO, the new level, and the tick. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -level 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.EE - -.br - -.br -The alert may be cancelled by passing NULL as the function. - -.br - -.br -The GPIO are sampled at a rate set when the library is started. - -.br - -.br -If a value isn't specifically set the default of 5 us is used. - -.br - -.br -The number of samples per second is given in the following table. - -.br - -.br - -.EX - samples -.br - per sec -.br - -.br - 1 1,000,000 -.br - 2 500,000 -.br -sample 4 250,000 -.br -rate 5 200,000 -.br -(us) 8 125,000 -.br - 10 100,000 -.br - -.EE - -.br - -.br -Level changes shorter than the sample rate may be missed. - -.br - -.br -The thread which calls the alert functions is triggered nominally -1000 times per second. The active alert functions will be called -once per level change since the last time the thread was activated. -i.e. The active alert functions will get all level changes but there -will be a latency. - -.br - -.br -If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use \fBgpioRead\fP. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. - -.br - -.br -The tick value is the time stamp of the sample in microseconds, see -\fBgpioTick\fP for more details. - -.br - -.br -\fBExample\fP -.br - -.EX -void aFunction(int gpio, int level, uint32_t tick) -.br -{ -.br - printf("GPIO %d became %d at %d", gpio, level, tick); -.br -} -.br - -.br -// call aFunction whenever GPIO 4 changes state -.br - -.br -gpioSetAlertFunc(4, aFunction); -.br - -.EE - -.IP "\fBint gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) when the specified -GPIO changes state. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - f: the callback function -.br - userdata: pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO. - -.br - -.br -One callback may be registered per GPIO. - -.br - -.br -The callback is passed the GPIO, the new level, the tick, and -the userdata pointer. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -level 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.br -userdata pointer Pointer to an arbitrary object -.br - -.EE - -.br - -.br -See \fBgpioSetAlertFunc\fP for further details. - -.br - -.br -Only one of \fBgpioSetAlertFunc\fP or \fBgpioSetAlertFuncEx\fP can be -registered per GPIO. - -.IP "\fBint gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. - -.br - -.br - -.EX - gpio: 0-53 -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE -.br -timeout: interrupt timeout in milliseconds (<=0 to cancel) -.br - f: the callback function -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. - -.br - -.br -One function may be registered per GPIO. - -.br - -.br -The function is passed the GPIO, the current level, and the -current tick. The level will be PI_TIMEOUT if the optional -interrupt timeout expires. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-53 The GPIO which has changed state -.br - -.br -level 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (interrupt timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.EE - -.br - -.br -The underlying Linux sysfs GPIO interface is used to provide -the interrupt services. - -.br - -.br -The first time the function is called, with a non-NULL f, the -GPIO is exported, set to be an input, and set to interrupt -on the given edge and timeout. - -.br - -.br -Subsequent calls, with a non-NULL f, can vary one or more of the -edge, timeout, or function. - -.br - -.br -The ISR may be cancelled by passing a NULL f, in which case the -GPIO is unexported. - -.br - -.br -The tick is that read at the time the process was informed of -the interrupt. This will be a variable number of microseconds -after the interrupt occurred. Typically the latency will be of -the order of 50 microseconds. The latency is not guaranteed -and will vary with system load. - -.br - -.br -The level is that read at the time the process was informed of -the interrupt, or PI_TIMEOUT if the optional interrupt timeout -expired. It may not be the same as the expected edge as -interrupts happening in rapid succession may be missed by the -kernel (i.e. this mechanism can not be used to capture several -interrupts only a few microseconds apart). - -.IP "\fBint gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. - -.br - -.br - -.EX - gpio: 0-53 -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE -.br - timeout: interrupt timeout in milliseconds (<=0 to cancel) -.br - f: the callback function -.br -userdata: pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. - -.br - -.br -The function is passed the GPIO, the current level, the -current tick, and the userdata pointer. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-53 The GPIO which has changed state -.br - -.br -level 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (interrupt timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.br -userdata pointer Pointer to an arbitrary object -.br - -.EE - -.br - -.br -Only one of \fBgpioSetISRFunc\fP or \fBgpioSetISRFuncEx\fP can be -registered per GPIO. - -.br - -.br -See \fBgpioSetISRFunc\fP for further details. - -.IP "\fBint gpioNotifyOpen(void)\fP" -.IP "" 4 -This function requests a free notification handle. - -.br - -.br -Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. - -.br - -.br -A notification is a method for being notified of GPIO state changes -via a pipe or socket. - -.br - -.br -Pipe notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). E.g. if the -function returns 15 then the notifications must be read -from /dev/pigpio15. - -.br - -.br -Socket notifications are returned to the socket which requested the -handle. - -.br - -.br -\fBExample\fP -.br - -.EX -h = gpioNotifyOpen(); -.br - -.br -if (h >= 0) -.br -{ -.br - sprintf(str, "/dev/pigpio%d", h); -.br - -.br - fd = open(str, O_RDONLY); -.br - -.br - if (fd >= 0) -.br - { -.br - // Okay. -.br - } -.br - else -.br - { -.br - // Error. -.br - } -.br -} -.br -else -.br -{ -.br - // Error. -.br -} -.br - -.EE - -.IP "\fBint gpioNotifyOpenWithSize(int bufSize)\fP" -.IP "" 4 -This function requests a free notification handle. - -.br - -.br -It differs from \fBgpioNotifyOpen\fP in that the pipe size may be -specified, whereas \fBgpioNotifyOpen\fP uses the default pipe size. - -.br - -.br -See \fBgpioNotifyOpen\fP for further details. - -.IP "\fBint gpioNotifyBegin(unsigned handle, uint32_t bits)\fP" -.IP "" 4 -This function starts notifications on a previously opened handle. - -.br - -.br - -.EX -handle: >=0, as returned by \fBgpioNotifyOpen\fP -.br - bits: a bit mask indicating the GPIO of interest -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -The notification sends state changes for each GPIO whose corresponding -bit in bits is set. - -.br - -.br -Each notification occupies 12 bytes in the fifo and has the -following structure. - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint16_t seqno; -.br - uint16_t flags; -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioReport_t; -.br - -.EE - -.br - -.br -seqno: starts at 0 each time the handle is opened and then increments -by one for each report. - -.br - -.br -flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. - -.br - -.br -If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. - -.br - -.br -If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. - -.br - -.br -If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. - -.br - -.br -tick: the number of microseconds since system boot. It wraps around -after 1h12m. - -.br - -.br -level: indicates the level of each GPIO. If bit 1<=0, as returned by \fBgpioNotifyOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -Notifications for the handle are suspended until \fBgpioNotifyBegin\fP -is called again. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioNotifyPause(h); -.br - -.EE - -.IP "\fBint gpioNotifyClose(unsigned handle)\fP" -.IP "" 4 -This function stops notifications on a previously opened handle -and releases the handle for reuse. - -.br - -.br - -.EX -handle: >=0, as returned by \fBgpioNotifyOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioNotifyClose(h); -.br - -.EE - -.IP "\fBint gpioWaveClear(void)\fP" -.IP "" 4 -This function clears all waveforms and any data added by calls to the -\fBgpioWaveAdd*\fP functions. - -.br - -.br -Returns 0 if OK. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioWaveClear(); -.br - -.EE - -.IP "\fBint gpioWaveAddNew(void)\fP" -.IP "" 4 -This function starts a new empty waveform. - -.br - -.br -You wouldn't normally need to call this function as it is automatically -called after a waveform is created with the \fBgpioWaveCreate\fP function. - -.br - -.br -Returns 0 if OK. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioWaveAddNew(); -.br - -.EE - -.IP "\fBint gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)\fP" -.IP "" 4 -This function adds a number of pulses to the current waveform. - -.br - -.br - -.EX -numPulses: the number of pulses -.br - pulses: an array of pulses -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. - -.br - -.br -The pulses are interleaved in time order within the existing waveform -(if any). - -.br - -.br -Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. - -.br - -.br -If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. - -.br - -.br -\fBExample\fP -.br - -.EX -// Construct and send a 30 microsecond square wave. -.br - -.br -gpioSetMode(gpio, PI_OUTPUT); -.br - -.br -pulse[0].gpioOn = (1<= 0) -.br -{ -.br - gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT); -.br - -.br - // Transmit for 30 seconds. -.br - -.br - sleep(30); -.br - -.br - gpioWaveTxStop(); -.br -} -.br -else -.br -{ -.br - // Wave create failed. -.br -} -.br - -.EE - -.IP "\fBint gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)\fP" -.IP "" 4 -This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - baud: 50-1000000 -.br -data_bits: 1-32 -.br -stop_bits: 2-8 -.br - offset: >=0 -.br - numBytes: >=1 -.br - str: an array of chars (which may contain nulls) -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. - -.br - -.br -NOTES: - -.br - -.br -The serial data is formatted as one start bit, data_bits data bits, and -stop_bits/2 stop bits. - -.br - -.br -It is legal to add serial data streams with different baud rates to -the same waveform. - -.br - -.br -numBytes is the number of bytes of data in str. - -.br - -.br -The bytes required for each character depend upon data_bits. - -.br - -.br -For data_bits 1-8 there will be one byte per character. -.br -For data_bits 9-16 there will be two bytes per character. -.br -For data_bits 17-32 there will be four bytes per character. - -.br - -.br -\fBExample\fP -.br - -.EX -#define MSG_LEN 8 -.br - -.br -int i; -.br -char *str; -.br -char data[MSG_LEN]; -.br - -.br -str = "Hello world!"; -.br - -.br -gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str); -.br - -.br -for (i=0; i=0, as returned by \fBgpioWaveCreate\fP -.br - -.EE - -.br - -.br -Wave ids are allocated in order, 0, 1, 2, etc. - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_WAVE_ID. - -.IP "\fBint gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The mode -determines whether the waveform is sent once or cycles endlessly. -The SYNC variants wait for the current waveform to reach the -end of a cycle or finish before starting the new waveform. - -.br - -.br -WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. - -.br - -.br -NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled. - -.br - -.br - -.EX - wave_id: >=0, as returned by \fBgpioWaveCreate\fP -.br -wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT, -.br - PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint gpioWaveChain(char *buf, unsigned bufSize)\fP" -.IP "" 4 -This function transmits a chain of waveforms. - -.br - -.br -NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled. - -.br - -.br -The waves to be transmitted are specified by the contents of buf -which contains an ordered list of \fBwave_id\fPs and optional command -codes and related data. - -.br - -.br - -.EX - buf: pointer to the wave_ids and optional command codes -.br -bufSize: the number of bytes in buf -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. - -.br - -.br -Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. - -.br - -.br -A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. - -.br - -.br -Delays between waves may be added with the delay command. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -Loop Start 255 0 Identify start of a wave block -.br -Loop Repeat 255 1 x y loop x + y*256 times -.br -Delay 255 2 x y delay x + y*256 microseconds -.br -Loop Forever 255 3 loop forever -.br - -.br - -.br -If present Loop Forever must be the last entry in the chain. - -.br - -.br -The code is currently dimensioned to support a chain with roughly -600 entries and 20 loop counters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -#define WAVES 5 -.br -#define GPIO 4 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, wid[WAVES]; -.br - -.br - if (gpioInitialise()<0) return -1; -.br - -.br - gpioSetMode(GPIO, PI_OUTPUT); -.br - -.br - printf("start piscope, press return"); getchar(); -.br - -.br - for (i=0; i=0 -.br - -.EE - -.br - -.br -Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. - -.br - -.br -The bytes returned for each character depend upon the number of -data bits \fBdata_bits\fP specified in the \fBgpioSerialReadOpen\fP command. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint gpioSerialReadClose(unsigned user_gpio)\fP" -.IP "" 4 -This function closes a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX -user_gpio: 0-31, previously opened with \fBgpioSerialReadOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. - -.IP "\fBint i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)\fP" -.IP "" 4 -This returns a handle for the device at the address on the I2C bus. - -.br - -.br - -.EX - i2cBus: >=0 -.br - i2cAddr: 0-0x7F -.br -i2cFlags: 0 -.br - -.EE - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.br - -.br -Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - SDA SCL -.br -I2C 0 0 1 -.br -I2C 1 2 3 -.br - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. - -.br - -.br -For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. - -.br - -.br - -.EX -S (1 bit) : Start bit -.br -P (1 bit) : Stop bit -.br -Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. -.br -A, NA (1 bit) : Accept and not accept bit. -.br -.br -.br -Addr (7 bits): I2C 7 bit address. -.br -i2cReg (8 bits): Command byte, a byte which often selects a register. -.br -Data (8 bits): A data byte. -.br -Count (8 bits): A byte defining the length of a block operation. -.br - -.br -[..]: Data sent by the device. -.br - -.EE - -.IP "\fBint i2cClose(unsigned handle)\fP" -.IP "" 4 -This closes the I2C device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint i2cWriteQuick(unsigned handle, unsigned bit)\fP" -.IP "" 4 -This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - bit: 0-1, the value to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Quick command. SMBus 2.0 5.5.1 - -.EX -S Addr bit [A] P -.br - -.EE - -.IP "\fBint i2cWriteByte(unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This sends a single byte to the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - bVal: 0-0xFF, the value to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Send byte. SMBus 2.0 5.5.2 - -.EX -S Addr Wr [A] bVal [A] P -.br - -.EE - -.IP "\fBint i2cReadByte(unsigned handle)\fP" -.IP "" 4 -This reads a single byte from the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. - -.br - -.br -Receive byte. SMBus 2.0 5.5.3 - -.EX -S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)\fP" -.IP "" 4 -This writes a single byte to the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write -.br - bVal: 0-0xFF, the value to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write byte. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] i2cReg [A] bVal [A] P -.br - -.EE - -.IP "\fBint i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)\fP" -.IP "" 4 -This writes a single 16 bit word to the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write -.br - wVal: 0-0xFFFF, the value to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write word. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P -.br - -.EE - -.IP "\fBint i2cReadByteData(unsigned handle, unsigned i2cReg)\fP" -.IP "" 4 -This reads a single byte from the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to read -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read byte. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2cReadWordData(unsigned handle, unsigned i2cReg)\fP" -.IP "" 4 -This reads a single 16 bit word from the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to read -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read word. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)\fP" -.IP "" 4 -This writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write/read -.br - wVal: 0-0xFFFF, the value to write -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Process call. SMBus 2.0 5.5.6 - -.EX -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] -.br - S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes up to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write -.br - buf: an array with the data to send -.br - count: 1-32, the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Block write. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] i2cReg [A] count [A] -.br - buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)\fP" -.IP "" 4 -This reads a block of up to 32 bytes from the specified register of -the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to read -.br - buf: an array to receive the read data -.br - -.EE - -.br - -.br -The amount of returned data is set by the device. - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Block read. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] i2cReg [A] -.br - S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write/read -.br - buf: an array with the data to send and to receive the read data -.br - count: 1-32, the number of bytes to write -.br - -.EE - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -The SMBus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. - -.br - -.br -Block write-block read. SMBus 2.0 5.5.8 - -.EX -S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A] -.br - S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P -.br - -.EE - -.IP "\fBint i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to read -.br - buf: an array to receive the read data -.br - count: 1-32, the number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] i2cReg [A] -.br - S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes 1 to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write -.br - buf: the data to write -.br - count: 1-32, the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2cReadDevice(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the raw device into buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - buf: an array to receive the read data bytes -.br - count: >0, the number of bytes to read -.br - -.EE - -.br - -.br -Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2cWriteDevice(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This writes count bytes from buf to the raw device. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - buf: an array containing the data bytes to write -.br - count: >0, the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBvoid i2cSwitchCombined(int setting)\fP" -.IP "" 4 -This sets the I2C (i2c-bcm2708) module "use combined transactions" -parameter on or off. - -.br - -.br - -.EX -setting: 0 to set the parameter off, non-zero to set it on -.br - -.EE - -.br - -.br - -.br - -.br -NOTE: when the flag is on a write followed by a read to the same -slave address will use a repeated start (rather than a stop/start). - -.IP "\fBint i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)\fP" -.IP "" 4 -This function executes multiple I2C segments in one transaction by -calling the I2C_RDWR ioctl. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - segs: an array of I2C segments -.br -numSegs: >0, the number of I2C segments -.br - -.EE - -.br - -.br -Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. - -.IP "\fBint i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -On 2 Switch combined flag on -.br -Off 3 Switch combined flag off -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53, write 0x32, read 6 bytes -.br -Set address 0x1E, write 0x03, read 6 bytes -.br -Set address 0x68, write 0x1B, read 8 bytes -.br -End -.br - -.br -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -.br -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -.br -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -.br -0x00 -.br - -.EE - -.IP "\fBint bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)\fP" -.IP "" 4 -This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. - -.br - -.br -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -.br - -.br -o baud rates as low as 50 -.br -o repeated starts -.br -o clock stretching -.br -o I2C on any pair of spare GPIO - -.br - -.br - -.EX - SDA: 0-31 -.br - SCL: 0-31 -.br -baud: 50-500000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -NOTE: - -.br - -.br -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -.IP "\fBint bbI2CClose(unsigned SDA)\fP" -.IP "" 4 -This function stops bit banging I2C on a pair of GPIO previously -opened with \fBbbI2COpen\fP. - -.br - -.br - -.EX -SDA: 0-31, the SDA GPIO used in a prior call to \fBbbI2COpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - -.IP "\fBint bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX - SDA: 0-31 (as used in a prior call to \fBbbI2COpen\fP) -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -Start 2 Start condition -.br -Stop 3 Stop condition -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -.br - -.br -No flags are currently defined. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53 -.br -start, write 0x32, (re)start, read 6 bytes, stop -.br -Set address 0x1E -.br -start, write 0x03, (re)start, read 6 bytes, stop -.br -Set address 0x68 -.br -start, write 0x1B, (re)start, read 8 bytes, stop -.br -End -.br - -.br -0x04 0x53 -.br -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x1E -.br -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x68 -.br -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 -.br - -.br -0x00 -.br - -.EE - -.IP "\fBint bscXfer(bsc_xfer_t *bsc_xfer)\fP" -.IP "" 4 -This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. - -.br - -.br -This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. - -.br - -.br -This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. - -.br - -.br -The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. - -.br - -.br -I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. - -.br - -.br -The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. - -.br - -.br - -.EX -bsc_xfer:= a structure defining the transfer -.br - -.br -typedef struct -.br -{ -.br - uint32_t control; // Write -.br - int rxCnt; // Read only -.br - char rxBuf[BSC_FIFO_SIZE]; // Read only -.br - int txCnt; // Write -.br - char txBuf[BSC_FIFO_SIZE]; // Write -.br -} bsc_xfer_t; -.br - -.EE - -.br - -.br -To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. - -.br - -.br -Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. - -.br - -.br -Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. - -.br - -.br -GPIO used for models other than those based on the BCM2711. - -.br - -.br - SDA SCL MOSI SCLK MISO CE -.br -I2C 18 19 - - - - -.br -SPI - - 18 19 20 21 -.br - -.br - -.br -GPIO used for models based on the BCM2711 (e.g. the Pi4B). - -.br - -.br - SDA SCL MOSI SCLK MISO CE -.br -I2C 10 11 - - - - -.br -SPI - - 10 11 9 8 -.br - -.br - -.br -When a zero control word is received the used GPIO will be reset -to INPUT mode. - -.br - -.br -The returned function value is the status of the transfer (see below). - -.br - -.br -If there was an error the status will be less than zero -(and will contain the error code). - -.br - -.br -The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). - -.br - -.br -control consists of the following bits. - -.br - -.br - -.EX -22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN -.br - -.EE - -.br - -.br -Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. - -.br - -.br -aaaaaaa defines the I2C slave address (only relevant in I2C mode) -.br -IT invert transmit status flags -.br -HC enable host control -.br -TF enable test FIFO -.br -IR invert receive status flags -.br -RE enable receive -.br -TE enable transmit -.br -BK abort operation and clear FIFOs -.br -EC send control register as first I2C byte -.br -ES send status register as first I2C byte -.br -PL set SPI polarity high -.br -PH set SPI phase high -.br -I2 enable I2C mode -.br -SP enable SPI mode -.br -EN enable BSC peripheral -.br - -.br - -.br -The returned status has the following format - -.br - -.br - -.EX -20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - S S S S S R R R R R T T T T T RB TE RF TF RE TB -.br - -.EE - -.br - -.br -Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. - -.br - -.br -SSSSS number of bytes successfully copied to transmit FIFO -.br -RRRRR number of bytes in receieve FIFO -.br -TTTTT number of bytes in transmit FIFO -.br -RB receive busy -.br -TE transmit FIFO empty -.br -RF receive FIFO full -.br -TF transmit FIFO full -.br -RE receive FIFO empty -.br -TB transmit busy -.br - -.br - -.br -The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. - -.br - -.br -\fBExample\fP -.br - -.EX -bsc_xfer_t xfer; -.br - -.br -xfer.control = (0x13<<16) | 0x305; -.br - -.br -memcpy(xfer.txBuf, "ABCD", 4); -.br -xfer.txCnt = 4; -.br - -.br -status = bscXfer(&xfer); -.br - -.br -if (status >= 0) -.br -{ -.br - // process transfer -.br -} -.br - -.EE - -.IP "\fBint bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)\fP" -.IP "" 4 -This function selects a set of GPIO for bit banging SPI with -a specified baud rate and mode. - -.br - -.br - -.EX - CS: 0-31 -.br - MISO: 0-31 -.br - MOSI: 0-31 -.br - SCLK: 0-31 -.br - baud: 50-250000 -.br -spiFlags: see below -.br - -.EE - -.br - -.br -spiFlags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m -.br - -.EE - -.br - -.br -mm defines the SPI mode, defaults to 0 - -.br - -.br - -.EX -Mode CPOL CPHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -p is 0 if CS is active low (default) and 1 for active high. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. - -.br - -.br -The other bits in flags should be set to zero. - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. - -.br - -.br -\fBExample\fP -.br - -.EX -bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1 -.br -bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2 -.br - -.EE - -.IP "\fBint bbSPIClose(unsigned CS)\fP" -.IP "" 4 -This function stops bit banging SPI on a set of GPIO -opened with \fBbbSPIOpen\fP. - -.br - -.br - -.EX -CS: 0-31, the CS GPIO used in a prior call to \fBbbSPIOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. - -.IP "\fBint bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)\fP" -.IP "" 4 -This function executes a bit banged SPI transfer. - -.br - -.br - -.EX - CS: 0-31 (as used in a prior call to \fBbbSPIOpen\fP) -.br - inBuf: pointer to buffer to hold data to be sent -.br -outBuf: pointer to buffer to hold returned data -.br - count: size of data transfer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. - -.br - -.br -\fBExample\fP -.br - -.EX -// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio -.br -// sudo ./bbSPIx_test -.br - -.br - -.br -#include -.br - -.br -#include "pigpio.h" -.br - -.br -#define CE0 5 -.br -#define CE1 6 -.br -#define MISO 13 -.br -#define MOSI 19 -.br -#define SCLK 12 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, count, set_val, read_val; -.br - unsigned char inBuf[3]; -.br - char cmd1[] = {0, 0}; -.br - char cmd2[] = {12, 0}; -.br - char cmd3[] = {1, 128, 0}; -.br - -.br - if (gpioInitialise() < 0) -.br - { -.br - fprintf(stderr, "pigpio initialisation failed.\n"); -.br - return 1; -.br - } -.br - -.br - bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC -.br - bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC -.br - -.br - for (i=0; i<256; i++) -.br - { -.br - cmd1[1] = i; -.br - -.br - count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC -.br - -.br - if (count == 2) -.br - { -.br - count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC -.br - -.br - if (count == 2) -.br - { -.br - set_val = inBuf[1]; -.br - -.br - count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC -.br - -.br - if (count == 3) -.br - { -.br - read_val = ((inBuf[1]&3)<<8) | inBuf[2]; -.br - printf("%d %d\n", set_val, read_val); -.br - } -.br - } -.br - } -.br - } -.br - -.br - bbSPIClose(CE0); -.br - bbSPIClose(CE1); -.br - -.br - gpioTerminate(); -.br - -.br - return 0; -.br -} -.br - -.EE - -.IP "\fBint spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)\fP" -.IP "" 4 -This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. - -.br - -.br -The Pi has two SPI peripherals: main and auxiliary. - -.br - -.br -The main SPI has two chip selects (channels), the auxiliary has -three. - -.br - -.br -The auxiliary SPI is available on all models but the A and B. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - MISO MOSI SCLK CE0 CE1 CE2 -.br -Main SPI 9 10 11 8 7 - -.br -Aux SPI 19 20 21 18 17 16 -.br - -.br - -.br - -.EX - spiChan: 0-1 (0-2 for the auxiliary SPI) -.br - baud: 32K-125M (values above 30M are unlikely to work) -.br -spiFlags: see below -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. - -.br - -.br -spiFlags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -.br - -.EE - -.br - -.br -mm defines the SPI mode. - -.br - -.br -Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. - -.br - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -px is 0 if CEx is active low (default) and 1 for active high. - -.br - -.br -ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. - -.br - -.br -A is 0 for the main SPI, 1 for the auxiliary SPI. - -.br - -.br -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main -SPI only. - -.br - -.br -nnnn defines the number of bytes (0-15) to write before switching -the MOSI line to MISO to read data. This field is ignored -if W is not set. Main SPI only. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. Auxiliary SPI -only. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. Auxiliary SPI -only. - -.br - -.br -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI only. - -.br - -.br -The \fBspiRead\fP, \fBspiWrite\fP, and \fBspiXfer\fP functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. - -.br - -.br -For bits 1-8 there will be one byte per word. -.br -For bits 9-16 there will be two bytes per word. -.br -For bits 17-32 there will be four bytes per word. - -.br - -.br -Multi-byte transfers are made in least significant byte first order. - -.br - -.br -E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. - -.br - -.br -E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed -by 0x1A. - -.br - -.br -The other bits in flags should be set to zero. - -.IP "\fBint spiClose(unsigned handle)\fP" -.IP "" 4 -This functions closes the SPI device identified by the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspiOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint spiRead(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads count bytes of data from the SPI -device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspiOpen\fP -.br - buf: an array to receive the read data bytes -.br - count: the number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spiWrite(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes of data from buf to the SPI -device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspiOpen\fP -.br - buf: the data bytes to write -.br - count: the number of bytes to write -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" -.IP "" 4 -This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspiOpen\fP -.br - txBuf: the data bytes to write -.br - rxBuf: the received data bytes -.br - count: the number of bytes to transfer -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint serOpen(char *sertty, unsigned baud, unsigned serFlags)\fP" -.IP "" 4 -This function opens a serial device at a specified baud rate -and with specified flags. The device name must start with -/dev/tty or /dev/serial. - -.br - -.br - -.EX - sertty: the serial device to open -.br - baud: the baud rate in bits per second, see below -.br -serFlags: 0 -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. - -.br - -.br -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.IP "\fBint serClose(unsigned handle)\fP" -.IP "" 4 -This function closes the serial device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint serWriteByte(unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This function writes bVal to the serial port associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serReadByte(unsigned handle)\fP" -.IP "" 4 -This function reads a byte from the serial port associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - -.EE - -.br - -.br -Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. - -.br - -.br -If no data is ready PI_SER_READ_NO_DATA is returned. - -.IP "\fBint serWrite(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the serial port -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - buf: the array of bytes to write -.br - count: the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serRead(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up count bytes from the the serial port -associated with handle and writes them to buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - buf: an array to receive the read data -.br - count: the maximum number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_SER_READ_NO_DATA. - -.br - -.br -If no data is ready zero is returned. - -.IP "\fBint serDataAvailable(unsigned handle)\fP" -.IP "" 4 -This function returns the number of bytes available -to be read from the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - -.EE - -.br - -.br -Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. - -.IP "\fBint gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)\fP" -.IP "" 4 -This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - pulseLen: 1-100 -.br - level: 0,1 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -or PI_BAD_PULSELEN. - -.IP "\fBint gpioSetWatchdog(unsigned user_gpio, unsigned timeout)\fP" -.IP "" 4 -Sets a watchdog for a GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - timeout: 0-60000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. - -.br - -.br -The watchdog is nominally in milliseconds. - -.br - -.br -One watchdog may be registered per GPIO. - -.br - -.br -The watchdog may be cancelled by setting timeout to 0. - -.br - -.br -Until cancelled a timeout will be reported every timeout milliseconds -after the last GPIO activity. - -.br - -.br -In particular: - -.br - -.br -1) any registered alert function for the GPIO will be called with - the level set to PI_TIMEOUT. - -.br - -.br -2) any notification for the GPIO will have a report written to the - fifo with the flags set to indicate a watchdog timeout. - -.br - -.br -\fBExample\fP -.br - -.EX -void aFunction(int gpio, int level, uint32_t tick) -.br -{ -.br - printf("GPIO %d became %d at %d", gpio, level, tick); -.br -} -.br - -.br -// call aFunction whenever GPIO 4 changes state -.br -gpioSetAlertFunc(4, aFunction); -.br - -.br -// or approximately every 5 millis -.br -gpioSetWatchdog(4, 5); -.br - -.EE - -.IP "\fBint gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)\fP" -.IP "" 4 -Sets a noise filter on a GPIO. - -.br - -.br -Level changes on the GPIO are ignored until a level which has -been stable for \fBsteady\fP microseconds is detected. Level changes -on the GPIO are then reported for \fBactive\fP microseconds after -which the process repeats. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - steady: 0-300000 -.br - active: 0-1000000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - -.br - -.br -This filter affects the GPIO samples returned to callbacks set up -with \fBgpioSetAlertFunc\fP, \fBgpioSetAlertFuncEx\fP, \fBgpioSetGetSamplesFunc\fP, -and \fBgpioSetGetSamplesFuncEx\fP. - -.br - -.br -It does not affect interrupts set up with \fBgpioSetISRFunc\fP, -\fBgpioSetISRFuncEx\fP, or levels read by \fBgpioRead\fP, -\fBgpioRead_Bits_0_31\fP, or \fBgpioRead_Bits_32_53\fP. - -.br - -.br -Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. - -.IP "\fBint gpioGlitchFilter(unsigned user_gpio, unsigned steady)\fP" -.IP "" 4 -Sets a glitch filter on a GPIO. - -.br - -.br -Level changes on the GPIO are not reported unless the level -has been stable for at least \fBsteady\fP microseconds. The -level is then reported. Level changes of less than \fBsteady\fP -microseconds are ignored. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - steady: 0-300000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - -.br - -.br -This filter affects the GPIO samples returned to callbacks set up -with \fBgpioSetAlertFunc\fP, \fBgpioSetAlertFuncEx\fP, \fBgpioSetGetSamplesFunc\fP, -and \fBgpioSetGetSamplesFuncEx\fP. - -.br - -.br -It does not affect interrupts set up with \fBgpioSetISRFunc\fP, -\fBgpioSetISRFuncEx\fP, or levels read by \fBgpioRead\fP, -\fBgpioRead_Bits_0_31\fP, or \fBgpioRead_Bits_32_53\fP. - -.br - -.br -Each (stable) edge will be timestamped \fBsteady\fP microseconds -after it was first detected. - -.IP "\fBint gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)\fP" -.IP "" 4 -Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. - -.br - -.br - -.EX - f: the function to call -.br -bits: the GPIO of interest -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -The function is passed a pointer to the samples (an array of -\fBgpioSample_t\fP), and the number of samples. - -.br - -.br -Only one function can be registered. - -.br - -.br -The callback may be cancelled by passing NULL as the function. - -.br - -.br -The samples returned will be the union of bits, plus any active alerts, -plus any active notifications. - -.br - -.br -e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO -8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO -7, 8, 9, 10, 17, 23, and 24 will be reported. - -.IP "\fBint gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. - -.br - -.br - -.EX - f: the function to call -.br - bits: the GPIO of interest -.br -userdata: a pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -The function is passed a pointer to the samples (an array of -\fBgpioSample_t\fP), the number of samples, and the userdata pointer. - -.br - -.br -Only one of \fBgpioGetSamplesFunc\fP or \fBgpioGetSamplesFuncEx\fP can be -registered. - -.br - -.br -See \fBgpioSetGetSamplesFunc\fP for further details. - -.IP "\fBint gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) every millis milliseconds. - -.br - -.br - -.EX - timer: 0-9 -.br -millis: 10-60000 -.br - f: the function to call -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. - -.br - -.br -10 timers are supported numbered 0 to 9. - -.br - -.br -One function may be registered per timer. - -.br - -.br -The timer may be cancelled by passing NULL as the function. - -.br - -.br -\fBExample\fP -.br - -.EX -void bFunction(void) -.br -{ -.br - printf("two seconds have elapsed"); -.br -} -.br - -.br -// call bFunction every 2000 milliseconds -.br -gpioSetTimerFunc(0, 2000, bFunction); -.br - -.EE - -.IP "\fBint gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) every millis milliseconds. - -.br - -.br - -.EX - timer: 0-9. -.br - millis: 10-60000 -.br - f: the function to call -.br -userdata: a pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. - -.br - -.br -The function is passed the userdata pointer. - -.br - -.br -Only one of \fBgpioSetTimerFunc\fP or \fBgpioSetTimerFuncEx\fP can be -registered per timer. - -.br - -.br -See \fBgpioSetTimerFunc\fP for further details. - -.IP "\fBpthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)\fP" -.IP "" 4 -Starts a new thread of execution with f as the main routine. - -.br - -.br - -.EX - f: the main function for the new thread -.br -userdata: a pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns a pointer to pthread_t if OK, otherwise NULL. - -.br - -.br -The function is passed the single argument arg. - -.br - -.br -The thread can be cancelled by passing the pointer to pthread_t to -\fBgpioStopThread\fP. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -void *myfunc(void *arg) -.br -{ -.br - while (1) -.br - { -.br - printf("%s", arg); -.br - sleep(1); -.br - } -.br -} -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - pthread_t *p1, *p2, *p3; -.br - -.br - if (gpioInitialise() < 0) return 1; -.br - -.br - p1 = gpioStartThread(myfunc, "thread 1"); sleep(3); -.br - -.br - p2 = gpioStartThread(myfunc, "thread 2"); sleep(3); -.br - -.br - p3 = gpioStartThread(myfunc, "thread 3"); sleep(3); -.br - -.br - gpioStopThread(p3); sleep(3); -.br - -.br - gpioStopThread(p2); sleep(3); -.br - -.br - gpioStopThread(p1); sleep(3); -.br - -.br - gpioTerminate(); -.br -} -.br - -.EE - -.IP "\fBvoid gpioStopThread(pthread_t *pth)\fP" -.IP "" 4 -Cancels the thread pointed at by pth. - -.br - -.br - -.EX -pth: a thread pointer returned by \fBgpioStartThread\fP -.br - -.EE - -.br - -.br -No value is returned. - -.br - -.br -The thread to be stopped should have been started with \fBgpioStartThread\fP. - -.IP "\fBint gpioStoreScript(char *script)\fP" -.IP "" 4 -This function stores a null terminated script for later execution. - -.br - -.br -See \fBhttp://abyz.me.uk/rpi/pigpio/pigs.html#Scripts\fP for details. - -.br - -.br - -.EX -script: the text of the script -.br - -.EE - -.br - -.br -The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. - -.IP "\fBint gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function runs a stored script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - numPar: 0-10, the number of parameters -.br - param: an array of parameters -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function runs a stored script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - numPar: 0-10, the number of parameters -.br - param: an array of parameters -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - numPar: 0-10, the number of parameters -.br - param: an array of parameters -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint gpioScriptStatus(unsigned script_id, uint32_t *param)\fP" -.IP "" 4 -This function returns the run status of a stored script as well as -the current values of parameters 0 to 9. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - param: an array to hold the returned 10 parameters -.br - -.EE - -.br - -.br -The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. - -.br - -.br -The run status may be - -.br - -.br - -.EX -PI_SCRIPT_INITING -.br -PI_SCRIPT_HALTED -.br -PI_SCRIPT_RUNNING -.br -PI_SCRIPT_WAITING -.br -PI_SCRIPT_FAILED -.br - -.EE - -.br - -.br -The current value of script parameters 0 to 9 are returned in param. - -.IP "\fBint gpioStopScript(unsigned script_id)\fP" -.IP "" 4 -This function stops a running script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint gpioDeleteScript(unsigned script_id)\fP" -.IP "" 4 -This function deletes a stored script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) when a signal occurs. - -.br - -.br - -.EX -signum: 0-63 -.br - f: the callback function -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_SIGNUM. - -.br - -.br -The function is passed the signal number. - -.br - -.br -One function may be registered per signal. - -.br - -.br -The callback may be cancelled by passing NULL. - -.br - -.br -By default all signals are treated as fatal and cause the library -to call gpioTerminate and then exit. - -.IP "\fBint gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) when a signal occurs. - -.br - -.br - -.EX - signum: 0-63 -.br - f: the callback function -.br -userdata: a pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_SIGNUM. - -.br - -.br -The function is passed the signal number and the userdata pointer. - -.br - -.br -Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be -registered per signal. - -.br - -.br -See gpioSetSignalFunc for further details. - -.IP "\fBuint32_t gpioRead_Bits_0_31(void)\fP" -.IP "" 4 -Returns the current level of GPIO 0-31. - -.IP "\fBuint32_t gpioRead_Bits_32_53(void)\fP" -.IP "" 4 -Returns the current level of GPIO 32-53. - -.IP "\fBint gpioWrite_Bits_0_31_Clear(uint32_t bits)\fP" -.IP "" 4 -Clears GPIO 0-31 if the corresponding bit in bits is set. - -.br - -.br - -.EX -bits: a bit mask of GPIO to clear -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -\fBExample\fP -.br - -.EX -// To clear (set to 0) GPIO 4, 7, and 15 -.br -gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) ); -.br - -.EE - -.IP "\fBint gpioWrite_Bits_32_53_Clear(uint32_t bits)\fP" -.IP "" 4 -Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. - -.br - -.br - -.EX -bits: a bit mask of GPIO to clear -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.IP "\fBint gpioWrite_Bits_0_31_Set(uint32_t bits)\fP" -.IP "" 4 -Sets GPIO 0-31 if the corresponding bit in bits is set. - -.br - -.br - -.EX -bits: a bit mask of GPIO to set -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.IP "\fBint gpioWrite_Bits_32_53_Set(uint32_t bits)\fP" -.IP "" 4 -Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. - -.br - -.br - -.EX -bits: a bit mask of GPIO to set -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -\fBExample\fP -.br - -.EX -// To set (set to 1) GPIO 32, 40, and 53 -.br -gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32))); -.br - -.EE - -.IP "\fBint gpioHardwareClock(unsigned gpio, unsigned clkfreq)\fP" -.IP "" 4 -Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. - -.br - -.br - -.EX - gpio: see description -.br -clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, -PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. - -.br - -.br -The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. - -.br - -.br -The GPIO must be one of the following. - -.br - -.br - -.EX -4 clock 0 All models -.br -5 clock 1 All models but A and B (reserved for system use) -.br -6 clock 2 All models but A and B -.br -20 clock 0 All models but A and B -.br -21 clock 1 All models but A and Rev.2 B (reserved for system use) -.br - -.br -32 clock 0 Compute module only -.br -34 clock 0 Compute module only -.br -42 clock 1 Compute module only (reserved for system use) -.br -43 clock 2 Compute module only -.br -44 clock 1 Compute module only (reserved for system use) -.br - -.EE - -.br - -.br -Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. - -.IP "\fBint gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)\fP" -.IP "" 4 -Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. - -.br - -.br -NOTE: Any waveform started by \fBgpioWaveTxSend\fP, or -\fBgpioWaveChain\fP will be cancelled. - -.br - -.br -This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden by a call to -\fBgpioCfgClock\fP. - -.br - -.br - -.EX - gpio: see description -.br -PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) -.br -PWMduty: 0 (off) to 1000000 (1M)(fully on) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, -PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. - -.br - -.br -The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. - -.br - -.br -The GPIO must be one of the following. - -.br - -.br - -.EX -12 PWM channel 0 All models but A and B -.br -13 PWM channel 1 All models but A and B -.br -18 PWM channel 0 All models -.br -19 PWM channel 1 All models but A and B -.br - -.br -40 PWM channel 0 Compute module only -.br -41 PWM channel 1 Compute module only -.br -45 PWM channel 1 Compute module only -.br -52 PWM channel 0 Compute module only -.br -53 PWM channel 1 Compute module only -.br - -.EE - -.br - -.br -The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). - -.br - -.br -The actual frequency set is 250M/steps (375M/steps for the BCM2711). - -.br - -.br -There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. - -.IP "\fBint gpioTime(unsigned timetype, int *seconds, int *micros)\fP" -.IP "" 4 -Updates the seconds and micros variables with the current time. - -.br - -.br - -.EX -timetype: 0 (relative), 1 (absolute) -.br - seconds: a pointer to an int to hold seconds -.br - micros: a pointer to an int to hold microseconds -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_TIMETYPE. - -.br - -.br -If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the -number of seconds and microseconds since the epoch (1st January 1970). - -.br - -.br -If timetype is PI_TIME_RELATIVE updates seconds and micros with the -number of seconds and microseconds since the library was initialised. - -.br - -.br -\fBExample\fP -.br - -.EX -int secs, mics; -.br - -.br -// print the number of seconds since the library was started -.br -gpioTime(PI_TIME_RELATIVE, &secs, &mics); -.br -printf("library started %d.%03d seconds ago", secs, mics/1000); -.br - -.EE - -.IP "\fBint gpioSleep(unsigned timetype, int seconds, int micros)\fP" -.IP "" 4 -Sleeps for the number of seconds and microseconds specified by seconds -and micros. - -.br - -.br - -.EX -timetype: 0 (relative), 1 (absolute) -.br - seconds: seconds to sleep -.br - micros: microseconds to sleep -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, -or PI_BAD_MICROS. - -.br - -.br -If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds -and microseconds since the epoch (1st January 1970) has elapsed. System -clock changes are taken into account. - -.br - -.br -If timetype is PI_TIME_RELATIVE the sleep is for the specified number -of seconds and microseconds. System clock changes do not effect the -sleep length. - -.br - -.br -For short delays (say, 50 microseonds or less) use \fBgpioDelay\fP. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds -.br - -.br -gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds -.br - -.br -gpioSleep(PI_TIME_RELATIVE, 60, 0); // sleep for one minute -.br - -.EE - -.IP "\fBuint32_t gpioDelay(uint32_t micros)\fP" -.IP "" 4 -Delays for at least the number of microseconds specified by micros. - -.br - -.br - -.EX -micros: the number of microseconds to sleep -.br - -.EE - -.br - -.br -Returns the actual length of the delay in microseconds. - -.br - -.br -Delays of 100 microseconds or less use busy waits. - -.IP "\fBuint32_t gpioTick(void)\fP" -.IP "" 4 -Returns the current system tick. - -.br - -.br -Tick is the number of microseconds since system boot. - -.br - -.br -As tick is an unsigned 32 bit quantity it wraps around after -2^32 microseconds, which is approximately 1 hour 12 minutes. - -.br - -.br -You don't need to worry about the wrap around as long as you -take a tick (uint32_t) from another tick, i.e. the following -code will always provide the correct difference. - -.br - -.br -\fBExample\fP -.br - -.EX -uint32_t startTick, endTick; -.br -int diffTick; -.br - -.br -startTick = gpioTick(); -.br - -.br -// do some processing -.br - -.br -endTick = gpioTick(); -.br - -.br -diffTick = endTick - startTick; -.br - -.br -printf("some processing took %d microseconds", diffTick); -.br - -.EE - -.IP "\fBunsigned gpioHardwareRevision(void)\fP" -.IP "" 4 -Returns the hardware revision. - -.br - -.br -If the hardware revision can not be found or is not a valid hexadecimal -number the function returns 0. - -.br - -.br -The hardware revision is the last few characters on the Revision line of -/proc/cpuinfo. - -.br - -.br -The revision number can be used to determine the assignment of GPIO -to pins (see \fBgpio\fP). - -.br - -.br -There are at least three types of board. - -.br - -.br -Type 1 boards have hardware revision numbers of 2 and 3. - -.br - -.br -Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. - -.br - -.br -Type 3 boards have hardware revision numbers of 16 or greater. - -.br - -.br -for "Revision : 0002" the function returns 2. -.br -for "Revision : 000f" the function returns 15. -.br -for "Revision : 000g" the function returns 0. - -.IP "\fBunsigned gpioVersion(void)\fP" -.IP "" 4 -Returns the pigpio version. - -.IP "\fBint gpioGetPad(unsigned pad)\fP" -.IP "" 4 -This function returns the pad drive strength in mA. - -.br - -.br - -.EX -pad: 0-2, the pad to get -.br - -.EE - -.br - -.br -Returns the pad drive strength if OK, otherwise PI_BAD_PAD. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -strength = gpioGetPad(1); // get pad 1 strength -.br - -.EE - -.IP "\fBint gpioSetPad(unsigned pad, unsigned padStrength)\fP" -.IP "" 4 -This function sets the pad drive strength in mA. - -.br - -.br - -.EX - pad: 0-2, the pad to set -.br -padStrength: 1-16 mA -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetPad(0, 16); // set pad 0 strength to 16 mA -.br - -.EE - -.IP "\fBint eventMonitor(unsigned handle, uint32_t bits)\fP" -.IP "" 4 -This function selects the events to be reported on a previously -opened handle. - -.br - -.br - -.EX -handle: >=0, as returned by \fBgpioNotifyOpen\fP -.br - bits: a bit mask indicating the events of interest -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -A report is sent each time an event is triggered providing the -corresponding bit in bits is set. - -.br - -.br -See \fBgpioNotifyBegin\fP for the notification format. - -.br - -.br -\fBExample\fP -.br - -.EX -// Start reporting events 3, 6, and 7. -.br - -.br -// bit 76543210 -.br -// (0xC8 = 0b11001000) -.br - -.br -eventMonitor(h, 0xC8); -.br - -.EE - -.br - -.br - -.IP "\fBint eventSetFunc(unsigned event, eventFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) when the specified -event occurs. - -.br - -.br - -.EX -event: 0-31 -.br - f: the callback function -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - -.br - -.br -One function may be registered per event. - -.br - -.br -The function is passed the event, and the tick. - -.br - -.br -The callback may be cancelled by passing NULL as the function. - -.IP "\fBint eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) when the specified -event occurs. - -.br - -.br - -.EX - event: 0-31 -.br - f: the callback function -.br -userdata: pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - -.br - -.br -One function may be registered per event. - -.br - -.br -The function is passed the event, the tick, and the ueserdata pointer. - -.br - -.br -The callback may be cancelled by passing NULL as the function. - -.br - -.br -Only one of \fBeventSetFunc\fP or \fBeventSetFuncEx\fP can be -registered per event. - -.IP "\fBint eventTrigger(unsigned event)\fP" -.IP "" 4 -This function signals the occurrence of an event. - -.br - -.br - -.EX -event: 0-31, the event -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - -.br - -.br -An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling \fBeventSetFunc\fP) will be informed by -a callback. - -.br - -.br -One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. - -.br - -.br -The meaning of other events is arbitrary. - -.br - -.br -Note that other than its id and its tick there is no data associated -with an event. - -.IP "\fBint shell(char *scriptName, char *scriptString)\fP" -.IP "" 4 -This function uses the system call to execute a shell script -with the given string as its parameter. - -.br - -.br - -.EX - scriptName: the name of the script, only alphanumeric characters, -.br - '-' and '_' are allowed in the name -.br -scriptString: the string to pass to the script -.br - -.EE - -.br - -.br -The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. - -.br - -.br -scriptName must exist in /opt/pigpio/cgi and must be executable. - -.br - -.br -The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. - -.br - -.br -The following table gives some example returned statuses. - -.br - -.br -Script exit status Returned system call status -.br -1 256 -.br -5 1280 -.br -10 2560 -.br -200 51200 -.br -script not found 32512 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -// pass two parameters, hello and world -.br -status = shell("scr1", "hello world"); -.br - -.br -// pass three parameters, hello, string with spaces, and world -.br -status = shell("scr1", "hello 'string with spaces' world"); -.br - -.br -// pass one parameter, hello string with spaces world -.br -status = shell("scr1", "\"hello string with spaces world\""); -.br - -.EE - -.IP "\fBint fileOpen(char *file, unsigned mode)\fP" -.IP "" 4 -This function returns a handle to a file opened in a specified mode. - -.br - -.br - -.EX -file: the file to open -.br -mode: the file open mode -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. - -.br - -.br -File - -.br - -.br -A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. - -.br - -.br -Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. - -.br - -.br -Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. - -.br - -.br -Suppose /opt/pigpio/access contains the following entries - -.br - -.br - -.EX -/home/* n -.br -/home/pi/shared/dir_1/* w -.br -/home/pi/shared/dir_2/* r -.br -/home/pi/shared/dir_3/* u -.br -/home/pi/shared/dir_1/file.txt n -.br - -.EE - -.br - -.br -Files may be written in directory dir_1 with the exception -of file.txt. - -.br - -.br -Files may be read in directory dir_2. - -.br - -.br -Files may be read and written in directory dir_3. - -.br - -.br -If a directory allows read, write, or read/write access then files may -be created in that directory. - -.br - -.br -In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. - -.br - -.br - -.EX -a path containing .. -.br -a path containing only wildcards (*?) -.br -a path containing less than two non-wildcard parts -.br - -.EE - -.br - -.br -Mode - -.br - -.br -The mode may have the following values. - -.br - -.br -Macro Value Meaning -.br -PI_FILE_READ 1 open file for reading -.br -PI_FILE_WRITE 2 open file for writing -.br -PI_FILE_RW 3 open file for reading and writing -.br - -.br - -.br -The following values may be or'd into the mode. - -.br - -.br -Macro Value Meaning -.br -PI_FILE_APPEND 4 Writes append data to the end of the file -.br -PI_FILE_CREATE 8 The file is created if it doesn't exist -.br -PI_FILE_TRUNC 16 The file is truncated -.br - -.br - -.br -Newly created files are owned by root with permissions owner read and write. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int handle, c; -.br - char buf[60000]; -.br - -.br - if (gpioInitialise() < 0) return 1; -.br - -.br - // assumes /opt/pigpio/access contains the following line -.br - // /ram/*.c r -.br - -.br - handle = fileOpen("/ram/pigpio.c", PI_FILE_READ); -.br - -.br - if (handle >= 0) -.br - { -.br - while ((c=fileRead(handle, buf, sizeof(buf)-1))) -.br - { -.br - buf[c] = 0; -.br - printf("%s", buf); -.br - } -.br - -.br - fileClose(handle); -.br - } -.br - -.br - gpioTerminate(); -.br -} -.br - -.EE - -.IP "\fBint fileClose(unsigned handle)\fP" -.IP "" 4 -This function closes the file associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBfileOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -\fBExample\fP -.br - -.EX -fileClose(h); -.br - -.EE - -.IP "\fBint fileWrite(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the file -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBfileOpen\fP -.br - buf: the array of bytes to write -.br - count: the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. - -.br - -.br -\fBExample\fP -.br - -.EX -status = fileWrite(h, buf, count); -.br -if (status == 0) -.br -{ -.br - // okay -.br -} -.br -else -.br -{ -.br - // error -.br -} -.br - -.EE - -.IP "\fBint fileRead(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up to count bytes from the the file -associated with handle and writes them to buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBfileOpen\fP -.br - buf: an array to receive the read data -.br - count: the maximum number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. - -.br - -.br -\fBExample\fP -.br - -.EX -if (fileRead(h, buf, sizeof(buf)) > 0) -.br -{ -.br - // process read data -.br -} -.br - -.EE - -.IP "\fBint fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)\fP" -.IP "" 4 -This function seeks to a position within the file associated -with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBfileOpen\fP -.br -seekOffset: the number of bytes to move. Positive offsets -.br - move forward, negative offsets backwards. -.br - seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1), -.br - or PI_FROM_END (2) -.br - -.EE - -.br - -.br -Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. - -.br - -.br -\fBExample\fP -.br - -.EX -fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20 -.br - -.br -size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size -.br - -.br -pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position -.br - -.EE - -.IP "\fBint fileList(char *fpat, char *buf, unsigned count)\fP" -.IP "" 4 -This function returns a list of files which match a pattern. The -pattern may contain wildcards. - -.br - -.br - -.EX - fpat: file pattern to match -.br - buf: an array to receive the matching file names -.br -count: the maximum number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. - -.br - -.br -The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See \fBfileOpen\fP. - -.br - -.br -NOTE - -.br - -.br -The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int c; -.br - char buf[1000]; -.br - -.br - if (gpioInitialise() < 0) return 1; -.br - -.br - // assumes /opt/pigpio/access contains the following line -.br - // /ram/*.c r -.br - -.br - c = fileList("/ram/p*.c", buf, sizeof(buf)); -.br - -.br - if (c >= 0) -.br - { -.br - // terminate string -.br - buf[c] = 0; -.br - printf("%s", buf); -.br - } -.br - -.br - gpioTerminate(); -.br -} -.br - -.EE - -.IP "\fBint gpioCfgBufferSize(unsigned cfgMillis)\fP" -.IP "" 4 -Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX -cfgMillis: 100-10000 -.br - -.EE - -.br - -.br -The default setting is 120 milliseconds. - -.br - -.br -The intention is to allow for bursts of data and protection against -other processes hogging cpu time. - -.br - -.br -I haven't seen a process locked out for more than 100 milliseconds. - -.br - -.br -Making the buffer bigger uses a LOT of memory at the more frequent -sampling rates as shown in the following table in MBs. - -.br - -.br - -.EX - buffer milliseconds -.br - 120 250 500 1sec 2sec 4sec 8sec -.br - -.br - 1 16 31 55 107 --- --- --- -.br - 2 10 18 31 55 107 --- --- -.br -sample 4 8 12 18 31 55 107 --- -.br - rate 5 8 10 14 24 45 87 --- -.br - (us) 8 6 8 12 18 31 55 107 -.br - 10 6 8 10 14 24 45 87 -.br - -.EE - -.IP "\fBint gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)\fP" -.IP "" 4 -Configures pigpio to use a particular sample rate timed by a specified -peripheral. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX - cfgMicros: 1, 2, 4, 5, 8, 10 -.br -cfgPeripheral: 0 (PWM), 1 (PCM) -.br - cfgSource: deprecated, value is ignored -.br - -.EE - -.br - -.br -The timings are provided by the specified peripheral (PWM or PCM). - -.br - -.br -The default setting is 5 microseconds using the PCM peripheral. - -.br - -.br -The approximate CPU percentage used for each sample rate is: - -.br - -.br - -.EX -sample cpu -.br - rate % -.br - -.br - 1 25 -.br - 2 16 -.br - 4 11 -.br - 5 10 -.br - 8 15 -.br - 10 14 -.br - -.EE - -.br - -.br -A sample rate of 5 microseconds seeems to be the sweet spot. - -.IP "\fBint gpioCfgDMAchannel(unsigned DMAchannel)\fP" -.IP "" 4 -Configures pigpio to use the specified DMA channel. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX -DMAchannel: 0-14 -.br - -.EE - -.br - -.br -The default setting is to use channel 14. - -.IP "\fBint gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)\fP" -.IP "" 4 -Configures pigpio to use the specified DMA channels. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX - primaryChannel: 0-14 -.br -secondaryChannel: 0-14 -.br - -.EE - -.br - -.br -The default setting depends on whether the Pi has a BCM2711 chip or -not (currently only the Pi4B has a BCM2711). - -.br - -.br -The default setting for a non-BCM2711 is to use channel 14 for the -primary channel and channel 6 for the secondary channel. - -.br - -.br -The default setting for a BCM2711 is to use channel 7 for the -primary channel and channel 6 for the secondary channel. - -.br - -.br -The secondary channel is only used for the transmission of waves. - -.br - -.br -If possible use one of channels 0 to 6 for the secondary channel -(a full channel). - -.br - -.br -A full channel only requires one DMA control block regardless of the -length of a pulse delay. Channels 7 to 14 (lite channels) require -one DMA control block for each 16383 microseconds of delay. I.e. -a 10 second pulse delay requires one control block on a full channel -and 611 control blocks on a lite channel. - -.IP "\fBint gpioCfgPermissions(uint64_t updateMask)\fP" -.IP "" 4 -Configures pigpio to restrict GPIO updates via the socket or pipe -interfaces to the GPIO specified by the mask. Programs directly -calling the pigpio library (i.e. linked with -lpigpio are not -affected). A GPIO update is a write to a GPIO or a GPIO mode -change or any function which would force such an action. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX -updateMask: bit (1<=0 -.br -arg2: >=0 -.br -argx: extra (byte) arguments -.br -argc: number of extra arguments -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.IP "\fBint gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It differs from gpioCustom1 in that it returns an array of bytes -rather than just an integer. - -.br - -.br -The returned value is an integer indicating the number of returned bytes. - -.EX - arg1: >=0 -.br - argx: extra (byte) arguments -.br - argc: number of extra arguments -.br -retBuf: buffer for returned bytes -.br -retMax: maximum number of bytes to return -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.br - -.br -The number of returned bytes must be retMax or less. - -.IP "\fBint rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)\fP" -.IP "" 4 -This function adds a waveform representing SPI data to the -existing waveform (if any). - -.br - -.br - -.EX - spi: a pointer to a spi object -.br - offset: microseconds from the start of the waveform -.br - spiSS: the slave select GPIO -.br - buf: the bits to transmit, most significant bit first -.br - spiTxBits: the number of bits to write -.br -spiBitFirst: the first bit to read -.br - spiBitLast: the last bit to read -.br - spiBits: the number of bits to transfer -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. - -.br - -.br -Not intended for general use. - -.IP "\fBint rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)\fP" -.IP "" 4 -This function adds a number of pulses to the current waveform. - -.br - -.br - -.EX -numPulses: the number of pulses -.br - pulses: the array containing the pulses -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. - -.br - -.br -The advantage of this function over gpioWaveAddGeneric is that it -allows the setting of the flags field. - -.br - -.br -The pulses are interleaved in time order within the existing waveform -(if any). - -.br - -.br -Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. - -.br - -.br -If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. - -.br - -.br -Not intended for general use. - -.IP "\fBunsigned rawWaveCB(void)\fP" -.IP "" 4 -Returns the number of the cb being currently output. - -.br - -.br -Not intended for general use. - -.IP "\fBrawCbs_t *rawWaveCBAdr(int cbNum)\fP" -.IP "" 4 -Return the (Linux) address of contol block cbNum. - -.br - -.br - -.EX -cbNum: the cb of interest -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBuint32_t rawWaveGetOOL(int pos)\fP" -.IP "" 4 -Gets the OOL parameter stored at pos. - -.br - -.br - -.EX -pos: the position of interest. -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBvoid rawWaveSetOOL(int pos, uint32_t lVal)\fP" -.IP "" 4 -Sets the OOL parameter stored at pos to value. - -.br - -.br - -.EX - pos: the position of interest -.br -lVal: the value to write -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBuint32_t rawWaveGetOut(int pos)\fP" -.IP "" 4 -Gets the wave output parameter stored at pos. - -.br - -.br -DEPRECATED: use rawWaveGetOOL instead. - -.br - -.br - -.EX -pos: the position of interest. -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBvoid rawWaveSetOut(int pos, uint32_t lVal)\fP" -.IP "" 4 -Sets the wave output parameter stored at pos to value. - -.br - -.br -DEPRECATED: use rawWaveSetOOL instead. - -.br - -.br - -.EX - pos: the position of interest -.br -lVal: the value to write -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBuint32_t rawWaveGetIn(int pos)\fP" -.IP "" 4 -Gets the wave input value parameter stored at pos. - -.br - -.br -DEPRECATED: use rawWaveGetOOL instead. - -.br - -.br - -.EX -pos: the position of interest -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBvoid rawWaveSetIn(int pos, uint32_t lVal)\fP" -.IP "" 4 -Sets the wave input value stored at pos to value. - -.br - -.br -DEPRECATED: use rawWaveSetOOL instead. - -.br - -.br - -.EX - pos: the position of interest -.br -lVal: the value to write -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBrawWaveInfo_t rawWaveInfo(int wave_id)\fP" -.IP "" 4 -Gets details about the wave with id wave_id. - -.br - -.br - -.EX -wave_id: the wave of interest -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBint getBitInBytes(int bitPos, char *buf, int numBits)\fP" -.IP "" 4 -Returns the value of the bit bitPos bits from the start of buf. Returns -0 if bitPos is greater than or equal to numBits. - -.br - -.br - -.EX - bitPos: bit index from the start of buf -.br - buf: array of bits -.br -numBits: number of valid bits in buf -.br - -.EE - -.br - -.br - -.IP "\fBvoid putBitInBytes(int bitPos, char *buf, int bit)\fP" -.IP "" 4 -Sets the bit bitPos bits from the start of buf to bit. - -.br - -.br - -.EX -bitPos: bit index from the start of buf -.br - buf: array of bits -.br - bit: 0-1, value to set -.br - -.EE - -.br - -.br - -.IP "\fBdouble time_time(void)\fP" -.IP "" 4 -Return the current time in seconds since the Epoch. - -.IP "\fBvoid time_sleep(double seconds)\fP" -.IP "" 4 -Delay execution for a given number of seconds - -.br - -.br - -.EX -seconds: the number of seconds to sleep -.br - -.EE - -.IP "\fBvoid rawDumpWave(void)\fP" -.IP "" 4 -Used to print a readable version of the current waveform to stderr. - -.br - -.br -Not intended for general use. - -.IP "\fBvoid rawDumpScript(unsigned script_id)\fP" -.IP "" 4 -Used to print a readable version of a script to stderr. - -.br - -.br - -.EX -script_id: >=0, a script_id returned by \fBgpioStoreScript\fP -.br - -.EE - -.br - -.br -Not intended for general use. -.SH PARAMETERS - -.br - -.br - -.IP "\fBactive\fP: 0-1000000" 0 - -.br - -.br -The number of microseconds level changes are reported for once -a noise filter has been triggered (by \fBsteady\fP microseconds of -a stable level). - -.br - -.br - -.IP "\fBarg1\fP" 0 - -.br - -.br -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBarg2\fP" 0 - -.br - -.br -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBargc\fP" 0 -The count of bytes passed to a user customised function. - -.br - -.br - -.IP "\fB*argx\fP" 0 -A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. - -.br - -.br - -.IP "\fBbaud\fP" 0 -The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. - -.br - -.br - -.IP "\fBbit\fP" 0 -A value of 0 or 1. - -.br - -.br - -.IP "\fBbitPos\fP" 0 -A bit position within a byte or word. The least significant bit is -position 0. - -.br - -.br - -.IP "\fBbits\fP" 0 -A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. - -.br - -.br -A convenient way to set bit n is to or in (1<=0" 0 - -.br - -.br -The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. - -.br - -.br - -.IP "\fBgpio\fP" 0 - -.br - -.br -A Broadcom numbered GPIO, in the range 0-53. - -.br - -.br -There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through -GPIO53. - -.br - -.br -They are split into two banks. Bank 1 consists of GPIO0 through -GPIO31. Bank 2 consists of GPIO32 through GPIO53. - -.br - -.br -All the GPIO which are safe for the user to read and write are in -bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards -have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. - -.br - -.br -See \fBgpioHardwareRevision\fP. - -.br - -.br -The user GPIO are marked with an X in the following table. - -.br - -.br - -.EX - 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -.br -Type 1 X X - - X - - X X X X X - - X X -.br -Type 2 - - X X X - - X X X X X - - X X -.br -Type 3 X X X X X X X X X X X X X X -.br - -.br - 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 -.br -Type 1 - X X - - X X X X X - - - - - - -.br -Type 2 - X X - - - X X X X - X X X X X -.br -Type 3 X X X X X X X X X X X X - - - - -.br - -.EE - -.br - -.br - -.IP "\fBgpioAlertFunc_t\fP" 0 - -.EX -typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBgpioAlertFuncEx_t\fP" 0 - -.EX -typedef void (*eventFuncEx_t) -.br - (int event, int level, uint32_t tick, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioCfg*\fP" 0 - -.br - -.br -These functions are only effective if called before \fBgpioInitialise\fP. - -.br - -.br -\fBgpioCfgBufferSize\fP -.br -\fBgpioCfgClock\fP -.br -\fBgpioCfgDMAchannel\fP -.br -\fBgpioCfgDMAchannels\fP -.br -\fBgpioCfgPermissions\fP -.br -\fBgpioCfgInterfaces\fP -.br -\fBgpioCfgSocketPort\fP -.br -\fBgpioCfgMemAlloc\fP - -.br - -.br - -.IP "\fBgpioGetSamplesFunc_t\fP" 0 - -.EX -typedef void (*gpioGetSamplesFunc_t) -.br - (const gpioSample_t *samples, int numSamples); -.br - -.EE - -.br - -.br - -.IP "\fBgpioGetSamplesFuncEx_t\fP" 0 - -.EX -typedef void (*gpioGetSamplesFuncEx_t) -.br - (const gpioSample_t *samples, int numSamples, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioISRFunc_t\fP" 0 - -.EX -typedef void (*gpioISRFunc_t) -.br - (int gpio, int level, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBgpioISRFuncEx_t\fP" 0 - -.EX -typedef void (*gpioISRFuncEx_t) -.br - (int gpio, int level, uint32_t tick, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioPulse_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br - -.IP "\fBgpioSample_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioSample_t; -.br - -.EE - -.br - -.br - -.IP "\fBgpioSignalFunc_t\fP" 0 - -.EX -typedef void (*gpioSignalFunc_t) (int signum); -.br - -.EE - -.br - -.br - -.IP "\fBgpioSignalFuncEx_t\fP" 0 - -.EX -typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioThreadFunc_t\fP" 0 - -.EX -typedef void *(gpioThreadFunc_t) (void *); -.br - -.EE - -.br - -.br - -.IP "\fBgpioTimerFunc_t\fP" 0 - -.EX -typedef void (*gpioTimerFunc_t) (void); -.br - -.EE - -.br - -.br - -.IP "\fBgpioTimerFuncEx_t\fP" 0 - -.EX -typedef void (*gpioTimerFuncEx_t) (void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioWaveAdd*\fP" 0 - -.br - -.br -One of - -.br - -.br -\fBgpioWaveAddNew\fP -.br -\fBgpioWaveAddGeneric\fP -.br -\fBgpioWaveAddSerial\fP - -.br - -.br - -.IP "\fBhandle\fP: >=0" 0 - -.br - -.br -A number referencing an object opened by one of - -.br - -.br -\fBfileOpen\fP -.br -\fBgpioNotifyOpen\fP -.br -\fBi2cOpen\fP -.br -\fBserOpen\fP -.br -\fBspiOpen\fP - -.br - -.br - -.IP "\fBi2cAddr\fP: 0-0x7F" 0 -The address of a device on the I2C bus. - -.br - -.br - -.IP "\fBi2cBus\fP: >=0" 0 - -.br - -.br -An I2C bus number. - -.br - -.br - -.IP "\fBi2cFlags\fP: 0" 0 - -.br - -.br -Flags which modify an I2C open command. None are currently defined. - -.br - -.br - -.IP "\fBi2cReg\fP: 0-255" 0 - -.br - -.br -A register of an I2C device. - -.br - -.br - -.IP "\fBifFlags\fP: 0-3" 0 - -.EX -PI_DISABLE_FIFO_IF 1 -.br -PI_DISABLE_SOCK_IF 2 -.br - -.EE - -.br - -.br - -.IP "\fB*inBuf\fP" 0 -A buffer used to pass data to a function. - -.br - -.br - -.IP "\fBinLen\fP" 0 -The number of bytes of data in a buffer. - -.br - -.br - -.IP "\fBint\fP" 0 -A whole number, negative or positive. - -.br - -.br - -.IP "\fBint32_t\fP" 0 -A 32-bit signed value. - -.br - -.br - -.IP "\fBinvert\fP" 0 -A flag used to set normal or inverted bit bang serial data level logic. - -.br - -.br - -.IP "\fBlevel\fP" 0 -The level of a GPIO. Low or High. - -.br - -.br - -.EX -PI_OFF 0 -.br -PI_ON 1 -.br - -.br -PI_CLEAR 0 -.br -PI_SET 1 -.br - -.br -PI_LOW 0 -.br -PI_HIGH 1 -.br - -.EE - -.br - -.br -There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See \fBgpioSetWatchdog\fP. - -.br - -.br - -.EX -PI_TIMEOUT 2 -.br - -.EE - -.br - -.br - -.br - -.br - -.IP "\fBlVal\fP: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)" 0 - -.br - -.br -A 32-bit word value. - -.br - -.br - -.IP "\fBmemAllocMode\fP: 0-2" 0 - -.br - -.br -The DMA memory allocation mode. - -.br - -.br - -.EX -PI_MEM_ALLOC_AUTO 0 -.br -PI_MEM_ALLOC_PAGEMAP 1 -.br -PI_MEM_ALLOC_MAILBOX 2 -.br - -.EE - -.br - -.br - -.IP "\fB*micros\fP" 0 - -.br - -.br -A value representing microseconds. - -.br - -.br - -.IP "\fBmicros\fP" 0 - -.br - -.br -A value representing microseconds. - -.br - -.br - -.IP "\fBmillis\fP" 0 - -.br - -.br -A value representing milliseconds. - -.br - -.br - -.IP "\fBMISO\fP" 0 -The GPIO used for the MISO signal when bit banging SPI. - -.br - -.br - -.IP "\fBmode\fP" 0 - -.br - -.br -1. The operational mode of a GPIO, normally INPUT or OUTPUT. - -.br - -.br - -.EX -PI_INPUT 0 -.br -PI_OUTPUT 1 -.br -PI_ALT0 4 -.br -PI_ALT1 5 -.br -PI_ALT2 6 -.br -PI_ALT3 7 -.br -PI_ALT4 3 -.br -PI_ALT5 2 -.br - -.EE - -.br - -.br -2. A file open mode. - -.br - -.br - -.EX -PI_FILE_READ 1 -.br -PI_FILE_WRITE 2 -.br -PI_FILE_RW 3 -.br - -.EE - -.br - -.br -The following values can be or'd into the mode. - -.br - -.br - -.EX -PI_FILE_APPEND 4 -.br -PI_FILE_CREATE 8 -.br -PI_FILE_TRUNC 16 -.br - -.EE - -.br - -.br - -.IP "\fBMOSI\fP" 0 -The GPIO used for the MOSI signal when bit banging SPI. - -.br - -.br - -.IP "\fBnumBits\fP" 0 - -.br - -.br -The number of bits stored in a buffer. - -.br - -.br - -.IP "\fBnumBytes\fP" 0 -The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. - -.br - -.br - -.IP "\fBnumPar\fP: 0-10" 0 -The number of parameters passed to a script. - -.br - -.br - -.IP "\fBnumPulses\fP" 0 -The number of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBnumSegs\fP" 0 -The number of segments in a combined I2C transaction. - -.br - -.br - -.IP "\fBnumSockAddr\fP" 0 -The number of network addresses allowed to use the socket interface. - -.br - -.br -0 means all addresses allowed. - -.br - -.br - -.IP "\fBoffset\fP" 0 -The associated data starts this number of microseconds from the start of -the waveform. - -.br - -.br - -.IP "\fB*outBuf\fP" 0 -A buffer used to return data from a function. - -.br - -.br - -.IP "\fBoutLen\fP" 0 -The size in bytes of an output buffer. - -.br - -.br - -.IP "\fBpad\fP: 0-2" 0 -A set of GPIO which share common drivers. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br - -.IP "\fBpadStrength\fP: 1-16" 0 -The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. - -.br - -.br - -.IP "\fB*param\fP" 0 -An array of script parameters. - -.br - -.br - -.IP "\fBpctBOOL\fP: 0-100" 0 -percent On-Off-Level (OOL) buffer to consume for wave output. - -.br - -.br - -.IP "\fBpctCB\fP: 0-100" 0 -the percent of all DMA control blocks to consume. - -.br - -.br - -.IP "\fBpctTOOL\fP: 0-100" 0 -the percent of OOL buffer to consume for wave input (flags). - -.br - -.br - -.IP "\fBpi_i2c_msg_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint16_t addr; // slave address -.br - uint16_t flags; -.br - uint16_t len; // msg length -.br - uint8_t *buf; // pointer to msg data -.br -} pi_i2c_msg_t; -.br - -.EE - -.br - -.br - -.IP "\fBport\fP: 1024-32000" 0 -The port used to bind to the pigpio socket. Defaults to 8888. - -.br - -.br - -.IP "\fBpos\fP" 0 -The position of an item. - -.br - -.br - -.IP "\fBprimaryChannel\fP: 0-15" 0 -The DMA channel used to time the sampling of GPIO and to time servo and -PWM pulses. - -.br - -.br - -.IP "\fB*pth\fP" 0 - -.br - -.br -A thread identifier, returned by \fBgpioStartThread\fP. - -.br - -.br - -.IP "\fBpthread_t\fP" 0 - -.br - -.br -A thread identifier. - -.br - -.br - -.IP "\fBpud\fP: 0-2" 0 - -.br - -.br -The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. - -.br - -.br - -.EX -PI_PUD_OFF 0 -.br -PI_PUD_DOWN 1 -.br -PI_PUD_UP 2 -.br - -.EE - -.br - -.br - -.IP "\fBpulseLen\fP" 0 - -.br - -.br -1-100, the length of a trigger pulse in microseconds. - -.br - -.br - -.IP "\fB*pulses\fP" 0 - -.br - -.br -An array of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBpulsewidth\fP: 0, 500-2500" 0 - -.EX -PI_SERVO_OFF 0 -.br -PI_MIN_SERVO_PULSEWIDTH 500 -.br -PI_MAX_SERVO_PULSEWIDTH 2500 -.br - -.EE - -.br - -.br - -.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 -The hardware PWM dutycycle. - -.br - -.br - -.EX -PI_HW_PWM_RANGE 1000000 -.br - -.EE - -.br - -.br - -.IP "\fBPWMfreq\fP: 1-125M (1-187.5M for the BCM2711)" 0 -The hardware PWM frequency. - -.br - -.br - -.EX -PI_HW_PWM_MIN_FREQ 1 -.br -PI_HW_PWM_MAX_FREQ 125000000 -.br -PI_HW_PWM_MAX_FREQ_2711 187500000 -.br - -.EE - -.br - -.br - -.IP "\fBrange\fP: 25-40000" 0 - -.EX -PI_MIN_DUTYCYCLE_RANGE 25 -.br -PI_MAX_DUTYCYCLE_RANGE 40000 -.br - -.EE - -.br - -.br - -.IP "\fBrawCbs_t\fP" 0 - -.EX -typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h -.br -{ -.br - unsigned long info; -.br - unsigned long src; -.br - unsigned long dst; -.br - unsigned long length; -.br - unsigned long stride; -.br - unsigned long next; -.br - unsigned long pad[2]; -.br -} rawCbs_t; -.br - -.EE - -.br - -.br - -.IP "\fBrawSPI_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - int clk; // GPIO for clock -.br - int mosi; // GPIO for MOSI -.br - int miso; // GPIO for MISO -.br - int ss_pol; // slave select off state -.br - int ss_us; // delay after slave select -.br - int clk_pol; // clock off state -.br - int clk_pha; // clock phase -.br - int clk_us; // clock micros -.br -} rawSPI_t; -.br - -.EE - -.br - -.br - -.IP "\fBrawWave_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br - uint32_t flags; -.br -} rawWave_t; -.br - -.EE - -.br - -.br - -.IP "\fBrawWaveInfo_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint16_t botCB; // first CB used by wave -.br - uint16_t topCB; // last CB used by wave -.br - uint16_t botOOL; // last OOL used by wave -.br - uint16_t topOOL; // first OOL used by wave -.br - uint16_t deleted; -.br - uint16_t numCB; -.br - uint16_t numBOOL; -.br - uint16_t numTOOL; -.br -} rawWaveInfo_t; -.br - -.EE - -.br - -.br - -.IP "\fB*retBuf\fP" 0 - -.br - -.br -A buffer to hold a number of bytes returned to a used customised function, - -.br - -.br - -.IP "\fBretMax\fP" 0 - -.br - -.br -The maximum number of bytes a user customised function should return. - -.br - -.br - -.IP "\fB*rxBuf\fP" 0 - -.br - -.br -A pointer to a buffer to receive data. - -.br - -.br - -.IP "\fBSCL\fP" 0 -The user GPIO to use for the clock when bit banging I2C. - -.br - -.br - -.IP "\fBSCLK\fP" 0 -The GPIO used for the SCLK signal when bit banging SPI. - -.br - -.br - -.IP "\fB*script\fP" 0 -A pointer to the text of a script. - -.br - -.br - -.IP "\fBscript_id\fP" 0 -An id of a stored script as returned by \fBgpioStoreScript\fP. - -.br - -.br - -.IP "\fB*scriptName\fP" 0 -The name of a \fBshell\fP script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. - -.br - -.br - -.IP "\fB*scriptString\fP" 0 -The string to be passed to a \fBshell\fP script to be executed. - -.br - -.br - -.IP "\fBSDA\fP" 0 -The user GPIO to use for data when bit banging I2C. - -.br - -.br - -.IP "\fBsecondaryChannel\fP: 0-6" 0 - -.br - -.br -The DMA channel used to time output waveforms. - -.br - -.br - -.IP "\fB*seconds\fP" 0 - -.br - -.br -A pointer to a uint32_t to store the second component of -a returned time. - -.br - -.br - -.IP "\fBseconds\fP" 0 -The number of seconds. - -.br - -.br - -.IP "\fBseekFrom\fP" 0 - -.br - -.br - -.EX -PI_FROM_START 0 -.br -PI_FROM_CURRENT 1 -.br -PI_FROM_END 2 -.br - -.EE - -.br - -.br - -.IP "\fBseekOffset\fP" 0 -The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). - -.br - -.br - -.IP "\fB*segs\fP" 0 -An array of segments which make up a combined I2C transaction. - -.br - -.br - -.IP "\fBserFlags\fP" 0 -Flags which modify a serial open command. None are currently defined. - -.br - -.br - -.IP "\fB*sertty\fP" 0 -The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. - -.br - -.br - -.IP "\fBsetting\fP" 0 -A value used to set a flag, 0 for false, non-zero for true. - -.br - -.br - -.IP "\fBsignum\fP: 0-63" 0 - -.EX -PI_MIN_SIGNUM 0 -.br -PI_MAX_SIGNUM 63 -.br - -.EE - -.br - -.br - -.IP "\fBsize_t\fP" 0 - -.br - -.br -A standard type used to indicate the size of an object in bytes. - -.br - -.br - -.IP "\fB*sockAddr\fP" 0 -An array of network addresses allowed to use the socket interface encoded -as 32 bit numbers. - -.br - -.br -E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. - -.br - -.br - -.IP "\fB*spi\fP" 0 -A pointer to a \fBrawSPI_t\fP structure. - -.br - -.br - -.IP "\fBspiBitFirst\fP" 0 -GPIO reads are made from spiBitFirst to spiBitLast. - -.br - -.br - -.IP "\fBspiBitLast\fP" 0 - -.br - -.br -GPIO reads are made from spiBitFirst to spiBitLast. - -.br - -.br - -.IP "\fBspiBits\fP" 0 -The number of bits to transfer in a raw SPI transaction. - -.br - -.br - -.IP "\fBspiChan\fP" 0 -A SPI channel, 0-2. - -.br - -.br - -.IP "\fBspiFlags\fP" 0 -See \fBspiOpen\fP and \fBbbSPIOpen\fP. - -.br - -.br - -.IP "\fBspiSS\fP" 0 -The SPI slave select GPIO in a raw SPI transaction. - -.br - -.br - -.IP "\fBspiTxBits\fP" 0 -The number of bits to transfer dring a raw SPI transaction - -.br - -.br - -.IP "\fBsteady\fP: 0-300000" 0 - -.br - -.br -The number of microseconds level changes must be stable for -before reporting the level changed (\fBgpioGlitchFilter\fP) or triggering -the active part of a noise filter (\fBgpioNoiseFilter\fP). - -.br - -.br - -.IP "\fBstop_bits\fP: 2-8" 0 -The number of (half) stop bits to be used when adding serial data -to a waveform. - -.br - -.br - -.EX -PI_MIN_WAVE_HALFSTOPBITS 2 -.br -PI_MAX_WAVE_HALFSTOPBITS 8 -.br - -.EE - -.br - -.br - -.IP "\fB*str\fP" 0 -An array of characters. - -.br - -.br - -.IP "\fBtimeout\fP" 0 -A GPIO level change timeout in milliseconds. - -.br - -.br -\fBgpioSetWatchdog\fP - -.EX -PI_MIN_WDOG_TIMEOUT 0 -.br -PI_MAX_WDOG_TIMEOUT 60000 -.br - -.EE - -.br - -.br -\fBgpioSetISRFunc\fP and \fBgpioSetISRFuncEx\fP - -.EX -<=0 cancel timeout -.br ->0 timeout after specified milliseconds -.br - -.EE - -.br - -.br - -.IP "\fBtimer\fP" 0 - -.EX -PI_MIN_TIMER 0 -.br -PI_MAX_TIMER 9 -.br - -.EE - -.br - -.br - -.IP "\fBtimetype\fP" 0 - -.EX -PI_TIME_RELATIVE 0 -.br -PI_TIME_ABSOLUTE 1 -.br - -.EE - -.br - -.br - -.IP "\fB*txBuf\fP" 0 - -.br - -.br -An array of bytes to transmit. - -.br - -.br - -.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 - -.br - -.br -A 32-bit unsigned value. - -.br - -.br - -.IP "\fBuint64_t\fP: 0-(2^64)-1" 0 - -.br - -.br -A 64-bit unsigned value. - -.br - -.br - -.IP "\fBunsigned\fP" 0 - -.br - -.br -A whole number >= 0. - -.br - -.br - -.IP "\fBupdateMask\fP" 0 - -.br - -.br -A 64 bit mask indicating which GPIO may be written to by the user. - -.br - -.br -If GPIO#n may be written then bit (1< 4 -.br -#define PI_BAD_CHANNEL -27 // DMA channel not 0-15 -.br -#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15 -.br -#define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000 -.br -#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command -.br -#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15 -.br -#define PI_NOT_INITIALISED -31 // function called before gpioInitialise -.br -#define PI_INITIALISED -32 // function called after gpioInitialise -.br -#define PI_BAD_WAVE_MODE -33 // waveform mode not 0-3 -.br -#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call -.br -#define PI_BAD_WAVE_BAUD -35 // baud rate not 50-250K(RX)/50-1M(TX) -.br -#define PI_TOO_MANY_PULSES -36 // waveform has too many pulses -.br -#define PI_TOO_MANY_CHARS -37 // waveform has too many chars -.br -#define PI_NOT_SERIAL_GPIO -38 // no bit bang serial read on GPIO -.br -#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter -.br -#define PI_BAD_SERIAL_BUF -40 // bad (null) serial buf parameter -.br -#define PI_NOT_PERMITTED -41 // GPIO operation not permitted -.br -#define PI_SOME_PERMITTED -42 // one or more GPIO not permitted -.br -#define PI_BAD_WVSC_COMMND -43 // bad WVSC subcommand -.br -#define PI_BAD_WVSM_COMMND -44 // bad WVSM subcommand -.br -#define PI_BAD_WVSP_COMMND -45 // bad WVSP subcommand -.br -#define PI_BAD_PULSELEN -46 // trigger pulse length not 1-100 -.br -#define PI_BAD_SCRIPT -47 // invalid script -.br -#define PI_BAD_SCRIPT_ID -48 // unknown script id -.br -#define PI_BAD_SER_OFFSET -49 // add serial data offset > 30 minutes -.br -#define PI_GPIO_IN_USE -50 // GPIO already in use -.br -#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time -.br -#define PI_BAD_PARAM_NUM -52 // script parameter id not 0-9 -.br -#define PI_DUP_TAG -53 // script has duplicate tag -.br -#define PI_TOO_MANY_TAGS -54 // script has too many tags -.br -#define PI_BAD_SCRIPT_CMD -55 // illegal script command -.br -#define PI_BAD_VAR_NUM -56 // script variable id not 0-149 -.br -#define PI_NO_SCRIPT_ROOM -57 // no more room for scripts -.br -#define PI_NO_MEMORY -58 // can't allocate temporary memory -.br -#define PI_SOCK_READ_FAILED -59 // socket read failed -.br -#define PI_SOCK_WRIT_FAILED -60 // socket write failed -.br -#define PI_TOO_MANY_PARAM -61 // too many script parameters (> 10) -.br -#define PI_NOT_HALTED -62 // DEPRECATED -.br -#define PI_SCRIPT_NOT_READY -62 // script initialising -.br -#define PI_BAD_TAG -63 // script has unresolved tag -.br -#define PI_BAD_MICS_DELAY -64 // bad MICS delay (too large) -.br -#define PI_BAD_MILS_DELAY -65 // bad MILS delay (too large) -.br -#define PI_BAD_WAVE_ID -66 // non existent wave id -.br -#define PI_TOO_MANY_CBS -67 // No more CBs for waveform -.br -#define PI_TOO_MANY_OOL -68 // No more OOL for waveform -.br -#define PI_EMPTY_WAVEFORM -69 // attempt to create an empty waveform -.br -#define PI_NO_WAVEFORM_ID -70 // no more waveforms -.br -#define PI_I2C_OPEN_FAILED -71 // can't open I2C device -.br -#define PI_SER_OPEN_FAILED -72 // can't open serial device -.br -#define PI_SPI_OPEN_FAILED -73 // can't open SPI device -.br -#define PI_BAD_I2C_BUS -74 // bad I2C bus -.br -#define PI_BAD_I2C_ADDR -75 // bad I2C address -.br -#define PI_BAD_SPI_CHANNEL -76 // bad SPI channel -.br -#define PI_BAD_FLAGS -77 // bad i2c/spi/ser open flags -.br -#define PI_BAD_SPI_SPEED -78 // bad SPI speed -.br -#define PI_BAD_SER_DEVICE -79 // bad serial device name -.br -#define PI_BAD_SER_SPEED -80 // bad serial baud rate -.br -#define PI_BAD_PARAM -81 // bad i2c/spi/ser parameter -.br -#define PI_I2C_WRITE_FAILED -82 // i2c write failed -.br -#define PI_I2C_READ_FAILED -83 // i2c read failed -.br -#define PI_BAD_SPI_COUNT -84 // bad SPI count -.br -#define PI_SER_WRITE_FAILED -85 // ser write failed -.br -#define PI_SER_READ_FAILED -86 // ser read failed -.br -#define PI_SER_READ_NO_DATA -87 // ser read no data available -.br -#define PI_UNKNOWN_COMMAND -88 // unknown command -.br -#define PI_SPI_XFER_FAILED -89 // spi xfer/read/write failed -.br -#define PI_BAD_POINTER -90 // bad (NULL) pointer -.br -#define PI_NO_AUX_SPI -91 // no auxiliary SPI on Pi A or B -.br -#define PI_NOT_PWM_GPIO -92 // GPIO is not in use for PWM -.br -#define PI_NOT_SERVO_GPIO -93 // GPIO is not in use for servo pulses -.br -#define PI_NOT_HCLK_GPIO -94 // GPIO has no hardware clock -.br -#define PI_NOT_HPWM_GPIO -95 // GPIO has no hardware PWM -.br -#define PI_BAD_HPWM_FREQ -96 // invalid hardware PWM frequency -.br -#define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M -.br -#define PI_BAD_HCLK_FREQ -98 // invalid hardware clock frequency -.br -#define PI_BAD_HCLK_PASS -99 // need password to use hardware clock 1 -.br -#define PI_HPWM_ILLEGAL -100 // illegal, PWM in use for main clock -.br -#define PI_BAD_DATABITS -101 // serial data bits not 1-32 -.br -#define PI_BAD_STOPBITS -102 // serial (half) stop bits not 2-8 -.br -#define PI_MSG_TOOBIG -103 // socket/pipe message too big -.br -#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode -.br -#define PI_TOO_MANY_SEGS -105 // too many I2C transaction segments -.br -#define PI_BAD_I2C_SEG -106 // an I2C transaction segment failed -.br -#define PI_BAD_SMBUS_CMD -107 // SMBus command not supported by driver -.br -#define PI_NOT_I2C_GPIO -108 // no bit bang I2C in progress on GPIO -.br -#define PI_BAD_I2C_WLEN -109 // bad I2C write length -.br -#define PI_BAD_I2C_RLEN -110 // bad I2C read length -.br -#define PI_BAD_I2C_CMD -111 // bad I2C command -.br -#define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k -.br -#define PI_CHAIN_LOOP_CNT -113 // bad chain loop count -.br -#define PI_BAD_CHAIN_LOOP -114 // empty chain loop -.br -#define PI_CHAIN_COUNTER -115 // too many chain counters -.br -#define PI_BAD_CHAIN_CMD -116 // bad chain command -.br -#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros -.br -#define PI_CHAIN_NESTING -118 // chain counters nested too deeply -.br -#define PI_CHAIN_TOO_BIG -119 // chain is too long -.br -#define PI_DEPRECATED -120 // deprecated function removed -.br -#define PI_BAD_SER_INVERT -121 // bit bang serial invert not 0 or 1 -.br -#define PI_BAD_EDGE -122 // bad ISR edge value, not 0-2 -.br -#define PI_BAD_ISR_INIT -123 // bad ISR initialisation -.br -#define PI_BAD_FOREVER -124 // loop forever must be last command -.br -#define PI_BAD_FILTER -125 // bad filter parameter -.br -#define PI_BAD_PAD -126 // bad pad number -.br -#define PI_BAD_STRENGTH -127 // bad pad drive strength -.br -#define PI_FIL_OPEN_FAILED -128 // file open failed -.br -#define PI_BAD_FILE_MODE -129 // bad file mode -.br -#define PI_BAD_FILE_FLAG -130 // bad file flag -.br -#define PI_BAD_FILE_READ -131 // bad file read -.br -#define PI_BAD_FILE_WRITE -132 // bad file write -.br -#define PI_FILE_NOT_ROPEN -133 // file not open for read -.br -#define PI_FILE_NOT_WOPEN -134 // file not open for write -.br -#define PI_BAD_FILE_SEEK -135 // bad file seek -.br -#define PI_NO_FILE_MATCH -136 // no files match pattern -.br -#define PI_NO_FILE_ACCESS -137 // no permission to access file -.br -#define PI_FILE_IS_A_DIR -138 // file is a directory -.br -#define PI_BAD_SHELL_STATUS -139 // bad shell return status -.br -#define PI_BAD_SCRIPT_NAME -140 // bad script name -.br -#define PI_BAD_SPI_BAUD -141 // bad SPI baud rate, not 50-500k -.br -#define PI_NOT_SPI_GPIO -142 // no bit bang SPI in progress on GPIO -.br -#define PI_BAD_EVENT_ID -143 // bad event id -.br -#define PI_CMD_INTERRUPTED -144 // Used by Python -.br -#define PI_NOT_ON_BCM2711 -145 // not available on BCM2711 -.br -#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711 -.br - -.br -#define PI_PIGIF_ERR_0 -2000 -.br -#define PI_PIGIF_ERR_99 -2099 -.br - -.br -#define PI_CUSTOM_ERR_0 -3000 -.br -#define PI_CUSTOM_ERR_999 -3999 -.br - -.br - -.EE -.SH Defaults - -.EX - -.br -#define PI_DEFAULT_BUFFER_MILLIS 120 -.br -#define PI_DEFAULT_CLK_MICROS 5 -.br -#define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM -.br -#define PI_DEFAULT_IF_FLAGS 0 -.br -#define PI_DEFAULT_FOREGROUND 0 -.br -#define PI_DEFAULT_DMA_CHANNEL 14 -.br -#define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14 -.br -#define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6 -.br -#define PI_DEFAULT_DMA_PRIMARY_CH_2711 7 -.br -#define PI_DEFAULT_DMA_SECONDARY_CH_2711 6 -.br -#define PI_DEFAULT_DMA_NOT_SET 15 -.br -#define PI_DEFAULT_SOCKET_PORT 8888 -.br -#define PI_DEFAULT_SOCKET_PORT_STR "8888" -.br -#define PI_DEFAULT_SOCKET_ADDR_STR "localhost" -.br -#define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_B1 0x03E7CF93 -.br -#define PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC7CF9C -.br -#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_ZERO 0x0080000FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_PI2B 0x0080480FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_PI3B 0x0000000FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_PI4B 0x0000000FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL -.br -#define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO -.br - -.br -#define PI_DEFAULT_CFG_INTERNALS 0 -.br - -.br - -.EE - -.SH SEE ALSO - -pigpiod(1), pig2vcd(1), pigs(1), pigpiod_if(3), pigpiod_if2(3) -.SH AUTHOR - -joan@abyz.me.uk diff --git a/DOC/MAN/pigpiod.1 b/DOC/MAN/pigpiod.1 deleted file mode 100644 index 29f8326..0000000 --- a/DOC/MAN/pigpiod.1 +++ /dev/null @@ -1,273 +0,0 @@ - -." Process this file with -." groff -man -Tascii pigpiod.1 -." -.TH pigpiod 1 2012-2020 Linux "pigpio archive" -.SH NAME -pigpiod - A utility to start the pigpio library as a daemon. - -.SH SYNOPSIS - -sudo pigpiod [OPTION]... -.SH DESCRIPTION - - -.ad l - -.nh -pigpiod is a utility which launches the pigpio library as a daemon. -.br - -.br -Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces. -.br - -.br -The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users. -.br - -.br -pigpiod accepts the following configuration options -.br - -.br -.SH OPTIONS - -.IP "\fB-a value\fP" -DMA memory allocation mode. -0=AUTO, 1=PMAP, 2=MBOX. -Default AUTO -. -.IP "\fB-b value\fP" -GPIO sample buffer size in milliseconds. -100-10000. -Default 120 -. -.IP "\fB-c value\fP" -Library internal settings. -. -Default 0 -. -.IP "\fB-d value\fP" -Primary DMA channel. -0-14. -Default 14 -. -.IP "\fB-e value\fP" -Secondary DMA channel. -0-14. -Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel -. -.IP "\fB-f\fP" -Disable fifo interface. -. -Default enabled -. -.IP "\fB-g\fP" -Run in foreground (do not fork). -. -Default disabled -. -.IP "\fB-k\fP" -Disable local and remote socket interface. -. -Default enabled -. -.IP "\fB-l\fP" -Disable remote socket interface. -. -Default enabled -. -.IP "\fB-m\fP" -Disable alerts (sampling). -. -Default enabled -. -.IP "\fB-n IP address\fP" -Allow IP address to use the socket interface. -Name (e.g. paul) or dotted quad (e.g. 192.168.1.66). -If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect -. -.IP "\fB-p value\fP" -Socket port. -1024-32000. -Default 8888 -. -.IP "\fB-s value\fP" -Sample rate. -1, 2, 4, 5, 8, or 10 microseconds. -Default 5 -. -.IP "\fB-t value\fP" -Clock peripheral. -0=PWM 1=PCM. -Default PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. -. -.IP "\fB-v -V\fP" -Display pigpio version and exit. -. - -. -.IP "\fB-x mask\fP" -GPIO which may be updated. -A 54 bit mask with (1< - - -gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt - - ./prog -.SH DESCRIPTION - - -.ad l - -.nh - -.br - -.br -THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO -USE THE MORE VERSATILE pigpiod_if2 LIBRARY. - -.br - -.br -pigpiod_if is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon. -.br - -.br - -.br -.SS Features -.br - -.br -o hardware timed PWM on any of GPIO 0-31 - -.br - -.br -o hardware timed servo pulses on any of GPIO 0-31 - -.br - -.br -o callbacks when any of GPIO 0-31 change state - -.br - -.br -o callbacks at timed intervals - -.br - -.br -o reading/writing all of the GPIO in a bank as one operation - -.br - -.br -o individually setting GPIO modes, reading and writing - -.br - -.br -o notifications when any of GPIO 0-31 change state - -.br - -.br -o the construction of output waveforms with microsecond timing - -.br - -.br -o rudimentary permission control over GPIO - -.br - -.br -o a simple interface to start and stop new threads - -.br - -.br -o I2C, SPI, and serial link wrappers - -.br - -.br -o creating and running scripts on the pigpio daemon - -.br - -.br -.SS GPIO -.br - -.br -ALL GPIO are identified by their Broadcom number. - -.br - -.br -.SS Notes -.br - -.br -The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. - -.br - -.br -.SS Usage -.br - -.br -Include in your source files. - -.br - -.br -Assuming your source is in prog.c use the following command to build - -.br - -.br - -.EX -gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt -.br - -.EE - -.br - -.br -to run make sure the pigpio daemon is running - -.br - -.br - -.EX -sudo pigpiod -.br - -.br - ./prog # sudo is not required to run programs linked to pigpiod_if -.br - -.EE - -.br - -.br -For examples see x_pigpiod_if.c within the pigpio archive file. - -.br - -.br -.SS Notes -.br - -.br -All the functions which return an int return < 0 on error - -.br - -.br - -.SH OVERVIEW - -.br -.SS ESSENTIAL -.br - -.br -pigpio_start Connects to the pigpio daemon -.br -pigpio_stop Disconnects from the pigpio daemon -.br -.SS BEGINNER -.br - -.br -set_mode Set a GPIO mode -.br -get_mode Get a GPIO mode -.br - -.br -set_pull_up_down Set/clear GPIO pull up/down resistor -.br - -.br -gpio_read Read a GPIO -.br -gpio_write Write a GPIO -.br - -.br -set_PWM_dutycycle Start/stop PWM pulses on a GPIO -.br -get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -.br - -.br -set_servo_pulsewidth Start/stop servo pulses on a GPIO -.br -get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -.br - -.br -callback Create GPIO level change callback -.br -callback_ex Create GPIO level change callback -.br -callback_cancel Cancel a callback -.br -wait_for_edge Wait for GPIO level change -.br -.SS INTERMEDIATE -.br - -.br -gpio_trigger Send a trigger pulse to a GPIO. -.br - -.br -set_watchdog Set a watchdog on a GPIO. -.br - -.br -set_PWM_range Configure PWM range for a GPIO -.br -get_PWM_range Get configured PWM range for a GPIO -.br - -.br -set_PWM_frequency Configure PWM frequency for a GPIO -.br -get_PWM_frequency Get configured PWM frequency for a GPIO -.br - -.br -read_bank_1 Read all GPIO in bank 1 -.br -read_bank_2 Read all GPIO in bank 2 -.br - -.br -clear_bank_1 Clear selected GPIO in bank 1 -.br -clear_bank_2 Clear selected GPIO in bank 2 -.br - -.br -set_bank_1 Set selected GPIO in bank 1 -.br -set_bank_2 Set selected GPIO in bank 2 -.br - -.br -start_thread Start a new thread -.br -stop_thread Stop a previously started thread -.br -.SS ADVANCED -.br - -.br -get_PWM_real_range Get underlying PWM range for a GPIO -.br - -.br -notify_open Request a notification handle -.br -notify_begin Start notifications for selected GPIO -.br -notify_pause Pause notifications -.br -notify_close Close a notification -.br - -.br -bb_serial_read_open Opens a GPIO for bit bang serial reads -.br -bb_serial_read Reads bit bang serial data from a GPIO -.br -bb_serial_read_close Closes a GPIO for bit bang serial reads -.br -bb_serial_invert Invert serial logic (1 invert, 0 normal) -.br - -.br -hardware_clock Start hardware clock on supported GPIO -.br -hardware_PWM Start hardware PWM on supported GPIO -.br - -.br -set_glitch_filter Set a glitch filter on a GPIO -.br -set_noise_filter Set a noise filter on a GPIO -.br -.SS SCRIPTS -.br - -.br -store_script Store a script -.br -run_script Run a stored script -.br -script_status Get script status and parameters -.br -stop_script Stop a running script -.br -delete_script Delete a stored script -.br -.SS WAVES -.br - -.br -wave_clear Deletes all waveforms -.br - -.br -wave_add_new Starts a new waveform -.br -wave_add_generic Adds a series of pulses to the waveform -.br -wave_add_serial Adds serial data to the waveform -.br - -.br -wave_create Creates a waveform from added data -.br -wave_delete Deletes one or more waveforms -.br - -.br -wave_send_once Transmits a waveform once -.br -wave_send_repeat Transmits a waveform repeatedly -.br - -.br -wave_chain Transmits a chain of waveforms -.br - -.br -wave_tx_busy Checks to see if the waveform has ended -.br -wave_tx_stop Aborts the current waveform -.br - -.br -wave_get_micros Length in microseconds of the current waveform -.br -wave_get_high_micros Length of longest waveform so far -.br -wave_get_max_micros Absolute maximum allowed micros -.br - -.br -wave_get_pulses Length in pulses of the current waveform -.br -wave_get_high_pulses Length of longest waveform so far -.br -wave_get_max_pulses Absolute maximum allowed pulses -.br - -.br -wave_get_cbs Length in cbs of the current waveform -.br -wave_get_high_cbs Length of longest waveform so far -.br -wave_get_max_cbs Absolute maximum allowed cbs -.br -.SS I2C -.br - -.br -i2c_open Opens an I2C device -.br -i2c_close Closes an I2C device -.br - -.br -i2c_write_quick smbus write quick -.br -i2c_write_byte smbus write byte -.br -i2c_read_byte smbus read byte -.br -i2c_write_byte_data smbus write byte data -.br -i2c_write_word_data smbus write word data -.br -i2c_read_byte_data smbus read byte data -.br -i2c_read_word_data smbus read word data -.br -i2c_process_call smbus process call -.br -i2c_write_block_data smbus write block data -.br -i2c_read_block_data smbus read block data -.br -i2c_block_process_call smbus block process call -.br - -.br -i2c_write_i2c_block_data smbus write I2C block data -.br -i2c_read_i2c_block_data smbus read I2C block data -.br - -.br -i2c_read_device Reads the raw I2C device -.br -i2c_write_device Writes the raw I2C device -.br - -.br -i2c_zip Performs multiple I2C transactions -.br - -.br -bb_i2c_open Opens GPIO for bit banging I2C -.br -bb_i2c_close Closes GPIO for bit banging I2C -.br -bb_i2c_zip Performs multiple bit banged I2C transactions -.br -.SS SPI -.br - -.br -spi_open Opens a SPI device -.br -spi_close Closes a SPI device -.br - -.br -spi_read Reads bytes from a SPI device -.br -spi_write Writes bytes to a SPI device -.br -spi_xfer Transfers bytes with a SPI device -.br -.SS SERIAL -.br - -.br -serial_open Opens a serial device -.br -serial_close Closes a serial device -.br - -.br -serial_write_byte Writes a byte to a serial device -.br -serial_read_byte Reads a byte from a serial device -.br -serial_write Writes bytes to a serial device -.br -serial_read Reads bytes from a serial device -.br - -.br -serial_data_available Returns number of bytes ready to be read -.br -.SS CUSTOM -.br - -.br -custom_1 User custom function 1 -.br -custom_2 User custom function 2 -.br -.SS UTILITIES -.br - -.br -get_current_tick Get current tick (microseconds) -.br - -.br -get_hardware_revision Get hardware revision -.br -get_pigpio_version Get the pigpio version -.br -pigpiod_if_version Get the pigpiod_if version -.br - -.br -pigpio_error Get a text description of an error code. -.br - -.br -time_sleep Sleeps for a float number of seconds -.br -time_time Float number of seconds since the epoch -.br -.SH FUNCTIONS - -.IP "\fBdouble time_time(void)\fP" -.IP "" 4 -Return the current time in seconds since the Epoch. - -.IP "\fBvoid time_sleep(double seconds)\fP" -.IP "" 4 -Delay execution for a given number of seconds. - -.br - -.br - -.EX -seconds: the number of seconds to delay. -.br - -.EE - -.IP "\fBchar *pigpio_error(int errnum)\fP" -.IP "" 4 -Return a text description for an error code. - -.br - -.br - -.EX -errnum: the error code. -.br - -.EE - -.IP "\fBunsigned pigpiod_if_version(void)\fP" -.IP "" 4 -Return the pigpiod_if version. - -.IP "\fBpthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)\fP" -.IP "" 4 -Starts a new thread of execution with thread_func as the main routine. - -.br - -.br - -.EX -thread_func: the main function for the new thread. -.br - userdata: a pointer to an arbitrary argument. -.br - -.EE - -.br - -.br -Returns a pointer to pthread_t if OK, otherwise NULL. - -.br - -.br -The function is passed the single argument userdata. - -.br - -.br -The thread can be cancelled by passing the pointer to pthread_t to -\fBstop_thread\fP. - -.IP "\fBvoid stop_thread(pthread_t *pth)\fP" -.IP "" 4 -Cancels the thread pointed at by pth. - -.br - -.br - -.EX -pth: the thread to be stopped. -.br - -.EE - -.br - -.br -No value is returned. - -.br - -.br -The thread to be stopped should have been started with \fBstart_thread\fP. - -.IP "\fBint pigpio_start(char *addrStr, char *portStr)\fP" -.IP "" 4 -Connect to the pigpio daemon. Reserving command and -notification streams. - -.br - -.br - -.EX -addrStr: specifies the host or IP address of the Pi running the -.br - pigpio daemon. It may be NULL in which case localhost -.br - is used unless overridden by the PIGPIO_ADDR environment -.br - variable. -.br - -.br -portStr: specifies the port address used by the Pi running the -.br - pigpio daemon. It may be NULL in which case "8888" -.br - is used unless overridden by the PIGPIO_PORT environment -.br - variable. -.br - -.EE - -.IP "\fBvoid pigpio_stop(void)\fP" -.IP "" 4 -Terminates the connection to the pigpio daemon and releases -resources used by the library. - -.IP "\fBint set_mode(unsigned gpio, unsigned mode)\fP" -.IP "" 4 -Set the GPIO mode. - -.br - -.br - -.EX -gpio: 0-53. -.br -mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, -.br - PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. - -.IP "\fBint get_mode(unsigned gpio)\fP" -.IP "" 4 -Get the GPIO mode. - -.br - -.br - -.EX -gpio: 0-53. -.br - -.EE - -.br - -.br -Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. - -.IP "\fBint set_pull_up_down(unsigned gpio, unsigned pud)\fP" -.IP "" 4 -Set or clear the GPIO pull-up/down resistor. - -.br - -.br - -.EX -gpio: 0-53. -.br - pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. - -.IP "\fBint gpio_read(unsigned gpio)\fP" -.IP "" 4 -Read the GPIO level. - -.br - -.br - -.EX -gpio:0-53. -.br - -.EE - -.br - -.br -Returns the GPIO level if OK, otherwise PI_BAD_GPIO. - -.IP "\fBint gpio_write(unsigned gpio, unsigned level)\fP" -.IP "" 4 -Write the GPIO level. - -.br - -.br - -.EX - gpio: 0-53. -.br -level: 0, 1. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. - -.br - -.br -Notes - -.br - -.br -If PWM or servo pulses are active on the GPIO they are switched off. - -.IP "\fBint set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)\fP" -.IP "" 4 -Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br -dutycycle: 0-range (range defaults to 255). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes - -.br - -.br -The \fBset_PWM_range\fP function may be used to change the -default range of 255. - -.IP "\fBint get_PWM_dutycycle(unsigned user_gpio)\fP" -.IP "" 4 -Return the PWM dutycycle in use on a GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. - -.br - -.br -For normal PWM the dutycycle will be out of the defined range -for the GPIO (see \fBget_PWM_range\fP). - -.br - -.br -If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). - -.IP "\fBint set_PWM_range(unsigned user_gpio, unsigned range)\fP" -.IP "" 4 -Set the range of PWM values to be used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - range: 25-40000. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. - -.br - -.br -Notes - -.br - -.br -If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. - -.br - -.br -The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is - -.br - -.br - -.EX - 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), -.br - 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12), -.br -2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18) -.br - -.EE - -.br - -.br -The real value set by set_PWM_range is (dutycycle * real range) / range. - -.IP "\fBint get_PWM_range(unsigned user_gpio)\fP" -.IP "" 4 -Get the range of PWM values being used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.br - -.br -If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). - -.IP "\fBint get_PWM_real_range(unsigned user_gpio)\fP" -.IP "" 4 -Get the real underlying range of PWM values being used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.br - -.br -If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. - -.br - -.br - -.IP "\fBint set_PWM_frequency(unsigned user_gpio, unsigned frequency)\fP" -.IP "" 4 -Set the frequency (in Hz) of the PWM to be used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br -frequency: >=0 (Hz). -.br - -.EE - -.br - -.br -Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. - -.br - -.br -If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. - -.br - -.br -Each GPIO can be independently set to one of 18 different -PWM frequencies. - -.br - -.br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. - -.br - -.br -The frequencies for each sample rate are: - -.br - -.br - -.EX - Hertz -.br - -.br - 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 -.br - 1250 1000 800 500 400 250 200 100 50 -.br - -.br - 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 -.br - 625 500 400 250 200 125 100 50 25 -.br - -.br - 4: 10000 5000 2500 2000 1250 1000 625 500 400 -.br - 313 250 200 125 100 63 50 25 13 -.br -sample -.br - rate -.br - (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 -.br - 250 200 160 100 80 50 40 20 10 -.br - -.br - 8: 5000 2500 1250 1000 625 500 313 250 200 -.br - 156 125 100 63 50 31 25 13 6 -.br - -.br - 10: 4000 2000 1000 800 500 400 250 200 160 -.br - 125 100 80 50 40 25 20 10 5 -.br - -.EE - -.IP "\fBint get_PWM_frequency(unsigned user_gpio)\fP" -.IP "" 4 -Get the frequency of PWM being used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -For normal PWM the frequency will be that defined for the GPIO by -\fBset_PWM_frequency\fP. - -.br - -.br -If a hardware clock is active on the GPIO the reported frequency -will be that set by \fBhardware_clock\fP. - -.br - -.br -If hardware PWM is active on the GPIO the reported frequency -will be that set by \fBhardware_PWM\fP. - -.br - -.br -Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.IP "\fBint set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)\fP" -.IP "" 4 -Start (500-2500) or stop (0) servo pulses on the GPIO. - -.br - -.br - -.EX - user_gpio: 0-31. -.br -pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. - -.br - -.br -The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. - -.br - -.br -The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. - -.br - -.br -You can DAMAGE a servo if you command it to move beyond its limits. - -.br - -.br -OTHER UPDATE RATES: - -.br - -.br -This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. - -.br - -.br - -.EX -Update Rate (Hz) 50 100 200 400 500 -.br -1E6/Hz 20000 10000 5000 2500 2000 -.br - -.EE - -.br - -.br -Firstly set the desired PWM frequency using \fBset_PWM_frequency\fP. - -.br - -.br -Then set the PWM range using \fBset_PWM_range\fP to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. - -.br - -.br -E.g. If you want to update a servo connected to GPIO 25 at 400Hz - -.br - -.br - -.EX -set_PWM_frequency(25, 400); -.br -set_PWM_range(25, 2500); -.br - -.EE - -.br - -.br -Thereafter use the \fBset_PWM_dutycycle\fP function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse. -.br - -.IP "\fBint get_servo_pulsewidth(unsigned user_gpio)\fP" -.IP "" 4 -Return the servo pulsewidth in use on a GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. - -.IP "\fBint notify_open(void)\fP" -.IP "" 4 -Get a free notification handle. - -.br - -.br -Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. - -.br - -.br -A notification is a method for being notified of GPIO state -changes via a pipe. - -.br - -.br -Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by \fBcallback\fP -should be used instead. - -.br - -.br -Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. - -.IP "\fBint notify_begin(unsigned handle, uint32_t bits)\fP" -.IP "" 4 -Start notifications on a previously opened handle. - -.br - -.br - -.EX -handle: 0-31 (as returned by \fBnotify_open\fP) -.br - bits: a mask indicating the GPIO to be notified. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -The notification sends state changes for each GPIO whose -corresponding bit in bits is set. - -.br - -.br -Each notification occupies 12 bytes in the fifo as follows: - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint16_t seqno; -.br - uint16_t flags; -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioReport_t; -.br - -.EE - -.br - -.br -seqno: starts at 0 each time the handle is opened and then increments -by one for each report. - -.br - -.br -flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. - -.br - -.br -PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. - -.br - -.br -PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. - -.br - -.br -tick: the number of microseconds since system boot. It wraps around -after 1h12m. - -.br - -.br -level: indicates the level of each GPIO. If bit 1<=0 -.br - numBytes: >=1 -.br - str: an array of chars. -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. - -.br - -.br -NOTES: - -.br - -.br -The serial data is formatted as one start bit, \fBdata_bits\fP data bits, -and \fBstop_bits\fP/2 stop bits. - -.br - -.br -It is legal to add serial data streams with different baud rates to -the same waveform. - -.br - -.br -\fBnumBytes\fP is the number of bytes of data in str. - -.br - -.br -The bytes required for each character depend upon \fBdata_bits\fP. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint wave_create(void)\fP" -.IP "" 4 -This function creates a waveform from the data provided by the prior -calls to the \fBwave_add_*\fP functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - -.br - -.br -The data provided by the \fBwave_add_*\fP functions is consumed by this -function. - -.br - -.br -As many waveforms may be created as there is space available. The -wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. - -.br - -.br -Normal usage would be - -.br - -.br -Step 1. \fBwave_clear\fP to clear all waveforms and added data. - -.br - -.br -Step 2. \fBwave_add_*\fP calls to supply the waveform data. - -.br - -.br -Step 3. \fBwave_create\fP to create the waveform and get a unique id - -.br - -.br -Repeat steps 2 and 3 as needed. - -.br - -.br -Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. - -.br - -.br -A waveform comprises one or more pulses. Each pulse consists of a -\fBgpioPulse_t\fP structure. - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br -The fields specify - -.br - -.br -1) the GPIO to be switched on at the start of the pulse. -.br -2) the GPIO to be switched off at the start of the pulse. -.br -3) the delay in microseconds before the next pulse. -.br - -.br - -.br -Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). - -.br - -.br -When a waveform is started each pulse is executed in order with the -specified delay between the pulse and the next. - -.br - -.br -Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. - -.IP "\fBint wave_delete(unsigned wave_id)\fP" -.IP "" 4 -This function deletes the waveform with id wave_id. - -.br - -.br - -.EX -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Wave ids are allocated in order, 0, 1, 2, etc. - -.br - -.br -The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. - -.br - -.br -- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. - -.br - -.br -- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_WAVE_ID. - -.IP "\fBint wave_send_once(unsigned wave_id)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The waveform -is sent once. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br - -.EX -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_send_repeat(unsigned wave_id)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by \fBwave_tx_stop\fP). - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br - -.EX -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_chain(char *buf, unsigned bufSize)\fP" -.IP "" 4 -This function transmits a chain of waveforms. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br -The waves to be transmitted are specified by the contents of buf -which contains an ordered list of \fBwave_id\fPs and optional command -codes and related data. - -.br - -.br - -.EX - buf: pointer to the wave_ids and optional command codes -.br -bufSize: the number of bytes in buf -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. - -.br - -.br -Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. - -.br - -.br -A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. - -.br - -.br -Delays between waves may be added with the delay command. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -Loop Start 255 0 Identify start of a wave block -.br -Loop Repeat 255 1 x y loop x + y*256 times -.br -Delay 255 2 x y delay x + y*256 microseconds -.br -Loop Forever 255 3 loop forever -.br - -.br - -.br -If present Loop Forever must be the last entry in the chain. - -.br - -.br -The code is currently dimensioned to support a chain with roughly -600 entries and 20 loop counters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -#define WAVES 5 -.br -#define GPIO 4 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, wid[WAVES]; -.br - -.br - if (pigpio_start(0, 0)<0) return -1; -.br - -.br - set_mode(GPIO, PI_OUTPUT); -.br - -.br - for (i=0; i=0, as returned by \fBstore_script\fP. -.br - numPar: 0-10, the number of parameters. -.br - param: an array of parameters. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint script_status(unsigned script_id, uint32_t *param)\fP" -.IP "" 4 -This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBstore_script\fP. -.br - param: an array to hold the returned 10 parameters. -.br - -.EE - -.br - -.br -The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. - -.br - -.br -The run status may be - -.br - -.br - -.EX -PI_SCRIPT_INITING -.br -PI_SCRIPT_HALTED -.br -PI_SCRIPT_RUNNING -.br -PI_SCRIPT_WAITING -.br -PI_SCRIPT_FAILED -.br - -.EE - -.br - -.br -The current value of script parameters 0 to 9 are returned in param. - -.IP "\fBint stop_script(unsigned script_id)\fP" -.IP "" 4 -This function stops a running script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBstore_script\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint delete_script(unsigned script_id)\fP" -.IP "" 4 -This function deletes a stored script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBstore_script\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)\fP" -.IP "" 4 -This function opens a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - baud: 50-250000 -.br -data_bits: 1-32 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. - -.br - -.br -The serial data is returned in a cyclic buffer and is read using -bb_serial_read. - -.br - -.br -It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. - -.IP "\fBint bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)\fP" -.IP "" 4 -This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. - -.br - -.br - -.EX -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - buf: an array to receive the read bytes. -.br - bufSize: >=0 -.br - -.EE - -.br - -.br -Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. - -.br - -.br -The bytes returned for each character depend upon the number of -data bits \fBdata_bits\fP specified in the \fBbb_serial_read_open\fP command. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint bb_serial_read_close(unsigned user_gpio)\fP" -.IP "" 4 -This function closes a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. - -.IP "\fBint bb_serial_invert(unsigned user_gpio, unsigned invert)\fP" -.IP "" 4 -This function inverts serial logic for big bang serial reads. - -.br - -.br - -.EX -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - invert: 0-1, 1 invert, 0 normal. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. - -.IP "\fBint i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)\fP" -.IP "" 4 -This returns a handle for the device at address i2c_addr on bus i2c_bus. - -.br - -.br - -.EX - i2c_bus: >=0. -.br - i2c_addr: 0-0x7F. -.br -i2c_flags: 0. -.br - -.EE - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.br - -.br -Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - SDA SCL -.br -I2C 0 0 1 -.br -I2C 1 2 3 -.br - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. - -.br - -.br -For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. - -.br - -.br - -.EX -S (1 bit) : Start bit -.br -P (1 bit) : Stop bit -.br -Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. -.br -A, NA (1 bit) : Accept and not accept bit. -.br -.br -.br -Addr (7 bits): I2C 7 bit address. -.br -Comm (8 bits): Command byte, a data byte which often selects a register. -.br -Data (8 bits): A data byte. -.br -Count (8 bits): A data byte containing the length of a block operation. -.br - -.br -[..]: Data sent by the device. -.br - -.EE - -.IP "\fBint i2c_close(unsigned handle)\fP" -.IP "" 4 -This closes the I2C device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint i2c_write_quick(unsigned handle, unsigned bit)\fP" -.IP "" 4 -This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - bit: 0-1, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Quick command. SMBus 2.0 5.5.1 - -.EX -S Addr Rd/Wr [A] P -.br - -.EE - -.IP "\fBint i2c_write_byte(unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This sends a single byte to the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - bVal: 0-0xFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Send byte. SMBus 2.0 5.5.2 - -.EX -S Addr Wr [A] Data [A] P -.br - -.EE - -.IP "\fBint i2c_read_byte(unsigned handle)\fP" -.IP "" 4 -This reads a single byte from the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. - -.br - -.br -Receive byte. SMBus 2.0 5.5.3 - -.EX -S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)\fP" -.IP "" 4 -This writes a single byte to the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - bVal: 0-0xFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write byte. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] Comm [A] Data [A] P -.br - -.EE - -.IP "\fBint i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" -.IP "" 4 -This writes a single 16 bit word to the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - wVal: 0-0xFFFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write word. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P -.br - -.EE - -.IP "\fBint i2c_read_byte_data(unsigned handle, unsigned i2c_reg)\fP" -.IP "" 4 -This reads a single byte from the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read byte. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2c_read_word_data(unsigned handle, unsigned i2c_reg)\fP" -.IP "" 4 -This reads a single 16 bit word from the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read word. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" -.IP "" 4 -This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write/read. -.br - wVal: 0-0xFFFF, the value to write. -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Process call. SMBus 2.0 5.5.6 - -.EX -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] -.br - S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes up to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - buf: an array with the data to send. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Block write. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P -.br - -.EE - -.IP "\fBint i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)\fP" -.IP "" 4 -This reads a block of up to 32 bytes from the specified register of -the device associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - buf: an array to receive the read data. -.br - -.EE - -.br - -.br -The amount of returned data is set by the device. - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Block read. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] Comm [A] -.br - S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P -.br - -.EE - -.IP "\fBint i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write/read. -.br - buf: an array with the data to send and to receive the read data. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. - -.br - -.br -Block write-block read. SMBus 2.0 5.5.8 - -.EX -S Addr Wr [A] Comm [A] Count [A] Data [A] ... -.br - S Addr Rd [A] [Count] A [Data] ... A P -.br - -.EE - -.IP "\fBint i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - buf: an array to receive the read data. -.br - count: 1-32, the number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] Comm [A] -.br - S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P -.br - -.EE - -.IP "\fBint i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes 1 to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - buf: the data to write. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P -.br - -.EE - -.IP "\fBint i2c_read_device(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the raw device into buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - buf: an array to receive the read data bytes. -.br - count: >0, the number of bytes to read. -.br - -.EE - -.br - -.br -Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. - -.IP "\fBint i2c_write_device(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This writes count bytes from buf to the raw device. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - buf: an array containing the data bytes to write. -.br - count: >0, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.IP "\fBint i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -On 2 Switch combined flag on -.br -Off 3 Switch combined flag off -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53, write 0x32, read 6 bytes -.br -Set address 0x1E, write 0x03, read 6 bytes -.br -Set address 0x68, write 0x1B, read 8 bytes -.br -End -.br - -.br -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -.br -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -.br -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -.br -0x00 -.br - -.EE - -.br - -.br - -.IP "\fBint bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)\fP" -.IP "" 4 -This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. - -.br - -.br -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -.br - -.br -o baud rates as low as 50 -.br -o repeated starts -.br -o clock stretching -.br -o I2C on any pair of spare GPIO - -.br - -.br - -.EX - SDA: 0-31 -.br - SCL: 0-31 -.br -baud: 50-500000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -NOTE: - -.br - -.br -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -.IP "\fBint bb_i2c_close(unsigned SDA)\fP" -.IP "" 4 -This function stops bit banging I2C on a pair of GPIO previously -opened with \fBbb_i2c_open\fP. - -.br - -.br - -.EX -SDA: 0-31, the SDA GPIO used in a prior call to \fBbb_i2c_open\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - -.IP "\fBint bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX - SDA: 0-31 (as used in a prior call to \fBbb_i2c_open\fP) -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -Start 2 Start condition -.br -Stop 3 Stop condition -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -.br - -.br -No flags are currently defined. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53 -.br -start, write 0x32, (re)start, read 6 bytes, stop -.br -Set address 0x1E -.br -start, write 0x03, (re)start, read 6 bytes, stop -.br -Set address 0x68 -.br -start, write 0x1B, (re)start, read 8 bytes, stop -.br -End -.br - -.br -0x04 0x53 -.br -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x1E -.br -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x68 -.br -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 -.br - -.br -0x00 -.br - -.EE - -.IP "\fBint spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)\fP" -.IP "" 4 -This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. - -.br - -.br -The Pi has two SPI peripherals: main and auxiliary. - -.br - -.br -The main SPI has two chip selects (channels), the auxiliary has -three. - -.br - -.br -The auxiliary SPI is available on all models but the A and B. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - MISO MOSI SCLK CE0 CE1 CE2 -.br -Main SPI 9 10 11 8 7 - -.br -Aux SPI 19 20 21 18 17 16 -.br - -.br - -.br - -.EX -spi_channel: 0-1 (0-2 for the auxiliary SPI). -.br - baud: 32K-125M (values above 30M are unlikely to work). -.br - spi_flags: see below. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. - -.br - -.br -spi_flags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -.br - -.EE - -.br - -.br -mm defines the SPI mode. - -.br - -.br -Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. - -.br - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -px is 0 if CEx is active low (default) and 1 for active high. - -.br - -.br -ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. - -.br - -.br -A is 0 for the main SPI, 1 for the auxiliary SPI. - -.br - -.br -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main -SPI only. - -.br - -.br -nnnn defines the number of bytes (0-15) to write before switching -the MOSI line to MISO to read data. This field is ignored -if W is not set. Main SPI only. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. Auxiliary SPI -only. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. Auxiliary SPI -only. - -.br - -.br -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI only. - -.br - -.br -The \fBspi_read\fP, \fBspi_write\fP, and \fBspi_xfer\fP functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. - -.br - -.br -For bits 1-8 there will be one byte per word. -.br -For bits 9-16 there will be two bytes per word. -.br -For bits 17-32 there will be four bytes per word. - -.br - -.br -Multi-byte transfers are made in least significant byte first order. - -.br - -.br -E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. - -.br - -.br -E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed -by 0x1A. - -.br - -.br -The other bits in flags should be set to zero. - -.IP "\fBint spi_close(unsigned handle)\fP" -.IP "" 4 -This functions closes the SPI device identified by the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint spi_read(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads count bytes of data from the SPI -device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - buf: an array to receive the read data bytes. -.br - count: the number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spi_write(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes of data from buf to the SPI -device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - buf: the data bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" -.IP "" 4 -This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - txBuf: the data bytes to write. -.br - rxBuf: the received data bytes. -.br - count: the number of bytes to transfer. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)\fP" -.IP "" 4 -This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. - -.br - -.br - -.EX - ser_tty: the serial device to open. -.br - baud: the baud rate in bits per second, see below. -.br -ser_flags: 0. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. - -.br - -.br -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.IP "\fBint serial_close(unsigned handle)\fP" -.IP "" 4 -This function closes the serial device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint serial_write_byte(unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This function writes bVal to the serial port associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serial_read_byte(unsigned handle)\fP" -.IP "" 4 -This function reads a byte from the serial port associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. - -.br - -.br -If no data is ready PI_SER_READ_NO_DATA is returned. - -.IP "\fBint serial_write(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the serial port -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - buf: the array of bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serial_read(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - buf: an array to receive the read data. -.br - count: the maximum number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. - -.br - -.br -If no data is ready zero is returned. - -.IP "\fBint serial_data_available(unsigned handle)\fP" -.IP "" 4 -Returns the number of bytes available to be read from the -device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. - -.IP "\fBint custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It returns a single integer value. - -.br - -.br - -.EX -arg1: >=0 -.br -arg2: >=0 -.br -argx: extra (byte) arguments -.br -argc: number of extra arguments -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.IP "\fBint custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It differs from custom_1 in that it returns an array of bytes -rather than just an integer. - -.br - -.br -The return value is an integer indicating the number of returned bytes. - -.EX - arg1: >=0 -.br - argc: extra (byte) arguments -.br - count: number of extra arguments -.br -retBuf: buffer for returned data -.br -retMax: maximum number of bytes to return -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.br - -.br -Note, the number of returned bytes will be retMax or less. - -.IP "\fBint callback(unsigned user_gpio, unsigned edge, CBFunc_t f)\fP" -.IP "" 4 -This function initialises a new callback. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - f: the callback function. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -edge 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.EE - -.IP "\fBint callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP" -.IP "" 4 -This function initialises a new callback. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - f: the callback function. -.br - userdata: a pointer to arbitrary user data. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the GPIO, edge, tick, and user, whenever -the GPIO has the identified edge. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -edge 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.br -userdata pointer Pointer to an arbitrary object -.br - -.EE - -.IP "\fBint callback_cancel(unsigned callback_id)\fP" -.IP "" 4 -This function cancels a callback identified by its id. - -.br - -.br - -.EX -callback_id: >=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise pigif_callback_not_found. - -.IP "\fBint wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)\fP" -.IP "" 4 -This function waits for edge on the GPIO for up to timeout -seconds. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - timeout: >=0. -.br - -.EE - -.br - -.br -The function returns 1 if the edge occurred, otherwise 0. - -.br - -.br -The function returns when the edge occurs or after the timeout. -.SH PARAMETERS - -.br - -.br - -.IP "\fBactive\fP: 0-1000000" 0 - -.br - -.br -The number of microseconds level changes are reported for once -a noise filter has been triggered (by \fBsteady\fP microseconds of -a stable level). - -.br - -.br - -.IP "\fB*addrStr\fP" 0 -A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. - -.br - -.br - -.IP "\fBarg1\fP" 0 -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBarg2\fP" 0 -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBargc\fP" 0 -The count of bytes passed to a user customised function. - -.br - -.br - -.IP "\fB*argx\fP" 0 -A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. - -.br - -.br - -.IP "\fBbaud\fP" 0 -The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. - -.br - -.br - -.IP "\fBbit\fP" 0 -A value of 0 or 1. - -.br - -.br - -.IP "\fBbits\fP" 0 -A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. - -.br - -.br -A convenient way to set bit n is to or in (1<=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. This is -passed to \fBcallback_cancel\fP to cancel the callback. - -.br - -.br - -.IP "\fBCBFunc_t\fP" 0 - -.EX -typedef void (*CBFunc_t) -.br - (unsigned user_gpio, unsigned level, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBCBFuncEx_t\fP" 0 - -.EX -typedef void (*CBFuncEx_t) -.br - (unsigned user_gpio, unsigned level, uint32_t tick, void * user); -.br - -.EE - -.br - -.br - -.IP "\fBchar\fP" 0 -A single character, an 8 bit quantity able to store 0-255. - -.br - -.br - -.IP "\fBclkfreq\fP: 4689-250000000 (250M)" 0 -The hardware clock frequency. - -.br - -.br - -.IP "\fBcount\fP" 0 -The number of bytes to be transferred in an I2C, SPI, or Serial -command. - -.br - -.br - -.IP "\fBdata_bits\fP: 1-32" 0 -The number of data bits in each character of serial data. - -.br - -.br - -.EX -#define PI_MIN_WAVE_DATABITS 1 -.br -#define PI_MAX_WAVE_DATABITS 32 -.br - -.EE - -.br - -.br - -.IP "\fBdouble\fP" 0 -A floating point number. - -.br - -.br - -.IP "\fBdutycycle\fP: 0-range" 0 -A number representing the ratio of on time to off time for PWM. - -.br - -.br -The number may vary between 0 and range (default 255) where -0 is off and range is fully on. - -.br - -.br - -.IP "\fBedge\fP" 0 -Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. - -.br - -.br - -.EX -RISING_EDGE 0 -.br -FALLING_EDGE 1 -.br -EITHER_EDGE. 2 -.br - -.EE - -.br - -.br - -.IP "\fBerrnum\fP" 0 -A negative number indicating a function call failed and the nature -of the error. - -.br - -.br - -.IP "\fBf\fP" 0 -A function. - -.br - -.br - -.IP "\fBfrequency\fP: >=0" 0 -The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. - -.br - -.br - -.br - -.br - -.IP "\fBgpio\fP" 0 -A Broadcom numbered GPIO, in the range 0-53. - -.br - -.br -There are 54 General Purpose Input Outputs (GPIO) named gpio0 through -gpio53. - -.br - -.br -They are split into two banks. Bank 1 consists of gpio0 through -gpio31. Bank 2 consists of gpio32 through gpio53. - -.br - -.br -All the GPIO which are safe for the user to read and write are in -bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards -have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. - -.br - -.br -See \fBget_hardware_revision\fP. - -.br - -.br -The user GPIO are marked with an X in the following table. - -.br - -.br - -.EX - 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -.br -Type 1 X X - - X - - X X X X X - - X X -.br -Type 2 - - X X X - - X X X X X - - X X -.br -Type 3 X X X X X X X X X X X X X X -.br - -.br - 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 -.br -Type 1 - X X - - X X X X X - - - - - - -.br -Type 2 - X X - - - X X X X - X X X X X -.br -Type 3 X X X X X X X X X X X X - - - - -.br - -.EE - -.br - -.br - -.IP "\fBgpioPulse_t\fP" 0 - -.EX -typedef struct -.br -{ -.br -uint32_t gpioOn; -.br -uint32_t gpioOff; -.br -uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br - -.IP "\fBgpioThreadFunc_t\fP" 0 - -.EX -typedef void *(gpioThreadFunc_t) (void *); -.br - -.EE - -.br - -.br - -.IP "\fBhandle\fP: >=0" 0 -A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\fP, -\fBserial_open\fP, and \fBspi_open\fP. - -.br - -.br - -.IP "\fBi2c_addr\fP: 0-0x7F" 0 -The address of a device on the I2C bus. - -.br - -.br - -.IP "\fBi2c_bus\fP: >=0" 0 -An I2C bus number. - -.br - -.br - -.IP "\fBi2c_flags\fP: 0" 0 -Flags which modify an I2C open command. None are currently defined. - -.br - -.br - -.IP "\fBi2c_reg\fP: 0-255" 0 -A register of an I2C device. - -.br - -.br - -.IP "\fB*inBuf\fP" 0 -A buffer used to pass data to a function. - -.br - -.br - -.IP "\fBinLen\fP" 0 -The number of bytes of data in a buffer. - -.br - -.br - -.IP "\fBint\fP" 0 -A whole number, negative or positive. - -.br - -.br - -.IP "\fBinvert\fP" 0 -A flag used to set normal or inverted bit bang serial data level logic. - -.br - -.br - -.IP "\fBlevel\fP" 0 -The level of a GPIO. Low or High. - -.br - -.br - -.EX -PI_OFF 0 -.br -PI_ON 1 -.br - -.br -PI_CLEAR 0 -.br -PI_SET 1 -.br - -.br -PI_LOW 0 -.br -PI_HIGH 1 -.br - -.EE - -.br - -.br -There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See \fBset_watchdog\fP. - -.br - -.br - -.EX -PI_TIMEOUT 2 -.br - -.EE - -.br - -.br - -.IP "\fBmode\fP: 0-7" 0 -The operational mode of a GPIO, normally INPUT or OUTPUT. - -.br - -.br - -.EX -PI_INPUT 0 -.br -PI_OUTPUT 1 -.br -PI_ALT0 4 -.br -PI_ALT1 5 -.br -PI_ALT2 6 -.br -PI_ALT3 7 -.br -PI_ALT4 3 -.br -PI_ALT5 2 -.br - -.EE - -.br - -.br - -.IP "\fBnumBytes\fP" 0 -The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. - -.br - -.br - -.IP "\fBnumPar\fP: 0-10" 0 -The number of parameters passed to a script. - -.br - -.br - -.IP "\fBnumPulses\fP" 0 -The number of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBoffset\fP" 0 -The associated data starts this number of microseconds from the start of -the waveform. - -.br - -.br - -.IP "\fB*outBuf\fP" 0 -A buffer used to return data from a function. - -.br - -.br - -.IP "\fBoutLen\fP" 0 -The size in bytes of an output buffer. - -.br - -.br - -.IP "\fB*param\fP" 0 -An array of script parameters. - -.br - -.br - -.IP "\fB*portStr\fP" 0 -A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. - -.br - -.br - -.IP "\fB*pth\fP" 0 -A thread identifier, returned by \fBstart_thread\fP. - -.br - -.br - -.br - -.br - -.IP "\fBpthread_t\fP" 0 -A thread identifier. - -.br - -.br - -.IP "\fBpud\fP: 0-2" 0 -The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. - -.EX -PI_PUD_OFF 0 -.br -PI_PUD_DOWN 1 -.br -PI_PUD_UP 2 -.br - -.EE - -.br - -.br - -.IP "\fBpulseLen\fP" 0 -1-100, the length of a trigger pulse in microseconds. - -.br - -.br - -.IP "\fB*pulses\fP" 0 -An array of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBpulsewidth\fP: 0, 500-2500" 0 - -.EX -PI_SERVO_OFF 0 -.br -PI_MIN_SERVO_PULSEWIDTH 500 -.br -PI_MAX_SERVO_PULSEWIDTH 2500 -.br - -.EE - -.br - -.br - -.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 -The hardware PWM dutycycle. - -.br - -.br - -.EX -#define PI_HW_PWM_RANGE 1000000 -.br - -.EE - -.br - -.br - -.IP "\fBPWMfreq\fP: 1-125000000 (125M)" 0 -The hardware PWM frequency. - -.br - -.br - -.EX -#define PI_HW_PWM_MIN_FREQ 1 -.br -#define PI_HW_PWM_MAX_FREQ 125000000 -.br - -.EE - -.br - -.br - -.IP "\fBrange\fP: 25-40000" 0 -The permissible dutycycle values are 0-range. - -.EX -PI_MIN_DUTYCYCLE_RANGE 25 -.br -PI_MAX_DUTYCYCLE_RANGE 40000 -.br - -.EE - -.br - -.br - -.IP "\fB*retBuf\fP" 0 -A buffer to hold a number of bytes returned to a used customised function, - -.br - -.br - -.IP "\fBretMax\fP" 0 -The maximum number of bytes a user customised function should return. - -.br - -.br - -.br - -.br - -.IP "\fB*rxBuf\fP" 0 -A pointer to a buffer to receive data. - -.br - -.br - -.IP "\fBSCL\fP" 0 -The user GPIO to use for the clock when bit banging I2C. - -.br - -.br - -.IP "\fB*script\fP" 0 -A pointer to the text of a script. - -.br - -.br - -.IP "\fBscript_id\fP" 0 -An id of a stored script as returned by \fBstore_script\fP. - -.br - -.br - -.IP "\fBSDA\fP" 0 -The user GPIO to use for data when bit banging I2C. - -.br - -.br - -.IP "\fBseconds\fP" 0 -The number of seconds. - -.br - -.br - -.IP "\fBser_flags\fP" 0 -Flags which modify a serial open command. None are currently defined. - -.br - -.br - -.IP "\fB*ser_tty\fP" 0 -The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. - -.br - -.br - -.IP "\fBsize_t\fP" 0 -A standard type used to indicate the size of an object in bytes. - -.br - -.br - -.IP "\fBspi_channel\fP" 0 -A SPI channel, 0-2. - -.br - -.br - -.IP "\fBspi_flags\fP" 0 -See \fBspi_open\fP. - -.br - -.br - -.IP "\fBsteady\fP: 0-300000" 0 - -.br - -.br -The number of microseconds level changes must be stable for -before reporting the level changed (\fBset_glitch_filter\fP) or triggering -the active part of a noise filter (\fBset_noise_filter\fP). - -.br - -.br - -.IP "\fBstop_bits\fP: 2-8" 0 -The number of (half) stop bits to be used when adding serial data -to a waveform. - -.br - -.br - -.EX -#define PI_MIN_WAVE_HALFSTOPBITS 2 -.br -#define PI_MAX_WAVE_HALFSTOPBITS 8 -.br - -.EE - -.br - -.br - -.IP "\fB*str\fP" 0 - An array of characters. - -.br - -.br - -.IP "\fBthread_func\fP" 0 -A function of type gpioThreadFunc_t used as the main function of a -thread. - -.br - -.br - -.IP "\fBtimeout\fP" 0 -A GPIO watchdog timeout in milliseconds. - -.EX -PI_MIN_WDOG_TIMEOUT 0 -.br -PI_MAX_WDOG_TIMEOUT 60000 -.br - -.EE - -.br - -.br - -.IP "\fB*txBuf\fP" 0 -An array of bytes to transmit. - -.br - -.br - -.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 -A 32-bit unsigned value. - -.br - -.br - -.IP "\fBunsigned\fP" 0 -A whole number >= 0. - -.br - -.br - -.IP "\fBuser_gpio\fP" 0 -0-31, a Broadcom numbered GPIO. - -.br - -.br -See \fBgpio\fP. - -.br - -.br - -.IP "\fB*userdata\fP" 0 -A pointer to arbitrary user data. This may be used to identify the instance. - -.br - -.br - -.IP "\fBvoid\fP" 0 -Denoting no parameter is required - -.br - -.br - -.IP "\fBwave_add_*\fP" 0 -One of \fBwave_add_new\fP, \fBwave_add_generic\fP, \fBwave_add_serial\fP. - -.br - -.br - -.IP "\fBwave_id\fP" 0 -A number representing a waveform created by \fBwave_create\fP. - -.br - -.br - -.IP "\fBwave_send_*\fP" 0 -One of \fBwave_send_once\fP, \fBwave_send_repeat\fP. - -.br - -.br - -.IP "\fBwVal\fP: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)" 0 -A 16-bit word value. - -.br - -.br -.SH pigpiod_if Error Codes - -.EX - -.br -typedef enum -.br -{ -.br - pigif_bad_send = -2000, -.br - pigif_bad_recv = -2001, -.br - pigif_bad_getaddrinfo = -2002, -.br - pigif_bad_connect = -2003, -.br - pigif_bad_socket = -2004, -.br - pigif_bad_noib = -2005, -.br - pigif_duplicate_callback = -2006, -.br - pigif_bad_malloc = -2007, -.br - pigif_bad_callback = -2008, -.br - pigif_notify_failed = -2009, -.br - pigif_callback_not_found = -2010, -.br -} pigifError_t; -.br - -.br - -.EE - -.SH SEE ALSO - -pigpiod(1), pig2vcd(1), pigs(1), pigpio(3), pigpiod_if2(3) -.SH AUTHOR - -joan@abyz.me.uk diff --git a/DOC/MAN/pigpiod_if2.3 b/DOC/MAN/pigpiod_if2.3 deleted file mode 100644 index f07de8d..0000000 --- a/DOC/MAN/pigpiod_if2.3 +++ /dev/null @@ -1,8057 +0,0 @@ - -." Process this file with -." groff -man -Tascii pigpiod_if2.3 -." -.TH pigpiod_if2 3 2012-2020 Linux "pigpio archive" -.SH NAME -pigpiod_if2 - A C library to interface to the pigpio daemon. - -.SH SYNOPSIS - -#include - - -gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt - - ./prog -.SH DESCRIPTION - - -.ad l - -.nh - -.br - -.br -pigpiod_if2 is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon. -.br - -.br - -.br -.SS Features -.br - -.br -o hardware timed PWM on any of GPIO 0-31 - -.br - -.br -o hardware timed servo pulses on any of GPIO 0-31 - -.br - -.br -o callbacks when any of GPIO 0-31 change state - -.br - -.br -o callbacks at timed intervals - -.br - -.br -o reading/writing all of the GPIO in a bank as one operation - -.br - -.br -o individually setting GPIO modes, reading and writing - -.br - -.br -o notifications when any of GPIO 0-31 change state - -.br - -.br -o the construction of output waveforms with microsecond timing - -.br - -.br -o rudimentary permission control over GPIO - -.br - -.br -o a simple interface to start and stop new threads - -.br - -.br -o I2C, SPI, and serial link wrappers - -.br - -.br -o creating and running scripts on the pigpio daemon - -.br - -.br -.SS GPIO -.br - -.br -ALL GPIO are identified by their Broadcom number. - -.br - -.br -.SS Notes -.br - -.br -The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. - -.br - -.br -.SS Usage -.br - -.br -Include in your source files. - -.br - -.br -Assuming your source is in prog.c use the following command to build - -.br - -.br - -.EX -gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt -.br - -.EE - -.br - -.br -to run make sure the pigpio daemon is running - -.br - -.br - -.EX -sudo pigpiod -.br - -.br - ./prog # sudo is not required to run programs linked to pigpiod_if2 -.br - -.EE - -.br - -.br -For examples see x_pigpiod_if2.c within the pigpio archive file. - -.br - -.br -.SS Notes -.br - -.br -All the functions which return an int return < 0 on error - -.br - -.br - -.SH OVERVIEW - -.br -.SS ESSENTIAL -.br - -.br -pigpio_start Connects to a pigpio daemon -.br -pigpio_stop Disconnects from a pigpio daemon -.br -.SS BASIC -.br - -.br -set_mode Set a GPIO mode -.br -get_mode Get a GPIO mode -.br - -.br -set_pull_up_down Set/clear GPIO pull up/down resistor -.br - -.br -gpio_read Read a GPIO -.br -gpio_write Write a GPIO -.br -.SS PWM (overrides servo commands on same GPIO) -.br - -.br -set_PWM_dutycycle Start/stop PWM pulses on a GPIO -.br -set_PWM_frequency Configure PWM frequency for a GPIO -.br -set_PWM_range Configure PWM range for a GPIO -.br - -.br -get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -.br -get_PWM_frequency Get configured PWM frequency for a GPIO -.br -get_PWM_range Get configured PWM range for a GPIO -.br - -.br -get_PWM_real_range Get underlying PWM range for a GPIO -.br -.SS Servo (overrides PWM commands on same GPIO) -.br - -.br -set_servo_pulsewidth Start/stop servo pulses on a GPIO -.br - -.br -get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -.br -.SS INTERMEDIATE -.br - -.br -gpio_trigger Send a trigger pulse to a GPIO. -.br - -.br -set_watchdog Set a watchdog on a GPIO. -.br - -.br -read_bank_1 Read all GPIO in bank 1 -.br -read_bank_2 Read all GPIO in bank 2 -.br - -.br -clear_bank_1 Clear selected GPIO in bank 1 -.br -clear_bank_2 Clear selected GPIO in bank 2 -.br - -.br -set_bank_1 Set selected GPIO in bank 1 -.br -set_bank_2 Set selected GPIO in bank 2 -.br - -.br -callback Create GPIO level change callback -.br -callback_ex Create GPIO level change callback, extended -.br - -.br -callback_cancel Cancel a callback -.br - -.br -wait_for_edge Wait for GPIO level change -.br - -.br -start_thread Start a new thread -.br -stop_thread Stop a previously started thread -.br -.SS ADVANCED -.br - -.br -notify_open Request a notification handle -.br -notify_begin Start notifications for selected GPIO -.br -notify_pause Pause notifications -.br -notify_close Close a notification -.br - -.br -hardware_clock Start hardware clock on supported GPIO -.br - -.br -hardware_PWM Start hardware PWM on supported GPIO -.br - -.br -set_glitch_filter Set a glitch filter on a GPIO -.br -set_noise_filter Set a noise filter on a GPIO -.br - -.br -set_pad_strength Sets a pads drive strength -.br -get_pad_strength Gets a pads drive strength -.br - -.br -shell_ Executes a shell command -.br -.SS Custom -.br - -.br -custom_1 User custom function 1 -.br -custom_2 User custom function 2 -.br -.SS Events -.br - -.br -event_callback Sets a callback for an event -.br -event_callback_ex Sets a callback for an event, extended -.br - -.br -event_callback_cancel Cancel an event callback -.br - -.br -event_trigger Triggers an event -.br - -.br -wait_for_event Wait for an event -.br -.SS Scripts -.br - -.br -store_script Store a script -.br -run_script Run a stored script -.br -update_script Set a scripts parameters -.br -script_status Get script status and parameters -.br -stop_script Stop a running script -.br -delete_script Delete a stored script -.br -.SS I2C -.br - -.br -i2c_open Opens an I2C device -.br -i2c_close Closes an I2C device -.br - -.br -i2c_write_quick smbus write quick -.br - -.br -i2c_read_byte smbus read byte -.br -i2c_write_byte smbus write byte -.br - -.br -i2c_read_byte_data smbus read byte data -.br -i2c_write_byte_data smbus write byte data -.br - -.br -i2c_read_word_data smbus read word data -.br -i2c_write_word_data smbus write word data -.br - -.br -i2c_read_block_data smbus read block data -.br -i2c_write_block_data smbus write block data -.br - -.br -i2c_read_i2c_block_data smbus read I2C block data -.br -i2c_write_i2c_block_data smbus write I2C block data -.br - -.br -i2c_read_device Reads the raw I2C device -.br -i2c_write_device Writes the raw I2C device -.br - -.br -i2c_process_call smbus process call -.br -i2c_block_process_call smbus block process call -.br - -.br -i2c_zip Performs multiple I2C transactions -.br -.SS I2C BIT BANG -.br - -.br -bb_i2c_open Opens GPIO for bit banging I2C -.br -bb_i2c_close Closes GPIO for bit banging I2C -.br - -.br -bb_i2c_zip Performs bit banged I2C transactions -.br -.SS I2C/SPI SLAVE -.br - -.br -bsc_xfer I2C/SPI as slave transfer -.br -bsc_i2c I2C as slave transfer -.br -.SS SERIAL -.br - -.br -serial_open Opens a serial device -.br -serial_close Closes a serial device -.br - -.br -serial_read_byte Reads a byte from a serial device -.br -serial_write_byte Writes a byte to a serial device -.br - -.br -serial_read Reads bytes from a serial device -.br -serial_write Writes bytes to a serial device -.br - -.br -serial_data_available Returns number of bytes ready to be read -.br -.SS SERIAL BIT BANG (read only) -.br - -.br -bb_serial_read_open Opens a GPIO for bit bang serial reads -.br -bb_serial_read_close Closes a GPIO for bit bang serial reads -.br - -.br -bb_serial_invert Invert serial logic (1 invert, 0 normal) -.br - -.br -bb_serial_read Reads bit bang serial data from a GPIO -.br -.SS SPI -.br - -.br -spi_open Opens a SPI device -.br -spi_close Closes a SPI device -.br - -.br -spi_read Reads bytes from a SPI device -.br -spi_write Writes bytes to a SPI device -.br -spi_xfer Transfers bytes with a SPI device -.br -.SS SPI BIT BANG -.br - -.br -bb_spi_open Opens GPIO for bit banging SPI -.br -bb_spi_close Closes GPIO for bit banging SPI -.br - -.br -bb_spi_xfer Transfers bytes with bit banging SPI -.br -.SS FILES -.br - -.br -file_open Opens a file -.br -file_close Closes a file -.br - -.br -file_read Reads bytes from a file -.br -file_write Writes bytes to a file -.br - -.br -file_seek Seeks to a position within a file -.br - -.br -file_list List files which match a pattern -.br -.SS WAVES -.br - -.br -wave_clear Deletes all waveforms -.br - -.br -wave_add_new Starts a new waveform -.br -wave_add_generic Adds a series of pulses to the waveform -.br -wave_add_serial Adds serial data to the waveform -.br - -.br -wave_create Creates a waveform from added data -.br -wave_create_and_pad Creates a waveform of fixed size from added data -.br -wave_delete Deletes one or more waveforms -.br - -.br -wave_send_once Transmits a waveform once -.br -wave_send_repeat Transmits a waveform repeatedly -.br -wave_send_using_mode Transmits a waveform in the chosen mode -.br - -.br -wave_chain Transmits a chain of waveforms -.br - -.br -wave_tx_at Returns the current transmitting waveform -.br - -.br -wave_tx_busy Checks to see if the waveform has ended -.br - -.br -wave_tx_stop Aborts the current waveform -.br - -.br -wave_get_cbs Length in cbs of the current waveform -.br -wave_get_high_cbs Length of longest waveform so far -.br -wave_get_max_cbs Absolute maximum allowed cbs -.br - -.br -wave_get_micros Length in micros of the current waveform -.br -wave_get_high_micros Length of longest waveform so far -.br -wave_get_max_micros Absolute maximum allowed micros -.br - -.br -wave_get_pulses Length in pulses of the current waveform -.br -wave_get_high_pulses Length of longest waveform so far -.br -wave_get_max_pulses Absolute maximum allowed pulses -.br -.SS UTILITIES -.br - -.br -get_current_tick Get current tick (microseconds) -.br - -.br -get_hardware_revision Get hardware revision -.br -get_pigpio_version Get the pigpio version -.br -pigpiod_if_version Get the pigpiod_if2 version -.br - -.br -pigpio_error Get a text description of an error code. -.br - -.br -time_sleep Sleeps for a float number of seconds -.br -time_time Float number of seconds since the epoch -.br -.SH FUNCTIONS - -.IP "\fBdouble time_time(void)\fP" -.IP "" 4 -Return the current time in seconds since the Epoch. - -.IP "\fBvoid time_sleep(double seconds)\fP" -.IP "" 4 -Delay execution for a given number of seconds. - -.br - -.br - -.EX -seconds: the number of seconds to delay. -.br - -.EE - -.IP "\fBchar *pigpio_error(int errnum)\fP" -.IP "" 4 -Return a text description for an error code. - -.br - -.br - -.EX -errnum: the error code. -.br - -.EE - -.IP "\fBunsigned pigpiod_if_version(void)\fP" -.IP "" 4 -Return the pigpiod_if2 version. - -.IP "\fBpthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)\fP" -.IP "" 4 -Starts a new thread of execution with thread_func as the main routine. - -.br - -.br - -.EX -thread_func: the main function for the new thread. -.br - userdata: a pointer to an arbitrary argument. -.br - -.EE - -.br - -.br -Returns a pointer to pthread_t if OK, otherwise NULL. - -.br - -.br -The function is passed the single argument userdata. - -.br - -.br -The thread can be cancelled by passing the pointer to pthread_t to -\fBstop_thread\fP. - -.IP "\fBvoid stop_thread(pthread_t *pth)\fP" -.IP "" 4 -Cancels the thread pointed at by pth. - -.br - -.br - -.EX -pth: the thread to be stopped. -.br - -.EE - -.br - -.br -No value is returned. - -.br - -.br -The thread to be stopped should have been started with \fBstart_thread\fP. - -.IP "\fBint pigpio_start(char *addrStr, char *portStr)\fP" -.IP "" 4 -Connect to the pigpio daemon. Reserving command and -notification streams. - -.br - -.br - -.EX -addrStr: specifies the host or IP address of the Pi running the -.br - pigpio daemon. It may be NULL in which case localhost -.br - is used unless overridden by the PIGPIO_ADDR environment -.br - variable. -.br - -.br -portStr: specifies the port address used by the Pi running the -.br - pigpio daemon. It may be NULL in which case "8888" -.br - is used unless overridden by the PIGPIO_PORT environment -.br - variable. -.br - -.EE - -.br - -.br -Returns an integer value greater than or equal to zero if OK. - -.br - -.br -This value is passed to the GPIO routines to specify the Pi -to be operated on. - -.IP "\fBvoid pigpio_stop(int pi)\fP" -.IP "" 4 -Terminates the connection to a pigpio daemon and releases -resources used by the library. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint set_mode(int pi, unsigned gpio, unsigned mode)\fP" -.IP "" 4 -Set the GPIO mode. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -gpio: 0-53. -.br -mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, -.br - PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. - -.IP "\fBint get_mode(int pi, unsigned gpio)\fP" -.IP "" 4 -Get the GPIO mode. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -gpio: 0-53. -.br - -.EE - -.br - -.br -Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. - -.IP "\fBint set_pull_up_down(int pi, unsigned gpio, unsigned pud)\fP" -.IP "" 4 -Set or clear the GPIO pull-up/down resistor. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -gpio: 0-53. -.br - pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. - -.IP "\fBint gpio_read(int pi, unsigned gpio)\fP" -.IP "" 4 -Read the GPIO level. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -gpio:0-53. -.br - -.EE - -.br - -.br -Returns the GPIO level if OK, otherwise PI_BAD_GPIO. - -.IP "\fBint gpio_write(int pi, unsigned gpio, unsigned level)\fP" -.IP "" 4 -Write the GPIO level. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - gpio: 0-53. -.br -level: 0, 1. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. - -.br - -.br -Notes - -.br - -.br -If PWM or servo pulses are active on the GPIO they are switched off. - -.IP "\fBint set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)\fP" -.IP "" 4 -Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br -dutycycle: 0-range (range defaults to 255). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes - -.br - -.br -The \fBset_PWM_range\fP function may be used to change the -default range of 255. - -.IP "\fBint get_PWM_dutycycle(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Return the PWM dutycycle in use on a GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. - -.br - -.br -For normal PWM the dutycycle will be out of the defined range -for the GPIO (see \fBget_PWM_range\fP). - -.br - -.br -If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). - -.IP "\fBint set_PWM_range(int pi, unsigned user_gpio, unsigned range)\fP" -.IP "" 4 -Set the range of PWM values to be used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - range: 25-40000. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. - -.br - -.br -Notes - -.br - -.br -If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. - -.br - -.br -The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is - -.br - -.br - -.EX - 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), -.br - 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12), -.br -2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18) -.br - -.EE - -.br - -.br -The real value set by set_PWM_range is (dutycycle * real range) / range. - -.IP "\fBint get_PWM_range(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Get the range of PWM values being used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.br - -.br -If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). - -.IP "\fBint get_PWM_real_range(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Get the real underlying range of PWM values being used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.br - -.br -If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. - -.br - -.br - -.IP "\fBint set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)\fP" -.IP "" 4 -Set the frequency (in Hz) of the PWM to be used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br -frequency: >=0 (Hz). -.br - -.EE - -.br - -.br -Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. - -.br - -.br -If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. - -.br - -.br -Each GPIO can be independently set to one of 18 different -PWM frequencies. - -.br - -.br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. - -.br - -.br -The frequencies for each sample rate are: - -.br - -.br - -.EX - Hertz -.br - -.br - 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 -.br - 1250 1000 800 500 400 250 200 100 50 -.br - -.br - 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 -.br - 625 500 400 250 200 125 100 50 25 -.br - -.br - 4: 10000 5000 2500 2000 1250 1000 625 500 400 -.br - 313 250 200 125 100 63 50 25 13 -.br -sample -.br - rate -.br - (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 -.br - 250 200 160 100 80 50 40 20 10 -.br - -.br - 8: 5000 2500 1250 1000 625 500 313 250 200 -.br - 156 125 100 63 50 31 25 13 6 -.br - -.br - 10: 4000 2000 1000 800 500 400 250 200 160 -.br - 125 100 80 50 40 25 20 10 5 -.br - -.EE - -.IP "\fBint get_PWM_frequency(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Get the frequency of PWM being used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -For normal PWM the frequency will be that defined for the GPIO by -\fBset_PWM_frequency\fP. - -.br - -.br -If a hardware clock is active on the GPIO the reported frequency -will be that set by \fBhardware_clock\fP. - -.br - -.br -If hardware PWM is active on the GPIO the reported frequency -will be that set by \fBhardware_PWM\fP. - -.br - -.br -Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.IP "\fBint set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)\fP" -.IP "" 4 -Start (500-2500) or stop (0) servo pulses on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - user_gpio: 0-31. -.br -pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. - -.br - -.br -The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. - -.br - -.br -The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. - -.br - -.br -You can DAMAGE a servo if you command it to move beyond its limits. - -.br - -.br -OTHER UPDATE RATES: - -.br - -.br -This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. - -.br - -.br - -.EX -Update Rate (Hz) 50 100 200 400 500 -.br -1E6/Hz 20000 10000 5000 2500 2000 -.br - -.EE - -.br - -.br -Firstly set the desired PWM frequency using \fBset_PWM_frequency\fP. - -.br - -.br -Then set the PWM range using \fBset_PWM_range\fP to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. - -.br - -.br -E.g. If you want to update a servo connected to GPIO 25 at 400Hz - -.br - -.br - -.EX -set_PWM_frequency(25, 400); -.br -set_PWM_range(25, 2500); -.br - -.EE - -.br - -.br -Thereafter use the \fBset_PWM_dutycycle\fP function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse. -.br - -.IP "\fBint get_servo_pulsewidth(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Return the servo pulsewidth in use on a GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. - -.IP "\fBint notify_open(int pi)\fP" -.IP "" 4 -Get a free notification handle. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. - -.br - -.br -A notification is a method for being notified of GPIO state -changes via a pipe. - -.br - -.br -Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by \fBcallback\fP -should be used instead. - -.br - -.br -Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. - -.IP "\fBint notify_begin(int pi, unsigned handle, uint32_t bits)\fP" -.IP "" 4 -Start notifications on a previously opened handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: 0-31 (as returned by \fBnotify_open\fP) -.br - bits: a mask indicating the GPIO to be notified. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -The notification sends state changes for each GPIO whose -corresponding bit in bits is set. - -.br - -.br -Each notification occupies 12 bytes in the fifo as follows: - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint16_t seqno; -.br - uint16_t flags; -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioReport_t; -.br - -.EE - -.br - -.br -seqno: starts at 0 each time the handle is opened and then increments -by one for each report. - -.br - -.br -flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. - -.br - -.br -If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. - -.br - -.br -If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. - -.br - -.br -If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. - -.br - -.br -tick: the number of microseconds since system boot. It wraps around -after 1h12m. - -.br - -.br -level: indicates the level of each GPIO. If bit 1<=0 (as returned by \fBpigpio_start\fP). -.br -handle: 0-31 (as returned by \fBnotify_open\fP) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -Notifications for the handle are suspended until -\fBnotify_begin\fP is called again. - -.IP "\fBint notify_close(int pi, unsigned handle)\fP" -.IP "" 4 -Stop notifications on a previously opened handle and -release the handle for reuse. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: 0-31 (as returned by \fBnotify_open\fP) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint set_watchdog(int pi, unsigned user_gpio, unsigned timeout)\fP" -.IP "" 4 -Sets a watchdog for a GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - timeout: 0-60000. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. - -.br - -.br -The watchdog is nominally in milliseconds. - -.br - -.br -Only one watchdog may be registered per GPIO. - -.br - -.br -The watchdog may be cancelled by setting timeout to 0. - -.br - -.br -Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. - -.br - -.br -The callback will receive the special level PI_TIMEOUT. - -.IP "\fBint set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)\fP" -.IP "" 4 -Sets a glitch filter on a GPIO. - -.br - -.br -Level changes on the GPIO are not reported unless the level -has been stable for at least \fBsteady\fP microseconds. The -level is then reported. Level changes of less than -\fBsteady\fP microseconds are ignored. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31 -.br - steady: 0-300000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - -.br - -.br -This filter affects the GPIO samples returned to callbacks set up -with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP. - -.br - -.br -It does not affect levels read by \fBgpio_read\fP, -\fBread_bank_1\fP, or \fBread_bank_2\fP. - -.br - -.br -Each (stable) edge will be timestamped \fBsteady\fP microseconds -after it was first detected. - -.IP "\fBint set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)\fP" -.IP "" 4 -Sets a noise filter on a GPIO. - -.br - -.br -Level changes on the GPIO are ignored until a level which has -been stable for \fBsteady\fP microseconds is detected. Level changes -on the GPIO are then reported for \fBactive\fP microseconds after -which the process repeats. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31 -.br - steady: 0-300000 -.br - active: 0-1000000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - -.br - -.br -This filter affects the GPIO samples returned to callbacks set up -with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP. - -.br - -.br -It does not affect levels read by \fBgpio_read\fP, -\fBread_bank_1\fP, or \fBread_bank_2\fP. - -.br - -.br -Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. - -.IP "\fBuint32_t read_bank_1(int pi)\fP" -.IP "" 4 -Read the levels of the bank 1 GPIO (GPIO 0-31). - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). - -.IP "\fBint clear_bank_1(int pi, uint32_t bits)\fP" -.IP "" 4 -Clears GPIO 0-31 if the corresponding bit in bits is set. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bits: a bit mask with 1 set if the corresponding GPIO is -.br - to be cleared. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_SOME_PERMITTED. - -.br - -.br -A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. - -.IP "\fBint clear_bank_2(int pi, uint32_t bits)\fP" -.IP "" 4 -Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bits: a bit mask with 1 set if the corresponding GPIO is -.br - to be cleared. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_SOME_PERMITTED. - -.br - -.br -A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. - -.IP "\fBint set_bank_1(int pi, uint32_t bits)\fP" -.IP "" 4 -Sets GPIO 0-31 if the corresponding bit in bits is set. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bits: a bit mask with 1 set if the corresponding GPIO is -.br - to be set. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_SOME_PERMITTED. - -.br - -.br -A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. - -.IP "\fBint set_bank_2(int pi, uint32_t bits)\fP" -.IP "" 4 -Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bits: a bit mask with 1 set if the corresponding GPIO is -.br - to be set. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_SOME_PERMITTED. - -.br - -.br -A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. - -.IP "\fBint hardware_clock(int pi, unsigned gpio, unsigned clkfreq)\fP" -.IP "" 4 -Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - gpio: see description -.br -frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. - -.br - -.br -The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. - -.br - -.br -The GPIO must be one of the following. - -.br - -.br - -.EX -4 clock 0 All models -.br -5 clock 1 All models but A and B (reserved for system use) -.br -6 clock 2 All models but A and B -.br -20 clock 0 All models but A and B -.br -21 clock 1 All models but A and Rev.2 B (reserved for system use) -.br - -.br -32 clock 0 Compute module only -.br -34 clock 0 Compute module only -.br -42 clock 1 Compute module only (reserved for system use) -.br -43 clock 2 Compute module only -.br -44 clock 1 Compute module only (reserved for system use) -.br - -.EE - -.br - -.br -Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. - -.IP "\fBint hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)\fP" -.IP "" 4 -Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. - -.br - -.br -NOTE: Any waveform started by \fBwave_send_*\fP or \fBwave_chain\fP -will be cancelled. - -.br - -.br -This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - gpio: see descripton -.br -PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) -.br -PWMduty: 0 (off) to 1000000 (1M)(fully on) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. - -.br - -.br -The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. - -.br - -.br -The GPIO must be one of the following. - -.br - -.br - -.EX -12 PWM channel 0 All models but A and B -.br -13 PWM channel 1 All models but A and B -.br -18 PWM channel 0 All models -.br -19 PWM channel 1 All models but A and B -.br - -.br -40 PWM channel 0 Compute module only -.br -41 PWM channel 1 Compute module only -.br -45 PWM channel 1 Compute module only -.br -52 PWM channel 0 Compute module only -.br -53 PWM channel 1 Compute module only -.br - -.EE - -.br - -.br -The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). - -.br - -.br -The actual frequency set is 250M/steps (375M/steps for the BCM2711). - -.br - -.br -There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. - -.IP "\fBuint32_t get_current_tick(int pi)\fP" -.IP "" 4 -Gets the current system tick. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Tick is the number of microseconds since system boot. - -.br - -.br -As tick is an unsigned 32 bit quantity it wraps around after -2**32 microseconds, which is approximately 1 hour 12 minutes. - -.br - -.br - -.IP "\fBuint32_t get_hardware_revision(int pi)\fP" -.IP "" 4 -Get the Pi's hardware revision number. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. - -.br - -.br -If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. - -.br - -.br -The revision number can be used to determine the assignment of GPIO -to pins (see \fBgpio\fP). - -.br - -.br -There are at least three types of board. - -.br - -.br -Type 1 boards have hardware revision numbers of 2 and 3. - -.br - -.br -Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. - -.br - -.br -Type 3 boards have hardware revision numbers of 16 or greater. - -.IP "\fBuint32_t get_pigpio_version(int pi)\fP" -.IP "" 4 -Returns the pigpio version. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_clear(int pi)\fP" -.IP "" 4 -This function clears all waveforms and any data added by calls to the -\fBwave_add_*\fP functions. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.IP "\fBint wave_add_new(int pi)\fP" -.IP "" 4 -This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the \fBwave_create\fP function. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.IP "\fBint wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)\fP" -.IP "" 4 -This function adds a number of pulses to the current waveform. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -numPulses: the number of pulses. -.br - pulses: an array of pulses. -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. - -.br - -.br -The pulses are interleaved in time order within the existing waveform -(if any). - -.br - -.br -Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. - -.br - -.br -If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. - -.IP "\fBint wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)\fP" -.IP "" 4 -This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - baud: 50-1000000 -.br -data_bits: number of data bits (1-32) -.br -stop_bits: number of stop half bits (2-8) -.br - offset: >=0 -.br - numBytes: >=1 -.br - str: an array of chars. -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. - -.br - -.br -NOTES: - -.br - -.br -The serial data is formatted as one start bit, \fBdata_bits\fP data bits, -and \fBstop_bits\fP/2 stop bits. - -.br - -.br -It is legal to add serial data streams with different baud rates to -the same waveform. - -.br - -.br -\fBnumBytes\fP is the number of bytes of data in str. - -.br - -.br -The bytes required for each character depend upon \fBdata_bits\fP. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint wave_create(int pi)\fP" -.IP "" 4 -This function creates a waveform from the data provided by the prior -calls to the \fBwave_add_*\fP functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -The data provided by the \fBwave_add_*\fP functions is consumed by this -function. - -.br - -.br -As many waveforms may be created as there is space available. The -wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. - -.br - -.br -Normal usage would be - -.br - -.br -Step 1. \fBwave_clear\fP to clear all waveforms and added data. - -.br - -.br -Step 2. \fBwave_add_*\fP calls to supply the waveform data. - -.br - -.br -Step 3. \fBwave_create\fP to create the waveform and get a unique id - -.br - -.br -Repeat steps 2 and 3 as needed. - -.br - -.br -Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. - -.br - -.br -A waveform comprises one or more pulses. Each pulse consists of a -\fBgpioPulse_t\fP structure. - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br -The fields specify - -.br - -.br -1) the GPIO to be switched on at the start of the pulse. -.br -2) the GPIO to be switched off at the start of the pulse. -.br -3) the delay in microseconds before the next pulse. -.br - -.br - -.br -Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). - -.br - -.br -When a waveform is started each pulse is executed in order with the -specified delay between the pulse and the next. - -.br - -.br -Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. - -.IP "\fBint wave_create_and_pad(int pi, int percent)\fP" -.IP "" 4 -This function creates a waveform like \fBwave_create\fP but pads the consumed -resources. Where percent gives the percentage of the resources to use (in terms -of the theoretical maximum, not the current amount free). This allows the reuse -.br -of deleted waves while a transmission is active. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br -percent: 0-100, size of waveform as percentage of maximum available. -.br - -.EE - -.br - -.br -The data provided by the \fBwave_add_*\fP functions are consumed by this -function. - -.br - -.br -As many waveforms may be created as there is space available. The -wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. - -.br - -.br -A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. - -.br - -.br -Normal usage: - -.br - -.br -Step 1. \fBwave_clear\fP to clear all waveforms and added data. - -.br - -.br -Step 2. \fBwave_add_*\fP calls to supply the waveform data. - -.br - -.br -Step 3. \fBwave_create_and_pad\fP to create a waveform of uniform size. - -.br - -.br -Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. - -.br - -.br -Repeat steps 2-4 as needed. - -.br - -.br -Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. - -.br - -.br -Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. - -.IP "\fBint wave_delete(int pi, unsigned wave_id)\fP" -.IP "" 4 -This function deletes the waveform with id wave_id. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Wave ids are allocated in order, 0, 1, 2, etc. - -.br - -.br -The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. - -.br - -.br -- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. - -.br - -.br -- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_WAVE_ID. - -.IP "\fBint wave_send_once(int pi, unsigned wave_id)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The waveform -is sent once. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_send_repeat(int pi, unsigned wave_id)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by \fBwave_tx_stop\fP). - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)\fP" -.IP "" 4 -Transmits the waveform with id wave_id using mode mode. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -wave_id: >=0, as returned by \fBwave_create\fP. -.br - mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT, -.br - PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC. -.br - -.EE - -.br - -.br -PI_WAVE_MODE_ONE_SHOT: same as \fBwave_send_once\fP. - -.br - -.br -PI_WAVE_MODE_REPEAT same as \fBwave_send_repeat\fP. - -.br - -.br -PI_WAVE_MODE_ONE_SHOT_SYNC same as \fBwave_send_once\fP but tries -to sync with the previous waveform. - -.br - -.br -PI_WAVE_MODE_REPEAT_SYNC same as \fBwave_send_repeat\fP but tries -to sync with the previous waveform. - -.br - -.br -WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_chain(int pi, char *buf, unsigned bufSize)\fP" -.IP "" 4 -This function transmits a chain of waveforms. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br -The waves to be transmitted are specified by the contents of buf -which contains an ordered list of \fBwave_id\fPs and optional command -codes and related data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - buf: pointer to the wave_ids and optional command codes -.br -bufSize: the number of bytes in buf -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. - -.br - -.br -Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. - -.br - -.br -A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. - -.br - -.br -Delays between waves may be added with the delay command. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -Loop Start 255 0 Identify start of a wave block -.br -Loop Repeat 255 1 x y loop x + y*256 times -.br -Delay 255 2 x y delay x + y*256 microseconds -.br -Loop Forever 255 3 loop forever -.br - -.br - -.br -If present Loop Forever must be the last entry in the chain. - -.br - -.br -The code is currently dimensioned to support a chain with roughly -600 entries and 20 loop counters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -#define WAVES 5 -.br -#define GPIO 4 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, pi, wid[WAVES]; -.br - -.br - pi = pigpio_start(0, 0); -.br - if (pi<0) return -1; -.br - -.br - set_mode(pi, GPIO, PI_OUTPUT); -.br - -.br - for (i=0; i=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns the waveform id or one of the following special values: - -.br - -.br -PI_WAVE_NOT_FOUND (9998) - transmitted wave not found. -.br -PI_NO_TX_WAVE (9999) - no wave being transmitted. - -.IP "\fBint wave_tx_busy(int pi)\fP" -.IP "" 4 -This function checks to see if a waveform is currently being -transmitted. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns 1 if a waveform is currently being transmitted, otherwise 0. - -.IP "\fBint wave_tx_stop(int pi)\fP" -.IP "" 4 -This function stops the transmission of the current waveform. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -This function is intended to stop a waveform started with the repeat mode. - -.IP "\fBint wave_get_micros(int pi)\fP" -.IP "" 4 -This function returns the length in microseconds of the current -waveform. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_high_micros(int pi)\fP" -.IP "" 4 -This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_max_micros(int pi)\fP" -.IP "" 4 -This function returns the maximum possible size of a waveform in -.br -microseconds. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_pulses(int pi)\fP" -.IP "" 4 -This function returns the length in pulses of the current waveform. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_high_pulses(int pi)\fP" -.IP "" 4 -This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_max_pulses(int pi)\fP" -.IP "" 4 -This function returns the maximum possible size of a waveform in pulses. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_cbs(int pi)\fP" -.IP "" 4 -This function returns the length in DMA control blocks of the current -waveform. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_high_cbs(int pi)\fP" -.IP "" 4 -This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_max_cbs(int pi)\fP" -.IP "" 4 -This function returns the maximum possible size of a waveform in DMA -control blocks. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)\fP" -.IP "" 4 -This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - pulseLen: 1-100. -.br - level: 0,1. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. - -.IP "\fBint store_script(int pi, char *script)\fP" -.IP "" 4 -This function stores a script for later execution. - -.br - -.br -See \fBhttp://abyz.me.uk/rpi/pigpio/pigs.html#Scripts\fP for details. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script: the text of the script. -.br - -.EE - -.br - -.br -The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. - -.IP "\fBint run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function runs a stored script. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - numPar: 0-10, the number of parameters. -.br - param: an array of parameters. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - numPar: 0-10, the number of parameters. -.br - param: an array of parameters. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint script_status(int pi, unsigned script_id, uint32_t *param)\fP" -.IP "" 4 -This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - param: an array to hold the returned 10 parameters. -.br - -.EE - -.br - -.br -The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. - -.br - -.br -The run status may be - -.br - -.br - -.EX -PI_SCRIPT_INITING -.br -PI_SCRIPT_HALTED -.br -PI_SCRIPT_RUNNING -.br -PI_SCRIPT_WAITING -.br -PI_SCRIPT_FAILED -.br - -.EE - -.br - -.br -The current value of script parameters 0 to 9 are returned in param. - -.IP "\fBint stop_script(int pi, unsigned script_id)\fP" -.IP "" 4 -This function stops a running script. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint delete_script(int pi, unsigned script_id)\fP" -.IP "" 4 -This function deletes a stored script. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)\fP" -.IP "" 4 -This function opens a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - baud: 50-250000 -.br -data_bits: 1-32 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. - -.br - -.br -The serial data is returned in a cyclic buffer and is read using -bb_serial_read. - -.br - -.br -It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. - -.IP "\fBint bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)\fP" -.IP "" 4 -This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - buf: an array to receive the read bytes. -.br - bufSize: >=0 -.br - -.EE - -.br - -.br -Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. - -.br - -.br -The bytes returned for each character depend upon the number of -data bits \fBdata_bits\fP specified in the \fBbb_serial_read_open\fP command. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint bb_serial_read_close(int pi, unsigned user_gpio)\fP" -.IP "" 4 -This function closes a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. - -.IP "\fBint bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)\fP" -.IP "" 4 -This function inverts serial logic for big bang serial reads. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - invert: 0-1, 1 invert, 0 normal. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. - -.IP "\fBint i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)\fP" -.IP "" 4 -This returns a handle for the device at address i2c_addr on bus i2c_bus. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - i2c_bus: >=0. -.br - i2c_addr: 0-0x7F. -.br -i2c_flags: 0. -.br - -.EE - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.br - -.br -Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - SDA SCL -.br -I2C 0 0 1 -.br -I2C 1 2 3 -.br - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. - -.br - -.br -For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. - -.br - -.br - -.EX -S (1 bit) : Start bit -.br -P (1 bit) : Stop bit -.br -Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. -.br -A, NA (1 bit) : Accept and not accept bit. -.br -.br -.br -Addr (7 bits): I2C 7 bit address. -.br -i2c_reg (8 bits): A byte which often selects a register. -.br -Data (8 bits): A data byte. -.br -Count (8 bits): A byte defining the length of a block operation. -.br - -.br -[..]: Data sent by the device. -.br - -.EE - -.IP "\fBint i2c_close(int pi, unsigned handle)\fP" -.IP "" 4 -This closes the I2C device associated with the handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint i2c_write_quick(int pi, unsigned handle, unsigned bit)\fP" -.IP "" 4 -This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - bit: 0-1, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Quick command. SMBus 2.0 5.5.1 - -.EX -S Addr bit [A] P -.br - -.EE - -.IP "\fBint i2c_write_byte(int pi, unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This sends a single byte to the device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - bVal: 0-0xFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Send byte. SMBus 2.0 5.5.2 - -.EX -S Addr Wr [A] bVal [A] P -.br - -.EE - -.IP "\fBint i2c_read_byte(int pi, unsigned handle)\fP" -.IP "" 4 -This reads a single byte from the device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. - -.br - -.br -Receive byte. SMBus 2.0 5.5.3 - -.EX -S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)\fP" -.IP "" 4 -This writes a single byte to the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - bVal: 0-0xFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write byte. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] i2c_reg [A] bVal [A] P -.br - -.EE - -.IP "\fBint i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" -.IP "" 4 -This writes a single 16 bit word to the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - wVal: 0-0xFFFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write word. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P -.br - -.EE - -.IP "\fBint i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)\fP" -.IP "" 4 -This reads a single byte from the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read byte. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)\fP" -.IP "" 4 -This reads a single 16 bit word from the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read word. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] i2c_reg [A] -.br - S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" -.IP "" 4 -This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write/read. -.br - wVal: 0-0xFFFF, the value to write. -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Process call. SMBus 2.0 5.5.6 - -.EX -S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A] -.br - S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes up to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - buf: an array with the data to send. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Block write. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ... -.br - [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)\fP" -.IP "" 4 -This reads a block of up to 32 bytes from the specified register of -the device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - buf: an array to receive the read data. -.br - -.EE - -.br - -.br -The amount of returned data is set by the device. - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Block read. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] i2c_reg [A] -.br - S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write/read. -.br - buf: an array with the data to send and to receive the read data. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. - -.br - -.br -Block write-block read. SMBus 2.0 5.5.8 - -.EX -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ... -.br - S Addr Rd [A] [Count] A [Data] ... A P -.br - -.EE - -.IP "\fBint i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - buf: an array to receive the read data. -.br - count: 1-32, the number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] i2c_reg [A] -.br - S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes 1 to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - buf: the data to write. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the raw device into buf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - buf: an array to receive the read data bytes. -.br - count: >0, the number of bytes to read. -.br - -.EE - -.br - -.br -Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This writes count bytes from buf to the raw device. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - buf: an array containing the data bytes to write. -.br - count: >0, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -On 2 Switch combined flag on -.br -Off 3 Switch combined flag off -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53, write 0x32, read 6 bytes -.br -Set address 0x1E, write 0x03, read 6 bytes -.br -Set address 0x68, write 0x1B, read 8 bytes -.br -End -.br - -.br -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -.br -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -.br -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -.br -0x00 -.br - -.EE - -.br - -.br - -.IP "\fBint bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)\fP" -.IP "" 4 -This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. - -.br - -.br -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -.br - -.br -o baud rates as low as 50 -.br -o repeated starts -.br -o clock stretching -.br -o I2C on any pair of spare GPIO - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - SDA: 0-31 -.br - SCL: 0-31 -.br -baud: 50-500000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -NOTE: - -.br - -.br -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -.IP "\fBint bb_i2c_close(int pi, unsigned SDA)\fP" -.IP "" 4 -This function stops bit banging I2C on a pair of GPIO previously -opened with \fBbb_i2c_open\fP. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -SDA: 0-31, the SDA GPIO used in a prior call to \fBbb_i2c_open\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - -.IP "\fBint bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - SDA: 0-31 (as used in a prior call to \fBbb_i2c_open\fP) -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -Start 2 Start condition -.br -Stop 3 Stop condition -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -.br - -.br -No flags are currently defined. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53 -.br -start, write 0x32, (re)start, read 6 bytes, stop -.br -Set address 0x1E -.br -start, write 0x03, (re)start, read 6 bytes, stop -.br -Set address 0x68 -.br -start, write 0x1B, (re)start, read 8 bytes, stop -.br -End -.br - -.br -0x04 0x53 -.br -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x1E -.br -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x68 -.br -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 -.br - -.br -0x00 -.br - -.EE - -.IP "\fBint bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)\fP" -.IP "" 4 -This function selects a set of GPIO for bit banging SPI at a -specified baud rate. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - CS: 0-31 -.br - MISO: 0-31 -.br - MOSI: 0-31 -.br - SCLK: 0-31 -.br - baud: 50-250000 -.br -spi_flags: see below -.br - -.EE - -.br - -.br -spi_flags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m -.br - -.EE - -.br - -.br -mm defines the SPI mode, defaults to 0 - -.br - -.br - -.EX -Mode CPOL CPHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -p is 0 if CS is active low (default) and 1 for active high. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. - -.br - -.br -The other bits in flags should be set to zero. - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. - -.br - -.br -\fBExample\fP -.br - -.EX -bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1 -.br -bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2 -.br - -.EE - -.IP "\fBint bb_spi_close(int pi, unsigned CS)\fP" -.IP "" 4 -This function stops bit banging SPI on a set of GPIO -opened with \fBbbSPIOpen\fP. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br -CS: 0-31, the CS GPIO used in a prior call to \fBbb_spi_open\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. - -.IP "\fBint bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)\fP" -.IP "" 4 -This function executes a bit banged SPI transfer. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - CS: 0-31 (as used in a prior call to \fBbb_spi_open\fP) -.br -txBuf: pointer to buffer to hold data to be sent -.br -rxBuf: pointer to buffer to hold returned data -.br -count: size of data transfer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. - -.br - -.br -\fBExample\fP -.br - -.EX -// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2 -.br -// ./bb_spi_x_test -.br - -.br -#include -.br - -.br -#include "pigpiod_if2.h" -.br - -.br -#define CE0 5 -.br -#define CE1 6 -.br -#define MISO 13 -.br -#define MOSI 19 -.br -#define SCLK 12 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, pi, count, set_val, read_val; -.br - unsigned char inBuf[3]; -.br - char cmd1[] = {0, 0}; -.br - char cmd2[] = {12, 0}; -.br - char cmd3[] = {1, 128, 0}; -.br - -.br - if ((pi = pigpio_start(0, 0)) < 0) -.br - { -.br - fprintf(stderr, "pigpio initialisation failed (%d).\n", pi); -.br - return 1; -.br - } -.br - -.br - bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC -.br - bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC -.br - -.br - for (i=0; i<256; i++) -.br - { -.br - cmd1[1] = i; -.br - -.br - count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC -.br - -.br - if (count == 2) -.br - { -.br - count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC -.br - -.br - if (count == 2) -.br - { -.br - set_val = inBuf[1]; -.br - -.br - count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC -.br - -.br - if (count == 3) -.br - { -.br - read_val = ((inBuf[1]&3)<<8) | inBuf[2]; -.br - printf("%d %d\n", set_val, read_val); -.br - } -.br - } -.br - } -.br - } -.br - -.br - bb_spi_close(pi, CE0); -.br - bb_spi_close(pi, CE1); -.br - -.br - pigpio_stop(pi); -.br -} -.br - -.EE - -.IP "\fBint spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)\fP" -.IP "" 4 -This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. - -.br - -.br -The Pi has two SPI peripherals: main and auxiliary. - -.br - -.br -The main SPI has two chip selects (channels), the auxiliary has -three. - -.br - -.br -The auxiliary SPI is available on all models but the A and B. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - MISO MOSI SCLK CE0 CE1 CE2 -.br -Main SPI 9 10 11 8 7 - -.br -Aux SPI 19 20 21 18 17 16 -.br - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -spi_channel: 0-1 (0-2 for the auxiliary SPI). -.br - baud: 32K-125M (values above 30M are unlikely to work). -.br - spi_flags: see below. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. - -.br - -.br -spi_flags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -.br - -.EE - -.br - -.br -mm defines the SPI mode. - -.br - -.br -Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. - -.br - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -px is 0 if CEx is active low (default) and 1 for active high. - -.br - -.br -ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. - -.br - -.br -A is 0 for the main SPI, 1 for the auxiliary SPI. - -.br - -.br -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main -SPI only. - -.br - -.br -nnnn defines the number of bytes (0-15) to write before switching -the MOSI line to MISO to read data. This field is ignored -if W is not set. Main SPI only. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. Auxiliary SPI -only. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. Auxiliary SPI -only. - -.br - -.br -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI only. - -.br - -.br -The \fBspi_read\fP, \fBspi_write\fP, and \fBspi_xfer\fP functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. - -.br - -.br -For bits 1-8 there will be one byte per character. -.br -For bits 9-16 there will be two bytes per character. -.br -For bits 17-32 there will be four bytes per character. - -.br - -.br -Multi-byte transfers are made in least significant byte first order. - -.br - -.br -E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. - -.br - -.br -E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed -by 0x1A. - -.br - -.br -The other bits in flags should be set to zero. - -.IP "\fBint spi_close(int pi, unsigned handle)\fP" -.IP "" 4 -This functions closes the SPI device identified by the handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint spi_read(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads count bytes of data from the SPI -device associated with the handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - buf: an array to receive the read data bytes. -.br - count: the number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spi_write(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes of data from buf to the SPI -device associated with the handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - buf: the data bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" -.IP "" 4 -This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - txBuf: the data bytes to write. -.br - rxBuf: the received data bytes. -.br - count: the number of bytes to transfer. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)\fP" -.IP "" 4 -This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. - -.br - -.br - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - ser_tty: the serial device to open. -.br - baud: the baud rate in bits per second, see below. -.br -ser_flags: 0. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. - -.br - -.br -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.IP "\fBint serial_close(int pi, unsigned handle)\fP" -.IP "" 4 -This function closes the serial device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint serial_write_byte(int pi, unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This function writes bVal to the serial port associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serial_read_byte(int pi, unsigned handle)\fP" -.IP "" 4 -This function reads a byte from the serial port associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. - -.br - -.br -If no data is ready PI_SER_READ_NO_DATA is returned. - -.IP "\fBint serial_write(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the serial port -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - buf: the array of bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serial_read(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - buf: an array to receive the read data. -.br - count: the maximum number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. - -.br - -.br -If no data is ready zero is returned. - -.IP "\fBint serial_data_available(int pi, unsigned handle)\fP" -.IP "" 4 -Returns the number of bytes available to be read from the -device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. - -.IP "\fBint custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It returns a single integer value. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -arg1: >=0 -.br -arg2: >=0 -.br -argx: extra (byte) arguments -.br -argc: number of extra arguments -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.IP "\fBint custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It differs from custom_1 in that it returns an array of bytes -rather than just an integer. - -.br - -.br -The return value is an integer indicating the number of returned bytes. - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - arg1: >=0 -.br - argc: extra (byte) arguments -.br - count: number of extra arguments -.br -retBuf: buffer for returned data -.br -retMax: maximum number of bytes to return -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.br - -.br -Note, the number of returned bytes will be retMax or less. - -.IP "\fBint get_pad_strength(int pi, unsigned pad)\fP" -.IP "" 4 -This function returns the pad drive strength in mA. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -pad: 0-2, the pad to get. -.br - -.EE - -.br - -.br -Returns the pad drive strength if OK, otherwise PI_BAD_PAD. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -strength = get_pad_strength(pi, 0); // get pad 0 strength -.br - -.EE - -.IP "\fBint set_pad_strength(int pi, unsigned pad, unsigned padStrength)\fP" -.IP "" 4 -This function sets the pad drive strength in mA. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - pad: 0-2, the pad to set. -.br -padStrength: 1-16 mA. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA -.br - -.EE - -.IP "\fBint shell_(int pi, char *scriptName, char *scriptString)\fP" -.IP "" 4 -This function uses the system call to execute a shell script -with the given string as its parameter. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - scriptName: the name of the script, only alphanumeric characters, -.br - '-' and '_' are allowed in the name. -.br -scriptString: the string to pass to the script. -.br - -.EE - -.br - -.br -The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. - -.br - -.br -scriptName must exist in /opt/pigpio/cgi and must be executable. - -.br - -.br -The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. - -.br - -.br -The following table gives some example returned statuses. - -.br - -.br -Script exit status Returned system call status -.br -1 256 -.br -5 1280 -.br -10 2560 -.br -200 51200 -.br -script not found 32512 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -// pass two parameters, hello and world -.br -status = shell_(pi, "scr1", "hello world"); -.br - -.br -// pass three parameters, hello, string with spaces, and world -.br -status = shell_(pi, "scr1", "hello 'string with spaces' world"); -.br - -.br -// pass one parameter, hello string with spaces world -.br -status = shell_(pi, "scr1", "\"hello string with spaces world\""); -.br - -.EE - -.IP "\fBint file_open(int pi, char *file, unsigned mode)\fP" -.IP "" 4 -This function returns a handle to a file opened in a specified mode. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -file: the file to open. -.br -mode: the file open mode. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. - -.br - -.br -File - -.br - -.br -A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. - -.br - -.br -Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. - -.br - -.br -Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. - -.br - -.br -Suppose /opt/pigpio/access contains the following entries - -.br - -.br - -.EX -/home/* n -.br -/home/pi/shared/dir_1/* w -.br -/home/pi/shared/dir_2/* r -.br -/home/pi/shared/dir_3/* u -.br -/home/pi/shared/dir_1/file.txt n -.br - -.EE - -.br - -.br -Files may be written in directory dir_1 with the exception -of file.txt. - -.br - -.br -Files may be read in directory dir_2. - -.br - -.br -Files may be read and written in directory dir_3. - -.br - -.br -If a directory allows read, write, or read/write access then files may -be created in that directory. - -.br - -.br -In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. - -.br - -.br - -.EX -a path containing .. -.br -a path containing only wildcards (*?) -.br -a path containing less than two non-wildcard parts -.br - -.EE - -.br - -.br -Mode - -.br - -.br -The mode may have the following values. - -.br - -.br -Macro Value Meaning -.br -PI_FILE_READ 1 open file for reading -.br -PI_FILE_WRITE 2 open file for writing -.br -PI_FILE_RW 3 open file for reading and writing -.br - -.br - -.br -The following values may be or'd into the mode. - -.br - -.br -Macro Value Meaning -.br -PI_FILE_APPEND 4 Writes append data to the end of the file -.br -PI_FILE_CREATE 8 The file is created if it doesn't exist -.br -PI_FILE_TRUNC 16 The file is truncated -.br - -.br - -.br -Newly created files are owned by root with permissions owner read and write. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int pi, handle, c; -.br - char buf[60000]; -.br - -.br - pi = pigpio_start(NULL, NULL); -.br - -.br - if (pi < 0) return 1; -.br - -.br - // assumes /opt/pigpio/access contains the following line -.br - // /ram/*.c r -.br - -.br - handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ); -.br - -.br - if (handle >= 0) -.br - { -.br - while ((c=file_read(pi, handle, buf, sizeof(buf)-1))) -.br - { -.br - buf[c] = 0; -.br - printf("%s", buf); -.br - } -.br - -.br - file_close(pi, handle); -.br - } -.br - -.br - pigpio_stop(pi); -.br -} -.br - -.EE - -.IP "\fBint file_close(int pi, unsigned handle)\fP" -.IP "" 4 -This function closes the file associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0 (as returned by \fBfile_open\fP). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -\fBExample\fP -.br - -.EX -file_close(pi, handle); -.br - -.EE - -.IP "\fBint file_write(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the file -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0 (as returned by \fBfile_open\fP). -.br - buf: the array of bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. - -.br - -.br -\fBExample\fP -.br - -.EX -if (file_write(pi, handle, buf, 100) == 0) -.br -{ -.br - // file written okay -.br -} -.br -else -.br -{ -.br - // error -.br -} -.br - -.EE - -.IP "\fBint file_read(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up to count bytes from the the file -associated with handle and writes them to buf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0 (as returned by \fBfile_open\fP). -.br - buf: an array to receive the read data. -.br - count: the maximum number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. - -.br - -.br -\fBExample\fP -.br - -.EX - bytes = file_read(pi, handle, buf, sizeof(buf)); -.br - -.br - if (bytes >= 0) -.br - { -.br - // process read data -.br - } -.br - -.EE - -.IP "\fBint file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)\fP" -.IP "" 4 -This function seeks to a position within the file associated -with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0 (as returned by \fBfile_open\fP). -.br -seekOffset: the number of bytes to move. Positive offsets -.br - move forward, negative offsets backwards. -.br - seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1), -.br - or PI_FROM_END (2). -.br - -.EE - -.br - -.br -Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. - -.br - -.br -\fBExample\fP -.br - -.EX -file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123 -.br - -.br -size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size -.br - -.br -pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position -.br - -.EE - -.IP "\fBint file_list(int pi, char *fpat, char *buf, unsigned count)\fP" -.IP "" 4 -This function returns a list of files which match a pattern. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - fpat: file pattern to match. -.br - buf: an array to receive the matching file names. -.br -count: the maximum number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. - -.br - -.br -The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See \fBfile_open\fP. - -.br - -.br -NOTE - -.br - -.br -The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int pi, handle, c; -.br - char buf[60000]; -.br - -.br - pi = pigpio_start(NULL, NULL); -.br - -.br - if (pi < 0) return 1; -.br - -.br - // assumes /opt/pigpio/access contains the following line -.br - // /ram/*.c r -.br - -.br - c = file_list(pi, "/ram/p*.c", buf, sizeof(buf)); -.br - -.br - if (c >= 0) -.br - { -.br - buf[c] = 0; -.br - printf("%s", buf); -.br - } -.br - -.br - pigpio_stop(pi); -.br -} -.br - -.EE - -.IP "\fBint callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)\fP" -.IP "" 4 -This function initialises a new callback. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - f: the callback function. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -edge 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.EE - -.br - -.br -The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). - -.br - -.br -The number of samples per second is given in the following table. - -.br - -.br - -.EX - samples -.br - per sec -.br - -.br - 1 1,000,000 -.br - 2 500,000 -.br -sample 4 250,000 -.br -rate 5 200,000 -.br -(us) 8 125,000 -.br - 10 100,000 -.br - -.EE - -.br - -.br -GPIO level changes shorter than the sample rate may be missed. - -.br - -.br -The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. - -.br - -.br -If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use \fBgpio_read\fP. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. - -.IP "\fBint callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP" -.IP "" 4 -This function initialises a new callback. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - f: the callback function. -.br - userdata: a pointer to arbitrary user data. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the GPIO, edge, tick, and the userdata -pointer, whenever the GPIO has the identified edge. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -edge 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.br -userdata pointer Pointer to an arbitrary object -.br - -.EE - -.IP "\fBint callback_cancel(unsigned callback_id)\fP" -.IP "" 4 -This function cancels a callback identified by its id. - -.br - -.br - -.EX -callback_id: >=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise pigif_callback_not_found. - -.IP "\fBint wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)\fP" -.IP "" 4 -This function waits for an edge on the GPIO for up to timeout -seconds. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - timeout: >=0. -.br - -.EE - -.br - -.br -The function returns when the edge occurs or after the timeout. - -.br - -.br -Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a \fBcallback\fP function. - -.br - -.br -The function returns 1 if the edge occurred, otherwise 0. - -.IP "\fBint bsc_xfer(int pi, bsc_xfer_t *bscxfer)\fP" -.IP "" 4 -This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. - -.br - -.br -This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. - -.br - -.br -This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. - -.br - -.br -The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. - -.br - -.br -I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. - -.br - -.br -The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bscxfer: a structure defining the transfer. -.br - -.br -typedef struct -.br -{ -.br - uint32_t control; // Write -.br - int rxCnt; // Read only -.br - char rxBuf[BSC_FIFO_SIZE]; // Read only -.br - int txCnt; // Write -.br - char txBuf[BSC_FIFO_SIZE]; // Write -.br -} bsc_xfer_t; -.br - -.EE - -.br - -.br -To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. - -.br - -.br -Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. - -.br - -.br -The returned function value is the status of the transfer (see below). - -.br - -.br -If there was an error the status will be less than zero -(and will contain the error code). - -.br - -.br -The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). - -.br - -.br -Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. - -.br - -.br -GPIO used for models other than those based on the BCM2711. - -.br - -.br - SDA SCL MOSI SCLK MISO CE -.br -I2C 18 19 - - - - -.br -SPI - - 18 19 20 21 -.br - -.br - -.br -GPIO used for models based on the BCM2711 (e.g. the Pi4B). - -.br - -.br - SDA SCL MOSI SCLK MISO CE -.br -I2C 10 11 - - - - -.br -SPI - - 10 11 9 8 -.br - -.br - -.br -When a zero control word is received the used GPIO will be reset -to INPUT mode. - -.br - -.br -control consists of the following bits. - -.br - -.br - -.EX -22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN -.br - -.EE - -.br - -.br -Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. - -.br - -.br -aaaaaaa defines the I2C slave address (only relevant in I2C mode) -.br -IT invert transmit status flags -.br -HC enable host control -.br -TF enable test FIFO -.br -IR invert receive status flags -.br -RE enable receive -.br -TE enable transmit -.br -BK abort operation and clear FIFOs -.br -EC send control register as first I2C byte -.br -ES send status register as first I2C byte -.br -PL set SPI polarity high -.br -PH set SPI phase high -.br -I2 enable I2C mode -.br -SP enable SPI mode -.br -EN enable BSC peripheral -.br - -.br - -.br -The returned status has the following format - -.br - -.br - -.EX -20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - S S S S S R R R R R T T T T T RB TE RF TF RE TB -.br - -.EE - -.br - -.br -Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. - -.br - -.br -SSSSS number of bytes successfully copied to transmit FIFO -.br -RRRRR number of bytes in receieve FIFO -.br -TTTTT number of bytes in transmit FIFO -.br -RB receive busy -.br -TE transmit FIFO empty -.br -RF receive FIFO full -.br -TF transmit FIFO full -.br -RE receive FIFO empty -.br -TB transmit busy -.br - -.br - -.br -The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. - -.br - -.br -\fBExample\fP -.br - -.EX -bsc_xfer_t xfer; -.br - -.br -xfer.control = (0x13<<16) | 0x305; -.br - -.br -memcpy(xfer.txBuf, "ABCD", 4); -.br -xfer.txCnt = 4; -.br - -.br -status = bsc_xfer(pi, &xfer); -.br - -.br -if (status >= 0) -.br -{ -.br - // process transfer -.br -} -.br - -.EE - -.IP "\fBint bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)\fP" -.IP "" 4 -This function allows the Pi to act as a slave I2C device. - -.br - -.br -This function is not available on the BCM2711 (e.g.as -used in the Pi4B). - -.br - -.br -The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -i2c_addr: 0-0x7F. -.br - bscxfer: a structure defining the transfer. -.br - -.br -typedef struct -.br -{ -.br - uint32_t control; // N/A -.br - int rxCnt; // Read only -.br - char rxBuf[BSC_FIFO_SIZE]; // Read only -.br - int txCnt; // Write -.br - char txBuf[BSC_FIFO_SIZE]; // Write -.br -} bsc_xfer_t; -.br - -.EE - -.br - -.br -txCnt is set to the number of bytes to be transmitted, possibly -zero. The data itself should be copied to txBuf. - -.br - -.br -Any received data will be written to rxBuf with rxCnt set. - -.br - -.br -See \fBbsc_xfer\fP for details of the returned status value. - -.br - -.br -If there was an error the status will be less than zero -(and will contain the error code). - -.br - -.br -Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. - -.IP "\fBint event_callback(int pi, unsigned event, evtCBFunc_t f)\fP" -.IP "" 4 -This function initialises an event callback. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -event: 0-31. -.br - f: the callback function. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the event id, and tick, whenever the -event occurs. - -.IP "\fBint event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)\fP" -.IP "" 4 -This function initialises an event callback. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - event: 0-31. -.br - f: the callback function. -.br -userdata: a pointer to arbitrary user data. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the event id, the tick, and the userdata -pointer whenever the event occurs. - -.IP "\fBint event_callback_cancel(unsigned callback_id)\fP" -.IP "" 4 -This function cancels an event callback identified by its id. - -.br - -.br - -.EX -callback_id: >=0, as returned by a call to \fBevent_callback\fP or -.br -\fBevent_callback_ex\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise pigif_callback_not_found. - -.IP "\fBint wait_for_event(int pi, unsigned event, double timeout)\fP" -.IP "" 4 -This function waits for an event for up to timeout seconds. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - event: 0-31. -.br -timeout: >=0. -.br - -.EE - -.br - -.br -The function returns when the event occurs or after the timeout. - -.br - -.br -The function returns 1 if the event occurred, otherwise 0. - -.IP "\fBint event_trigger(int pi, unsigned event)\fP" -.IP "" 4 -This function signals the occurrence of an event. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -event: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - -.br - -.br -An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling \fBevent_callback\fP) will be informed by -a callback. - -.br - -.br -One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. - -.br - -.br -The meaning of other events is arbitrary. - -.br - -.br -Note that other than its id and its tick there is no data associated -with an event. -.SH PARAMETERS - -.br - -.br - -.IP "\fBactive\fP: 0-1000000" 0 - -.br - -.br -The number of microseconds level changes are reported for once -a noise filter has been triggered (by \fBsteady\fP microseconds of -a stable level). - -.br - -.br - -.IP "\fB*addrStr\fP" 0 -A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. - -.br - -.br - -.IP "\fBarg1\fP" 0 -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBarg2\fP" 0 -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBargc\fP" 0 -The count of bytes passed to a user customised function. - -.br - -.br - -.IP "\fB*argx\fP" 0 -A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. - -.br - -.br - -.IP "\fBbaud\fP" 0 -The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. - -.br - -.br - -.IP "\fBbit\fP" 0 -A value of 0 or 1. - -.br - -.br - -.IP "\fBbits\fP" 0 -A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. - -.br - -.br -A convenient way to set bit n is to or in (1<=0, as returned by a call to a callback function, one of - -.br - -.br -\fBcallback\fP -.br -\fBcallback_ex\fP -.br -\fBevent_callback\fP -.br -\fBevent_callback_ex\fP - -.br - -.br -The id is passed to \fBcallback_cancel\fP or \fBevent_callback_cancel\fP -to cancel the callback. - -.br - -.br - -.IP "\fBCBFunc_t\fP" 0 - -.EX -typedef void (*CBFunc_t) -.br - (int pi, unsigned user_gpio, unsigned level, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBCBFuncEx_t\fP" 0 - -.EX -typedef void (*CBFuncEx_t) -.br - (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata); -.br - -.EE - -.br - -.br - -.IP "\fBchar\fP" 0 -A single character, an 8 bit quantity able to store 0-255. - -.br - -.br - -.IP "\fBclkfreq\fP: 4689-250M (13184-375M for the BCM2711)" 0 -The hardware clock frequency. - -.br - -.br - -.IP "\fBcount\fP" 0 -The number of bytes to be transferred in a file, I2C, SPI, or serial -command. - -.br - -.br - -.IP "\fBCS\fP" 0 -The GPIO used for the slave select signal when bit banging SPI. - -.br - -.br - -.IP "\fBdata_bits\fP: 1-32" 0 -The number of data bits in each character of serial data. - -.br - -.br - -.EX -#define PI_MIN_WAVE_DATABITS 1 -.br -#define PI_MAX_WAVE_DATABITS 32 -.br - -.EE - -.br - -.br - -.IP "\fBdouble\fP" 0 -A floating point number. - -.br - -.br - -.IP "\fBdutycycle\fP: 0-range" 0 -A number representing the ratio of on time to off time for PWM. - -.br - -.br -The number may vary between 0 and range (default 255) where -0 is off and range is fully on. - -.br - -.br - -.IP "\fBedge\fP" 0 -Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. - -.br - -.br - -.EX -RISING_EDGE 0 -.br -FALLING_EDGE 1 -.br -EITHER_EDGE. 2 -.br - -.EE - -.br - -.br - -.IP "\fBerrnum\fP" 0 -A negative number indicating a function call failed and the nature -of the error. - -.br - -.br - -.IP "\fBevent\fP: 0-31" 0 -An event is a signal used to inform one or more consumers -to start an action. - -.br - -.br - -.IP "\fBevtCBFunc_t\fP" 0 - -.br - -.br - -.EX -typedef void (*evtCBFunc_t) -.br - (int pi, unsigned event, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBevtCBFuncEx_t\fP" 0 - -.br - -.br - -.EX -typedef void (*evtCBFuncEx_t) -.br - (int pi, unsigned event, uint32_t tick, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBf\fP" 0 -A function. - -.br - -.br - -.IP "\fB*file\fP" 0 -A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. - -.br - -.br - -.IP "\fB*fpat\fP" 0 -A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. - -.br - -.br - -.IP "\fBfrequency\fP: >=0" 0 -The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. - -.br - -.br - -.IP "\fBgpio\fP" 0 -A Broadcom numbered GPIO, in the range 0-53. - -.br - -.br -There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through -GPIO53. - -.br - -.br -They are split into two banks. Bank 1 consists of GPIO0 through -GPIO31. Bank 2 consists of GPIO32 through GPIO53. - -.br - -.br -All the GPIO which are safe for the user to read and write are in -bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards -have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. - -.br - -.br -See \fBget_hardware_revision\fP. - -.br - -.br -The user GPIO are marked with an X in the following table. - -.br - -.br - -.EX - 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -.br -Type 1 X X - - X - - X X X X X - - X X -.br -Type 2 - - X X X - - X X X X X - - X X -.br -Type 3 X X X X X X X X X X X X X X -.br - -.br - 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 -.br -Type 1 - X X - - X X X X X - - - - - - -.br -Type 2 - X X - - - X X X X - X X X X X -.br -Type 3 X X X X X X X X X X X X - - - - -.br - -.EE - -.br - -.br - -.IP "\fBgpioPulse_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br - -.IP "\fBgpioThreadFunc_t\fP" 0 - -.EX -typedef void *(gpioThreadFunc_t) (void *); -.br - -.EE - -.br - -.br - -.IP "\fBhandle\fP: >=0" 0 -A number referencing an object opened by one of - -.br - -.br -\fBfile_open\fP -.br -\fBi2c_open\fP -.br -\fBnotify_open\fP -.br -\fBserial_open\fP -.br -\fBspi_open\fP - -.br - -.br - -.IP "\fBi2c_addr\fP: 0-0x7F" 0 -The address of a device on the I2C bus. - -.br - -.br - -.IP "\fBi2c_bus\fP: >=0" 0 -An I2C bus number. - -.br - -.br - -.IP "\fBi2c_flags\fP: 0" 0 -Flags which modify an I2C open command. None are currently defined. - -.br - -.br - -.IP "\fBi2c_reg\fP: 0-255" 0 -A register of an I2C device. - -.br - -.br - -.IP "\fB*inBuf\fP" 0 -A buffer used to pass data to a function. - -.br - -.br - -.IP "\fBinLen\fP" 0 -The number of bytes of data in a buffer. - -.br - -.br - -.IP "\fBint\fP" 0 -A whole number, negative or positive. - -.br - -.br - -.IP "\fBint32_t\fP" 0 -A 32-bit signed value. - -.br - -.br - -.IP "\fBinvert\fP" 0 -A flag used to set normal or inverted bit bang serial data level logic. - -.br - -.br - -.IP "\fBlevel\fP" 0 -The level of a GPIO. Low or High. - -.br - -.br - -.EX -PI_OFF 0 -.br -PI_ON 1 -.br - -.br -PI_CLEAR 0 -.br -PI_SET 1 -.br - -.br -PI_LOW 0 -.br -PI_HIGH 1 -.br - -.EE - -.br - -.br -There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See \fBset_watchdog\fP. - -.br - -.br - -.EX -PI_TIMEOUT 2 -.br - -.EE - -.br - -.br - -.IP "\fBMISO\fP" 0 -The GPIO used for the MISO signal when bit banging SPI. - -.br - -.br - -.IP "\fBmode\fP" 0 -1. The operational mode of a GPIO, normally INPUT or OUTPUT. - -.br - -.br - -.EX -PI_INPUT 0 -.br -PI_OUTPUT 1 -.br -PI_ALT0 4 -.br -PI_ALT1 5 -.br -PI_ALT2 6 -.br -PI_ALT3 7 -.br -PI_ALT4 3 -.br -PI_ALT5 2 -.br - -.EE - -.br - -.br -2. The mode of waveform transmission. - -.br - -.br - -.EX -PI_WAVE_MODE_ONE_SHOT 0 -.br -PI_WAVE_MODE_REPEAT 1 -.br -PI_WAVE_MODE_ONE_SHOT_SYNC 2 -.br -PI_WAVE_MODE_REPEAT_SYNC 3 -.br - -.EE - -.br - -.br -3. A file open mode. - -.br - -.br - -.EX -PI_FILE_READ 1 -.br -PI_FILE_WRITE 2 -.br -PI_FILE_RW 3 -.br - -.EE - -.br - -.br -The following values can be or'd into the mode. - -.br - -.br - -.EX -PI_FILE_APPEND 4 -.br -PI_FILE_CREATE 8 -.br -PI_FILE_TRUNC 16 -.br - -.EE - -.br - -.br - -.IP "\fBMOSI\fP" 0 -The GPIO used for the MOSI signal when bit banging SPI. - -.br - -.br - -.IP "\fBnumBytes\fP" 0 -The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. - -.br - -.br - -.IP "\fBnumPar\fP: 0-10" 0 -The number of parameters passed to a script. - -.br - -.br - -.IP "\fBnumPulses\fP" 0 -The number of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBoffset\fP" 0 -The associated data starts this number of microseconds from the start of -the waveform. - -.br - -.br - -.IP "\fB*outBuf\fP" 0 -A buffer used to return data from a function. - -.br - -.br - -.IP "\fBoutLen\fP" 0 -The size in bytes of an output buffer. - -.br - -.br - -.IP "\fBpad\fP: 0-2" 0 -A set of GPIO which share common drivers. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br - -.IP "\fBpadStrength\fP: 1-16" 0 -The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. - -.br - -.br - -.IP "\fB*param\fP" 0 -An array of script parameters. - -.br - -.br - -.IP "\fBpercent\fP: 0-100" 0 -The size of waveform as percentage of maximum available. - -.br - -.br - -.IP "\fBpi\fP" 0 -An integer defining a connected Pi. The value is returned by -\fBpigpio_start\fP upon success. - -.br - -.br - -.IP "\fB*portStr\fP" 0 -A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. - -.br - -.br - -.IP "\fB*pth\fP" 0 -A thread identifier, returned by \fBstart_thread\fP. - -.br - -.br - -.br - -.br - -.IP "\fBpthread_t\fP" 0 -A thread identifier. - -.br - -.br - -.IP "\fBpud\fP: 0-2" 0 -The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. - -.EX -PI_PUD_OFF 0 -.br -PI_PUD_DOWN 1 -.br -PI_PUD_UP 2 -.br - -.EE - -.br - -.br - -.IP "\fBpulseLen\fP" 0 -1-100, the length of a trigger pulse in microseconds. - -.br - -.br - -.IP "\fB*pulses\fP" 0 -An array of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBpulsewidth\fP: 0, 500-2500" 0 - -.EX -PI_SERVO_OFF 0 -.br -PI_MIN_SERVO_PULSEWIDTH 500 -.br -PI_MAX_SERVO_PULSEWIDTH 2500 -.br - -.EE - -.br - -.br - -.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 -The hardware PWM dutycycle. - -.br - -.br - -.EX -#define PI_HW_PWM_RANGE 1000000 -.br - -.EE - -.br - -.br - -.IP "\fBPWMfreq\fP: 1-125M (1-187.5M for the BCM2711)" 0 -The hardware PWM frequency. - -.br - -.br - -.EX -#define PI_HW_PWM_MIN_FREQ 1 -.br -#define PI_HW_PWM_MAX_FREQ 125000000 -.br -#define PI_HW_PWM_MAX_FREQ_2711 187500000 -.br - -.EE - -.br - -.br - -.IP "\fBrange\fP: 25-40000" 0 -The permissible dutycycle values are 0-range. - -.br - -.br - -.EX -PI_MIN_DUTYCYCLE_RANGE 25 -.br -PI_MAX_DUTYCYCLE_RANGE 40000 -.br - -.EE - -.br - -.br - -.IP "\fB*retBuf\fP" 0 -A buffer to hold a number of bytes returned to a used customised function, - -.br - -.br - -.IP "\fBretMax\fP" 0 -The maximum number of bytes a user customised function should return. - -.br - -.br - -.br - -.br - -.IP "\fB*rxBuf\fP" 0 -A pointer to a buffer to receive data. - -.br - -.br - -.IP "\fBSCL\fP" 0 -The user GPIO to use for the clock when bit banging I2C. - -.br - -.br - -.IP "\fBSCLK\fP" 0 -The GPIO used for the SCLK signal when bit banging SPI. - -.br - -.br - -.IP "\fB*script\fP" 0 -A pointer to the text of a script. - -.br - -.br - -.IP "\fBscript_id\fP" 0 -An id of a stored script as returned by \fBstore_script\fP. - -.br - -.br - -.IP "\fB*scriptName\fP" 0 -The name of a \fBshell_\fP script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. - -.br - -.br - -.IP "\fB*scriptString\fP" 0 -The string to be passed to a \fBshell_\fP script to be executed. - -.br - -.br - -.IP "\fBSDA\fP" 0 -The user GPIO to use for data when bit banging I2C. - -.br - -.br - -.IP "\fBseconds\fP" 0 -The number of seconds. - -.br - -.br - -.IP "\fBseekFrom\fP" 0 - -.br - -.br - -.EX -PI_FROM_START 0 -.br -PI_FROM_CURRENT 1 -.br -PI_FROM_END 2 -.br - -.EE - -.br - -.br - -.IP "\fBseekOffset\fP" 0 -The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). - -.br - -.br - -.IP "\fBser_flags\fP" 0 -Flags which modify a serial open command. None are currently defined. - -.br - -.br - -.IP "\fB*ser_tty\fP" 0 -The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. - -.br - -.br - -.IP "\fBsize_t\fP" 0 -A standard type used to indicate the size of an object in bytes. - -.br - -.br - -.IP "\fBspi_channel\fP" 0 -A SPI channel, 0-2. - -.br - -.br - -.IP "\fBspi_flags\fP" 0 -See \fBspi_open\fP and \fBbb_spi_open\fP. - -.br - -.br - -.IP "\fBsteady\fP: 0-300000" 0 - -.br - -.br -The number of microseconds level changes must be stable for -before reporting the level changed (\fBset_glitch_filter\fP) or triggering -the active part of a noise filter (\fBset_noise_filter\fP). - -.br - -.br - -.IP "\fBstop_bits\fP: 2-8" 0 -The number of (half) stop bits to be used when adding serial data -to a waveform. - -.br - -.br - -.EX -#define PI_MIN_WAVE_HALFSTOPBITS 2 -.br -#define PI_MAX_WAVE_HALFSTOPBITS 8 -.br - -.EE - -.br - -.br - -.IP "\fB*str\fP" 0 - An array of characters. - -.br - -.br - -.IP "\fBthread_func\fP" 0 -A function of type gpioThreadFunc_t used as the main function of a -thread. - -.br - -.br - -.IP "\fBtimeout\fP" 0 -A GPIO watchdog timeout in milliseconds. - -.br - -.br - -.EX -PI_MIN_WDOG_TIMEOUT 0 -.br -PI_MAX_WDOG_TIMEOUT 60000 -.br - -.EE - -.br - -.br - -.IP "\fB*txBuf\fP" 0 -An array of bytes to transmit. - -.br - -.br - -.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 -A 32-bit unsigned value. - -.br - -.br - -.IP "\fBunsigned\fP" 0 -A whole number >= 0. - -.br - -.br - -.IP "\fBuser_gpio\fP" 0 -0-31, a Broadcom numbered GPIO. - -.br - -.br -See \fBgpio\fP. - -.br - -.br - -.IP "\fB*userdata\fP" 0 - -.br - -.br -A pointer to arbitrary user data. This may be used to identify the instance. - -.br - -.br -You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. - -.br - -.br -In the calling function: - -.br - -.br - -.EX -user_type *userdata; -.br -.br -.br -user_type my_userdata; -.br - -.br -userdata = malloc(sizeof(user_type)); -.br -.br -.br -*userdata = my_userdata; -.br - -.EE - -.br - -.br -In the receiving function: - -.br - -.br - -.EX -user_type my_userdata = *(user_type*)userdata; -.br - -.br -free(userdata); -.br - -.EE - -.br - -.br - -.IP "\fBvoid\fP" 0 -Denoting no parameter is required - -.br - -.br - -.IP "\fBwave_add_*\fP" 0 -One of - -.br - -.br -\fBwave_add_new\fP -.br -\fBwave_add_generic\fP -.br -\fBwave_add_serial\fP - -.br - -.br - -.IP "\fBwave_id\fP" 0 -A number representing a waveform created by \fBwave_create\fP. - -.br - -.br - -.IP "\fBwave_send_*\fP" 0 -One of - -.br - -.br -\fBwave_send_once\fP -.br -\fBwave_send_repeat\fP - -.br - -.br - -.IP "\fBwVal\fP: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)" 0 -A 16-bit word value. - -.br - -.br -.SH pigpiod_if2 Error Codes - -.EX - -.br -typedef enum -.br -{ -.br - pigif_bad_send = -2000, -.br - pigif_bad_recv = -2001, -.br - pigif_bad_getaddrinfo = -2002, -.br - pigif_bad_connect = -2003, -.br - pigif_bad_socket = -2004, -.br - pigif_bad_noib = -2005, -.br - pigif_duplicate_callback = -2006, -.br - pigif_bad_malloc = -2007, -.br - pigif_bad_callback = -2008, -.br - pigif_notify_failed = -2009, -.br - pigif_callback_not_found = -2010, -.br - pigif_unconnected_pi = -2011, -.br - pigif_too_many_pis = -2012, -.br -} pigifError_t; -.br - -.br - -.EE - -.SH SEE ALSO - -pigpiod(1), pig2vcd(1), pigs(1), pigpio(3), pigpiod_if(3) -.SH AUTHOR - -joan@abyz.me.uk diff --git a/DOC/MAN/pigs.1 b/DOC/MAN/pigs.1 deleted file mode 100644 index 9b6192c..0000000 --- a/DOC/MAN/pigs.1 +++ /dev/null @@ -1,6331 +0,0 @@ - -." Process this file with -." groff -man -Tascii foo.1 -." -.TH pigs 1 2012-2020 Linux "pigpio archive" -.SH NAME -pigs - command line socket access to the pigpio daemon. - -/dev/pigpio - command line pipe access to the pigpio daemon. - -.SH SYNOPSIS - -.B sudo pigpiod - -then - -.B pigs {command}+ - -or - -.B "echo {command}+ >/dev/pigpio" - -.SH DESCRIPTION - -.ad l - -.nh - - -.br -The socket and pipe interfaces allow control of the Pi's GPIO by -passing messages to the running pigpio library. - -.br -The normal way to start the pigpio library would be as a daemon during boot. - -.br - -.EX -sudo pigpiod -.br - -.EE - -.br -.SS Features -.br -o hardware timed PWM on any of GPIO 0-31 - -.br -o hardware timed servo pulses on any of GPIO 0-31 - -.br -o reading/writing all of the GPIO in a bank as one operation - -.br -o individually setting GPIO modes, reading and writing - -.br -o notifications when any of GPIO 0-31 change state - -.br -o the construction of output waveforms with microsecond timing - -.br -o I2C, SPI, and serial link wrappers - -.br -o creating and running scripts on the pigpio daemon - -.br -.SS GPIO -.br -ALL GPIO are identified by their Broadcom number. - -.br -.SS Usage -.br -pigs is a program and internally uses the socket interface to pigpio -whereas /dev/pigpio uses the pipe interface. - -.br -pigs and the pipe interface share the same commands and are invoked in -a similar fashion from the command line. - -.br -The pigpio library must be running, either by running a program linked -with the library or starting the pigpio daemon (sudo pigpiod). - -.br -pigs {command}+ - -.br -echo "{command}+" >/dev/pigpio - -.br -pigs will show the result of the command on screen. - -.br -The pigs process returns an exit status (which can be displayed with -the command echo $?). - -.br - -.EX -PIGS_OK 0 -.br -PIGS_CONNECT_ERR 255 -.br -PIGS_OPTION_ERR 254 -.br -PIGS_SCRIPT_ERR 253 -.br -.br -.br - -.EE - -.br -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). - -.br -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. - -.br -Several commands may be entered on a line. If present PROC and PARSE must -be the last command on a line. - -.br -E.g. - -.br - -.EX -pigs w 22 1 mils 1000 w 22 0 -.br - -.EE - -.br -is equivalent to - -.br - -.EX -pigs w 22 1 -.br -pigs mils 1000 -.br -pigs w 22 0 -.br - -.EE - -.br -and - -.br - -.EX -echo "m 4 w w 4 0 mils 250 m 4 r r 4" >/dev/pigpio -.br - -.EE - -.br -is equivalent to - -.br - -.EX -echo "m 4 w" >/dev/pigpio -.br -echo "w 4 0" >/dev/pigpio -.br -echo "mils 250" >/dev/pigpio -.br -echo "m 4 r" >/dev/pigpio -.br -echo "r 4" >/dev/pigpio -.br - -.EE - -.br -.SS Notes -.br -The examples from now on will show the pigs interface but the same -commands will also work on the pipe interface. - -.br -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. - -.br -The status/data of each command sent to the pipe interface should -be read from /dev/pigout. - -.br -When a command takes a number as a parameter it may be entered as hex -(precede by 0x), octal (precede by 0), or decimal. - -.br -E.g. 23 is 23 decimal, 0x100 is 256 decimal, 070 is 56 decimal. - -.br -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. - -.br -E.g. assuming the transmitted serial data is the letters ABCDEONM - -.br - -.EX -$ pigs slr 4 100 -.br -8 65 66 67 68 69 79 78 77 -.br - -.br -$ pigs -a slr 4 100 -.br -8 ABCDEONM -.br - -.br -$ pigs -x slr 4 100 -.br -8 41 42 43 44 45 4f 4e 4d -.br - -.EE - -.br - -.SH OVERVIEW -.SS BASIC -.B M/MODES g m -Set GPIO mode -.P -.B MG/MODEG g -Get GPIO mode -.P -.B PUD g p -Set GPIO pull up/down -.P -.B R/READ g -Read GPIO level -.P -.B W/WRITE g L -Write GPIO level -.P -.SS PWM (overrides servo commands on same GPIO) -.B P/PWM u v -Set GPIO PWM value -.P -.B PFS u v -Set GPIO PWM frequency -.P -.B PRS u v -Set GPIO PWM range -.P -.B GDC u -Get GPIO PWM dutycycle -.P -.B PFG u -Get GPIO PWM frequency -.P -.B PRG u -Get GPIO PWM range -.P -.B PRRG u -Get GPIO PWM real range -.P -.SS Servo (overrides PWM commands on same GPIO) -.B S/SERVO u v -Set GPIO servo pulsewidth -.P -.B GPW u -Get GPIO servo pulsewidth -.P -.SS INTERMEDIATE -.B TRIG u pl L -Send a trigger pulse -.P -.B WDOG u v -Set GPIO watchdog -.P -.B BR1 -Read bank 1 GPIO -.P -.B BR2 -Read bank 2 GPIO -.P -.B BC1 bits -Clear specified GPIO in bank 1 -.P -.B BC2 bits -Clear specified GPIO in bank 2 -.P -.B BS1 bits -Set specified GPIO in bank 1 -.P -.B BS2 bits -Set specified GPIO in bank 2 -.P -.SS ADVANCED -.B NO -Request a notification -.P -.B NC h -Close notification -.P -.B NB h bits -Start notification -.P -.B NP h -Pause notification -.P -.B HC g cf -Set hardware clock frequency -.P -.B HP g pf pdc -Set hardware PWM frequency and dutycycle -.P -.B FG u stdy -Set a glitch filter on a GPIO -.P -.B FN u stdy actv -Set a noise filter on a GPIO -.P -.B PADS pad padma -Set pad drive strength -.P -.B PADG pad -Get pad drive strength -.P -.B SHELL name str -Execute a shell command -.P -.SS Custom -.B CF1 uvs -Custom function 1 -.P -.B CF2 uvs -Custom function 2 -.P -.SS Events -.B EVM h bits -Set events to monitor -.P -.B EVT event -Trigger event -.P -.SS Scripts -.B PROC t -Store script -.P -.B PROCR sid pars -Run script -.P -.B PROCU sid pars -Set script parameters -.P -.B PROCP sid -Get script status and parameters -.P -.B PROCS sid -Stop script -.P -.B PROCD sid -Delete script -.P -.B PARSE t -Validate script -.P -.SS I2C -.B I2CO ib id if -Open I2C bus and device with flags -.P -.B I2CC h -Close I2C handle -.P -.B I2CWQ h bit -smb Write Quick: write bit -.P -.B I2CRS h -smb Read Byte: read byte -.P -.B I2CWS h bv -smb Write Byte: write byte -.P -.B I2CRB h r -smb Read Byte Data: read byte from register -.P -.B I2CWB h r bv -smb Write Byte Data: write byte to register -.P -.B I2CRW h r -smb Read Word Data: read word from register -.P -.B I2CWW h r wv -smb Write Word Data: write word to register -.P -.B I2CRK h r -smb Read Block Data: read data from register -.P -.B I2CWK h r bvs -smb Write Block Data: write data to register -.P -.B I2CWI h r bvs -smb Write I2C Block Data -.P -.B I2CRI h r num -smb Read I2C Block Data: read bytes from register -.P -.B I2CRD h num -i2c Read device -.P -.B I2CWD h bvs -i2c Write device -.P -.B I2CPC h r wv -smb Process Call: exchange register with word -.P -.B I2CPK h r bvs -smb Block Process Call: exchange data bytes with register -.P -.B I2CZ h bvs -Performs multiple I2C transactions -.P -.SS I2C BIT BANG -.B BI2CO sda scl b -Open bit bang I2C -.P -.B BI2CC sda -Close bit bang I2C -.P -.B BI2CZ sda bvs -I2C bit bang multiple transactions -.P -.SS I2C/SPI SLAVE -.B BSCX bctl bvs -BSC I2C/SPI transfer -.P -.SS SERIAL -.B SERO dev b sef -Open serial device dev at baud b with flags -.P -.B SERC h -Close serial handle -.P -.B SERRB -Read byte from serial handle -.P -.B SERWB h bv -Write byte to serial handle -.P -.B SERR h num -Read bytes from serial handle -.P -.B SERW h bvs -Write bytes to serial handle -.P -.B SERDA h -Check for serial data ready to read -.P -.SS SERIAL BIT BANG (read only) -.B SLRO u b db -Open GPIO for bit bang serial data -.P -.B SLRC u -Close GPIO for bit bang serial data -.P -.B SLRI u v -Sets bit bang serial data logic levels -.P -.B SLR u num -Read bit bang serial data from GPIO -.P -.SS SPI -.B SPIO c b spf -SPI open channel at baud b with flags -.P -.B SPIC h -SPI close handle -.P -.B SPIR h num -SPI read bytes from handle -.P -.B SPIW h bvs -SPI write bytes to handle -.P -.B SPIX h bvs -SPI transfer bytes to handle -.P -.SS SPI BIT BANG -.B BSPIO cs miso mosi sclk b spf -Open bit bang SPI -.P -.B BSPIC cs -Close bit bang SPI -.P -.B BSPIX cs bvs -SPI bit bang transfer -.P -.SS FILES -.B FO file mode -Open a file in mode -.P -.B FC h -Close file handle -.P -.B FR h num -Read bytes from file handle -.P -.B FW h bvs -Write bytes to file handle -.P -.B FS h num from -Seek to file handle position -.P -.B FL pat num -List files which match pattern -.P -.SS WAVES -.B WVCLR -Clear all waveforms -.P -.B WVNEW -Initialise a new waveform -.P -.B WVAG trips -Add generic pulses to waveform -.P -.B WVAS u b db sb o bvs -Add serial data to waveform -.P -.B WVCRE -Create a waveform -.P -.B WVCAP -Create a waveform of fixed size -.P -.B WVDEL wid -Delete selected waveform -.P -.B WVTX wid -Transmits waveform once -.P -.B WVTXM wid wmde -Transmits waveform using mode -.P -.B WVTXR wid -Transmits waveform repeatedly -.P -.B WVCHA bvs -Transmits a chain of waveforms -.P -.B WVTAT -Returns the current transmitting waveform -.P -.B WVBSY -Check if waveform is being transmitted -.P -.B WVHLT -Stop waveform -.P -.B WVSC ws -Get waveform DMA CB stats -.P -.B WVSM ws -Get waveform time stats -.P -.B WVSP ws -Get waveform pulse stats -.P -.SS UTILITIES -.B H/HELP -Display command help -.P -.B HWVER -Get hardware version -.P -.B MICS v -Microseconds delay -.P -.B MILS v -Milliseconds delay -.P -.B PIGPV -Get pigpio library version -.P -.B T/TICK -Get current tick -.P -.SS CONFIGURATION -.B CGI -Configuration get internals -.P -.B CSI v -Configuration set internals -.P - -.SH COMMANDS - -.br - -.IP "\fBBC1 bits\fP - Clear specified GPIO in bank 1" -.IP "" 4 -This command clears (sets low) the GPIO specified by \fBbits\fP in bank 1. -Bank 1 consists of GPIO 0-31. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bc1 0x400010 # clear GPIO 4 (1<<4) and 22 (1<<22) -.br - -.br -$ pigs bc1 32 # clear GPIO 5 (1<<5) -.br --42 -.br -ERROR: no permission to update one or more GPIO -.br - -.EE - -.br - -.IP "\fBBC2 bits\fP - Clear specified GPIO in bank 2" -.IP "" 4 -This command clears (sets low) the GPIO specified by \fBbits\fP in bank 2. -Bank 2 consists of GPIO 32-53. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bc2 0x8000 # clear GPIO 47 (activity LED on A+/B+/Pi2/Pi3) -.br - -.br -$ pigs bc2 1 # clear GPIO 32 (first in bank 2) -.br --42 -.br -ERROR: no permission to update one or more GPIO -.br - -.EE - -.br - -.IP "\fBBI2CC sda\fP - Close bit bang I2C" -.IP "" 4 -This command signals that bit banging I2C on \fBsda\fP (and \fBscl\fP) is no -longer required. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bi2cc 5 -.br - -.EE - -.br - -.IP "\fBBI2CO sda scl b\fP - Open bit bang I2C" -.IP "" 4 -This command signals that GPIO \fBsda\fP and \fBscl\fP are to be used -for bit banging I2C at \fBb\fP baud. - -.br -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -.br -o baud rates as low as 50 -.br -o repeated starts -.br -o clock stretching -.br -o I2C on any pair of spare GPIO - -.br -The baud rate may be between 50 and 500000 bits per second. - -.br -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -.br - -.IP "\fBBI2CZ sda bvs\fP - I2C bit bang multiple transactions" -.IP "" 4 -This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of \fBbvs\fP -which contains the concatenated command codes and associated data. - -.br -The following command codes are supported: - -.br - -.EX -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 - -.EE - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -.br -No flags are currently defined. - -.br - -\fBExample\fP -.br - -.EX -Set address 0x53 -.br -start, write 0x32, (re)start, read 6 bytes, stop -.br -Set address 0x1E -.br -start, write 0x03, (re)start, read 6 bytes, stop -.br -Set address 0x68 -.br -start, write 0x1B, (re)start, read 8 bytes, stop -.br -End -.br - -.br -0x04 0x53 -.br -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x1E -.br -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x68 -.br -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 -.br - -.br -0x00 -.br - -.EE - -.br - -.IP "\fBBR1 \fP - Read bank 1 GPIO" -.IP "" 4 -This command read GPIO 0-31 (bank 1) and returns the levels as a -32-bit hexadecimal value. - -.br - -\fBExample\fP -.br - -.EX -$ pigs br1 -.br -1001C1CF -.br - -.EE - -.br - -.IP "\fBBR2 \fP - Read bank 2 GPIO" -.IP "" 4 -This command read GPIO 32-53 (bank 2) and returns the levels as a -32-bit hexadecimal value. - -.br - -\fBExample\fP -.br - -.EX -$ pigs br2 -.br -003F0000 -.br - -.EE - -.br - -.IP "\fBBS1 bits\fP - Set specified GPIO in bank 1" -.IP "" 4 -This command sets (sets high) the GPIO specified by \fBbits\fP in bank 1. -Bank 1 consists of GPIO 0-31. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bs1 16 # set GPIO 4 (1<<4) -.br - -.br -$ pigs bs1 1 # set GPIO 1 (1<<0) -.br --42 -.br -ERROR: no permission to update one or more GPIO -.br - -.EE - -.br - -.IP "\fBBS2 bits\fP - Set specified GPIO in bank 2" -.IP "" 4 -This command sets (sets high) the GPIO specified by \fBbits\fP in bank 2. -Bank 2 consists of GPIO 32-53. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bs2 0x40 # set GPIO 38 (enable high current mode A+/B+/Pi2/Pi3) -.br - -.br -$ pigs bs2 1 # set GPIO 32 (first in bank 2) -.br --42 -.br -ERROR: no permission to update one or more GPIO -.br - -.EE - -.br - -.IP "\fBBSCX bctl bvs\fP - BSC I2C/SPI transfer" -.IP "" 4 - -.br -This command performs a BSC I2C/SPI slave transfer as defined by -\fBbctl\fP with data \fBbvs\fP. - -.br -This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. - -.br -This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. - -.br -This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. - -.br -The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. - -.br -I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. - -.br -The command sets the BSC mode and writes any data \fBbvs\fP -to the BSC transmit FIFO. It returns the data count (at least 1 -for the status word), the status word, followed by any data bytes -read from the BSC receive FIFO. - -.br -Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. - -.br -For I2C use a control word of (I2C address << 16) + 0x305. - -.br -E.g. to talk as I2C slave with address 0x13 use 0x130305. - -.br -GPIO used for models other than those based on the BCM2711. - -.br - -.EX - SDA SCL MOSI SCLK MISO CE -I2C 18 19 - - - - -SPI - - 18 19 20 21 - -.EE - -.br -GPIO used for models based on the BCM2711 (e.g. the Pi4B). - -.br - -.EX - SDA SCL MOSI SCLK MISO CE -I2C 10 11 - - - - -SPI - - 10 11 9 8 - -.EE - -.br -When a zero control word is received the used GPIO will be reset -to INPUT mode. - -.br -The control word consists of the following bits. - -.br - -.EX -22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN -.br - -.EE - -.br -Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. - -.br - -.EX -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 - -.EE - -.br -The returned status has the following format - -.br - -.EX -20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - S S S S S R R R R R T T T T T RB TE RF TF RE TB -.br - -.EE - -.br -Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. - -.br - -.EX -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 - -.EE - -.br -This example assumes that GPIO 2/3 are connected to GPIO 18/19 -(GPIO 10/11 on the BCM2711). - -.br - -\fBExample\fP -.br - -.EX -$ pigs bscx 0x130305 # start BSC as I2C slave 0x13 -.br -1 18 -.br - -.br -$ i2cdetect -y 1 -.br - 0 1 2 3 4 5 6 7 8 9 a b c d e f -.br -00: -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- -- -.br -20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -70: -- -- -- -- -- -- -- -- -.br - -.br -$ pigs i2co 1 0x13 0 # get handle for device 0x13 on bus 1 -.br -0 -.br - -.br -$ pigs i2cwd 0 90 87 51 9 23 # write 5 bytes -.br - -.br -$ pigs bscx 0x130305 # check for data -.br -6 18 90 87 51 9 23 -.br - -.br -$ pigs bscx 0x130305 11 13 15 17 # check for data and send 4 bytes -.br -1 262338 -.br - -.br -$ pigs i2crd 0 4 # read 4 bytes -.br -4 11 13 15 17 -.br - -.br -$ pigs i2cwd 0 90 87 51 9 23 # write 5 bytes -.br -$ pigs bscx 0x130305 11 13 15 17 # check for data and send 4 bytes -.br -6 262338 90 87 51 9 23 -.br - -.br -$ pigs i2crd 0 4 -.br -4 11 13 15 17 -.br - -.br -$ pigs bscx 0x130305 22 33 44 55 66 -.br -1 327938 -.br -$ pigs i2crd 0 5 -.br -5 22 33 44 55 66 -.br - -.EE - -.br - -.IP "\fBBSPIC cs\fP - Close bit bang SPI" -.IP "" 4 - -.br -This command stops bit banging SPI on a set of GPIO -opened with \fBBSPIO\fP. - -.br -The set of GPIO is specifed by \fBcs\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bspic 10 -.br - -.br -$ pigs bspic 10 -.br --142 -.br -ERROR: no bit bang SPI in progress on GPIO -.br - -.EE - -.br - -.IP "\fBBSPIO cs miso mosi sclk b spf\fP - Open bit bang SPI" -.IP "" 4 - -.br -This command starts bit banging SPI on a group of GPIO with slave -select \fBcs\fP, MISO \fBmiso\fP, MOSI \fBmosi\fP, and clock \fBsclk\fP. - -.br -Data will be transferred at baud \fBb\fP bits per second (which may -be set in the range 50-250000). - -.br -The flags \fBspf\fP may be used to modify the default behaviour of -mode 0, active low chip select. - -.br -The flags consists of the least significant 22 bits. - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m -.br - -.EE - -.br -mm defines the SPI mode. - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br -p is 0 if CS is active low (default) and 1 for active high. - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. - -.br -The other bits in flags should be set to zero. - -.br -Upon success 0 is returned. On error a negative status code -will be returned. - -.br -If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bspio 9 11 12 13 50000 0 -.br - -.br -$ pigs bspio 10 11 12 13 50000 0 -.br - -.br -$ pigs bspio 29 19 20 21 50000 0 # GPIO 29 not avaialble on this Pi -.br --41 -.br -ERROR: no permission to update GPIO -.br - -.EE - -.br - -.IP "\fBBSPIX cs bvs\fP - SPI bit bang transfer" -.IP "" 4 - -.br -This command writes bytes \fBbvs\fP to the bit bang SPI device -associated with slave select \fBcs\fP. It returns the same -number of bytes read from the device. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bspio 5 13 19 12 10000 0 # MCP4251 DAC -.br -$ pigs bspio 6 13 19 12 20000 3 # MCP3008 ADC -.br - -.br -$ pigs bspix 5 0 16 # set DAC to 16 -.br -2 255 255 -.br - -.br -$ pigs bspix 5 12 0 # read back DAC -.br -2 254 16 -.br - -.br -$ pigs bspix 6 1 128 0 # read ADC input 0 -.br -3 0 3 184 # 952 -.br - -.br -$ pigs bspix 5 0 240 # set DAC to 240 -.br -2 255 255 -.br - -.br -$ pigs bspix 5 12 0 # read back DAC -.br -2 254 240 -.br - -.br -$ pigs bspix 6 1 128 0 # read ADC input 0 -.br -3 0 0 63 # 63 -.br - -.br -$ pigs bspix 5 0 128 # set DAC to 128 -.br -2 255 255 -.br - -.br -$ pigs bspix 5 12 0 # read back DAC -.br -2 254 128 -.br - -.br -$ pigs bspix 6 1 128 0 # read ADC input 0 -.br -3 0 1 255 # 511 -.br - -.br -$ pigs bspic 5 # close SPI CS 5 -.br -$ pigs bspic 6 # close SPI CS 6 -.br - -.br -$ pigs bspic 5 # try to close SPI CS 5 again -.br --142 -.br -ERROR: no bit bang SPI in progress on GPIO -.br - -.EE - -.br - -.br - -.IP "\fBCF1 uvs\fP - Custom function 1" -.IP "" 4 - -.br -This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. - -.br - -.IP "\fBCF2 uvs\fP - Custom function 2" -.IP "" 4 - -.br -This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. - -.br - -.IP "\fBCGI \fP - Configuration get internals" -.IP "" 4 -This command returns the value of the internal library -configuration settings. - -.br - -.IP "\fBCSI v\fP - Configuration set internals" -.IP "" 4 -This command sets the value of the internal library -configuration settings to \fBv\fP. - -.br - -.IP "\fBEVM h bits\fP - Set events to monitor" -.IP "" 4 -This command starts event reporting on handle \fBh\fP (returned by -a prior call to \fBNO\fP). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The notification gets reports for each event specified by \fBbits\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs evm 0 -1 # Shorthand for events 0-31. -.br -$ pigs evm 0 0xf0 # Get notifications for events 4-7. -.br - -.br -$ pigs evm 1 0xf -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBEVT event\fP - Trigger event" -.IP "" 4 -This command triggers event \fBevent\fP. - -.br -One event, number 31, is predefined. This event is -auto generated on BSC slave activity. - -.br - -\fBExample\fP -.br - -.EX -$ pigs evt 12 -.br -$ pigs evt 5 -.br - -.br -$ pigs evt 32 -.br --143 -.br -ERROR: bad event id -.br - -.EE - -.br - -.IP "\fBFC h\fP - Close file handle" -.IP "" 4 -This command closes a file handle \fBh\fP previously opened with \fBFO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fc 0 # First close okay. -.br - -.br -$ pigs fc 0 # Second fails. -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBFG u stdy\fP - Set a glitch filter on a GPIO" -.IP "" 4 - -.br -Level changes on the GPIO \fBu\fP are not reported unless the level -has been stable for at least \fBstdy\fP microseconds. The -level is then reported. Level changes of less than \fBstdy\fP -microseconds are ignored. - -.br -The filter only affects callbacks (including pipe notifications). - -.br -The \fBR/READ\fP, \fBBR1\fP, and \fBBR2\fP commands are not affected. - -.br -Note, each (stable) edge will be timestamped \fBstdy\fP microseconds -after it was first detected. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fg 4 250 -.br - -.br -$ pigs fg 4 1000000 -.br --125 -.br -ERROR: bad filter parameter -.br - -.EE - -.br - -.IP "\fBFL pat num\fP - List files which match pattern" -.IP "" 4 -This command returns a list of the files matching \fBpat\fP. Up -to \fBnum\fP bytes may be returned. - -.br -Upon success the count of returned bytes followed by the matching -files is returned. On error a negative status code will be returned. - -.br -A newline (0x0a) character separates each file name. - -.br -Only files which have a matching entry in /opt/pigpio/access may -be listed. - -.br -Suppose /opt/pigpio/access contains - -.br -/sys/bus/w1/devices/28*/w1_slave r - -.br - -\fBExample\fP -.br - -.EX -$ pigs -a fl "/sys/bus/w1/devices/28*/w1_slave" 5000 -.br -90 /sys/bus/w1/devices/28-000005d34cd2/w1_slave -.br -/sys/bus/w1/devices/28-001414abbeff/w1_slave -.br - -.br -$ pigs -a fl "/sys/bus/*" 5000 -.br -ERROR: no permission to access file -.br --137 -.br - -.EE - -.br - -.IP "\fBFN u stdy actv\fP - Set a noise filter on a GPIO" -.IP "" 4 - -.br -Level changes on the GPIO \fBu\fP are ignored until a level which has -been stable for \fBstdy\fP microseconds is detected. Level -changes on the GPIO are then reported for \fBactv\fP microseconds -after which the process repeats. - -.br -The filter only affects callbacks (including pipe notifications). - -.br -The \fBR/READ\fP, \fBBR1\fP, and \fBBR2\fP commands are not affected. - -.br -Note, level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fn 7 250 1000 -.br - -.br -$ pigs fn 7 2500000 1000 -.br --125 -.br -ERROR: bad filter parameter -.br - -.EE - -.br - -.IP "\fBFO file mode\fP - Open a file in mode" -.IP "" 4 -This function returns a handle to a file \fBfile\fP opened -in a specified mode \fBmode\fP. - -.br -Upon success a handle (>=0) is returned. On error a negative status code -will be returned. - -.br -File - -.br -A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. - -.br -Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. - -.br -Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. - -.br -Suppose /opt/pigpio/access contains the following entries - -.br - -.EX -/home/* n -.br -/home/pi/shared/dir_1/* w -.br -/home/pi/shared/dir_2/* r -.br -/home/pi/shared/dir_3/* u -.br -/home/pi/shared/dir_1/file.txt n -.br - -.EE - -.br -Files may be written in directory dir_1 with the exception -of file.txt. - -.br -Files may be read in directory dir_2. - -.br -Files may be read and written in directory dir_3. - -.br -If a directory allows read, write, or read/write access then files may -be created in that directory. - -.br -In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. - -.br - -.EX -a path containing .. -.br -a path containing only wildcards (*?) -.br -a path containing less than two non-wildcard parts -.br - -.EE - -.br -Mode - -.br -The mode may have the following values. - -.br - -.EX - Value Meaning -READ 1 open file for reading -WRITE 2 open file for writing -RW 3 open file for reading and writing - -.EE - -.br -The following values may be or'd into the mode. - -.br - -.EX - 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 - -.EE - -.br -Newly created files are owned by root with permissions owner read and write. - -.br - -\fBExample\fP -.br - -.EX -$ ls /ram/*.c -.br -/ram/command.c /ram/pigpiod.c /ram/pigs.c -.br -/ram/x_pigpiod_if.c /ram/pig2vcd.c /ram/pigpiod_if2.c -.br -/ram/x_pigpio.c /ram/x_repeat.c /ram/pigpio.c -.br -/ram/pigpiod_if.c /ram/x_pigpiod_if2.c -.br - -.br -# assumes /opt/pigpio/access contains the following line -.br -# /ram/*.c r -.br - -.br -$ pigs fo /ram/pigpio.c 1 -.br -0 -.br - -.br -$ pigs fo /ram/new.c 1 -.br --128 -.br -ERROR: file open failed -.br - -.br -$ pigs fo /ram/new.c 9 -.br -1 -.br - -.br -$ ls /ram/*.c -l -.br --rw-r--r-- 1 joan joan 42923 Jul 10 11:22 /ram/command.c -.br --rw------- 1 root root 0 Jul 10 16:54 /ram/new.c -.br --rw-r--r-- 1 joan joan 2971 Jul 10 11:22 /ram/pig2vcd.c -.br --rw------- 1 joan joan 296235 Jul 10 11:22 /ram/pigpio.c -.br --rw-r--r-- 1 joan joan 9266 Jul 10 11:22 /ram/pigpiod.c -.br --rw-r--r-- 1 joan joan 37331 Jul 10 11:22 /ram/pigpiod_if2.c -.br --rw-r--r-- 1 joan joan 33088 Jul 10 11:22 /ram/pigpiod_if.c -.br --rw-r--r-- 1 joan joan 7990 Jul 10 11:22 /ram/pigs.c -.br --rw-r--r-- 1 joan joan 19970 Jul 10 11:22 /ram/x_pigpio.c -.br --rw-r--r-- 1 joan joan 20804 Jul 10 11:22 /ram/x_pigpiod_if2.c -.br --rw-r--r-- 1 joan joan 19844 Jul 10 11:22 /ram/x_pigpiod_if.c -.br --rw-r--r-- 1 joan joan 19907 Jul 10 11:22 /ram/x_repeat.c -.br - -.EE - -.br - -.IP "\fBFR h num\fP - Read bytes from file handle" -.IP "" 4 -This command returns up to \fBnum\fP bytes of data read from the -file associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fr 0 10 -.br -5 48 49 128 144 255 -.br - -.br -$ pigs fr 0 10 -.br -0 -.br - -.EE - -.br - -.IP "\fBFS h num from\fP - Seek to file handle position" -.IP "" 4 -This command seeks to a position within the file associated -with handle \fBh\fP. - -.br -The number of bytes to move is \fBnum\fP. Positive offsets -move forward, negative offsets backwards. The move start -position is determined by \fBfrom\fP as follows. - -.br - -.EX - From -0 start -1 current position -2 end - -.EE - -.br -Upon success the new byte position within the file (>=0) is -returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fs 0 200 0 # Seek to start of file plus 200 -.br -200 -.br - -.br -$ pigs fs 0 0 1 # Return current position -.br -200 -.br - -.br -$ pigs fs 0 0 2 # Seek to end of file, return size -.br -296235 -.br - -.EE - -.br - -.IP "\fBFW h bvs\fP - Write bytes to file handle" -.IP "" 4 -This command writes bytes \fBbvs\fP to the file -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fw 0 23 45 67 89 -.br - -.EE - -.br - -.IP "\fBGDC u\fP - Get GPIO PWM dutycycle" -.IP "" 4 - -.br -This command returns the PWM dutycycle in use on GPIO \fBu\fP. - -.br -Upon success the dutycycle is returned. On error a negative -status code will be returned. - -.br -For normal PWM the dutycycle will be out of the defined range -for the GPIO (see \fBPRG\fP). - -.br -If a hardware clock is active on the GPIO the reported -dutycycle will be 500000 (500k) out of 1000000 (1M). - -.br -If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). - -.br - -\fBExample\fP -.br - -.EX -$ pigs p 4 129 -.br -$ pigs gdc 4 -.br -129 -.br - -.br -pigs gdc 5 -.br --92 -.br -ERROR: GPIO is not in use for PWM -.br - -.EE - -.br - -.IP "\fBGPW u\fP - Get GPIO servo pulsewidth" -.IP "" 4 - -.br -This command returns the servo pulsewidth in use on GPIO \fBu\fP. - -.br -Upon success the servo pulsewidth is returned. On error a negative -status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs s 4 1235 -.br -$ pigs gpw 4 -.br -1235 -.br - -.br -$ pigs gpw 9 -.br --93 -.br -ERROR: GPIO is not in use for servo pulses -.br - -.EE - -.br - -.IP "\fBH/HELP \fP - Display command help" -.IP "" 4 -This command displays a brief list of the commands and their parameters. - -.br - -\fBExample\fP -.br - -.EX -$ pigs h -.br - -.br -$ pigs help -.br - -.EE - -.br - -.IP "\fBHC g cf\fP - Set hardware clock frequency" -.IP "" 4 -This command sets the hardware clock associated with GPIO \fBg\fP to -frequency \fBcf\fP. Frequencies above 30MHz are unlikely to work. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs hc 4 5000 # start a 5 KHz clock on GPIO 4 (clock 0) -.br - -.br -$ pigs hc 5 5000000 # start a 5 MHz clcok on GPIO 5 (clock 1) -.br --99 -.br -ERROR: need password to use hardware clock 1 -.br - -.EE - -.br -The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. - -.br -The GPIO must be one of the following. - -.br - -.EX -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) - -.EE - -.br - -.EX -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) - -.EE - -.br -Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. - -.br - -.IP "\fBHP g pf pdc\fP - Set hardware PWM frequency and dutycycle" -.IP "" 4 -This command sets the hardware PWM associated with GPIO \fBg\fP to -frequency \fBpf\fP with dutycycle \fBpdc\fP. Frequencies above 30MHz -are unlikely to work. - -.br -NOTE: Any waveform started by \fBWVTX\fP, \fBWVTXR\fP, or \fBWVCHA\fP -will be cancelled. - -.br -This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -.EX -$ pigs hp 18 100 800000 # 80% dutycycle -.br - -.br -$ pigs hp 19 100 200000 # 20% dutycycle -.br - -.br -$ pigs hp 19 400000000 100000 -.br --96 -.br -ERROR: invalid hardware PWM frequency -.br - -.EE - -.br -The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. - -.br -The GPIO must be one of the following. - -.br - -.EX -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 - -.EE - -.br - -.EX -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 - -.EE - -.br -The actual number of steps beween off and fully on is the -integral part of 250M/\fBpf\fP (375M/\fBpf\fP for the BCM2711). - -.br -The actual frequency set is 250M/steps (375M/steps for the BCM2711). - -.br -There will only be a million steps for a \fBpf\fP of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. \fBpdc\fP is -automatically scaled to take this into account. - -.br - -.IP "\fBHWVER \fP - Get hardware version" -.IP "" 4 -This command returns the hardware revision of the Pi. - -.br -The hardware revision is found in the last 4 characters on the revision -line of /proc/cpuinfo. - -.br -If the hardware revision can not be found or is not a valid hexadecimal -number the command returns 0. - -.br -The revision number can be used to determine the assignment of GPIO -to pins (see \fBg\fP). - -.br -There are currently three types of board. - -.br -Type 1 boards have hardware revision numbers of 2 and 3. - -.br -Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. - -.br -Type 3 boards have hardware revision numbers of 16 or greater. - -.br -for "Revision : 0002" the command returns 2. - -.br -for "Revision : 000f" the command returns 15. - -.br -for "Revision : 000g" the command returns 0. - -.br - -\fBExample\fP -.br - -.EX -$ pigs hwver # On a B+ -.br -16 -.br - -.EE - -.br - -.IP "\fBI2CC h\fP - Close I2C handle" -.IP "" 4 -This command closes an I2C handle \fBh\fP previously opened with \fBI2CO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cc 0 # First close okay. -.br - -.br -$ pigs i2cc 0 # Second fails. -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBI2CO ib id if\fP - Open I2C bus and device with flags" -.IP "" 4 -This command returns a handle to access device \fBid\fP on I2C bus \fBib\fP. -The device is opened with flags \fBif\fP. - -.br -Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. - -.br -The GPIO used are given in the following table. - -.br - -.EX - SDA SCL -I2C 0 0 1 -I2C 1 2 3 - -.EE - -.br -No flags are currently defined. The parameter \fBif\fP should be 0. - -.br -Upon success the next free handle (>=0) is returned. On error a -negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2co 1 0x70 0 # Bus 1, device 0x70, flags 0. -.br -0 -.br - -.br -$ pigs i2co 1 0x53 0 # Bus 1, device 0x53, flags 0. -.br -1 -.br - -.EE - -.br - -.IP "\fBI2CPC h r wv\fP - smb Process Call: exchange register with word" -.IP "" 4 -This command writes \fBwv\fP to register \fBr\fP of the I2C device -associated with handle \fBh\fP and returns a 16-bit word read from the -device. - -.br -Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cpc 0 37 43210 -.br -39933 -.br - -.br -$ pigs i2cpc 0 256 43210 -.br -ERROR: bad i2c/spi/ser parameter -.br --81 -.br - -.EE - -.br - -.IP "\fBI2CPK h r bvs\fP - smb Block Process Call: exchange data bytes with register" -.IP "" 4 - -.br -This command writes the data bytes \fBbvs\fP to register \fBr\fP of the I2C device -associated with handle \fBh\fP and returns a device specific number of bytes. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cpk 0 0 0x11 0x12 -.br -6 0 0 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBI2CRB h r\fP - smb Read Byte Data: read byte from register" -.IP "" 4 - -.br -This command returns a single byte read from register \fBr\fP of the I2C device -associated with handle \fBh\fP. - -.br -Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crb 0 0 -.br -6 -.br - -.EE - -.br - -.IP "\fBI2CRD h num\fP - i2c Read device" -.IP "" 4 - -.br -This command returns \fBnum\fP bytes read from the I2C device associated with -handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br -This command operates on the raw I2C device. The maximum value of the -parameter \fBnum\fP is dependent on the I2C drivers and the device -itself. pigs imposes a limit of about 8000 bytes. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crd 0 16 -.br -16 6 24 0 0 0 0 0 0 0 0 0 0 0 0 32 78 -.br - -.EE - -.br - -.IP "\fBI2CRI h r num\fP - smb Read I2C Block Data: read bytes from register" -.IP "" 4 - -.br -This command returns \fBnum\fP bytes from register \fBr\fP of the I2C device -associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br -The parameter \fBnum\fP may be 1-32. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cri 0 0 16 -.br -16 237 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 -.br - -.EE - -.br - -.IP "\fBI2CRK h r\fP - smb Read Block Data: read data from register" -.IP "" 4 - -.br -This command returns between 1 and 32 bytes read from register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br -The number of bytes of returned data is specific to the device and -register. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crk 0 0 -.br -6 0 0 0 0 0 0 -.br - -.br -$ pigs i2crk 0 1 -.br -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 -.br - -.EE - -.br - -.IP "\fBI2CRS h\fP - smb Read Byte: read byte" -.IP "" 4 - -.br -This command returns a single byte read from the I2C device -associated with handle \fBh\fP. - -.br -Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crs 0 -.br -0 -.br - -.EE - -.br - -.IP "\fBI2CRW h r\fP - smb Read Word Data: read word from register" -.IP "" 4 - -.br -This command returns a single 16 bit word read from register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crw 0 0 -.br -6150 -.br - -.EE - -.br - -.IP "\fBI2CWB h r bv\fP - smb Write Byte Data: write byte to register" -.IP "" 4 - -.br -This command writes a single byte \fBbv\fP to register \fBr\fP of the -I2C device associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cwb 0 10 0x54 -.br - -.EE - -.br - -.IP "\fBI2CWD h bvs\fP - i2c Write device" -.IP "" 4 - -.br -This command writes a block of bytes \fBbvs\fP to the I2C device -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The number of bytes which may be written in one transaction is -dependent on the I2C drivers and the device itself. pigs imposes -a limit of about 500 bytes. - -.br -This command operates on the raw I2C device. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cwd 0 0x01 0x02 0x03 0x04 -.br - -.EE - -.br - -.IP "\fBI2CWI h r bvs\fP - smb Write I2C Block Data" -.IP "" 4 - -.br -This command writes between 1 and 32 bytes \fBbvs\fP to register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cwi 0 4 0x01 0x04 0xc0 -.br - -.EE - -.br - -.IP "\fBI2CWK h r bvs\fP - smb Write Block Data: write data to register" -.IP "" 4 - -.br -This command writes between 1 and 32 bytes \fBbvs\fP to register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -pigs i2cwk 0 4 0x01 0x04 0xc0 -.br - -.EE - -.br - -.IP "\fBI2CWQ h bit\fP - smb Write Quick: write bit" -.IP "" 4 - -.br -This command writes a single \fBbit\fP to the I2C device associated -with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cwq 0 1 -.br - -.EE - -.br - -.IP "\fBI2CWS h bv\fP - smb Write Byte: write byte" -.IP "" 4 - -.br -This command writes a single byte \fBbv\fP to the I2C device associated -with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cws 0 0x12 -.br - -.br -$ pigs i2cws 0 0xff -.br --82 -.br -ERROR: I2C write failed -.br - -.EE - -.br - -.IP "\fBI2CWW h r wv\fP - smb Write Word Data: write word to register" -.IP "" 4 - -.br -This command writes a single 16 bit word \fBwv\fP to register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cww 0 0 0xffff -.br - -.EE - -.br - -.IP "\fBI2CZ h bvs\fP - Performs multiple I2C transactions" -.IP "" 4 -This command executes a sequence of I2C operations. The -operations to be performed are specified by the contents of \fBbvs\fP -which contains the concatenated command codes and associated data. - -.br -The following command codes are supported: - -.br - -.EX -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 - -.EE - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br -The address defaults to that associated with the handle \fBh\fP. -The flags default to 0. The address and flags maintain their -previous value until updated. - -.br - -\fBExample\fP -.br - -.EX -Set address 0x53, write 0x32, read 6 bytes -.br -Set address 0x1E, write 0x03, read 6 bytes -.br -Set address 0x68, write 0x1B, read 8 bytes -.br -End -.br - -.br -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -.br -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -.br -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -.br -0x00 -.br - -.EE - -.br - -.br - -.IP "\fBM/MODES g m\fP - Set GPIO mode" -.IP "" 4 - -.br -This command sets GPIO \fBg\fP to mode \fBm\fP, typically input (read) -or output (write). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -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. - -.br -To set the mode use the code for the mode. - -.br - -.EX -Mode Input Output ALT0 ALT1 ALT2 ALT3 ALT4 ALT5 -Code R W 0 1 2 3 4 5 - -.EE - -.br - -\fBExample\fP -.br - -.EX -$ pigs m 4 r # Input (read) -.br -$ pigs m 4 w # Output (write) -.br -$ pigs m 4 0 # ALT 0 -.br -$ pigs m 4 5 # ALT 5 -.br - -.EE - -.br - -.IP "\fBMG/MODEG g\fP - Get GPIO mode" -.IP "" 4 - -.br -This command returns the current mode of GPIO \fBg\fP. - -.br -Upon success the value of the GPIO mode is returned. -On error a negative status code will be returned. - -.br - -.EX -Value 0 1 2 3 4 5 6 7 -Mode Input Output ALT5 ALT4 ALT0 ALT1 ALT2 ALT3 - -.EE - -.br - -\fBExample\fP -.br - -.EX -$ pigs mg 4 -.br -1 -.br - -.EE - -.br - -.IP "\fBMICS v\fP - Microseconds delay" -.IP "" 4 -This command delays execution for \fBv\fP microseconds. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The main use of this command is expected to be within \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs mics 20 # Delay 20 microseconds. -.br -$ pigs mics 1000000 # Delay 1 second. -.br - -.br -$ pigs mics 2000000 -.br --64 -.br -ERROR: bad MICS delay (too large) -.br - -.EE - -.br - -.IP "\fBMILS v\fP - Milliseconds delay" -.IP "" 4 - -.br -This command delays execution for \fBv\fP milliseconds. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs mils 2000 # Delay 2 seconds. -.br - -.br -$ pigs mils 61000 -.br --65 -.br -ERROR: bad MILS delay (too large) -.br - -.EE - -.br - -.IP "\fBNB h bits\fP - Start notification" -.IP "" 4 - -.br -This command starts notifications on handle \fBh\fP returned by -a prior call to \fBNO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The notification gets state changes for each GPIO specified by \fBbits\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs nb 0 -1 # Shorthand for GPIO 0-31. -.br -$ pigs nb 0 0xf0 # Get notifications for GPIO 4-7. -.br - -.br -$ pigs nb 1 0xf -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBNC h\fP - Close notification" -.IP "" 4 - -.br -This command stops notifications on handle \fBh\fP returned by -a prior call to \fBNO\fP and releases the handle for reuse. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs nc 0 # First call succeeds. -.br - -.br -$ pigs nc 1 # Second call fails. -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBNO \fP - Request a notification" -.IP "" 4 - -.br -This command requests a free notification handle. - -.br -A notification is a method for being notified of GPIO state changes via a pipe. - -.br -Upon success the command returns a handle greater than or equal to zero. -On error a negative status code will be returned. - -.br -Notifications for handle x will be available at the pipe named /dev/pigpiox -(where x is the handle number). - -.br -E.g. if the command returns 15 then the notifications must be read -from /dev/pigpio15. - -.br - -\fBExample\fP -.br - -.EX -$ pigs no -.br -0 -.br - -.EE - -.br - -.IP "\fBNP h\fP - Pause notification" -.IP "" 4 - -.br -This command pauses notifications on handle \fBh\fP returned by -a prior call to \fBNO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -Notifications for the handle are suspended until a new \fBNB\fP command -is given for the handle. - -.br - -\fBExample\fP -.br - -.EX -$ pigs np 0 -.br - -.EE - -.br - -.IP "\fBP/PWM u v\fP - Set GPIO PWM value" -.IP "" 4 - -.br -This command starts PWM on GPIO \fBu\fP with dutycycle \fBv\fP. The dutycycle -varies from 0 (off) to range (fully on). The range defaults to 255. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -This and the servo functionality use the DMA and PWM or PCM peripherals -to control and schedule the pulsewidths and dutycycles. - -.br -The \fBPRS\fP command may be used to change the default range of 255. - -.br - -\fBExample\fP -.br - -.EX -$ pigs p 4 64 # Start PWM on GPIO 4 with 25% dutycycle -.br -$ pigs p 4 128 # 50% -.br -$ pigs p 4 192 # 75% -.br -$ pigs p 4 255 # 100% -.br - -.EE - -.br - -.IP "\fBPADG pad\fP - Get pad drive strength" -.IP "" 4 - -.br -This command gets the \fBpad\fP drive strength \fBpadma\fP in mA. - -.br -Returns the pad drive strength if OK. On error a negative status code -will be returned. - -.br - -.EX -Pad GPIO -0 0-27 -1 28-45 -2 46-53 - -.EE - -.br - -\fBExample\fP -.br - -.EX -$ pigs padg 0 -.br -8 -.br -$ pigs pads 0 16 -.br -$ pigs padg 0 -.br -16 -.br -pigs padg 3 -.br --126 -.br -ERROR: bad pad number -.br - -.EE - -.br - -.IP "\fBPADS pad padma\fP - Set pad drive strength" -.IP "" 4 - -.br -This command sets the \fBpad\fP drive strength \fBpadma\fP in mA. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -.EX -Pad GPIO -0 0-27 -1 28-45 -2 46-53 - -.EE - -.br - -\fBExample\fP -.br - -.EX -$ pigs pads 0 16 -.br -$ pigs padg 0 -.br -16 -.br -$ pigs pads 0 17 -.br --127 -.br -ERROR: bad pad drive strength -.br - -.EE - -.br - -.IP "\fBPARSE t\fP - Validate script" -.IP "" 4 - -.br -Validates the text \fBt\fP of a script without storing the script. - -.br -Upon success nothing is returned. On error a list of detected -script errors will be given. - -.br -See \fBScripts\fP. - -.br -This command may be used to find script syntax faults. - -.br - -\fBExample\fP -.br - -.EX -$ pigs parse tag 100 w 22 1 mils 200 w 22 0 mils 800 jmp 100 -.br - -.br -$ pigs parse tag 0 w 22 1 mills 50 w 22 0 dcr p10 jp 99 -.br -Unknown command: mills -.br -Unknown command: 50 -.br -Bad parameter to dcr -.br -Can't resolve tag 99 -.br - -.EE - -.br - -.IP "\fBPFG u\fP - Get GPIO PWM frequency" -.IP "" 4 - -.br -This command returns the PWM frequency in Hz used for GPIO \fBu\fP. - -.br -Upon success the PWM frequency is returned. On error a negative -status code will be returned. - -.br -For normal PWM the frequency will be that defined for the GPIO -by \fBPFS\fP. - -.br -If a hardware clock is active on the GPIO the reported frequency -will be that set by \fBHC\fP. - -.br -If hardware PWM is active on the GPIO the reported frequency -will be that set by \fBHP\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs pfg 4 -.br -800 -.br - -.br -$ pigs pfg 34 -.br -ERROR: GPIO not 0-31 -.br --2 -.br - -.EE - -.br - -.IP "\fBPFS u v\fP - Set GPIO PWM frequency" -.IP "" 4 -This command sets the PWM frequency \fBv\fP to be used for GPIO \fBu\fP. - -.br -The numerically closest frequency to \fBv\fP will be selected. - -.br -Upon success the new frequency is returned. On error a negative status code -will be returned. - -.br -If PWM is currently active on the GPIO it will be -switched off and then back on at the new frequency. - -.br -Each GPIO can be independently set to one of 18 different PWM -frequencies. - -.br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. - -.br -The frequencies for each sample rate are: - -.br - -.EX - Hertz -.br - -.br - 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 -.br - 1250 1000 800 500 400 250 200 100 50 -.br - -.br - 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 -.br - 625 500 400 250 200 125 100 50 25 -.br - -.br - 4: 10000 5000 2500 2000 1250 1000 625 500 400 -.br - 313 250 200 125 100 63 50 25 13 -.br -sample -.br - rate -.br - (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 -.br - 250 200 160 100 80 50 40 20 10 -.br - -.br - 8: 5000 2500 1250 1000 625 500 313 250 200 -.br - 156 125 100 63 50 31 25 13 6 -.br - -.br - 10: 4000 2000 1000 800 500 400 250 200 160 -.br - 125 100 80 50 40 25 20 10 5 -.br - -.EE - -.br - -\fBExample\fP -.br - -.EX -pigs pfs 4 0 # 0 selects the lowest frequency. -.br -10 -.br - -.br -$ pigs pfs 4 1000 # Set 1000Hz PWM. -.br -1000 -.br - -.br -$ pigs pfs 4 100000 # Very big number selects the highest frequency. -.br -8000 -.br - -.EE - -.br - -.IP "\fBPIGPV \fP - Get pigpio library version" -.IP "" 4 - -.br -This command returns the pigpio library version. - -.br - -\fBExample\fP -.br - -.EX -$ pigs pigpv -.br -17 -.br - -.EE - -.br - -.IP "\fBPRG u\fP - Get GPIO PWM range" -.IP "" 4 - -.br -This command returns the dutycycle range for GPIO \fBu\fP. - -.br -Upon success the range is returned. On error a negative status code -will be returned. - -.br -If a hardware clock or hardware PWM is active on the GPIO the reported -range will be 1000000 (1M). - -.br - -\fBExample\fP -.br - -.EX -$ pigs prg 4 -.br -255 -.br - -.EE - -.br - -.IP "\fBPROC t\fP - Store script" -.IP "" 4 - -.br -This command stores a script \fBt\fP for later execution. - -.br -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. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123 -.br -0 -.br - -.br -$ pigs proc tag 123 w 4 0 mils 5 w 4 1 mils 5 jmp 12 -.br -ERROR: script has unresolved tag -.br --63 -.br - -.EE - -.br - -.IP "\fBPROCD sid\fP - Delete script" -.IP "" 4 - -.br -This command deletes script \fBsid\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs procd 1 -.br - -.br -$ pigs procd 1 -.br -ERROR: unknown script id -.br --48 -.br - -.EE - -.br - -.IP "\fBPROCP sid\fP - Get script status and parameters" -.IP "" 4 - -.br -This command returns the status of script \fBsid\fP as well as the -current value of its 10 parameters. - -.br -Upon success the script status and parameters are returned. -On error a negative status code will be returned. - -.br -The script status may be one of - -.br - -.EX -0 being initialised -1 halted -2 running -3 waiting -4 failed - -.EE - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs procp 0 -.br -1 0 0 0 0 0 0 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBPROCR sid pars\fP - Run script" -.IP "" 4 - -.br -This command runs stored script \fBsid\fP passing it up to 10 optional -parameters. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123 -.br -0 -.br - -.br -$ pigs procr 0 50 # Run script 0 with parameter 0 of 50. -.br - -.br -$ pigs procp 0 -.br -2 44 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -2 37 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -2 10 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -2 5 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -2 2 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -1 -1 0 0 0 0 0 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBPROCS sid\fP - Stop script" -.IP "" 4 - -.br -This command stops a running script \fBsid\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs procs 0 -.br - -.br -$ pigs procs 1 -.br --48 -.br -ERROR: unknown script id -.br - -.EE - -.br - -.IP "\fBPROCU sid pars\fP - Set script parameters" -.IP "" 4 - -.br -This command sets the parameters of a stored script \fBsid\fP passing -it up to 10 parameters. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs proc tag 0 hp 18 p0 p1 mils 1000 jmp 0 -.br -0 -.br -$ pigs procu 0 50 500000 -.br -$ pigs procr 0 -.br -$ pigs procu 0 100 -.br -$ pigs procu 0 200 -.br -$ pigs procu 0 200 100000 -.br - -.EE - -.br - -.IP "\fBPRRG u\fP - Get GPIO PWM real range" -.IP "" 4 - -.br -This command returns the real underlying range used by GPIO \fBu\fP. - -.br -If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). - -.br -If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. - -.br -On error a negative status code will be returned. - -.br -See \fBPRS\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs prrg 17 -.br -250 -.br - -.br -$ pigs pfs 17 0 -.br -10 -.br -$ pigs prrg 17 -.br -20000 -.br - -.br -$ pigs pfs 17 100000 -.br -8000 -.br -$ pigs prrg 17 -.br -25 -.br - -.EE - -.br - -.IP "\fBPRS u v\fP - Set GPIO PWM range" -.IP "" 4 - -.br -This command sets the dutycycle range \fBv\fP to be used for GPIO \fBu\fP. -Subsequent uses of command \fBP/PWM\fP will use a dutycycle between 0 (off) -and \fBv\fP (fully on). - -.br -Upon success the real underlying range used by the GPIO is returned. -On error a negative status code will be returned. - -.br -If PWM is currently active on the GPIO its dutycycle will be scaled to -reflect the new range. - -.br -The real range, the number of steps between fully off and fully on -for each frequency, is given in the following table. - -.br - -.EX - #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 - -.EE - -.br -The real value set by \fBPRS\fP is (dutycycle * real range) / range. - -.br -See \fBPRRG\fP - -.br - -\fBExample\fP -.br - -.EX -$ pigs prs 18 1000 -.br -250 -.br - -.EE - -.br - -.IP "\fBPUD g p\fP - Set GPIO pull up/down" -.IP "" 4 - -.br -This command sets the internal pull/up down for GPIO \fBg\fP to mode \fBp\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The mode may be pull-down (D), pull-up (U), or off (O). - -.br - -\fBExample\fP -.br - -.EX -$ pigs pud 4 d # Set pull-down on GPIO 4. -.br -$ pigs pud 4 u # Set pull-up on GPIO 4. -.br -$ pigs pud 4 o # No pull-up/down on GPIO 4. -.br - -.EE - -.br - -.IP "\fBR/READ g\fP - Read GPIO level" -.IP "" 4 - -.br -This reads the current level of GPIO \fBg\fP. - -.br -Upon success the current level is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs r 17 # Get level of GPIO 17. -.br -0 -.br - -.br -$ pigs r 4 # Get level of GPIO 4. -.br -1 -.br - -.EE - -.br - -.IP "\fBS/SERVO u v\fP - Set GPIO servo pulsewidth" -.IP "" 4 - -.br -This command starts servo pulses of \fBv\fP microseconds on GPIO \fBu\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The servo pulsewidth may be 0 (off), 500 (most anti-clockwise) -to 2500 (most clockwise). - -.br -The range supported by servos varies and should probably be determined -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. - -.br -You can DAMAGE a servo if you command it to move beyond its limits. - -.br - -\fBExample\fP -.br - -.EX -$ pigs SERVO 17 1500 -.br - -.EE - -.br -This example causes an on pulse of 1500 microseconds duration to be -transmitted on GPIO 17 at a rate of 50 times per second. - -.br -This will command a servo connected to GPIO 17 to rotate to its mid-point. - -.br - -\fBExample\fP -.br - -.EX -pigs s 17 0 # Switch servo pulses off. -.br - -.EE - -.br - -.IP "\fBSERC h\fP - Close serial handle" -.IP "" 4 - -.br -This command closes a serial handle \fBh\fP previously opened with \fBSERO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serc 0 # First close okay. -.br - -.br -$ pigs serc 0 # Second close gives error. -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBSERDA h\fP - Check for serial data ready to read" -.IP "" 4 - -.br -This command returns the number of bytes of data available -to be read from the serial device associated with handle \fBh\fP. - -.br -Upon success the count of bytes available to be read is -returned (which may be 0). On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serda 0 -.br -0 -.br - -.EE - -.br - -.IP "\fBSERO dev b sef\fP - Open serial device dev at baud b with flags" -.IP "" 4 - -.br -This command opens the serial \fBdev\fP at \fBb\fP bits per second. - -.br -No flags are currently defined. \fBsef\fP should be set to zero. - -.br -Upon success a handle (>=0) is returned. On error a negative status code -will be returned. - -.br -The device name must start with /dev/tty or /dev/serial. - -.br - -.br -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -.br - -\fBExample\fP -.br - -.EX -$ pigs sero /dev/ttyAMA0 9600 0 -.br -0 -.br - -.br -$ pigs sero /dev/tty1 38400 0 -.br -1 -.br - -.EE - -.br - -.IP "\fBSERR h num\fP - Read bytes from serial handle" -.IP "" 4 - -.br -This command returns up to \fBnum\fP bytes of data read from the -serial device associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serr 0 10 -.br -5 48 49 128 144 255 -.br - -.br -$ pigs serr 0 10 -.br -0 -.br - -.EE - -.br - -.IP "\fBSERRB \fP - Read byte from serial handle" -.IP "" 4 - -.br -This command returns a byte of data read from the serial -device associated with handle \fBh\fP. - -.br -Upon success a number between 0 and 255 is returned. -On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serrb 0 -.br -23 -.br -$ pigs serrb 0 -.br -45 -.br - -.EE - -.br - -.IP "\fBSERW h bvs\fP - Write bytes to serial handle" -.IP "" 4 - -.br -This command writes bytes \fBbvs\fP to the serial device -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serw 0 23 45 67 89 -.br - -.EE - -.br - -.IP "\fBSERWB h bv\fP - Write byte to serial handle" -.IP "" 4 - -.br -This command writes a single byte \fBbv\fP to the serial device -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serwb 0 23 -.br -$ pigs serwb 0 0xf0 -.br - -.EE - -.br - -.IP "\fBSHELL name str\fP - Execute a shell command" -.IP "" 4 - -.br -This command uses the system call to execute a shell script \fBname\fP -with the given string \fBstr\fP as its parameter. - -.br -The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. - -.br -\fBname\fP must exist in /opt/pigpio/cgi and must be executable. - -.br -The returned exit status is normally 256 times that set -by the shell script exit function. If the script can't -be found 32512 will be returned. - -.br -The following table gives some example returned statuses. - -.br - -.EX -Script exit status Returned system call status -1 256 -5 1280 -10 2560 -200 51200 -script not found 32512 - -.EE - -.br - -\fBExample\fP -.br - -.EX -# pass two parameters, hello and world -.br -$ pigs shell scr1 hello world -.br -256 -.br - -.br -# pass three parameters, hello, string with spaces, and world -.br -$ pigs shell scr1 "hello 'string with spaces' world" -.br -256 -.br - -.br -# pass one parameter, hello string with spaces world -.br -$ pigs shell scr1 "\"hello string with spaces world\"" -.br -256 -.br - -.br -# non-existent script -.br -$ pigs shell scr78 par1 -.br -32512 -.br - -.EE - -.br - -.IP "\fBSLR u num\fP - Read bit bang serial data from GPIO" -.IP "" 4 - -.br -This command returns up to \fBnum\fP bytes of bit bang serial data -read from GPIO \fBu\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br -The GPIO \fBu\fP should have been initialised with the \fBSLRO\fP command. - -.br -The bytes returned for each character depend upon the number of -data bits \fBdb\fP specified in the \fBSLRO\fP command. - -.br -For \fBdb\fP 1-8 there will be one byte per character. -.br -For \fBdb\fP 9-16 there will be two bytes per character. -.br -For \fBdb\fP 17-32 there will be four bytes per character. - -.br - -\fBExample\fP -.br - -.EX -$ pigs slr 15 20 -.br -6 1 0 23 45 89 0 -.br - -.EE - -.br - -.IP "\fBSLRC u\fP - Close GPIO for bit bang serial data" -.IP "" 4 - -.br -This command closes GPIO \fBu\fP for reading bit bang serial data. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs slrc 23 -.br - -.br -$ pigs slrc 23 -.br --38 -.br -ERROR: no serial read in progress on GPIO -.br - -.EE - -.br - -.IP "\fBSLRI u v\fP - Sets bit bang serial data logic levels" -.IP "" 4 - -.br -This command sets the logic level for reading bit bang serial data -on GPIO \fBu\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The invert parameter \fBv\fP is 1 for inverted signal, 0 for normal. - -.br - -\fBExample\fP -.br - -.EX -$ pigs slri 17 1 # invert logic on GPIO 17 -.br - -.br -$ pigs slri 23 0 # use normal logic on GPIO 23 -.br - -.EE - -.br - -.IP "\fBSLRO u b db\fP - Open GPIO for bit bang serial data" -.IP "" 4 - -.br -This command opens GPIO \fBu\fP for reading bit bang serial data -at \fBb\fP baud and \fBdb\fP data bits. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The baud rate may be between 50 and 250000 bits per second. - -.br -The received data is held in a cyclic buffer. - -.br -It is the user's responsibility to read the data (with \fBSLR\fP) -in a timely fashion. - -.br - -\fBExample\fP -.br - -.EX -$ pigs slro 23 19200 8 -.br - -.br -$ pigs slro 23 19200 8 -.br --50 -.br -ERROR: GPIO already in use -.br - -.EE - -.br - -.IP "\fBSPIC h\fP - SPI close handle" -.IP "" 4 - -.br -This command closes the SPI handle \fBh\fP returned by a prior -call to \fBSPIO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spic 1 -.br - -.br -$ pigs spic 1 -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBSPIO c b spf\fP - SPI open channel at baud b with flags" -.IP "" 4 - -.br -This command returns a handle to a SPI device on channel \fBc\fP. - -.br -Data will be transferred at \fBb\fP bits per second. The flags \fBspf\fP -may be used to modify the default behaviour of 4-wire operation, -mode 0, active low chip select. - -.br -Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps -are unlikely to work. - -.br -The Pi has two SPI peripherals: main and auxiliary. - -.br -The main SPI has two chip selects (channels), the auxiliary has -three. - -.br -The auxiliary SPI is available on all models but the A and B. - -.br -The GPIO used are given in the following table. - -.br - -.EX - MISO MOSI SCLK CE0 CE1 CE2 -Main SPI 9 10 11 8 7 - -Aux SPI 19 20 21 18 17 16 - -.EE - -.br -The flags consists of the least significant 22 bits. - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -.br - -.EE - -.br -mm defines the SPI mode. - -.br -Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br -px is 0 if CEx is active low (default) and 1 for active high. - -.br -ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. - -.br -A is 0 for the main SPI, 1 for the auxiliary SPI. - -.br -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main -SPI only. - -.br -nnnn defines the number of bytes (0-15) to write before switching -the MOSI line to MISO to read data. This field is ignored -if W is not set. Main SPI only. - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. Auxiliary SPI -only. - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. Auxiliary SPI -only. - -.br -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI only. - -.br -The \fBSPIR\fP, \fBSPIW\fP, and \fBSPIX\fP commands transfer data -packed into 1, 2, or 4 bytes according to the word size in bits. - -.br -For bits 1-8 there will be one byte per character. -.br -For bits 9-16 there will be two bytes per character. -.br -For bits 17-32 there will be four bytes per character. - -.br -Multi-byte transfers are made in least significant byte first order. - -.br -E.g. to transfer 32 11-bit words 64 bytes need to be sent. - -.br -E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed -by 0x1A. - -.br -The other bits in flags should be set to zero. - -.br -Upon success a handle (>=0) is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spio 0 100000 3 # Open channel 0 at 100kbps in mode 3. -.br -0 -.br - -.br -$ pigs spio 0 32000 256 # Open channel 0 of auxiliary spi at 32kbps. -.br -1 -.br - -.EE - -.br - -.IP "\fBSPIR h num\fP - SPI read bytes from handle" -.IP "" 4 - -.br -This command returns \fBnum\fP bytes read from the SPI device -associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spir 0 10 # Read 10 bytes from the SPI device. -.br -10 0 0 0 0 0 0 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBSPIW h bvs\fP - SPI write bytes to handle" -.IP "" 4 - -.br -This command writes bytes \fBbvs\fP to the SPI device -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spiw 0 0x22 0x33 0xcc 0xff -.br - -.EE - -.br - -.IP "\fBSPIX h bvs\fP - SPI transfer bytes to handle" -.IP "" 4 - -.br -This command writes bytes \fBbvs\fP to the SPI device -associated with handle \fBh\fP. It returns the same -number of bytes read from the device. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spix 0 0x22 0x33 0xcc 0xff -.br -4 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBT/TICK \fP - Get current tick" -.IP "" 4 - -.br -This command returns the current system tick. - -.br -Tick is the number of microseconds since system boot. - -.br -As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, -which is approximately 1 hour 12 minutes. - -.br - -\fBExample\fP -.br - -.EX -$ pigs t mils 1000 t -.br -3691823946 -.br -3692833987 -.br - -.EE - -.br - -.IP "\fBTRIG u pl L\fP - Send a trigger pulse" -.IP "" 4 - -.br -This command sends a trigger pulse of \fBpl\fP microseconds at level \fBL\fP -to GPIO \fBu\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The GPIO is set to not level at the end of the pulse. - -.br - -\fBExample\fP -.br - -.EX -$ pigs trig 4 10 1 -.br - -.br -$ pigs trig 4 51 1 -.br --46 -.br -ERROR: trigger pulse > 50 microseconds -.br - -.EE - -.br - -.IP "\fBW/WRITE g L\fP - Write GPIO level" -.IP "" 4 - -.br -This command sets GPIO \fBg\fP to level \fBL\fP. The level may be 0 -(low, off, clear) or 1 (high, on, set). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs w 23 0 -.br -$ pigs w 23 1 -.br - -.br -$ pigs w 23 2 -.br --5 -.br -ERROR: level not 0-1 -.br - -.EE - -.br - -.IP "\fBWDOG u v\fP - Set GPIO watchdog" -.IP "" 4 - -.br -This command sets a watchdog of \fBv\fP milliseconds on GPIO \fBu\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The watchdog is nominally in milliseconds. - -.br -One watchdog may be registered per GPIO. - -.br -The watchdog may be cancelled by setting timeout to 0. - -.br -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. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wdog 23 90000 -.br --15 -.br -ERROR: timeout not 0-60000 -.br - -.br -$ pigs wdog 23 9000 -.br - -.EE - -.br -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. - -.br - -.IP "\fBWVAG trips\fP - Add generic pulses to waveform" -.IP "" 4 - -.br -This command adds 1 one or more triplets \fBtrips\fP of GPIO on, GPIO off, -delay to the existing waveform (if any). - -.br -Upon success the total number of pulses in the waveform so far is -returned. On error a negative status code will be returned. - -.br -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. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvag 0x10 0x80 1000 0x80 0x10 9000 -.br -2 -.br - -.br -$ pigs wvag 0 0 10000 0x10 0x80 1000 0x80 0x10 9000 -.br -4 -.br - -.EE - -.br - -.IP "\fBWVAS u b db sb o bvs\fP - Add serial data to waveform" -.IP "" 4 - -.br -This command adds a waveform representing serial data \fBbvs\fP to -GPIO \fBu\fP at \fBb\fP baud to the existing waveform (if any). -The serial data starts \fBo\fP microseconds from the start of the -waveform. - -.br -Upon success the total number of pulses in the waveform so far is -returned. On error a negative status code will be returned. - -.br -The serial data is formatted as one start bit, \fBdb\fP data bits, and -\fBsb\fP/2 stop bits. - -.br -The baud rate may be between 50 and 1000000 bits per second. - -.br -It is legal to add serial data streams with different baud rates to -the same waveform. - -.br -The bytes required for each character depend upon \fBdb\fP. - -.br -For \fBdb\fP 1-8 there will be one byte per character. -.br -For \fBdb\fP 9-16 there will be two bytes per character. -.br -For \fBdb\fP 17-32 there will be four bytes per character. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvas 4 9600 8 2 0 0x30 0x31 0x32 0x33 -.br -23 -.br - -.br -$ pigs wvas 7 38400 8 2 0 0x41 0x42 -.br -35 -.br - -.EE - -.br - -.IP "\fBWVTAT \fP - Returns the current transmitting waveform" -.IP "" 4 - -.br -This command returns the id of the waveform currently -being transmitted. - -.br -Returns the waveform id or one of the following special -values: - -.br -9998 - transmitted wave not found -.br -9999 - no wave being transmitted - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvtat -.br -9999 -.br - -.EE - -.br - -.IP "\fBWVBSY \fP - Check if waveform is being transmitted" -.IP "" 4 - -.br -This command checks to see if a waveform is currently being transmitted. - -.br -Returns 1 if a waveform is currently being transmitted, otherwise 0. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvbsy -.br -0 -.br - -.EE - -.br - -.IP "\fBWVCHA bvs\fP - Transmits a chain of waveforms" -.IP "" 4 - -.br -This command transmits a chain of waveforms. - -.br -NOTE: Any hardware PWM started by \fBHP\fP will -be cancelled. - -.br -The waves to be transmitted are specified by the contents of -\fBbvs\fP which contains an ordered list of wave_ids and optional -command codes and related data. - -.br -Upon success 0 is returned. On error a negative status code -will be returned. - -.br -Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. - -.br -A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. - -.br -Delays between waves may be added with the delay command. - -.br -The following command codes are supported: - -.br - -.EX -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 - -.EE - -.br -If present Loop Forever must be the last entry in the chain. - -.br -The code is currently dimensioned to support a chain with roughly -600 entries and 20 loop counters. - -.br - -\fBExample\fP -.br - -.EX -#!/bin/bash -.br - -.br -GPIO=4 -.br -WAVES=5 -.br - -.br -pigs m $GPIO w -.br - -.br -for ((i=0; i<$WAVES; i++)) -.br -do -.br - pigs wvag $((1<=0) is returned. On error a negative status -code will be returned. - -.br -The data provided by the \fBWVAG\fP and \fBWVAS\fP commands is -consumed by this command. - -.br -As many waveforms may be created as there is space available. -The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the -waveform to transmit. - -.br -Normal usage would be - -.br -Step 1. \fBWVCLR\fP to clear all waveforms and added data. - -.br -Step 2. \fBWVAG\fP/\fBWVAS\fP calls to supply the waveform data. - -.br -Step 3. \fBWVCRE\fP to create the waveform and get a unique id. - -.br -Repeat steps 2 and 3 as needed. - -.br -Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit. - -.br -A waveform comprises of one or more pulses. - -.br -A pulse specifies - -.br -1) the GPIO to be switched on at the start of the pulse. -.br -2) the GPIO to be switched off at the start of the pulse. -.br -3) the delay in microseconds before the next pulse. - -.br -Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). - -.br -When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvas 4 9600 0 23 45 67 89 90 -.br -37 -.br -$ pigs wvcre -.br -0 -.br - -.br -$ pigs wvcre -.br --69 -.br -ERROR: attempt to create an empty waveform -.br - -.EE - -.br - -.IP "\fBWVCAP \fP - Create a waveform of fixed size" -.IP "" 4 - -.br -Similar to \fBWVCRE\fP, this command creates a waveform but pads the consumed -resources to a fixed size, specified as a percent of total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. - -.br -Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. - -.br -The data provided by the \fBWVAG\fP and \fBWVAS\fP commands are -consumed by this command. - -.br -As many waveforms may be created as there is space available. -The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the -waveform to transmit. - -.br -Normal usage would be - -.br -Step 1. \fBWVCLR\fP to clear all waveforms and added data. - -.br -Step 2. \fBWVAG\fP/\fBWVAS\fP calls to supply the waveform data. - -.br -Step 3. \fBWVCAP\fP to create a waveform of a uniform size. - -.br -Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit. - -.br -Repeat steps 2 - 4 as needed. - -.br -Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. - -.br - -\fBExample\fP -.br - -.EX -# Create a wave that consumes 50% of the total resource: -.br - -.br -$ pigs wvag 16 0 5000000 0 16 5000000 -.br -2 -.br -$ pigs wvcap 50 -.br -0 -.br -$ pigs wvtx 0 -.br -11918 -.br - -.EE - -.br - -.IP "\fBWVDEL wid\fP - Delete selected waveform" -.IP "" 4 - -.br -This command deletes the waveform with id \fBwid\fP. - -.br -The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. - -.br -- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. - -.br -- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvdel 0 -.br - -.br -$ pigs wvdel 0 -.br --66 -.br -ERROR: non existent wave id -.br - -.EE - -.br - -.IP "\fBWVHLT \fP - Stop waveform" -.IP "" 4 - -.br -This command aborts the transmission of the current waveform. - -.br -Nothing is returned. - -.br -This command is intended to stop a waveform started in the repeat mode. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvhlt -.br - -.EE - -.br - -.IP "\fBWVNEW \fP - Initialise a new waveform" -.IP "" 4 - -.br -This clears any existing waveform data ready for the creation of a new -waveform. - -.br -Nothing is returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvnew -.br - -.EE - -.br - -.IP "\fBWVSC ws\fP - Get waveform DMA CB stats" -.IP "" 4 - -.br -The statistic requested by \fBws\fP is returned. - -.br -\fBws\fP identifies the subcommand as follows. - -.br -0 Get Cbs -.br -1 Get High Cbs -.br -2 Get Max Cbs - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvas 4 9600 0 23 45 67 89 90 -.br -37 -.br - -.br -$ pigs wvsc 0 -.br -74 -.br -$ pigs wvsc 1 -.br -74 -.br -$ pigs wvsc 2 -.br -25016 -.br - -.EE - -.br - -.IP "\fBWVSM ws\fP - Get waveform time stats" -.IP "" 4 - -.br -The statistic requested by \fBws\fP is returned. - -.br -\fBws\fP identifies the subcommand as follows. - -.br -0 Get Micros -.br -1 Get High Micros -.br -2 Get Max Micros - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvsm 0 -.br -5314 -.br -$ pigs wvsm 1 -.br -5314 -.br -$ pigs wvsm 2 -.br -1800000000 -.br - -.EE - -.br - -.IP "\fBWVSP ws\fP - Get waveform pulse stats" -.IP "" 4 - -.br -The statistic requested by \fBws\fP is returned. - -.br -\fBws\fP identifies the subcommand as follows. - -.br -0 Get Pulses -.br -1 Get High Pulses -.br -2 Get Max Pulses - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvsp 0 -.br -37 -.br -$ pigs wvsp 1 -.br -37 -.br -$ pigs wvsp 2 -.br -12000 -.br - -.EE - -.br - -.IP "\fBWVTX wid\fP - Transmits waveform once" -.IP "" 4 - -.br -This command transmits the waveform with id \fBwid\fP once. - -.br -NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. - -.br -Upon success the number of DMA control blocks in the waveform is returned. -On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvtx 1 -.br -75 -.br - -.br -$ pigs wvtx 2 -.br --66 -.br -ERROR: non existent wave id -.br - -.EE - -.br - -.IP "\fBWVTXM wid wmde\fP - Transmits waveform using mode" -.IP "" 4 - -.br -This command transmits the waveform with id \fBwid\fP using mode \fBwmde\fP. - -.br -The mode may be send once (0), send repeatedly (1), send once but -first sync with previous wave (2), or send repeatedly but first -sync with previous wave (3). - -.br -WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. - -.br -NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. - -.br -Upon success the number of DMA control blocks in the waveform is returned. -On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvtxm 1 3 -.br -75 -.br - -.br -$ pigs wvtxm 2 0 -.br --66 -.br -ERROR: non existent wave id -.br - -.EE - -.br - -.IP "\fBWVTXR wid\fP - Transmits waveform repeatedly" -.IP "" 4 - -.br -This command transmits the waveform with id \fBwid\fP repeatedly. - -.br -NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. - -.br -Upon success the number of DMA control blocks in the waveform is returned. -On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvtxr 1 -.br -75 -.br - -.br -$ pigs wvtxr 2 -.br --66 -.br -ERROR: non existent wave id -.br - -.EE - -.br - -.SH PARAMETERS - -.br - -.IP "\fBactv\fP - 0-1000000" 0 - -.br -The number of microseconds level changes are reported for once -a noise filter has been triggered (by \fBstdy\fP microseconds of -a stable level). - -.br - -.IP "\fBb\fP - baud" 0 -The command expects the baud rate in bits per second for -the transmission of serial data (I2C/SPI/serial link, waves). - -.br - -.IP "\fBbctl\fP - BSC control word" 0 -The command expects a BSC control word, see \fBBSCX\fP. - -.br - -.IP "\fBbit\fP - bit value (0-1)" 0 -The command expects 0 or 1. - -.br - -.IP "\fBbits\fP - a bit mask" 0 -A mask is used to select one or more GPIO. A GPIO is selected -if bit (1<=0)" 0 -The command expects a handle. - -.br -A handle is a number referencing an object opened by one of \fBFO\fP, -\fBI2CO\fP, \fBNO\fP, \fBSERO\fP, \fBSPIO\fP. - -.br - -.IP "\fBib\fP - I2C bus (>=0)" 0 -The command expects an I2C bus number. - -.br - -.IP "\fBid\fP - I2C device (0-0x7F)" 0 -The command expects the address of an I2C device. - -.br - -.IP "\fBif\fP - I2C flags (0)" 0 -The command expects an I2C flags value. No flags are currently defined. - -.br - -.IP "\fBL\fP - level (0-1)" 0 -The command expects a GPIO level. - -.br - -.IP "\fBm\fP - mode (RW540123)" 0 -The command expects a mode character. - -.br -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. - -.br -To set the mode use the code for the mode. - -.br -The value is returned by the mode get command. - -.br - -.EX -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 - -.EE - -.br - -.IP "\fBmiso\fP - GPIO (0-31)" 0 -The GPIO used for the MISO signal when bit banging SPI. - -.br - -.IP "\fBmode\fP - file open mode" 0 -One of the following values. - -.br - -.EX - Value Meaning -READ 1 open file for reading -WRITE 2 open file for writing -RW 3 open file for reading and writing - -.EE - -.br -The following values can be or'd into the mode. - -.br - -.EX - 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 - -.EE - -.br - -.IP "\fBmosi\fP - GPIO (0-31)" 0 -The GPIO used for the MOSI signal when bit banging SPI. - -.br - -.IP "\fBname\fP - the name of a script" 0 -Only alphanumeric characters, '-' and '_' are allowed in the name. - -.br - -.IP "\fBnum\fP - maximum number of bytes to return (1-)" 0 -The command expects the maximum number of bytes to return. - -.br -For the I2C and SPI commands the requested number of bytes will always -be returned. - -.br -For the serial and file commands the smaller of the number of -bytes available to be read (which may be zero) and \fBnum\fP bytes -will be returned. - -.br - -.IP "\fBo\fP - offset (>=0)" 0 -Serial data is stored offset microseconds from the start of the waveform. - -.br - -.IP "\fBp\fP - PUD (ODU)" 0 -The command expects a PUD character. - -.br -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. - -.br -A pull up will default the input to 1 (high). - -.br -A pull down will default the input to 0 (low). - -.br -To set the pull up down state use the command character for the state. - -.br - -.EX -Pull Up Down Off Pull Down Pull Up -Command Character O D U - -.EE - -.br -There is no mechanism to read the pull up down state. - -.br - -.IP "\fBpad\fP - 0-2" 0 -A set of GPIO which share common drivers. - -.br - -.EX -Pad GPIO -0 0-27 -1 28-45 -2 46-53 - -.EE - -.br - -.IP "\fBpadma\fP - 1-16" 0 -The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. - -.br - -.IP "\fBpars\fP - script parameters" 0 -The command expects 0 to 10 numbers as parameters to be passed to the script. - -.br - -.IP "\fBpat\fP - a file name pattern" 0 -A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. - -.br - -.IP "\fBpdc\fP - hardware PWM dutycycle (0-1000000)" 0 -The command expects a dutycycle. - -.br - -.IP "\fBpf\fP - hardware PWM frequency (1-125M, 1-187.5M for the BCM2711)" 0 -The command expects a frequency. - -.br - -.IP "\fBpl\fP - pulse length (1-100)" 0 -The command expects a pulse length in microseconds. - -.br - -.IP "\fBr\fP - register (0-255)" 0 -The command expects an I2C register number. - -.br - -.IP "\fBsb\fP - serial stop (half) bits (2-8)" 0 -The command expects the number of stop (half) bits per serial character. - -.br - -.IP "\fBscl\fP - user GPIO (0-31)" 0 -The command expects the number of the GPIO to be used for SCL -when bit banging I2C. - -.br - -.IP "\fBsclk\fP - user GPIO (0-31)" 0 -The GPIO used for the SCLK signal when bit banging SPI. - -.br - -.IP "\fBsda\fP - user GPIO (0-31)" 0 -The command expects the number of the GPIO to be used for SDA -when bit banging I2C. - -.br - -.IP "\fBsef\fP - serial flags (32 bits)" 0 -The command expects a flag value. No serial flags are currently defined. - -.br - -.IP "\fBsid\fP - script id (>= 0)" 0 -The command expects a script id as returned by a call to \fBPROC\fP. - -.br - -.IP "\fBspf\fP - SPI flags (32 bits)" 0 -See \fBSPIO\fP and \fBBSPIO\fP. - -.br - -.IP "\fBstdy\fP - 0-300000" 0 - -.br -The number of microseconds level changes must be stable for -before reporting the level changed (\fBFG\fP) or triggering -the active part of a noise filter (\fBFN\fP). - -.br - -.IP "\fBstr\fP - a string" 0 -The command expects a string. - -.br - -.IP "\fBt\fP - a string" 0 -The command expects a string. - -.br - -.IP "\fBtrips\fP - triplets" 0 -The command expects 1 or more triplets of GPIO on, GPIO off, delay. - -.br -E.g. 0x400000 0 100000 0 0x400000 900000 defines two pulses as follows - -.br - -.EX - GPIO on GPIO off delay -0x400000 (GPIO 22) 0 (None) 100000 (1/10th s) - 0 (None) 0x400000 (GPIO 22) 900000 (9/10th s) - -.EE - -.br - -.IP "\fBu\fP - user GPIO (0-31)" 0 -The command expects the number of a user GPIO. - -.br -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. - -.br -It is your responsibility to ensure that the PWM and servo commands -are only used on safe GPIO. - -.br -See \fBg\fP - -.br - -.IP "\fBuvs\fP - values" 0 -The command expects an arbitrary number of >=0 values (possibly none). -Any after the first two must be <= 255. - -.br - -.IP "\fBv\fP - value" 0 -The command expects a number. - -.br - -.IP "\fBwid\fP - wave id (>=0)" 0 -The command expects a wave id. - -.br -When a waveform is created it is given an id (0, 1, 2, ...). - -.br - -.IP "\fBwmde\fP - mode (0-3)" 0 -The command expects a wave transmission mode. - -.br -0 = send once -.br -1 = send repeatedly -.br -2 = send once but first sync with previous wave -.br -3 = send repeatedly but first sync with previous wave -.br - -.br - -.IP "\fBws\fP - wave stats sucommand (0-2)" 0 -The command expects a subcommand. - -.br -0 = current value. -.br -1 = highest value so far. -.br -2 = maximum possible value. - -.br - -.IP "\fBwv\fP - word value (0-65535)" 0 -The command expects a word value. - -.br - -.SH SCRIPTS - -.br -Scripts are programs to be stored and executed by the pigpio daemon. -They are intended to mitigate any performance problems associated with -the pigpio daemon server/client model. - -.br -.SS Example -.br -A trivial example might be useful. Suppose you want to toggle a GPIO -on and off as fast as possible. - -.br -From the command line you could write - -.br - -.EX -for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done -.br - -.EE - -.br -Timing that you will see it takes about 14 seconds, or roughly -70 toggles per second. - -.br -Using the pigpio Python module you could use code such as - -.br - -.EX -#!/usr/bin/env python -.br - -.br -import time -.br - -.br -import pigpio -.br - -.br -PIN=4 -.br - -.br -TOGGLE=10000 -.br - -.br -pi = pigpio.pi() # Connect to local Pi. -.br - -.br -s = time.time() -.br - -.br -for i in range(TOGGLE): -.br - pi.write(PIN, 1) -.br - pi.write(PIN, 0) -.br - -.br -e = time.time() -.br - -.br -print("pigpio did {} toggles per second".format(int(TOGGLE/(e-s)))) -.br - -.br -pi.stop() -.br - -.EE - -.br -Timing that shows a speed improvement to roughly 800 toggles per second. - -.br -Now let's use a script. - -.br - -.EX -pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999 -.br - -.EE - -.br -Ignore the details for now. - -.br -Let's time the script running. - -.br -Again, ignore the details for now. - -.br - -.EX -time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ -.br - do sleep 0.2; done) -.br - -.EE - -.br -The script takes roughly 12 seconds to complete, or 800,000 toggles per second. - -.br -That is the advantage of a stored script. - -.br -Some details. - -.br - -.EX -pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999 -.br - -.EE - -.br -proc introduces a script. Everything after proc is part of the script. -.br -tag 999 names the current position in the script. -.br -w 22 1 writes 1 to GPIO 22. -.br -w 22 0 writes 0 to GPIO 22. -.br -dcr p0 decrements parameter 0. -.br -jp 999 jumps to tag 999 if the result is positive. - -.br - -.EX -time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ -.br - do sleep 0.2; done) -.br - -.EE - -.br -pigs procr 0 10000000 starts script 0 with parameter 0 of 10 million. - -.br -The rest is bash apart from - -.br -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. - -.br -.SS Virtual machine -.br -A script runs within a virtual machine with - -.br -a 32 bit accumulator A. -.br -a flags register F. -.br -a program counter PC. - -.br -Each script has - -.br -10 parameters named 0 through 9. -.br -150 variables named 0 through 149. -.br -50 labels which are named by any unique number. - -.br -.SS Commands -.br -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. - -.br -The following commands are not permitted within a script: - -.br -File - FL FO FR FW - -.br -I2C - BI2CZ I2CPK I2CRD I2CRI I2CRK I2CWD I2CWI I2CWK I2CZ - -.br -Misc - BSCX CF1 CF2 SHELL - -.br -Script control - PARSE PROC PROCD PROCP PROCR PROCS PROCU - -.br -Serial - SERO SERR SERW SLR - -.br -SPI - BSPIO BSPIX SPIR SPIW SPIX - -.br -Waves - WVAG WVAS WVCHA WVGO WVGOR - -.br -The following commands are only permitted within a script: - -.br - -.EX -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 - -.EE - -.br -x may be a constant, a parameter (p0-p9), or a variable (v0-v149). - -.br -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. - -.br -The EVTWT command parameter is a bit-mask with 1 set for events of interest. - -.br -The WAIT command parameter is a bit-mask with 1 set for GPIO of interest. - -.br -The SYS script receives two unsigned parameters: the accumulator A and -the current GPIO levels. - -.br - -.SH SEE ALSO - -pigpiod(1), pig2vcd(1), pigpio(3), pigpiod_if(3), pigpiod_if2(3) -.SH AUTHOR - -joan@abyz.me.uk diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 b/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 deleted file mode 100644 index 0820b48..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 b/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 deleted file mode 100644 index 93b1db0..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 b/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 deleted file mode 100644 index d89cd8f..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 b/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 deleted file mode 100644 index 79a4182..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 deleted file mode 100644 index 07931f1..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 deleted file mode 100644 index c9ca6e2..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 deleted file mode 100644 index 1630297..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 deleted file mode 100644 index 840f6a8..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 deleted file mode 100644 index ef77c96..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 deleted file mode 100644 index 125a0fc..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 deleted file mode 100644 index 70b41cd..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 b/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 deleted file mode 100644 index 98a0cb1..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 b/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 deleted file mode 100644 index d763ce9..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 deleted file mode 100644 index 23be3f5..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 deleted file mode 100644 index 1dc038e..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 deleted file mode 100644 index 03f11ba..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 deleted file mode 100644 index d37369e..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 and /dev/null differ diff --git a/DOC/tmp/body/cif.body b/DOC/tmp/body/cif.body deleted file mode 100644 index f20d1c4..0000000 --- a/DOC/tmp/body/cif.body +++ /dev/null @@ -1,1824 +0,0 @@ -

pigpio is a C library for the Raspberry which allows control of the GPIO. -

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts -

GPIO

ALL GPIO are identified by their Broadcom number. -

Credits

The PWM and servo pulses are timed using the DMA and PWM peripherals. -

This use was inspired by Richard Hirst's servoblaster kernel module. -

Usage

Include <pigpio.h> in your source files. -

Assuming your source is in prog.c use the following command to build and -run the executable. -

gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
sudo ./prog


For examples of usage see the C programs within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error. -

gpioInitialise must be called before all other library functions -with the following exceptions: -

gpioCfg*
gpioVersion
gpioHardwareRevision


If the library is not initialised all but the gpioCfg*, -gpioVersion, and gpioHardwareRevision functions will -return error PI_NOT_INITIALISED. -

If the library is initialised the gpioCfg* functions will return -error PI_INITIALISED. -

OVERVIEW

ESSENTIAL -
gpioInitialise Initialise library -
gpioTerminate Stop library -
BASIC -
gpioSetMode Set a GPIO mode -
gpioGetMode Get a GPIO mode -
gpioSetPullUpDown Set/clear GPIO pull up/down resistor -
gpioRead Read a GPIO -
gpioWrite Write a GPIO -
PWM (overrides servo commands on same GPIO) -
gpioPWM Start/stop PWM pulses on a GPIO -
gpioSetPWMfrequency Configure PWM frequency for a GPIO -
gpioSetPWMrange Configure PWM range for a GPIO -
gpioGetPWMdutycycle Get dutycycle setting on a GPIO -
gpioGetPWMfrequency Get configured PWM frequency for a GPIO -
gpioGetPWMrange Get configured PWM range for a GPIO -
gpioGetPWMrealRange Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
gpioServo Start/stop servo pulses on a GPIO -
gpioGetServoPulsewidth Get pulsewidth setting on a GPIO -
INTERMEDIATE -
gpioTrigger Send a trigger pulse to a GPIO -
gpioSetWatchdog Set a watchdog on a GPIO -
gpioRead_Bits_0_31 Read all GPIO in bank 1 -
gpioRead_Bits_32_53 Read all GPIO in bank 2 -
gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 -
gpioWrite_Bits_32_53_ClearClear selected GPIO in bank 2 -
gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 -
gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 -
gpioSetAlertFunc Request a GPIO level change callback -
gpioSetAlertFuncEx Request a GPIO change callback, extended -
gpioSetTimerFunc Request a regular timed callback -
gpioSetTimerFuncEx Request a regular timed callback, extended -
gpioStartThread Start a new thread -
gpioStopThread Stop a previously started thread -
ADVANCED -
gpioNotifyOpen Request a notification handle -
gpioNotifyClose Close a notification -
gpioNotifyOpenWithSize Request a notification with sized pipe -
gpioNotifyBegin Start notifications for selected GPIO -
gpioNotifyPause Pause notifications -
gpioHardwareClock Start hardware clock on supported GPIO -
gpioHardwarePWM Start hardware PWM on supported GPIO -
gpioGlitchFilter Set a glitch filter on a GPIO -
gpioNoiseFilter Set a noise filter on a GPIO -
gpioSetPad Sets a pads drive strength -
gpioGetPad Gets a pads drive strength -
shell Executes a shell command -
gpioSetISRFunc Request a GPIO interrupt callback -
gpioSetISRFuncEx Request a GPIO interrupt callback, extended -
gpioSetSignalFunc Request a signal callback -
gpioSetSignalFuncEx Request a signal callback, extended -
gpioSetGetSamplesFunc Requests a GPIO samples callback -
gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended -
Custom -
gpioCustom1 User custom function 1 -
gpioCustom2 User custom function 2 -
Events -
eventMonitor Sets the events to monitor -
eventSetFunc Request an event callback -
eventSetFuncEx Request an event callback, extended -
eventTrigger Trigger an event -
Scripts -
gpioStoreScript Store a script -
gpioRunScript Run a stored script -
gpioUpdateScript Set a scripts parameters -
gpioScriptStatus Get script status and parameters -
gpioStopScript Stop a running script -
gpioDeleteScript Delete a stored script -
I2C -
i2cOpen Opens an I2C device -
i2cClose Closes an I2C device -
i2cWriteQuick SMBus write quick -
i2cReadByte SMBus read byte -
i2cWriteByte SMBus write byte -
i2cReadByteData SMBus read byte data -
i2cWriteByteData SMBus write byte data -
i2cReadWordData SMBus read word data -
i2cWriteWordData SMBus write word data -
i2cReadBlockData SMBus read block data -
i2cWriteBlockData SMBus write block data -
i2cReadI2CBlockData SMBus read I2C block data -
i2cWriteI2CBlockData SMBus write I2C block data -
i2cReadDevice Reads the raw I2C device -
i2cWriteDevice Writes the raw I2C device -
i2cProcessCall SMBus process call -
i2cBlockProcessCall SMBus block process call -
i2cSwitchCombined Sets or clears the combined flag -
i2cSegments Performs multiple I2C transactions -
i2cZip Performs multiple I2C transactions -
I2C BIT BANG -
bbI2COpen Opens GPIO for bit banging I2C -
bbI2CClose Closes GPIO for bit banging I2C -
bbI2CZip Performs bit banged I2C transactions -
I2C/SPI SLAVE -
bscXfer I2C/SPI as slave transfer -
SERIAL -
serOpen Opens a serial device -
serClose Closes a serial device -
serReadByte Reads a byte from a serial device -
serWriteByte Writes a byte to a serial device -
serRead Reads bytes from a serial device -
serWrite Writes bytes to a serial device -
serDataAvailable Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
gpioSerialReadOpen Opens a GPIO for bit bang serial reads -
gpioSerialReadClose Closes a GPIO for bit bang serial reads -
gpioSerialReadInvert Configures normal/inverted for serial reads -
gpioSerialRead Reads bit bang serial data from a GPIO -
SPI -
spiOpen Opens a SPI device -
spiClose Closes a SPI device -
spiRead Reads bytes from a SPI device -
spiWrite Writes bytes to a SPI device -
spiXfer Transfers bytes with a SPI device -
SPI BIT BANG -
bbSPIOpen Opens GPIO for bit banging SPI -
bbSPIClose Closes GPIO for bit banging SPI -
bbSPIXfer Performs bit banged SPI transactions -
FILES -
fileOpen Opens a file -
fileClose Closes a file -
fileRead Reads bytes from a file -
fileWrite Writes bytes to a file -
fileSeek Seeks to a position within a file -
fileList List files which match a pattern -
WAVES -
gpioWaveClear Deletes all waveforms -
gpioWaveAddNew Starts a new waveform -
gpioWaveAddGeneric Adds a series of pulses to the waveform -
gpioWaveAddSerial Adds serial data to the waveform -
gpioWaveCreate Creates a waveform from added data -
gpioWaveCreatePad Creates a waveform of fixed size from added data -
gpioWaveDelete Deletes a waveform -
gpioWaveTxSend Transmits a waveform -
gpioWaveChain Transmits a chain of waveforms -
gpioWaveTxAt Returns the current transmitting waveform -
gpioWaveTxBusy Checks to see if the waveform has ended -
gpioWaveTxStop Aborts the current waveform -
gpioWaveGetCbs Length in CBs of the current waveform -
gpioWaveGetHighCbs Length of longest waveform so far -
gpioWaveGetMaxCbs Absolute maximum allowed CBs -
gpioWaveGetMicros Length in micros of the current waveform -
gpioWaveGetHighMicros Length of longest waveform so far -
gpioWaveGetMaxMicros Absolute maximum allowed micros -
gpioWaveGetPulses Length in pulses of the current waveform -
gpioWaveGetHighPulses Length of longest waveform so far -
gpioWaveGetMaxPulses Absolute maximum allowed pulses -
UTILITIES -
gpioDelay Delay for a number of microseconds -
gpioTick Get current tick (microseconds) -
gpioHardwareRevision Get hardware revision -
gpioVersion Get the pigpio version -
getBitInBytes Get the value of a bit -
putBitInBytes Set the value of a bit -
gpioTime Get current time -
gpioSleep Sleep for specified time -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -
CONFIGURATION -
gpioCfgBufferSize Configure the GPIO sample buffer size -
gpioCfgClock Configure the GPIO sample rate -
gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) -
gpioCfgDMAchannels Configure the DMA channels -
gpioCfgPermissions Configure the GPIO access permissions -
gpioCfgInterfaces Configure user interfaces -
gpioCfgSocketPort Configure socket port -
gpioCfgMemAlloc Configure DMA memory allocation mode -
gpioCfgNetAddr Configure allowed network addresses -
gpioCfgInternals Configure misc. internals (DEPRECATED) -
gpioCfgGetInternals Get internal configuration settings -
gpioCfgSetInternals Set internal configuration settings -
EXPERT -
rawWaveAddSPI Not intended for general use -
rawWaveAddGeneric Not intended for general use -
rawWaveCB Not intended for general use -
rawWaveCBAdr Not intended for general use -
rawWaveGetOOL Not intended for general use -
rawWaveSetOOL Not intended for general use -
rawWaveGetOut Not intended for general use -
rawWaveSetOut Not intended for general use -
rawWaveGetIn Not intended for general use -
rawWaveSetIn Not intended for general use -
rawWaveInfo Not intended for general use -
rawDumpWave Not intended for general use -
rawDumpScript Not intended for general use -

FUNCTIONS

int gpioInitialise(void)

-Initialises the library. -

Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. -

gpioInitialise must be called before using the other library functions -with the following exceptions: -

gpioCfg*
gpioVersion
gpioHardwareRevision


Example

if (gpioInitialise() < 0)
{
   // pigpio initialisation failed.
}
else
{
   // pigpio initialised okay.
}

void gpioTerminate(void)

-Terminates the library. -

Returns nothing. -

Call before program exit. -

This function resets the used DMA channels, releases memory, and -terminates any running threads. -

Example

gpioTerminate();

int gpioSetMode(unsigned gpio, unsigned mode)

-Sets the GPIO mode, typically input or output. -

gpio: 0-53
mode: 0-7


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. -

Arduino style: pinMode. -

Example

gpioSetMode(17, PI_INPUT);  // Set GPIO17 as input.

gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output.

gpioSetMode(22,PI_ALT0);    // Set GPIO22 to alternative mode 0.


See http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf page 102 for an overview of the modes. -

int gpioGetMode(unsigned gpio)

-Gets the GPIO mode. -

gpio: 0-53


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

Example

if (gpioGetMode(17) != PI_ALT0)
{
   gpioSetMode(17, PI_ALT0);  // set GPIO17 to ALT0
}

int gpioSetPullUpDown(unsigned gpio, unsigned pud)

-Sets or clears resistor pull ups or downs on the GPIO. -

gpio: 0-53
 pud: 0-2


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. -

Example

gpioSetPullUpDown(17, PI_PUD_UP);   // Sets a pull-up.

gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.

gpioSetPullUpDown(23, PI_PUD_OFF);  // Clear any pull-ups/downs.

int gpioRead(unsigned gpio)

-Reads the GPIO level, on or off. -

gpio: 0-53


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

Arduino style: digitalRead. -

Example

printf("GPIO24 is level %d", gpioRead(24));

int gpioWrite(unsigned gpio, unsigned level)

-Sets the GPIO level, on or off. -

 gpio: 0-53
level: 0-1


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. -

If PWM or servo pulses are active on the GPIO they are switched off. -

Arduino style: digitalWrite -

Example

gpioWrite(24, 1); // Set GPIO24 high.

int gpioPWM(unsigned user_gpio, unsigned dutycycle)

-Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). -Range defaults to 255. -

user_gpio: 0-31
dutycycle: 0-range


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. -

Arduino style: analogWrite -

This and the servo functionality use the DMA and PWM or PCM peripherals -to control and schedule the pulse lengths and dutycycles. -

The gpioSetPWMrange function may be used to change the default -range of 255. -

Example

gpioPWM(17, 255); // Sets GPIO17 full on.

gpioPWM(18, 128); // Sets GPIO18 half on.

gpioPWM(23, 0);   // Sets GPIO23 full off.

int gpioGetPWMdutycycle(unsigned user_gpio)

-Returns the PWM dutycycle setting for the GPIO. -

user_gpio: 0-31


Returns between 0 (off) and range (fully on) if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see gpioGetPWMrange). -

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). -

Normal PWM range defaults to 255. -

int gpioSetPWMrange(unsigned user_gpio, unsigned range)

-Selects the dutycycle range to be used for the GPIO. Subsequent calls -to gpioPWM will use a dutycycle between 0 (off) and range (fully on). -

user_gpio: 0-31
    range: 25-40000


Returns the real range for the given GPIO's frequency if OK, -otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. -

If PWM is currently active on the GPIO its dutycycle will be scaled -to reflect the new range. -

The real range, the number of steps between fully off and fully -on for each frequency, is given in the following table. -

  25,   50,  100,  125,  200,  250,  400,   500,   625,
 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000


The real value set by gpioPWM is (dutycycle * real range) / range. -

Example

gpioSetPWMrange(24, 2000); // Now 2000 is fully on
                           //     1000 is half on
                           //      500 is quarter on, etc.

int gpioGetPWMrange(unsigned user_gpio)

-Returns the dutycycle range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). -

Example

r = gpioGetPWMrange(23);

int gpioGetPWMrealRange(unsigned user_gpio)

-Returns the real range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


If a hardware clock is active on the GPIO the reported real -range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

Example

rr = gpioGetPWMrealRange(17);

int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)

-Sets the frequency in hertz to be used for the GPIO. -

user_gpio: 0-31
frequency: >=0


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO. -

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 frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency.

gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz.

gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency.

int gpioGetPWMfrequency(unsigned user_gpio)

-Returns the frequency (in hertz) used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


For normal PWM the frequency will be that defined for the GPIO by -gpioSetPWMfrequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by gpioHardwareClock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by gpioHardwarePWM. -

Example

f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23.

int gpioServo(unsigned user_gpio, unsigned pulsewidth)

-Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to -2500 (most clockwise). -

 user_gpio: 0-31
pulsewidth: 0, 500-2500


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. -

The range supported by servos varies and should probably be determined -by experiment. A value of 1500 should always be safe and represents -the mid-point of rotation. You can DAMAGE a servo if you command it -to move beyond its limits. -

The following 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

gpioServo(17, 1000); // Move servo to safe position anti-clockwise.

gpioServo(23, 1500); // Move servo to centre position.

gpioServo(25, 2000); // Move servo to safe position clockwise.


OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

PWM Hz    50   100  200  400  500
1E6/Hz 20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using gpioSetPWMfrequency. -

Then set the PWM range using gpioSetPWMrange to 1E6/frequency. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO25 at 400Hz -

gpioSetPWMfrequency(25, 400);

gpioSetPWMrange(25, 2500);


Thereafter use the PWM command to move the servo, -e.g. gpioPWM(25, 1500) will set a 1500 us pulse. -

int gpioGetServoPulsewidth(unsigned user_gpio)

-Returns the servo pulsewidth setting for the GPIO. -

user_gpio: 0-31


Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) -if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)

-Registers a function to be called (a callback) when the specified -GPIO changes state. -

user_gpio: 0-31
        f: the callback function


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -

One callback may be registered per GPIO. -

The callback is passed the GPIO, the new level, and the tick. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The alert may be cancelled by passing NULL as the function. -

The GPIO are sampled at a rate set when the library is started. -

If a value isn't specifically set the default of 5 us is used. -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


Level changes shorter than the sample rate may be missed. -

The thread which calls the alert functions is triggered nominally -1000 times per second. The active alert functions will be called -once per level change since the last time the thread was activated. -i.e. The active alert functions will get all level changes but there -will be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use gpioRead. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

The tick value is the time stamp of the sample in microseconds, see -gpioTick for more details. -

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state

gpioSetAlertFunc(4, aFunction);

int gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when the specified -GPIO changes state. -

user_gpio: 0-31
        f: the callback function
 userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -

One callback may be registered per GPIO. -

The callback is passed the GPIO, the new level, the tick, and -the userdata pointer. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


See gpioSetAlertFunc for further details. -

Only one of gpioSetAlertFunc or gpioSetAlertFuncEx can be -registered per GPIO. -

int gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)

-Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. -

   gpio: 0-53
   edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
timeout: interrupt timeout in milliseconds (<=0 to cancel)
      f: the callback function


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. -

One function may be registered per GPIO. -

The function is passed the GPIO, the current level, and the -current tick. The level will be PI_TIMEOUT if the optional -interrupt timeout expires. -

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The underlying Linux sysfs GPIO interface is used to provide -the interrupt services. -

The first time the function is called, with a non-NULL f, the -GPIO is exported, set to be an input, and set to interrupt -on the given edge and timeout. -

Subsequent calls, with a non-NULL f, can vary one or more of the -edge, timeout, or function. -

The ISR may be cancelled by passing a NULL f, in which case the -GPIO is unexported. -

The tick is that read at the time the process was informed of -the interrupt. This will be a variable number of microseconds -after the interrupt occurred. Typically the latency will be of -the order of 50 microseconds. The latency is not guaranteed -and will vary with system load. -

The level is that read at the time the process was informed of -the interrupt, or PI_TIMEOUT if the optional interrupt timeout -expired. It may not be the same as the expected edge as -interrupts happening in rapid succession may be missed by the -kernel (i.e. this mechanism can not be used to capture several -interrupts only a few microseconds apart). -

int gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. -

    gpio: 0-53
    edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 timeout: interrupt timeout in milliseconds (<=0 to cancel)
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. -

The function is passed the GPIO, the current level, the -current tick, and the userdata pointer. -

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


Only one of gpioSetISRFunc or gpioSetISRFuncEx can be -registered per GPIO. -

See gpioSetISRFunc for further details. -

int gpioNotifyOpen(void)

-This function requests a free notification handle. -

Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state changes -via a pipe or socket. -

Pipe notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). E.g. if the -function returns 15 then the notifications must be read -from /dev/pigpio15. -

Socket notifications are returned to the socket which requested the -handle. -

Example

h = gpioNotifyOpen();

if (h >= 0)
{
   sprintf(str, "/dev/pigpio%d", h);

   fd = open(str, O_RDONLY);

   if (fd >= 0)
   {
      // Okay.
   }
   else
   {
      // Error.
   }
}
else
{
   // Error.
}

int gpioNotifyOpenWithSize(int bufSize)

-This function requests a free notification handle. -

It differs from gpioNotifyOpen in that the pipe size may be -specified, whereas gpioNotifyOpen uses the default pipe size. -

See gpioNotifyOpen for further details. -

int gpioNotifyBegin(unsigned handle, uint32_t bits)

-This function starts notifications on a previously opened handle. -

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the GPIO of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose corresponding -bit in bits is set. -

Each notification occupies 12 bytes in the fifo and has the -following structure. -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

Example

// Start notifications for GPIO 1, 4, 6, 7, 10.

//                         1
//                         0  76 4  1
// (1234 = 0x04D2 = 0b0000010011010010)

gpioNotifyBegin(h, 1234);

int gpioNotifyPause(unsigned handle)

-This function pauses notifications on a previously opened handle. -

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until gpioNotifyBegin -is called again. -

Example

gpioNotifyPause(h);

int gpioNotifyClose(unsigned handle)

-This function stops notifications on a previously opened handle -and releases the handle for reuse. -

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

gpioNotifyClose(h);

int gpioWaveClear(void)

-This function clears all waveforms and any data added by calls to the -gpioWaveAdd* functions. -

Returns 0 if OK. -

Example

gpioWaveClear();

int gpioWaveAddNew(void)

-This function starts a new empty waveform. -

You wouldn't normally need to call this function as it is automatically -called after a waveform is created with the gpioWaveCreate function. -

Returns 0 if OK. -

Example

gpioWaveAddNew();

int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses
   pulses: an array of pulses


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. -

Example

// Construct and send a 30 microsecond square wave.

gpioSetMode(gpio, PI_OUTPUT);

pulse[0].gpioOn = (1<<gpio);
pulse[0].gpioOff = 0;
pulse[0].usDelay = 15;

pulse[1].gpioOn = 0;
pulse[1].gpioOff = (1<<gpio);
pulse[1].usDelay = 15;

gpioWaveAddNew();

gpioWaveAddGeneric(2, pulse);

wave_id = gpioWaveCreate();

if (wave_id >= 0)
{
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);

   // Transmit for 30 seconds.

   sleep(30);

   gpioWaveTxStop();
}
else
{
   // Wave create failed.
}

int gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

user_gpio: 0-31
     baud: 50-1000000
data_bits: 1-32
stop_bits: 2-8
   offset: >=0
 numBytes: >=1
      str: an array of chars (which may contain nulls)


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, and -stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

Example

#define MSG_LEN 8

int i;
char *str;
char data[MSG_LEN];

str = "Hello world!";

gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str);

for (i=0; i<MSG_LEN; i++) data[i] = i;

// Data added is offset 1 second from the waveform start.
gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);

int gpioWaveCreate(void)

-This function creates a waveform from the data provided by the prior -calls to the gpioWaveAdd* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the gpioWaveAdd* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to gpioWaveTxSend to specify the waveform to transmit. -

Normal usage would be -

Step 1. gpioWaveClear to clear all waveforms and added data. -

Step 2. gpioWaveAdd* calls to supply the waveform data. -

Step 3. gpioWaveCreate to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. gpioWaveTxSend with the id of the waveform to transmit. -

A waveform comprises one of more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL)

-Similar to gpioWaveCreate, this function creates a waveform but pads the consumed -resources. Padded waves of equal dimension can be re-cycled efficiently allowing -newly created waves to re-use the resources of deleted waves of the same dimension. -

pctCB: 0-100, the percent of all DMA control blocks to consume.
pctBOOL: 0-100, percent On-Off-Level (OOL) buffer to consume for wave output.
pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags).


Upon success a wave id greater than or equal to 0 is returned, otherwise -PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

Waveform data provided by gpioWaveAdd* and rawWaveAdd* functions are -consumed by this function. -

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Example

  // get firstWaveChunk, somehow
  gpioWaveAddGeneric(firstWaveChunk);
  wid = gpioWaveCreatePad(50, 50, 0);
  gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
  // get nextWaveChunk

  while (nextWaveChunk) {
     gpioWaveAddGeneric(nextWaveChunk);
     nextWid = gpioWaveCreatePad(50, 50, 0);
     gpioWaveTxSend(nextWid, PI_WAVE_MODE_ONE_SHOT_SYNC);
     while(gpioWaveTxAt() == wid) time_sleep(0.1);
     gpioWaveDelete(wid);
     wid = nextWid;
     // get nextWaveChunk
  }

int gpioWaveDelete(unsigned wave_id)

-This function deletes the waveform with id wave_id. -

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). -

wave_id: >=0, as returned by gpioWaveCreate


Wave ids are allocated in order, 0, 1, 2, etc. -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)

-This function transmits the waveform with id wave_id. The mode -determines whether the waveform is sent once or cycles endlessly. -The SYNC variants wait for the current waveform to reach the -end of a cycle or finish before starting the new waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. -

  wave_id: >=0, as returned by gpioWaveCreate
wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
           PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int gpioWaveChain(char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpio.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (gpioInitialise()<0) return -1;

   gpioSetMode(GPIO, PI_OUTPUT);

   printf("start piscope, press return"); getchar();

   for (i=0; i<WAVES; i++)
   {
      gpioWaveAddGeneric(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = gpioWaveCreate();
   }

   gpioWaveChain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (gpioWaveTxBusy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);

   printf("stop piscope, press return"); getchar();

   gpioTerminate();
}

int gpioWaveTxAt(void)

-This function returns the id of the waveform currently being -transmitted. -

Returns the waveform id or one of the following special values: -

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
-PI_NO_TX_WAVE (9999) - no wave being transmitted. -

int gpioWaveTxBusy(void)

-This function checks to see if a waveform is currently being -transmitted. -

Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int gpioWaveTxStop(void)

-This function aborts the transmission of the current waveform. -

Returns 0 if OK. -

This function is intended to stop a waveform started in repeat mode. -

int gpioWaveGetMicros(void)

-This function returns the length in microseconds of the current -waveform. -

int gpioWaveGetHighMicros(void)

-This function returns the length in microseconds of the longest waveform -created since gpioInitialise was called. -

int gpioWaveGetMaxMicros(void)

-This function returns the maximum possible size of a waveform in -microseconds. -

int gpioWaveGetPulses(void)

-This function returns the length in pulses of the current waveform. -

int gpioWaveGetHighPulses(void)

-This function returns the length in pulses of the longest waveform -created since gpioInitialise was called. -

int gpioWaveGetMaxPulses(void)

-This function returns the maximum possible size of a waveform in pulses. -

int gpioWaveGetCbs(void)

-This function returns the length in DMA control blocks of the current -waveform. -

int gpioWaveGetHighCbs(void)

-This function returns the length in DMA control blocks of the longest -waveform created since gpioInitialise was called. -

int gpioWaveGetMaxCbs(void)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

int gpioSerialReadOpen(unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

user_gpio: 0-31
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -PI_BAD_DATABITS, or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -gpioSerialRead. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int gpioSerialReadInvert(unsigned user_gpio, unsigned invert)

-This function configures the level logic for bit bang serial reads. -

Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for -normal logic. Default is PI_BB_SER_NORMAL. -

user_gpio: 0-31
   invert: 0-1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, -PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT. -

The GPIO must be opened for bit bang reading of serial data using -gpioSerialReadOpen prior to calling this function. -

int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

user_gpio: 0-31, previously opened with gpioSerialReadOpen
      buf: an array to receive the read bytes
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the gpioSerialReadOpen command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int gpioSerialReadClose(unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

user_gpio: 0-31, previously opened with gpioSerialReadOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)

-This returns a handle for the device at the address on the I2C bus. -

  i2cBus: >=0
 i2cAddr: 0-0x7F
i2cFlags: 0


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S      (1 bit) : Start bit
P      (1 bit) : Stop bit
Rd/Wr  (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA  (1 bit) : Accept and not accept bit.

Addr   (7 bits): I2C 7 bit address.
i2cReg (8 bits): Command byte, a byte which often selects a register.
Data   (8 bits): A data byte.
Count  (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2cClose(unsigned handle)

-This closes the I2C device associated with the handle. -

handle: >=0, as returned by a call to i2cOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2cWriteQuick(unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

handle: >=0, as returned by a call to i2cOpen
   bit: 0-1, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr bit [A] P

int i2cWriteByte(unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] bVal [A] P

int i2cReadByte(unsigned handle)

-This reads a single byte from the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] i2cReg [A] bVal [A] P

int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  wVal: 0-0xFFFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P

int i2cReadByteData(unsigned handle, unsigned i2cReg)

-This reads a single byte from the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P

int i2cReadWordData(unsigned handle, unsigned i2cReg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
  wVal: 0-0xFFFF, the value to write


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: an array with the data to send
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] i2cReg [A] count [A]
   buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
   buf: an array with the data to send and to receive the read data
 count: 1-32, the number of bytes to write


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The SMBus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A]
   S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P

int i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data
 count: 1-32, the number of bytes to read


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: the data to write
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadDevice(unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

handle: >=0, as returned by a call to i2cOpen
   buf: an array to receive the read data bytes
 count: >0, the number of bytes to read


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteDevice(unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

handle: >=0, as returned by a call to i2cOpen
   buf: an array containing the data bytes to write
 count: >0, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

void i2cSwitchCombined(int setting)

-This sets the I2C (i2c-bcm2708) module "use combined transactions" -parameter on or off. -

setting: 0 to set the parameter off, non-zero to set it on


NOTE: when the flag is on a write followed by a read to the same -slave address will use a repeated start (rather than a stop/start). -

int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)

-This function executes multiple I2C segments in one transaction by -calling the I2C_RDWR ioctl. -

 handle: >=0, as returned by a call to i2cOpen
   segs: an array of I2C segments
numSegs: >0, the number of I2C segments


Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. -

int i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bbI2CClose(unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bbI2COpen. -

SDA: 0-31, the SDA GPIO used in a prior call to bbI2COpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

   SDA: 0-31 (as used in a prior call to bbI2COpen)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bscXfer(bsc_xfer_t *bsc_xfer)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

bsc_xfer:= a structure defining the transfer

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. -

Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

The returned function value is the status of the transfer (see below). -

If there was an error the status will be less than zero -(and will contain the error code). -

The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). -

control consists of the following bits. -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. -

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bscXfer(&xfer);

if (status >= 0)
{
   // process transfer
}

int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)

-This function selects a set of GPIO for bit banging SPI with -a specified baud rate and mode. -

      CS: 0-31
    MISO: 0-31
    MOSI: 0-31
    SCLK: 0-31
    baud: 50-250000
spiFlags: see below


spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bbSPIClose(unsigned CS)

-This function stops bit banging SPI on a set of GPIO -opened with bbSPIOpen. -

CS: 0-31, the CS GPIO used in a prior call to bbSPIOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

int bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)

-This function executes a bit banged SPI transfer. -

    CS: 0-31 (as used in a prior call to bbSPIOpen)
 inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
 count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. -

Example

// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
// sudo ./bbSPIx_test

#include <stdio.h>

#include "pigpio.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if (gpioInitialise() < 0)
   {
      fprintf(stderr, "pigpio initialisation failed.\n");
      return 1;
   }

   bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bbSPIClose(CE0);
   bbSPIClose(CE1);

   gpioTerminate();

   return 0;
}

int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


 spiChan: 0-1 (0-2 for the auxiliary SPI)
    baud: 32K-125M (values above 30M are unlikely to work)
spiFlags: see below


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 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. -

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 spiRead, spiWrite, and spiXfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per word.
-For bits 9-16 there will be two bytes per word.
-For bits 17-32 there will be four bytes per word. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spiClose(unsigned handle)

-This functions closes the SPI device identified by the handle. -

handle: >=0, as returned by a call to spiOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spiRead(unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spiOpen
   buf: an array to receive the read data bytes
 count: the number of bytes to read


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spiWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spiOpen
   buf: the data bytes to write
 count: the number of bytes to write


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

handle: >=0, as returned by a call to spiOpen
 txBuf: the data bytes to write
 rxBuf: the received data bytes
 count: the number of bytes to transfer


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serOpen(char *sertty, unsigned baud, unsigned serFlags)

-This function opens a serial device at a specified baud rate -and with specified flags. The device name must start with -/dev/tty or /dev/serial. -

  sertty: the serial device to open
    baud: the baud rate in bits per second, see below
serFlags: 0


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serClose(unsigned handle)

-This function closes the serial device associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serWriteByte(unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serReadByte(unsigned handle)

-This function reads a byte from the serial port associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

handle: >=0, as returned by a call to serOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serRead(unsigned handle, char *buf, unsigned count)

-This function reads up count bytes from the the serial port -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to serOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_SER_READ_NO_DATA. -

If no data is ready zero is returned. -

int serDataAvailable(unsigned handle)

-This function returns the number of bytes available -to be read from the device associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

user_gpio: 0-31
 pulseLen: 1-100
    level: 0,1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -or PI_BAD_PULSELEN. -

int gpioSetWatchdog(unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

user_gpio: 0-31
  timeout: 0-60000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

One watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Until cancelled a timeout will be reported every timeout milliseconds -after the last GPIO activity. -

In particular: -

1) any registered alert function for the GPIO will be called with - the level set to PI_TIMEOUT. -

2) any notification for the GPIO will have a report written to the - fifo with the flags set to indicate a watchdog timeout. -

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state
gpioSetAlertFunc(4, aFunction);

//  or approximately every 5 millis
gpioSetWatchdog(4, 5);

int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, -and gpioSetGetSamplesFuncEx. -

It does not affect interrupts set up with gpioSetISRFunc, -gpioSetISRFuncEx, or levels read by gpioRead, -gpioRead_Bits_0_31, or gpioRead_Bits_32_53. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

int gpioGlitchFilter(unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, -and gpioSetGetSamplesFuncEx. -

It does not affect interrupts set up with gpioSetISRFunc, -gpioSetISRFuncEx, or levels read by gpioRead, -gpioRead_Bits_0_31, or gpioRead_Bits_32_53. -

Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)

-Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. -

   f: the function to call
bits: the GPIO of interest


Returns 0 if OK. -

The function is passed a pointer to the samples (an array of -gpioSample_t), and the number of samples. -

Only one function can be registered. -

The callback may be cancelled by passing NULL as the function. -

The samples returned will be the union of bits, plus any active alerts, -plus any active notifications. -

e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO -8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO -7, 8, 9, 10, 17, 23, and 24 will be reported. -

int gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)

-Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. -

       f: the function to call
    bits: the GPIO of interest
userdata: a pointer to arbitrary user data


Returns 0 if OK. -

The function is passed a pointer to the samples (an array of -gpioSample_t), the number of samples, and the userdata pointer. -

Only one of gpioGetSamplesFunc or gpioGetSamplesFuncEx can be -registered. -

See gpioSetGetSamplesFunc for further details. -

int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)

-Registers a function to be called (a callback) every millis milliseconds. -

 timer: 0-9
millis: 10-60000
     f: the function to call


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. -

10 timers are supported numbered 0 to 9. -

One function may be registered per timer. -

The timer may be cancelled by passing NULL as the function. -

Example

void bFunction(void)
{
   printf("two seconds have elapsed");
}

// call bFunction every 2000 milliseconds
gpioSetTimerFunc(0, 2000, bFunction);

int gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) every millis milliseconds. -

   timer: 0-9.
  millis: 10-60000
       f: the function to call
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. -

The function is passed the userdata pointer. -

Only one of gpioSetTimerFunc or gpioSetTimerFuncEx can be -registered per timer. -

See gpioSetTimerFunc for further details. -

pthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)

-Starts a new thread of execution with f as the main routine. -

       f: the main function for the new thread
userdata: a pointer to arbitrary user data


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument arg. -

The thread can be cancelled by passing the pointer to pthread_t to -gpioStopThread. -

Example

#include <stdio.h>
#include <pigpio.h>

void *myfunc(void *arg)
{
   while (1)
   {
      printf("%s", arg);
      sleep(1);
   }
}

int main(int argc, char *argv[])
{
   pthread_t *p1, *p2, *p3;

   if (gpioInitialise() < 0) return 1;

   p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);

   p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);

   p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);

   gpioStopThread(p3); sleep(3);

   gpioStopThread(p2); sleep(3);

   gpioStopThread(p1); sleep(3);

   gpioTerminate();
}

void gpioStopThread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: a thread pointer returned by gpioStartThread


No value is returned. -

The thread to be stopped should have been started with gpioStartThread. -

int gpioStoreScript(char *script)

-This function stores a null terminated script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

script: the text of the script


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioScriptStatus(unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well as -the current values of parameters 0 to 9. -

script_id: >=0, as returned by gpioStoreScript
    param: an array to hold the returned 10 parameters


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int gpioStopScript(unsigned script_id)

-This function stops a running script. -

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int gpioDeleteScript(unsigned script_id)

-This function deletes a stored script. -

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)

-Registers a function to be called (a callback) when a signal occurs. -

signum: 0-63
     f: the callback function


Returns 0 if OK, otherwise PI_BAD_SIGNUM. -

The function is passed the signal number. -

One function may be registered per signal. -

The callback may be cancelled by passing NULL. -

By default all signals are treated as fatal and cause the library -to call gpioTerminate and then exit. -

int gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when a signal occurs. -

  signum: 0-63
       f: the callback function
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_SIGNUM. -

The function is passed the signal number and the userdata pointer. -

Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be -registered per signal. -

See gpioSetSignalFunc for further details. -

uint32_t gpioRead_Bits_0_31(void)

-Returns the current level of GPIO 0-31. -

uint32_t gpioRead_Bits_32_53(void)

-Returns the current level of GPIO 32-53. -

int gpioWrite_Bits_0_31_Clear(uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask of GPIO to clear


Returns 0 if OK. -

Example

// To clear (set to 0) GPIO 4, 7, and 15
gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );

int gpioWrite_Bits_32_53_Clear(uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask of GPIO to clear


Returns 0 if OK. -

int gpioWrite_Bits_0_31_Set(uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask of GPIO to set


Returns 0 if OK. -

int gpioWrite_Bits_32_53_Set(uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask of GPIO to set


Returns 0 if OK. -

Example

// To set (set to 1) GPIO 32, 40, and 53
gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));

int gpioHardwareClock(unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

   gpio: see description
clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, -PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by gpioWaveTxSend, or -gpioWaveChain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden by a call to -gpioCfgClock. -

   gpio: see description
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, -PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. -

int gpioTime(unsigned timetype, int *seconds, int *micros)

-Updates the seconds and micros variables with the current time. -

timetype: 0 (relative), 1 (absolute)
 seconds: a pointer to an int to hold seconds
  micros: a pointer to an int to hold microseconds


Returns 0 if OK, otherwise PI_BAD_TIMETYPE. -

If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the -number of seconds and microseconds since the epoch (1st January 1970). -

If timetype is PI_TIME_RELATIVE updates seconds and micros with the -number of seconds and microseconds since the library was initialised. -

Example

int secs, mics;

// print the number of seconds since the library was started
gpioTime(PI_TIME_RELATIVE, &secs, &mics);
printf("library started %d.%03d seconds ago", secs, mics/1000);

int gpioSleep(unsigned timetype, int seconds, int micros)

-Sleeps for the number of seconds and microseconds specified by seconds -and micros. -

timetype: 0 (relative), 1 (absolute)
 seconds: seconds to sleep
  micros: microseconds to sleep


Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, -or PI_BAD_MICROS. -

If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds -and microseconds since the epoch (1st January 1970) has elapsed. System -clock changes are taken into account. -

If timetype is PI_TIME_RELATIVE the sleep is for the specified number -of seconds and microseconds. System clock changes do not effect the -sleep length. -

For short delays (say, 50 microseonds or less) use gpioDelay. -

Example

gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds

gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds

gpioSleep(PI_TIME_RELATIVE, 60, 0);     // sleep for one minute

uint32_t gpioDelay(uint32_t micros)

-Delays for at least the number of microseconds specified by micros. -

micros: the number of microseconds to sleep


Returns the actual length of the delay in microseconds. -

Delays of 100 microseconds or less use busy waits. -

uint32_t gpioTick(void)

-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. -

You don't need to worry about the wrap around as long as you -take a tick (uint32_t) from another tick, i.e. the following -code will always provide the correct difference. -

Example

uint32_t startTick, endTick;
int diffTick;

startTick = gpioTick();

// do some processing

endTick = gpioTick();

diffTick = endTick - startTick;

printf("some processing took %d microseconds", diffTick);

unsigned gpioHardwareRevision(void)

-Returns the hardware revision. -

If the hardware revision can not be found or is not a valid hexadecimal -number the function returns 0. -

The hardware revision is the last few characters on the Revision line of -/proc/cpuinfo. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

for "Revision : 0002" the function returns 2.
-for "Revision : 000f" the function returns 15.
-for "Revision : 000g" the function returns 0. -

unsigned gpioVersion(void)

-Returns the pigpio version. -

int gpioGetPad(unsigned pad)

-This function returns the pad drive strength in mA. -

pad: 0-2, the pad to get


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = gpioGetPad(1); // get pad 1 strength

int gpioSetPad(unsigned pad, unsigned padStrength)

-This function sets the pad drive strength in mA. -

        pad: 0-2, the pad to set
padStrength: 1-16 mA


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

gpioSetPad(0, 16); // set pad 0 strength to 16 mA

int eventMonitor(unsigned handle, uint32_t bits)

-This function selects the events to be reported on a previously -opened handle. -

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the events of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

A report is sent each time an event is triggered providing the -corresponding bit in bits is set. -

See gpioNotifyBegin for the notification format. -

Example

// Start reporting events 3, 6, and 7.

//  bit      76543210
// (0xC8 = 0b11001000)

eventMonitor(h, 0xC8);

int eventSetFunc(unsigned event, eventFunc_t f)

-Registers a function to be called (a callback) when the specified -event occurs. -

event: 0-31
    f: the callback function


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

One function may be registered per event. -

The function is passed the event, and the tick. -

The callback may be cancelled by passing NULL as the function. -

int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when the specified -event occurs. -

   event: 0-31
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

One function may be registered per event. -

The function is passed the event, the tick, and the ueserdata pointer. -

The callback may be cancelled by passing NULL as the function. -

Only one of eventSetFunc or eventSetFuncEx can be -registered per event. -

int eventTrigger(unsigned event)

-This function signals the occurrence of an event. -

event: 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling eventSetFunc) will be informed by -a callback. -

One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

int shell(char *scriptName, char *scriptString)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name
scriptString: the string to pass to the script


The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. -

scriptName must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell("scr1", "\"hello string with spaces world\"");

int fileOpen(char *file, unsigned mode)

-This function returns a handle to a file opened in a specified mode. -

file: the file to open
mode: the file open mode


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


The following values may be or'd into the mode. -

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int handle, c;
   char buf[60000];

   if (gpioInitialise() < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   handle = fileOpen("/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=fileRead(handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      fileClose(handle);
   }

   gpioTerminate();
}

int fileClose(unsigned handle)

-This function closes the file associated with handle. -

handle: >=0, as returned by a call to fileOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

fileClose(h);

int fileWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the file -associated with handle. -

handle: >=0, as returned by a call to fileOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. -

Example

status = fileWrite(h, buf, count);
if (status == 0)
{
   // okay
}
else
{
   // error
}

int fileRead(unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the file -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to fileOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. -

Example

if (fileRead(h, buf, sizeof(buf)) > 0)
{
   // process read data
}

int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)

-This function seeks to a position within the file associated -with handle. -

    handle: >=0, as returned by a call to fileOpen
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2)


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. -

Example

fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20

size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size

pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position

int fileList(char *fpat, char *buf, unsigned count)

-This function returns a list of files which match a pattern. The -pattern may contain wildcards. -

 fpat: file pattern to match
  buf: an array to receive the matching file names
count: the maximum number of bytes to read


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See fileOpen. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int c;
   char buf[1000];

   if (gpioInitialise() < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   c = fileList("/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      // terminate string
      buf[c] = 0;
      printf("%s", buf);
   }

   gpioTerminate();
}

int gpioCfgBufferSize(unsigned cfgMillis)

-Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. -

This function is only effective if called before gpioInitialise. -

cfgMillis: 100-10000


The default setting is 120 milliseconds. -

The intention is to allow for bursts of data and protection against -other processes hogging cpu time. -

I haven't seen a process locked out for more than 100 milliseconds. -

Making the buffer bigger uses a LOT of memory at the more frequent -sampling rates as shown in the following table in MBs. -

                     buffer milliseconds
               120 250 500 1sec 2sec 4sec 8sec

         1      16  31  55  107  ---  ---  ---
         2      10  18  31   55  107  ---  ---
sample   4       8  12  18   31   55  107  ---
 rate    5       8  10  14   24   45   87  ---
 (us)    8       6   8  12   18   31   55  107
        10       6   8  10   14   24   45   87

int gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)

-Configures pigpio to use a particular sample rate timed by a specified -peripheral. -

This function is only effective if called before gpioInitialise. -

    cfgMicros: 1, 2, 4, 5, 8, 10
cfgPeripheral: 0 (PWM), 1 (PCM)
    cfgSource: deprecated, value is ignored


The timings are provided by the specified peripheral (PWM or PCM). -

The default setting is 5 microseconds using the PCM peripheral. -

The approximate CPU percentage used for each sample rate is: -

sample  cpu
 rate    %

  1     25
  2     16
  4     11
  5     10
  8     15
 10     14


A sample rate of 5 microseconds seeems to be the sweet spot. -

int gpioCfgDMAchannel(unsigned DMAchannel)

-Configures pigpio to use the specified DMA channel. -

This function is only effective if called before gpioInitialise. -

DMAchannel: 0-14


The default setting is to use channel 14. -

int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)

-Configures pigpio to use the specified DMA channels. -

This function is only effective if called before gpioInitialise. -

  primaryChannel: 0-14
secondaryChannel: 0-14


The default setting depends on whether the Pi has a BCM2711 chip or -not (currently only the Pi4B has a BCM2711). -

The default setting for a non-BCM2711 is to use channel 14 for the -primary channel and channel 6 for the secondary channel. -

The default setting for a BCM2711 is to use channel 7 for the -primary channel and channel 6 for the secondary channel. -

The secondary channel is only used for the transmission of waves. -

If possible use one of channels 0 to 6 for the secondary channel -(a full channel). -

A full channel only requires one DMA control block regardless of the -length of a pulse delay. Channels 7 to 14 (lite channels) require -one DMA control block for each 16383 microseconds of delay. I.e. -a 10 second pulse delay requires one control block on a full channel -and 611 control blocks on a lite channel. -

int gpioCfgPermissions(uint64_t updateMask)

-Configures pigpio to restrict GPIO updates via the socket or pipe -interfaces to the GPIO specified by the mask. Programs directly -calling the pigpio library (i.e. linked with -lpigpio are not -affected). A GPIO update is a write to a GPIO or a GPIO mode -change or any function which would force such an action. -

This function is only effective if called before gpioInitialise. -

updateMask: bit (1<<n) is set for each GPIO n which may be updated


The default setting depends upon the Pi model. The user GPIO are -added to the mask. -

If the board revision is not recognised then GPIO 2-27 are allowed. -

Unknown boardPI_DEFAULT_UPDATE_MASK_UNKNOWN0x0FFFFFFC
Type 1 boardPI_DEFAULT_UPDATE_MASK_B10x03E6CF93
Type 2 boardPI_DEFAULT_UPDATE_MASK_A_B20xFBC6CF9C
Type 3 boardPI_DEFAULT_UPDATE_MASK_R30x0FFFFFFC

int gpioCfgSocketPort(unsigned port)

-Configures pigpio to use the specified socket port. -

This function is only effective if called before gpioInitialise. -

port: 1024-32000


The default setting is to use port 8888. -

int gpioCfgInterfaces(unsigned ifFlags)

-Configures pigpio support of the fifo and socket interfaces. -

This function is only effective if called before gpioInitialise. -

ifFlags: 0-7


The default setting (0) is that both interfaces are enabled. -

Or in PI_DISABLE_FIFO_IF to disable the pipe interface. -

Or in PI_DISABLE_SOCK_IF to disable the socket interface. -

Or in PI_LOCALHOST_SOCK_IF to disable remote socket -access (this means that the socket interface is only -usable from the local Pi). -

int gpioCfgMemAlloc(unsigned memAllocMode)

-Selects the method of DMA memory allocation. -

This function is only effective if called before gpioInitialise. -

memAllocMode: 0-2


There are two methods of DMA memory allocation. The original method -uses the /proc/self/pagemap file to allocate bus memory. The new -method uses the mailbox property interface to allocate bus memory. -

Auto will use the mailbox method unless a larger than default buffer -size is requested with gpioCfgBufferSize. -

int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)

-Sets the network addresses which are allowed to talk over the -socket interface. -

This function is only effective if called before gpioInitialise. -

numSockAddr: 0-256 (0 means all addresses allowed)
   sockAddr: an array of permitted network addresses.

int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)

-Used to tune internal settings. -

cfgWhat: see source code
 cfgVal: see source code

uint32_t gpioCfgGetInternals(void)

-This function returns the current library internal configuration -settings. -

int gpioCfgSetInternals(uint32_t cfgVal)

-This function sets the current library internal configuration -settings. -

cfgVal: see source code

int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from gpioCustom1 in that it returns an array of bytes -rather than just an integer. -

The returned value is an integer indicating the number of returned bytes. -  arg1: >=0
  argx: extra (byte) arguments
  argc: number of extra arguments
retBuf: buffer for returned bytes
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

The number of returned bytes must be retMax or less. -

int rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)

-This function adds a waveform representing SPI data to the -existing waveform (if any). -

        spi: a pointer to a spi object
     offset: microseconds from the start of the waveform
      spiSS: the slave select GPIO
        buf: the bits to transmit, most significant bit first
  spiTxBits: the number of bits to write
spiBitFirst: the first bit to read
 spiBitLast: the last bit to read
    spiBits: the number of bits to transfer


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. -

Not intended for general use. -

int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses
   pulses: the array containing the pulses


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The advantage of this function over gpioWaveAddGeneric is that it -allows the setting of the flags field. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. -

Not intended for general use. -

unsigned rawWaveCB(void)

-Returns the number of the cb being currently output. -

Not intended for general use. -

rawCbs_t *rawWaveCBAdr(int cbNum)

-Return the (Linux) address of contol block cbNum. -

cbNum: the cb of interest


Not intended for general use. -

uint32_t rawWaveGetOOL(int pos)

-Gets the OOL parameter stored at pos. -

pos: the position of interest.


Not intended for general use. -

void rawWaveSetOOL(int pos, uint32_t lVal)

-Sets the OOL parameter stored at pos to value. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

uint32_t rawWaveGetOut(int pos)

-Gets the wave output parameter stored at pos. -

DEPRECATED: use rawWaveGetOOL instead. -

pos: the position of interest.


Not intended for general use. -

void rawWaveSetOut(int pos, uint32_t lVal)

-Sets the wave output parameter stored at pos to value. -

DEPRECATED: use rawWaveSetOOL instead. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

uint32_t rawWaveGetIn(int pos)

-Gets the wave input value parameter stored at pos. -

DEPRECATED: use rawWaveGetOOL instead. -

pos: the position of interest


Not intended for general use. -

void rawWaveSetIn(int pos, uint32_t lVal)

-Sets the wave input value stored at pos to value. -

DEPRECATED: use rawWaveSetOOL instead. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

rawWaveInfo_t rawWaveInfo(int wave_id)

-Gets details about the wave with id wave_id. -

wave_id: the wave of interest


Not intended for general use. -

int getBitInBytes(int bitPos, char *buf, int numBits)

-Returns the value of the bit bitPos bits from the start of buf. Returns -0 if bitPos is greater than or equal to numBits. -

 bitPos: bit index from the start of buf
    buf: array of bits
numBits: number of valid bits in buf

void putBitInBytes(int bitPos, char *buf, int bit)

-Sets the bit bitPos bits from the start of buf to bit. -

bitPos: bit index from the start of buf
   buf: array of bits
   bit: 0-1, value to set

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds -

seconds: the number of seconds to sleep

void rawDumpWave(void)

-Used to print a readable version of the current waveform to stderr. -

Not intended for general use. -

void rawDumpScript(unsigned script_id)

-Used to print a readable version of a script to stderr. -

script_id: >=0, a script_id returned by gpioStoreScript


Not intended for general use. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bitPos

-A bit position within a byte or word. The least significant bit is -position 0. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

*bsc_xfer

-A pointer to a bsc_xfer_t object used to control a BSC transfer. -

bsc_xfer_t

-typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

cbNum

-A number identifying a DMA contol block. -

cfgMicros

-The GPIO sample rate in microseconds. The default is 5us, or 200 thousand -samples per second. -

cfgMillis: 100-10000

-The size of the sample buffer in milliseconds. Generally this should be -left at the default of 120ms. If you expect intense bursts of signals it -might be necessary to increase the buffer size. -

cfgPeripheral

-One of the PWM or PCM peripherals used to pace DMA transfers for timing -purposes. -

cfgSource

-Deprecated. -

cfgVal

-A number specifying the value of a configuration item. See cfgWhat. -

cfgWhat

-A number specifying a configuration item. -

562484977: print enhanced statistics at termination.
-984762879: set the initial debug level. -

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

-The hardware clock frequency. -

PI_HW_CLK_MIN_FREQ 4689
PI_HW_CLK_MAX_FREQ 250000000
PI_HW_CLK_MAX_FREQ_2711 375000000

count

-The number of bytes to be transferred in an I2C, SPI, or Serial -command. -

CS

-The GPIO used for the slave select signal when bit banging SPI. -

data_bits: 1-32

-The number of data bits to be used when adding serial data to a -waveform. -

PI_MIN_WAVE_DATABITS 1
PI_MAX_WAVE_DATABITS 32

DMAchannel: 0-15

-PI_MIN_DMA_CHANNEL 0
PI_MAX_DMA_CHANNEL 15

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge: 0-2

-The type of GPIO edge to generate an interrupt. See gpioSetISRFunc -and gpioSetISRFuncEx. -

RISING_EDGE 0
FALLING_EDGE 1
EITHER_EDGE 2

event: 0-31

-An event is a signal used to inform one or more consumers -to start an action. -

eventFunc_t

-typedef void (*eventFunc_t) (int event, uint32_t tick);

eventFuncEx_t

-typedef void (*eventFuncEx_t)
   (int event, uint32_t tick, void *userdata);

f

-A function. -

*file

-A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. -

*fpat

-A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 gpioHardwareRevision. -

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  -  -  -  -

gpioAlertFunc_t

-typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);

gpioAlertFuncEx_t

-typedef void (*eventFuncEx_t)
   (int event, int level, uint32_t tick, void *userdata);

gpioCfg*

-These functions are only effective if called before gpioInitialise. -

gpioCfgBufferSize
-gpioCfgClock
-gpioCfgDMAchannel
-gpioCfgDMAchannels
-gpioCfgPermissions
-gpioCfgInterfaces
-gpioCfgSocketPort
-gpioCfgMemAlloc -

gpioGetSamplesFunc_t

-typedef void (*gpioGetSamplesFunc_t)
   (const gpioSample_t *samples, int numSamples);

gpioGetSamplesFuncEx_t

-typedef void (*gpioGetSamplesFuncEx_t)
   (const gpioSample_t *samples, int numSamples, void *userdata);

gpioISRFunc_t

-typedef void (*gpioISRFunc_t)
   (int gpio, int level, uint32_t tick);

gpioISRFuncEx_t

-typedef void (*gpioISRFuncEx_t)
   (int gpio, int level, uint32_t tick, void *userdata);

gpioPulse_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioSample_t

-typedef struct
{
   uint32_t tick;
   uint32_t level;
} gpioSample_t;

gpioSignalFunc_t

-typedef void (*gpioSignalFunc_t) (int signum);

gpioSignalFuncEx_t

-typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

gpioTimerFunc_t

-typedef void (*gpioTimerFunc_t) (void);

gpioTimerFuncEx_t

-typedef void (*gpioTimerFuncEx_t) (void *userdata);

gpioWaveAdd*

-One of -

gpioWaveAddNew
-gpioWaveAddGeneric
-gpioWaveAddSerial -

handle: >=0

-A number referencing an object opened by one of -

fileOpen
-gpioNotifyOpen
-i2cOpen
-serOpen
-spiOpen -

i2cAddr: 0-0x7F

-The address of a device on the I2C bus. -

i2cBus: >=0

-An I2C bus number. -

i2cFlags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2cReg: 0-255

-A register of an I2C device. -

ifFlags: 0-3

-PI_DISABLE_FIFO_IF 1
PI_DISABLE_SOCK_IF 2

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

int32_t

-A 32-bit signed value. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See gpioSetWatchdog. -

PI_TIMEOUT 2

lVal: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)

-A 32-bit word value. -

memAllocMode: 0-2

-The DMA memory allocation mode. -

PI_MEM_ALLOC_AUTO    0
PI_MEM_ALLOC_PAGEMAP 1
PI_MEM_ALLOC_MAILBOX 2

*micros

-A value representing microseconds. -

micros

-A value representing microseconds. -

millis

-A value representing milliseconds. -

MISO

-The GPIO used for the MISO signal when bit banging SPI. -

mode

-1. The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. A file open mode. -

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


The following values can be or'd into the mode. -

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

-The GPIO used for the MOSI signal when bit banging SPI. -

numBits

-The number of bits stored in a buffer. -

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

numSegs

-The number of segments in a combined I2C transaction. -

numSockAddr

-The number of network addresses allowed to use the socket interface. -

0 means all addresses allowed. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

pad: 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

-The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

*param

-An array of script parameters. -

pctBOOL: 0-100

-percent On-Off-Level (OOL) buffer to consume for wave output. -

pctCB: 0-100

-the percent of all DMA control blocks to consume. -

pctTOOL: 0-100

-the percent of OOL buffer to consume for wave input (flags). -

pi_i2c_msg_t

-typedef struct
{
   uint16_t addr;  // slave address
   uint16_t flags;
   uint16_t len;   // msg length
   uint8_t  *buf;  // pointer to msg data
} pi_i2c_msg_t;

port: 1024-32000

-The port used to bind to the pigpio socket. Defaults to 8888. -

pos

-The position of an item. -

primaryChannel: 0-15

-The DMA channel used to time the sampling of GPIO and to time servo and -PWM pulses. -

*pth

-A thread identifier, returned by gpioStartThread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -

PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

-The hardware PWM frequency. -

PI_HW_PWM_MIN_FREQ 1
PI_HW_PWM_MAX_FREQ 125000000
PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

-PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

rawCbs_t

-typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
{
   unsigned long info;
   unsigned long src;
   unsigned long dst;
   unsigned long length;
   unsigned long stride;
   unsigned long next;
   unsigned long pad[2];
} rawCbs_t;

rawSPI_t

-typedef struct
{
   int clk;     // GPIO for clock
   int mosi;    // GPIO for MOSI
   int miso;    // GPIO for MISO
   int ss_pol;  // slave select off state
   int ss_us;   // delay after slave select
   int clk_pol; // clock off state
   int clk_pha; // clock phase
   int clk_us;  // clock micros
} rawSPI_t;

rawWave_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
   uint32_t flags;
} rawWave_t;

rawWaveInfo_t

-typedef struct
{
   uint16_t botCB;  // first CB used by wave
   uint16_t topCB;  // last CB used by wave
   uint16_t botOOL; // last OOL used by wave
   uint16_t topOOL; // first OOL used by wave
   uint16_t deleted;
   uint16_t numCB;
   uint16_t numBOOL;
   uint16_t numTOOL;
} rawWaveInfo_t;

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

SCLK

-The GPIO used for the SCLK signal when bit banging SPI. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by gpioStoreScript. -

*scriptName

-The name of a shell script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. -

*scriptString

-The string to be passed to a shell script to be executed. -

SDA

-The user GPIO to use for data when bit banging I2C. -

secondaryChannel: 0-6

-The DMA channel used to time output waveforms. -

*seconds

-A pointer to a uint32_t to store the second component of -a returned time. -

seconds

-The number of seconds. -

seekFrom

-PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

-The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). -

*segs

-An array of segments which make up a combined I2C transaction. -

serFlags

-Flags which modify a serial open command. None are currently defined. -

*sertty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

setting

-A value used to set a flag, 0 for false, non-zero for true. -

signum: 0-63

-PI_MIN_SIGNUM 0
PI_MAX_SIGNUM 63

size_t

-A standard type used to indicate the size of an object in bytes. -

*sockAddr

-An array of network addresses allowed to use the socket interface encoded -as 32 bit numbers. -

E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. -

*spi

-A pointer to a rawSPI_t structure. -

spiBitFirst

-GPIO reads are made from spiBitFirst to spiBitLast. -

spiBitLast

-GPIO reads are made from spiBitFirst to spiBitLast. -

spiBits

-The number of bits to transfer in a raw SPI transaction. -

spiChan

-A SPI channel, 0-2. -

spiFlags

-See spiOpen and bbSPIOpen. -

spiSS

-The SPI slave select GPIO in a raw SPI transaction. -

spiTxBits

-The number of bits to transfer dring a raw SPI transaction -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (gpioGlitchFilter) or triggering -the active part of a noise filter (gpioNoiseFilter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

PI_MIN_WAVE_HALFSTOPBITS 2
PI_MAX_WAVE_HALFSTOPBITS 8

*str

-An array of characters. -

timeout

-A GPIO level change timeout in milliseconds. -

gpioSetWatchdog -PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000


gpioSetISRFunc and gpioSetISRFuncEx -<=0 cancel timeout
>0 timeout after specified milliseconds

timer

-PI_MIN_TIMER 0
PI_MAX_TIMER 9

timetype

-PI_TIME_RELATIVE 0
PI_TIME_ABSOLUTE 1

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

uint64_t: 0-(2^64)-1

-A 64-bit unsigned value. -

unsigned

-A whole number >= 0. -

updateMask

-A 64 bit mask indicating which GPIO may be written to by the user. -

If GPIO#n may be written then bit (1<<n) is set. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. -

In the calling function: -

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: -

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

-Denoting no parameter is required -

wave_id

-A number identifying a waveform created by gpioWaveCreate. -

wave_mode

-The mode determines if the waveform is sent once or cycles -repeatedly. The SYNC variants wait for the current waveform -to reach the end of a cycle or finish before starting the new -waveform. -

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

Socket Command Codes


#define PI_CMD_MODES  0
#define PI_CMD_MODEG  1
#define PI_CMD_PUD    2
#define PI_CMD_READ   3
#define PI_CMD_WRITE  4
#define PI_CMD_PWM    5
#define PI_CMD_PRS    6
#define PI_CMD_PFS    7
#define PI_CMD_SERVO  8
#define PI_CMD_WDOG   9
#define PI_CMD_BR1   10
#define PI_CMD_BR2   11
#define PI_CMD_BC1   12
#define PI_CMD_BC2   13
#define PI_CMD_BS1   14
#define PI_CMD_BS2   15
#define PI_CMD_TICK  16
#define PI_CMD_HWVER 17
#define PI_CMD_NO    18
#define PI_CMD_NB    19
#define PI_CMD_NP    20
#define PI_CMD_NC    21
#define PI_CMD_PRG   22
#define PI_CMD_PFG   23
#define PI_CMD_PRRG  24
#define PI_CMD_HELP  25
#define PI_CMD_PIGPV 26
#define PI_CMD_WVCLR 27
#define PI_CMD_WVAG  28
#define PI_CMD_WVAS  29
#define PI_CMD_WVGO  30
#define PI_CMD_WVGOR 31
#define PI_CMD_WVBSY 32
#define PI_CMD_WVHLT 33
#define PI_CMD_WVSM  34
#define PI_CMD_WVSP  35
#define PI_CMD_WVSC  36
#define PI_CMD_TRIG  37
#define PI_CMD_PROC  38
#define PI_CMD_PROCD 39
#define PI_CMD_PROCR 40
#define PI_CMD_PROCS 41
#define PI_CMD_SLRO  42
#define PI_CMD_SLR   43
#define PI_CMD_SLRC  44
#define PI_CMD_PROCP 45
#define PI_CMD_MICS  46
#define PI_CMD_MILS  47
#define PI_CMD_PARSE 48
#define PI_CMD_WVCRE 49
#define PI_CMD_WVDEL 50
#define PI_CMD_WVTX  51
#define PI_CMD_WVTXR 52
#define PI_CMD_WVNEW 53

#define PI_CMD_I2CO  54
#define PI_CMD_I2CC  55
#define PI_CMD_I2CRD 56
#define PI_CMD_I2CWD 57
#define PI_CMD_I2CWQ 58
#define PI_CMD_I2CRS 59
#define PI_CMD_I2CWS 60
#define PI_CMD_I2CRB 61
#define PI_CMD_I2CWB 62
#define PI_CMD_I2CRW 63
#define PI_CMD_I2CWW 64
#define PI_CMD_I2CRK 65
#define PI_CMD_I2CWK 66
#define PI_CMD_I2CRI 67
#define PI_CMD_I2CWI 68
#define PI_CMD_I2CPC 69
#define PI_CMD_I2CPK 70

#define PI_CMD_SPIO  71
#define PI_CMD_SPIC  72
#define PI_CMD_SPIR  73
#define PI_CMD_SPIW  74
#define PI_CMD_SPIX  75

#define PI_CMD_SERO  76
#define PI_CMD_SERC  77
#define PI_CMD_SERRB 78
#define PI_CMD_SERWB 79
#define PI_CMD_SERR  80
#define PI_CMD_SERW  81
#define PI_CMD_SERDA 82

#define PI_CMD_GDC   83
#define PI_CMD_GPW   84

#define PI_CMD_HC    85
#define PI_CMD_HP    86

#define PI_CMD_CF1   87
#define PI_CMD_CF2   88

#define PI_CMD_BI2CC 89
#define PI_CMD_BI2CO 90
#define PI_CMD_BI2CZ 91

#define PI_CMD_I2CZ  92

#define PI_CMD_WVCHA 93

#define PI_CMD_SLRI  94

#define PI_CMD_CGI   95
#define PI_CMD_CSI   96

#define PI_CMD_FG    97
#define PI_CMD_FN    98

#define PI_CMD_NOIB  99

#define PI_CMD_WVTXM 100
#define PI_CMD_WVTAT 101

#define PI_CMD_PADS  102
#define PI_CMD_PADG  103

#define PI_CMD_FO    104
#define PI_CMD_FC    105
#define PI_CMD_FR    106
#define PI_CMD_FW    107
#define PI_CMD_FS    108
#define PI_CMD_FL    109

#define PI_CMD_SHELL 110

#define PI_CMD_BSPIC 111
#define PI_CMD_BSPIO 112
#define PI_CMD_BSPIX 113

#define PI_CMD_BSCX  114

#define PI_CMD_EVM   115
#define PI_CMD_EVT   116

#define PI_CMD_PROCU 117
#define PI_CMD_WVCAP 118

Error Codes


#define PI_INIT_FAILED       -1 // gpioInitialise failed
#define PI_BAD_USER_GPIO     -2 // GPIO not 0-31
#define PI_BAD_GPIO          -3 // GPIO not 0-53
#define PI_BAD_MODE          -4 // mode not 0-7
#define PI_BAD_LEVEL         -5 // level not 0-1
#define PI_BAD_PUD           -6 // pud not 0-2
#define PI_BAD_PULSEWIDTH    -7 // pulsewidth not 0 or 500-2500
#define PI_BAD_DUTYCYCLE     -8 // dutycycle outside set range
#define PI_BAD_TIMER         -9 // timer not 0-9
#define PI_BAD_MS           -10 // ms not 10-60000
#define PI_BAD_TIMETYPE     -11 // timetype not 0-1
#define PI_BAD_SECONDS      -12 // seconds < 0
#define PI_BAD_MICROS       -13 // micros not 0-999999
#define PI_TIMER_FAILED     -14 // gpioSetTimerFunc failed
#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
#define PI_NO_ALERT_FUNC    -16 // DEPRECATED
#define PI_BAD_CLK_PERIPH   -17 // clock peripheral not 0-1
#define PI_BAD_CLK_SOURCE   -18 // DEPRECATED
#define PI_BAD_CLK_MICROS   -19 // clock micros not 1, 2, 4, 5, 8, or 10
#define PI_BAD_BUF_MILLIS   -20 // buf millis not 100-10000
#define PI_BAD_DUTYRANGE    -21 // dutycycle range not 25-40000
#define PI_BAD_DUTY_RANGE   -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
#define PI_BAD_SIGNUM       -22 // signum not 0-63
#define PI_BAD_PATHNAME     -23 // can't open pathname
#define PI_NO_HANDLE        -24 // no handle available
#define PI_BAD_HANDLE       -25 // unknown handle
#define PI_BAD_IF_FLAGS     -26 // ifFlags > 4
#define PI_BAD_CHANNEL      -27 // DMA channel not 0-15
#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15
#define PI_BAD_SOCKET_PORT  -28 // socket port not 1024-32000
#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15
#define PI_NOT_INITIALISED  -31 // function called before gpioInitialise
#define PI_INITIALISED      -32 // function called after gpioInitialise
#define PI_BAD_WAVE_MODE    -33 // waveform mode not 0-3
#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
#define PI_BAD_WAVE_BAUD    -35 // baud rate not 50-250K(RX)/50-1M(TX)
#define PI_TOO_MANY_PULSES  -36 // waveform has too many pulses
#define PI_TOO_MANY_CHARS   -37 // waveform has too many chars
#define PI_NOT_SERIAL_GPIO  -38 // no bit bang serial read on GPIO
#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
#define PI_BAD_SERIAL_BUF   -40 // bad (null) serial buf parameter
#define PI_NOT_PERMITTED    -41 // GPIO operation not permitted
#define PI_SOME_PERMITTED   -42 // one or more GPIO not permitted
#define PI_BAD_WVSC_COMMND  -43 // bad WVSC subcommand
#define PI_BAD_WVSM_COMMND  -44 // bad WVSM subcommand
#define PI_BAD_WVSP_COMMND  -45 // bad WVSP subcommand
#define PI_BAD_PULSELEN     -46 // trigger pulse length not 1-100
#define PI_BAD_SCRIPT       -47 // invalid script
#define PI_BAD_SCRIPT_ID    -48 // unknown script id
#define PI_BAD_SER_OFFSET   -49 // add serial data offset > 30 minutes
#define PI_GPIO_IN_USE      -50 // GPIO already in use
#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
#define PI_BAD_PARAM_NUM    -52 // script parameter id not 0-9
#define PI_DUP_TAG          -53 // script has duplicate tag
#define PI_TOO_MANY_TAGS    -54 // script has too many tags
#define PI_BAD_SCRIPT_CMD   -55 // illegal script command
#define PI_BAD_VAR_NUM      -56 // script variable id not 0-149
#define PI_NO_SCRIPT_ROOM   -57 // no more room for scripts
#define PI_NO_MEMORY        -58 // can't allocate temporary memory
#define PI_SOCK_READ_FAILED -59 // socket read failed
#define PI_SOCK_WRIT_FAILED -60 // socket write failed
#define PI_TOO_MANY_PARAM   -61 // too many script parameters (> 10)
#define PI_NOT_HALTED       -62 // DEPRECATED
#define PI_SCRIPT_NOT_READY -62 // script initialising
#define PI_BAD_TAG          -63 // script has unresolved tag
#define PI_BAD_MICS_DELAY   -64 // bad MICS delay (too large)
#define PI_BAD_MILS_DELAY   -65 // bad MILS delay (too large)
#define PI_BAD_WAVE_ID      -66 // non existent wave id
#define PI_TOO_MANY_CBS     -67 // No more CBs for waveform
#define PI_TOO_MANY_OOL     -68 // No more OOL for waveform
#define PI_EMPTY_WAVEFORM   -69 // attempt to create an empty waveform
#define PI_NO_WAVEFORM_ID   -70 // no more waveforms
#define PI_I2C_OPEN_FAILED  -71 // can't open I2C device
#define PI_SER_OPEN_FAILED  -72 // can't open serial device
#define PI_SPI_OPEN_FAILED  -73 // can't open SPI device
#define PI_BAD_I2C_BUS      -74 // bad I2C bus
#define PI_BAD_I2C_ADDR     -75 // bad I2C address
#define PI_BAD_SPI_CHANNEL  -76 // bad SPI channel
#define PI_BAD_FLAGS        -77 // bad i2c/spi/ser open flags
#define PI_BAD_SPI_SPEED    -78 // bad SPI speed
#define PI_BAD_SER_DEVICE   -79 // bad serial device name
#define PI_BAD_SER_SPEED    -80 // bad serial baud rate
#define PI_BAD_PARAM        -81 // bad i2c/spi/ser parameter
#define PI_I2C_WRITE_FAILED -82 // i2c write failed
#define PI_I2C_READ_FAILED  -83 // i2c read failed
#define PI_BAD_SPI_COUNT    -84 // bad SPI count
#define PI_SER_WRITE_FAILED -85 // ser write failed
#define PI_SER_READ_FAILED  -86 // ser read failed
#define PI_SER_READ_NO_DATA -87 // ser read no data available
#define PI_UNKNOWN_COMMAND  -88 // unknown command
#define PI_SPI_XFER_FAILED  -89 // spi xfer/read/write failed
#define PI_BAD_POINTER      -90 // bad (NULL) pointer
#define PI_NO_AUX_SPI       -91 // no auxiliary SPI on Pi A or B
#define PI_NOT_PWM_GPIO     -92 // GPIO is not in use for PWM
#define PI_NOT_SERVO_GPIO   -93 // GPIO is not in use for servo pulses
#define PI_NOT_HCLK_GPIO    -94 // GPIO has no hardware clock
#define PI_NOT_HPWM_GPIO    -95 // GPIO has no hardware PWM
#define PI_BAD_HPWM_FREQ    -96 // invalid hardware PWM frequency
#define PI_BAD_HPWM_DUTY    -97 // hardware PWM dutycycle not 0-1M
#define PI_BAD_HCLK_FREQ    -98 // invalid hardware clock frequency
#define PI_BAD_HCLK_PASS    -99 // need password to use hardware clock 1
#define PI_HPWM_ILLEGAL    -100 // illegal, PWM in use for main clock
#define PI_BAD_DATABITS    -101 // serial data bits not 1-32
#define PI_BAD_STOPBITS    -102 // serial (half) stop bits not 2-8
#define PI_MSG_TOOBIG      -103 // socket/pipe message too big
#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode
#define PI_TOO_MANY_SEGS   -105 // too many I2C transaction segments
#define PI_BAD_I2C_SEG     -106 // an I2C transaction segment failed
#define PI_BAD_SMBUS_CMD   -107 // SMBus command not supported by driver
#define PI_NOT_I2C_GPIO    -108 // no bit bang I2C in progress on GPIO
#define PI_BAD_I2C_WLEN    -109 // bad I2C write length
#define PI_BAD_I2C_RLEN    -110 // bad I2C read length
#define PI_BAD_I2C_CMD     -111 // bad I2C command
#define PI_BAD_I2C_BAUD    -112 // bad I2C baud rate, not 50-500k
#define PI_CHAIN_LOOP_CNT  -113 // bad chain loop count
#define PI_BAD_CHAIN_LOOP  -114 // empty chain loop
#define PI_CHAIN_COUNTER   -115 // too many chain counters
#define PI_BAD_CHAIN_CMD   -116 // bad chain command
#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
#define PI_CHAIN_NESTING   -118 // chain counters nested too deeply
#define PI_CHAIN_TOO_BIG   -119 // chain is too long
#define PI_DEPRECATED      -120 // deprecated function removed
#define PI_BAD_SER_INVERT  -121 // bit bang serial invert not 0 or 1
#define PI_BAD_EDGE        -122 // bad ISR edge value, not 0-2
#define PI_BAD_ISR_INIT    -123 // bad ISR initialisation
#define PI_BAD_FOREVER     -124 // loop forever must be last command
#define PI_BAD_FILTER      -125 // bad filter parameter
#define PI_BAD_PAD         -126 // bad pad number
#define PI_BAD_STRENGTH    -127 // bad pad drive strength
#define PI_FIL_OPEN_FAILED -128 // file open failed
#define PI_BAD_FILE_MODE   -129 // bad file mode
#define PI_BAD_FILE_FLAG   -130 // bad file flag
#define PI_BAD_FILE_READ   -131 // bad file read
#define PI_BAD_FILE_WRITE  -132 // bad file write
#define PI_FILE_NOT_ROPEN  -133 // file not open for read
#define PI_FILE_NOT_WOPEN  -134 // file not open for write
#define PI_BAD_FILE_SEEK   -135 // bad file seek
#define PI_NO_FILE_MATCH   -136 // no files match pattern
#define PI_NO_FILE_ACCESS  -137 // no permission to access file
#define PI_FILE_IS_A_DIR   -138 // file is a directory
#define PI_BAD_SHELL_STATUS -139 // bad shell return status
#define PI_BAD_SCRIPT_NAME -140 // bad script name
#define PI_BAD_SPI_BAUD    -141 // bad SPI baud rate, not 50-500k
#define PI_NOT_SPI_GPIO    -142 // no bit bang SPI in progress on GPIO
#define PI_BAD_EVENT_ID    -143 // bad event id
#define PI_CMD_INTERRUPTED -144 // Used by Python
#define PI_NOT_ON_BCM2711  -145 // not available on BCM2711
#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711

#define PI_PIGIF_ERR_0    -2000
#define PI_PIGIF_ERR_99   -2099

#define PI_CUSTOM_ERR_0   -3000
#define PI_CUSTOM_ERR_999 -3999

Defaults


#define PI_DEFAULT_BUFFER_MILLIS           120
#define PI_DEFAULT_CLK_MICROS              5
#define PI_DEFAULT_CLK_PERIPHERAL          PI_CLOCK_PCM
#define PI_DEFAULT_IF_FLAGS                0
#define PI_DEFAULT_FOREGROUND              0
#define PI_DEFAULT_DMA_CHANNEL             14
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL     14
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL   6
#define PI_DEFAULT_DMA_PRIMARY_CH_2711     7
#define PI_DEFAULT_DMA_SECONDARY_CH_2711   6
#define PI_DEFAULT_DMA_NOT_SET             15
#define PI_DEFAULT_SOCKET_PORT             8888
#define PI_DEFAULT_SOCKET_PORT_STR         "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR         "localhost"
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN     0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_B1          0x03E7CF93
#define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_ZERO        0x0080000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI2B        0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI3B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI4B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_COMPUTE     0x00FFFFFFFFFFFFLL
#define PI_DEFAULT_MEM_ALLOC_MODE          PI_MEM_ALLOC_AUTO

#define PI_DEFAULT_CFG_INTERNALS           0

\ No newline at end of file diff --git a/DOC/tmp/body/download.body b/DOC/tmp/body/download.body deleted file mode 100644 index cdabc9a..0000000 --- a/DOC/tmp/body/download.body +++ /dev/null @@ -1,57 +0,0 @@ - -If the pigpio daemon is running it should be killed (sudo killall -pigpiod) before make install and restarted afterwards (sudo -pigpiod).
-
-The initial part of the make, the -compilation of pigpio.c, takes 100 seconds on early model -Pis.  Be patient.  The overall install takes just over 3 -minutes.
-

Download and install (V75)

-wget https://github.com/joan2937/pigpio/archive/v75.zip
-unzip v75.zip
-cd pigpio-75
-make
-sudo make install

-
-If the Python part of the install fails it may be because you need -the setup tools.
-
-sudo apt install python-setuptools -python3-setuptools

-
-

To check the library

-These tests make extensive use of GPIO 25 (pin 22).  Make sure -nothing, or only a LED, is connected to the GPIO before running the -tests.  Most tests are statistical in nature and so may on -occasion fail.  Repeated failures on the same test or many -failures in a group of tests indicate a problem.
-
-sudo ./x_pigpio # check C I/F
-
-sudo pigpiod    # start daemon
-
-./x_pigpiod_if2 # check C      I/F to -daemon
-./x_pigpio.py   # check Python I/F to daemon
-./x_pigs        # check -pigs   I/F to daemon
-./x_pipe        # check -pipe   I/F to daemon
-
-
-

To compile, link, and run a C program

-gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
-sudo ./foobar


-

To start the pigpio daemon

-sudo pigpiod
-

To stop the pigpio daemon

-sudo killall pigpiod

-

github

-git clone https://github.com/joan2937/pigpio
-

Raspbian (raspberrypi.org image)

-

This may not be the most recent version.  You can check the -version with the command pigpiod -v.

-sudo apt-get update
-sudo apt-get install pigpio python-pigpio python3-pigpio

-
diff --git a/DOC/tmp/body/ex_LDR.body b/DOC/tmp/body/ex_LDR.body deleted file mode 100644 index 1b1911a..0000000 --- a/DOC/tmp/body/ex_LDR.body +++ /dev/null @@ -1,141 +0,0 @@ - -

The following code shows a method of reading analogue sensors on -the digital input only Pi.  A Light Dependent Resistor (LDR) -varies its resistance according to the incident light -intensisty.

-

SETUP

-fritzing diagramThe LDR -used is a Cadmium Sulphide device with a 1MOhm dark resistance and -2-4KOhm at 100 lux.  The capacitor is a 104 -ceramic.
-
-One end of the capacitor is connected to Pi ground.
-
-One end of the LDR is connected to Pi 3V3.
-
-The other ends of the capacitor and LDR are connected to a spare -gpio.

-

Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18 -(P1-12) is used for the gpio.

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/* ------------------------------------------------------------------------
- -
-   3V3 ----- Light Dependent Resistor --+-- Capacitor ------ Ground
-                                        -|
-                                        -+-- gpio
-
-
-  cc -o LDR LDR.c -lpigpio -lpthread -lrt
-  sudo ./LDR
-
-*/
-
-#define LDR 18
-
-/* forward declaration */
-
-void alert(int pin, int level, uint32_t tick);
-
-int main (int argc, char *argv[])
-{
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetAlertFunc(LDR, alert); /* call alert when LDR -changes state */
-    
-   while (1)
-   {
-      gpioSetMode(LDR, PI_OUTPUT); /* -drain capacitor */
-
-      gpioWrite(LDR, PI_OFF);
-
-      gpioDelay(200); /* 50 micros is -enough, 200 is overkill */
-
-      gpioSetMode(LDR, PI_INPUT); /* start -capacitor recharge */
-
-      gpioDelay(10000); /* nominal 100 -readings per second */
-   }
-
-   gpioTerminate();
-}
-
-void alert(int pin, int level, uint32_t tick)
-{
-   static uint32_t inited = 0;
-   static uint32_t lastTick, firstTick;
-
-   uint32_t diffTick;
-
-   if (inited)
-   {
-      diffTick = tick - lastTick;
-      lastTick = tick;
-
-      if (level == 1) printf("%u %d\ ", -tick-firstTick, diffTick);
-   }
-   else
-   {
-      inited = 1;
-      firstTick = tick;
-      lastTick = firstTick;
-   }
-}
-

BUILD

-cc -o LDR LDR.c -lpigpio -lrt -lpthread
-

RUN

-sudo ./LDR >LDR.dat &
-
-While the program is running you can capture the waveform using the -notification feature built in to pigpio.  Issue the following -commands on the Pi.
-
-pigs no
-pig2vcd  </dev/pigpio0 >LDR.vcd &
-pigs nb 0 0x40000 # set bit for gpio 18
-

Change the light falling on the LDR for a few seconds (e.g. -shine a torch on it or shade it with your hands).

-pigs nc 0
-

The file LDR.vcd will contain the captured waveform, which can -be viewed using GTKWave.

-

Overview

-LDR waveform 1
-

Reading circa every 10ms

-LDR waveform 2
-

One reading, circa 400us

-LDR waveform 3
-

The file LDR.dat will contain pairs of timestamps and recharge -time (in us).  The following  script will convert the -timestamps into seconds.

-

awk '{print $1/1000000, $2}' LDR.dat ->LDR-secs.dat

-

Gnuplot is a useful tool to graph data.

-plot [14:24] 'LDR-secs.dat' with lines title 'LDR' -

Gnuplot readings 14-24 seconds

-

gnuplot 1

-plot [18:21] 'LDR-secs.dat' with lines title 'LDR'
-
-Gnuplot readings 18-21 seconds -

Gnuplot 2

diff --git a/DOC/tmp/body/ex_ir_remote.body b/DOC/tmp/body/ex_ir_remote.body deleted file mode 100644 index cebc97f..0000000 --- a/DOC/tmp/body/ex_ir_remote.body +++ /dev/null @@ -1,244 +0,0 @@ - -

The following code shows one way to read an infrared remote -control device (the sort used in TVs and stereo systems).

-

SETUP

-fritzing diagramThe device used -is a SFH5110 (IR Receiver for remote control, -carrier 38 kHz).
-
Pin 1 (left from front) may be connected to any spare -gpio.  Here it's connected via a 4K7 current limiting -resistor.  This isn't really needed as the device has an -internal 23K resistor in-line.  It does no harm though.
-
-Pin 2 should be connected to a Pi ground pin.
-
-Pin 3 should be connected to a Pi 5V pin.
-

Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground -(P1-14), and pin 3 to 5V (P1-2).

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-#define IR_PIN 7
-
-#define OUTSIDE_CODE 0
-#define INSIDE_CODE  1
-
-#define MIN_MESSAGE_GAP 3000
-#define MAX_MESSAGE_END 3000
-
-#define MAX_TRANSITIONS 500
-
-/*
-   using the FNV-1a -hash                
- -   from -http://isthe.com/chongo/tech/comp/fnv/#FNV-param
-*/
-
-#define FNV_PRIME_32 16777619
-#define FNV_BASIS_32 2166136261U
-
-static volatile uint32_t ir_hash = 0;
-
-typedef struct
-{
-   int state;
-   int count;
-   int level;
-   uint16_t micros[MAX_TRANSITIONS];
-} decode_t;
-
-/* forward declarations */
-
-void     alert(int gpio, int level, uint32_t -tick);
-uint32_t getHash(decode_t * decode);
-void     updateState(decode_t * decode, int -level, uint32_t micros);
-
-int main(int argc, char * argv[])
-{
-   if (gpioInitialise()<0)
-   {
-      return 1 ;
-   }
-
-   /* IR pin as input */
-
-   gpioSetMode(IR_PIN, PI_INPUT);
-
-   /* 5ms max gap after last pulse */
-
-   gpioSetWatchdog(IR_PIN, 5);
-
-   /* monitor IR level changes */
-
-   gpioSetAlertFunc(IR_PIN, alert);
-
-   while (1)
-   {
-      if (ir_hash)
-      {
-         /* non-zero means -new decode */
-         printf("ir code is -%u\ ", ir_hash);
-         ir_hash = 0;
-      }
-
-      gpioDelay(100000); /* check remote -10 times per second */
-   }
-
-   gpioTerminate();
-}
-
-void alert(int gpio, int level, uint32_t tick)
-{
-   static int inited = 0;
-
-   static decode_t activeHigh, activeLow;
-
-   static uint32_t lastTick;
-
-   uint32_t diffTick;
-
-   if (!inited)
-   {
-      inited = 1;
-
-      activeHigh.state = OUTSIDE_CODE; -activeHigh.level = PI_LOW;
-      activeLow.state  = -OUTSIDE_CODE; activeLow.level  = PI_HIGH;
-
-      lastTick = tick;
-      return;
-   }
-
-   diffTick = tick - lastTick;
-
-   if (level != PI_TIMEOUT) lastTick = tick;
-
-   updateState(&activeHigh, level, diffTick);
-   updateState(&activeLow, level, diffTick);
-}
-
-void updateState(decode_t * decode, int level, uint32_t micros)
-{
-   /*
-      We are dealing with active high as -well as active low
-      remotes.  Abstract the common -functionality.
-   */
-
-   if (decode->state == OUTSIDE_CODE)
-   {
-      if (level == decode->level)
-      {
-         if (micros > -MIN_MESSAGE_GAP)
-         {
-            -decode->state = INSIDE_CODE;
-            -decode->count = 0;
-         }
-      }
-   }
-   else
-   {
-      if (micros > MAX_MESSAGE_END)
-      {
-         /* end of message -*/
-
-         /* ignore if last -code not consumed */
-
-         if (!ir_hash) -ir_hash = getHash(decode);
-
-         decode->state = -OUTSIDE_CODE;
-      }
-      else
-      {
-         if -(decode->count < (MAX_TRANSITIONS-1))
-         {
-            -if (level != PI_TIMEOUT)
-               -decode->micros[decode->count++] = micros;
-         }
-      }
-   }
-}
-
-int compare(unsigned int oldval, unsigned int newval)
-{
-   if      (newval < (oldval -* 0.75)) {return 1;}
-   else if (oldval < (newval * 0.75)) {return 2;}
-   -else                               -{return 4;}
-}
-
-uint32_t getHash(decode_t * decode)
-{
-   /* use FNV-1a */
-
-   uint32_t hash;
-   int i, value;
-
-   if (decode->count < 6) {return 0;}
-
-   hash = FNV_BASIS_32;
-
-   for (i=0; i<(decode->count-2); i++)
-   {
-      value = -compare(decode->micros[i], decode->micros[i+2]);
-
-      hash = hash ^ value;
-      hash = (hash * FNV_PRIME_32);
-   }
-
-   return hash;
-}
-

BUILD

-cc -o ir_remote ir_remote.c -lpigpio -lrt --lpthread
-

RUN

-sudo ./ir_remote
-

A hash code is formed from the level transitions detected during -a remote key press.  This is likely to be unique over multiple -remotes and keys.

-

While the program is running you can capture the waveform using -the notification feature built in to pigpio.  Issue the -following commands on the Pi.

-pigs no
-pig2vcd  </dev/pigpio0 >ir.vcd &
-pigs nb 0 0x80 # set bits for gpios 7 (0x80)
-

Press a few different remotes and keys.  Then enter

-pigs nc 0
-

The file ir.vcd will contain the captured waveform, which can be -viewed using GTKWave.

-

Overview

-ir remote waveform 1
-

Remote A typical waveform

-ir remote waveform 2
-

Remote B typical waveform

--"ir diff --git a/DOC/tmp/body/ex_motor_shield.body b/DOC/tmp/body/ex_motor_shield.body deleted file mode 100644 index fbadb3a..0000000 --- a/DOC/tmp/body/ex_motor_shield.body +++ /dev/null @@ -1,245 +0,0 @@ - -The following example demonstrates the use of an Arduino shield -from the Rasperry Pi.
-
-The shield used is a clone of the Adafruit motor shield.  See -shieldlist.org -for details.
-
-For the demonstration DC motors 3 and 4 are being driven forwards -and backwards with changing speeds (speeds are controlled via -PWM).
-
-Seven connections are made between the Pi and the shield.  -Four to latch the motor states (latch, enable, data, clock); Two to -control motor speed (PWM 3 and 4); and ground.
-
-The code used was ported from the Adafruit Arduino code and -converted to use the pigpio library.  Only the DC motor code -was ported.
-
-A video of the shield in use is available at youtube.com
-
-#include <stdio.h>

-
-#include <pigpio.h>
-
-/*
-   This code may be used to drive the Adafruit (or -clones) Motor Shield.
-
-   The code as written only supports DC motors.
-
-   http://shieldlist.org/adafruit/motor
-
-   The shield pinouts are
-
-   D12 MOTORLATCH
-   D11 PMW motor 1
-   D10 Servo 1
-   D9  Servo 2
-   D8  MOTORDATA
-
-   D7  MOTORENABLE
-   D6  PWM motor 4
-   D5  PWM motor 3
-   D4  MOTORCLK
-   D3  PWM motor 2
-
-   The motor states (forward, backward, brake, release) -are encoded using the
-   MOTOR_ latch pins.  This saves four gpios.
-*/
-
-typedef unsigned char uint8_t;
-
-#define BIT(bit) (1 << (bit))
-
-/* assign gpios to drive the shield pins */
-
-/*      -Shield      Pi */
-
-#define MOTORLATCH  14
-#define MOTORCLK    24
-#define MOTORENABLE 25
-#define MOTORDATA   15
-
-#define MOTOR_3_PWM  7
-#define MOTOR_4_PWM  8
-
-/*
-   The only other connection needed between the Pi and -the shield
-   is ground to ground. I used Pi P1-6 to shield gnd -(next to D13).
-*/
-
-/* assignment of motor states to latch */
-
-#define MOTOR1_A 2
-#define MOTOR1_B 3
-#define MOTOR2_A 1
-#define MOTOR2_B 4
-#define MOTOR4_A 0
-#define MOTOR4_B 6
-#define MOTOR3_A 5
-#define MOTOR3_B 7
-
-#define FORWARD  1
-#define BACKWARD 2
-#define BRAKE    3
-#define RELEASE  4
-
-static uint8_t latch_state;
-
-void latch_tx(void)
-{
-   unsigned char i;
-
-   gpioWrite(MOTORLATCH, PI_LOW);
-
-   gpioWrite(MOTORDATA, PI_LOW);
-
-   for (i=0; i<8; i++)
-   {
-      gpioDelay(10);  // 10 micros -delay
-
-      gpioWrite(MOTORCLK, PI_LOW);
-
-      if (latch_state & BIT(7-i)) -gpioWrite(MOTORDATA, PI_HIGH);
-      -else                        -gpioWrite(MOTORDATA, PI_LOW);
-
-      gpioDelay(10);  // 10 micros -delay
-
-      gpioWrite(MOTORCLK, PI_HIGH);
-   }
-
-   gpioWrite(MOTORLATCH, PI_HIGH);
-}
-
-void init(void)
-{
-   latch_state = 0;
-
-   latch_tx();
-
-   gpioWrite(MOTORENABLE, PI_LOW);
-}
-
-void DCMotorInit(uint8_t num)
-{
-   switch (num)
-   {
-      case 1: latch_state &= -~BIT(MOTOR1_A) & ~BIT(MOTOR1_B); break;
-      case 2: latch_state &= -~BIT(MOTOR2_A) & ~BIT(MOTOR2_B); break;
-      case 3: latch_state &= -~BIT(MOTOR3_A) & ~BIT(MOTOR3_B); break;
-      case 4: latch_state &= -~BIT(MOTOR4_A) & ~BIT(MOTOR4_B); break;
-      default: return;
-   }
-
-   latch_tx();
-
-   printf("Latch=%08X\ ", latch_state);
-}
-
-void DCMotorRun(uint8_t motornum, uint8_t cmd)
-{
-   uint8_t a, b;
-
-   switch (motornum)
-   {
-      case 1: a = MOTOR1_A; b = MOTOR1_B; -break;
-      case 2: a = MOTOR2_A; b = MOTOR2_B; -break;
-      case 3: a = MOTOR3_A; b = MOTOR3_B; -break;
-      case 4: a = MOTOR4_A; b = MOTOR4_B; -break;
-      default: return;
-   }

-   switch (cmd)
-   {
-      case FORWARD:  latch_state -|=  BIT(a); latch_state &= ~BIT(b); break;
-      case BACKWARD: latch_state &= -~BIT(a); latch_state |=  BIT(b); break;
-      case RELEASE:  latch_state -&= ~BIT(a); latch_state &= ~BIT(b); break;
-      default: return;
-   }
-
-   latch_tx();
-
-   printf("Latch=%08X\ ", latch_state);
-}
-
-int main (int argc, char *argv[])
-{
-   int i;
-
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(MOTORLATCH,  PI_OUTPUT);
-   gpioSetMode(MOTORENABLE, PI_OUTPUT);
-   gpioSetMode(MOTORDATA,   PI_OUTPUT);
-   gpioSetMode(MOTORCLK,    -PI_OUTPUT);
-
-   gpioSetMode(MOTOR_3_PWM, PI_OUTPUT);
-   gpioSetMode(MOTOR_4_PWM, PI_OUTPUT);
-
-   gpioPWM(MOTOR_3_PWM, 0);
-   gpioPWM(MOTOR_4_PWM, 0);
-
-   init();
-
-   for (i=60; i<160; i+=20)
-   {
-      gpioPWM(MOTOR_3_PWM, i);
-      gpioPWM(MOTOR_4_PWM, 220-i);
-
-      DCMotorRun(3, FORWARD);
-      DCMotorRun(4, BACKWARD);
-
-      sleep(2);
-
-      DCMotorRun(3, RELEASE);
-      DCMotorRun(4, RELEASE);
-
-      sleep(2);
-
-      gpioPWM(MOTOR_4_PWM, i);
-      gpioPWM(MOTOR_3_PWM, 220-i);
-
-      DCMotorRun(3, BACKWARD);
-      DCMotorRun(4, FORWARD);
-
-      sleep(2);
-
-      DCMotorRun(3, RELEASE);
-      DCMotorRun(4, RELEASE);
-
-      sleep(2);
-   }
-
-   gpioPWM(MOTOR_4_PWM, 0);
-   gpioPWM(MOTOR_3_PWM, 0);
-
-   DCMotorRun(3, RELEASE);
-   DCMotorRun(4, RELEASE);
-
-   gpioTerminate();
-}
diff --git a/DOC/tmp/body/ex_rotary_encoder.body b/DOC/tmp/body/ex_rotary_encoder.body deleted file mode 100644 index f399e29..0000000 --- a/DOC/tmp/body/ex_rotary_encoder.body +++ /dev/null @@ -1,176 +0,0 @@ - -

The following code shows one way to read an incremental -mechanical rotary enoder (the sort used for volume control in audio -systems).  These rotary encoders have two switches A and B -which return a quadrature output, i.e. they are 90 degrees out of -phase.

-

SETUP

-fritzing diagramThe common -(centre) terminal should be connected to a Pi ground. -

The A and B terminals may be connected to any spare gpios.

-

Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7 -(P1-26).

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/*
-   Rotary encoder connections:
-
-   Encoder A      - gpio -18   (pin P1-12)
-   Encoder B      - gpio -7    (pin P1-26)
-   Encoder Common - Pi ground (pin P1-20)
-*/
-
-#define ENCODER_A 18
-#define ENCODER_B  7
-
-static volatile int encoderPos;
-
-/* forward declaration */
-
-void encoderPulse(int gpio, int lev, uint32_t tick);
-
-int main(int argc, char * argv[])
-{
-   int pos=0;
-
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(ENCODER_A, PI_INPUT);
-   gpioSetMode(ENCODER_B, PI_INPUT);
-
-   /* pull up is needed as encoder common is grounded -*/
-
-   gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);
-   gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);
-
-   encoderPos = pos;
-
-   /* monitor encoder level changes */
-
-   gpioSetAlertFunc(ENCODER_A, encoderPulse);
-   gpioSetAlertFunc(ENCODER_B, encoderPulse);
-
-   while (1)
-   {
-      if (pos != encoderPos)
-      {
-         pos = -encoderPos;
-         printf("pos=%d\ ", -pos);
-      }
-      gpioDelay(20000); /* check pos 50 -times per second */
-   }
-
-   gpioTerminate();
-}
-
-void encoderPulse(int gpio, int level, uint32_t tick)
-{
-   /*
-
-             -+---------+         -+---------+      0
-             -|         -|         -|         |
-   A         -|         -|         -|         |
-             -|         -|         -|         |
-   -+---------+         -+---------+         +----- -1
-
-       -+---------+         -+---------+            -0
-       -|         -|         -|         |
-   B   -|         -|         -|         |
-       -|         -|         -|         |
-   ----+         -+---------+         -+---------+  1
-
-   */
-
-   static int levA=0, levB=0, lastGpio = -1;
-
-   if (gpio == ENCODER_A) levA = level; else levB = -level;
-
-   if (gpio != lastGpio) /* debounce */
-   {
-      lastGpio = gpio;
-
-      if ((gpio == ENCODER_A) && -(level == 0))
-      {
-         if (!levB) -++encoderPos;
-      }
-      else if ((gpio == ENCODER_B) -&& (level == 1))
-      {
-         if (levA) ---encoderPos;
-      }
-   }
-}
-

BUILD

-cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt --lpthread
-

RUN

-sudo ./rotary_encoder
-

While the program is running you can capture the waveform using -the notification feature built in to pigpio.  Issue the -following commands on the Pi.

-pigs no
-pig2vcd  </dev/pigpio0 >re.vcd &
-pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18 -(0x40000)
-

Twiddle the rotary encoder forwards and backwards for a few -seconds.  Then enter

-pigs nc 0
-

The file re.vcd will contain the captured waveform, which can be -viewed using GTKWave.

-
-Overview
-
--"rotary
-
-Detail of switch bounce.  Contact A bounces for circa 700 us -before completing the level transition
-
--"rotary
diff --git a/DOC/tmp/body/ex_sonar_ranger.body b/DOC/tmp/body/ex_sonar_ranger.body deleted file mode 100644 index 8b3de67..0000000 --- a/DOC/tmp/body/ex_sonar_ranger.body +++ /dev/null @@ -1,155 +0,0 @@ - -

The following code shows a method of reading a class of sonar -rangers.  These rangers requires a trigger pulse.  -Shortly after receiving a trigger they transmit a noise pulse and -set the echo line high.  When the echo is received the echo -line is set low.

-

SETUP

-fritzing diagram
-
-
-
-
-The ranger used is a SRF05 (check the pinouts, there are many -variants).
-
-The fritzing diagram shows the back of the ranger, i.e. pin 1 is -the rightmost.
-
-Pin 1 is 5V.
-Pin 2 is the trigger line.
-Pin 3 is the echo line.
-Pin 4 is out (unused).
-Pin 5 is ground.
-
-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/*
-
-P1  Name  gpio    used for
-
- 2  5V    ---     -5V
- 6  GND   ---     -Ground
-24  CE0   8       -Sonar echo
-26  CE1   7       -Sonar trigger
-
-*/
-
-#define SONAR_TRIGGER 7
-#define SONAR_ECHO    8
-
-/* forward prototypes */
-
-void sonarTrigger(void);
-
-void sonarEcho(int gpio, int level, uint32_t tick);
-
-int main(int argc, char *argv[])
-{
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);
-   gpioWrite  (SONAR_TRIGGER, PI_OFF);
-
-   gpioSetMode(SONAR_ECHO,    -PI_INPUT);
-
-   /* update sonar 20 times a second, timer #0 */
-
-   gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms -*/
-
-   /* monitor sonar echos */
-
-   gpioSetAlertFunc(SONAR_ECHO, sonarEcho);
-
-   while (1) sleep(1);
-
-   gpioTerminate();
-
-   return 0;
-}
-
-void sonarTrigger(void)
-{
-   /* trigger a sonar reading */
-
-   gpioWrite(SONAR_TRIGGER, PI_ON);
-
-   gpioDelay(10); /* 10us trigger pulse */
-
-   gpioWrite(SONAR_TRIGGER, PI_OFF);
-}
-
-void sonarEcho(int gpio, int level, uint32_t tick)
-{
-   static uint32_t startTick, firstTick=0;
-
-   int diffTick;
-
-   if (!firstTick) firstTick = tick;
-
-   if (level == PI_ON)
-   {
-      startTick = tick;
-   }
-   else if (level == PI_OFF)
-   {
-      diffTick = tick - startTick;
-
-      printf("%u %u\ ", tick-firstTick, -diffTick);
-   }
-}
-

BUILD

-cc -o sonar sonar.c -lpigpio -lrt -lpthread
-

RUN

-sudo ./sonar >sonar.dat &
-
-While the program is running you can capture the waveform using the -notification feature built in to pigpio.  Issue the following -commands on the Pi.
-
-pigs no
-pig2vcd  </dev/pigpio0 >sonar.vcd &
-pigs nb 0 0x180 # set bits for gpios 7 and 8
-

Move an object in front of the sonar ranger for a few -seconds.

-pigs nc 0
-

The file sonar.vcd will contain the captured waveform, which can -be viewed using GTKWave.

-

Overview

-LDR waveform 1
-

Reading circa every 10ms

-Sonar waveform 2
-

One reading, circa 400us

-Sonar waveform 3
-

another

-Sonar waveform 4
-

The file sonar.dat will contain pairs of timestamps and echo -length (in us).  The following  script will convert the -timestamps into seconds.

-

awk '{print $1/1000000, $2}' sonar.dat ->sonar-secs.dat

-

Gnuplot is a useful tool to graph data.

-plot 'sonar-secs.dat' title 'Sonar'
-

gnuplot 1
- plot [10:25] 'sonar-secs.dat' title 'Sonar'

-

gnuplot 1

diff --git a/DOC/tmp/body/examples.body b/DOC/tmp/body/examples.body deleted file mode 100644 index 7df20a8..0000000 --- a/DOC/tmp/body/examples.body +++ /dev/null @@ -1,495 +0,0 @@ -The following examples show various ways pigpio may be used to communicate with sensors via the GPIO.
-
-Although many are complete programs they are intended to be a starting point in producing your own code, not an end point.
-
-Index

-Hardware

-Shell code

-C code

-C++ code

-pigpiod_if2 code

-Python code

-Miscellaneous related code

-External links

-

Hardware

-A few practical examples of using pigpio with hardware.
-
-
IR Receiver
2013-06-09
Reading an infrared remote receiver.
-
-
Light Dependent Resistor
2013-06-09
Measuring brightness with a light dependent resistor (LDR). Improved methods of timing the start of the capacitor recharge are given for C and Python.
-
-
Motor Shield
2013-12-15
Using an Arduino motor shield.
-
-
Rotary Encoder
2013-06-09
Reading a rotary encoder.
-
-
Sonar Ranger
2013-06-10
Measuring range with a sonar ranger.
-
-

Shell code

-Examples of using pigpio with shell code.
-
-
GPIO test
2014-08-11
This bash script tests the user GPIO. Video
-
-

C code

-Examples of C pigpio programs.
-
-If your program is called foobar.c then build with
-
-gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
-
-
Frequency Counter 1
2014-08-20
A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs).
-
-
Frequency Counter 2
2014-08-20
A program showing how to use the gpioSetGetSamplesFunc function to set a callback for accumulated GPIO state changes over the last millisecond. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). Generally the method used is more complicated but more efficient than frequency counter 1.
-
-
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
-
-
I2C Sniffer
2014-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results. This C program uses pigpio notifications.
-
-
IR Receiver
2015-02-25
Function to hash a code from an IR receiver (reading an IR remote control).
-
-
PCF8591 YL-40
2014-08-26
A program to display readings from the (I2C) PCF8591.
-
-
Pot + Capacitor Recharge Timing
2014-03-14
Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
-
-
Rotary Encoder
2015-10-03
Function to decode a mechanical rotary encoder.
-
-
SPI bit bang MCP3008
2016-03-20
This program shows how to read multiple MCP3008 ADC simultaneously with accurately timed intervals. One 10-bit channel of each ADC may be sampled at up to 25k samples per second.
-
-
SPI bit bang MCP3202
2016-03-20
This program shows how to read multiple MCP3202 ADC simultaneously with accurately timed intervals. One 12-bit channel of each ADC may be sampled at up to 25k samples per second.
-
-
SPI bit bang MCP3008 and MCP3202
2016-03-20
This program shows how to read multiple MCP3008 and MCP3202 ADC simultaneously with accurately timed intervals. One channel of each ADC may be sampled at up to 25k samples per second. The 10-bit MCP3008 readings are multiplied by 4 so they have the same range (0-4095) as the 12-bit MCP3202.
-
-
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-sudo ./servo_demo # Generate pulses on GPIO 4.
-
-sudo ./servo_demo 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
SPI pigpio driver speed test
2016-11-06
This C code is used to benchmark the pigpio SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
-
-
Wiegand Reader
2013-12-30
Function to read a Wiegand Reader.
-
-

C++ code

-Examples of C++ pigpio programs.
-
-If your program is called foobar.cpp then build with
-
-g++ -Wall -pthread -o foobar foobar.cpp -lpigpio -lrt
-
-
IR Receiver
2015-02-22
Class to hash a code from an IR receiver (reading an IR remote control).
-
-
Rotary Encoder
2013-12-30
Class to decode a mechanical rotary encoder.
-
-
Wiegand Reader
2013-12-30
Class to read a Wiegand Reader.
-
-

pigpiod_if2 code

The pigpiod_if2 code examples are linked with libpigpiod_if2 and are written in C.
-
-The pigpiod_if2 library may be compiled and run on any Linux machine and allows control of the GPIO on one or more networked Pis.
-
-It should be possible to adapt the library to run on Macs and PCs.
-
-Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
-
-
433MHz Keyfob RX/TX
2015-11-17
Code to read and transmit 313 and 434 MHz key fob codes. The codes to be read must use Manchester encoding. The transmitted codes use Manchester encoding.
-
-./_433D -r10 # Print fob keycodes received on GPIO 10.
-
-./_433D -t5 8246184 # Transmit code on GPIO 5.
-
-./_433D -r10 -t5 8246184 # Transmit code on GPIO 5 then listen for codes
-
-./_433D -? for options.
-
-
DHT11/21/22/33/44 Sensor
2016-02-16
Code to read the DHT temperature and humidity sensors. The sensor may be auto detected. A DHT11 sensor may be read once per second. The other sensors should not be read more often than once every three seconds.
-
-The code auto detects the DHT model and generally only the GPIO needs to be specified.
-
-./DHTXXD -g17 # Read a DHT connected to GPIO 17.
-
-./DHTXXD -g5 -i3 # Read a DHT connected to GPIO 5 every three seconds.
-
-./DHTXXD -? # for options.
-
-
Rotary Encoder
2015-11-18
Code to monitor a rotary encoder and show the position changes. By default the detent changes are shown. There is an option to show the four steps per detent instead.
-
-./RED -a7 -b8 -s30 # Show encoder on 7/8 detent changes for 30 seconds.
-
-./RED -a5 -b6 -m1 # Show encoder on 5/6 step changes forever.
-
-./RED -? # for options.
-
-
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-./servo_demo_D # Generate pulses on GPIO 4.
-
-./servo_demo_D 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
Sonar Ranger
2015-11-16
Code to read the SRF-04 and SRF-05 type of sonar rangers which use the trigger echo method of operation. A 10 μs trigger pulse initiates a series of high frequency sonar chirps. The echo line then goes high and stays high until an echo from an object is received. The echo high time is used to calculate the distance of the object.
-
-For a one-off reading only the trigger and echo GPIO need to be specified.
-
-./SRTED -t5 -e6 # Read a sonar ranger connected to GPIO 5/6.
-
-./SRTED -t11 -e5 -i0.1 # Read a sonar ranger connected to GPIO 11/5 every 0.1 seconds.
-
-./SRTED -? # for options.
-
-
Transmit Rotary Encoder Test Signals
2015-11-25
Code to transmit quadrature signals to test rotary encoder software.
-
-tx_RED -aGPIO -bGPIO [options]
-
-tx_RED -? for options
-
-E.g.
-
-tx_RED -a5 -b6 -s20 -r-100
-
-
Transmit Wiegand Test Signals
2015-11-25
Code to transmit Wiegand codes to test Wiegand decoder software.
-
-tx_WD -gGPIO -wGPIO [options] {code}+
-
-tx_WD -? for options
-
-E.g.
-
-tx_WD -g5 -w6 -s37 12345 67890 123 899999
-
-
Wiegand Reader
2015-11-25
Code to read a Wiegand Reader.
-
-./WD -g7 -w8 -s30 # Read Wiegand codes from GPIO 7/8 for 30 seconds.
-
-./WD -g5 -w6 # Read Wiegand codes from GPIO 5/6 forever.
-
-./WD -? # for options.
-
-

Python code

The Python code may be run on any Python machine and allows control of the GPIO on one or more networked Pis.
-
-The Python machine need not be a Pi, it may run Windows, Mac, Linux, anything as long as it supports Python.
-
-Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
-
-
433MHz Keyfob RX/TX
2015-10-30
Classes to send and receive 433MHz wireless keyfob codes. These keyfobs are widely used for remote control of devices.
-
-
7-Segment LED Display Multiplexing
2016-12-12
Script to multiplex several 7-segment LED displays. Each display has the segments a-g and the decimal point connected in parallel but has an individual enable GPIO (connected to the common anode or cathode).
-
-
APA102 LED strip driver
2017-03-28
Script to drive an APA102 LED strip. Three different methods are demonstrated - using spidev SPI (only works on the local Pi), pigpio SPI, and pigpio waves. The SPI solutions only work with the dedicated SPI GPIO. Waves may use any spare GPIO. Four different examples are given including a LED strip clock.
-
-
BME280 Sensor
2016-08-05
Class to read the relative humidity, temperature, and pressure from a BME280 sensor. The sensor has both an I2C and a SPI interface which are both
-supported by the class.
-
-
DHT11/21/22/33/44 Sensor
2019-11-07
Class to read the relative humidity and temperature from a DHT sensor. It can automatically recognize the sensor type.
-
-The default script prints the reading from the specified DHT every 2 seconds. E.g. ./DHT.py 22 27 displays the data for DHT connected to GPIO 22 and 27.
-
-The following data is printed for each DHT: timestamp, GPIO, status, temperature, and humidity.
-
-The timestamp is the number of seconds since the epoch (start of 1970).
-
-The status will be one of: 0 - a good reading, 1 - checksum failure, 2 - data had one or more invalid values, 3 - no response from sensor.
-
-
DHT22 AM2302 Sensor
2014-07-11
Class to read the relative humidity and temperature from a DHT22/AM2302 sensor.
-
-
DS18B20 Temperature Sensor
2016-06-29
Script to read the temperature from any DS18B20 sensors connected to the 1-wire bus.
-
-To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
-
-dtoverlay=w1-gpio
-
-By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
-
-Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
-
-This script uses the file features of pigpio to access the remote file system.
-
-The following entry must be in /opt/pigpio/access.
-
-/sys/bus/w1/devices/28*/w1_slave r
-
-
Dust Sensor
2015-11-22
Class to read a Shinyei PPD42NS Dust Sensor, e.g. as used in the Grove dust sensor.
-
-
GPIO Status
2014-06-12
Script to display the status of GPIO 0-31.
-
-
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
-
-
HX711 24-bit ADC
2018-03-05
Class to read the channels of a HX711 24-bit ADC.
-
-
I2C ADXL345 Accelerometer
2015-04-01
Script to display the X, Y, and Z values read from an ADXL345 accelerometer.
-
-
I2C HMC5883L Magnetometer
2015-04-01
Script to display the X, Y, and Z values read from a HMC5883L Magnetometer (compass).
-
-
I2C ITG3205 Gyroscope
2015-04-01
Script to display the X, Y, Z, and temperature values read from an ITG3205 gyroscope.
-
-
I2C LCD Display
2016-04-20
Class to display text on a LCD character display. The class supports the PCF8574T 8-bit I2C port expander connected to a HD44780 based LCD display. These displays are commonly available in 16x2 and 20x4 character formats.
-
-
I2C slave device
2016-10-31
This script demonstrates how to transfer messages from an Arduino acting as the I2C bus master to the Pi acting as an I2C slave device.
-
-
I2C Sniffer
2015-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results.
-
-
I2C Sonar
2016-03-24
A class to read up to 8 HC-SR04 sonar rangers connected to an MCP23017 port expander.
-
-
IR Receiver
2014-06-12
Class to hash a code from an IR receiver (reading an IR remote control).
-
-
IR Record and Playback
2015-12-21
This script may be used to record and play back arbitrary IR codes.
-
-To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given.
-
-E.g. ./irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0
-
-To playback the GPIO connected to the IR transmitter, the file containing the recorded codes, and the codes to be played back are given.
-
-E.g. ./irrp.py -p -g18 -fir-codes 2 3 4
-
-./irrp.py -h # for options
-
-
Kivy GPIO control
2016-12-11
This example shows how to use Kivy to control a Pi's GPIO. The GPIO may be configured as inputs, outputs, or to generate Servo or PWM pulses. Kivy is an Open source Python library for rapid development of applications.
-
-
MAX6675 SPI Temperature Sensor
2016-05-02
A script to read the temperature from a MAX6675 connected to a K-type thermocouple. The MAX6675 supports readings in the range 0 - 1023.75 C. Up to 4 readings may be made per second.
-
-
Monitor GPIO
2016-09-17
Script to monitor GPIO for level changes. By default all GPIO are monitored. At a level change the GPIO, new level, and microseconds since the last change is printed.
-
-
Morse Code
2015-06-17
Script to transmit the morse code corresponding to a text string.
-
-
NRF24 radio transceiver
2018-01-06
Script to transmit and receive messages using the nRF24L01 radio transceiver.
-
-
PCA9685 16 Channel PWM
2016-01-31
Class to control the 16 PWM channels of the I2C PCA9685. All channels use the same frequency. The duty cycle or pulse width may be set independently for each channel.
-
-
PCF8591 YL-40
2014-08-26
Script to display readings from the (I2C) PCF8591.
-
-
PPM (Pulse Position Modulation) generation
2016-02-19
Script to generate PPM signals on a chosen GPIO.
-
-
PPM (Pulse Position Modulation) to servo pulses
2019-10-09
Script to read a PPM signal on a GPIO and generate the corresponding servo signals on chosen GPIO.
-
-
pigpio Benchmark
2014-06-12
Script to benchmark the pigpio Python module's performance.
-
-
pigpio CGI
2015-05-04
Script demonstrating how to access the pigpio daemon using CGI from a browser. Instructions on how to use with Apache2 on the Pi are given in the comments.
-
-
Playback piscope recordings
2016-12-23
Script to playback GPIO data recorded in piscope format.
-
-To playback GPIO 4 to GPIO 4 from file data.piscope
-./playback.py data.piscope 4
-
-To playback GPIO 4 to GPIO 7 from file rec.txt
-./playback.py rec.txt 7=4
-
-
Pot + Capacitor Recharge Timing
2016-09-26
Class to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
-
-
PWM Monitor
2015-12-08
Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle.
-
-
Rotary Encoder
2014-06-12
Class to decode a mechanical rotary encoder.
-
-
RPM Monitor
2016-01-20
Class to monitor speedometer pulses and calculate the RPM (Revolutions Per Minute).
-
-
Si7021 I2C Temperature and Humidity Sensor
2016-05-07
Class to read the temperature and relative humidity from a Si7021.
-
-
SPI Monitor
2016-09-21
A program to passively sniff SPI transactions and display the results. The SPI rate should be limited to about 70kbps if using the default pigpio 5µs sampling rate.
-
-
Servo Pulse Generator
2016-10-07
This script generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-./servo_demo.py # Generate pulses on GPIO 4.
-
-./servo_demo.py 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
Sonar Ranger
2014-06-12
Class to read sonar rangers with separate trigger and echo pins.
-
-
TCS3200 Colour Sensor
2015-07-03
Class to read the TCS3200 colour sensor
-
-
Virtual Wire
2015-10-31
Class to send and receive radio messages compatible with the Virtual Wire library for Arduinos. This library is commonly used with 313MHz and 434MHz radio tranceivers.
-
-
Wave create
2019-11-18
Script to generate waves from a template defined in a text file.
-
-You can also specify one of py, c, or pdif - the script output will then be a complete program to generate the wave (py for Python script, c for a C program, pdif for a C program using the pigpio daemon I/F).
-
-If none of py, c, or pdif are chosen the waveform will be generated for 30 seconds.
-
-Example text file
-
-# GPIO levels
-23 11000001
-11 01110000
-12 00011100
-4 00000111
-
-To generate a pdif program with a bit time of 100 microseconds
-./create_wave.py wave_file 100 pdif >wave_pdif.c
-
-To just transmit the wave with a bit time of 50 microseconds
-./create_wave.py wave_file 50
-
-
Wave PWM 1
2016-03-19
Script to show how waves may be used to generate PWM at (one) arbitrary frequency on multiple GPIO. For instance PWM at 10kHz may be generated with 100 steps between off and fully on.
-
-
Wave PWM 2
2016-10-06
Class to generate PWM on multiple GPIO. It is more flexible than the Wave PWM 1 example in that the start of the pulse within each cycle may be specified as well as the duty cycle. The start and length of each pulse may be specified on a GPIO by GPIO basis in microseconds or as a fraction of the cycle time. The class includes a __main__ to demostrate its ability to send servo pulses.
-
-
Wiegand Reader
2014-06-12
Class to read a Wiegand reader.
-
-

Miscellaneous related code

-The following code examples do not use pigpio.
-
-
ADXL345
2014-03-12
This C program reads x, y, and z accelerations from the ADXL345 via I2C address 0x53.
-
-
DS18B20 Temperature Sensor
2016-04-25
This Python script reads the temperature from any DS18B20 sensors connected to the 1-wire bus.
-
-To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
-
-dtoverlay=w1-gpio
-
-By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
-
-Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
-
-
Easy as Pi Server
2014-09-15
This Python class implements a simple server which allows broswer commands to be executed on the Pi.
-
-
Minimal Clock Access
2015-05-20
This C code sets GPIO 4 to a specified clock frequency. The frequency can be set between 4.6875 kHz and 500 MHz (untested). The clock can be preferentially set from one of the sources OSC (19.2MHz), HDMI (216MHz), PLLD (500MHz), or PLLC (1000MHz). MASH can be set between 0 and 3. MASH may not work properly for clock dividers less than 5.
-
-
Minimal GPIO Access
2019-07-03
This C code has a minimal set of functions needed to control the GPIO and other Broadcom peripherals. The program requires root privileges to run. See Tiny GPIO access for an alternative which controls the GPIO (but not the other peripherals) and does not require root access.
-
-The code has been updated for the BCM2711 (Pi4B).
-
-The following functions are provided.
-
-gpioInitialise
-gpioSetMode
-gpioGetMode
-gpioSetPullUpDown
-gpioRead
-gpioWrite
-gpioTrigger
-gpioReadBank1
-gpioReadBank2
-gpioClearBank1
-gpioClearBank2
-gpioSetBank1
-gpioSetBank2
-gpioHardwareRevision
-gpioTick
-
-
Nanosecond Pulse Generation
2014-01-29
This C program uses the PWM peripheral to generate precisely timed pulses of very short duration. Pulses as short as 4 nano seconds can be generated.
-
-
PCF8591 YL-40
2014-08-26
C and Python code to read the (I2C) PCF8591.
-
-
SPI Linux driver speed test
2016-11-06
This C code is used to benchmark the Linux SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
-
-
Tiny GPIO Access
2016-04-30
This C code has a minimal set of functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO).
-
-You may need to change the permissions and ownership of /dev/gpiomem if they have not been correctly set up.
-
-sudo chown root:gpio /dev/gpiomem
-sudo chmod g+rw /dev/gpiomem
-
-The user (default pi) needs to be in the gpio group.
-
-sudo adduser pi gpio
-
-The following functions are provided.
-
-gpioInitialise
-gpioSetMode
-gpioGetMode
-gpioSetPullUpDown
-gpioRead
-gpioWrite
-gpioTrigger
-gpioReadBank1
-gpioReadBank2
-gpioClearBank1
-gpioClearBank2
-gpioSetBank1
-gpioSetBank2
-gpioHardwareRevision
-
-

External links

-Related code.
-
-
Stepper Motor
2016-08-12
Stepper motor code.
-
-
Parallax ActivityBot 360
2018-11-03
Python 3 implementation for programming a Parallax ActivityBot 360 Robot Kit with a Raspberry Pi.
-
-

Index

- -
433MHz Keyfob RX/TX pdif2 - Python -
7-Segment LED Display Multiplexing Python -
ADXL345 Misc -
APA102 LED strip driver Python -
BME280 Sensor Python -
DHT11/21/22/33/44 Sensor pdif2 - Python -
DHT22 AM2302 Sensor Python -
DS18B20 Temperature Sensor Python - Misc -
Dust Sensor Python -
Easy as Pi Server Misc -
Frequency Counter 1 C -
Frequency Counter 2 C -
GPIO Status Python -
GPIO test Shell -
Hall Effect Sensor C - Python -
HX711 24-bit ADC Python -
I2C ADXL345 Accelerometer Python -
I2C HMC5883L Magnetometer Python -
I2C ITG3205 Gyroscope Python -
I2C LCD Display Python -
I2C slave device Python -
I2C Sniffer C - Python -
I2C Sonar Python -
IR Receiver Hardware - C - C++ - Python -
IR Record and Playback Python -
Kivy GPIO control Python -
Light Dependent Resistor Hardware -
MAX6675 SPI Temperature Sensor Python -
Minimal Clock Access Misc -
Minimal GPIO Access Misc -
Monitor GPIO Python -
Morse Code Python -
Motor Shield Hardware -
Nanosecond Pulse Generation Misc -
NRF24 radio transceiver Python -
Parallax ActivityBot 360 External -
PCA9685 16 Channel PWM Python -
PCF8591 YL-40 C - Python - Misc -
pigpio Benchmark Python -
pigpio CGI Python -
Playback piscope recordings Python -
Pot + Capacitor Recharge Timing C - Python -
PPM (Pulse Position Modulation) generation Python -
PPM (Pulse Position Modulation) to servo pulses Python -
PWM Monitor Python -
Rotary Encoder Hardware - C - C++ - pdif2 - Python -
RPM Monitor Python -
Servo Pulse Generator C - pdif2 - Python -
Si7021 I2C Temperature and Humidity Sensor Python -
Sonar Ranger Hardware - pdif2 - Python -
SPI bit bang MCP3008 C -
SPI bit bang MCP3008 and MCP3202 C -
SPI bit bang MCP3202 C -
SPI Linux driver speed test Misc -
SPI Monitor Python -
SPI pigpio driver speed test C -
Stepper Motor External -
TCS3200 Colour Sensor Python -
Tiny GPIO Access Misc -
Transmit Rotary Encoder Test Signals pdif2 -
Transmit Wiegand Test Signals pdif2 -
Virtual Wire Python -
Wave create Python -
Wave PWM 1 Python -
Wave PWM 2 Python -
Wiegand Reader C - C++ - pdif2 - Python -
\ No newline at end of file diff --git a/DOC/tmp/body/faq.body b/DOC/tmp/body/faq.body deleted file mode 100644 index 7c505f0..0000000 --- a/DOC/tmp/body/faq.body +++ /dev/null @@ -1,452 +0,0 @@ - -Are my GPIO broken?
-
-Audio is broken
-
-Can´t initialise pigpio -library
-
-Can´t lock -var/run/pigpio.pid
-
-Hello World!
-
-Clock skew, make fails
-
-Have I fried my GPIO?
-
-How do I debounce -inputs?
-
-How fast is SPI?
-
-Library update didn't work
-
-make fails with clock skew
-
-Porting pigpio to another CPU/SoC
-
-Sound isn't working
-
-Symbol not found
-
-What is I2C?
-
-What is Serial?
-
-What is SPI?
-
-Which library should I use?
-
-

Are my -GPIO broken?

-

See Have I fried my -GPIO?

-

Audio is -broken

-

See Sound isn't -working

-

Can´t lock -/var/run/pigpio.pid

-

See Can´t_initialise_pigpio_library
-

-

Can´t initialise pigpio -library

-

This message means the pigpio daemon is already running.

-

The default daemon is called pigpiod and may be removed as -follows.

-Check that it is running with the command -

ps aux | grep pigpiod

-

Kill the daemon with

-

sudo killall pigpiod

-

If your own program is acting as the daemon it may be removed as -follows.

-

Find its process id (pid).

-

cat /var/run/pigpio.pid

-

Kill the program with

-

sudo kill -9 pid

-If the above doesn't work do the following and try starting the -daemon again -

sudo rm /var/run/pigpio.pid

-

To start the daemon do

-

sudo pigpiod

-

Have I fried my GPIO?

-

If you think you have damaged one or more GPIO you can carry out -a diagnostic test.

-

The test is a command line script called gpiotest

-For the duration of the test nothing must be connected to the GPIO -(no LEDs, wires, ribbon cables etc.). -

The test checks that each GPIO may be read and written and that -the internal resistor pull-ups and pull-downs are functional.

-

A video -showing what happens to the GPIO during a test.

-

A test with all GPIO okay.

-
This program checks the Pi's (user) gpios.
-
-The program reads and writes all the gpios.  Make sure NOTHING
-is connected to the gpios during this test.
-
-The program uses the pigpio daemon which must be running.
-
-To start the daemon use the command sudo pigpiod.
-
-Press the ENTER key to continue or ctrl-C to abort...
-
-Testing...
-Skipped non-user gpios: 0 1 28 29 30 31 
-Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 -Failed user gpios: None -
-

A test showing failed GPIO.

-
This program checks the Pi's (user) gpios.
-
-The program reads and writes all the gpios. Make sure NOTHING
-is connected to the gpios during this test.
-
-The program uses the pigpio daemon which must be running.
-
-To start the daemon use the command sudo pigpiod.
-
-Press the ENTER key to continue or ctrl-C to abort...
-
-Testing...
-Write 1 to gpio 17 failed.
-Pull up on gpio 17 failed.
-Write 1 to gpio 18 failed.
-Pull up on gpio 18 failed.
-Write 0 to gpio 23 failed.
-Pull down on gpio 23 failed.
-Write 0 to gpio 24 failed.
-Pull down on gpio 24 failed.
-Write 1 to gpio 27 failed.
-Pull up on gpio 27 failed.
-Skipped non-user gpios: 0 1 28 29 30 31
-Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 -Failed user gpios: 17 18 23 24 27 -
-

How do I debounce inputs?

-

Some devices like mechanical switches can generate multiple -interrupts as they bounce between on and off.  It is possible -to debounce the inputs in hardware by the correct use of resistors -and capacitors.

-

In software use the glitch filter which ignores all events -shorter than a set number of microseconds.  C gpioGlitchFilter, Python set_glitch_filter.

-

How fast is -SPI?

-The SPI throughput in samples per second depends on a number of -factors.
-
-
    -
  • The SPI bit rate (transfer rate in bits per second)
  • -
-
    -
  • The number of bytes transferred per sample (a 12 bit ADC sample -may require 3 bytes to transfer)
  • -
-
    -
  • The driver used
  • -
-

Two of those factors are fixed, the variable is the driver -used.

-

The pigpio driver is considerably faster than the Linux SPI -driver as is demonstrated by the following graphs.

-

Each graph shows the SPI bit rate in bits per second along the -horizontal axis.  The samples per second achieved is shown on -the vertical axis.  Each graph contains plots assuming 1 to 5 -bytes per transfer.

-

The source code used for the tests is spi-driver-speed.c and spi-pigpio-speed.c

-

spi-lnx-pibr1.png

-
-

spi-pig-pibr1.png

-
-

spi-lnx-pi3b.png

-
-

spi-pig-pi3b.png

-

Library update didn't work

-

pigpio places files in the following locations

-

/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
-/usr/local/lib (libpigpio.so, libpigpiod_if.so, -libpigpiod_if2.so)
-/usr/local/bin (pig2vcd, pigpiod, pigs)
-/usr/local/man (man pages)

-The raspberrypi.org image containing pigpio uses different -locations.
-

/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
-/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)
-/usr/bin (pig2vcd, pigpiod, pigs)
-/usr/man (man pages)

-

Mostly this doesn't matter as the /usr/local directories will -generally be earlier in the search path.  The pigpio built -includes, binaries, and manuals are normally found first.

-

However the wrong libraries may be linked during the -compilation.  If this is the case remove the /usr/lib entries -for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so

-

Hello World!

-

The following examples show how to use the various components of -the pigpio library.

-

Each example shows how to read the level of a GPIO.

-

C

-read_cif.c -
-#include <stdio.h>
-#include <pigpio.h>
-
-int main(int argc, char *argv[])
-{
-   int GPIO=4;
-   int level;
-
-   if (gpioInitialise() < 0) return 1;
-
-   level = gpioRead(GPIO);
-
-   printf("GPIO %d is %d\n", GPIO, level);
-
-   gpioTerminate();
-}
-    
-

Build

-gcc -pthread -o read_cif read_cif.c -lpigpio -

Run

-sudo ./read_cif -

C via pigpio daemon

-read_pdif.c -
-#include <stdio.h>
-#include <pigpiod_if2.h>
-
-int main(int argc, char *argv[])
-{
-   int pi;
-   int GPIO=4;
-   int level;
-
-   pi = pigpio_start(0, 0); /* Connect to local Pi. */
-
-   if (pi < 0)
-   {
-      printf("Can't connect to pigpio daemon\n");
-      return 1;
-   }
-
-   level = gpio_read(pi, GPIO);
-
-   printf("GPIO %d is %d\n", GPIO, level);
-
-   pigpio_stop(pi); /* Disconnect from local Pi. */
-   
-   return 0;
-}
-
-

Build

-gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2 -

Run

-./read_pdif -

Python

-read_gpio.py -
-#!/usr/bin/env python
-
-import pigpio
-
-GPIO=4
-
-pi = pigpio.pi()
-if not pi.connected:
-   exit()
-
-level = pi.read(GPIO)
-
-print("GPIO {} is {}".format(GPIO, level))
-
-pi.stop()
-    
-

Run

-python read_gpio.py -

pigs

-
-pigs r 4
-    
-

pipe I/F

-
-echo "r 4" >/dev/pigpio
-cat /dev/pigout
-    
-

make fails with clock -skew

-

If make fails with one of the following messages it is probably -because the Pi's clock is wrong.

-

make: Warning: File 'xxx' has modification time x s in the -future
-make: warning: Clock skew detected. Your build may be -incomplete.

-

make uses the current time to work out which files need to be -rebuilt (a file is rebuilt if it depends on other files which have -a later time-stamp).

-

The solution is to make sure the system clock is correct.  -If the Pi is networked this will not normally be a problem.

-

To set the date and time use the date command as in the -following example.

-

sudo date -d "2017-03-01 18:47:00"

-

Porting pigpio -to another CPU/SoC

-

Sound -isn't working

-

The Pi contains two pieces of hardware, a PWM peripheral and a -PCM peripheral, to generate sound.  The PWM peripheral is -normally used and generates medium quality audio out of the -headphone jack.  The PCM peripheral may be used by add-ons -such as HATs and generates high quality audio.

-

pigpio uses at least one of these peripherals during normal -operation (for timing DMA transfers).  pigpio will use both -peripherals if waves or the hardware PWM function is used.

-

By default pigpio uses the PCM peripheral leaving the PWM -peripheral free for medium quality audio.

-

You can change the default with a configuration option.  -For C use gpioCfgClock, for the -pigpio daemon use the -t option.

-

What is I2C?

-

I2C is a data link between the Pi (master) and one or more -slaves.

-

Data may be sent and received but the Pi initiates all -transfers.

-

I2C is a medium speed link.  On the Pi the default speed is -100 kbps, but 400 kbps also works.

-

I2C is implemented as a bus with two lines called

-
    -
  • SDA - for data
  • -
  • SCL - for a clock
  • -
-On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO -3 (pin 5) for SCL.
-
-Only one slave device may be communicated with at a time.  -Each message from the Pi includes the slave to be addressed and -whether a read or write is to be performed.
-
-When the Pi (master) wishes to talk to a slave it begins by issuing -a start sequence on the I2C bus. A start sequence is one of two -special sequences defined for the I2C bus, the other being the stop -sequence. The start sequence and stop sequence are special in that -these are the only places where the SDA (data line) is allowed to -change while the SCL (clock line) is high. When data is being -transferred, SDA must remain stable and not change whilst SCL is -high. The start and stop sequences mark the beginning and end of a -transaction with the slave device.
-
-I2C start and stop sequences
-
-Data is transferred in 8-bit bytes. The bytes are placed on the SDA -line starting with the most significant bit. The SCL line is then -pulsed high, then low. For every byte transferred, the device -receiving the data sends back an acknowledge bit, so there are -actually 9 SCL clock pulses to transfer each 8-bit byte of data. If -the receiving device sends back a low ACK bit, then it has received -the data and is ready to accept another byte. If it sends back a -high then it is indicating it cannot accept any further data and -the master should terminate the transfer by sending a stop -sequence.
-
-

I2C waveform

-

What is -Serial?

-

Serial is a data link between the Pi and one other -device.

-

Data may be sent and received.  Either the Pi or the device -can initiate a transfer.

-

Serial is a low to medium speed link.  On the Pi speeds of -50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, -19200, 38400, 57600, 115200, and 230400 bps may be used.

-

Serial is implemented with one line for transmit called TXD and -one line for receive called RXD.

-

If only receive or transmit are required the other line need not -be connected.

-

The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for -RXD.

-

Data is normally transmitted in 8-bit bytes with a start bit, -eight data bits, no parity, and one stop bit.  This is -represented as 8N1.  The number of transmitted bits per second -(bps) is called the baud rate.   The time for each bit, -1 / baud rate seconds, is -referred to as the bit period.

-

The lines are in the high state when no data is being -transmitted.  The start of a byte is signalled by the line -going low for one bit period (the start bit).  The data bits -are then sent least significant bit firsts (low if the bit is 0, -high if the bit is 1).  The data bits are followed by the -optional parity bit.  Finally the line is set high for at -least the number of stop bit periods.  The line will stay high -if there are no more bytes to be transmitted.

-

Serial waveform

-

What is SPI?

-

SPI is a data link between the Pi (master) and one or more -slaves.

-

Data may be sent and received but the Pi initiates all -transfers.

-

SPI is a medium to high speed link.  On the Pi speeds of 32 -kbps to 8 Mbps may be used.

-

SPI is implemented as a bus with three lines called

-
    -
  • MOSI - for data from the Pi to the slave
  • -
  • MISO - for data from the slave to the Pi
  • -
  • SCLK - for a clock
  • -
-Only one slave device may be communicated with at a time.  An -additional line per slave called slave select is used to identify -the slave to be addressed. -

The Pi has two SPI buses

-
    -
  1. the main SPI bus -
      -
    • MOSI GPIO 10 (pin 19)
    • -
    • MISO GPIO 9 (pin 21)
    • -
    • SCLK GPIO 11 (pin 23)
    • -
    • Slave selects
    • -
    • -
        -
      • CE0 GPIO 8 (pin 24)
      • -
      • CE1 GPIO 7 (pin 26)
      • -
      -
    • -
    -
  2. -
  3. the auxiliary SPI bus -
      -
    • MOSI GPIO 20 (pin 38)
    • -
    • MISO GPIO 19 (pin 35)
    • -
    • SCLK GPIO 21 (pin 40)
    • -
    • Slave selects
    • -
    • -
        -
      • CE0 GPIO 18 (pin 12)
      • -
      • CE1 GPIO 17 (pin 11)
      • -
      • CE2 GPIO 16 (pin 36)
      • -
      -
    • -
    -
  4. -
-

SPI waveform

-


-

Which library -should I use?

-


diff --git a/DOC/tmp/body/index.body b/DOC/tmp/body/index.body deleted file mode 100644 index f8a4d2e..0000000 --- a/DOC/tmp/body/index.body +++ /dev/null @@ -1,652 +0,0 @@ - -pigpio is a library for the Raspberry which allows control of the -General Purpose Input Outputs (GPIO).  pigpio works on all -versions of the Pi. -

At the moment pigpio on the Pi4B is experimental. I am not -sure if the DMA channels being used are safe. The Pi4B defaults are -primary channel 7, secondary channel 6. If these channels do not -work you will have to experiment. You can set the channels used by -the pigpio daemon by invoking it with the -d and -e options, e.g. -sudo pigpiod -d 5 -e 8 to specify primary 5, -secondary 8.

-

Download

-

Features

-
    -
  • -

    hardware timed sampling and time-stamping of GPIO 0-31 every 5 -us

    -
  • -
  • -

    hardware timed PWM on all of GPIO 0-31

    -
  • -
  • -

    hardware timed servo pulses on all of GPIO 0-31

    -
  • -
  • -

    callbacks on GPIO 0-31 level change (time accurate to a few -us)

    -
  • -
  • -

    notifications via pipe on GPIO 0-31 level change

    -
  • -
  • -

    callbacks at timed intervals

    -
  • -
  • -

    reading/writing all of the GPIO in a bank (0-31, 32-53) as a -single operation

    -
  • -
  • -

    GPIO reading, writing, modes, and internal pulls

    -
  • -
  • -

    socket and pipe interfaces for the bulk of the functionality

    -
  • -
  • -

    waveforms to generate GPIO level changes (time accurate to a few -us)

    -
  • -
  • -

    software serial links using any user GPIO

    -
  • -
  • -

    rudimentary permission control through the socket and pipe -interfaces

    -
  • -
  • creating and running scripts on the pigpio daemon
  • -
-

General

-The pigpio library is written in the C -programming language.
-
-The pigpio daemon offers a socket and pipe interface to -the underlying C library.
-
-A C library and a Python module allow control of the GPIO via the -pigpio daemon.
-
-There is third party support for a number of other languages.  -

piscope

-

piscope is a logic analyser (digital -waveform viewer).

-piscope is a GTK+3 application and uses pigpio to provide raw GPIO -level data.  piscope may be run on a Pi or on any machine -capable of compiling a GTK+3 application. -

GPIO

-

ALL GPIO are identified -by their Broadcom -number.  See -elinux.org

-There are 54 GPIO in total, arranged in two banks.
-

Bank 1 contains GPIO 0-31.  Bank 2 contains GPIO -32-53.

-For all types of Pi it is safe to read all the GPIO. If you try to -write a system GPIO or change its mode you can crash the Pi or -corrupt the data on the SD card.
-
-There are several types of board, each with different expansion -headers, giving physical access to different GPIO.  - -

Type 1 - Model B (original -model)

-
    -
  • 26 pin header (P1).
  • -
-
    -
  • Hardware revision numbers of 2 and 3.
  • -
-
    -
  • User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA0
34-5V
SCL1
56-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

211314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
-
-

Type 2 - Model A, B (revision -2)

-26 pin header (P1) and an additional 8 pin header (P5). -
    -
  • Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13, -14, 15 (B).
  • -
-
    -
  • User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
5V
-12-3V3
SDA
283429SCL

305631
Ground
-
78-
Ground
-
-

Type 3 - Model A+, B+, Pi -Zero, Pi Zero W, Pi2B, Pi3B, Pi4B

-
    -
  • 40 pin expansion header (J8).
  • -
-
    -
  • Hardware revision numbers of 16 or greater.
  • -
-
    -
  • User GPIO 2-27 (0 and 1 are reserved).
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
ID_SD027281ID_SC

52930-Ground

6313212

133334-Ground
miso19353616ce2

26373820mosi
Ground-394021sclk
-
-

Compute Module

-

All 54 GPIO may be physically accessed.  Some are reserved -for system use - refer to the Compute Module documentation.

-

Only GPIO 0-31 are supported for hardware timed sampling, PWM, -servo pulses, alert callbacks, waves, and software serial -links.

-

Other -Languages

-

There are several third party projects which provide wrappers -for pigpio.

-

Some I am aware of are:

-
    -
  • Erlang -(skvamme)
  • -
  • Java JNI -wrapper around the pigpio C library (mattlewis)
  • -
  • Java via -diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc -(mattlewis)
  • -
  • Java -(nkolban)
  • -
  • .NET/mono -(unosquare)
  • -
  • Node.js -(fivdi)
  • -
  • Perl (Gligan -Calin Horea)
  • -
  • Ruby -(Nak)
  • -
  • Smalltalk(Instantiations)
  • -
  • Xojo(UBogun)
  • -
-
-

The PWM and servo pulses are timed using the DMA -and PWM/PCM peripherals.  This use was inspired by Richard -Hirst's servoblaster kernel module.

diff --git a/DOC/tmp/body/misc.body b/DOC/tmp/body/misc.body deleted file mode 100644 index 8bb3552..0000000 --- a/DOC/tmp/body/misc.body +++ /dev/null @@ -1,24 +0,0 @@ - -There are two C libraries which provide a socket interface to the -pigpio daemon.  They provide an interface very similar to the -pigpio Python module.
-
    -
  • The original pigpiod_if library is -now deprecated and will no longer be updated.  This library is -limited to controlling one Pi at a time.
  • -
-
    -
  • The new pigpiod_if2 library which -should be used for new code.  This library allows multiple Pis -to be controlled at one time.
  • -
-Additional details of the pigpio socket -interface.
-
-Additional details of the pigpio pipe -interface.
-
-pig2vcd is a utility which converts -pigpio notifications into the VCD (Value Change Dump) format.  -VCD can be read by many programs, in particular GTKWave. diff --git a/DOC/tmp/body/pdif.body b/DOC/tmp/body/pdif.body deleted file mode 100644 index 238e3f7..0000000 --- a/DOC/tmp/body/pdif.body +++ /dev/null @@ -1,1105 +0,0 @@ -

THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO -USE THE MORE VERSATILE pigpiod_if2 LIBRARY. -

pigpiod_if is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon.
-

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. -

Usage

Include <pigpiod_if.h> in your source files. -

Assuming your source is in prog.c use the following command to build -

gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt


to run make sure the pigpio daemon is running -

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if


For examples see x_pigpiod_if.c within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error -

OVERVIEW

ESSENTIAL -
pigpio_start Connects to the pigpio daemon -
pigpio_stop Disconnects from the pigpio daemon -
BEGINNER -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
gpio_read Read a GPIO -
gpio_write Write a GPIO -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -
set_servo_pulsewidth Start/stop servo pulses on a GPIO -
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -
callback Create GPIO level change callback -
callback_ex Create GPIO level change callback -
callback_cancel Cancel a callback -
wait_for_edge Wait for GPIO level change -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO. -
set_watchdog Set a watchdog on a GPIO. -
set_PWM_range Configure PWM range for a GPIO -
get_PWM_range Get configured PWM range for a GPIO -
set_PWM_frequency Configure PWM frequency for a GPIO -
get_PWM_frequency Get configured PWM frequency for a GPIO -
read_bank_1 Read all GPIO in bank 1 -
read_bank_2 Read all GPIO in bank 2 -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
start_thread Start a new thread -
stop_thread Stop a previously started thread -
ADVANCED -
get_PWM_real_range Get underlying PWM range for a GPIO -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
bb_serial_read_open Opens a GPIO for bit bang serial reads -
bb_serial_read Reads bit bang serial data from a GPIO -
bb_serial_read_close Closes a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
SCRIPTS -
store_script Store a script -
run_script Run a stored script -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_delete Deletes one or more waveforms -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_chain Transmits a chain of waveforms -
wave_tx_busy Checks to see if the waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_micros Length in microseconds of the current waveform -
wave_get_high_micros Length of longest waveform so far -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_high_pulses Length of longest waveform so far -
wave_get_max_pulses Absolute maximum allowed pulses -
wave_get_cbs Length in cbs of the current waveform -
wave_get_high_cbs Length of longest waveform so far -
wave_get_max_cbs Absolute maximum allowed cbs -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick smbus write quick -
i2c_write_byte smbus write byte -
i2c_read_byte smbus read byte -
i2c_write_byte_data smbus write byte data -
i2c_write_word_data smbus write word data -
i2c_read_byte_data smbus read byte data -
i2c_read_word_data smbus read word data -
i2c_process_call smbus process call -
i2c_write_block_data smbus write block data -
i2c_read_block_data smbus read block data -
i2c_block_process_call smbus block process call -
i2c_write_i2c_block_data smbus write I2C block data -
i2c_read_i2c_block_data smbus read I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_zip Performs multiple I2C transactions -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs multiple bit banged I2C transactions -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write Writes bytes to a serial device -
serial_read Reads bytes from a serial device -
serial_data_available Returns number of bytes ready to be read -
CUSTOM -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpiod_if_version Get the pigpiod_if version -
pigpio_error Get a text description of an error code. -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -

FUNCTIONS

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds. -

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

-Return a text description for an error code. -

errnum: the error code.

unsigned pigpiod_if_version(void)

-Return the pigpiod_if version. -

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

-Starts a new thread of execution with thread_func as the main routine. -

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument userdata. -

The thread can be cancelled by passing the pointer to pthread_t to -stop_thread. -

void stop_thread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: the thread to be stopped.


No value is returned. -

The thread to be stopped should have been started with start_thread. -

int pigpio_start(char *addrStr, char *portStr)

-Connect to the pigpio daemon. Reserving command and -notification streams. -

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.

void pigpio_stop(void)

-Terminates the connection to the pigpio daemon and releases -resources used by the library. -

int set_mode(unsigned gpio, unsigned mode)

-Set the GPIO mode. -

gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. -

int get_mode(unsigned gpio)

-Get the GPIO mode. -

gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

int set_pull_up_down(unsigned gpio, unsigned pud)

-Set or clear the GPIO pull-up/down resistor. -

gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. -

int gpio_read(unsigned gpio)

-Read the GPIO level. -

gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

int gpio_write(unsigned gpio, unsigned level)

-Write the GPIO level. -

 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. -

Notes -

If PWM or servo pulses are active on the GPIO they are switched off. -

int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)

-Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. -

user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes -

The set_PWM_range function may be used to change the -default range of 255. -

int get_PWM_dutycycle(unsigned user_gpio)

-Return the PWM dutycycle in use on a GPIO. -

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

int set_PWM_range(unsigned user_gpio, unsigned range)

-Set the range of PWM values to be used on the GPIO. -

user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. -

Notes -

If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. -

The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is -

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


The real value set by set_PWM_range is (dutycycle * real range) / range. -

int get_PWM_range(unsigned user_gpio)

-Get the range of PWM values being used on the GPIO. -

user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). -

int get_PWM_real_range(unsigned user_gpio)

-Get the real underlying range of PWM values being used on the GPIO. -

user_gpio: 0-31.


Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

int set_PWM_frequency(unsigned user_gpio, unsigned frequency)

-Set the frequency (in Hz) of the PWM to be used on the GPIO. -

user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(unsigned user_gpio)

-Get the frequency of PWM being used on the GPIO. -

user_gpio: 0-31.


For normal PWM the frequency will be that defined for the GPIO by -set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)

-Start (500-2500) or stop (0) servo pulses on the GPIO. -

 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. -

The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its limits. -

OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. -

Then set the PWM range using set_PWM_range to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO 25 at 400Hz -

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-

int get_servo_pulsewidth(unsigned user_gpio)

-Return the servo pulsewidth in use on a GPIO. -

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int notify_open(void)

-Get a free notification handle. -

Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by callback -should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

int notify_begin(unsigned handle, uint32_t bits)

-Start notifications on a previously opened handle. -

handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

Each notification occupies 12 bytes in the fifo as follows: -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. -

PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

int notify_pause(unsigned handle)

-Pause notifications on a previously opened handle. -

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until -notify_begin is called again. -

int notify_close(unsigned handle)

-Stop notifications on a previously opened handle and -release the handle for reuse. -

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int set_watchdog(unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. -

The callback will receive the special level PI_TIMEOUT. -

int set_glitch_filter(unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

uint32_t read_bank_1(void)

-Read the levels of the bank 1 GPIO (GPIO 0-31). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<n). -

uint32_t read_bank_2(void)

-Read the levels of the bank 2 GPIO (GPIO 32-53). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). -

int clear_bank_1(uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int clear_bank_2(uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_1(uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_2(uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int hardware_clock(unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

     gpio: see description
frequency: 0 (off) or 4689-250000000 (250M)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int hardware_PWM(unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_once, wave_send_repeat, -or wave_chain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

   gpio: see descripton
PWMfreq: 0 (off) or 1-125000000 (125M)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only

uint32_t get_current_tick(void)

-Gets 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. -

uint32_t get_hardware_revision(void)

-Get the Pi's hardware revision number. -

The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

uint32_t get_pigpio_version(void)

-Returns the pigpio version. -

int wave_clear(void)

-This function clears all waveforms and any data added by calls to the -wave_add_* functions. -

Returns 0 if OK. -

int wave_add_new(void)

-This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the wave_create function. -

Returns 0 if OK. -

int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. -

int wave_add_serial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, -and stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int wave_create(void)

-This function creates a waveform from the data provided by the prior -calls to the wave_add_* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the wave_add_* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_delete(unsigned wave_id)

-This function deletes the waveform with id wave_id. -

wave_id: >=0, as returned by wave_create.


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int wave_send_once(unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -is sent once. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_repeat(unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by wave_tx_stop). -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_chain(char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (pigpio_start(0, 0)<0) return -1;

   set_mode(GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create();
   }

   wave_chain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(wid[i]);

   pigpio_stop();
}

int wave_tx_busy(void)

-This function checks to see if a waveform is currently being -transmitted. -

Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int wave_tx_stop(void)

-This function stops the transmission of the current waveform. -

Returns 0 if OK. -

This function is intended to stop a waveform started with the repeat mode. -

int wave_get_micros(void)

-This function returns the length in microseconds of the current -waveform. -

int wave_get_high_micros(void)

-This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. -

int wave_get_max_micros(void)

-This function returns the maximum possible size of a waveform in
-microseconds. -

int wave_get_pulses(void)

-This function returns the length in pulses of the current waveform. -

int wave_get_high_pulses(void)

-This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. -

int wave_get_max_pulses(void)

-This function returns the maximum possible size of a waveform in pulses. -

int wave_get_cbs(void)

-This function returns the length in DMA control blocks of the current -waveform. -

int wave_get_high_cbs(void)

-This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. -

int wave_get_max_cbs(void)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

int gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. -

int store_script(char *script)

-This function stores a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

script: the text of the script.


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int run_script(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int script_status(unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. -

script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int stop_script(unsigned script_id)

-This function stops a running script. -

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int delete_script(unsigned script_id)

-This function deletes a stored script. -

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the bb_serial_read_open command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int bb_serial_read_close(unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int bb_serial_invert(unsigned user_gpio, unsigned invert)

-This function inverts serial logic for big bang serial reads. -

user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. -

int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

-This returns a handle for the device at address i2c_addr on bus i2c_bus. -

  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.

Addr  (7 bits): I2C 7 bit address.
Comm  (8 bits): Command byte, a data byte which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A data byte containing the length of a block operation.

[..]: Data sent by the device.

int i2c_close(unsigned handle)

-This closes the I2C device associated with the handle. -

handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2c_write_quick(unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr Rd/Wr [A] P

int i2c_write_byte(unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] Data [A] P

int i2c_read_byte(unsigned handle)

-This reads a single byte from the device associated with handle. -

handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] Comm [A] Data [A] P

int i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P

int i2c_read_byte_data(unsigned handle, unsigned i2c_reg)

-This reads a single byte from the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(unsigned handle, unsigned i2c_reg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

int i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] Comm [A] Count [A] Data [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

int i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_device(unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

int i2c_write_device(unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

int i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bb_i2c_close(unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bb_i2c_open. -

SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per word.
-For bits 9-16 there will be two bytes per word.
-For bits 17-32 there will be four bytes per word. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spi_close(unsigned handle)

-This functions closes the SPI device identified by the handle. -

handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spi_read(unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_write(unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)

-This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. -

  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serial_close(unsigned handle)

-This function closes the serial device associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serial_write_byte(unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read_byte(unsigned handle)

-This function reads a byte from the serial port associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serial_write(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read(unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. -

If no data is ready zero is returned. -

int serial_data_available(unsigned handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from custom_1 in that it returns an array of bytes -rather than just an integer. -

The return value is an integer indicating the number of returned bytes. -  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

Note, the number of returned bytes will be retMax or less. -

int callback(unsigned user_gpio, unsigned edge, CBFunc_t f)

-This function initialises a new callback. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

int callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

-This function initialises a new callback. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, tick, and user, whenever -the GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

-This function cancels a callback identified by its id. -

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)

-This function waits for edge on the GPIO for up to timeout -seconds. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns 1 if the edge occurred, otherwise 0. -

The function returns when the edge occurs or after the timeout. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

*addrStr

-A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

callback_id

-A >=0, as returned by a call to callback or callback_ex. This is -passed to callback_cancel to cancel the callback. -

CBFunc_t

-typedef void (*CBFunc_t)
   (unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

-typedef void (*CBFuncEx_t)
   (unsigned user_gpio, unsigned level, uint32_t tick, void * user);

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250000000 (250M)

-The hardware clock frequency. -

count

-The number of bytes to be transferred in an I2C, SPI, or Serial -command. -

data_bits: 1-32

-The number of data bits in each character of serial data. -

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge

-Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. -

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

-A negative number indicating a function call failed and the nature -of the error. -

f

-A function. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 get_hardware_revision. -

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  -  -  -  -

gpioPulse_t

-typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

-A number referencing an object opened by one of i2c_open, notify_open, -serial_open, and spi_open. -

i2c_addr: 0-0x7F

-The address of a device on the I2C bus. -

i2c_bus: >=0

-An I2C bus number. -

i2c_flags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2c_reg: 0-255

-A register of an I2C device. -

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See set_watchdog. -

PI_TIMEOUT 2

mode: 0-7

-The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

*param

-An array of script parameters. -

*portStr

-A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. -

*pth

-A thread identifier, returned by start_thread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125000000 (125M)

-The hardware PWM frequency. -

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000

range: 25-40000

-The permissible dutycycle values are 0-range. -PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by store_script. -

SDA

-The user GPIO to use for data when bit banging I2C. -

seconds

-The number of seconds. -

ser_flags

-Flags which modify a serial open command. None are currently defined. -

*ser_tty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

size_t

-A standard type used to indicate the size of an object in bytes. -

spi_channel

-A SPI channel, 0-2. -

spi_flags

-See spi_open. -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) or triggering -the active part of a noise filter (set_noise_filter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

- An array of characters. -

thread_func

-A function of type gpioThreadFunc_t used as the main function of a -thread. -

timeout

-A GPIO watchdog timeout in milliseconds. -PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

unsigned

-A whole number >= 0. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

void

-Denoting no parameter is required -

wave_add_*

-One of wave_add_new, wave_add_generic, wave_add_serial. -

wave_id

-A number representing a waveform created by wave_create. -

wave_send_*

-One of wave_send_once, wave_send_repeat. -

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

pigpiod_if Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
} pigifError_t;

\ No newline at end of file diff --git a/DOC/tmp/body/pdif2.body b/DOC/tmp/body/pdif2.body deleted file mode 100644 index 21d2b4b..0000000 --- a/DOC/tmp/body/pdif2.body +++ /dev/null @@ -1,1460 +0,0 @@ -

pigpiod_if2 is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon.
-

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. -

Usage

Include <pigpiod_if2.h> in your source files. -

Assuming your source is in prog.c use the following command to build -

gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt


to run make sure the pigpio daemon is running -

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if2


For examples see x_pigpiod_if2.c within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error -

OVERVIEW

ESSENTIAL -
pigpio_start Connects to a pigpio daemon -
pigpio_stop Disconnects from a pigpio daemon -
BASIC -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
gpio_read Read a GPIO -
gpio_write Write a GPIO -
PWM (overrides servo commands on same GPIO) -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
set_PWM_frequency Configure PWM frequency for a GPIO -
set_PWM_range Configure PWM range for a GPIO -
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -
get_PWM_frequency Get configured PWM frequency for a GPIO -
get_PWM_range Get configured PWM range for a GPIO -
get_PWM_real_range Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
set_servo_pulsewidth Start/stop servo pulses on a GPIO -
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO. -
set_watchdog Set a watchdog on a GPIO. -
read_bank_1 Read all GPIO in bank 1 -
read_bank_2 Read all GPIO in bank 2 -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
callback Create GPIO level change callback -
callback_ex Create GPIO level change callback, extended -
callback_cancel Cancel a callback -
wait_for_edge Wait for GPIO level change -
start_thread Start a new thread -
stop_thread Stop a previously started thread -
ADVANCED -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
set_pad_strength Sets a pads drive strength -
get_pad_strength Gets a pads drive strength -
shell_ Executes a shell command -
Custom -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
Events -
event_callback Sets a callback for an event -
event_callback_ex Sets a callback for an event, extended -
event_callback_cancel Cancel an event callback -
event_trigger Triggers an event -
wait_for_event Wait for an event -
Scripts -
store_script Store a script -
run_script Run a stored script -
update_script Set a scripts parameters -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick smbus write quick -
i2c_read_byte smbus read byte -
i2c_write_byte smbus write byte -
i2c_read_byte_data smbus read byte data -
i2c_write_byte_data smbus write byte data -
i2c_read_word_data smbus read word data -
i2c_write_word_data smbus write word data -
i2c_read_block_data smbus read block data -
i2c_write_block_data smbus write block data -
i2c_read_i2c_block_data smbus read I2C block data -
i2c_write_i2c_block_data smbus write I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_process_call smbus process call -
i2c_block_process_call smbus block process call -
i2c_zip Performs multiple I2C transactions -
I2C BIT BANG -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs bit banged I2C transactions -
I2C/SPI SLAVE -
bsc_xfer I2C/SPI as slave transfer -
bsc_i2c I2C as slave transfer -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read Reads bytes from a serial device -
serial_write Writes bytes to a serial device -
serial_data_available Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
bb_serial_read_open Opens a GPIO for bit bang serial reads -
bb_serial_read_close Closes a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
bb_serial_read Reads bit bang serial data from a GPIO -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SPI BIT BANG -
bb_spi_open Opens GPIO for bit banging SPI -
bb_spi_close Closes GPIO for bit banging SPI -
bb_spi_xfer Transfers bytes with bit banging SPI -
FILES -
file_open Opens a file -
file_close Closes a file -
file_read Reads bytes from a file -
file_write Writes bytes to a file -
file_seek Seeks to a position within a file -
file_list List files which match a pattern -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_create_and_pad Creates a waveform of fixed size from added data -
wave_delete Deletes one or more waveforms -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_send_using_mode Transmits a waveform in the chosen mode -
wave_chain Transmits a chain of waveforms -
wave_tx_at Returns the current transmitting waveform -
wave_tx_busy Checks to see if the waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_cbs Length in cbs of the current waveform -
wave_get_high_cbs Length of longest waveform so far -
wave_get_max_cbs Absolute maximum allowed cbs -
wave_get_micros Length in micros of the current waveform -
wave_get_high_micros Length of longest waveform so far -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_high_pulses Length of longest waveform so far -
wave_get_max_pulses Absolute maximum allowed pulses -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpiod_if_version Get the pigpiod_if2 version -
pigpio_error Get a text description of an error code. -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -

FUNCTIONS

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds. -

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

-Return a text description for an error code. -

errnum: the error code.

unsigned pigpiod_if_version(void)

-Return the pigpiod_if2 version. -

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

-Starts a new thread of execution with thread_func as the main routine. -

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument userdata. -

The thread can be cancelled by passing the pointer to pthread_t to -stop_thread. -

void stop_thread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: the thread to be stopped.


No value is returned. -

The thread to be stopped should have been started with start_thread. -

int pigpio_start(char *addrStr, char *portStr)

-Connect to the pigpio daemon. Reserving command and -notification streams. -

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.


Returns an integer value greater than or equal to zero if OK. -

This value is passed to the GPIO routines to specify the Pi -to be operated on. -

void pigpio_stop(int pi)

-Terminates the connection to a pigpio daemon and releases -resources used by the library. -

pi: >=0 (as returned by pigpio_start).

int set_mode(int pi, unsigned gpio, unsigned mode)

-Set the GPIO mode. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. -

int get_mode(int pi, unsigned gpio)

-Get the GPIO mode. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

int set_pull_up_down(int pi, unsigned gpio, unsigned pud)

-Set or clear the GPIO pull-up/down resistor. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. -

int gpio_read(int pi, unsigned gpio)

-Read the GPIO level. -

  pi: >=0 (as returned by pigpio_start).
gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

int gpio_write(int pi, unsigned gpio, unsigned level)

-Write the GPIO level. -

   pi: >=0 (as returned by pigpio_start).
 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. -

Notes -

If PWM or servo pulses are active on the GPIO they are switched off. -

int set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)

-Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes -

The set_PWM_range function may be used to change the -default range of 255. -

int get_PWM_dutycycle(int pi, unsigned user_gpio)

-Return the PWM dutycycle in use on a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

int set_PWM_range(int pi, unsigned user_gpio, unsigned range)

-Set the range of PWM values to be used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. -

Notes -

If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. -

The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is -

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


The real value set by set_PWM_range is (dutycycle * real range) / range. -

int get_PWM_range(int pi, unsigned user_gpio)

-Get the range of PWM values being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). -

int get_PWM_real_range(int pi, unsigned user_gpio)

-Get the real underlying range of PWM values being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

int set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)

-Set the frequency (in Hz) of the PWM to be used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(int pi, unsigned user_gpio)

-Get the frequency of PWM being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


For normal PWM the frequency will be that defined for the GPIO by -set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

int set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)

-Start (500-2500) or stop (0) servo pulses on the GPIO. -

        pi: >=0 (as returned by pigpio_start).
 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. -

The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its limits. -

OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. -

Then set the PWM range using set_PWM_range to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO 25 at 400Hz -

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-

int get_servo_pulsewidth(int pi, unsigned user_gpio)

-Return the servo pulsewidth in use on a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int notify_open(int pi)

-Get a free notification handle. -

pi: >=0 (as returned by pigpio_start).


Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by callback -should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

int notify_begin(int pi, unsigned handle, uint32_t bits)

-Start notifications on a previously opened handle. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

Each notification occupies 12 bytes in the fifo as follows: -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

int notify_pause(int pi, unsigned handle)

-Pause notifications on a previously opened handle. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until -notify_begin is called again. -

int notify_close(int pi, unsigned handle)

-Stop notifications on a previously opened handle and -release the handle for reuse. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int set_watchdog(int pi, unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. -

The callback will receive the special level PI_TIMEOUT. -

int set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than -steady microseconds are ignored. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

uint32_t read_bank_1(int pi)

-Read the levels of the bank 1 GPIO (GPIO 0-31). -

pi: >=0 (as returned by pigpio_start).


The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<n). -

uint32_t read_bank_2(int pi)

-Read the levels of the bank 2 GPIO (GPIO 32-53). -

pi: >=0 (as returned by pigpio_start).


The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). -

int clear_bank_1(int pi, uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int clear_bank_2(int pi, uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_1(int pi, uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_2(int pi, uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int hardware_clock(int pi, unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

       pi: >=0 (as returned by pigpio_start).
     gpio: see description
frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_* or wave_chain -will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

     pi: >=0 (as returned by pigpio_start).
   gpio: see descripton
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. -

uint32_t get_current_tick(int pi)

-Gets the current system tick. -

pi: >=0 (as returned by pigpio_start).


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. -

uint32_t get_hardware_revision(int pi)

-Get the Pi's hardware revision number. -

pi: >=0 (as returned by pigpio_start).


The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

uint32_t get_pigpio_version(int pi)

-Returns the pigpio version. -

pi: >=0 (as returned by pigpio_start).

int wave_clear(int pi)

-This function clears all waveforms and any data added by calls to the -wave_add_* functions. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

int wave_add_new(int pi)

-This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the wave_create function. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

int wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

       pi: >=0 (as returned by pigpio_start).
numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. -

int wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, -and stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int wave_create(int pi)

-This function creates a waveform from the data provided by the prior -calls to the wave_add_* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_create_and_pad(int pi, int percent)

-This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use (in terms -of the theoretical maximum, not the current amount free). This allows the reuse
-of deleted waves while a transmission is active. -

pi: >=0 (as returned by pigpio_start).
percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Normal usage: -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create_and_pad to create a waveform of uniform size. -

Step 4. wave_send_* with the id of the waveform to transmit. -

Repeat steps 2-4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_delete(int pi, unsigned wave_id)

-This function deletes the waveform with id wave_id. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int wave_send_once(int pi, unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -is sent once. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_repeat(int pi, unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by wave_tx_stop). -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)

-Transmits the waveform with id wave_id using mode mode. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.
   mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
         PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC.


PI_WAVE_MODE_ONE_SHOT: same as wave_send_once. -

PI_WAVE_MODE_REPEAT same as wave_send_repeat. -

PI_WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries -to sync with the previous waveform. -

PI_WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries -to sync with the previous waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_chain(int pi, char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

     pi: >=0 (as returned by pigpio_start).
    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if2.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, pi, wid[WAVES];

   pi = pigpio_start(0, 0);
   if (pi<0) return -1;

   set_mode(pi, GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(pi, 2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create(pi);
   }

   wave_chain(pi, (char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy(pi)) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(pi, wid[i]);

   pigpio_stop(pi);
}

int wave_tx_at(int pi)

-This function returns the id of the waveform currently being -transmitted. -

pi: >=0 (as returned by pigpio_start).


Returns the waveform id or one of the following special values: -

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
-PI_NO_TX_WAVE (9999) - no wave being transmitted. -

int wave_tx_busy(int pi)

-This function checks to see if a waveform is currently being -transmitted. -

pi: >=0 (as returned by pigpio_start).


Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int wave_tx_stop(int pi)

-This function stops the transmission of the current waveform. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

This function is intended to stop a waveform started with the repeat mode. -

int wave_get_micros(int pi)

-This function returns the length in microseconds of the current -waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_micros(int pi)

-This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_micros(int pi)

-This function returns the maximum possible size of a waveform in
-microseconds. -

pi: >=0 (as returned by pigpio_start).

int wave_get_pulses(int pi)

-This function returns the length in pulses of the current waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_pulses(int pi)

-This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_pulses(int pi)

-This function returns the maximum possible size of a waveform in pulses. -

pi: >=0 (as returned by pigpio_start).

int wave_get_cbs(int pi)

-This function returns the length in DMA control blocks of the current -waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_cbs(int pi)

-This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_cbs(int pi)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

pi: >=0 (as returned by pigpio_start).

int gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. -

int store_script(int pi, char *script)

-This function stores a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

    pi: >=0 (as returned by pigpio_start).
script: the text of the script.


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

-This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int script_status(int pi, unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int stop_script(int pi, unsigned script_id)

-This function stops a running script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int delete_script(int pi, unsigned script_id)

-This function deletes a stored script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the bb_serial_read_open command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int bb_serial_read_close(int pi, unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)

-This function inverts serial logic for big bang serial reads. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. -

int i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

-This returns a handle for the device at address i2c_addr on bus i2c_bus. -

       pi: >=0 (as returned by pigpio_start).
  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S       (1 bit) : Start bit
P       (1 bit) : Stop bit
Rd/Wr   (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA   (1 bit) : Accept and not accept bit.

Addr    (7 bits): I2C 7 bit address.
i2c_reg (8 bits): A byte which often selects a register.
Data    (8 bits): A data byte.
Count   (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2c_close(int pi, unsigned handle)

-This closes the I2C device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2c_write_quick(int pi, unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr bit [A] P

int i2c_write_byte(int pi, unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] bVal [A] P

int i2c_read_byte(int pi, unsigned handle)

-This reads a single byte from the device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] i2c_reg [A] bVal [A] P

int i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P

int i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)

-This reads a single byte from the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ...
   [A] bufn [A] P

int i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

  pi: >=0 (as returned by pigpio_start).
 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bb_i2c_close(int pi, unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bb_i2c_open. -

 pi: >=0 (as returned by pigpio_start).
SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

    pi: >=0 (as returned by pigpio_start).
   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)

-This function selects a set of GPIO for bit banging SPI at a -specified baud rate. -

       pi: >=0 (as returned by pigpio_start).
       CS: 0-31
     MISO: 0-31
     MOSI: 0-31
     SCLK: 0-31
     baud: 50-250000
spi_flags: see below


spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bb_spi_close(int pi, unsigned CS)

-This function stops bit banging SPI on a set of GPIO -opened with bbSPIOpen. -

pi: >=0 (as returned by pigpio_start).
CS: 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

int bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)

-This function executes a bit banged SPI transfer. -

   pi: >=0 (as returned by pigpio_start).
   CS: 0-31 (as used in a prior call to bb_spi_open)
txBuf: pointer to buffer to hold data to be sent
rxBuf: pointer to buffer to hold returned data
count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. -

Example

// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2
// ./bb_spi_x_test

#include <stdio.h>

#include "pigpiod_if2.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, pi, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if ((pi = pigpio_start(0, 0)) < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bb_spi_close(pi, CE0);
   bb_spi_close(pi, CE1);

   pigpio_stop(pi);
}

int spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


         pi: >=0 (as returned by pigpio_start).
spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per character.
-For bits 9-16 there will be two bytes per character.
-For bits 17-32 there will be four bytes per character. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spi_close(int pi, unsigned handle)

-This functions closes the SPI device identified by the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spi_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)

-This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. -

       pi: >=0 (as returned by pigpio_start).
  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serial_close(int pi, unsigned handle)

-This function closes the serial device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serial_write_byte(int pi, unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read_byte(int pi, unsigned handle)

-This function reads a byte from the serial port associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serial_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. -

If no data is ready zero is returned. -

int serial_data_available(int pi, unsigned handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

  pi: >=0 (as returned by pigpio_start).
arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from custom_1 in that it returns an array of bytes -rather than just an integer. -

The return value is an integer indicating the number of returned bytes. -    pi: >=0 (as returned by pigpio_start).
  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

Note, the number of returned bytes will be retMax or less. -

int get_pad_strength(int pi, unsigned pad)

-This function returns the pad drive strength in mA. -

 pi: >=0 (as returned by pigpio_start).
pad: 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = get_pad_strength(pi, 0); //  get pad 0 strength

int set_pad_strength(int pi, unsigned pad, unsigned padStrength)

-This function sets the pad drive strength in mA. -

         pi: >=0 (as returned by pigpio_start).
        pad: 0-2, the pad to set.
padStrength: 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA

int shell_(int pi, char *scriptName, char *scriptString)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

          pi: >=0 (as returned by pigpio_start).
  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name.
scriptString: the string to pass to the script.


The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. -

scriptName must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell_(pi, "scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell_(pi, "scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell_(pi, "scr1", "\"hello string with spaces world\"");

int file_open(int pi, char *file, unsigned mode)

-This function returns a handle to a file opened in a specified mode. -

  pi: >=0 (as returned by pigpio_start).
file: the file to open.
mode: the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


The following values may be or'd into the mode. -

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=file_read(pi, handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      file_close(pi, handle);
   }

   pigpio_stop(pi);
}

int file_close(int pi, unsigned handle)

-This function closes the file associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

file_close(pi, handle);

int file_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the file -associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. -

Example

if (file_write(pi, handle, buf, 100) == 0)
{
   // file written okay
}
else
{
   // error
}

int file_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the file -associated with handle and writes them to buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. -

Example

   bytes = file_read(pi, handle, buf, sizeof(buf));

   if (bytes >= 0)
   {
      // process read data
   }

int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)

-This function seeks to a position within the file associated -with handle. -

        pi: >=0 (as returned by pigpio_start).
    handle: >=0 (as returned by file_open).
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2).


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. -

Example

file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123

size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size

pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position

int file_list(int pi, char *fpat, char *buf, unsigned count)

-This function returns a list of files which match a pattern. -

   pi: >=0 (as returned by pigpio_start).
 fpat: file pattern to match.
  buf: an array to receive the matching file names.
count: the maximum number of bytes to read.


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See file_open. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   c = file_list(pi, "/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      buf[c] = 0;
      printf("%s", buf);
   }

   pigpio_stop(pi);
}

int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)

-This function initialises a new callback. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. -

The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use gpio_read. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

int callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

-This function initialises a new callback. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, tick, and the userdata -pointer, whenever the GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

-This function cancels a callback identified by its id. -

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)

-This function waits for an edge on the GPIO for up to timeout -seconds. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns when the edge occurs or after the timeout. -

Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a callback function. -

The function returns 1 if the edge occurred, otherwise 0. -

int bsc_xfer(int pi, bsc_xfer_t *bscxfer)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

     pi: >=0 (as returned by pigpio_start).
bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. -

Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. -

The returned function value is the status of the transfer (see below). -

If there was an error the status will be less than zero -(and will contain the error code). -

The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

control consists of the following bits. -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. -

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bsc_xfer(pi, &xfer);

if (status >= 0)
{
   // process transfer
}

int bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)

-This function allows the Pi to act as a slave I2C device. -

This function is not available on the BCM2711 (e.g.as -used in the Pi4B). -

The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. -

      pi: >=0 (as returned by pigpio_start).
i2c_addr: 0-0x7F.
 bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // N/A
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


txCnt is set to the number of bytes to be transmitted, possibly -zero. The data itself should be copied to txBuf. -

Any received data will be written to rxBuf with rxCnt set. -

See bsc_xfer for details of the returned status value. -

If there was an error the status will be less than zero -(and will contain the error code). -

Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. -

int event_callback(int pi, unsigned event, evtCBFunc_t f)

-This function initialises an event callback. -

   pi: >=0 (as returned by pigpio_start).
event: 0-31.
    f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the event id, and tick, whenever the -event occurs. -

int event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)

-This function initialises an event callback. -

      pi: >=0 (as returned by pigpio_start).
   event: 0-31.
       f: the callback function.
userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the event id, the tick, and the userdata -pointer whenever the event occurs. -

int event_callback_cancel(unsigned callback_id)

-This function cancels an event callback identified by its id. -

callback_id: >=0, as returned by a call to event_callback or
event_callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_event(int pi, unsigned event, double timeout)

-This function waits for an event for up to timeout seconds. -

     pi: >=0 (as returned by pigpio_start).
  event: 0-31.
timeout: >=0.


The function returns when the event occurs or after the timeout. -

The function returns 1 if the event occurred, otherwise 0. -

int event_trigger(int pi, unsigned event)

-This function signals the occurrence of an event. -

   pi: >=0 (as returned by pigpio_start).
event: 0-31.


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling event_callback) will be informed by -a callback. -

One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

*addrStr

-A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

bsc_xfer_t

-typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*bscxfer

-A pointer to a bsc_xfer_t object used to control a BSC transfer. -

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

callback_id

-A value >=0, as returned by a call to a callback function, one of -

callback
-callback_ex
-event_callback
-event_callback_ex -

The id is passed to callback_cancel or event_callback_cancel -to cancel the callback. -

CBFunc_t

-typedef void (*CBFunc_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

-typedef void (*CBFuncEx_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata);

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

-The hardware clock frequency. -

count

-The number of bytes to be transferred in a file, I2C, SPI, or serial -command. -

CS

-The GPIO used for the slave select signal when bit banging SPI. -

data_bits: 1-32

-The number of data bits in each character of serial data. -

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge

-Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. -

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

-A negative number indicating a function call failed and the nature -of the error. -

event: 0-31

-An event is a signal used to inform one or more consumers -to start an action. -

evtCBFunc_t

-typedef void (*evtCBFunc_t)
   (int pi, unsigned event, uint32_t tick);

evtCBFuncEx_t

-typedef void (*evtCBFuncEx_t)
   (int pi, unsigned event, uint32_t tick, void *userdata);

f

-A function. -

*file

-A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. -

*fpat

-A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 get_hardware_revision. -

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  -  -  -  -

gpioPulse_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

-A number referencing an object opened by one of -

file_open
-i2c_open
-notify_open
-serial_open
-spi_open -

i2c_addr: 0-0x7F

-The address of a device on the I2C bus. -

i2c_bus: >=0

-An I2C bus number. -

i2c_flags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2c_reg: 0-255

-A register of an I2C device. -

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

int32_t

-A 32-bit signed value. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See set_watchdog. -

PI_TIMEOUT 2

MISO

-The GPIO used for the MISO signal when bit banging SPI. -

mode

-1. The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. The mode of waveform transmission. -

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3


3. A file open mode. -

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


The following values can be or'd into the mode. -

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

-The GPIO used for the MOSI signal when bit banging SPI. -

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

pad: 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

-The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

*param

-An array of script parameters. -

percent: 0-100

-The size of waveform as percentage of maximum available. -

pi

-An integer defining a connected Pi. The value is returned by -pigpio_start upon success. -

*portStr

-A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. -

*pth

-A thread identifier, returned by start_thread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

-The hardware PWM frequency. -

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000
#define PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

-The permissible dutycycle values are 0-range. -

PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

SCLK

-The GPIO used for the SCLK signal when bit banging SPI. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by store_script. -

*scriptName

-The name of a shell_ script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. -

*scriptString

-The string to be passed to a shell_ script to be executed. -

SDA

-The user GPIO to use for data when bit banging I2C. -

seconds

-The number of seconds. -

seekFrom

-PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

-The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). -

ser_flags

-Flags which modify a serial open command. None are currently defined. -

*ser_tty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

size_t

-A standard type used to indicate the size of an object in bytes. -

spi_channel

-A SPI channel, 0-2. -

spi_flags

-See spi_open and bb_spi_open. -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) or triggering -the active part of a noise filter (set_noise_filter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

- An array of characters. -

thread_func

-A function of type gpioThreadFunc_t used as the main function of a -thread. -

timeout

-A GPIO watchdog timeout in milliseconds. -

PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

unsigned

-A whole number >= 0. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. -

In the calling function: -

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: -

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

-Denoting no parameter is required -

wave_add_*

-One of -

wave_add_new
-wave_add_generic
-wave_add_serial -

wave_id

-A number representing a waveform created by wave_create. -

wave_send_*

-One of -

wave_send_once
-wave_send_repeat -

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

pigpiod_if2 Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
   pigif_unconnected_pi     = -2011,
   pigif_too_many_pis       = -2012,
} pigifError_t;

\ No newline at end of file diff --git a/DOC/tmp/body/pif.body b/DOC/tmp/body/pif.body deleted file mode 100644 index d72d3f8..0000000 --- a/DOC/tmp/body/pif.body +++ /dev/null @@ -1,21 +0,0 @@ - -pigpio provides a pipe interface to many of its functions.
-
-The pipe interface is available whenever pigpio is running, either -because it has been started as a daemon, or it has been linked in -to a running user program.  The pipe interface can be disabled -by the program which initialises the library.  pigpiod offers -the -f option to disable the pipe interface.  User programs -should call gpioCfgInterfaces -if they wish to disable the pipe interface.
-
-pigpio listens for commands on pipe /dev/pigpio.  The commands -consist of a command identifier with, depending on the command, -zero, one, or two parameters.  The result, if any, may be read -from pipe /dev/pigout.  If any errors are detected a message -will be written to pipe /dev/pigerr.
-
-
-The format of the commands is identical to those used by pigs. diff --git a/DOC/tmp/body/pig2vcd.body b/DOC/tmp/body/pig2vcd.body deleted file mode 100644 index a6a7719..0000000 --- a/DOC/tmp/body/pig2vcd.body +++ /dev/null @@ -1,20 +0,0 @@ -pig2vcd is a utility which reads notifications on stdin and writes the -output as a Value Change Dump (VCD) file on stdout. -

The VCD file can be viewed using GTKWave. -

Notifications

Notifications consist of 12 bytes with the following binary format. -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments by one for each report. -

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. -

tick: the number of microseconds since system boot. It wraps around after 1h12m. -

level: indicates the level of each gpio. If bit 1<<x is set then gpio x is high. pig2vcd takes these notifications and outputs a text format VCD. -

VCD format

The VCD starts with a header. -

$date 2013-05-31 18:49:36 $end
$version pig2vcd V1 $end
$timescale 1 us $end
$scope module top $end
$var wire 1 A 0 $end
$var wire 1 B 1 $end
$var wire 1 C 2 $end
$var wire 1 D 3 $end
$var wire 1 E 4 $end
$var wire 1 F 5 $end
$var wire 1 G 6 $end
$var wire 1 H 7 $end
$var wire 1 I 8 $end
$var wire 1 J 9 $end
$var wire 1 K 10 $end
$var wire 1 L 11 $end
$var wire 1 M 12 $end
$var wire 1 N 13 $end
$var wire 1 O 14 $end
$var wire 1 P 15 $end
$var wire 1 Q 16 $end
$var wire 1 R 17 $end
$var wire 1 S 18 $end
$var wire 1 T 19 $end
$var wire 1 U 20 $end
$var wire 1 V 21 $end
$var wire 1 W 22 $end
$var wire 1 X 23 $end
$var wire 1 Y 24 $end
$var wire 1 Z 25 $end
$var wire 1 a 26 $end
$var wire 1 b 27 $end
$var wire 1 c 28 $end
$var wire 1 d 29 $end
$var wire 1 e 30 $end
$var wire 1 f 31 $end
$upscope $end
$enddefinitions $end


The header defines gpio identifiers and their name. Each gpio identifier -must be unique. pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0 -through 25, and 'a' through 'f' for gpios 26 through 31. -The corresponding names are 0 through 31.
-

The VCD file may be edited to give a frendlier name, e.g. 8 could be -changed to ENCODER_A if an encoder switch A is connected to gpio 8. -

Following the header pig2vcd takes notifications and outputs a timestamp -followed by a list of one or more gpios which have changed state. -The timestamp consists of a '#' followed by the microsecond tick. -The state lines contain the new state followed by the gpio identifier. -

#1058747
0H
0I
#1059012
1H
#1079777
1I
#1079782
0I
#1079852
1I
#1079857
0I
0H
#1165113
1H
#1165118
0H
#1165153
1H
\ No newline at end of file diff --git a/DOC/tmp/body/pigpiod.body b/DOC/tmp/body/pigpiod.body deleted file mode 100644 index 1aed926..0000000 --- a/DOC/tmp/body/pigpiod.body +++ /dev/null @@ -1,51 +0,0 @@ -pigpiod is a utility which launches the pigpio library as a daemon.
-
-Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.
-
-The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.
-
-pigpiod accepts the following configuration options
-
-
-a valueDMA memory allocation mode0=AUTO, 1=PMAP, 2=MBOXDefault AUTO -
-b valueGPIO sample buffer size in milliseconds100-10000Default 120 -
-c valueLibrary internal settingsDefault 0 -
-d valuePrimary DMA channel0-14Default 14 -
-e valueSecondary DMA channel0-14Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel -
-fDisable fifo interfaceDefault enabled -
-gRun in foreground (do not fork)Default disabled -
-kDisable local and remote socket interfaceDefault enabled -
-lDisable remote socket interfaceDefault enabled -
-mDisable alerts (sampling)Default enabled -
-n IP addressAllow IP address to use the socket interfaceName (e.g. paul) or dotted quad (e.g. 192.168.1.66)If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect -
-p valueSocket port1024-32000Default 8888 -
-s valueSample rate1, 2, 4, 5, 8, or 10 microsecondsDefault 5 -
-t valueClock peripheral0=PWM 1=PCMDefault PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. -
-v -VDisplay pigpio version and exit -
-x maskGPIO which may be updatedA 54 bit mask with (1<<n) set if the user may update GPIO #nDefault is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO -

Example

sudo pigpiod -s 2 -b 200 -f


Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer. Disable the fifo interface. -

Permissions

pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces. -

All GPIO may be read. -

Only the user GPIO for the board type or those specified by the -x option may be updated. -

Type 1 boards 0x03E6CF93 (26 pin header)
Type 2 boards 0xFBC6CF9C (26 pin + 8 pin header)
Type 3 boards 0x0FFFFFFC (40 pin header)


In this context an update includes the following: -

GPIO mode set
-GPIO pull/up down
-GPIO write
-GPIO set PWM (including range and frequency)
-GPIO set servo -

In addition the bank clear and set commands, and the wave commands will only -affect updateable GPIO. -

Exceptions

The following exceptions are made for particular models. -

Models A and B

The green activity LED (GPIO 16) may be written.
-
Models A+ and B+

The green activity LED (GPIO 47) may be written.
-The red power LED (GPIO 35) may be written.
-The high USB power mode (GPIO 38) may be written.
-
Pi Zero

The green activity LED (GPIO 47) may be written.
-
Pi2B

The green activity LED (GPIO 47) may be written.
-The red power LED (GPIO 35) may be written.
-The high USB power mode (GPIO 38) may be written.
-
Pi3B

The green activity LED and the red power LED are not writable.
-The USB power mode is fixed at 1.2 amps (high power).
-

DMA Channels

The secondary channel is only used for the transmission of waves. -

If possible use one of channels 0 to 6 for the secondary channel (a full channel). -

A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel. -

\ No newline at end of file diff --git a/DOC/tmp/body/pigs.body b/DOC/tmp/body/pigs.body deleted file mode 100644 index 4a88b42..0000000 --- a/DOC/tmp/body/pigs.body +++ /dev/null @@ -1,1205 +0,0 @@ -

Introduction

-The socket and pipe interfaces allow control of the Pi's GPIO by -passing messages to the running pigpio library. -

The normal way to start the pigpio library would be as a daemon during boot. -

sudo pigpiod

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

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. -

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 $?). -

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). -

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. -

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. -

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 mSet GPIO mode gpioSetMode
MG/MODEG gGet GPIO mode gpioGetMode
PUD g pSet GPIO pull up/down gpioSetPullUpDown
R/READ gRead GPIO level gpioRead
W/WRITE g LWrite GPIO level gpioWrite
PWM (overrides servo commands on same GPIO) -
P/PWM u vSet GPIO PWM value gpioPWM
PFS u vSet GPIO PWM frequency gpioSetPWMfrequency
PRS u vSet GPIO PWM range gpioSetPWMrange
GDC uGet GPIO PWM dutycycle gpioGetPWMdutycycle
PFG uGet GPIO PWM frequency gpioGetPWMfrequency
PRG uGet GPIO PWM range gpioGetPWMrange
PRRG uGet GPIO PWM real range gpioGetPWMrealRange
Servo (overrides PWM commands on same GPIO) -
S/SERVO u vSet GPIO servo pulsewidth gpioServo
GPW uGet GPIO servo pulsewidth gpioGetServoPulsewidth
INTERMEDIATE -
TRIG u pl LSend a trigger pulse gpioTrigger
WDOG u vSet GPIO watchdog gpioSetWatchdog
BR1Read bank 1 GPIO gpioRead_Bits_0_31
BR2Read bank 2 GPIO gpioRead_Bits_32_53
BC1 bitsClear specified GPIO in bank 1 gpioWrite_Bits_0_31_Clear
BC2 bitsClear specified GPIO in bank 2 gpioWrite_Bits_32_53_Clear
BS1 bitsSet specified GPIO in bank 1 gpioWrite_Bits_0_31_Set
BS2 bitsSet specified GPIO in bank 2 gpioWrite_Bits_32_53_Set
ADVANCED -
NORequest a notification gpioNotifyOpen
NC hClose notification gpioNotifyClose
NB h bitsStart notification gpioNotifyBegin
NP hPause notification gpioNotifyPause
HC g cfSet hardware clock frequency gpioHardwareClock
HP g pf pdcSet hardware PWM frequency and dutycycle gpioHardwarePWM
FG u stdySet a glitch filter on a GPIO gpioGlitchFilter
FN u stdy actvSet a noise filter on a GPIO gpioNoiseFilter
PADS pad padmaSet pad drive strength gpioSetPad
PADG padGet pad drive strength gpioGetPad
SHELL name strExecute a shell command shell
Custom -
CF1 uvsCustom function 1 gpioCustom1
CF2 uvsCustom function 2 gpioCustom1
Events -
EVM h bitsSet events to monitor eventMonitor
EVT eventTrigger event eventTrigger
Scripts -
PROC tStore script gpioStoreScript
PROCR sid parsRun script gpioRunScript
PROCU sid parsSet script parameters gpioUpdateScript
PROCP sidGet script status and parameters gpioScriptStatus
PROCS sidStop script gpioStopScript
PROCD sidDelete script gpioDeleteScript
PARSE tValidate script gpioParseScript
I2C -
I2CO ib id ifOpen I2C bus and device with flags i2cOpen
I2CC hClose I2C handle i2cClose
I2CWQ h bitsmb Write Quick: write bit i2cWriteQuick
I2CRS hsmb Read Byte: read byte i2cReadByte
I2CWS h bvsmb Write Byte: write byte i2cWriteByte
I2CRB h rsmb Read Byte Data: read byte from register i2cReadByteData
I2CWB h r bvsmb Write Byte Data: write byte to register i2cWriteByteData
I2CRW h rsmb Read Word Data: read word from register i2cReadWordData
I2CWW h r wvsmb Write Word Data: write word to register i2cWriteWordData
I2CRK h rsmb Read Block Data: read data from register i2cReadBlockData
I2CWK h r bvssmb Write Block Data: write data to register i2cWriteBlockData
I2CWI h r bvssmb Write I2C Block Data i2cWriteI2CBlockData
I2CRI h r numsmb Read I2C Block Data: read bytes from register i2cReadI2CBlockData
I2CRD h numi2c Read device i2cReadDevice
I2CWD h bvsi2c Write device i2cWriteDevice
I2CPC h r wvsmb Process Call: exchange register with word i2cProcessCall
I2CPK h r bvssmb Block Process Call: exchange data bytes with register i2cBlockProcessCall
I2CZ h bvsPerforms multiple I2C transactions i2cZip
I2C BIT BANG -
BI2CO sda scl bOpen bit bang I2C bbI2COpen
BI2CC sdaClose bit bang I2C bbI2CClose
BI2CZ sda bvsI2C bit bang multiple transactions bbI2CZip
I2C/SPI SLAVE -
BSCX bctl bvsBSC I2C/SPI transfer bscXfer
SERIAL -
SERO dev b sefOpen serial device dev at baud b with flags serOpen
SERC hClose serial handle serClose
SERRBRead byte from serial handle serReadByte
SERWB h bvWrite byte to serial handle serWriteByte
SERR h numRead bytes from serial handle serRead
SERW h bvsWrite bytes to serial handle serWrite
SERDA hCheck for serial data ready to read serDataAvailable
SERIAL BIT BANG (read only) -
SLRO u b dbOpen GPIO for bit bang serial data gpioSerialReadOpen
SLRC uClose GPIO for bit bang serial data gpioSerialReadClose
SLRI u vSets bit bang serial data logic levels gpioSerialReadInvert
SLR u numRead bit bang serial data from GPIO gpioSerialRead
SPI -
SPIO c b spfSPI open channel at baud b with flags spiOpen
SPIC hSPI close handle spiClose
SPIR h numSPI read bytes from handle spiRead
SPIW h bvsSPI write bytes to handle spiWrite
SPIX h bvsSPI transfer bytes to handle spiXfer
SPI BIT BANG -
BSPIO cs miso mosi sclk b spfOpen bit bang SPI bbSPIOpen
BSPIC csClose bit bang SPI bbSPIClose
BSPIX cs bvsSPI bit bang transfer bbSPIXfer
FILES -
FO file modeOpen a file in mode fileOpen
FC hClose file handle fileClose
FR h numRead bytes from file handle fileRead
FW h bvsWrite bytes to file handle fileWrite
FS h num fromSeek to file handle position fileSeek
FL pat numList files which match pattern fileList
WAVES -
WVCLRClear all waveforms gpioWaveClear
WVNEWInitialise a new waveform gpioWaveAddNew
WVAG tripsAdd generic pulses to waveform gpioWaveAddGeneric
WVAS u b db sb o bvsAdd serial data to waveform gpioWaveAddSerial
WVCRECreate a waveform gpioWaveCreate
WVCAPCreate a waveform of fixed size gpioWaveCreatePad
WVDEL widDelete selected waveform gpioWaveDelete
WVTX widTransmits waveform once gpioWaveTxSend
WVTXM wid wmdeTransmits waveform using mode gpioWaveTxSend
WVTXR widTransmits waveform repeatedly gpioWaveTxSend
WVCHA bvsTransmits a chain of waveforms gpioWaveChain
WVTATReturns the current transmitting waveform gpioWaveTxAt
WVBSYCheck if waveform is being transmitted gpioWaveTxBusy
WVHLTStop waveform gpioWaveTxStop
WVSC wsGet waveform DMA CB stats gpioWaveGetCbs
WVSM wsGet waveform time stats gpioWaveGetMicros
WVSP wsGet waveform pulse stats gpioWaveGetPulses
UTILITIES -
H/HELPDisplay command help
HWVERGet hardware version gpioHardwareRevision
MICS vMicroseconds delay gpioDelay
MILS vMilliseconds delay gpioDelay
PIGPVGet pigpio library version gpioVersion
T/TICKGet current tick gpioTick
CONFIGURATION -
CGIConfiguration get internals gpioCfgGetInternals
CSI vConfiguration set internals gpioCfgSetInternals

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. -

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. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o 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. -

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: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

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 read GPIO 0-31 (bank 1) and returns the levels as a -32-bit hexadecimal value. -

Example

$ pigs br1
1001C1CF

BR2 - - Read bank 2 GPIO

This command read 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 (sets high) 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 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

This command sets (sets high) 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 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

This command performs a BSC I2C/SPI slave transfer as defined by -bctl with data bvs. -

This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

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, followed by any data bytes -read from the BSC receive FIFO. -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

For I2C use a control word of (I2C address << 16) + 0x305. -

E.g. to talk as I2C slave with address 0x13 use 0x130305. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

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. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit 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 -opened with BSPIO. -

The set of GPIO is specifed by cs. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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 command starts bit banging SPI on a group of GPIO with slave -select cs, MISO miso, MOSI mosi, and clock sclk. -

Data will be transferred at baud b bits per second (which may -be set in the range 50-250000). -

The flags spf may be used to modify the default behaviour of -mode 0, active low chip select. -

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
 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 (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. -

Upon success 0 is returned. On error a negative status code -will be returned. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

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. It returns the same -number of bytes read from the device. -

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 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

This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. -

CF2 - uvs - Custom function 2

This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. -

CGI - - Configuration get internals

This command returns the value of the internal library -configuration settings. -

CSI - v - Configuration set internals

This command sets the value of the internal library -configuration settings to v. -

EVM - h bits - Set events to monitor

This command starts event reporting 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 reports for each 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

This command triggers event event. -

One event, number 31, is predefined. This event is -auto generated on BSC slave activity. -

Example

$ pigs evt 12
$ pigs evt 5

$ pigs evt 32
-143
ERROR: bad event id

FC - h - Close file handle

This command closes a file handle h previously opened with FO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs fc 0 # First close okay.

$ pigs fc 0 # Second fails.
-25
ERROR: unknown handle

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. The -level is then reported. Level changes of less than stdy -microseconds are ignored. -

The filter only affects callbacks (including pipe notifications). -

The R/READ, BR1, and BR2 commands are not affected. -

Note, each (stable) edge will be timestamped stdy microseconds -after it was first detected. -

Example

$ pigs fg 4 250

$ pigs fg 4 1000000
-125
ERROR: bad filter parameter

FL - pat num - List files which match pattern

This command returns a list of the files matching pat. Up -to num bytes may be returned. -

Upon success the count of returned bytes followed by the matching -files is returned. On error a negative status code will be returned. -

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 are ignored until a level which has -been stable for stdy microseconds is detected. Level -changes on the GPIO are then reported for actv microseconds -after which the process repeats. -

The filter only affects callbacks (including pipe notifications). -

The R/READ, BR1, and BR2 commands are not affected. -

Note, level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

Example

$ pigs fn 7 250 1000

$ pigs fn 7 2500000 1000
-125
ERROR: bad filter parameter

FO - file mode - Open a file in mode

This function 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 -will be returned. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


The following values may be or'd into the mode. -

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

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

This command 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 will be returned. -

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

This command 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 backwards. The move start -position is determined by from as follows. -

From
0start
1current position
2end


Upon success the new byte position within the file (>=0) is -returned. On error a negative status code will be returned. -

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

This command writes bytes bvs to the file -associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs fw 0 23 45 67 89

GDC - u - Get GPIO PWM dutycycle

This command returns the PWM dutycycle in use on GPIO u. -

Upon success the dutycycle is returned. On error a negative -status code will be returned. -

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

This command returns the servo pulsewidth in use on GPIO u. -

Upon success the servo pulsewidth is returned. On error a negative -status code will be returned. -

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

This command displays a brief list of the commands and their parameters. -

Example

$ pigs h

$ pigs help

HC - g cf - Set hardware clock frequency

This command sets the hardware clock associated with GPIO g to -frequency cf. Frequencies above 30MHz are unlikely to work. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

The GPIO must be one of the following. -

4clock 0All models
5clock 1All models but A and B (reserved for system use)
6clock 2All models but A and B
20clock 0All models but A and B
21clock 1All models but A and B Rev.2 (reserved for system use)


32clock 0Compute module only
34clock 0Compute module only
42clock 1Compute module only (reserved for system use)
43clock 2Compute module only
44clock 1Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. -

HP - g pf pdc - Set hardware PWM frequency and dutycycle

This command sets the hardware PWM associated with GPIO g to -frequency pf with dutycycle pdc. Frequencies above 30MHz -are unlikely to work. -

NOTE: Any waveform started by WVTX, WVTXR, or WVCHA -will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

Upon success nothing is returned. On error a negative status code -will be returned. -

$ 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


The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12PWM channel 0All models but A and B
13PWM channel 1All models but A and B
18PWM channel 0All models
19PWM channel 1All models but A and B


40PWM channel 0Compute module only
41PWM channel 1Compute module only
45PWM channel 1Compute module only
52PWM channel 0Compute module only
53PWM channel 1Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/pf (375M/pf for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a pf of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. pdc is -automatically scaled to take this into account. -

HWVER - - Get hardware version

This command returns the hardware revision of the Pi. -

The hardware revision is found in the last 4 characters on the revision -line of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid hexadecimal -number the command returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see g). -

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

This command closes an I2C handle h previously opened with I2CO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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 command returns a handle to access device id on I2C bus ib. -The device is opened with flags if. -

Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


No flags are currently defined. The parameter if should be 0. -

Upon success the next free handle (>=0) is returned. On error a -negative status code will be returned. -

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

This command writes wv to register r of the I2C device -associated with handle h and returns a 16-bit word read from the -device. -

Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. -

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

This command writes the data bytes bvs to register r of the I2C device -associated with handle h and returns a device specific number of 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 i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0

I2CRB - h r - smb Read Byte Data: read byte from register

This command returns a single byte read from register r of the I2C device -associated with handle h. -

Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crb 0 0
6

I2CRD - h num - i2c Read device

This command returns num bytes read from the I2C 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. -

This command operates on the raw I2C device. The maximum value of the -parameter num is dependent on the I2C drivers and the device -itself. pigs imposes a limit of 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

This command returns num bytes from register r of the I2C 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. -

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

This command returns between 1 and 32 bytes read from register r of -the I2C 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. -

The number of bytes of returned data is specific to the device and -register. -

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

This command returns a single byte read from the I2C device -associated with handle h. -

Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crs 0
0

I2CRW - h r - smb Read Word Data: read word from register

This command returns a single 16 bit word read from register r of -the I2C device associated with handle h. -

Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crw 0 0
6150

I2CWB - h r bv - smb Write Byte Data: write byte to register

This command writes a single byte bv to register r of the -I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwb 0 10 0x54

I2CWD - h bvs - i2c Write device

This command writes a block of bytes bvs to the I2C device -associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

The number of bytes which may be written in one transaction is -dependent on the I2C drivers and the device itself. pigs imposes -a limit of about 500 bytes. -

This command operates on the raw I2C device. -

Example

$ pigs i2cwd 0 0x01 0x02 0x03 0x04

I2CWI - h r bvs - smb Write I2C Block Data

This command writes between 1 and 32 bytes bvs to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwi 0 4 0x01 0x04 0xc0

I2CWK - h r bvs - smb Write Block Data: write data to register

This command writes between 1 and 32 bytes bvs to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

pigs i2cwk 0 4 0x01 0x04 0xc0

I2CWQ - h bit - smb Write Quick: write bit

This command writes a single bit to the I2C device associated -with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwq 0 1

I2CWS - h bv - smb Write Byte: write byte

This command writes a single byte bv to the I2C device associated -with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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

This command writes a single 16 bit word wv to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cww 0 0 0xffff

I2CZ - h bvs - Performs multiple I2C transactions

This command executes a sequence of 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: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle h. -The flags default to 0. The address and flags maintain their -previous value until updated. -

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/MODES - g m - Set GPIO mode

This command sets GPIO g to mode m, typically input (read) -or output (write). -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345


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. -

Value01234567
ModeInputOutputALT5ALT4ALT0ALT1ALT2ALT3


Example

$ pigs mg 4
1

MICS - v - Microseconds delay

This command delays execution for v microseconds. -

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. -

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. -

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. -

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. -

PadGPIO
00-27
128-45
246-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. -

PadGPIO
00-27
128-45
246-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. -

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. -

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

       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


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). -

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. -

Upon success the script status and parameters are returned. -On error a negative status code will be returned. -

The script status may be one of -

0being initialised
1halted
2running
3waiting
4failed


See Scripts. -

Example

$ pigs procp 0
1 0 0 0 0 0 0 0 0 0 0

PROCR - sid pars - Run script

This command runs stored script sid passing it up to 10 optional -parameters. -

Upon success nothing is returned. 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 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

This command stops a running script sid. -

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

This command sets the parameters of a stored script sid passing -it up to 10 parameters. -

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 used by GPIO u. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

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 command sets the dutycycle range v to be used for GPIO u. -Subsequent uses of command P/PWM will use a dutycycle between 0 (off) -and v (fully on). -

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 will be scaled to -reflect the new range. -

The real range, the number of steps between fully off and fully on -for each frequency, is given in the following table. -

#1#2#3#4#5#6#7#8#9
2550100125200250400500625
#10#11#12#13#14#15#16#17#18
8001000125020002500400050001000020000


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

This command 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 may 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

This 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

This command 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 may be 0 (off), 500 (most anti-clockwise) -to 2500 (most clockwise). -

The range supported by servos varies and should probably be determined -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. -

You can DAMAGE a servo if you command it to move beyond its limits. -

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

This command closes a serial handle h 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

This command 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). 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

This command 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. -

Example

$ pigs sero /dev/ttyAMA0 9600 0
0

$ pigs sero /dev/tty1 38400 0
1

SERR - h num - Read bytes from serial handle

This command 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

This command 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

This command 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

This command 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 command 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. -

The returned exit status is normally 256 times that set -by the shell script exit function. If the script can't -be found 32512 will be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


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 "\"hello string with spaces world\""
256

# non-existent script
$ pigs shell scr78 par1
32512

SLR - u num - Read bit bang serial data from GPIO

This command 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. -

The GPIO u should have been initialised with the SLRO command. -

The bytes returned for each character depend upon the number of -data bits db 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

This command 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

This command 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

This command 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 may be between 50 and 250000 bits per second. -

The received data is held in a cyclic buffer. -

It is the user's responsibility to read the data (with SLR) -in a timely fashion. -

Example

$ pigs slro 23 19200 8

$ pigs slro 23 19200 8
-50
ERROR: GPIO already in use

SPIC - h - SPI close handle

This command closes the SPI handle h returned by a prior -call to SPIO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

Data will be transferred at b bits per second. The flags spf -may be used to modify the default behaviour of 4-wire operation, -mode 0, active low chip select. -

Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps -are unlikely to work. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


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. -

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. -

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. -

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. -

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. -

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

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. -

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. -

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. -

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. -

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. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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 \
   ${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

WVCLR - - Clear all waveforms

This command clears all waveforms. -

Nothing is returned. -

Example

$ pigs wvclr

WVCRE - - Create a waveform

This command creates a waveform from the data provided by the prior -calls to the WVAG and WVAS commands. -

Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. -

The data provided by the WVAG and WVAS commands is -consumed by this command. -

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 -

Step 1. WVCLR to clear all waveforms and added data. -

Step 2. WVAG/WVAS calls to supply the waveform data. -

Step 3. WVCRE to create the waveform and get a unique id. -

Repeat steps 2 and 3 as needed. -

Step 4. WVTX or WVTXR with the id of the waveform to transmit. -

A waveform comprises of one or more pulses. -

A pulse specifies -

1) the GPIO to be switched on at the start of the pulse.
-2) the GPIO to be switched off at the start of the pulse.
-3) the delay in microseconds before the next pulse. -

Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). -

When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. -

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

WVCAP - - 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 total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. -

Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. -

The data provided by the WVAG and WVAS commands are -consumed by this command. -

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 -

Step 1. WVCLR to clear all waveforms and added data. -

Step 2. WVAG/WVAS calls to supply the waveform data. -

Step 3. WVCAP to create a waveform of a uniform size. -

Step 4. WVTX or WVTXR with the id of the waveform to transmit. -

Repeat steps 2 - 4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

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

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

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. -

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

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. -

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), or 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. -

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. -

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

-

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. -

From
0start
1current position
2end

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. -

0123456789101112131415
Type 1XX--X--XXXXX--XX
Type 2--XXX--XXXXX--XX
Type 3XXXXXXXXXXXXXX
16171819202122232425262728293031
Type 1-XX--XXXXX------
Type 2-XX---XXXX-XXXXX
Type 3XXXXXXXXXXXX----


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. -

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345
Value01456732

miso - GPIO (0-31)

-The GPIO used for the MISO signal when bit banging SPI. -

mode - file open mode

-One of the following values. -

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


The following values can be or'd into the mode. -

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The 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 DownOffPull DownPull Up
Command CharacterODU


There is no mechanism to read the pull up down state. -

pad - 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-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. -

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 onGPIO offdelay
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

-Scripts are programs to be stored and executed by the pigpio daemon. -They are intended to mitigate any performance problems associated with -the pigpio daemon server/client model. -

Example

A trivial example might be useful. Suppose you want to toggle a GPIO -on and off as fast as possible. -

From the command line you could write -

for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done


Timing that you will see it takes about 14 seconds, or roughly -70 toggles per second. -

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. -

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. -

Let's time the script running. -

Again, ignore the details for now. -

time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
 do sleep 0.2; done)


The script takes roughly 12 seconds to complete, or 800,000 toggles per second. -

That is the advantage of a stored script. -

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 ]];\
 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. -

Virtual machine

A script runs within a virtual machine with -

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. -

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: -

CommandDescriptionDefinition
ADD xAdd x to accumulatorA+=x; F=A
AND xAnd x with accumulatorA&=x; F=A
CALL LCall subroutine at tag Lpush(PC+1); PC=L
CMP xCompare x with accumulatorF=A-x
DCR yDecrement register--*y; F=*y
DCRADecrement accumulator--A; F=A
DIV xDivide x into accumulatorA/=x; F=A
EVTWTWait for an event to occurA=wait(x); F=A
HALTHaltHalt
INR yIncrement register++*y; F=*y
INRAIncrement accumulator++A; F=A
JM LJump if minus to tag Lif (F<0) PC=L
JMP LJump to tag LPC=L
JNZ LJump if non-zero to tag Lif (F) PC=L
JP LJump if positive to tag Lif (F>=0) PC=L
JZ LJump if zero to tag Lif (!F) PC=L
LD y xLoad register with x*y=x
LDA xLoad accumulator with xA=x
MLT xMultiply x with accumulatorA*=x; F=A
MOD xModulus x with accumulatorA%=x; F=A
OR xOr x with accumulatorA|=x; F=A
POP yPop registery=pop()
POPAPop accumulatorA=pop()
PUSH yPush registerpush(y)
PUSHAPush accumulatorpush(A)
RETReturn from subroutinePC=pop()
RL y xRotate left register x bits*y<<=x; F=*y
RLA xRotate left accumulator x bitsA<<=x; F=A
RR y xRotate right register x bits*y>>=x; F=*y
RRA xRotate right accumulator x bitsA>>=x; F=A
STA yStore accumulator in registery=A
SUB xSubtract x from accumulatorA-=x; F=A
SYS strRun external script (/opt/pigpio/cgi/str)system(str); F=A
TAG LLabel the current script positionN/A
WAIT xWait for a GPIO in x to change stateA=wait(x); F=A
X y1 y2Exchange contents of registers y1 and y2t=*y1;*y1=*y2;*y2=t
XA yExchange contents of accumulator and registert=A;A=*y;*y=t
XOR xXor x with accumulatorA^=x; F=A


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. -

\ No newline at end of file diff --git a/DOC/tmp/body/piscope.body b/DOC/tmp/body/piscope.body deleted file mode 100644 index dd0c7ce..0000000 --- a/DOC/tmp/body/piscope.body +++ /dev/null @@ -1,205 +0,0 @@ - -

Introduction

-piscope is a logic analyser (digital -waveform viewer) for the Raspberry.  It shows the state (high -or low) of selected GPIO in real-time.
-
-See video.
-
-piscope uses the services of the pigpio library.  pigpio needs to be running on -the Pi whose GPIO are to be monitored.
-
-The pigpio library may be started as a daemon (background process) -by the following command.
-
-sudo pigpiod

-piscope may be invoked in several different ways
-
- - - - - - - - - - - - - - - - - - - - - - - -
Pi
pi_host ~ $ piscope -&
Pi captures -data
-Pi processes data
-Pi displays data
Pi plus Linux PC
-
-(with the
-display on a remote
-  Linux PC)
remote_host ~ $ ssh -X pi_host
pi_host ~ $ piscope -&
Pi captures data
-Pi processes data
-Remote Linux PC displays data
Pi plus Windows PC
-
-(with the
-display on a remote
-  Windows PC)
You need to install an SSH -client (putty suggested) and a X11 server (xming suggested).
-
-Run Program Files -> Xming -> XLaunch and accept the -defaults.
-
-Run putty and enter the Pi's host name or IP address.  Click -on SSH X11 and tick Enable X11 forwarding and then select -Open.

-
pi_host ~ $ piscope -&
Pi captures data
-Pi processes data
-Remote Windows PC displays data
Pi plus Linux PC
-
-(with the display and processing on a remote Linux -PC)
remote_host ~ $ export -PIGPIO_ADDR=pi_host
-remote_host ~ $ piscope -&
Pi captures data
-Remote processes data
-Remote displays data
-
-piscope operates in one of three modes
-
- - - - - - - - - - - - - - - - - - -
Live
The latest GPIO samples are -displayed.
-
-The mode will automatically change to Pause if a sampling trigger -is detected.
-
-There are four triggers.  Each trigger is made up of a -combination of GPIO states (one of don't care, low, high, edge, -falling, or rising per GPIO).  Triggers are always -counted.  In addition a trigger may be sample to, sample -around, or sample from, a so called sampling trigger.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full the oldest samples are discarded.
Play
Recorded GPIO samples are -displayed.
-
-The play speed may be varied between 64 times real-time to 1/32768 -of real-time.
-
-The page up key increases the play speed by a factor of 2.  -The page down key decreases the play speed by a factor of 2.  -The home key sets the play speed to 1X.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full new samples are discarded.
Pause
Recorded GPIO samples are -displayed.
-
-The left and right cursor keys move the blue marker to the previous -or next edge.  By default all GPIO edges are considered.  -Clicking on a GPIO name will limit edge searches to the highlighted -GPIO only.
-
-The left and right square bracket keys move the blue marker to the -previous or next trigger.
-
-The time between the blue and gold markers is displayed.  The -gold marker is set to the blue marker by a press of the 'g' -key.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full new samples are discarded.
-
-In all modes the down and up cursor keys zoom the time scale in and -out.
-
-Samples can be saved with File Save All Samples or File Save -Selected Samples. -

To select samples enter pause mode. Press 1 to specify the start -of the samples (green marker) and 2 to specify the end of the -samples (red marker).

-

The samples may be saved in the native piscope format or in VCD -format.

-

Data saved in VCD format may be viewed and further processed -with GTKWave.

-

Data saved in the native piscope format may be restored later -with File Restore Saved Data.

-

Installation

-

To download and install piscope.

-

Pi (pre-built image)

-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make hf
-make install

-

Linux 64 bit X86/AMD (pre-built image)

-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make x86_64
-make install
-

All machines (building from source)

-You only need to perform this step if you want to build the -executable from the source files.  This is not needed if you -use a pre-built image.
-
-WARNING
: Installing gtk+-3.0 uses a lot of SD card -space.
-
-Most of the space used by gtk+-3.0 is taken up by unneeded *-dbg -packages.
-
-With *-dbg packages an additional 3753MB SD space is required.
-
-If you edit the list of packages to be downloaded and remove the -*-dbg packages only 134MB of additional SD space is needed (as at -the time of writing).
-
-#
# *** This may take a lot of time and use -a lot of SD card space ***
#
-sudo apt-get install gtk+-3.0
#
-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make
-make install

diff --git a/DOC/tmp/body/python.body b/DOC/tmp/body/python.body deleted file mode 100644 index 4f756e4..0000000 --- a/DOC/tmp/body/python.body +++ /dev/null @@ -1,1231 +0,0 @@ -pigpio is a Python module for the Raspberry which talks to -the pigpio daemon to allow control of the general purpose -input outputs (GPIO). -

Features

o the pigpio Python module can run on Windows, Macs, or Linux -

o controls one or more Pi's -

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o creating and transmitting precisely timed waveforms -

o reading/writing GPIO and setting their modes -

o wrappers for I2C, SPI, and serial links -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

Transmitted waveforms are accurate to a microsecond. -

Callback level changes are time-stamped and will be -accurate to within a few microseconds. -

Settings

A number of settings are determined when the pigpio daemon is started. -

o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). -

o the set of GPIO which may be updated (generally written to). The - default set is those available on the Pi board revision. -

o the available PWM frequencies (see set_PWM_frequency). -

Exceptions

By default a fatal exception is raised if you pass an invalid -argument to a pigpio function. -

If you wish to handle the returned status yourself you should set -pigpio.exceptions to False. -

You may prefer to check the returned status in only a few parts -of your code. In that case do the following: -

Example

pigpio.exceptions = False

# Code where you want to test the error status.

pigpio.exceptions = True

Usage

This module uses the services of the C pigpio library. pigpio -must be running on the Pi(s) whose GPIO are to be manipulated. -

The normal way to start pigpio is as a daemon (during system -start). -

sudo pigpiod -

Your Python program must import pigpio and create one or more -instances of the pigpio.pi class. This class gives access to -a specified Pi's GPIO. -

Example

pi1 = pigpio.pi()       # pi1 accesses the local Pi's GPIO
pi2 = pigpio.pi('tom')  # pi2 accesses tom's GPIO
pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO

pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4)     # get level of dick's GPIO 4


The later example code snippets assume that pi is an instance of -the pigpio.pi class. -

OVERVIEW

ESSENTIAL -
pigpio.pi Initialise Pi connection -
stop Stop a Pi connection -
BASIC -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
read Read a GPIO -
write Write a GPIO -
PWM (overrides servo commands on same GPIO) -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
set_PWM_frequency Set PWM frequency of a GPIO -
set_PWM_range Configure PWM range of a GPIO -
get_PWM_dutycycle Get PWM dutycycle set on a GPIO -
get_PWM_frequency Get PWM frequency of a GPIO -
get_PWM_range Get configured PWM range of a GPIO -
get_PWM_real_range Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
set_servo_pulsewidth Start/Stop servo pulses on a GPIO -
get_servo_pulsewidth Get servo pulsewidth set on a GPIO -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO -
set_watchdog Set a watchdog on a GPIO -
read_bank_1 Read all bank 1 GPIO -
read_bank_2 Read all bank 2 GPIO -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
callback Create GPIO level change callback -
wait_for_edge Wait for GPIO level change -
ADVANCED -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
set_pad_strength Sets a pads drive strength -
get_pad_strength Gets a pads drive strength -
shell Executes a shell command -
Custom -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
Events -
event_callback Sets a callback for an event -
event_trigger Triggers an event -
wait_for_event Wait for an event -
Scripts -
store_script Store a script -
run_script Run a stored script -
update_script Set a scripts parameters -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick SMBus write quick -
i2c_read_byte SMBus read byte -
i2c_write_byte SMBus write byte -
i2c_read_byte_data SMBus read byte data -
i2c_write_byte_data SMBus write byte data -
i2c_read_word_data SMBus read word data -
i2c_write_word_data SMBus write word data -
i2c_read_block_data SMBus read block data -
i2c_write_block_data SMBus write block data -
i2c_read_i2c_block_data SMBus read I2C block data -
i2c_write_i2c_block_data SMBus write I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_process_call SMBus process call -
i2c_block_process_call SMBus block process call -
i2c_zip Performs multiple I2C transactions -
I2C BIT BANG -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs multiple bit banged I2C transactions -
I2C/SPI SLAVE -
bsc_xfer I2C/SPI as slave transfer -
bsc_i2c I2C as slave transfer -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read Reads bytes from a serial device -
serial_write Writes bytes to a serial device -
serial_data_available Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
bb_serial_read_open Open a GPIO for bit bang serial reads -
bb_serial_read_close Close a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
bb_serial_read Read bit bang serial data from a GPIO -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SPI BIT BANG -
bb_spi_open Opens GPIO for bit banging SPI -
bb_spi_close Closes GPIO for bit banging SPI -
bb_spi_xfer Transfers bytes with bit banging SPI -
FILES -
file_open Opens a file -
file_close Closes a file -
file_read Reads bytes from a file -
file_write Writes bytes to a file -
file_seek Seeks to a position within a file -
file_list List files which match a pattern -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_create_and_pad Creates a waveform of fixed size from added data -
wave_delete Deletes a waveform -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_send_using_mode Transmits a waveform in the chosen mode -
wave_chain Transmits a chain of waveforms -
wave_tx_at Returns the current transmitting waveform -
wave_tx_busy Checks to see if a waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_cbs Length in cbs of the current waveform -
wave_get_max_cbs Absolute maximum allowed cbs -
wave_get_micros Length in microseconds of the current waveform -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_max_pulses Absolute maximum allowed pulses -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpio.error_text Gets error text from error number -
pigpio.tickDiff Returns difference between two ticks -

class pi -

pigpio.pi(host, port, show_errors)

-Grants access to a Pi's GPIO. -

Parameters

host:= the host name of the Pi on which the pigpio daemon is
       running.  The default is localhost unless overridden by
       the PIGPIO_ADDR environment variable.


Parameters

port:= the port number on which the pigpio daemon is listening.
       The default is 8888 unless overridden by the PIGPIO_PORT
       environment variable.  The pigpio daemon must have been
       started with the same port number.


This connects to the pigpio daemon and reserves resources -to be used for sending commands and receiving notifications. -

An instance attribute connected may be used to check the -success of the connection. If the connection is established -successfully connected will be True, otherwise False. -

Example

pi = pigio.pi()              # use defaults
pi = pigpio.pi('mypi')       # specify host, default port
pi = pigpio.pi('mypi', 7777) # specify host and port

pi = pigpio.pi()             # exit script if no connection
if not pi.connected:
   exit()

__repr__()

-

bb_i2c_close(SDA)

-This function stops bit banging I2C on a pair of GPIO -previously opened with bb_i2c_open. -

Parameters

SDA:= 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

Example

pi.bb_i2c_close(SDA)

bb_i2c_open(SDA, SCL, baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50 -o repeated starts -o clock stretching -o I2C on any pair of spare GPIO -

Parameters

 SDA:= 0-31
 SCL:= 0-31
baud:= 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. -As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

Example

h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps

bb_i2c_zip(SDA, data)

-This function executes a sequence of bit banged I2C operations. -The operations to be performed are specified by the contents -of data which contains the concatenated command codes and -associated data. -

Parameters

 SDA:= 0-31 (as used in a prior call to bb_i2c_open)
data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.bb_i2c_zip(
                   SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0])


The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

Any read I2C data is concatenated in the returned bytearray. -

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

bb_serial_invert(user_gpio, invert)

-Invert serial logic. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)
    invert:= 0-1 (1 invert, 0 normal)


Example

status = pi.bb_serial_invert(17, 1)

bb_serial_read(user_gpio)

-Returns data from the bit bang serial cyclic buffer. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

The bytes returned for each character depend upon the number of -data bits bb_bits specified in the bb_serial_read_open -command. -

For bb_bits 1-8 there will be one byte per character. -For bb_bits 9-16 there will be two bytes per character. -For bb_bits 17-32 there will be four bytes per character. -

Example

(count, data) = pi.bb_serial_read(4)

bb_serial_read_close(user_gpio)

-Closes a GPIO for bit bang reading of serial data. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


Example

status = pi.bb_serial_read_close(17)

bb_serial_read_open(user_gpio, baud, bb_bits)

-Opens a GPIO for bit bang reading of serial data. -

Parameters

user_gpio:= 0-31, the GPIO to use.
     baud:= 50-250000, the baud rate.
  bb_bits:= 1-32, the number of bits per word, default 8.


The serial data is held in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic -buffer in a timely fashion. -

Example

status = pi.bb_serial_read_open(4, 19200)
status = pi.bb_serial_read_open(17, 9600)

bb_spi_close(CS)

-This function stops bit banging SPI on a set of GPIO -opened with bb_spi_open. -

Parameters

CS:= 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

Example

pi.bb_spi_close(CS)

bb_spi_open(CS, MISO, MOSI, SCLK, baud, spi_flags)

-This function selects a set of GPIO for bit banging SPI at a -specified baud rate. -

Parameters

      CS := 0-31
    MISO := 0-31
    MOSI := 0-31
    SCLK := 0-31
    baud := 50-250000
spiFlags := see below


spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0     0    0
 1     0    1
 2     1    0
 3     1    1


The following constants may be used to set the mode: -

pigpio.SPI_MODE_0
pigpio.SPI_MODE_1
pigpio.SPI_MODE_2
pigpio.SPI_MODE_3


Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA -may be used. -

p is 0 if CS is active low (default) and 1 for active high. -pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag. -

T is 1 if the least significant bit is transmitted on MOSI first, -the default (0) shifts the most significant bit out first. -pigpio.SPI_TX_LSBFIRST may be used to set this flag. -

R is 1 if the least significant bit is received on MISO first, -the default (0) receives the most significant bit first. -pigpio.SPI_RX_LSBFIRST may be used to set this flag. -

The other bits in spiFlags should be set to zero. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2

bb_spi_xfer(CS, data)

-This function executes a bit banged SPI transfer. -

Parameters

  CS:= 0-31 (as used in a prior call to bb_spi_open)
data:= data to be sent


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

#!/usr/bin/env python

import pigpio

CE0=5
CE1=6
MISO=13
MOSI=19
SCLK=12

pi = pigpio.pi()
if not pi.connected:
   exit()

pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC
pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC

for i in range(256):

   count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value

   if count == 2:

      count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC

      if count == 2:

         set_val = data[1]

         count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC

         if count == 3:

            read_val = ((data[1]&3)<<8) | data[2]

            print("{} {}".format(set_val, read_val))

pi.bb_spi_close(CE0)
pi.bb_spi_close(CE1)

pi.stop()

bsc_i2c(i2c_address, data)

-This function allows the Pi to act as a slave I2C device. -

This function is not available on the BCM2711 (e.g. as -used in the Pi4B). -

The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. -

Parameters

i2c_address:= the I2C slave address.
       data:= the data bytes to transmit.


The returned value is a tuple of the status, the number -of bytes read, and a bytearray containing the read bytes. -

See bsc_xfer for details of the status value. -

If there was an error the status will be less than zero -(and will contain the error code). -

Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. -

This example assumes GPIO 2/3 are connected to GPIO 18/19 -(GPIO 10/11 on the BCM2711). -

Example

#!/usr/bin/env python
import time
import pigpio

I2C_ADDR=0x13

def i2c(id, tick):
    global pi

    s, b, d = pi.bsc_i2c(I2C_ADDR)
    if b:
        if d[0] == ord('t'): # 116 send 'HH:MM:SS*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[11:19]))

        elif d[0] == ord('d'): # 100 send 'Sun Oct 30*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[:10]))

pi = pigpio.pi()

if not pi.connected:
    exit()

# Respond to BSC slave activity

e = pi.event_callback(pigpio.EVENT_BSC, i2c)

pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave

time.sleep(600)

e.cancel()

pi.bsc_i2c(0) # Disable BSC peripheral

pi.stop()


While running the above. -

$ i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

$ pigs i2co 1 0x13 0
0

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:13:58*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:14:29*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:23:16*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

bsc_xfer(bsc_control, data)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

Parameters

bsc_control:= see below
       data:= the data bytes to place in the transmit FIFO.


The returned value is a tuple of the status (see below), -the number of bytes read, and a bytearray containing the -read bytes. If there was an error the status will be less -than zero (and will contain the error code). -

Note that the control word sets the BSC mode. The BSC will -stay in that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

bsc_control consists of the following bits: -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable BSC peripheral


The status has the following format: -

20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 S  S  S  S  S  R  R  R  R  R  T  T  T  T  T RB TE RF TF RE TB


Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


Example

(status, count, data) = pi.bsc_xfer(0x330305, "Hello!")

callback(user_gpio, edge, func)

-Calls a user supplied function (a callback) whenever the -specified GPIO edge is detected. -

Parameters

user_gpio:= 0-31.
     edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.
     func:= user supplied callback function.


The user supplied callback receives three parameters, the GPIO, -the level, and the tick. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


If a user callback is not specified a default tally callback is -provided which simply counts edges. The count may be retrieved -by calling the tally function. The count may be reset to zero -by calling the reset_tally function. -

The callback may be cancelled by calling the cancel function. -

A GPIO may have multiple callbacks (although I can't think of -a reason to do so). -

The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. -

The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use read. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

Example

def cbf(gpio, level, tick):
   print(gpio, level, tick)

cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf)

cb2 = pi.callback(4, pigpio.EITHER_EDGE)

cb3 = pi.callback(17)

print(cb3.tally())

cb3.reset_tally()

cb1.cancel() # To cancel callback cb1.

clear_bank_1(bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.clear_bank_1(int("111110010000",2))

clear_bank_2(bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.clear_bank_2(0x1010)

custom_1(arg1, arg2, argx)

-Calls a pigpio function customised by the user. -

Parameters

arg1:= >=0, default 0.
arg2:= >=0, default 0.
argx:= extra arguments (each 0-255), default empty.


The returned value is an integer which by convention -should be >=0 for OK and <0 for error. -

Example

value = pi.custom_1()

value = pi.custom_1(23)

value = pi.custom_1(0, 55)

value = pi.custom_1(23, 56, [1, 5, 7])

value = pi.custom_1(23, 56, b"hello")

value = pi.custom_1(23, 56, "hello")

custom_2(arg1, argx, retMax)

-Calls a pigpio function customised by the user. -

Parameters

  arg1:= >=0, default 0.
  argx:= extra arguments (each 0-255), default empty.
retMax:= >=0, maximum number of bytes to return, default 8192.


The returned value is a tuple of the number of bytes -returned and a bytearray containing the bytes. If -there was an error the number of bytes read will be -less than zero (and will contain the error code). -

Example

(count, data) = pi.custom_2()

(count, data) = pi.custom_2(23)

(count, data) = pi.custom_2(23, [1, 5, 7])

(count, data) = pi.custom_2(23, b"hello")

(count, data) = pi.custom_2(23, "hello", 128)

delete_script(script_id)

-Deletes a stored script. -

Parameters

script_id:= id of stored script.


Example

status = pi.delete_script(sid)

event_callback(event, func)

-Calls a user supplied function (a callback) whenever the -specified event is signalled. -

Parameters

event:= 0-31.
 func:= user supplied callback function.


The user supplied callback receives two parameters, the event id, -and the tick. -

If a user callback is not specified a default tally callback is -provided which simply counts events. The count may be retrieved -by calling the tally function. The count may be reset to zero -by calling the reset_tally function. -

The callback may be cancelled by calling the event_cancel function. -

An event may have multiple callbacks (although I can't think of -a reason to do so). -

Example

def cbf(event, tick):
   print(event, tick)

cb1 = pi.event_callback(22, cbf)

cb2 = pi.event_callback(4)

print(cb2.tally())

cb2.reset_tally()

cb1.event_cancel() # To cancel callback cb1.

event_trigger(event)

-This function signals the occurrence of an event. -

Parameters

event:= 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an -interest in the event (e.g. by calling event_callback) will -be informed by a callback. -

One event, EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

Example

pi.event_trigger(23)

file_close(handle)

-Closes the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).


Example

pi.file_close(handle)

file_list(fpattern)

-Returns a list of files which match a pattern. -

Parameters

fpattern:= file pattern to match.


Returns the number of returned bytes if OK, otherwise -PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The -pattern may contain wildcards. See file_open. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

# Assumes /opt/pigpio/access contains the following line:
# /ram/*.c r

c, d = pi.file_list("/ram/p*.c")
if c > 0:
   print(d)

pi.stop()

file_open(file_name, file_mode)

-This function returns a handle to a file opened in a specified mode. -

Parameters

file_name:= the file to open.
file_mode:= the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, -PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE, -PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

Example

h = pi.file_open("/home/pi/shared/dir_3/file.txt",
        pigpio.FILE_WRITE | pigpio.FILE_CREATE)

pi.file_write(h, "Hello world")

pi.file_close(h)


File -

A file may only be opened if permission is granted by an entry -in /opt/pigpio/access. This is intended to allow remote access -to files in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries: -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files -may be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access: -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values: -

ConstantValueMeaning
FILE_READ1open file for reading
FILE_WRITE2open file for writing
FILE_RW3open file for reading and writing


The following values may be or'd into the mode: -

NameValueMeaning
FILE_APPEND4All writes append data to the end of the file
FILE_CREATE8The file is created if it doesn't exist
FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner -read and write. -

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

# Assumes /opt/pigpio/access contains the following line:
# /ram/*.c r

handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ)

done = False

while not done:
   c, d = pi.file_read(handle, 60000)
   if c > 0:
      print(d)
   else:
      done = True

pi.file_close(handle)

pi.stop()

file_read(handle, count)

-Reads up to count bytes from the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.file_read(h2, 100)
if b > 0:
   # process read data

file_seek(handle, seek_offset, seek_from)

-Seeks to a position relative to the start, current position, -or end of the file. Returns the new position. -

Parameters

     handle:= >=0 (as returned by a prior call to file_open).
seek_offset:= byte offset.
  seek_from:= FROM_START, FROM_CURRENT, or FROM_END.


Example

new_pos = pi.file_seek(h, 100, pigpio.FROM_START)

cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT)

file_size = pi.file_seek(h, 0, pigpio.FROM_END)

file_write(handle, data)

-Writes the data bytes to the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).
  data:= the bytes to write.


Example

pi.file_write(h1, b'\x02\x03\x04')

pi.file_write(h2, b'help')

pi.file_write(h2, "hello")

pi.file_write(h1, [2, 3, 4])

get_PWM_dutycycle(user_gpio)

-Returns the PWM dutycycle being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the PWM dutycycle. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported -dutycycle will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

Example

pi.set_PWM_dutycycle(4, 25)
print(pi.get_PWM_dutycycle(4))
25

pi.set_PWM_dutycycle(4, 203)
print(pi.get_PWM_dutycycle(4))
203

get_PWM_frequency(user_gpio)

-Returns the frequency of PWM being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the frequency (in Hz) used for the GPIO. -

For normal PWM the frequency will be that defined for the GPIO -by set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_frequency(4))
800

get_PWM_range(user_gpio)

-Returns the range of PWM values being used on the GPIO. -

Parameters

user_gpio:= 0-31.


If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). -

Example

pi.set_PWM_range(9, 500)
print(pi.get_PWM_range(9))
500

get_PWM_real_range(user_gpio)

-Returns the real (underlying) range of PWM values being -used on the GPIO. -

Parameters

user_gpio:= 0-31.


If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

Example

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_real_range(4))
250

get_current_tick()

-Returns the current system tick. -

Tick is the number of microseconds since system boot. As an -unsigned 32 bit quantity tick wraps around approximately -every 71.6 minutes. -

Example

t1 = pi.get_current_tick()
time.sleep(1)
t2 = pi.get_current_tick()

get_hardware_revision()

-Returns the Pi's hardware revision number. -

The hardware revision is the last few characters on the -Revision line of /proc/cpuinfo. -

The revision number can be used to determine the assignment -of GPIO to pins (see
gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

Example

print(pi.get_hardware_revision())
2

get_mode(gpio)

-Returns the GPIO mode. -

Parameters

gpio:= 0-53.


Returns a value as follows -

0 = INPUT
1 = OUTPUT
2 = ALT5
3 = ALT4
4 = ALT0
5 = ALT1
6 = ALT2
7 = ALT3


Example

print(pi.get_mode(0))
4

get_pad_strength(pad)

-This function returns the pad drive strength in mA. -

Parameters

pad:= 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = pi.get_pad_strength(0) # Get pad 0 strength.

get_pigpio_version()

-Returns the pigpio software version. -

Example

v = pi.get_pigpio_version()

get_servo_pulsewidth(user_gpio)

-Returns the servo pulsewidth being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the servo pulsewidth. -

Example

pi.set_servo_pulsewidth(4, 525)
print(pi.get_servo_pulsewidth(4))
525

pi.set_servo_pulsewidth(4, 2130)
print(pi.get_servo_pulsewidth(4))
2130

gpio_trigger(user_gpio, pulse_len, level)

-Send a trigger pulse to a GPIO. The GPIO is set to -level for pulse_len microseconds and then reset to not level. -

Parameters

user_gpio:= 0-31
pulse_len:= 1-100
    level:= 0-1


Example

pi.gpio_trigger(23, 10, 1)

hardware_PWM(gpio, PWMfreq, PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency -and dutycycle. Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_once, -wave_send_repeat, or wave_chain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. -The main clock defaults to PCM but may be overridden when the -pigpio daemon is started (option -t). -

Parameters

   gpio:= see descripton
PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711).
PWMduty:= 0 (off) to 1000000 (1M)(fully on).


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. -

The same PWM channel is available on multiple GPIO. -The latest frequency and dutycycle setting will be used -by all GPIO which share a PWM channel. -

The GPIO must be one of the following: -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps -for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 -(375 for the BCM2711). Lower frequencies will have more -steps and higher frequencies will have fewer steps. -PWMduty is automatically scaled to take this into account. -

Example

pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle

pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle

hardware_clock(gpio, clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

Parameters

   gpio:= see description
clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following: -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. -

Example

pi.hardware_clock(4, 5000) # 5 KHz clock on GPIO 4

pi.hardware_clock(4, 40000000) # 40 MHz clock on GPIO 4

i2c_block_process_call(handle, reg, data)

-Writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


The SMBus 2.0 documentation states that a minimum of 1 byte may -be sent and a minimum of 1 byte may be received. The total -number of bytes sent/received must be 32 or less. -

SMBus 2.0 5.5.8 - Block write-block read. -S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A]
   S Addr Rd [A] [Count] A [Data] ... A P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00')

(b, d) = pi.i2c_block_process_call(h, 10, b'abcdr')

(b, d) = pi.i2c_block_process_call(h, 10, "abracad")

(b, d) = pi.i2c_block_process_call(h, 10, [2, 5, 16])

i2c_close(handle)

-Closes the I2C device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).


Example

pi.i2c_close(h)

i2c_open(i2c_bus, i2c_address, i2c_flags)

-Returns a handle (>=0) for the device at the I2C bus address. -

Parameters

    i2c_bus:= >=0.
i2c_address:= 0-0x7F.
  i2c_flags:= 0, no flags are currently defined.


Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


For the SMBus commands the low level transactions are shown -at the end of the function description. The following -abbreviations are used: -

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.
Addr  (7 bits): I2C 7 bit address.
reg   (8 bits): Command byte, which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.


Example

h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1

i2c_process_call(handle, reg, word_val)

-Writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.6 - Process call. -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

r = pi.i2c_process_call(h, 4, 0x1231)
r = pi.i2c_process_call(h, 6, 0)

i2c_read_block_data(handle, reg)

-Reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.7 - Block read. -S Addr Wr [A] reg [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P


The amount of returned data is set by the device. -

The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_read_block_data(h, 10)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_byte(handle)

-Reads a single byte from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).


SMBus 2.0 5.5.3 - Receive byte. -S Addr Rd [A] [Data] NA P


Example

b = pi.i2c_read_byte(2) # read a byte from device 2

i2c_read_byte_data(handle, reg)

-Reads a single byte from the specified register of the device -associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read byte. -S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P


Example

# read byte from reg 17 of device 2
b = pi.i2c_read_byte_data(2, 17)

# read byte from reg  1 of device 0
b = pi.i2c_read_byte_data(0, 1)

i2c_read_device(handle, count)

-Returns count bytes read from the raw device associated -with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
 count:= >0, the number of bytes to read.


S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.i2c_read_device(h, 12)

i2c_read_i2c_block_data(handle, reg, count)

-Reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
 count:= >0, the number of bytes to read.


S Addr Wr [A] reg [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_read_i2c_block_data(h, 4, 32)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_word_data(handle, reg)

-Reads a single 16 bit word from the specified register of the -device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read word. -S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

# read word from reg 2 of device 3
w = pi.i2c_read_word_data(3, 2)

# read word from reg 7 of device 2
w = pi.i2c_read_word_data(2, 7)

i2c_write_block_data(handle, reg, data)

-Writes up to 32 bytes to the specified register of the device -associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


SMBus 2.0 5.5.7 - Block write. -S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A]
   datan [A] P


Example

pi.i2c_write_block_data(4, 5, b'hello')

pi.i2c_write_block_data(4, 5, "data bytes")

pi.i2c_write_block_data(5, 0, b'\x00\x01\x22')

pi.i2c_write_block_data(6, 2, [0, 1, 0x22])

i2c_write_byte(handle, byte_val)

-Sends a single byte to the device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.2 - Send byte. -S Addr Wr [A] byte_val [A] P


Example

pi.i2c_write_byte(1, 17)   # send byte   17 to device 1
pi.i2c_write_byte(2, 0x23) # send byte 0x23 to device 2

i2c_write_byte_data(handle, reg, byte_val)

-Writes a single byte to the specified register of the device -associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.4 - Write byte. -S Addr Wr [A] reg [A] byte_val [A] P


Example

# send byte 0xC5 to reg 2 of device 1
pi.i2c_write_byte_data(1, 2, 0xC5)

# send byte 9 to reg 4 of device 2
pi.i2c_write_byte_data(2, 4, 9)

i2c_write_device(handle, data)

-Writes the data bytes to the raw device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the bytes to write.


S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P


Example

pi.i2c_write_device(h, b"\x12\x34\xA8")

pi.i2c_write_device(h, b"help")

pi.i2c_write_device(h, 'help')

pi.i2c_write_device(h, [23, 56, 231])

i2c_write_i2c_block_data(handle, reg, data)

-Writes data bytes to the specified register of the device -associated with handle . 1-32 bytes may be written. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P


Example

pi.i2c_write_i2c_block_data(4, 5, 'hello')

pi.i2c_write_i2c_block_data(4, 5, b'hello')

pi.i2c_write_i2c_block_data(5, 0, b'\x00\x01\x22')

pi.i2c_write_i2c_block_data(6, 2, [0, 1, 0x22])

i2c_write_quick(handle, bit)

-Sends a single bit to the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   bit:= 0 or 1, the value to write.


SMBus 2.0 5.5.1 - Quick command. -S Addr bit [A] P


Example

pi.i2c_write_quick(0, 1) # send 1 to device 0
pi.i2c_write_quick(3, 0) # send 0 to device 3

i2c_write_word_data(handle, reg, word_val)

-Writes a single 16 bit word to the specified register of the -device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.4 - Write word. -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P


Example

# send word 0xA0C5 to reg 5 of device 4
pi.i2c_write_word_data(4, 5, 0xA0C5)

# send word 2 to reg 2 of device 5
pi.i2c_write_word_data(5, 2, 23)

i2c_zip(handle, data)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of data -which contains the concatenated command codes and associated data. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0])


The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

Any read I2C data is concatenated in the returned bytearray. -

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

notify_begin(handle, bits)

-Starts notifications on a handle. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)
  bits:= a 32 bit mask indicating the GPIO to be notified.


The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

The following code starts notifications for GPIO 1, 4, -6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_close(handle)

-Stops notifications on a handle and releases the handle for reuse. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)


Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_close(h)
   ...

notify_open()

-Returns a notification handle (>=0). -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this -function serves no purpose if you are using Python from a -remote machine. The in-built (socket) notifications -provided by
callback should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -

E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

Notifications have the following structure: -

H seqno
H flags
I tick
I level


seqno: starts at 0 each time the handle is opened and then -increments by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the -flags indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep -alive signal on the pipe/socket and is sent once a minute -in the absence of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the -flags indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps -around after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set -then GPIO x is high. -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_pause(handle)

-Pauses notifications on a handle. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)


Notifications for the handle are suspended until -notify_begin is called again. -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_pause(h)
   ...
   pi.notify_begin(h, 1234)
   ...

read(gpio)

-Returns the GPIO level. -

Parameters

gpio:= 0-53.


Example

pi.set_mode(23, pigpio.INPUT)

pi.set_pull_up_down(23, pigpio.PUD_DOWN)
print(pi.read(23))
0

pi.set_pull_up_down(23, pigpio.PUD_UP)
print(pi.read(23))
1

read_bank_1()

-Returns the levels of the bank 1 GPIO (GPIO 0-31). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is high. GPIO n has bit value (1<<n). -

Example

print(bin(pi.read_bank_1()))
0b10010100000011100100001001111

read_bank_2()

-Returns the levels of the bank 2 GPIO (GPIO 32-53). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is high. GPIO n has bit value (1<<(n-32)). -

Example

print(bin(pi.read_bank_2()))
0b1111110000000000000000

run_script(script_id, params)

-Runs a stored script. -

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.run_script(sid, [par1, par2])

s = pi.run_script(sid)

s = pi.run_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

script_status(script_id)

-Returns the run status of a stored script as well as the -current values of parameters 0 to 9. -

Parameters

script_id:= id of stored script.


The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The return value is a tuple of run status and a list of -the 10 parameters. On error the run status will be negative -and the parameter list will be empty. -

Example

(s, pars) = pi.script_status(sid)

serial_close(handle)

-Closes the serial device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


Example

pi.serial_close(h1)

serial_data_available(handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


Example

rdy = pi.serial_data_available(h1)

if rdy > 0:
   (b, d) = pi.serial_read(h1, rdy)

serial_open(tty, baud, ser_flags)

-Returns a handle for the serial tty device opened -at baud bits per second. The device name must start -with /dev/tty or /dev/serial. -

Parameters

      tty:= the serial device to open.
     baud:= baud rate in bits per second, see below.
ser_flags:= 0, no flags are currently defined.


Normally you would only use the serial_* functions if -you are or will be connecting to the Pi over a network. If -you will always run on the local Pi use the standard serial -module instead. -

The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. -

Example

h1 = pi.serial_open("/dev/ttyAMA0", 300)

h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0)

h3 = pi.serial_open("/dev/serial0", 9600)

serial_read(handle, count)

-Reads up to count bytes from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
 count:= >0, the number of bytes to read (defaults to 1000).


The returned value is a tuple of the number of bytes read and -a bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

If no data is ready a bytes read of zero is returned. -Example

(b, d) = pi.serial_read(h2, 100)
if b > 0:
   # process read data

serial_read_byte(handle)

-Returns a single byte from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


If no data is ready a negative error code will be returned. -

Example

b = pi.serial_read_byte(h1)

serial_write(handle, data)

-Writes the data bytes to the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
  data:= the bytes to write.


Example

pi.serial_write(h1, b'\x02\x03\x04')

pi.serial_write(h2, b'help')

pi.serial_write(h2, "hello")

pi.serial_write(h1, [2, 3, 4])

serial_write_byte(handle, byte_val)

-Writes a single byte to the device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to serial_open).
byte_val:= 0-255, the value to write.


Example

pi.serial_write_byte(h1, 23)

pi.serial_write_byte(h1, ord('Z'))

set_PWM_dutycycle(user_gpio, dutycycle)

-Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. -

Parameters

user_gpio:= 0-31.
dutycycle:= 0-range (range defaults to 255).


The set_PWM_range function can change the default range of 255. -

Example

pi.set_PWM_dutycycle(4,   0) # PWM off
pi.set_PWM_dutycycle(4,  64) # PWM 1/4 on
pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on
pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on
pi.set_PWM_dutycycle(4, 255) # PWM full on

set_PWM_frequency(user_gpio, frequency)

-Sets the frequency (in Hz) of the PWM to be used on the GPIO. -

Parameters

user_gpio:= 0-31.
frequency:= >=0 Hz


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4,100000)
print(pi.get_PWM_frequency(4))
8000

set_PWM_range(user_gpio, range_)

-Sets the range of PWM values to be used on the GPIO. -

Parameters

user_gpio:= 0-31.
   range_:= 25-40000.


Example

pi.set_PWM_range(9, 100)  # now  25 1/4,   50 1/2,   75 3/4 on
pi.set_PWM_range(9, 500)  # now 125 1/4,  250 1/2,  375 3/4 on
pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on

set_bank_1(bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.set_bank_1(int("111110010000",2))

set_bank_2(bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.set_bank_2(0x303)

set_glitch_filter(user_gpio, steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

Parameters

user_gpio:= 0-31
   steady:= 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback and wait_for_edge. -

It does not affect levels read by read, -read_bank_1, or read_bank_2. -

Each (stable) edge will be timestamped steady -microseconds after it was first detected. -

Example

pi.set_glitch_filter(23, 100)

set_mode(gpio, mode)

-Sets the GPIO mode. -

Parameters

gpio:= 0-53.
mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5.


Example

pi.set_mode( 4, pigpio.INPUT)  # GPIO  4 as input
pi.set_mode(17, pigpio.OUTPUT) # GPIO 17 as output
pi.set_mode(24, pigpio.ALT2)   # GPIO 24 as ALT2

set_noise_filter(user_gpio, steady, active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level -changes on the GPIO are then reported for active -microseconds after which the process repeats. -

Parameters

user_gpio:= 0-31
   steady:= 0-300000
   active:= 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback and wait_for_edge. -

It does not affect levels read by read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

Example

pi.set_noise_filter(23, 1000, 5000)

set_pad_strength(pad, pad_strength)

-This function sets the pad drive strength in mA. -

Parameters

         pad:= 0-2, the pad to set.
pad_strength:= 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA.

set_pull_up_down(gpio, pud)

-Sets or clears the internal GPIO pull-up/down resistor. -

Parameters

gpio:= 0-53.
 pud:= PUD_UP, PUD_DOWN, PUD_OFF.


Example

pi.set_pull_up_down(17, pigpio.PUD_OFF)
pi.set_pull_up_down(23, pigpio.PUD_UP)
pi.set_pull_up_down(24, pigpio.PUD_DOWN)

set_servo_pulsewidth(user_gpio, pulsewidth)

-Starts (500-2500) or stops (0) servo pulses on the GPIO. -

Parameters

 user_gpio:= 0-31.
pulsewidth:= 0 (off),
             500 (most anti-clockwise) - 2500 (most clockwise).


The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably -be determined by experiment. A value of 1500 should always be -safe and represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its -limits. -

Example

pi.set_servo_pulsewidth(17, 0)    # off
pi.set_servo_pulsewidth(17, 1000) # safe anti-clockwise
pi.set_servo_pulsewidth(17, 1500) # centre
pi.set_servo_pulsewidth(17, 2000) # safe clockwise

set_watchdog(user_gpio, wdog_timeout)

-Sets a watchdog timeout for a GPIO. -

Parameters

   user_gpio:= 0-31.
wdog_timeout:= 0-60000.


The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO -will be triggered every timeout interval after the last -GPIO activity. -

The callback will receive the special level TIMEOUT. -

Example

pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23
pi.set_watchdog(23, 0)    # cancel watchdog on GPIO 23

shell(shellscr, pstring)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

Parameters

shellscr:= the name of the script, only alphanumerics,
              '-' and '_' are allowed in the name
pstring := the parameter string to pass to the script


The exit status of the system call is returned if OK, -otherwise PI_BAD_SHELL_STATUS. -

shellscr must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by -the shell script exit function. If the script can't be -found 32512 will be returned. -

The following table gives some example returned statuses: -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = pi.shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = pi.shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = pi.shell("scr1", "\"hello string with spaces world\"");

spi_close(handle)

-Closes the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).


Example

pi.spi_close(h)

spi_open(spi_channel, baud, spi_flags)

-Returns a handle for the SPI device on the channel. Data -will be transferred at baud bits per second. The flags -may be used to modify the default behaviour of 4-wire -operation, mode 0, active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


Parameters

spi_channel:= 0-1 (0-2 for the auxiliary SPI).
       baud:= 32K-125M (values above 30M are unlikely to work).
  spi_flags:= see below.


spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

WARNING: modes 1 and 3 do not appear to work on -the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per character. -For bits 9-16 there will be two bytes per character. -For bits 17-32 there will be four bytes per character. -

Multi-byte transfers are made in least significant byte -first order. -

E.g. to transfer 32 11-bit words data should -contain 64 bytes. -

E.g. to transfer the 14 bit value 0x1ABC send the -bytes 0xBC followed by 0x1A. -

The other bits in flags should be set to zero. -

Example

# open SPI device on channel 1 in mode 3 at 50000 bits per second

h = pi.spi_open(1, 50000, 3)

spi_read(handle, count)

-Reads count bytes from the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.spi_read(h, 60) # read 60 bytes from device h
if b == 60:
   # process read data
else:
   # error path

spi_write(handle, data)

-Writes the data bytes to the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


Example

pi.spi_write(0, b'\x02\xc0\x80') # write 3 bytes to device 0

pi.spi_write(0, b'defgh')        # write 5 bytes to device 0

pi.spi_write(0, "def")           # write 3 bytes to device 0

pi.spi_write(1, [2, 192, 128])   # write 3 bytes to device 1

spi_xfer(handle, data)

-Writes the data bytes to the SPI device associated with handle, -returning the data bytes read from the device. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00')

(count, rx_data) = pi.spi_xfer(h, [1, 128, 0])

(count, rx_data) = pi.spi_xfer(h, b"hello")

(count, rx_data) = pi.spi_xfer(h, "hello")

stop()

-Release pigpio resources. -

Example

pi.stop()

stop_script(script_id)

-Stops a running script. -

Parameters

script_id:= id of stored script.


Example

status = pi.stop_script(sid)

store_script(script)

-Store a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for -details. -

Parameters

script:= the script text as a series of bytes.


Returns a >=0 script id if OK. -

Example

sid = pi.store_script(
   b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0')

update_script(script_id, params)

-Sets the parameters of a script. The script may or -may not be running. The first parameters of the script are -overwritten with the new values. -

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.update_script(sid, [par1, par2])

s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

wait_for_edge(user_gpio, edge, wait_timeout)

-Wait for an edge event on a GPIO. -

Parameters

   user_gpio:= 0-31.
        edge:= EITHER_EDGE, RISING_EDGE (default), or
               FALLING_EDGE.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the edge is detected or after -the number of seconds specified by timeout has expired. -

Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a callback function. -

The function returns True if the edge is detected, -otherwise False. -

Example

if pi.wait_for_edge(23):
   print("Rising edge detected")
else:
   print("wait for edge timed out")

if pi.wait_for_edge(23, pigpio.FALLING_EDGE, 5.0):
   print("Falling edge detected")
else:
   print("wait for falling edge timed out")

wait_for_event(event, wait_timeout)

-Wait for an event. -

Parameters

       event:= 0-31.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the event is signalled or after -the number of seconds specified by timeout has expired. -

The function returns True if the event is detected, -otherwise False. -

Example

if pi.wait_for_event(23):
   print("event detected")
else:
   print("wait for event timed out")

wave_add_generic(pulses)

-Adds a list of pulses to the current waveform. -

Parameters

pulses:= list of pulses to add to the waveform.


Returns the new total number of pulses in the current waveform. -

The pulses are interleaved in time order within the existing -waveform (if any). -

Merging allows the waveform to be built in parts, that is the -settings for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within -the existing waveform then the first pulse should consist -solely of a delay. -

Example

G1=4
G2=24

pi.set_mode(G1, pigpio.OUTPUT)
pi.set_mode(G2, pigpio.OUTPUT)

flash_500=[] # flash every 500 ms
flash_100=[] # flash every 100 ms

#                              ON     OFF  DELAY

flash_500.append(pigpio.pulse(1<<G1, 1<<G2, 500000))
flash_500.append(pigpio.pulse(1<<G2, 1<<G1, 500000))

flash_100.append(pigpio.pulse(1<<G1, 1<<G2, 100000))
flash_100.append(pigpio.pulse(1<<G2, 1<<G1, 100000))

pi.wave_clear() # clear any existing waveforms

pi.wave_add_generic(flash_500) # 500 ms flashes
f500 = pi.wave_create() # create and save id

pi.wave_add_generic(flash_100) # 100 ms flashes
f100 = pi.wave_create() # create and save id

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_send_repeat(f100)

time.sleep(4)

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_tx_stop() # stop waveform

pi.wave_clear() # clear all waveforms

wave_add_new()

-Starts a new empty waveform. -

You would not normally need to call this function as it is -automatically called after a waveform is created with the -
wave_create function. -

Example

pi.wave_add_new()

wave_add_serial(user_gpio, baud, data, offset, bb_bits, bb_stop)

-Adds a waveform representing serial data to the existing -waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

Parameters

user_gpio:= GPIO to transmit data.  You must set the GPIO mode
            to output.
     baud:= 50-1000000 bits per second.
     data:= the bytes to write.
   offset:= number of microseconds from the start of the
            waveform, default 0.
  bb_bits:= number of data bits, default 8.
  bb_stop:= number of stop half bits, default 2.


Returns the new total number of pulses in the current waveform. -

The serial data is formatted as one start bit, bb_bits -data bits, and bb_stop/2 stop bits. -

It is legal to add serial data streams with different baud -rates to the same waveform. -

The bytes required for each character depend upon bb_bits. -

For bb_bits 1-8 there will be one byte per character. -For bb_bits 9-16 there will be two bytes per character. -For bb_bits 17-32 there will be four bytes per character. -

Example

pi.wave_add_serial(4, 300, 'Hello world')

pi.wave_add_serial(4, 300, b"Hello world")

pi.wave_add_serial(4, 300, b'\x23\x01\x00\x45')

pi.wave_add_serial(17, 38400, [23, 128, 234], 5000)

wave_chain(data)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM -will be cancelled. -

The waves to be transmitted are specified by the contents -of data which contains an ordered list of wave_ids -and optional command codes and related data. -

Returns 0 if OK, otherwise PI_CHAIN_NESTING, -PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, -PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, -or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave -may occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by -using the loop commands. The block is bracketed by loop -start and end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#!/usr/bin/env python

import time
import pigpio

WAVES=5
GPIO=4

wid=[0]*WAVES

pi = pigpio.pi() # Connect to local Pi.

pi.set_mode(GPIO, pigpio.OUTPUT);

for i in range(WAVES):
   pi.wave_add_generic([
      pigpio.pulse(1<<GPIO, 0, 20),
      pigpio.pulse(0, 1<<GPIO, (i+1)*200)]);

   wid[i] = pi.wave_create();

pi.wave_chain([
   wid[4], wid[3], wid[2],       # transmit waves 4+3+2
   255, 0,                       # loop start
      wid[0], wid[0], wid[0],    # transmit waves 0+0+0
      255, 0,                    # loop start
         wid[0], wid[1],         # transmit waves 0+1
         255, 2, 0x88, 0x13,     # delay 5000us
      255, 1, 30, 0,             # loop end (repeat 30 times)
      255, 0,                    # loop start
         wid[2], wid[3], wid[0], # transmit waves 2+3+0
         wid[3], wid[1], wid[2], # transmit waves 3+1+2
      255, 1, 10, 0,             # loop end (repeat 10 times)
   255, 1, 5, 0,                 # loop end (repeat 5 times)
   wid[4], wid[4], wid[4],       # transmit waves 4+4+4
   255, 2, 0x20, 0x4E,           # delay 20000us
   wid[0], wid[0], wid[0],       # transmit waves 0+0+0
   ])

while pi.wave_tx_busy():
   time.sleep(0.1);

for i in range(WAVES):
   pi.wave_delete(wid[i])

pi.stop()

wave_clear()

-Clears all waveforms and any data added by calls to the -wave_add_* functions. -

Example

pi.wave_clear()

wave_create()

-Creates a waveform from the data provided by the prior calls -to the wave_add_* functions. -

Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the wave_add_* functions is consumed by -this function. -

As many waveforms may be created as there is space available. -The wave id is passed to wave_send_* to specify the waveform -to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. -

A pulse specifies -

1) the GPIO to be switched on at the start of the pulse. -2) the GPIO to be switched off at the start of the pulse. -3) the delay in microseconds before the next pulse. -

Any or all the fields can be zero. It doesn't make any sense -to set all the fields to zero (the pulse will be ignored). -

When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. -

Example

wid = pi.wave_create()

wave_create_and_pad(percent)

-This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use -(in terms of the theoretical maximum, not the current amount free). -This allows the reuse of deleted waves while a transmission is active. -

Upon success a wave id greater than or equal to 0 is returned, otherwise -PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

A usage would be the creation of two waves where one is filled while the -other is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Normal usage: -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create_and_pad to create a waveform of uniform size. -

Step 4. wave_send_* with the id of the waveform to transmit. -

Repeat steps 2-4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

Example

wid = pi.wave_create_and_pad(50)

wave_delete(wave_id)

-This function deletes the waveform with id wave_id. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Example

pi.wave_delete(6) # delete waveform with id 6

pi.wave_delete(0) # delete waveform with id 0

wave_get_cbs()

-Returns the length in DMA control blocks of the current -waveform. -

Example

cbs = pi.wave_get_cbs()

wave_get_max_cbs()

-Returns the maximum possible size of a waveform in DMA -control blocks. -

Example

cbs = pi.wave_get_max_cbs()

wave_get_max_micros()

-Returns the maximum possible size of a waveform in microseconds. -

Example

micros = pi.wave_get_max_micros()

wave_get_max_pulses()

-Returns the maximum possible size of a waveform in pulses. -

Example

pulses = pi.wave_get_max_pulses()

wave_get_micros()

-Returns the length in microseconds of the current waveform. -

Example

micros = pi.wave_get_micros()

wave_get_pulses()

-Returns the length in pulses of the current waveform. -

Example

pulses = pi.wave_get_pulses()

wave_send_once(wave_id)

-Transmits the waveform with id wave_id. The waveform is sent -once. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_once(wid)

wave_send_repeat(wave_id)

-Transmits the waveform with id wave_id. The waveform repeats -until wave_tx_stop is called or another call to wave_send_* -is made. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_repeat(wid)

wave_send_using_mode(wave_id, mode)

-Transmits the waveform with id wave_id using mode mode. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).
   mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT,
          WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC.


WAVE_MODE_ONE_SHOT: same as wave_send_once. -

WAVE_MODE_REPEAT same as wave_send_repeat. -

WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries -to sync with the previous waveform. -

WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries -to sync with the previous waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC)

wave_tx_at()

-Returns the id of the waveform currently being -transmitted. -

Returns the waveform id or one of the following special -values: -

WAVE_NOT_FOUND (9998) - transmitted wave not found. -NO_TX_WAVE (9999) - no wave being transmitted. -

Example

wid = pi.wave_tx_at()

wave_tx_busy()

-Returns 1 if a waveform is currently being transmitted, -otherwise 0. -

Example

pi.wave_send_once(0) # send first waveform

while pi.wave_tx_busy(): # wait for waveform to be sent
   time.sleep(0.1)

pi.wave_send_once(1) # send next waveform

wave_tx_repeat()

-This function is deprecated and has beeen removed. -

Use
wave_create/wave_send_* instead. -

wave_tx_start()

-This function is deprecated and has been removed. -

Use
wave_create/wave_send_* instead. -

wave_tx_stop()

-Stops the transmission of the current waveform. -

This function is intended to stop a waveform started with -wave_send_repeat. -

Example

pi.wave_send_repeat(3)

time.sleep(5)

pi.wave_tx_stop()

write(gpio, level)

-Sets the GPIO level. -

Parameters

 GPIO:= 0-53.
level:= 0, 1.


If PWM or servo pulses are active on the GPIO they are -switched off. -

Example

pi.set_mode(17, pigpio.OUTPUT)

pi.write(17,0)
print(pi.read(17))
0

pi.write(17,1)
print(pi.read(17))
1

class pulse -

pigpio.pulse(gpio_on, gpio_off, delay)

-Initialises a pulse. -

Parameters

 gpio_on:= the GPIO to switch on at the start of the pulse.
gpio_off:= the GPIO to switch off at the start of the pulse.
   delay:= the delay in microseconds before the next pulse.

FUNCTIONS

pigpio.error_text(errnum)

-Returns a text description of a pigpio error. -

Parameters

errnum:= <0, the error number


Example

print(pigpio.error_text(-5))
level not 0-1

pigpio.tickDiff(t1, t2)

-Returns the microsecond difference between two ticks. -

Parameters

t1:= the earlier tick
t2:= the later tick


Example

print(pigpio.tickDiff(4294967272, 12))
36

pigpio.u2i(uint32)

-Converts a 32 bit unsigned number to signed. -

Parameters

uint32:= an unsigned 32 bit number


Example

print(u2i(4294967272))
-24
print(u2i(37))
37

PARAMETERS

active: 0-1000000

The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

arg1:

An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2:

An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argx:

An array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud:

The speed of serial communication (I2C, SPI, serial link, waves) -in bits per second. -

bb_bits: 1-32

The number of data bits to be used when adding serial data to a -waveform. -

bb_stop: 2-8

The number of (half) stop bits to be used when adding serial data -to a waveform. -

bit: 0-1

A value of 0 or 1. -

bits: 32 bit number

A mask used to select GPIO to be operated on. If bit n is set -then GPIO n is selected. A convenient way of setting bit n is to -bit or in the value (1<<n). -

To select GPIO 1, 7, 23 -

bits = (1<<1) | (1<<7) | (1<<23) -

bsc_control:

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) -

Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document. -

byte_val: 0-255

A whole number. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

The hardware clock frequency. -

connected:

True if a connection was established, False otherwise. -

count:

The number of bytes of data to be transferred. -

CS:

The GPIO used for the slave select signal when bit banging SPI. -

data:

Data to be transmitted, a series of bytes. -

delay: >=1

The length of a pulse in microseconds. -

dutycycle: 0-range_

A number between 0 and range_. -

The dutycycle sets the proportion of time on versus time off during each -PWM cycle. -

DutycycleOn time
0Off
range_ * 0.2525% On
range_ * 0.5050% On
range_ * 0.7575% On
range_Fully On

edge: 0-2

EITHER_EDGE = 2
FALLING_EDGE = 1
RISING_EDGE = 0

errnum: <0

PI_BAD_USER_GPIO = -2
PI_BAD_GPIO = -3
PI_BAD_MODE = -4
PI_BAD_LEVEL = -5
PI_BAD_PUD = -6
PI_BAD_PULSEWIDTH = -7
PI_BAD_DUTYCYCLE = -8
PI_BAD_WDOG_TIMEOUT = -15
PI_BAD_DUTYRANGE = -21
PI_NO_HANDLE = -24
PI_BAD_HANDLE = -25
PI_BAD_WAVE_BAUD = -35
PI_TOO_MANY_PULSES = -36
PI_TOO_MANY_CHARS = -37
PI_NOT_SERIAL_GPIO = -38
PI_NOT_PERMITTED = -41
PI_SOME_PERMITTED = -42
PI_BAD_WVSC_COMMND = -43
PI_BAD_WVSM_COMMND = -44
PI_BAD_WVSP_COMMND = -45
PI_BAD_PULSELEN = -46
PI_BAD_SCRIPT = -47
PI_BAD_SCRIPT_ID = -48
PI_BAD_SER_OFFSET = -49
PI_GPIO_IN_USE = -50
PI_BAD_SERIAL_COUNT = -51
PI_BAD_PARAM_NUM = -52
PI_DUP_TAG = -53
PI_TOO_MANY_TAGS = -54
PI_BAD_SCRIPT_CMD = -55
PI_BAD_VAR_NUM = -56
PI_NO_SCRIPT_ROOM = -57
PI_NO_MEMORY = -58
PI_SOCK_READ_FAILED = -59
PI_SOCK_WRIT_FAILED = -60
PI_TOO_MANY_PARAM = -61
PI_SCRIPT_NOT_READY = -62
PI_BAD_TAG = -63
PI_BAD_MICS_DELAY = -64
PI_BAD_MILS_DELAY = -65
PI_BAD_WAVE_ID = -66
PI_TOO_MANY_CBS = -67
PI_TOO_MANY_OOL = -68
PI_EMPTY_WAVEFORM = -69
PI_NO_WAVEFORM_ID = -70
PI_I2C_OPEN_FAILED = -71
PI_SER_OPEN_FAILED = -72
PI_SPI_OPEN_FAILED = -73
PI_BAD_I2C_BUS = -74
PI_BAD_I2C_ADDR = -75
PI_BAD_SPI_CHANNEL = -76
PI_BAD_FLAGS = -77
PI_BAD_SPI_SPEED = -78
PI_BAD_SER_DEVICE = -79
PI_BAD_SER_SPEED = -80
PI_BAD_PARAM = -81
PI_I2C_WRITE_FAILED = -82
PI_I2C_READ_FAILED = -83
PI_BAD_SPI_COUNT = -84
PI_SER_WRITE_FAILED = -85
PI_SER_READ_FAILED = -86
PI_SER_READ_NO_DATA = -87
PI_UNKNOWN_COMMAND = -88
PI_SPI_XFER_FAILED = -89
PI_NO_AUX_SPI = -91
PI_NOT_PWM_GPIO = -92
PI_NOT_SERVO_GPIO = -93
PI_NOT_HCLK_GPIO = -94
PI_NOT_HPWM_GPIO = -95
PI_BAD_HPWM_FREQ = -96
PI_BAD_HPWM_DUTY = -97
PI_BAD_HCLK_FREQ = -98
PI_BAD_HCLK_PASS = -99
PI_HPWM_ILLEGAL = -100
PI_BAD_DATABITS = -101
PI_BAD_STOPBITS = -102
PI_MSG_TOOBIG = -103
PI_BAD_MALLOC_MODE = -104
PI_BAD_SMBUS_CMD = -107
PI_NOT_I2C_GPIO = -108
PI_BAD_I2C_WLEN = -109
PI_BAD_I2C_RLEN = -110
PI_BAD_I2C_CMD = -111
PI_BAD_I2C_BAUD = -112
PI_CHAIN_LOOP_CNT = -113
PI_BAD_CHAIN_LOOP = -114
PI_CHAIN_COUNTER = -115
PI_BAD_CHAIN_CMD = -116
PI_BAD_CHAIN_DELAY = -117
PI_CHAIN_NESTING = -118
PI_CHAIN_TOO_BIG = -119
PI_DEPRECATED = -120
PI_BAD_SER_INVERT = -121
PI_BAD_FOREVER = -124
PI_BAD_FILTER = -125
PI_BAD_PAD = -126
PI_BAD_STRENGTH = -127
PI_FIL_OPEN_FAILED = -128
PI_BAD_FILE_MODE = -129
PI_BAD_FILE_FLAG = -130
PI_BAD_FILE_READ = -131
PI_BAD_FILE_WRITE = -132
PI_FILE_NOT_ROPEN = -133
PI_FILE_NOT_WOPEN = -134
PI_BAD_FILE_SEEK = -135
PI_NO_FILE_MATCH = -136
PI_NO_FILE_ACCESS = -137
PI_FILE_IS_A_DIR = -138
PI_BAD_SHELL_STATUS = -139
PI_BAD_SCRIPT_NAME = -140
PI_BAD_SPI_BAUD = -141
PI_NOT_SPI_GPIO = -142
PI_BAD_EVENT_ID = -143
PI_CMD_INTERRUPTED = -144
PI_NOT_ON_BCM2711   = -145
PI_ONLY_ON_BCM2711  = -146

event: 0-31

An event is a signal used to inform one or more consumers -to start an action. -

file_mode:

The mode may have the following values -

FILE_READ   1
FILE_WRITE  2
FILE_RW     3


The following values can be or'd into the file open mode -

FILE_APPEND 4
FILE_CREATE 8
FILE_TRUNC  16

file_name:

A full file path. To be accessible the path must match -an entry in /opt/pigpio/access. -

fpattern:

A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: 0-40000

Defines the frequency to be used for PWM on a GPIO. -The closest permitted frequency will be used. -

func:

A user supplied callback function. -

gpio: 0-53

A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. -

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 get_hardware_revision. -

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  -  -  -  -

gpio_off:

A mask used to select GPIO to be operated on. See bits. -

This mask selects the GPIO to be switched off at the start -of a pulse. -

gpio_on:

A mask used to select GPIO to be operated on. See bits. -

This mask selects the GPIO to be switched on at the start -of a pulse. -

handle: >=0

A number referencing an object opened by one of the following -

file_open -i2c_open -notify_open -serial_open -spi_open -

host:

The name or IP address of the Pi running the pigpio daemon. -

i2c_address: 0-0x7F

The address of a device on the I2C bus. -

i2c_bus: >=0

An I2C bus number. -

i2c_flags: 0

No I2C flags are currently defined. -

invert: 0-1

A flag used to set normal or inverted bit bang serial data -level logic. -

level: 0-1 (2)

CLEAR = 0
HIGH = 1
LOW = 0
OFF = 0
ON = 1
SET = 1
TIMEOUT = 2 # only returned for a watchdog timeout

MISO:

The GPIO used for the MISO signal when bit banging SPI. -

mode:

1.The operational mode of a GPIO, normally INPUT or OUTPUT. -

ALT0 = 4
ALT1 = 5
ALT2 = 6
ALT3 = 7
ALT4 = 3
ALT5 = 2
INPUT = 0
OUTPUT = 1


2. The mode of waveform transmission. -

WAVE_MODE_ONE_SHOT = 0
WAVE_MODE_REPEAT = 1
WAVE_MODE_ONE_SHOT_SYNC = 2
WAVE_MODE_REPEAT_SYNC = 3

MOSI:

The GPIO used for the MOSI signal when bit banging SPI. -

offset: >=0

The offset wave data starts from the beginning of the waveform -being currently defined. -

pad: 0-2

A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

pad_strength: 1-16

The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

params: 32 bit number

When scripts are started they can receive up to 10 parameters -to define their operation. -

percent: : 0-100

The size of waveform as percentage of maximum available. -

port:

The port used by the pigpio daemon, defaults to 8888. -

pstring:

The string to be passed to a shell script to be executed. -

pud: 0-2

PUD_DOWN = 1
PUD_OFF = 0
PUD_UP = 2

pulse_len: 1-100

The length of the trigger pulse in microseconds. -

pulses:

A list of class pulse objects defining the characteristics of a -waveform. -

pulsewidth:

The servo pulsewidth in microseconds. 0 switches pulses off. -

PWMduty: 0-1000000 (1M)

The hardware PWM dutycycle. -

PWMfreq: 1-125M (1-187.5M for the BCM2711)

The hardware PWM frequency. -

range_: 25-40000

Defines the limits for the dutycycle parameter. -

range_ defaults to 255. -

reg: 0-255

An I2C device register. The usable registers depend on the -actual device. -

retMax: >=0

The maximum number of bytes a user customised function -should return, default 8192. -

SCL:

The user GPIO to use for the clock when bit banging I2C. -

SCLK: :

The GPIO used for the SCLK signal when bit banging SPI. -

script:

The text of a script to store on the pigpio daemon. -

script_id: >=0

A number referencing a script created by store_script. -

SDA:

The user GPIO to use for data when bit banging I2C. -

seek_from: 0-2

Direction to seek for file_seek. -

FROM_START=0
FROM_CURRENT=1
FROM_END=2

seek_offset:

The number of bytes to move forward (positive) or backwards -(negative) from the seek position (start, current, or end of file). -

ser_flags: 32 bit

No serial flags are currently defined. -

serial_*:

One of the serial_ functions. -

shellscr:

The name of a shell script. The script must exist -in /opt/pigpio/cgi and must be executable. -

show_errors:

Controls the display of pigpio daemon connection failures. -The default of True prints the probable failure reasons to -standard output. -

spi_channel: 0-2

A SPI channel. -

spi_flags: 32 bit

See spi_open. -

steady: 0-300000

The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) -or triggering the active part of a noise filter -(set_noise_filter). -

t1:

A tick (earlier). -

t2:

A tick (later). -

tty:

A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0 -

uint32:

An unsigned 32 bit number. -

user_gpio: 0-31

A Broadcom numbered GPIO. -

All the user GPIO are in the range 0-31. -

Not all the GPIO within this range are usable, some are reserved -for system use. -

See gpio. -

wait_timeout: 0.0 -

The number of seconds to wait in wait_for_edge before timing out. -

wave_add_*:

One of the following -

wave_add_new -wave_add_generic -wave_add_serial -

wave_id: >=0

A number referencing a wave created by wave_create. -

wave_send_*:

One of the following -

wave_send_once -wave_send_repeat -

wdog_timeout: 0-60000

Defines a GPIO watchdog timeout in milliseconds. If no level -change is detected on the GPIO for timeout millisecond a watchdog -timeout report is issued (with level TIMEOUT). -

word_val: 0-65535

A whole number. -

\ No newline at end of file diff --git a/DOC/tmp/body/sif.body b/DOC/tmp/body/sif.body deleted file mode 100644 index 1274ee9..0000000 --- a/DOC/tmp/body/sif.body +++ /dev/null @@ -1,1994 +0,0 @@ - -pigpio provides a socket interface to many of its functions.
-
-The socket interface is available whenever pigpio is running, -either because it has been started as a daemon, or it has been -linked in to a running user program.
-
-The socket interface can be disabled by the program which -initialises the library.  pigpiod offers the -k option to -disable the socket interface.  User programs should call -gpioCfgInterfaces if they -wish to disable the socket interface.
-
-pigpio listens for connections on port 8888 by default.  This -default may be overridden when pigpio starts by the gpioCfgSocketPort function -call.  The pigpio daemon uses this function to provide an -option to change the port number.
-
-The pigs utility is an example of using the socket interface from -C.
-

Request

-

pigpio expects messages of type cmdCmd_t immediately followed with an -extension for a few commands.
-
-The caller should fill in cmd, p1, p2, p3/res, and any extension as -needed.  p3 will always be zero unless the command requires an -extension in which case p3 will be the length in bytes of the -extension.
-
-The cmdCmd_t is echoed back with -the result, if any, in p3/res, and an extension immediately -afterwards for a few commands.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
COMMANDcmd
p1p2p3Extension
MODES0gpiomode0-
MODEG1gpio00-
PUD2gpiopud0-
READ3gpio00-
WRITE4gpiolevel0-
PWM5gpiodutycycle0-
PRS6gpiorange0-
PFS7gpiofrequency0-
SERVO8gpiopulsewidth0-
WDOG9gpiotimeout0-
BR110000-
BR211000-
BC112bits00-
BC213bits00-
BS114bits00-
BS215bits00-
TICK16000-
HWVER17000-
NO18000-
NB19handlebits0-
NP20handle00-
NC21handle00-
PRG22gpio00-
PFG23gpio00-
PRRG24gpio00-
HELP
25N/A
N/A
N/A
N/A
PIGPV26000-
WVCLR27000-
WVAG280012*XgpioPulse_t pulse[X]
WVAS29gpiobaud12+Xuint32_t databits
-uint32_t stophalfbits
-uint32_t offset
-uint8_t data[X]
N/A
30000-
N/A
31000-
WVBSY32000-
WVHLT33000-
WVSM34subcmd00-
WVSP35subcmd00-
WVSC36subcmd00-
TRIG37gpiopulselen4uint32_t level
PROC3800Xuint8_t text[X]
PROCD39script_id00-
PROCR40script_id04*X
uint32_t pars[X]
PROCS41script_id00-
SLRO42gpiobaud4uint32_t databits
SLR43gpiocount0-
SLRC44gpio00-
PROCP45script_id00-
MICS46micros00-
MILS47millis00-
PARSE48N/AN/A
N/A
N/A
WVCRE49000-
WVDEL50wave_id00-
WVTX51wave_id00-
WVTXR52wave_id00-
WVNEW53000-
I2CO54busdevice4uint32_t flags
I2CC55handle00-
I2CRD56handlecount0-
I2CWD57handle0Xuint8_t data[X]
I2CWQ58handlebit0-
I2CRS59handle00-
I2CWS60handlebyte0-
I2CRB61handleregister0-
I2CWB62handleregister4uint32_t byte
I2CRW63handleregister0-
I2CWW64handleregister4uint32_t word
I2CRK65handleregister
0-
I2CWK66handleregister
Xuint8_t bvs[X]
I2CRI67handleregister
4uint32_t num
I2CWI68handleregister
X
uint8_t bvs[X]
I2CPC69handleregister
4uint32_t word
I2CPK70handleregister
X
uint8_t data[X]
SPIO
71channelbaud4uint32_t flags
SPIC72handle00-
SPIR73handlecount0-
SPIW74handle0Xuint8_t data[X]
SPIX75handle0Xuint8_t data[X]
SERO76baudflagsXuint8_t device[X]
SERC77handle00-
SERRB78handle00-
SERWB79handlebyte0-
SERR80handlecount0-
SERW81handle0Xuint8_t data[X]
SERDA82handle00-
GDC
83
gpio
0
0
-
GPW
84
gpio
0
0
-
HC
85
gpio
frequency
0
-
HP
86
gpio
frequency
4
uint32_t dutycycle
CF1
87
arg1
arg2
X
uint8_t argx[X]
CF2
88
arg1
retMax
X
uint8_t argx[X]
BI2CC
89
sda
0
0
-
BI2CO
90
sda
scl
4
uint32_t baud
BI2CZ
91
sda
0
X
uint8_t data[X]
I2CZ
92
handle
0
X
uint8_t data[X]
WVCHA
93
0
0
X
uint8_t data[X]
SLRI
94
gpio
invert
0
-
CGI
95
0
0
0
-
CSI
96
config
0
0
-
FG
97
gpio
steady
0
-
FN
98
gpio
steady
4
uint32_t active
NOIB99000-
WVTXM
100
wave_id
mode
0
-
WVTAT
101
0
0
0
-
PADS
102
pad
strength
0
-
PADG
103
pad
0
0
-
FO
104
mode
0
X
uint8_t file[X]
FC
105
handle
0
0
-
FR
106
handle
count
0
-
FW
107
handle
0
X
uint8_t data[X]
FS
108
handle
offset
4
uint32_t from
FL
109
count
0
X
uint8_t pattern[X]
SHELL
110
len(name)
0
len(name)+
-1+
-len(string)
uint8_t name[len(name)]
-uint8_t null (0)
-uint8_t string[len(string)]
BSPIC
111
CS
0
0
-
BSPIO
112
CS
0
20
uint32_t MISO
-uint32_t MOSI
-uint32_t SCLK
-uint32_t baud
-uint32_t spi_flags
BSPIX
113
CS
0
X
uint8_t data[X]
BSCX
114
control
0
X
uint8_t data[X]
EVM
115
handle
bits
0
-
EVT
116
event
0
0
-
PROCU
117
script_id
0
4*X
uint32_t pars[X]
-

Response

-

The response has cmd/p1/p2 as in the request.  p3/res holds -the return value.  If the command returns additional values -they will be in the immediately following extension.

-Normally res should be treated as a 32 bit signed value and will be -greater than or equal to zero.  Upon failure res will be less -than 0 and contains an error code.
-

There are a few commands where the returned value should be -treated as a 32 bit unsigned value.  These commands can not -fail.  They are indicated with a * after the command -name.

-

Commands with an extension have the size of the extension in -bytes returned in res (or <0 on error as above).

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
COMMANDcmd
p1
p2
res
Extension
MODES0-
-
0-
MODEG1-
-
mode
-
PUD2-
-
0-
READ3-
-
level
-
WRITE4-
-
0-
PWM5-
-
0-
PRS6-
-
0-
PFS7-
-
0-
SERVO8-
-
0-
WDOG9-
-
0-
BR1 *10-
-
bits
-
BR2 *11-
-
bits
-
BC112-
-
0-
BC213-
-
0-
BS114-
-
0-
BS215-
-
0-
TICK *
16-
-
tick
-
HWVER *
17-
-
version
-
NO18-
-
handle
-
NB19-
-
0-
NP20-
-
0-
NC21-
-
0-
PRG22-
-
range
-
PFG23-
-
frequency
-
PRRG24-
-
real range
-
HELP25-
-
N/A
N/A
PIGPV *
26-
-
version
-
WVCLR27-
-
0-
WVAG28-
-
wave pulses
-
WVAS29-
-
wave pulses
-
N/A
30-
-
-
-
N/A
31-
-
-
-
WVBSY32-
-
busy (1) or not busy (0)
-
WVHLT33-
-
0-
WVSM34-
-
wave micros
-wave micros - high
-wave micros - max
-
WVSP35-
-
wave pulses
-wave pulses - high
-wave pulses - max
-
WVSC36-
-
wave DMA CBs
-wave DMA CBs - high
-wave DMA CBs - max
-
TRIG37-
-
0
-
PROC38-
-
script id
-
PROCD39-
-
0-
PROCR40-
-
script status
-
PROCS41-
-
0-
SLRO42-
-
0
-
SLR43-
-
X
uint8_t data[X]
SLRC44-
-
0-
PROCP45-
-
44uint32_t script_status
-uint32_t pars[10]
MICS46-
-
0-
MILS47-
-
0-
PARSE48-
-
N/A
-
WVCRE49-
-
wave id
-
WVDEL50-
-
0-
WVTX51-
-
wave DMA CBs
-
WVTXR52-
-
wave DMA CBs
-
WVNEW53-
-
0-
I2CO54-
-
handle-
I2CC55-
-
0-
I2CRD56-
-
X
uint8_t data[X]
I2CWD57-
-
0
-
I2CWQ58-
-
0-
I2CRS59-
-
byte value
-
I2CWS60-
-
0-
I2CRB61-
-
byte value
-
I2CWB62-
-
0
-
I2CRW63-
-
word value
-
I2CWW64-
-
0
-
I2CRK65-
-
0-
I2CWK66-
-
0
-
I2CRI67-
-
X
uint8_t data[X]
I2CWI68-
-
0
-
I2CPC69-
-
word value
-
I2CPK70-
-
X
uint8_t data[X]
SPIO
71-
-
handle
-
SPIC72-
-
0-
SPIR73-
-
X
uint8_t data[X]
SPIW74-
-
0
-
SPIX75-
-
Xuint8_t data[X]
SERO76-
-
handle
-
SERC77-
-
0-
SERRB78-
-
byte value
-
SERWB79-
-
0-
SERR80-
-
X
uint8_t data[X]
SERW81-
-
0
-
SERDA82-
-
data ready count
-
GDC
83
-
-
dutycycle
-
GPW
84
-
-
pulsewidth
-
HC
85
-
-
0
-
HP
86
-
-
0
-
CF1
87
-
-
value
-
CF2
88
-
-
X
uint8_t retBuf[X]
BI2CC
89
-
-
0
-
BI2CO
90
-
-
handle
-
BI2CZ
91
-
-
X
uint8_t data[X]
I2CZ
92
-
-
X
uint8_t data[X]
WVCHA
93
-
-
0
-
SLRI
94
-
-
0
-
CGI
95
-
-
config
-
CSI
96
-
-
0
-
FG
97
-
-
0
-
FN
98
-
-
0
-
NOIB99-
-
0-
WVTXM
100
-
-
wave DMA CBs
-
WVTAT
101
-
-
wave id
-
PADS
102
-
-
0
-
PADG
103
-
-
strength
-
FO
104
-
-
handle
-
FC
105
-
-
0
-
FR
106
-
-
X
uint8_t data[X]
FW
107
-
-
0
-
FS
108
-
-
position
-
FL
109
-
-
X
uint8_t filenames[X]
SHELL
110
-
-
exit status
-
BSPIC
111
-
-
0
-
BSPIO
112
-
-
0
-
BSPIX
113
-
-
X
uint8_t data[X]
BSCX
114
-
-
X+4
uint32_t status
-uint8_t data[X]
EVM
115
-
-
0
-
EVT
116
-
-
0
-
PROCU
117
-
-
0
-
-
-

cmdCmd_t

-typedef struct
-{
-   uint32_t cmd;
-   uint32_t p1;
-   uint32_t p2;
-   union
-   {
-      uint32_t p3;
-      uint32_t ext_len;
-      uint32_t res;
-   };
-} cmdCmd_t;

diff --git a/DOC/tmp/pydoc/pigpio.pydoc b/DOC/tmp/pydoc/pigpio.pydoc deleted file mode 100644 index c5dbdc2..0000000 --- a/DOC/tmp/pydoc/pigpio.pydoc +++ /dev/null @@ -1,4162 +0,0 @@ -Help on module pigpio: - -NAME - pigpio - -FILE - /mnt/d/Users/guy/Projects/pigpio/pigpio.py - -DESCRIPTION - pigpio is a Python module for the Raspberry which talks to - the pigpio daemon to allow control of the general purpose - input outputs (GPIO). - - [http://abyz.me.uk/rpi/pigpio/python.html] - - *Features* - - o the pigpio Python module can run on Windows, Macs, or Linux - - o controls one or more Pi's - - o hardware timed PWM on any of GPIO 0-31 - - o hardware timed servo pulses on any of GPIO 0-31 - - o callbacks when any of GPIO 0-31 change state - - o creating and transmitting precisely timed waveforms - - o reading/writing GPIO and setting their modes - - o wrappers for I2C, SPI, and serial links - - o creating and running scripts on the pigpio daemon - - *GPIO* - - ALL GPIO are identified by their Broadcom number. - - *Notes* - - Transmitted waveforms are accurate to a microsecond. - - Callback level changes are time-stamped and will be - accurate to within a few microseconds. - - *Settings* - - A number of settings are determined when the pigpio daemon is started. - - o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). - - o the set of GPIO which may be updated (generally written to). The - default set is those available on the Pi board revision. - - o the available PWM frequencies (see [*set_PWM_frequency*]). - - *Exceptions* - - By default a fatal exception is raised if you pass an invalid - argument to a pigpio function. - - If you wish to handle the returned status yourself you should set - pigpio.exceptions to False. - - You may prefer to check the returned status in only a few parts - of your code. In that case do the following: - - ... - pigpio.exceptions = False - - # Code where you want to test the error status. - - pigpio.exceptions = True - ... - - *Usage* - - This module uses the services of the C pigpio library. pigpio - must be running on the Pi(s) whose GPIO are to be manipulated. - - The normal way to start pigpio is as a daemon (during system - start). - - sudo pigpiod - - Your Python program must import pigpio and create one or more - instances of the pigpio.pi class. This class gives access to - a specified Pi's GPIO. - - ... - pi1 = pigpio.pi() # pi1 accesses the local Pi's GPIO - pi2 = pigpio.pi('tom') # pi2 accesses tom's GPIO - pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO - - pi1.write(4, 0) # set local Pi's GPIO 4 low - pi2.write(4, 1) # set tom's GPIO 4 to high - pi3.read(4) # get level of dick's GPIO 4 - ... - - The later example code snippets assume that pi is an instance of - the pigpio.pi class. - - OVERVIEW - - ESSENTIAL - - pigpio.pi Initialise Pi connection - stop Stop a Pi connection - - BASIC - - set_mode Set a GPIO mode - get_mode Get a GPIO mode - - set_pull_up_down Set/clear GPIO pull up/down resistor - - read Read a GPIO - write Write a GPIO - - PWM_(overrides_servo_commands_on_same_GPIO) - - set_PWM_dutycycle Start/stop PWM pulses on a GPIO - set_PWM_frequency Set PWM frequency of a GPIO - set_PWM_range Configure PWM range of a GPIO - - get_PWM_dutycycle Get PWM dutycycle set on a GPIO - get_PWM_frequency Get PWM frequency of a GPIO - get_PWM_range Get configured PWM range of a GPIO - - get_PWM_real_range Get underlying PWM range for a GPIO - - Servo_(overrides_PWM_commands_on_same_GPIO) - - set_servo_pulsewidth Start/Stop servo pulses on a GPIO - - get_servo_pulsewidth Get servo pulsewidth set on a GPIO - - INTERMEDIATE - - gpio_trigger Send a trigger pulse to a GPIO - - set_watchdog Set a watchdog on a GPIO - - read_bank_1 Read all bank 1 GPIO - read_bank_2 Read all bank 2 GPIO - - clear_bank_1 Clear selected GPIO in bank 1 - clear_bank_2 Clear selected GPIO in bank 2 - - set_bank_1 Set selected GPIO in bank 1 - set_bank_2 Set selected GPIO in bank 2 - - callback Create GPIO level change callback - - wait_for_edge Wait for GPIO level change - - ADVANCED - - notify_open Request a notification handle - notify_begin Start notifications for selected GPIO - notify_pause Pause notifications - notify_close Close a notification - - hardware_clock Start hardware clock on supported GPIO - - hardware_PWM Start hardware PWM on supported GPIO - - set_glitch_filter Set a glitch filter on a GPIO - set_noise_filter Set a noise filter on a GPIO - - set_pad_strength Sets a pads drive strength - get_pad_strength Gets a pads drive strength - - shell Executes a shell command - - Custom - - custom_1 User custom function 1 - custom_2 User custom function 2 - - Events - - event_callback Sets a callback for an event - - event_trigger Triggers an event - - wait_for_event Wait for an event - - Scripts - - store_script Store a script - run_script Run a stored script - update_script Set a scripts parameters - script_status Get script status and parameters - stop_script Stop a running script - delete_script Delete a stored script - - I2C - - i2c_open Opens an I2C device - i2c_close Closes an I2C device - - i2c_write_quick SMBus write quick - - i2c_read_byte SMBus read byte - i2c_write_byte SMBus write byte - - i2c_read_byte_data SMBus read byte data - i2c_write_byte_data SMBus write byte data - - i2c_read_word_data SMBus read word data - i2c_write_word_data SMBus write word data - - i2c_read_block_data SMBus read block data - i2c_write_block_data SMBus write block data - - i2c_read_i2c_block_data SMBus read I2C block data - i2c_write_i2c_block_data SMBus write I2C block data - - i2c_read_device Reads the raw I2C device - i2c_write_device Writes the raw I2C device - - i2c_process_call SMBus process call - i2c_block_process_call SMBus block process call - - i2c_zip Performs multiple I2C transactions - - I2C_BIT_BANG - - bb_i2c_open Opens GPIO for bit banging I2C - bb_i2c_close Closes GPIO for bit banging I2C - - bb_i2c_zip Performs multiple bit banged I2C transactions - - I2C/SPI_SLAVE - - bsc_xfer I2C/SPI as slave transfer - bsc_i2c I2C as slave transfer - - SERIAL - - serial_open Opens a serial device - serial_close Closes a serial device - - serial_read_byte Reads a byte from a serial device - serial_write_byte Writes a byte to a serial device - - serial_read Reads bytes from a serial device - serial_write Writes bytes to a serial device - - serial_data_available Returns number of bytes ready to be read - - SERIAL_BIT_BANG_(read_only) - - bb_serial_read_open Open a GPIO for bit bang serial reads - bb_serial_read_close Close a GPIO for bit bang serial reads - - bb_serial_invert Invert serial logic (1 invert, 0 normal) - - bb_serial_read Read bit bang serial data from a GPIO - - SPI - - spi_open Opens a SPI device - spi_close Closes a SPI device - - spi_read Reads bytes from a SPI device - spi_write Writes bytes to a SPI device - spi_xfer Transfers bytes with a SPI device - - SPI_BIT_BANG - - bb_spi_open Opens GPIO for bit banging SPI - bb_spi_close Closes GPIO for bit banging SPI - bb_spi_xfer Transfers bytes with bit banging SPI - - FILES - - file_open Opens a file - file_close Closes a file - - file_read Reads bytes from a file - file_write Writes bytes to a file - - file_seek Seeks to a position within a file - - file_list List files which match a pattern - - WAVES - - wave_clear Deletes all waveforms - - wave_add_new Starts a new waveform - wave_add_generic Adds a series of pulses to the waveform - wave_add_serial Adds serial data to the waveform - - wave_create Creates a waveform from added data - wave_create_and_pad Creates a waveform of fixed size from added data - wave_delete Deletes a waveform - - wave_send_once Transmits a waveform once - wave_send_repeat Transmits a waveform repeatedly - wave_send_using_mode Transmits a waveform in the chosen mode - - wave_chain Transmits a chain of waveforms - - wave_tx_at Returns the current transmitting waveform - - wave_tx_busy Checks to see if a waveform has ended - - wave_tx_stop Aborts the current waveform - - wave_get_cbs Length in cbs of the current waveform - wave_get_max_cbs Absolute maximum allowed cbs - - wave_get_micros Length in microseconds of the current waveform - wave_get_max_micros Absolute maximum allowed micros - - wave_get_pulses Length in pulses of the current waveform - wave_get_max_pulses Absolute maximum allowed pulses - - UTILITIES - - get_current_tick Get current tick (microseconds) - - get_hardware_revision Get hardware revision - get_pigpio_version Get the pigpio version - - pigpio.error_text Gets error text from error number - pigpio.tickDiff Returns difference between two ticks - -CLASSES - exceptions.Exception(exceptions.BaseException) - error - pi - pulse - - class error(exceptions.Exception) - | pigpio module exception - | - | Method resolution order: - | error - | exceptions.Exception - | exceptions.BaseException - | __builtin__.object - | - | Methods defined here: - | - | __init__(self, value) - | - | __str__(self) - | - | ---------------------------------------------------------------------- - | Data descriptors defined here: - | - | __weakref__ - | list of weak references to the object (if defined) - | - | ---------------------------------------------------------------------- - | Data and other attributes inherited from exceptions.Exception: - | - | __new__ = - | T.__new__(S, ...) -> a new object with type S, a subtype of T - | - | ---------------------------------------------------------------------- - | Methods inherited from exceptions.BaseException: - | - | __delattr__(...) - | x.__delattr__('name') <==> del x.name - | - | __getattribute__(...) - | x.__getattribute__('name') <==> x.name - | - | __getitem__(...) - | x.__getitem__(y) <==> x[y] - | - | __getslice__(...) - | x.__getslice__(i, j) <==> x[i:j] - | - | Use of negative indices is not supported. - | - | __reduce__(...) - | - | __repr__(...) - | x.__repr__() <==> repr(x) - | - | __setattr__(...) - | x.__setattr__('name', value) <==> x.name = value - | - | __setstate__(...) - | - | __unicode__(...) - | - | ---------------------------------------------------------------------- - | Data descriptors inherited from exceptions.BaseException: - | - | __dict__ - | - | args - | - | message - - class pi - | Methods defined here: - | - | __init__(self, host='localhost', port=8888, show_errors=True) - | Grants access to a Pi's GPIO. - | - | host:= the host name of the Pi on which the pigpio daemon is - | running. The default is localhost unless overridden by - | the PIGPIO_ADDR environment variable. - | - | port:= the port number on which the pigpio daemon is listening. - | The default is 8888 unless overridden by the PIGPIO_PORT - | environment variable. The pigpio daemon must have been - | started with the same port number. - | - | This connects to the pigpio daemon and reserves resources - | to be used for sending commands and receiving notifications. - | - | An instance attribute [*connected*] may be used to check the - | success of the connection. If the connection is established - | successfully [*connected*] will be True, otherwise False. - | - | ... - | pi = pigio.pi() # use defaults - | pi = pigpio.pi('mypi') # specify host, default port - | pi = pigpio.pi('mypi', 7777) # specify host and port - | - | pi = pigpio.pi() # exit script if no connection - | if not pi.connected: - | exit() - | ... - | - | __repr__(self) - | - | bb_i2c_close(self, SDA) - | This function stops bit banging I2C on a pair of GPIO - | previously opened with [*bb_i2c_open*]. - | - | SDA:= 0-31, the SDA GPIO used in a prior call to [*bb_i2c_open*] - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - | - | ... - | pi.bb_i2c_close(SDA) - | ... - | - | bb_i2c_open(self, SDA, SCL, baud=100000) - | This function selects a pair of GPIO for bit banging I2C at a - | specified baud rate. - | - | Bit banging I2C allows for certain operations which are not possible - | with the standard I2C driver. - | - | o baud rates as low as 50 - | o repeated starts - | o clock stretching - | o I2C on any pair of spare GPIO - | - | SDA:= 0-31 - | SCL:= 0-31 - | baud:= 50-500000 - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or - | PI_GPIO_IN_USE. - | - | NOTE: - | - | The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. - | As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - | - | ... - | h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps - | ... - | - | bb_i2c_zip(self, SDA, data) - | This function executes a sequence of bit banged I2C operations. - | The operations to be performed are specified by the contents - | of data which contains the concatenated command codes and - | associated data. - | - | SDA:= 0-31 (as used in a prior call to [*bb_i2c_open*]) - | data:= the concatenated I2C commands, see below - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (count, data) = pi.bb_i2c_zip( - | SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0]) - | ... - | - | The following command codes are supported: - | - | Name @ Cmd & Data @ Meaning - | End @ 0 @ No more commands - | Escape @ 1 @ Next P is two bytes - | Start @ 2 @ Start condition - | Stop @ 3 @ Stop condition - | Address @ 4 P @ Set I2C address to P - | Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) - | Read @ 6 P @ Read P bytes of data - | Write @ 7 P ... @ Write P bytes of data - | - | The address, read, and write commands take a parameter P. - | Normally P is one byte (0-255). If the command is preceded by - | the Escape command then P is two bytes (0-65535, least significant - | byte first). - | - | The address and flags default to 0. The address and flags maintain - | their previous value until updated. - | - | No flags are currently defined. - | - | Any read I2C data is concatenated in the returned bytearray. - | - | ... - | Set address 0x53 - | start, write 0x32, (re)start, read 6 bytes, stop - | Set address 0x1E - | start, write 0x03, (re)start, read 6 bytes, stop - | Set address 0x68 - | start, write 0x1B, (re)start, read 8 bytes, stop - | End - | - | 0x04 0x53 - | 0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 - | - | 0x04 0x1E - | 0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 - | - | 0x04 0x68 - | 0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 - | - | 0x00 - | ... - | - | bb_serial_invert(self, user_gpio, invert) - | Invert serial logic. - | - | user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - | invert:= 0-1 (1 invert, 0 normal) - | - | ... - | status = pi.bb_serial_invert(17, 1) - | ... - | - | bb_serial_read(self, user_gpio) - | Returns data from the bit bang serial cyclic buffer. - | - | user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | The bytes returned for each character depend upon the number of - | data bits [*bb_bits*] specified in the [*bb_serial_read_open*] - | command. - | - | For [*bb_bits*] 1-8 there will be one byte per character. - | For [*bb_bits*] 9-16 there will be two bytes per character. - | For [*bb_bits*] 17-32 there will be four bytes per character. - | - | ... - | (count, data) = pi.bb_serial_read(4) - | ... - | - | bb_serial_read_close(self, user_gpio) - | Closes a GPIO for bit bang reading of serial data. - | - | user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - | - | ... - | status = pi.bb_serial_read_close(17) - | ... - | - | bb_serial_read_open(self, user_gpio, baud, bb_bits=8) - | Opens a GPIO for bit bang reading of serial data. - | - | user_gpio:= 0-31, the GPIO to use. - | baud:= 50-250000, the baud rate. - | bb_bits:= 1-32, the number of bits per word, default 8. - | - | The serial data is held in a cyclic buffer and is read using - | [*bb_serial_read*]. - | - | It is the caller's responsibility to read data from the cyclic - | buffer in a timely fashion. - | - | ... - | status = pi.bb_serial_read_open(4, 19200) - | status = pi.bb_serial_read_open(17, 9600) - | ... - | - | bb_spi_close(self, CS) - | This function stops bit banging SPI on a set of GPIO - | opened with [*bb_spi_open*]. - | - | CS:= 0-31, the CS GPIO used in a prior call to [*bb_spi_open*] - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. - | - | ... - | pi.bb_spi_close(CS) - | ... - | - | bb_spi_open(self, CS, MISO, MOSI, SCLK, baud=100000, spi_flags=0) - | This function selects a set of GPIO for bit banging SPI at a - | specified baud rate. - | - | CS := 0-31 - | MISO := 0-31 - | MOSI := 0-31 - | SCLK := 0-31 - | baud := 50-250000 - | spiFlags := see below - | - | spiFlags consists of the least significant 22 bits. - | - | . . - | 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - | 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m - | . . - | - | mm defines the SPI mode, defaults to 0 - | - | . . - | Mode CPOL CPHA - | 0 0 0 - | 1 0 1 - | 2 1 0 - | 3 1 1 - | . . - | - | The following constants may be used to set the mode: - | - | . . - | pigpio.SPI_MODE_0 - | pigpio.SPI_MODE_1 - | pigpio.SPI_MODE_2 - | pigpio.SPI_MODE_3 - | . . - | - | Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA - | may be used. - | - | p is 0 if CS is active low (default) and 1 for active high. - | pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag. - | - | T is 1 if the least significant bit is transmitted on MOSI first, - | the default (0) shifts the most significant bit out first. - | pigpio.SPI_TX_LSBFIRST may be used to set this flag. - | - | R is 1 if the least significant bit is received on MISO first, - | the default (0) receives the most significant bit first. - | pigpio.SPI_RX_LSBFIRST may be used to set this flag. - | - | The other bits in spiFlags should be set to zero. - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or - | PI_GPIO_IN_USE. - | - | If more than one device is connected to the SPI bus (defined by - | SCLK, MOSI, and MISO) each must have its own CS. - | - | ... - | bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1 - | bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2 - | ... - | - | bb_spi_xfer(self, CS, data) - | This function executes a bit banged SPI transfer. - | - | CS:= 0-31 (as used in a prior call to [*bb_spi_open*]) - | data:= data to be sent - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | #!/usr/bin/env python - | - | import pigpio - | - | CE0=5 - | CE1=6 - | MISO=13 - | MOSI=19 - | SCLK=12 - | - | pi = pigpio.pi() - | if not pi.connected: - | exit() - | - | pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC - | pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC - | - | for i in range(256): - | - | count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value - | - | if count == 2: - | - | count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC - | - | if count == 2: - | - | set_val = data[1] - | - | count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC - | - | if count == 3: - | - | read_val = ((data[1]&3)<<8) | data[2] - | - | print("{} {}".format(set_val, read_val)) - | - | pi.bb_spi_close(CE0) - | pi.bb_spi_close(CE1) - | - | pi.stop() - | ... - | - | bsc_i2c(self, i2c_address, data=[]) - | This function allows the Pi to act as a slave I2C device. - | - | This function is not available on the BCM2711 (e.g. as - | used in the Pi4B). - | - | The data bytes (if any) are written to the BSC transmit - | FIFO and the bytes in the BSC receive FIFO are returned. - | - | i2c_address:= the I2C slave address. - | data:= the data bytes to transmit. - | - | The returned value is a tuple of the status, the number - | of bytes read, and a bytearray containing the read bytes. - | - | See [*bsc_xfer*] for details of the status value. - | - | If there was an error the status will be less than zero - | (and will contain the error code). - | - | Note that an i2c_address of 0 may be used to close - | the BSC device and reassign the used GPIO as inputs. - | - | This example assumes GPIO 2/3 are connected to GPIO 18/19 - | (GPIO 10/11 on the BCM2711). - | - | ... - | #!/usr/bin/env python - | import time - | import pigpio - | - | I2C_ADDR=0x13 - | - | def i2c(id, tick): - | global pi - | - | s, b, d = pi.bsc_i2c(I2C_ADDR) - | if b: - | if d[0] == ord('t'): # 116 send 'HH:MM:SS*' - | - | print("sent={} FR={} received={} [{}]". - | format(s>>16, s&0xfff,b,d)) - | - | s, b, d = pi.bsc_i2c(I2C_ADDR, - | "{}*".format(time.asctime()[11:19])) - | - | elif d[0] == ord('d'): # 100 send 'Sun Oct 30*' - | - | print("sent={} FR={} received={} [{}]". - | format(s>>16, s&0xfff,b,d)) - | - | s, b, d = pi.bsc_i2c(I2C_ADDR, - | "{}*".format(time.asctime()[:10])) - | - | pi = pigpio.pi() - | - | if not pi.connected: - | exit() - | - | # Respond to BSC slave activity - | - | e = pi.event_callback(pigpio.EVENT_BSC, i2c) - | - | pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave - | - | time.sleep(600) - | - | e.cancel() - | - | pi.bsc_i2c(0) # Disable BSC peripheral - | - | pi.stop() - | ... - | - | While running the above. - | - | . . - | $ i2cdetect -y 1 - | 0 1 2 3 4 5 6 7 8 9 a b c d e f - | 00: -- -- -- -- -- -- -- -- -- -- -- -- -- - | 10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- -- - | 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 70: -- -- -- -- -- -- -- -- - | - | $ pigs i2co 1 0x13 0 - | 0 - | - | $ pigs i2cwd 0 116 - | $ pigs i2crd 0 9 -a - | 9 10:13:58* - | - | $ pigs i2cwd 0 116 - | $ pigs i2crd 0 9 -a - | 9 10:14:29* - | - | $ pigs i2cwd 0 100 - | $ pigs i2crd 0 11 -a - | 11 Sun Oct 30* - | - | $ pigs i2cwd 0 100 - | $ pigs i2crd 0 11 -a - | 11 Sun Oct 30* - | - | $ pigs i2cwd 0 116 - | $ pigs i2crd 0 9 -a - | 9 10:23:16* - | - | $ pigs i2cwd 0 100 - | $ pigs i2crd 0 11 -a - | 11 Sun Oct 30* - | . . - | - | bsc_xfer(self, bsc_control, data) - | This function provides a low-level interface to the SPI/I2C Slave - | peripheral on the BCM chip. - | - | This peripheral allows the Pi to act as a hardware slave device - | on an I2C or SPI bus. - | - | This is not a bit bang version and as such is OS timing - | independent. The bus timing is handled directly by the chip. - | - | The output process is simple. You simply append data to the FIFO - | buffer on the chip. This works like a queue, you add data to the - | queue and the master removes it. - | - | I can't get SPI to work properly. I tried with a - | control word of 0x303 and swapped MISO and MOSI. - | - | The function sets the BSC mode, writes any data in - | the transmit buffer to the BSC transmit FIFO, and - | copies any data in the BSC receive FIFO to the - | receive buffer. - | - | bsc_control:= see below - | data:= the data bytes to place in the transmit FIFO. - | - | The returned value is a tuple of the status (see below), - | the number of bytes read, and a bytearray containing the - | read bytes. If there was an error the status will be less - | than zero (and will contain the error code). - | - | Note that the control word sets the BSC mode. The BSC will - | stay in that mode until a different control word is sent. - | - | 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 will be reset - | to INPUT mode. - | - | bsc_control consists of the following bits: - | - | . . - | 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - | a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN - | . . - | - | Bits 0-13 are copied unchanged to the BSC CR register. See - | pages 163-165 of the Broadcom peripherals document for full - | details. - | - | aaaaaaa @ defines the I2C slave address (only relevant in I2C mode) - | IT @ invert transmit status flags - | HC @ enable host control - | TF @ enable test FIFO - | IR @ invert receive status flags - | RE @ enable receive - | TE @ enable transmit - | BK @ abort operation and clear FIFOs - | EC @ send control register as first I2C byte - | ES @ send status register as first I2C byte - | PL @ set SPI polarity high - | PH @ set SPI phase high - | I2 @ enable I2C mode - | SP @ enable SPI mode - | EN @ enable BSC peripheral - | - | The status has the following format: - | - | . . - | 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - | S S S S S R R R R R T T T T T RB TE RF TF RE TB - | . . - | - | Bits 0-15 are copied unchanged from the BSC FR register. See - | pages 165-166 of the Broadcom peripherals document for full - | details. - | - | SSSSS @ number of bytes successfully copied to transmit FIFO - | RRRRR @ number of bytes in receieve FIFO - | TTTTT @ number of bytes in transmit FIFO - | RB @ receive busy - | TE @ transmit FIFO empty - | RF @ receive FIFO full - | TF @ transmit FIFO full - | RE @ receive FIFO empty - | TB @ transmit busy - | - | ... - | (status, count, data) = pi.bsc_xfer(0x330305, "Hello!") - | ... - | - | callback(self, user_gpio, edge=0, func=None) - | Calls a user supplied function (a callback) whenever the - | specified GPIO edge is detected. - | - | user_gpio:= 0-31. - | edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE. - | func:= user supplied callback function. - | - | The user supplied callback receives three parameters, the GPIO, - | the level, and the tick. - | - | . . - | Parameter Value Meaning - | - | GPIO 0-31 The GPIO which has changed state - | - | level 0-2 0 = change to low (a falling edge) - | 1 = change to high (a rising edge) - | 2 = no level change (a watchdog timeout) - | - | tick 32 bit The number of microseconds since boot - | WARNING: this wraps around from - | 4294967295 to 0 roughly every 72 minutes - | . . - | - | If a user callback is not specified a default tally callback is - | provided which simply counts edges. The count may be retrieved - | by calling the tally function. The count may be reset to zero - | by calling the reset_tally function. - | - | The callback may be cancelled by calling the cancel function. - | - | A GPIO may have multiple callbacks (although I can't think of - | a reason to do so). - | - | The GPIO are sampled at a rate set when the pigpio daemon - | is started (default 5 us). - | - | The number of samples per second is given in the following table. - | - | . . - | samples - | per sec - | - | 1 1,000,000 - | 2 500,000 - | sample 4 250,000 - | rate 5 200,000 - | (us) 8 125,000 - | 10 100,000 - | . . - | - | GPIO level changes shorter than the sample rate may be missed. - | - | The daemon software which generates the callbacks is triggered - | 1000 times per second. The callbacks will be called once per - | level change since the last time they were called. - | i.e. The callbacks will get all level changes but there will - | be a latency. - | - | If you want to track the level of more than one GPIO do so by - | maintaining the state in the callback. Do not use [*read*]. - | Remember the event that triggered the callback may have - | happened several milliseconds before and the GPIO may have - | changed level many times since then. - | - | ... - | def cbf(gpio, level, tick): - | print(gpio, level, tick) - | - | cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf) - | - | cb2 = pi.callback(4, pigpio.EITHER_EDGE) - | - | cb3 = pi.callback(17) - | - | print(cb3.tally()) - | - | cb3.reset_tally() - | - | cb1.cancel() # To cancel callback cb1. - | ... - | - | clear_bank_1(self, bits) - | Clears GPIO 0-31 if the corresponding bit in bits is set. - | - | bits:= a 32 bit mask with 1 set if the corresponding GPIO is - | to be cleared. - | - | A returned status of PI_SOME_PERMITTED indicates that the user - | is not allowed to write to one or more of the GPIO. - | - | ... - | pi.clear_bank_1(int("111110010000",2)) - | ... - | - | clear_bank_2(self, bits) - | Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. - | - | bits:= a 32 bit mask with 1 set if the corresponding GPIO is - | to be cleared. - | - | A returned status of PI_SOME_PERMITTED indicates that the user - | is not allowed to write to one or more of the GPIO. - | - | ... - | pi.clear_bank_2(0x1010) - | ... - | - | custom_1(self, arg1=0, arg2=0, argx=[]) - | Calls a pigpio function customised by the user. - | - | arg1:= >=0, default 0. - | arg2:= >=0, default 0. - | argx:= extra arguments (each 0-255), default empty. - | - | The returned value is an integer which by convention - | should be >=0 for OK and <0 for error. - | - | ... - | value = pi.custom_1() - | - | value = pi.custom_1(23) - | - | value = pi.custom_1(0, 55) - | - | value = pi.custom_1(23, 56, [1, 5, 7]) - | - | value = pi.custom_1(23, 56, b"hello") - | - | value = pi.custom_1(23, 56, "hello") - | ... - | - | custom_2(self, arg1=0, argx=[], retMax=8192) - | Calls a pigpio function customised by the user. - | - | arg1:= >=0, default 0. - | argx:= extra arguments (each 0-255), default empty. - | retMax:= >=0, maximum number of bytes to return, default 8192. - | - | The returned value is a tuple of the number of bytes - | returned and a bytearray containing the bytes. If - | there was an error the number of bytes read will be - | less than zero (and will contain the error code). - | - | ... - | (count, data) = pi.custom_2() - | - | (count, data) = pi.custom_2(23) - | - | (count, data) = pi.custom_2(23, [1, 5, 7]) - | - | (count, data) = pi.custom_2(23, b"hello") - | - | (count, data) = pi.custom_2(23, "hello", 128) - | ... - | - | delete_script(self, script_id) - | Deletes a stored script. - | - | script_id:= id of stored script. - | - | ... - | status = pi.delete_script(sid) - | ... - | - | event_callback(self, event, func=None) - | Calls a user supplied function (a callback) whenever the - | specified event is signalled. - | - | event:= 0-31. - | func:= user supplied callback function. - | - | The user supplied callback receives two parameters, the event id, - | and the tick. - | - | If a user callback is not specified a default tally callback is - | provided which simply counts events. The count may be retrieved - | by calling the tally function. The count may be reset to zero - | by calling the reset_tally function. - | - | The callback may be cancelled by calling the event_cancel function. - | - | An event may have multiple callbacks (although I can't think of - | a reason to do so). - | - | ... - | def cbf(event, tick): - | print(event, tick) - | - | cb1 = pi.event_callback(22, cbf) - | - | cb2 = pi.event_callback(4) - | - | print(cb2.tally()) - | - | cb2.reset_tally() - | - | cb1.event_cancel() # To cancel callback cb1. - | ... - | - | event_trigger(self, event) - | This function signals the occurrence of an event. - | - | event:= 0-31, the event - | - | Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - | - | An event is a signal used to inform one or more consumers - | to start an action. Each consumer which has registered an - | interest in the event (e.g. by calling [*event_callback*]) will - | be informed by a callback. - | - | One event, EVENT_BSC (31) is predefined. This event is - | auto generated on BSC slave activity. - | - | The meaning of other events is arbitrary. - | - | Note that other than its id and its tick there is no data associated - | with an event. - | - | ... - | pi.event_trigger(23) - | ... - | - | file_close(self, handle) - | Closes the file associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*file_open*]). - | - | ... - | pi.file_close(handle) - | ... - | - | file_list(self, fpattern) - | Returns a list of files which match a pattern. - | - | fpattern:= file pattern to match. - | - | Returns the number of returned bytes if OK, otherwise - | PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. - | - | The pattern must match an entry in /opt/pigpio/access. The - | pattern may contain wildcards. See [*file_open*]. - | - | NOTE - | - | The returned value is not the number of files, it is the number - | of bytes in the buffer. The file names are separated by newline - | characters. - | - | ... - | #!/usr/bin/env python - | - | import pigpio - | - | pi = pigpio.pi() - | - | if not pi.connected: - | exit() - | - | # Assumes /opt/pigpio/access contains the following line: - | # /ram/*.c r - | - | c, d = pi.file_list("/ram/p*.c") - | if c > 0: - | print(d) - | - | pi.stop() - | ... - | - | file_open(self, file_name, file_mode) - | This function returns a handle to a file opened in a specified mode. - | - | file_name:= the file to open. - | file_mode:= the file open mode. - | - | Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, - | PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE, - | PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. - | - | ... - | h = pi.file_open("/home/pi/shared/dir_3/file.txt", - | pigpio.FILE_WRITE | pigpio.FILE_CREATE) - | - | pi.file_write(h, "Hello world") - | - | pi.file_close(h) - | ... - | - | File - | - | A file may only be opened if permission is granted by an entry - | in /opt/pigpio/access. This is intended to allow remote access - | to files in a more or less controlled manner. - | - | Each entry in /opt/pigpio/access takes the form of a file path - | which may contain wildcards followed by a single letter permission. - | The permission may be R for read, W for write, U for read/write, - | and N for no access. - | - | Where more than one entry matches a file the most specific rule - | applies. If no entry matches a file then access is denied. - | - | Suppose /opt/pigpio/access contains the following entries: - | - | . . - | /home/* n - | /home/pi/shared/dir_1/* w - | /home/pi/shared/dir_2/* r - | /home/pi/shared/dir_3/* u - | /home/pi/shared/dir_1/file.txt n - | . . - | - | Files may be written in directory dir_1 with the exception - | of file.txt. - | - | Files may be read in directory dir_2. - | - | Files may be read and written in directory dir_3. - | - | If a directory allows read, write, or read/write access then files - | may be created in that directory. - | - | In an attempt to prevent risky permissions the following paths are - | ignored in /opt/pigpio/access: - | - | . . - | a path containing .. - | a path containing only wildcards (*?) - | a path containing less than two non-wildcard parts - | . . - | - | Mode - | - | The mode may have the following values: - | - | Constant @ Value @ Meaning - | FILE_READ @ 1 @ open file for reading - | FILE_WRITE @ 2 @ open file for writing - | FILE_RW @ 3 @ open file for reading and writing - | - | The following values may be or'd into the mode: - | - | Name @ Value @ Meaning - | FILE_APPEND @ 4 @ All writes append data to the end of the file - | FILE_CREATE @ 8 @ The file is created if it doesn't exist - | FILE_TRUNC @ 16 @ The file is truncated - | - | Newly created files are owned by root with permissions owner - | read and write. - | - | ... - | #!/usr/bin/env python - | - | import pigpio - | - | pi = pigpio.pi() - | - | if not pi.connected: - | exit() - | - | # Assumes /opt/pigpio/access contains the following line: - | # /ram/*.c r - | - | handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ) - | - | done = False - | - | while not done: - | c, d = pi.file_read(handle, 60000) - | if c > 0: - | print(d) - | else: - | done = True - | - | pi.file_close(handle) - | - | pi.stop() - | ... - | - | file_read(self, handle, count) - | Reads up to count bytes from the file associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*file_open*]). - | count:= >0, the number of bytes to read. - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.file_read(h2, 100) - | if b > 0: - | # process read data - | ... - | - | file_seek(self, handle, seek_offset, seek_from) - | Seeks to a position relative to the start, current position, - | or end of the file. Returns the new position. - | - | handle:= >=0 (as returned by a prior call to [*file_open*]). - | seek_offset:= byte offset. - | seek_from:= FROM_START, FROM_CURRENT, or FROM_END. - | - | ... - | new_pos = pi.file_seek(h, 100, pigpio.FROM_START) - | - | cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT) - | - | file_size = pi.file_seek(h, 0, pigpio.FROM_END) - | ... - | - | file_write(self, handle, data) - | Writes the data bytes to the file associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*file_open*]). - | data:= the bytes to write. - | - | ... - | pi.file_write(h1, b'\x02\x03\x04') - | - | pi.file_write(h2, b'help') - | - | pi.file_write(h2, "hello") - | - | pi.file_write(h1, [2, 3, 4]) - | ... - | - | get_PWM_dutycycle(self, user_gpio) - | Returns the PWM dutycycle being used on the GPIO. - | - | user_gpio:= 0-31. - | - | Returns the PWM dutycycle. - | - | - | For normal PWM the dutycycle will be out of the defined range - | for the GPIO (see [*get_PWM_range*]). - | - | If a hardware clock is active on the GPIO the reported - | dutycycle will be 500000 (500k) out of 1000000 (1M). - | - | If hardware PWM is active on the GPIO the reported dutycycle - | will be out of a 1000000 (1M). - | - | ... - | pi.set_PWM_dutycycle(4, 25) - | print(pi.get_PWM_dutycycle(4)) - | 25 - | - | pi.set_PWM_dutycycle(4, 203) - | print(pi.get_PWM_dutycycle(4)) - | 203 - | ... - | - | get_PWM_frequency(self, user_gpio) - | Returns the frequency of PWM being used on the GPIO. - | - | user_gpio:= 0-31. - | - | Returns the frequency (in Hz) used for the GPIO. - | - | For normal PWM the frequency will be that defined for the GPIO - | by [*set_PWM_frequency*]. - | - | If a hardware clock is active on the GPIO the reported frequency - | will be that set by [*hardware_clock*]. - | - | If hardware PWM is active on the GPIO the reported frequency - | will be that set by [*hardware_PWM*]. - | - | ... - | pi.set_PWM_frequency(4,0) - | print(pi.get_PWM_frequency(4)) - | 10 - | - | pi.set_PWM_frequency(4, 800) - | print(pi.get_PWM_frequency(4)) - | 800 - | ... - | - | get_PWM_range(self, user_gpio) - | Returns the range of PWM values being used on the GPIO. - | - | user_gpio:= 0-31. - | - | If a hardware clock or hardware PWM is active on the GPIO - | the reported range will be 1000000 (1M). - | - | ... - | pi.set_PWM_range(9, 500) - | print(pi.get_PWM_range(9)) - | 500 - | ... - | - | get_PWM_real_range(self, user_gpio) - | Returns the real (underlying) range of PWM values being - | used on the GPIO. - | - | user_gpio:= 0-31. - | - | If a hardware clock is active on the GPIO the reported - | real range will be 1000000 (1M). - | - | If hardware PWM is active on the GPIO the reported real range - | will be approximately 250M divided by the set PWM frequency. - | - | ... - | pi.set_PWM_frequency(4, 800) - | print(pi.get_PWM_real_range(4)) - | 250 - | ... - | - | get_current_tick(self) - | Returns the current system tick. - | - | Tick is the number of microseconds since system boot. As an - | unsigned 32 bit quantity tick wraps around approximately - | every 71.6 minutes. - | - | ... - | t1 = pi.get_current_tick() - | time.sleep(1) - | t2 = pi.get_current_tick() - | ... - | - | get_hardware_revision(self) - | Returns the Pi's hardware revision number. - | - | The hardware revision is the last few characters on the - | Revision line of /proc/cpuinfo. - | - | The revision number can be used to determine the assignment - | of GPIO to pins (see [*gpio*]). - | - | There are at least three types of board. - | - | Type 1 boards have hardware revision numbers of 2 and 3. - | - | Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. - | - | Type 3 boards have hardware revision numbers of 16 or greater. - | - | If the hardware revision can not be found or is not a valid - | hexadecimal number the function returns 0. - | - | ... - | print(pi.get_hardware_revision()) - | 2 - | ... - | - | get_mode(self, gpio) - | Returns the GPIO mode. - | - | gpio:= 0-53. - | - | Returns a value as follows - | - | . . - | 0 = INPUT - | 1 = OUTPUT - | 2 = ALT5 - | 3 = ALT4 - | 4 = ALT0 - | 5 = ALT1 - | 6 = ALT2 - | 7 = ALT3 - | . . - | - | ... - | print(pi.get_mode(0)) - | 4 - | ... - | - | get_pad_strength(self, pad) - | This function returns the pad drive strength in mA. - | - | pad:= 0-2, the pad to get. - | - | Returns the pad drive strength if OK, otherwise PI_BAD_PAD. - | - | Pad @ GPIO - | 0 @ 0-27 - | 1 @ 28-45 - | 2 @ 46-53 - | - | ... - | strength = pi.get_pad_strength(0) # Get pad 0 strength. - | ... - | - | get_pigpio_version(self) - | Returns the pigpio software version. - | - | ... - | v = pi.get_pigpio_version() - | ... - | - | get_servo_pulsewidth(self, user_gpio) - | Returns the servo pulsewidth being used on the GPIO. - | - | user_gpio:= 0-31. - | - | Returns the servo pulsewidth. - | - | ... - | pi.set_servo_pulsewidth(4, 525) - | print(pi.get_servo_pulsewidth(4)) - | 525 - | - | pi.set_servo_pulsewidth(4, 2130) - | print(pi.get_servo_pulsewidth(4)) - | 2130 - | ... - | - | gpio_trigger(self, user_gpio, pulse_len=10, level=1) - | Send a trigger pulse to a GPIO. The GPIO is set to - | level for pulse_len microseconds and then reset to not level. - | - | user_gpio:= 0-31 - | pulse_len:= 1-100 - | level:= 0-1 - | - | ... - | pi.gpio_trigger(23, 10, 1) - | ... - | - | hardware_PWM(self, gpio, PWMfreq, PWMduty) - | Starts hardware PWM on a GPIO at the specified frequency - | and dutycycle. Frequencies above 30MHz are unlikely to work. - | - | NOTE: Any waveform started by [*wave_send_once*], - | [*wave_send_repeat*], or [*wave_chain*] will be cancelled. - | - | This function is only valid if the pigpio main clock is PCM. - | The main clock defaults to PCM but may be overridden when the - | pigpio daemon is started (option -t). - | - | gpio:= see descripton - | PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711). - | PWMduty:= 0 (off) to 1000000 (1M)(fully on). - | - | Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, - | PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. - | - | The same PWM channel is available on multiple GPIO. - | The latest frequency and dutycycle setting will be used - | by all GPIO which share a PWM channel. - | - | The GPIO must be one of the following: - | - | . . - | 12 PWM channel 0 All models but A and B - | 13 PWM channel 1 All models but A and B - | 18 PWM channel 0 All models - | 19 PWM channel 1 All models but A and B - | - | 40 PWM channel 0 Compute module only - | 41 PWM channel 1 Compute module only - | 45 PWM channel 1 Compute module only - | 52 PWM channel 0 Compute module only - | 53 PWM channel 1 Compute module only - | . . - | - | The actual number of steps beween off and fully on is the - | integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). - | - | The actual frequency set is 250M/steps (375M/steps - | for the BCM2711). - | - | There will only be a million steps for a PWMfreq of 250 - | (375 for the BCM2711). Lower frequencies will have more - | steps and higher frequencies will have fewer steps. - | PWMduty is automatically scaled to take this into account. - | - | ... - | pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle - | - | pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle - | ... - | - | hardware_clock(self, gpio, clkfreq) - | Starts a hardware clock on a GPIO at the specified frequency. - | Frequencies above 30MHz are unlikely to work. - | - | gpio:= see description - | clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711) - | - | - | Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, - | PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. - | - | The same clock is available on multiple GPIO. The latest - | frequency setting will be used by all GPIO which share a clock. - | - | The GPIO must be one of the following: - | - | . . - | 4 clock 0 All models - | 5 clock 1 All models but A and B (reserved for system use) - | 6 clock 2 All models but A and B - | 20 clock 0 All models but A and B - | 21 clock 1 All models but A and Rev.2 B (reserved for system use) - | - | 32 clock 0 Compute module only - | 34 clock 0 Compute module only - | 42 clock 1 Compute module only (reserved for system use) - | 43 clock 2 Compute module only - | 44 clock 1 Compute module only (reserved for system use) - | . . - | - | Access to clock 1 is protected by a password as its use will - | likely crash the Pi. The password is given by or'ing 0x5A000000 - | with the GPIO number. - | - | ... - | pi.hardware_clock(4, 5000) # 5 KHz clock on GPIO 4 - | - | pi.hardware_clock(4, 40000000) # 40 MHz clock on GPIO 4 - | ... - | - | i2c_block_process_call(self, handle, reg, data) - | Writes data bytes to the specified register of the device - | associated with handle and reads a device specified number - | of bytes of data in return. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | data:= the bytes to write. - | - | The SMBus 2.0 documentation states that a minimum of 1 byte may - | be sent and a minimum of 1 byte may be received. The total - | number of bytes sent/received must be 32 or less. - | - | SMBus 2.0 5.5.8 - Block write-block read. - | . . - | S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A] - | S Addr Rd [A] [Count] A [Data] ... A P - | . . - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00') - | - | (b, d) = pi.i2c_block_process_call(h, 10, b'abcdr') - | - | (b, d) = pi.i2c_block_process_call(h, 10, "abracad") - | - | (b, d) = pi.i2c_block_process_call(h, 10, [2, 5, 16]) - | ... - | - | i2c_close(self, handle) - | Closes the I2C device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | - | ... - | pi.i2c_close(h) - | ... - | - | i2c_open(self, i2c_bus, i2c_address, i2c_flags=0) - | Returns a handle (>=0) for the device at the I2C bus address. - | - | i2c_bus:= >=0. - | i2c_address:= 0-0x7F. - | i2c_flags:= 0, no flags are currently defined. - | - | Physically buses 0 and 1 are available on the Pi. Higher - | numbered buses will be available if a kernel supported bus - | multiplexor is being used. - | - | The GPIO used are given in the following table. - | - | @ SDA @ SCL - | I2C 0 @ 0 @ 1 - | I2C 1 @ 2 @ 3 - | - | For the SMBus commands the low level transactions are shown - | at the end of the function description. The following - | abbreviations are used: - | - | . . - | S (1 bit) : Start bit - | P (1 bit) : Stop bit - | Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. - | A, NA (1 bit) : Accept and not accept bit. - | Addr (7 bits): I2C 7 bit address. - | reg (8 bits): Command byte, which often selects a register. - | Data (8 bits): A data byte. - | Count (8 bits): A byte defining the length of a block operation. - | - | [..]: Data sent by the device. - | . . - | - | ... - | h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1 - | ... - | - | i2c_process_call(self, handle, reg, word_val) - | Writes 16 bits of data to the specified register of the device - | associated with handle and reads 16 bits of data in return. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | word_val:= 0-65535, the value to write. - | - | SMBus 2.0 5.5.6 - Process call. - | . . - | S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] - | S Addr Rd [A] [DataLow] A [DataHigh] NA P - | . . - | - | ... - | r = pi.i2c_process_call(h, 4, 0x1231) - | r = pi.i2c_process_call(h, 6, 0) - | ... - | - | i2c_read_block_data(self, handle, reg) - | Reads a block of up to 32 bytes from the specified register of - | the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | - | SMBus 2.0 5.5.7 - Block read. - | . . - | S Addr Wr [A] reg [A] - | S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P - | . . - | - | The amount of returned data is set by the device. - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.i2c_read_block_data(h, 10) - | if b >= 0: - | # process data - | else: - | # process read failure - | ... - | - | i2c_read_byte(self, handle) - | Reads a single byte from the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | - | SMBus 2.0 5.5.3 - Receive byte. - | . . - | S Addr Rd [A] [Data] NA P - | . . - | - | ... - | b = pi.i2c_read_byte(2) # read a byte from device 2 - | ... - | - | i2c_read_byte_data(self, handle, reg) - | Reads a single byte from the specified register of the device - | associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | - | SMBus 2.0 5.5.5 - Read byte. - | . . - | S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P - | . . - | - | ... - | # read byte from reg 17 of device 2 - | b = pi.i2c_read_byte_data(2, 17) - | - | # read byte from reg 1 of device 0 - | b = pi.i2c_read_byte_data(0, 1) - | ... - | - | i2c_read_device(self, handle, count) - | Returns count bytes read from the raw device associated - | with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | count:= >0, the number of bytes to read. - | - | . . - | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P - | . . - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (count, data) = pi.i2c_read_device(h, 12) - | ... - | - | i2c_read_i2c_block_data(self, handle, reg, count) - | Reads count bytes from the specified register of the device - | associated with handle . The count may be 1-32. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | count:= >0, the number of bytes to read. - | - | . . - | S Addr Wr [A] reg [A] - | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P - | . . - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.i2c_read_i2c_block_data(h, 4, 32) - | if b >= 0: - | # process data - | else: - | # process read failure - | ... - | - | i2c_read_word_data(self, handle, reg) - | Reads a single 16 bit word from the specified register of the - | device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | - | SMBus 2.0 5.5.5 - Read word. - | . . - | S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P - | . . - | - | ... - | # read word from reg 2 of device 3 - | w = pi.i2c_read_word_data(3, 2) - | - | # read word from reg 7 of device 2 - | w = pi.i2c_read_word_data(2, 7) - | ... - | - | i2c_write_block_data(self, handle, reg, data) - | Writes up to 32 bytes to the specified register of the device - | associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | data:= the bytes to write. - | - | SMBus 2.0 5.5.7 - Block write. - | . . - | S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A] - | datan [A] P - | . . - | - | ... - | pi.i2c_write_block_data(4, 5, b'hello') - | - | pi.i2c_write_block_data(4, 5, "data bytes") - | - | pi.i2c_write_block_data(5, 0, b'\x00\x01\x22') - | - | pi.i2c_write_block_data(6, 2, [0, 1, 0x22]) - | ... - | - | i2c_write_byte(self, handle, byte_val) - | Sends a single byte to the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | byte_val:= 0-255, the value to write. - | - | SMBus 2.0 5.5.2 - Send byte. - | . . - | S Addr Wr [A] byte_val [A] P - | . . - | - | ... - | pi.i2c_write_byte(1, 17) # send byte 17 to device 1 - | pi.i2c_write_byte(2, 0x23) # send byte 0x23 to device 2 - | ... - | - | i2c_write_byte_data(self, handle, reg, byte_val) - | Writes a single byte to the specified register of the device - | associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | byte_val:= 0-255, the value to write. - | - | SMBus 2.0 5.5.4 - Write byte. - | . . - | S Addr Wr [A] reg [A] byte_val [A] P - | . . - | - | ... - | # send byte 0xC5 to reg 2 of device 1 - | pi.i2c_write_byte_data(1, 2, 0xC5) - | - | # send byte 9 to reg 4 of device 2 - | pi.i2c_write_byte_data(2, 4, 9) - | ... - | - | i2c_write_device(self, handle, data) - | Writes the data bytes to the raw device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | data:= the bytes to write. - | - | . . - | S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P - | . . - | - | ... - | pi.i2c_write_device(h, b"\x12\x34\xA8") - | - | pi.i2c_write_device(h, b"help") - | - | pi.i2c_write_device(h, 'help') - | - | pi.i2c_write_device(h, [23, 56, 231]) - | ... - | - | i2c_write_i2c_block_data(self, handle, reg, data) - | Writes data bytes to the specified register of the device - | associated with handle . 1-32 bytes may be written. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | data:= the bytes to write. - | - | . . - | S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P - | . . - | - | ... - | pi.i2c_write_i2c_block_data(4, 5, 'hello') - | - | pi.i2c_write_i2c_block_data(4, 5, b'hello') - | - | pi.i2c_write_i2c_block_data(5, 0, b'\x00\x01\x22') - | - | pi.i2c_write_i2c_block_data(6, 2, [0, 1, 0x22]) - | ... - | - | i2c_write_quick(self, handle, bit) - | Sends a single bit to the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | bit:= 0 or 1, the value to write. - | - | SMBus 2.0 5.5.1 - Quick command. - | . . - | S Addr bit [A] P - | . . - | - | ... - | pi.i2c_write_quick(0, 1) # send 1 to device 0 - | pi.i2c_write_quick(3, 0) # send 0 to device 3 - | ... - | - | i2c_write_word_data(self, handle, reg, word_val) - | Writes a single 16 bit word to the specified register of the - | device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | word_val:= 0-65535, the value to write. - | - | SMBus 2.0 5.5.4 - Write word. - | . . - | S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P - | . . - | - | ... - | # send word 0xA0C5 to reg 5 of device 4 - | pi.i2c_write_word_data(4, 5, 0xA0C5) - | - | # send word 2 to reg 2 of device 5 - | pi.i2c_write_word_data(5, 2, 23) - | ... - | - | i2c_zip(self, handle, data) - | This function executes a sequence of I2C operations. The - | operations to be performed are specified by the contents of data - | which contains the concatenated command codes and associated data. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | data:= the concatenated I2C commands, see below - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0]) - | ... - | - | The following command codes are supported: - | - | Name @ Cmd & Data @ Meaning - | End @ 0 @ No more commands - | Escape @ 1 @ Next P is two bytes - | On @ 2 @ Switch combined flag on - | Off @ 3 @ Switch combined flag off - | Address @ 4 P @ Set I2C address to P - | Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) - | Read @ 6 P @ Read P bytes of data - | Write @ 7 P ... @ Write P bytes of data - | - | The address, read, and write commands take a parameter P. - | Normally P is one byte (0-255). If the command is preceded by - | the Escape command then P is two bytes (0-65535, least significant - | byte first). - | - | The address defaults to that associated with the handle. - | The flags default to 0. The address and flags maintain their - | previous value until updated. - | - | Any read I2C data is concatenated in the returned bytearray. - | - | ... - | Set address 0x53, write 0x32, read 6 bytes - | Set address 0x1E, write 0x03, read 6 bytes - | Set address 0x68, write 0x1B, read 8 bytes - | End - | - | 0x04 0x53 0x07 0x01 0x32 0x06 0x06 - | 0x04 0x1E 0x07 0x01 0x03 0x06 0x06 - | 0x04 0x68 0x07 0x01 0x1B 0x06 0x08 - | 0x00 - | ... - | - | notify_begin(self, handle, bits) - | Starts notifications on a handle. - | - | handle:= >=0 (as returned by a prior call to [*notify_open*]) - | bits:= a 32 bit mask indicating the GPIO to be notified. - | - | The notification sends state changes for each GPIO whose - | corresponding bit in bits is set. - | - | The following code starts notifications for GPIO 1, 4, - | 6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). - | - | ... - | h = pi.notify_open() - | if h >= 0: - | pi.notify_begin(h, 1234) - | ... - | - | notify_close(self, handle) - | Stops notifications on a handle and releases the handle for reuse. - | - | handle:= >=0 (as returned by a prior call to [*notify_open*]) - | - | ... - | h = pi.notify_open() - | if h >= 0: - | pi.notify_begin(h, 1234) - | ... - | pi.notify_close(h) - | ... - | ... - | - | notify_open(self) - | Returns a notification handle (>=0). - | - | A notification is a method for being notified of GPIO state - | changes via a pipe. - | - | Pipes are only accessible from the local machine so this - | function serves no purpose if you are using Python from a - | remote machine. The in-built (socket) notifications - | provided by [*callback*] should be used instead. - | - | Notifications for handle x will be available at the pipe - | named /dev/pigpiox (where x is the handle number). - | - | E.g. if the function returns 15 then the notifications must be - | read from /dev/pigpio15. - | - | Notifications have the following structure: - | - | . . - | H seqno - | H flags - | I tick - | I level - | . . - | - | seqno: starts at 0 each time the handle is opened and then - | increments by one for each report. - | - | flags: three flags are defined, PI_NTFY_FLAGS_WDOG, - | PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. - | - | If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the - | flags indicate a GPIO which has had a watchdog timeout. - | - | If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep - | alive signal on the pipe/socket and is sent once a minute - | in the absence of other notification activity. - | - | If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the - | flags indicate an event which has been triggered. - | - | - | tick: the number of microseconds since system boot. It wraps - | around after 1h12m. - | - | level: indicates the level of each GPIO. If bit 1<= 0: - | pi.notify_begin(h, 1234) - | ... - | - | notify_pause(self, handle) - | Pauses notifications on a handle. - | - | handle:= >=0 (as returned by a prior call to [*notify_open*]) - | - | Notifications for the handle are suspended until - | [*notify_begin*] is called again. - | - | ... - | h = pi.notify_open() - | if h >= 0: - | pi.notify_begin(h, 1234) - | ... - | pi.notify_pause(h) - | ... - | pi.notify_begin(h, 1234) - | ... - | ... - | - | read(self, gpio) - | Returns the GPIO level. - | - | gpio:= 0-53. - | - | ... - | pi.set_mode(23, pigpio.INPUT) - | - | pi.set_pull_up_down(23, pigpio.PUD_DOWN) - | print(pi.read(23)) - | 0 - | - | pi.set_pull_up_down(23, pigpio.PUD_UP) - | print(pi.read(23)) - | 1 - | ... - | - | read_bank_1(self) - | Returns the levels of the bank 1 GPIO (GPIO 0-31). - | - | The returned 32 bit integer has a bit set if the corresponding - | GPIO is high. GPIO n has bit value (1<=0 (as returned by a prior call to [*serial_open*]). - | - | ... - | pi.serial_close(h1) - | ... - | - | serial_data_available(self, handle) - | Returns the number of bytes available to be read from the - | device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | - | ... - | rdy = pi.serial_data_available(h1) - | - | if rdy > 0: - | (b, d) = pi.serial_read(h1, rdy) - | ... - | - | serial_open(self, tty, baud, ser_flags=0) - | Returns a handle for the serial tty device opened - | at baud bits per second. The device name must start - | with /dev/tty or /dev/serial. - | - | tty:= the serial device to open. - | baud:= baud rate in bits per second, see below. - | ser_flags:= 0, no flags are currently defined. - | - | Normally you would only use the [*serial_**] functions if - | you are or will be connecting to the Pi over a network. If - | you will always run on the local Pi use the standard serial - | module instead. - | - | The baud rate must be one of 50, 75, 110, 134, 150, - | 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, - | 38400, 57600, 115200, or 230400. - | - | ... - | h1 = pi.serial_open("/dev/ttyAMA0", 300) - | - | h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0) - | - | h3 = pi.serial_open("/dev/serial0", 9600) - | ... - | - | serial_read(self, handle, count=1000) - | Reads up to count bytes from the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | count:= >0, the number of bytes to read (defaults to 1000). - | - | The returned value is a tuple of the number of bytes read and - | a bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | If no data is ready a bytes read of zero is returned. - | ... - | (b, d) = pi.serial_read(h2, 100) - | if b > 0: - | # process read data - | ... - | - | serial_read_byte(self, handle) - | Returns a single byte from the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | - | If no data is ready a negative error code will be returned. - | - | ... - | b = pi.serial_read_byte(h1) - | ... - | - | serial_write(self, handle, data) - | Writes the data bytes to the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | data:= the bytes to write. - | - | ... - | pi.serial_write(h1, b'\x02\x03\x04') - | - | pi.serial_write(h2, b'help') - | - | pi.serial_write(h2, "hello") - | - | pi.serial_write(h1, [2, 3, 4]) - | ... - | - | serial_write_byte(self, handle, byte_val) - | Writes a single byte to the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | byte_val:= 0-255, the value to write. - | - | ... - | pi.serial_write_byte(h1, 23) - | - | pi.serial_write_byte(h1, ord('Z')) - | ... - | - | set_PWM_dutycycle(self, user_gpio, dutycycle) - | Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. - | - | user_gpio:= 0-31. - | dutycycle:= 0-range (range defaults to 255). - | - | The [*set_PWM_range*] function can change the default range of 255. - | - | ... - | pi.set_PWM_dutycycle(4, 0) # PWM off - | pi.set_PWM_dutycycle(4, 64) # PWM 1/4 on - | pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on - | pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on - | pi.set_PWM_dutycycle(4, 255) # PWM full on - | ... - | - | set_PWM_frequency(self, user_gpio, frequency) - | Sets the frequency (in Hz) of the PWM to be used on the GPIO. - | - | user_gpio:= 0-31. - | frequency:= >=0 Hz - | - | Returns the numerically closest frequency if OK, otherwise - | PI_BAD_USER_GPIO or PI_NOT_PERMITTED. - | - | If PWM is currently active on the GPIO it will be switched - | off and then back on at the new frequency. - | - | Each GPIO can be independently set to one of 18 different - | PWM frequencies. - | - | The selectable frequencies depend upon the sample rate which - | may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The - | sample rate is set when the pigpio daemon is started. - | - | The frequencies for each sample rate are: - | - | . . - | Hertz - | - | 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 - | 1250 1000 800 500 400 250 200 100 50 - | - | 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 - | 625 500 400 250 200 125 100 50 25 - | - | 4: 10000 5000 2500 2000 1250 1000 625 500 400 - | 313 250 200 125 100 63 50 25 13 - | sample - | rate - | (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 - | 250 200 160 100 80 50 40 20 10 - | - | 8: 5000 2500 1250 1000 625 500 313 250 200 - | 156 125 100 63 50 31 25 13 6 - | - | 10: 4000 2000 1000 800 500 400 250 200 160 - | 125 100 80 50 40 25 20 10 5 - | . . - | - | ... - | pi.set_PWM_frequency(4,0) - | print(pi.get_PWM_frequency(4)) - | 10 - | - | pi.set_PWM_frequency(4,100000) - | print(pi.get_PWM_frequency(4)) - | 8000 - | ... - | - | set_PWM_range(self, user_gpio, range_) - | Sets the range of PWM values to be used on the GPIO. - | - | user_gpio:= 0-31. - | range_:= 25-40000. - | - | ... - | pi.set_PWM_range(9, 100) # now 25 1/4, 50 1/2, 75 3/4 on - | pi.set_PWM_range(9, 500) # now 125 1/4, 250 1/2, 375 3/4 on - | pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on - | ... - | - | set_bank_1(self, bits) - | Sets GPIO 0-31 if the corresponding bit in bits is set. - | - | bits:= a 32 bit mask with 1 set if the corresponding GPIO is - | to be set. - | - | A returned status of PI_SOME_PERMITTED indicates that the user - | is not allowed to write to one or more of the GPIO. - | - | ... - | pi.set_bank_1(int("111110010000",2)) - | ... - | - | set_bank_2(self, bits) - | Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. - | - | bits:= a 32 bit mask with 1 set if the corresponding GPIO is - | to be set. - | - | A returned status of PI_SOME_PERMITTED indicates that the user - | is not allowed to write to one or more of the GPIO. - | - | ... - | pi.set_bank_2(0x303) - | ... - | - | set_glitch_filter(self, user_gpio, steady) - | Sets a glitch filter on a GPIO. - | - | Level changes on the GPIO are not reported unless the level - | has been stable for at least [*steady*] microseconds. The - | level is then reported. Level changes of less than [*steady*] - | microseconds are ignored. - | - | user_gpio:= 0-31 - | steady:= 0-300000 - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - | - | This filter affects the GPIO samples returned to callbacks set up - | with [*callback*] and [*wait_for_edge*]. - | - | It does not affect levels read by [*read*], - | [*read_bank_1*], or [*read_bank_2*]. - | - | Each (stable) edge will be timestamped [*steady*] - | microseconds after it was first detected. - | - | ... - | pi.set_glitch_filter(23, 100) - | ... - | - | set_mode(self, gpio, mode) - | Sets the GPIO mode. - | - | gpio:= 0-53. - | mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5. - | - | ... - | pi.set_mode( 4, pigpio.INPUT) # GPIO 4 as input - | pi.set_mode(17, pigpio.OUTPUT) # GPIO 17 as output - | pi.set_mode(24, pigpio.ALT2) # GPIO 24 as ALT2 - | ... - | - | set_noise_filter(self, user_gpio, steady, active) - | Sets a noise filter on a GPIO. - | - | Level changes on the GPIO are ignored until a level which has - | been stable for [*steady*] microseconds is detected. Level - | changes on the GPIO are then reported for [*active*] - | microseconds after which the process repeats. - | - | user_gpio:= 0-31 - | steady:= 0-300000 - | active:= 0-1000000 - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - | - | This filter affects the GPIO samples returned to callbacks set up - | with [*callback*] and [*wait_for_edge*]. - | - | It does not affect levels read by [*read*], - | [*read_bank_1*], or [*read_bank_2*]. - | - | Level changes before and after the active period may - | be reported. Your software must be designed to cope with - | such reports. - | - | ... - | pi.set_noise_filter(23, 1000, 5000) - | ... - | - | set_pad_strength(self, pad, pad_strength) - | This function sets the pad drive strength in mA. - | - | - | pad:= 0-2, the pad to set. - | pad_strength:= 1-16 mA. - | - | Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. - | - | Pad @ GPIO - | 0 @ 0-27 - | 1 @ 28-45 - | 2 @ 46-53 - | - | ... - | pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA. - | ... - | - | set_pull_up_down(self, gpio, pud) - | Sets or clears the internal GPIO pull-up/down resistor. - | - | gpio:= 0-53. - | pud:= PUD_UP, PUD_DOWN, PUD_OFF. - | - | ... - | pi.set_pull_up_down(17, pigpio.PUD_OFF) - | pi.set_pull_up_down(23, pigpio.PUD_UP) - | pi.set_pull_up_down(24, pigpio.PUD_DOWN) - | ... - | - | set_servo_pulsewidth(self, user_gpio, pulsewidth) - | Starts (500-2500) or stops (0) servo pulses on the GPIO. - | - | user_gpio:= 0-31. - | pulsewidth:= 0 (off), - | 500 (most anti-clockwise) - 2500 (most clockwise). - | - | The selected pulsewidth will continue to be transmitted until - | changed by a subsequent call to set_servo_pulsewidth. - | - | The pulsewidths supported by servos varies and should probably - | be determined by experiment. A value of 1500 should always be - | safe and represents the mid-point of rotation. - | - | You can DAMAGE a servo if you command it to move beyond its - | limits. - | - | ... - | pi.set_servo_pulsewidth(17, 0) # off - | pi.set_servo_pulsewidth(17, 1000) # safe anti-clockwise - | pi.set_servo_pulsewidth(17, 1500) # centre - | pi.set_servo_pulsewidth(17, 2000) # safe clockwise - | ... - | - | set_watchdog(self, user_gpio, wdog_timeout) - | Sets a watchdog timeout for a GPIO. - | - | user_gpio:= 0-31. - | wdog_timeout:= 0-60000. - | - | The watchdog is nominally in milliseconds. - | - | Only one watchdog may be registered per GPIO. - | - | The watchdog may be cancelled by setting timeout to 0. - | - | Once a watchdog has been started callbacks for the GPIO - | will be triggered every timeout interval after the last - | GPIO activity. - | - | The callback will receive the special level TIMEOUT. - | - | ... - | pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23 - | pi.set_watchdog(23, 0) # cancel watchdog on GPIO 23 - | ... - | - | shell(self, shellscr, pstring='') - | This function uses the system call to execute a shell script - | with the given string as its parameter. - | - | shellscr:= the name of the script, only alphanumerics, - | '-' and '_' are allowed in the name - | pstring := the parameter string to pass to the script - | - | The exit status of the system call is returned if OK, - | otherwise PI_BAD_SHELL_STATUS. - | - | [*shellscr*] must exist in /opt/pigpio/cgi and must be executable. - | - | The returned exit status is normally 256 times that set by - | the shell script exit function. If the script can't be - | found 32512 will be returned. - | - | The following table gives some example returned statuses: - | - | Script exit status @ Returned system call status - | 1 @ 256 - | 5 @ 1280 - | 10 @ 2560 - | 200 @ 51200 - | script not found @ 32512 - | - | ... - | // pass two parameters, hello and world - | status = pi.shell("scr1", "hello world"); - | - | // pass three parameters, hello, string with spaces, and world - | status = pi.shell("scr1", "hello 'string with spaces' world"); - | - | // pass one parameter, hello string with spaces world - | status = pi.shell("scr1", "\"hello string with spaces world\""); - | ... - | - | spi_close(self, handle) - | Closes the SPI device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*spi_open*]). - | - | ... - | pi.spi_close(h) - | ... - | - | spi_open(self, spi_channel, baud, spi_flags=0) - | Returns a handle for the SPI device on the channel. Data - | will be transferred at baud bits per second. The flags - | may be used to modify the default behaviour of 4-wire - | operation, mode 0, active low chip select. - | - | 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 - | - | spi_channel:= 0-1 (0-2 for the auxiliary SPI). - | baud:= 32K-125M (values above 30M are unlikely to work). - | spi_flags:= see below. - | - | spi_flags consists of the least significant 22 bits. - | - | . . - | 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - | b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m - | . . - | - | mm defines the SPI mode. - | - | WARNING: modes 1 and 3 do not appear to work on - | the auxiliary SPI. - | - | . . - | 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 [*spi_read*], [*spi_write*], and [*spi_xfer*] functions - | transfer data packed into 1, 2, or 4 bytes according to - | the word size in bits. - | - | For bits 1-8 there will be one byte per character. - | For bits 9-16 there will be two bytes per character. - | For bits 17-32 there will be four bytes per character. - | - | Multi-byte transfers are made in least significant byte - | first order. - | - | E.g. to transfer 32 11-bit words data should - | contain 64 bytes. - | - | E.g. to transfer the 14 bit value 0x1ABC send the - | bytes 0xBC followed by 0x1A. - | - | The other bits in flags should be set to zero. - | - | ... - | # open SPI device on channel 1 in mode 3 at 50000 bits per second - | - | h = pi.spi_open(1, 50000, 3) - | ... - | - | spi_read(self, handle, count) - | Reads count bytes from the SPI device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*spi_open*]). - | count:= >0, the number of bytes to read. - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.spi_read(h, 60) # read 60 bytes from device h - | if b == 60: - | # process read data - | else: - | # error path - | ... - | - | spi_write(self, handle, data) - | Writes the data bytes to the SPI device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*spi_open*]). - | data:= the bytes to write. - | - | ... - | pi.spi_write(0, b'\x02\xc0\x80') # write 3 bytes to device 0 - | - | pi.spi_write(0, b'defgh') # write 5 bytes to device 0 - | - | pi.spi_write(0, "def") # write 3 bytes to device 0 - | - | pi.spi_write(1, [2, 192, 128]) # write 3 bytes to device 1 - | ... - | - | spi_xfer(self, handle, data) - | Writes the data bytes to the SPI device associated with handle, - | returning the data bytes read from the device. - | - | handle:= >=0 (as returned by a prior call to [*spi_open*]). - | data:= the bytes to write. - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00') - | - | (count, rx_data) = pi.spi_xfer(h, [1, 128, 0]) - | - | (count, rx_data) = pi.spi_xfer(h, b"hello") - | - | (count, rx_data) = pi.spi_xfer(h, "hello") - | ... - | - | stop(self) - | Release pigpio resources. - | - | ... - | pi.stop() - | ... - | - | stop_script(self, script_id) - | Stops a running script. - | - | script_id:= id of stored script. - | - | ... - | status = pi.stop_script(sid) - | ... - | - | store_script(self, script) - | Store a script for later execution. - | - | See [[http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts]] for - | details. - | - | script:= the script text as a series of bytes. - | - | Returns a >=0 script id if OK. - | - | ... - | sid = pi.store_script( - | b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0') - | ... - | - | update_script(self, script_id, params=None) - | Sets the parameters of a script. The script may or - | may not be running. The first parameters of the script are - | overwritten with the new values. - | - | script_id:= id of stored script. - | params:= up to 10 parameters required by the script. - | - | ... - | s = pi.update_script(sid, [par1, par2]) - | - | s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - | ... - | - | wait_for_edge(self, user_gpio, edge=0, wait_timeout=60.0) - | Wait for an edge event on a GPIO. - | - | user_gpio:= 0-31. - | edge:= EITHER_EDGE, RISING_EDGE (default), or - | FALLING_EDGE. - | wait_timeout:= >=0.0 (default 60.0). - | - | The function returns when the edge is detected or after - | the number of seconds specified by timeout has expired. - | - | Do not use this function for precise timing purposes, - | the edge is only checked 20 times a second. Whenever - | you need to know the accurate time of GPIO events use - | a [*callback*] function. - | - | The function returns True if the edge is detected, - | otherwise False. - | - | ... - | if pi.wait_for_edge(23): - | print("Rising edge detected") - | else: - | print("wait for edge timed out") - | - | if pi.wait_for_edge(23, pigpio.FALLING_EDGE, 5.0): - | print("Falling edge detected") - | else: - | print("wait for falling edge timed out") - | ... - | - | wait_for_event(self, event, wait_timeout=60.0) - | Wait for an event. - | - | event:= 0-31. - | wait_timeout:= >=0.0 (default 60.0). - | - | The function returns when the event is signalled or after - | the number of seconds specified by timeout has expired. - | - | The function returns True if the event is detected, - | otherwise False. - | - | ... - | if pi.wait_for_event(23): - | print("event detected") - | else: - | print("wait for event timed out") - | ... - | - | wave_add_generic(self, pulses) - | Adds a list of pulses to the current waveform. - | - | pulses:= list of pulses to add to the waveform. - | - | Returns the new total number of pulses in the current waveform. - | - | The pulses are interleaved in time order within the existing - | waveform (if any). - | - | Merging allows the waveform to be built in parts, that is the - | settings for GPIO#1 can be added, and then GPIO#2 etc. - | - | If the added waveform is intended to start after or within - | the existing waveform then the first pulse should consist - | solely of a delay. - | - | ... - | G1=4 - | G2=24 - | - | pi.set_mode(G1, pigpio.OUTPUT) - | pi.set_mode(G2, pigpio.OUTPUT) - | - | flash_500=[] # flash every 500 ms - | flash_100=[] # flash every 100 ms - | - | # ON OFF DELAY - | - | flash_500.append(pigpio.pulse(1<=0) if OK, otherwise PI_EMPTY_WAVEFORM, - | PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - | - | The data provided by the [*wave_add_**] functions is consumed by - | this function. - | - | As many waveforms may be created as there is space available. - | The wave id is passed to [*wave_send_**] to specify the waveform - | to transmit. - | - | Normal usage would be - | - | Step 1. [*wave_clear*] to clear all waveforms and added data. - | - | Step 2. [*wave_add_**] calls to supply the waveform data. - | - | Step 3. [*wave_create*] to create the waveform and get a unique id - | - | Repeat steps 2 and 3 as needed. - | - | Step 4. [*wave_send_**] with the id of the waveform to transmit. - | - | A waveform comprises one or more pulses. - | - | A pulse specifies - | - | 1) the GPIO to be switched on at the start of the pulse. - | 2) the GPIO to be switched off at the start of the pulse. - | 3) the delay in microseconds before the next pulse. - | - | Any or all the fields can be zero. It doesn't make any sense - | to set all the fields to zero (the pulse will be ignored). - | - | When a waveform is started each pulse is executed in order with - | the specified delay between the pulse and the next. - | - | ... - | wid = pi.wave_create() - | ... - | - | wave_create_and_pad(self, percent) - | This function creates a waveform like [*wave_create*] but pads the consumed - | resources. Where percent gives the percentage of the resources to use - | (in terms of the theoretical maximum, not the current amount free). - | This allows the reuse of deleted waves while a transmission is active. - | - | Upon success a wave id greater than or equal to 0 is returned, otherwise - | PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - | - | . . - | percent: 0-100, size of waveform as percentage of maximum available. - | . . - | - | The data provided by the [*wave_add_**] functions are consumed by this - | function. - | - | As many waveforms may be created as there is space available. The - | wave id is passed to [*wave_send_**] to specify the waveform to transmit. - | - | A usage would be the creation of two waves where one is filled while the - | other is being transmitted. Each wave is assigned 50% of the resources. - | This buffer structure allows the transmission of infinite wave sequences. - | - | Normal usage: - | - | Step 1. [*wave_clear*] to clear all waveforms and added data. - | - | Step 2. [*wave_add_**] calls to supply the waveform data. - | - | Step 3. [*wave_create_and_pad*] to create a waveform of uniform size. - | - | Step 4. [*wave_send_**] with the id of the waveform to transmit. - | - | Repeat steps 2-4 as needed. - | - | Step 5. Any wave id can now be deleted and another wave of the same size - | can be created in its place. - | - | ... - | wid = pi.wave_create_and_pad(50) - | ... - | - | wave_delete(self, wave_id) - | This function deletes the waveform with id wave_id. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | - | Wave ids are allocated in order, 0, 1, 2, etc. - | - | The wave is flagged for deletion. The resources used by the wave - | will only be reused when either of the following apply. - | - | - all waves with higher numbered wave ids have been deleted or have - | been flagged for deletion. - | - | - a new wave is created which uses exactly the same resources as - | the current wave (see the C source for gpioWaveCreate for details). - | - | ... - | pi.wave_delete(6) # delete waveform with id 6 - | - | pi.wave_delete(0) # delete waveform with id 0 - | ... - | - | wave_get_cbs(self) - | Returns the length in DMA control blocks of the current - | waveform. - | - | ... - | cbs = pi.wave_get_cbs() - | ... - | - | wave_get_max_cbs(self) - | Returns the maximum possible size of a waveform in DMA - | control blocks. - | - | ... - | cbs = pi.wave_get_max_cbs() - | ... - | - | wave_get_max_micros(self) - | Returns the maximum possible size of a waveform in microseconds. - | - | ... - | micros = pi.wave_get_max_micros() - | ... - | - | wave_get_max_pulses(self) - | Returns the maximum possible size of a waveform in pulses. - | - | ... - | pulses = pi.wave_get_max_pulses() - | ... - | - | wave_get_micros(self) - | Returns the length in microseconds of the current waveform. - | - | ... - | micros = pi.wave_get_micros() - | ... - | - | wave_get_pulses(self) - | Returns the length in pulses of the current waveform. - | - | ... - | pulses = pi.wave_get_pulses() - | ... - | - | wave_send_once(self, wave_id) - | Transmits the waveform with id wave_id. The waveform is sent - | once. - | - | NOTE: Any hardware PWM started by [*hardware_PWM*] will - | be cancelled. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | - | Returns the number of DMA control blocks used in the waveform. - | - | ... - | cbs = pi.wave_send_once(wid) - | ... - | - | wave_send_repeat(self, wave_id) - | Transmits the waveform with id wave_id. The waveform repeats - | until wave_tx_stop is called or another call to [*wave_send_**] - | is made. - | - | NOTE: Any hardware PWM started by [*hardware_PWM*] will - | be cancelled. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | - | Returns the number of DMA control blocks used in the waveform. - | - | ... - | cbs = pi.wave_send_repeat(wid) - | ... - | - | wave_send_using_mode(self, wave_id, mode) - | Transmits the waveform with id wave_id using mode mode. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, - | WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC. - | - | WAVE_MODE_ONE_SHOT: same as [*wave_send_once*]. - | - | WAVE_MODE_REPEAT same as [*wave_send_repeat*]. - | - | WAVE_MODE_ONE_SHOT_SYNC same as [*wave_send_once*] but tries - | to sync with the previous waveform. - | - | WAVE_MODE_REPEAT_SYNC same as [*wave_send_repeat*] but tries - | to sync with the previous waveform. - | - | WARNING: bad things may happen if you delete the previous - | waveform before it has been synced to the new waveform. - | - | NOTE: Any hardware PWM started by [*hardware_PWM*] will - | be cancelled. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | - | Returns the number of DMA control blocks used in the waveform. - | - | ... - | cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC) - | ... - | - | wave_tx_at(self) - | Returns the id of the waveform currently being - | transmitted. - | - | Returns the waveform id or one of the following special - | values: - | - | WAVE_NOT_FOUND (9998) - transmitted wave not found. - | NO_TX_WAVE (9999) - no wave being transmitted. - | - | ... - | wid = pi.wave_tx_at() - | ... - | - | wave_tx_busy(self) - | Returns 1 if a waveform is currently being transmitted, - | otherwise 0. - | - | ... - | pi.wave_send_once(0) # send first waveform - | - | while pi.wave_tx_busy(): # wait for waveform to be sent - | time.sleep(0.1) - | - | pi.wave_send_once(1) # send next waveform - | ... - | - | wave_tx_repeat(self) - | This function is deprecated and has beeen removed. - | - | Use [*wave_create*]/[*wave_send_**] instead. - | - | wave_tx_start(self) - | This function is deprecated and has been removed. - | - | Use [*wave_create*]/[*wave_send_**] instead. - | - | wave_tx_stop(self) - | Stops the transmission of the current waveform. - | - | This function is intended to stop a waveform started with - | wave_send_repeat. - | - | ... - | pi.wave_send_repeat(3) - | - | time.sleep(5) - | - | pi.wave_tx_stop() - | ... - | - | write(self, gpio, level) - | Sets the GPIO level. - | - | GPIO:= 0-53. - | level:= 0, 1. - | - | If PWM or servo pulses are active on the GPIO they are - | switched off. - | - | ... - | pi.set_mode(17, pigpio.OUTPUT) - | - | pi.write(17,0) - | print(pi.read(17)) - | 0 - | - | pi.write(17,1) - | print(pi.read(17)) - | 1 - | ... - - class pulse - | A class to store pulse information. - | - | Methods defined here: - | - | __init__(self, gpio_on, gpio_off, delay) - | Initialises a pulse. - | - | gpio_on:= the GPIO to switch on at the start of the pulse. - | gpio_off:= the GPIO to switch off at the start of the pulse. - | delay:= the delay in microseconds before the next pulse. - -FUNCTIONS - error_text(errnum) - Returns a text description of a pigpio error. - - errnum:= <0, the error number - - ... - print(pigpio.error_text(-5)) - level not 0-1 - ... - - tickDiff(t1, t2) - Returns the microsecond difference between two ticks. - - t1:= the earlier tick - t2:= the later tick - - ... - print(pigpio.tickDiff(4294967272, 12)) - 36 - ... - - u2i(uint32) - Converts a 32 bit unsigned number to signed. - - uint32:= an unsigned 32 bit number - - ... - print(u2i(4294967272)) - -24 - print(u2i(37)) - 37 - ... - - xref() - active: 0-1000000 - The number of microseconds level changes are reported for once - a noise filter has been triggered (by [*steady*] microseconds of - a stable level). - - - arg1: - An unsigned argument passed to a user customised function. Its - meaning is defined by the customiser. - - arg2: - An unsigned argument passed to a user customised function. Its - meaning is defined by the customiser. - - argx: - An array of bytes passed to a user customised function. - Its meaning and content is defined by the customiser. - - baud: - The speed of serial communication (I2C, SPI, serial link, waves) - in bits per second. - - bb_bits: 1-32 - The number of data bits to be used when adding serial data to a - waveform. - - bb_stop: 2-8 - The number of (half) stop bits to be used when adding serial data - to a waveform. - - bit: 0-1 - A value of 0 or 1. - - bits: 32 bit number - A mask used to select GPIO to be operated on. If bit n is set - then GPIO n is selected. A convenient way of setting bit n is to - bit or in the value (1<=1 - The length of a pulse in microseconds. - - dutycycle: 0-range_ - A number between 0 and range_. - - The dutycycle sets the proportion of time on versus time off during each - PWM cycle. - - Dutycycle @ On time - 0 @ Off - range_ * 0.25 @ 25% On - range_ * 0.50 @ 50% On - range_ * 0.75 @ 75% On - range_ @ Fully On - - edge: 0-2 - - . . - EITHER_EDGE = 2 - FALLING_EDGE = 1 - RISING_EDGE = 0 - . . - - errnum: <0 - - . . - PI_BAD_USER_GPIO = -2 - PI_BAD_GPIO = -3 - PI_BAD_MODE = -4 - PI_BAD_LEVEL = -5 - PI_BAD_PUD = -6 - PI_BAD_PULSEWIDTH = -7 - PI_BAD_DUTYCYCLE = -8 - PI_BAD_WDOG_TIMEOUT = -15 - PI_BAD_DUTYRANGE = -21 - PI_NO_HANDLE = -24 - PI_BAD_HANDLE = -25 - PI_BAD_WAVE_BAUD = -35 - PI_TOO_MANY_PULSES = -36 - PI_TOO_MANY_CHARS = -37 - PI_NOT_SERIAL_GPIO = -38 - PI_NOT_PERMITTED = -41 - PI_SOME_PERMITTED = -42 - PI_BAD_WVSC_COMMND = -43 - PI_BAD_WVSM_COMMND = -44 - PI_BAD_WVSP_COMMND = -45 - PI_BAD_PULSELEN = -46 - PI_BAD_SCRIPT = -47 - PI_BAD_SCRIPT_ID = -48 - PI_BAD_SER_OFFSET = -49 - PI_GPIO_IN_USE = -50 - PI_BAD_SERIAL_COUNT = -51 - PI_BAD_PARAM_NUM = -52 - PI_DUP_TAG = -53 - PI_TOO_MANY_TAGS = -54 - PI_BAD_SCRIPT_CMD = -55 - PI_BAD_VAR_NUM = -56 - PI_NO_SCRIPT_ROOM = -57 - PI_NO_MEMORY = -58 - PI_SOCK_READ_FAILED = -59 - PI_SOCK_WRIT_FAILED = -60 - PI_TOO_MANY_PARAM = -61 - PI_SCRIPT_NOT_READY = -62 - PI_BAD_TAG = -63 - PI_BAD_MICS_DELAY = -64 - PI_BAD_MILS_DELAY = -65 - PI_BAD_WAVE_ID = -66 - PI_TOO_MANY_CBS = -67 - PI_TOO_MANY_OOL = -68 - PI_EMPTY_WAVEFORM = -69 - PI_NO_WAVEFORM_ID = -70 - PI_I2C_OPEN_FAILED = -71 - PI_SER_OPEN_FAILED = -72 - PI_SPI_OPEN_FAILED = -73 - PI_BAD_I2C_BUS = -74 - PI_BAD_I2C_ADDR = -75 - PI_BAD_SPI_CHANNEL = -76 - PI_BAD_FLAGS = -77 - PI_BAD_SPI_SPEED = -78 - PI_BAD_SER_DEVICE = -79 - PI_BAD_SER_SPEED = -80 - PI_BAD_PARAM = -81 - PI_I2C_WRITE_FAILED = -82 - PI_I2C_READ_FAILED = -83 - PI_BAD_SPI_COUNT = -84 - PI_SER_WRITE_FAILED = -85 - PI_SER_READ_FAILED = -86 - PI_SER_READ_NO_DATA = -87 - PI_UNKNOWN_COMMAND = -88 - PI_SPI_XFER_FAILED = -89 - PI_NO_AUX_SPI = -91 - PI_NOT_PWM_GPIO = -92 - PI_NOT_SERVO_GPIO = -93 - PI_NOT_HCLK_GPIO = -94 - PI_NOT_HPWM_GPIO = -95 - PI_BAD_HPWM_FREQ = -96 - PI_BAD_HPWM_DUTY = -97 - PI_BAD_HCLK_FREQ = -98 - PI_BAD_HCLK_PASS = -99 - PI_HPWM_ILLEGAL = -100 - PI_BAD_DATABITS = -101 - PI_BAD_STOPBITS = -102 - PI_MSG_TOOBIG = -103 - PI_BAD_MALLOC_MODE = -104 - PI_BAD_SMBUS_CMD = -107 - PI_NOT_I2C_GPIO = -108 - PI_BAD_I2C_WLEN = -109 - PI_BAD_I2C_RLEN = -110 - PI_BAD_I2C_CMD = -111 - PI_BAD_I2C_BAUD = -112 - PI_CHAIN_LOOP_CNT = -113 - PI_BAD_CHAIN_LOOP = -114 - PI_CHAIN_COUNTER = -115 - PI_BAD_CHAIN_CMD = -116 - PI_BAD_CHAIN_DELAY = -117 - PI_CHAIN_NESTING = -118 - PI_CHAIN_TOO_BIG = -119 - PI_DEPRECATED = -120 - PI_BAD_SER_INVERT = -121 - PI_BAD_FOREVER = -124 - PI_BAD_FILTER = -125 - PI_BAD_PAD = -126 - PI_BAD_STRENGTH = -127 - PI_FIL_OPEN_FAILED = -128 - PI_BAD_FILE_MODE = -129 - PI_BAD_FILE_FLAG = -130 - PI_BAD_FILE_READ = -131 - PI_BAD_FILE_WRITE = -132 - PI_FILE_NOT_ROPEN = -133 - PI_FILE_NOT_WOPEN = -134 - PI_BAD_FILE_SEEK = -135 - PI_NO_FILE_MATCH = -136 - PI_NO_FILE_ACCESS = -137 - PI_FILE_IS_A_DIR = -138 - PI_BAD_SHELL_STATUS = -139 - PI_BAD_SCRIPT_NAME = -140 - PI_BAD_SPI_BAUD = -141 - PI_NOT_SPI_GPIO = -142 - PI_BAD_EVENT_ID = -143 - PI_CMD_INTERRUPTED = -144 - PI_NOT_ON_BCM2711 = -145 - PI_ONLY_ON_BCM2711 = -146 - . . - - event:0-31 - An event is a signal used to inform one or more consumers - to start an action. - - file_mode: - The mode may have the following values - - . . - FILE_READ 1 - FILE_WRITE 2 - FILE_RW 3 - . . - - The following values can be or'd into the file open mode - - . . - FILE_APPEND 4 - FILE_CREATE 8 - FILE_TRUNC 16 - . . - - file_name: - A full file path. To be accessible the path must match - an entry in /opt/pigpio/access. - - fpattern: - A file path which may contain wildcards. To be accessible the path - must match an entry in /opt/pigpio/access. - - frequency: 0-40000 - Defines the frequency to be used for PWM on a GPIO. - The closest permitted frequency will be used. - - func: - A user supplied callback function. - - gpio: 0-53 - A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. - - 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 [*get_hardware_revision*]. - - 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 - - - - - . . - - gpio_off: - A mask used to select GPIO to be operated on. See [*bits*]. - - This mask selects the GPIO to be switched off at the start - of a pulse. - - gpio_on: - A mask used to select GPIO to be operated on. See [*bits*]. - - This mask selects the GPIO to be switched on at the start - of a pulse. - - handle: >=0 - A number referencing an object opened by one of the following - - [*file_open*] - [*i2c_open*] - [*notify_open*] - [*serial_open*] - [*spi_open*] - - host: - The name or IP address of the Pi running the pigpio daemon. - - i2c_address: 0-0x7F - The address of a device on the I2C bus. - - i2c_bus: >=0 - An I2C bus number. - - i2c_flags: 0 - No I2C flags are currently defined. - - invert: 0-1 - A flag used to set normal or inverted bit bang serial data - level logic. - - level: 0-1 (2) - - . . - CLEAR = 0 - HIGH = 1 - LOW = 0 - OFF = 0 - ON = 1 - SET = 1 - TIMEOUT = 2 # only returned for a watchdog timeout - . . - - MISO: - The GPIO used for the MISO signal when bit banging SPI. - - mode: - - 1.The operational mode of a GPIO, normally INPUT or OUTPUT. - - . . - ALT0 = 4 - ALT1 = 5 - ALT2 = 6 - ALT3 = 7 - ALT4 = 3 - ALT5 = 2 - INPUT = 0 - OUTPUT = 1 - . . - - 2. The mode of waveform transmission. - - . . - WAVE_MODE_ONE_SHOT = 0 - WAVE_MODE_REPEAT = 1 - WAVE_MODE_ONE_SHOT_SYNC = 2 - WAVE_MODE_REPEAT_SYNC = 3 - . . - - MOSI: - The GPIO used for the MOSI signal when bit banging SPI. - - offset: >=0 - The offset wave data starts from the beginning of the waveform - being currently defined. - - pad: 0-2 - A set of GPIO which share common drivers. - - Pad @ GPIO - 0 @ 0-27 - 1 @ 28-45 - 2 @ 46-53 - - pad_strength: 1-16 - The mA which may be drawn from each GPIO whilst still guaranteeing the - high and low levels. - - params: 32 bit number - When scripts are started they can receive up to 10 parameters - to define their operation. - - percent:: 0-100 - The size of waveform as percentage of maximum available. - - port: - The port used by the pigpio daemon, defaults to 8888. - - pstring: - The string to be passed to a [*shell*] script to be executed. - - pud: 0-2 - . . - PUD_DOWN = 1 - PUD_OFF = 0 - PUD_UP = 2 - . . - - pulse_len: 1-100 - The length of the trigger pulse in microseconds. - - pulses: - A list of class pulse objects defining the characteristics of a - waveform. - - pulsewidth: - The servo pulsewidth in microseconds. 0 switches pulses off. - - PWMduty: 0-1000000 (1M) - The hardware PWM dutycycle. - - PWMfreq: 1-125M (1-187.5M for the BCM2711) - The hardware PWM frequency. - - range_: 25-40000 - Defines the limits for the [*dutycycle*] parameter. - - range_ defaults to 255. - - reg: 0-255 - An I2C device register. The usable registers depend on the - actual device. - - retMax: >=0 - The maximum number of bytes a user customised function - should return, default 8192. - - SCL: - The user GPIO to use for the clock when bit banging I2C. - - SCLK:: - The GPIO used for the SCLK signal when bit banging SPI. - - script: - The text of a script to store on the pigpio daemon. - - script_id: >=0 - A number referencing a script created by [*store_script*]. - - SDA: - The user GPIO to use for data when bit banging I2C. - - seek_from: 0-2 - Direction to seek for [*file_seek*]. - - . . - FROM_START=0 - FROM_CURRENT=1 - FROM_END=2 - . . - - seek_offset: - The number of bytes to move forward (positive) or backwards - (negative) from the seek position (start, current, or end of file). - - ser_flags: 32 bit - No serial flags are currently defined. - - serial_*: - One of the serial_ functions. - - shellscr: - The name of a shell script. The script must exist - in /opt/pigpio/cgi and must be executable. - - show_errors: - Controls the display of pigpio daemon connection failures. - The default of True prints the probable failure reasons to - standard output. - - spi_channel: 0-2 - A SPI channel. - - spi_flags: 32 bit - See [*spi_open*]. - - steady: 0-300000 - - The number of microseconds level changes must be stable for - before reporting the level changed ([*set_glitch_filter*]) - or triggering the active part of a noise filter - ([*set_noise_filter*]). - - t1: - A tick (earlier). - - t2: - A tick (later). - - tty: - A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0 - - uint32: - An unsigned 32 bit number. - - user_gpio: 0-31 - A Broadcom numbered GPIO. - - All the user GPIO are in the range 0-31. - - Not all the GPIO within this range are usable, some are reserved - for system use. - - See [*gpio*]. - - wait_timeout: 0.0 - - The number of seconds to wait in [*wait_for_edge*] before timing out. - - wave_add_*: - One of the following - - [*wave_add_new*] - [*wave_add_generic*] - [*wave_add_serial*] - - wave_id: >=0 - A number referencing a wave created by [*wave_create*]. - - wave_send_*: - One of the following - - [*wave_send_once*] - [*wave_send_repeat*] - - wdog_timeout: 0-60000 - Defines a GPIO watchdog timeout in milliseconds. If no level - change is detected on the GPIO for timeout millisecond a watchdog - timeout report is issued (with level TIMEOUT). - - word_val: 0-65535 - A whole number. - -DATA - ALT0 = 4 - ALT1 = 5 - ALT2 = 6 - ALT3 = 7 - ALT4 = 3 - ALT5 = 2 - CLEAR = 0 - EITHER_EDGE = 2 - EVENT_BSC = 31 - FALLING_EDGE = 1 - FILE_APPEND = 4 - FILE_CREATE = 8 - FILE_READ = 1 - FILE_RW = 3 - FILE_TRUNC = 16 - FILE_WRITE = 2 - FROM_CURRENT = 1 - FROM_END = 2 - FROM_START = 0 - HIGH = 1 - INPUT = 0 - LOW = 0 - NO_TX_WAVE = 9999 - NTFY_FLAGS_ALIVE = 64 - NTFY_FLAGS_EVENT = 128 - NTFY_FLAGS_GPIO = 31 - NTFY_FLAGS_WDOG = 32 - OFF = 0 - ON = 1 - OUTPUT = 1 - PI_BAD_CHAIN_CMD = -116 - PI_BAD_CHAIN_DELAY = -117 - PI_BAD_CHAIN_LOOP = -114 - PI_BAD_DATABITS = -101 - PI_BAD_DUTYCYCLE = -8 - PI_BAD_DUTYRANGE = -21 - PI_BAD_EVENT_ID = -143 - PI_BAD_FILE_FLAG = -130 - PI_BAD_FILE_MODE = -129 - PI_BAD_FILE_READ = -131 - PI_BAD_FILE_SEEK = -135 - PI_BAD_FILE_WRITE = -132 - PI_BAD_FILTER = -125 - PI_BAD_FLAGS = -77 - PI_BAD_FOREVER = -124 - PI_BAD_GPIO = -3 - PI_BAD_HANDLE = -25 - PI_BAD_HCLK_FREQ = -98 - PI_BAD_HCLK_PASS = -99 - PI_BAD_HPWM_DUTY = -97 - PI_BAD_HPWM_FREQ = -96 - PI_BAD_I2C_ADDR = -75 - PI_BAD_I2C_BAUD = -112 - PI_BAD_I2C_BUS = -74 - PI_BAD_I2C_CMD = -111 - PI_BAD_I2C_RLEN = -110 - PI_BAD_I2C_WLEN = -109 - PI_BAD_LEVEL = -5 - PI_BAD_MALLOC_MODE = -104 - PI_BAD_MICS_DELAY = -64 - PI_BAD_MILS_DELAY = -65 - PI_BAD_MODE = -4 - PI_BAD_PAD = -126 - PI_BAD_PARAM = -81 - PI_BAD_PARAM_NUM = -52 - PI_BAD_PUD = -6 - PI_BAD_PULSELEN = -46 - PI_BAD_PULSEWIDTH = -7 - PI_BAD_SCRIPT = -47 - PI_BAD_SCRIPT_CMD = -55 - PI_BAD_SCRIPT_ID = -48 - PI_BAD_SCRIPT_NAME = -140 - PI_BAD_SERIAL_COUNT = -51 - PI_BAD_SER_DEVICE = -79 - PI_BAD_SER_INVERT = -121 - PI_BAD_SER_OFFSET = -49 - PI_BAD_SER_SPEED = -80 - PI_BAD_SHELL_STATUS = -139 - PI_BAD_SMBUS_CMD = -107 - PI_BAD_SPI_BAUD = -141 - PI_BAD_SPI_CHANNEL = -76 - PI_BAD_SPI_COUNT = -84 - PI_BAD_SPI_SPEED = -78 - PI_BAD_STOPBITS = -102 - PI_BAD_STRENGTH = -127 - PI_BAD_TAG = -63 - PI_BAD_USER_GPIO = -2 - PI_BAD_VAR_NUM = -56 - PI_BAD_WAVE_BAUD = -35 - PI_BAD_WAVE_ID = -66 - PI_BAD_WDOG_TIMEOUT = -15 - PI_BAD_WVSC_COMMND = -43 - PI_BAD_WVSM_COMMND = -44 - PI_BAD_WVSP_COMMND = -45 - PI_CHAIN_COUNTER = -115 - PI_CHAIN_LOOP_CNT = -113 - PI_CHAIN_NESTING = -118 - PI_CHAIN_TOO_BIG = -119 - PI_CMD_INTERRUPTED = -144 - PI_DEPRECATED = -120 - PI_DUP_TAG = -53 - PI_EMPTY_WAVEFORM = -69 - PI_FILE_IS_A_DIR = -138 - PI_FILE_NOT_ROPEN = -133 - PI_FILE_NOT_WOPEN = -134 - PI_FIL_OPEN_FAILED = -128 - PI_GPIO_IN_USE = -50 - PI_HPWM_ILLEGAL = -100 - PI_I2C_OPEN_FAILED = -71 - PI_I2C_READ_FAILED = -83 - PI_I2C_WRITE_FAILED = -82 - PI_MSG_TOOBIG = -103 - PI_NOT_HCLK_GPIO = -94 - PI_NOT_HPWM_GPIO = -95 - PI_NOT_I2C_GPIO = -108 - PI_NOT_ON_BCM2711 = -145 - PI_NOT_PERMITTED = -41 - PI_NOT_PWM_GPIO = -92 - PI_NOT_SERIAL_GPIO = -38 - PI_NOT_SERVO_GPIO = -93 - PI_NOT_SPI_GPIO = -142 - PI_NO_AUX_SPI = -91 - PI_NO_FILE_ACCESS = -137 - PI_NO_FILE_MATCH = -136 - PI_NO_HANDLE = -24 - PI_NO_MEMORY = -58 - PI_NO_SCRIPT_ROOM = -57 - PI_NO_WAVEFORM_ID = -70 - PI_ONLY_ON_BCM2711 = -146 - PI_SCRIPT_FAILED = 4 - PI_SCRIPT_HALTED = 1 - PI_SCRIPT_INITING = 0 - PI_SCRIPT_NOT_READY = -62 - PI_SCRIPT_RUNNING = 2 - PI_SCRIPT_WAITING = 3 - PI_SER_OPEN_FAILED = -72 - PI_SER_READ_FAILED = -86 - PI_SER_READ_NO_DATA = -87 - PI_SER_WRITE_FAILED = -85 - PI_SOCK_READ_FAILED = -59 - PI_SOCK_WRIT_FAILED = -60 - PI_SOME_PERMITTED = -42 - PI_SPI_OPEN_FAILED = -73 - PI_SPI_XFER_FAILED = -89 - PI_TOO_MANY_CBS = -67 - PI_TOO_MANY_CHARS = -37 - PI_TOO_MANY_OOL = -68 - PI_TOO_MANY_PARAM = -61 - PI_TOO_MANY_PULSES = -36 - PI_TOO_MANY_TAGS = -54 - PI_UNKNOWN_COMMAND = -88 - PUD_DOWN = 1 - PUD_OFF = 0 - PUD_UP = 2 - RISING_EDGE = 0 - SET = 1 - SPI_CPHA = 1 - SPI_CPOL = 2 - SPI_CS_HIGH_ACTIVE = 4 - SPI_MODE_0 = 0 - SPI_MODE_1 = 1 - SPI_MODE_2 = 2 - SPI_MODE_3 = 3 - SPI_RX_LSBFIRST = 32768 - SPI_TX_LSBFIRST = 16384 - TIMEOUT = 2 - VERSION = '1.46' - WAVE_MODE_ONE_SHOT = 0 - WAVE_MODE_ONE_SHOT_SYNC = 2 - WAVE_MODE_REPEAT = 1 - WAVE_MODE_REPEAT_SYNC = 3 - WAVE_NOT_FOUND = 9998 - exceptions = True - - -- cgit v1.2.3 From d2ec8894dc454e3e8a7c990c17aff14e90850700 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 30 Apr 2020 13:30:59 -0500 Subject: Fix DOC/MAN folder. --- .gitignore | 3 ++- DOC/MAN/README | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 DOC/MAN/README diff --git a/.gitignore b/.gitignore index 7885815..4449b61 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,6 @@ dist # DOC files DOC/dbase/pigpio.sqlite.* DOC/tmp -DOC/MAN +DOC/MAN/* +!DOC/MAN/README* DOC/HTML/*.html diff --git a/DOC/MAN/README b/DOC/MAN/README new file mode 100644 index 0000000..cde5d85 --- /dev/null +++ b/DOC/MAN/README @@ -0,0 +1 @@ +Placeholder directory for man pages. -- cgit v1.2.3 From e9a0dd8ead58eb5e15c62e64d36a788c27835a9c Mon Sep 17 00:00:00 2001 From: hazuki Date: Sun, 26 Apr 2020 17:42:35 +0900 Subject: Remove excessive PROT_EXEC --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 1bdae12..5b11476 100644 --- a/pigpio.c +++ b/pigpio.c @@ -7318,7 +7318,7 @@ static int initGrabLockFile(void) static uint32_t * initMapMem(int fd, uint32_t addr, uint32_t len) { return (uint32_t *) mmap(0, len, - PROT_READ|PROT_WRITE|PROT_EXEC, + PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fd, addr); } -- cgit v1.2.3 From c05024e20abc8d030ae1c19f9aa3e741c946296a Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Fri, 1 May 2020 11:17:39 -0500 Subject: Bump rev to 7601. --- pigpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.h b/pigpio.h index 5794e4e..7aa6f78 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7600 +#define PIGPIO_VERSION 7601 /*TEXT -- cgit v1.2.3 From 1c9b6e2790fd8a1a1291b41a28a1b8cb9f6f7a32 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sat, 2 May 2020 11:17:25 -0500 Subject: Issue #220 Calling exit from a signal handler is not safe. --- pigpio.c | 6 +++--- pigpio.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pigpio.c b/pigpio.c index 5b11476..5e04e0a 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 76 */ +/* pigpio version 7602 */ /* include ------------------------------------------------------- */ @@ -5621,7 +5621,7 @@ static void sigHandler(int signum) default: DBG(DBG_ALWAYS, "Unhandled signal %d, terminating\n", signum); gpioTerminate(); - exit(-1); + _exit(); } } } @@ -5631,7 +5631,7 @@ static void sigHandler(int signum) DBG(DBG_ALWAYS, "Unhandled signal %d, terminating\n", signum); gpioTerminate(); - exit(-1); + _exit(); } } diff --git a/pigpio.h b/pigpio.h index 7aa6f78..56a5f11 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7601 +#define PIGPIO_VERSION 7602 /*TEXT -- cgit v1.2.3 From 18e532b8407c564942185e618b3becb6b75af234 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Mon, 4 May 2020 20:46:45 +0100 Subject: updated pigs.def for WVCAP and download.html for download version --- .gitignore | 6 ++++++ DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/defs/pigs.def | 27 +++++++++++++-------------- DOC/src/html/download.html | 14 ++++++++------ pigs.1 | 34 ++++++++++++++++++---------------- 5 files changed, 45 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 140d796..39331b5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,10 @@ build dist *.egg-info wavepad_jitter.py +# DOC files +DOC/dbase/pigpio.sqlite.* +DOC/tmp +DOC/MAN/* +!DOC/MAN/README* +DOC/HTML/*.html diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index 531ccfd..22ceb98 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/defs/pigs.def b/DOC/src/defs/pigs.def index 2f6d23c..7c3ef07 100644 --- a/DOC/src/defs/pigs.def +++ b/DOC/src/defs/pigs.def @@ -320,7 +320,7 @@ 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 +WVCAP percent :: Create a waveform of fixed size :: gpioWaveCreatePad WVDEL wid :: Delete selected waveform :: gpioWaveDelete WVTX wid :: Transmits waveform once :: gpioWaveTxSend @@ -2786,20 +2786,13 @@ ERROR: attempt to create an empty waveform WVCAP :: -Similar to [*WVCRE*], this command creates a waveform but pads the consumed -resources to a fixed size, specified as a percent of total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. +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 allowing newly created waves to re-use the resources of deleted waves of the same dimension. -Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. +Upon success a wave id (>=0) is returned. On error a negative status code will be returned. -The data provided by the [*WVAG*] and [*WVAS*] commands are -consumed by this command. +The data provided by the [*WVAG*] and [*WVAS*] commands are consumed by this command. -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. +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 @@ -2813,8 +2806,9 @@ Step 4. [*WVTX*] or [*WVTXR*] with the id of the waveform to transmit. Repeat steps 2 - 4 as needed. -Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. +Step 5. Any wave id can now be deleted and another wave of the same size can be created in its place. + +Example ... # Create a wave that consumes 50% of the total resource: @@ -3200,6 +3194,11 @@ 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. diff --git a/DOC/src/html/download.html b/DOC/src/html/download.html index 8c2c7be..740a3c8 100644 --- a/DOC/src/html/download.html +++ b/DOC/src/html/download.html @@ -1,7 +1,7 @@ - + download @@ -14,12 +14,14 @@ pigpiod).
compilation of pigpio.c, takes 100 seconds on early model Pis.  Be patient.  The overall install takes just over 3 minutes.
-

Download and install (V75)

-wget https://github.com/joan2937/pigpio/archive/v75.zip
-unzip v75.zip
-cd pigpio-75
+

Download and install latest version

+ +wget https://github.com/joan2937/pigpio/archive/master.zip
+unzip master.zip
+cd pigpio-master
make
-sudo make install

+sudo make install
+

If the Python part of the install fails it may be because you need the setup tools.
diff --git a/pigs.1 b/pigs.1 index 9b6192c..b315910 100644 --- a/pigs.1 +++ b/pigs.1 @@ -548,8 +548,8 @@ Add serial data to waveform .B WVCRE Create a waveform .P -.B WVCAP -Create a waveform of fixed size +.B WVCAP percent +Create a waveform of fixed size .P .B WVDEL wid Delete selected waveform @@ -5142,27 +5142,20 @@ ERROR: attempt to create an empty waveform .br -.IP "\fBWVCAP \fP - Create a waveform of fixed size" +.IP "\fBWVCAP percent\fP - Create a waveform of fixed size" .IP "" 4 .br -Similar to \fBWVCRE\fP, this command creates a waveform but pads the consumed -resources to a fixed size, specified as a percent of total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. +Create a waveform of fixed size. Similar to \fBWVCRE\fP, this command creates a waveform but pads the consumed resources to a fixed size, specified as a \fBpercent\fP of the total resources. Padded waves of equal size can be re-cycled efficiently allowing newly created waves to re-use the resources of deleted waves of the same dimension. .br -Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. +Upon success a wave id (>=0) is returned. On error a negative status code will be returned. .br -The data provided by the \fBWVAG\fP and \fBWVAS\fP commands are -consumed by this command. +The data provided by the \fBWVAG\fP and \fBWVAS\fP commands are consumed by this command. .br -As many waveforms may be created as there is space available. -The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the -waveform to transmit. +As many waveforms may be created as there is space available. The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the waveform to transmit. .br Normal usage would be @@ -5183,8 +5176,10 @@ Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit. Repeat steps 2 - 4 as needed. .br -Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. +Step 5. Any wave id can now be deleted and another wave of the same size can be created in its place. + +.br +Example .br @@ -5881,6 +5876,13 @@ The command expects a dutycycle. .br +.IP "\fBpercent\fP - percent (1-100)" 0 +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). + +.br + .IP "\fBpf\fP - hardware PWM frequency (1-125M, 1-187.5M for the BCM2711)" 0 The command expects a frequency. -- cgit v1.2.3 From c85285ee38d610fcb63a4d917c015208db713825 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Thu, 7 May 2020 11:53:04 +0100 Subject: fixed untracked files --- DOC/HTML/cif.html | 1887 ----- DOC/HTML/download.html | 121 - DOC/HTML/ex_LDR.html | 205 - DOC/HTML/ex_ir_remote.html | 308 - DOC/HTML/ex_motor_shield.html | 309 - DOC/HTML/ex_rotary_encoder.html | 240 - DOC/HTML/ex_sonar_ranger.html | 219 - DOC/HTML/examples.html | 558 -- DOC/HTML/faq.html | 516 -- DOC/HTML/index.html | 716 -- DOC/HTML/misc.html | 88 - DOC/HTML/pdif.html | 1168 --- DOC/HTML/pdif2.html | 1523 ---- DOC/HTML/pif.html | 85 - DOC/HTML/pig2vcd.html | 83 - DOC/HTML/pigpiod.html | 114 - DOC/HTML/pigs.html | 1268 --- DOC/HTML/piscope.html | 269 - DOC/HTML/python.html | 1294 --- DOC/HTML/sif.html | 2058 ----- DOC/HTML/sitemap.html | 85 - DOC/MAN/pig2vcd.1 | 246 - DOC/MAN/pigpio.3 | 11137 -------------------------- DOC/MAN/pigpiod.1 | 273 - DOC/MAN/pigpiod_if.3 | 5339 ------------ DOC/MAN/pigpiod_if2.3 | 8057 ------------------- DOC/MAN/pigs.1 | 6331 --------------- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 | Bin 1433600 -> 0 bytes DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 | Bin 1433600 -> 0 bytes DOC/src/defs/examples.def | 7 + DOC/tmp/body/cif.body | 1824 ----- DOC/tmp/body/download.body | 57 - DOC/tmp/body/ex_LDR.body | 141 - DOC/tmp/body/ex_ir_remote.body | 244 - DOC/tmp/body/ex_motor_shield.body | 245 - DOC/tmp/body/ex_rotary_encoder.body | 176 - DOC/tmp/body/ex_sonar_ranger.body | 155 - DOC/tmp/body/examples.body | 495 -- DOC/tmp/body/faq.body | 452 -- DOC/tmp/body/index.body | 652 -- DOC/tmp/body/misc.body | 24 - DOC/tmp/body/pdif.body | 1105 --- DOC/tmp/body/pdif2.body | 1460 ---- DOC/tmp/body/pif.body | 21 - DOC/tmp/body/pig2vcd.body | 20 - DOC/tmp/body/pigpiod.body | 51 - DOC/tmp/body/pigs.body | 1205 --- DOC/tmp/body/piscope.body | 205 - DOC/tmp/body/python.body | 1231 --- DOC/tmp/body/sif.body | 1994 ----- DOC/tmp/pydoc/pigpio.pydoc | 4162 ---------- util/pigpiod | 31 - 68 files changed, 7 insertions(+), 60447 deletions(-) delete mode 100644 DOC/HTML/cif.html delete mode 100644 DOC/HTML/download.html delete mode 100644 DOC/HTML/ex_LDR.html delete mode 100644 DOC/HTML/ex_ir_remote.html delete mode 100644 DOC/HTML/ex_motor_shield.html delete mode 100644 DOC/HTML/ex_rotary_encoder.html delete mode 100644 DOC/HTML/ex_sonar_ranger.html delete mode 100644 DOC/HTML/examples.html delete mode 100644 DOC/HTML/faq.html delete mode 100644 DOC/HTML/index.html delete mode 100644 DOC/HTML/misc.html delete mode 100644 DOC/HTML/pdif.html delete mode 100644 DOC/HTML/pdif2.html delete mode 100644 DOC/HTML/pif.html delete mode 100644 DOC/HTML/pig2vcd.html delete mode 100644 DOC/HTML/pigpiod.html delete mode 100644 DOC/HTML/pigs.html delete mode 100644 DOC/HTML/piscope.html delete mode 100644 DOC/HTML/python.html delete mode 100644 DOC/HTML/sif.html delete mode 100644 DOC/HTML/sitemap.html delete mode 100644 DOC/MAN/pig2vcd.1 delete mode 100644 DOC/MAN/pigpio.3 delete mode 100644 DOC/MAN/pigpiod.1 delete mode 100644 DOC/MAN/pigpiod_if.3 delete mode 100644 DOC/MAN/pigpiod_if2.3 delete mode 100644 DOC/MAN/pigs.1 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 delete mode 100644 DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 delete mode 100644 DOC/tmp/body/cif.body delete mode 100644 DOC/tmp/body/download.body delete mode 100644 DOC/tmp/body/ex_LDR.body delete mode 100644 DOC/tmp/body/ex_ir_remote.body delete mode 100644 DOC/tmp/body/ex_motor_shield.body delete mode 100644 DOC/tmp/body/ex_rotary_encoder.body delete mode 100644 DOC/tmp/body/ex_sonar_ranger.body delete mode 100644 DOC/tmp/body/examples.body delete mode 100644 DOC/tmp/body/faq.body delete mode 100644 DOC/tmp/body/index.body delete mode 100644 DOC/tmp/body/misc.body delete mode 100644 DOC/tmp/body/pdif.body delete mode 100644 DOC/tmp/body/pdif2.body delete mode 100644 DOC/tmp/body/pif.body delete mode 100644 DOC/tmp/body/pig2vcd.body delete mode 100644 DOC/tmp/body/pigpiod.body delete mode 100644 DOC/tmp/body/pigs.body delete mode 100644 DOC/tmp/body/piscope.body delete mode 100644 DOC/tmp/body/python.body delete mode 100644 DOC/tmp/body/sif.body delete mode 100644 DOC/tmp/pydoc/pigpio.pydoc delete mode 100755 util/pigpiod diff --git a/DOC/HTML/cif.html b/DOC/HTML/cif.html deleted file mode 100644 index 58d6eea..0000000 --- a/DOC/HTML/cif.html +++ /dev/null @@ -1,1887 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigpio C Interface



pigpio is a C library for the Raspberry which allows control of the GPIO. -

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts -

GPIO

ALL GPIO are identified by their Broadcom number. -

Credits

The PWM and servo pulses are timed using the DMA and PWM peripherals. -

This use was inspired by Richard Hirst's servoblaster kernel module. -

Usage

Include <pigpio.h> in your source files. -

Assuming your source is in prog.c use the following command to build and -run the executable. -

gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
sudo ./prog


For examples of usage see the C programs within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error. -

gpioInitialise must be called before all other library functions -with the following exceptions: -

gpioCfg*
gpioVersion
gpioHardwareRevision


If the library is not initialised all but the gpioCfg*, -gpioVersion, and gpioHardwareRevision functions will -return error PI_NOT_INITIALISED. -

If the library is initialised the gpioCfg* functions will return -error PI_INITIALISED. -

OVERVIEW

ESSENTIAL -
gpioInitialise Initialise library -
gpioTerminate Stop library -
BASIC -
gpioSetMode Set a GPIO mode -
gpioGetMode Get a GPIO mode -
gpioSetPullUpDown Set/clear GPIO pull up/down resistor -
gpioRead Read a GPIO -
gpioWrite Write a GPIO -
PWM (overrides servo commands on same GPIO) -
gpioPWM Start/stop PWM pulses on a GPIO -
gpioSetPWMfrequency Configure PWM frequency for a GPIO -
gpioSetPWMrange Configure PWM range for a GPIO -
gpioGetPWMdutycycle Get dutycycle setting on a GPIO -
gpioGetPWMfrequency Get configured PWM frequency for a GPIO -
gpioGetPWMrange Get configured PWM range for a GPIO -
gpioGetPWMrealRange Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
gpioServo Start/stop servo pulses on a GPIO -
gpioGetServoPulsewidth Get pulsewidth setting on a GPIO -
INTERMEDIATE -
gpioTrigger Send a trigger pulse to a GPIO -
gpioSetWatchdog Set a watchdog on a GPIO -
gpioRead_Bits_0_31 Read all GPIO in bank 1 -
gpioRead_Bits_32_53 Read all GPIO in bank 2 -
gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 -
gpioWrite_Bits_32_53_ClearClear selected GPIO in bank 2 -
gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 -
gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 -
gpioSetAlertFunc Request a GPIO level change callback -
gpioSetAlertFuncEx Request a GPIO change callback, extended -
gpioSetTimerFunc Request a regular timed callback -
gpioSetTimerFuncEx Request a regular timed callback, extended -
gpioStartThread Start a new thread -
gpioStopThread Stop a previously started thread -
ADVANCED -
gpioNotifyOpen Request a notification handle -
gpioNotifyClose Close a notification -
gpioNotifyOpenWithSize Request a notification with sized pipe -
gpioNotifyBegin Start notifications for selected GPIO -
gpioNotifyPause Pause notifications -
gpioHardwareClock Start hardware clock on supported GPIO -
gpioHardwarePWM Start hardware PWM on supported GPIO -
gpioGlitchFilter Set a glitch filter on a GPIO -
gpioNoiseFilter Set a noise filter on a GPIO -
gpioSetPad Sets a pads drive strength -
gpioGetPad Gets a pads drive strength -
shell Executes a shell command -
gpioSetISRFunc Request a GPIO interrupt callback -
gpioSetISRFuncEx Request a GPIO interrupt callback, extended -
gpioSetSignalFunc Request a signal callback -
gpioSetSignalFuncEx Request a signal callback, extended -
gpioSetGetSamplesFunc Requests a GPIO samples callback -
gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended -
Custom -
gpioCustom1 User custom function 1 -
gpioCustom2 User custom function 2 -
Events -
eventMonitor Sets the events to monitor -
eventSetFunc Request an event callback -
eventSetFuncEx Request an event callback, extended -
eventTrigger Trigger an event -
Scripts -
gpioStoreScript Store a script -
gpioRunScript Run a stored script -
gpioUpdateScript Set a scripts parameters -
gpioScriptStatus Get script status and parameters -
gpioStopScript Stop a running script -
gpioDeleteScript Delete a stored script -
I2C -
i2cOpen Opens an I2C device -
i2cClose Closes an I2C device -
i2cWriteQuick SMBus write quick -
i2cReadByte SMBus read byte -
i2cWriteByte SMBus write byte -
i2cReadByteData SMBus read byte data -
i2cWriteByteData SMBus write byte data -
i2cReadWordData SMBus read word data -
i2cWriteWordData SMBus write word data -
i2cReadBlockData SMBus read block data -
i2cWriteBlockData SMBus write block data -
i2cReadI2CBlockData SMBus read I2C block data -
i2cWriteI2CBlockData SMBus write I2C block data -
i2cReadDevice Reads the raw I2C device -
i2cWriteDevice Writes the raw I2C device -
i2cProcessCall SMBus process call -
i2cBlockProcessCall SMBus block process call -
i2cSwitchCombined Sets or clears the combined flag -
i2cSegments Performs multiple I2C transactions -
i2cZip Performs multiple I2C transactions -
I2C BIT BANG -
bbI2COpen Opens GPIO for bit banging I2C -
bbI2CClose Closes GPIO for bit banging I2C -
bbI2CZip Performs bit banged I2C transactions -
I2C/SPI SLAVE -
bscXfer I2C/SPI as slave transfer -
SERIAL -
serOpen Opens a serial device -
serClose Closes a serial device -
serReadByte Reads a byte from a serial device -
serWriteByte Writes a byte to a serial device -
serRead Reads bytes from a serial device -
serWrite Writes bytes to a serial device -
serDataAvailable Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
gpioSerialReadOpen Opens a GPIO for bit bang serial reads -
gpioSerialReadClose Closes a GPIO for bit bang serial reads -
gpioSerialReadInvert Configures normal/inverted for serial reads -
gpioSerialRead Reads bit bang serial data from a GPIO -
SPI -
spiOpen Opens a SPI device -
spiClose Closes a SPI device -
spiRead Reads bytes from a SPI device -
spiWrite Writes bytes to a SPI device -
spiXfer Transfers bytes with a SPI device -
SPI BIT BANG -
bbSPIOpen Opens GPIO for bit banging SPI -
bbSPIClose Closes GPIO for bit banging SPI -
bbSPIXfer Performs bit banged SPI transactions -
FILES -
fileOpen Opens a file -
fileClose Closes a file -
fileRead Reads bytes from a file -
fileWrite Writes bytes to a file -
fileSeek Seeks to a position within a file -
fileList List files which match a pattern -
WAVES -
gpioWaveClear Deletes all waveforms -
gpioWaveAddNew Starts a new waveform -
gpioWaveAddGeneric Adds a series of pulses to the waveform -
gpioWaveAddSerial Adds serial data to the waveform -
gpioWaveCreate Creates a waveform from added data -
gpioWaveCreatePad Creates a waveform of fixed size from added data -
gpioWaveDelete Deletes a waveform -
gpioWaveTxSend Transmits a waveform -
gpioWaveChain Transmits a chain of waveforms -
gpioWaveTxAt Returns the current transmitting waveform -
gpioWaveTxBusy Checks to see if the waveform has ended -
gpioWaveTxStop Aborts the current waveform -
gpioWaveGetCbs Length in CBs of the current waveform -
gpioWaveGetHighCbs Length of longest waveform so far -
gpioWaveGetMaxCbs Absolute maximum allowed CBs -
gpioWaveGetMicros Length in micros of the current waveform -
gpioWaveGetHighMicros Length of longest waveform so far -
gpioWaveGetMaxMicros Absolute maximum allowed micros -
gpioWaveGetPulses Length in pulses of the current waveform -
gpioWaveGetHighPulses Length of longest waveform so far -
gpioWaveGetMaxPulses Absolute maximum allowed pulses -
UTILITIES -
gpioDelay Delay for a number of microseconds -
gpioTick Get current tick (microseconds) -
gpioHardwareRevision Get hardware revision -
gpioVersion Get the pigpio version -
getBitInBytes Get the value of a bit -
putBitInBytes Set the value of a bit -
gpioTime Get current time -
gpioSleep Sleep for specified time -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -
CONFIGURATION -
gpioCfgBufferSize Configure the GPIO sample buffer size -
gpioCfgClock Configure the GPIO sample rate -
gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) -
gpioCfgDMAchannels Configure the DMA channels -
gpioCfgPermissions Configure the GPIO access permissions -
gpioCfgInterfaces Configure user interfaces -
gpioCfgSocketPort Configure socket port -
gpioCfgMemAlloc Configure DMA memory allocation mode -
gpioCfgNetAddr Configure allowed network addresses -
gpioCfgInternals Configure misc. internals (DEPRECATED) -
gpioCfgGetInternals Get internal configuration settings -
gpioCfgSetInternals Set internal configuration settings -
EXPERT -
rawWaveAddSPI Not intended for general use -
rawWaveAddGeneric Not intended for general use -
rawWaveCB Not intended for general use -
rawWaveCBAdr Not intended for general use -
rawWaveGetOOL Not intended for general use -
rawWaveSetOOL Not intended for general use -
rawWaveGetOut Not intended for general use -
rawWaveSetOut Not intended for general use -
rawWaveGetIn Not intended for general use -
rawWaveSetIn Not intended for general use -
rawWaveInfo Not intended for general use -
rawDumpWave Not intended for general use -
rawDumpScript Not intended for general use -

FUNCTIONS

int gpioInitialise(void)

-Initialises the library. -

Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. -

gpioInitialise must be called before using the other library functions -with the following exceptions: -

gpioCfg*
gpioVersion
gpioHardwareRevision


Example

if (gpioInitialise() < 0)
{
   // pigpio initialisation failed.
}
else
{
   // pigpio initialised okay.
}

void gpioTerminate(void)

-Terminates the library. -

Returns nothing. -

Call before program exit. -

This function resets the used DMA channels, releases memory, and -terminates any running threads. -

Example

gpioTerminate();

int gpioSetMode(unsigned gpio, unsigned mode)

-Sets the GPIO mode, typically input or output. -

gpio: 0-53
mode: 0-7


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. -

Arduino style: pinMode. -

Example

gpioSetMode(17, PI_INPUT);  // Set GPIO17 as input.

gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output.

gpioSetMode(22,PI_ALT0);    // Set GPIO22 to alternative mode 0.


See http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf page 102 for an overview of the modes. -

int gpioGetMode(unsigned gpio)

-Gets the GPIO mode. -

gpio: 0-53


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

Example

if (gpioGetMode(17) != PI_ALT0)
{
   gpioSetMode(17, PI_ALT0);  // set GPIO17 to ALT0
}

int gpioSetPullUpDown(unsigned gpio, unsigned pud)

-Sets or clears resistor pull ups or downs on the GPIO. -

gpio: 0-53
 pud: 0-2


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. -

Example

gpioSetPullUpDown(17, PI_PUD_UP);   // Sets a pull-up.

gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.

gpioSetPullUpDown(23, PI_PUD_OFF);  // Clear any pull-ups/downs.

int gpioRead(unsigned gpio)

-Reads the GPIO level, on or off. -

gpio: 0-53


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

Arduino style: digitalRead. -

Example

printf("GPIO24 is level %d", gpioRead(24));

int gpioWrite(unsigned gpio, unsigned level)

-Sets the GPIO level, on or off. -

 gpio: 0-53
level: 0-1


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. -

If PWM or servo pulses are active on the GPIO they are switched off. -

Arduino style: digitalWrite -

Example

gpioWrite(24, 1); // Set GPIO24 high.

int gpioPWM(unsigned user_gpio, unsigned dutycycle)

-Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). -Range defaults to 255. -

user_gpio: 0-31
dutycycle: 0-range


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. -

Arduino style: analogWrite -

This and the servo functionality use the DMA and PWM or PCM peripherals -to control and schedule the pulse lengths and dutycycles. -

The gpioSetPWMrange function may be used to change the default -range of 255. -

Example

gpioPWM(17, 255); // Sets GPIO17 full on.

gpioPWM(18, 128); // Sets GPIO18 half on.

gpioPWM(23, 0);   // Sets GPIO23 full off.

int gpioGetPWMdutycycle(unsigned user_gpio)

-Returns the PWM dutycycle setting for the GPIO. -

user_gpio: 0-31


Returns between 0 (off) and range (fully on) if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see gpioGetPWMrange). -

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). -

Normal PWM range defaults to 255. -

int gpioSetPWMrange(unsigned user_gpio, unsigned range)

-Selects the dutycycle range to be used for the GPIO. Subsequent calls -to gpioPWM will use a dutycycle between 0 (off) and range (fully on). -

user_gpio: 0-31
    range: 25-40000


Returns the real range for the given GPIO's frequency if OK, -otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. -

If PWM is currently active on the GPIO its dutycycle will be scaled -to reflect the new range. -

The real range, the number of steps between fully off and fully -on for each frequency, is given in the following table. -

  25,   50,  100,  125,  200,  250,  400,   500,   625,
 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000


The real value set by gpioPWM is (dutycycle * real range) / range. -

Example

gpioSetPWMrange(24, 2000); // Now 2000 is fully on
                           //     1000 is half on
                           //      500 is quarter on, etc.

int gpioGetPWMrange(unsigned user_gpio)

-Returns the dutycycle range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). -

Example

r = gpioGetPWMrange(23);

int gpioGetPWMrealRange(unsigned user_gpio)

-Returns the real range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


If a hardware clock is active on the GPIO the reported real -range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

Example

rr = gpioGetPWMrealRange(17);

int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)

-Sets the frequency in hertz to be used for the GPIO. -

user_gpio: 0-31
frequency: >=0


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO. -

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 frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency.

gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz.

gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency.

int gpioGetPWMfrequency(unsigned user_gpio)

-Returns the frequency (in hertz) used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


For normal PWM the frequency will be that defined for the GPIO by -gpioSetPWMfrequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by gpioHardwareClock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by gpioHardwarePWM. -

Example

f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23.

int gpioServo(unsigned user_gpio, unsigned pulsewidth)

-Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to -2500 (most clockwise). -

 user_gpio: 0-31
pulsewidth: 0, 500-2500


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. -

The range supported by servos varies and should probably be determined -by experiment. A value of 1500 should always be safe and represents -the mid-point of rotation. You can DAMAGE a servo if you command it -to move beyond its limits. -

The following 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

gpioServo(17, 1000); // Move servo to safe position anti-clockwise.

gpioServo(23, 1500); // Move servo to centre position.

gpioServo(25, 2000); // Move servo to safe position clockwise.


OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

PWM Hz    50   100  200  400  500
1E6/Hz 20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using gpioSetPWMfrequency. -

Then set the PWM range using gpioSetPWMrange to 1E6/frequency. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO25 at 400Hz -

gpioSetPWMfrequency(25, 400);

gpioSetPWMrange(25, 2500);


Thereafter use the PWM command to move the servo, -e.g. gpioPWM(25, 1500) will set a 1500 us pulse. -

int gpioGetServoPulsewidth(unsigned user_gpio)

-Returns the servo pulsewidth setting for the GPIO. -

user_gpio: 0-31


Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) -if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)

-Registers a function to be called (a callback) when the specified -GPIO changes state. -

user_gpio: 0-31
        f: the callback function


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -

One callback may be registered per GPIO. -

The callback is passed the GPIO, the new level, and the tick. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The alert may be cancelled by passing NULL as the function. -

The GPIO are sampled at a rate set when the library is started. -

If a value isn't specifically set the default of 5 us is used. -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


Level changes shorter than the sample rate may be missed. -

The thread which calls the alert functions is triggered nominally -1000 times per second. The active alert functions will be called -once per level change since the last time the thread was activated. -i.e. The active alert functions will get all level changes but there -will be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use gpioRead. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

The tick value is the time stamp of the sample in microseconds, see -gpioTick for more details. -

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state

gpioSetAlertFunc(4, aFunction);

int gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when the specified -GPIO changes state. -

user_gpio: 0-31
        f: the callback function
 userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -

One callback may be registered per GPIO. -

The callback is passed the GPIO, the new level, the tick, and -the userdata pointer. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


See gpioSetAlertFunc for further details. -

Only one of gpioSetAlertFunc or gpioSetAlertFuncEx can be -registered per GPIO. -

int gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)

-Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. -

   gpio: 0-53
   edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
timeout: interrupt timeout in milliseconds (<=0 to cancel)
      f: the callback function


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. -

One function may be registered per GPIO. -

The function is passed the GPIO, the current level, and the -current tick. The level will be PI_TIMEOUT if the optional -interrupt timeout expires. -

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The underlying Linux sysfs GPIO interface is used to provide -the interrupt services. -

The first time the function is called, with a non-NULL f, the -GPIO is exported, set to be an input, and set to interrupt -on the given edge and timeout. -

Subsequent calls, with a non-NULL f, can vary one or more of the -edge, timeout, or function. -

The ISR may be cancelled by passing a NULL f, in which case the -GPIO is unexported. -

The tick is that read at the time the process was informed of -the interrupt. This will be a variable number of microseconds -after the interrupt occurred. Typically the latency will be of -the order of 50 microseconds. The latency is not guaranteed -and will vary with system load. -

The level is that read at the time the process was informed of -the interrupt, or PI_TIMEOUT if the optional interrupt timeout -expired. It may not be the same as the expected edge as -interrupts happening in rapid succession may be missed by the -kernel (i.e. this mechanism can not be used to capture several -interrupts only a few microseconds apart). -

int gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. -

    gpio: 0-53
    edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 timeout: interrupt timeout in milliseconds (<=0 to cancel)
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. -

The function is passed the GPIO, the current level, the -current tick, and the userdata pointer. -

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


Only one of gpioSetISRFunc or gpioSetISRFuncEx can be -registered per GPIO. -

See gpioSetISRFunc for further details. -

int gpioNotifyOpen(void)

-This function requests a free notification handle. -

Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state changes -via a pipe or socket. -

Pipe notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). E.g. if the -function returns 15 then the notifications must be read -from /dev/pigpio15. -

Socket notifications are returned to the socket which requested the -handle. -

Example

h = gpioNotifyOpen();

if (h >= 0)
{
   sprintf(str, "/dev/pigpio%d", h);

   fd = open(str, O_RDONLY);

   if (fd >= 0)
   {
      // Okay.
   }
   else
   {
      // Error.
   }
}
else
{
   // Error.
}

int gpioNotifyOpenWithSize(int bufSize)

-This function requests a free notification handle. -

It differs from gpioNotifyOpen in that the pipe size may be -specified, whereas gpioNotifyOpen uses the default pipe size. -

See gpioNotifyOpen for further details. -

int gpioNotifyBegin(unsigned handle, uint32_t bits)

-This function starts notifications on a previously opened handle. -

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the GPIO of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose corresponding -bit in bits is set. -

Each notification occupies 12 bytes in the fifo and has the -following structure. -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

Example

// Start notifications for GPIO 1, 4, 6, 7, 10.

//                         1
//                         0  76 4  1
// (1234 = 0x04D2 = 0b0000010011010010)

gpioNotifyBegin(h, 1234);

int gpioNotifyPause(unsigned handle)

-This function pauses notifications on a previously opened handle. -

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until gpioNotifyBegin -is called again. -

Example

gpioNotifyPause(h);

int gpioNotifyClose(unsigned handle)

-This function stops notifications on a previously opened handle -and releases the handle for reuse. -

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

gpioNotifyClose(h);

int gpioWaveClear(void)

-This function clears all waveforms and any data added by calls to the -gpioWaveAdd* functions. -

Returns 0 if OK. -

Example

gpioWaveClear();

int gpioWaveAddNew(void)

-This function starts a new empty waveform. -

You wouldn't normally need to call this function as it is automatically -called after a waveform is created with the gpioWaveCreate function. -

Returns 0 if OK. -

Example

gpioWaveAddNew();

int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses
   pulses: an array of pulses


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. -

Example

// Construct and send a 30 microsecond square wave.

gpioSetMode(gpio, PI_OUTPUT);

pulse[0].gpioOn = (1<<gpio);
pulse[0].gpioOff = 0;
pulse[0].usDelay = 15;

pulse[1].gpioOn = 0;
pulse[1].gpioOff = (1<<gpio);
pulse[1].usDelay = 15;

gpioWaveAddNew();

gpioWaveAddGeneric(2, pulse);

wave_id = gpioWaveCreate();

if (wave_id >= 0)
{
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);

   // Transmit for 30 seconds.

   sleep(30);

   gpioWaveTxStop();
}
else
{
   // Wave create failed.
}

int gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

user_gpio: 0-31
     baud: 50-1000000
data_bits: 1-32
stop_bits: 2-8
   offset: >=0
 numBytes: >=1
      str: an array of chars (which may contain nulls)


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, and -stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

Example

#define MSG_LEN 8

int i;
char *str;
char data[MSG_LEN];

str = "Hello world!";

gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str);

for (i=0; i<MSG_LEN; i++) data[i] = i;

// Data added is offset 1 second from the waveform start.
gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);

int gpioWaveCreate(void)

-This function creates a waveform from the data provided by the prior -calls to the gpioWaveAdd* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the gpioWaveAdd* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to gpioWaveTxSend to specify the waveform to transmit. -

Normal usage would be -

Step 1. gpioWaveClear to clear all waveforms and added data. -

Step 2. gpioWaveAdd* calls to supply the waveform data. -

Step 3. gpioWaveCreate to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. gpioWaveTxSend with the id of the waveform to transmit. -

A waveform comprises one of more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL)

-Similar to gpioWaveCreate, this function creates a waveform but pads the consumed -resources. Padded waves of equal dimension can be re-cycled efficiently allowing -newly created waves to re-use the resources of deleted waves of the same dimension. -

pctCB: 0-100, the percent of all DMA control blocks to consume.
pctBOOL: 0-100, percent On-Off-Level (OOL) buffer to consume for wave output.
pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags).


Upon success a wave id greater than or equal to 0 is returned, otherwise -PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

Waveform data provided by gpioWaveAdd* and rawWaveAdd* functions are -consumed by this function. -

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Example

  // get firstWaveChunk, somehow
  gpioWaveAddGeneric(firstWaveChunk);
  wid = gpioWaveCreatePad(50, 50, 0);
  gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
  // get nextWaveChunk

  while (nextWaveChunk) {
     gpioWaveAddGeneric(nextWaveChunk);
     nextWid = gpioWaveCreatePad(50, 50, 0);
     gpioWaveTxSend(nextWid, PI_WAVE_MODE_ONE_SHOT_SYNC);
     while(gpioWaveTxAt() == wid) time_sleep(0.1);
     gpioWaveDelete(wid);
     wid = nextWid;
     // get nextWaveChunk
  }

int gpioWaveDelete(unsigned wave_id)

-This function deletes the waveform with id wave_id. -

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). -

wave_id: >=0, as returned by gpioWaveCreate


Wave ids are allocated in order, 0, 1, 2, etc. -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)

-This function transmits the waveform with id wave_id. The mode -determines whether the waveform is sent once or cycles endlessly. -The SYNC variants wait for the current waveform to reach the -end of a cycle or finish before starting the new waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. -

  wave_id: >=0, as returned by gpioWaveCreate
wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
           PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int gpioWaveChain(char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpio.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (gpioInitialise()<0) return -1;

   gpioSetMode(GPIO, PI_OUTPUT);

   printf("start piscope, press return"); getchar();

   for (i=0; i<WAVES; i++)
   {
      gpioWaveAddGeneric(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = gpioWaveCreate();
   }

   gpioWaveChain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (gpioWaveTxBusy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);

   printf("stop piscope, press return"); getchar();

   gpioTerminate();
}

int gpioWaveTxAt(void)

-This function returns the id of the waveform currently being -transmitted. -

Returns the waveform id or one of the following special values: -

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
-PI_NO_TX_WAVE (9999) - no wave being transmitted. -

int gpioWaveTxBusy(void)

-This function checks to see if a waveform is currently being -transmitted. -

Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int gpioWaveTxStop(void)

-This function aborts the transmission of the current waveform. -

Returns 0 if OK. -

This function is intended to stop a waveform started in repeat mode. -

int gpioWaveGetMicros(void)

-This function returns the length in microseconds of the current -waveform. -

int gpioWaveGetHighMicros(void)

-This function returns the length in microseconds of the longest waveform -created since gpioInitialise was called. -

int gpioWaveGetMaxMicros(void)

-This function returns the maximum possible size of a waveform in -microseconds. -

int gpioWaveGetPulses(void)

-This function returns the length in pulses of the current waveform. -

int gpioWaveGetHighPulses(void)

-This function returns the length in pulses of the longest waveform -created since gpioInitialise was called. -

int gpioWaveGetMaxPulses(void)

-This function returns the maximum possible size of a waveform in pulses. -

int gpioWaveGetCbs(void)

-This function returns the length in DMA control blocks of the current -waveform. -

int gpioWaveGetHighCbs(void)

-This function returns the length in DMA control blocks of the longest -waveform created since gpioInitialise was called. -

int gpioWaveGetMaxCbs(void)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

int gpioSerialReadOpen(unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

user_gpio: 0-31
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -PI_BAD_DATABITS, or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -gpioSerialRead. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int gpioSerialReadInvert(unsigned user_gpio, unsigned invert)

-This function configures the level logic for bit bang serial reads. -

Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for -normal logic. Default is PI_BB_SER_NORMAL. -

user_gpio: 0-31
   invert: 0-1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, -PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT. -

The GPIO must be opened for bit bang reading of serial data using -gpioSerialReadOpen prior to calling this function. -

int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

user_gpio: 0-31, previously opened with gpioSerialReadOpen
      buf: an array to receive the read bytes
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the gpioSerialReadOpen command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int gpioSerialReadClose(unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

user_gpio: 0-31, previously opened with gpioSerialReadOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)

-This returns a handle for the device at the address on the I2C bus. -

  i2cBus: >=0
 i2cAddr: 0-0x7F
i2cFlags: 0


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S      (1 bit) : Start bit
P      (1 bit) : Stop bit
Rd/Wr  (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA  (1 bit) : Accept and not accept bit.

Addr   (7 bits): I2C 7 bit address.
i2cReg (8 bits): Command byte, a byte which often selects a register.
Data   (8 bits): A data byte.
Count  (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2cClose(unsigned handle)

-This closes the I2C device associated with the handle. -

handle: >=0, as returned by a call to i2cOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2cWriteQuick(unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

handle: >=0, as returned by a call to i2cOpen
   bit: 0-1, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr bit [A] P

int i2cWriteByte(unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] bVal [A] P

int i2cReadByte(unsigned handle)

-This reads a single byte from the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] i2cReg [A] bVal [A] P

int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  wVal: 0-0xFFFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P

int i2cReadByteData(unsigned handle, unsigned i2cReg)

-This reads a single byte from the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P

int i2cReadWordData(unsigned handle, unsigned i2cReg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
  wVal: 0-0xFFFF, the value to write


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: an array with the data to send
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] i2cReg [A] count [A]
   buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
   buf: an array with the data to send and to receive the read data
 count: 1-32, the number of bytes to write


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The SMBus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A]
   S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P

int i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data
 count: 1-32, the number of bytes to read


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: the data to write
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadDevice(unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

handle: >=0, as returned by a call to i2cOpen
   buf: an array to receive the read data bytes
 count: >0, the number of bytes to read


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteDevice(unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

handle: >=0, as returned by a call to i2cOpen
   buf: an array containing the data bytes to write
 count: >0, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

void i2cSwitchCombined(int setting)

-This sets the I2C (i2c-bcm2708) module "use combined transactions" -parameter on or off. -

setting: 0 to set the parameter off, non-zero to set it on


NOTE: when the flag is on a write followed by a read to the same -slave address will use a repeated start (rather than a stop/start). -

int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)

-This function executes multiple I2C segments in one transaction by -calling the I2C_RDWR ioctl. -

 handle: >=0, as returned by a call to i2cOpen
   segs: an array of I2C segments
numSegs: >0, the number of I2C segments


Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. -

int i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bbI2CClose(unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bbI2COpen. -

SDA: 0-31, the SDA GPIO used in a prior call to bbI2COpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

   SDA: 0-31 (as used in a prior call to bbI2COpen)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bscXfer(bsc_xfer_t *bsc_xfer)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

bsc_xfer:= a structure defining the transfer

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. -

Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

The returned function value is the status of the transfer (see below). -

If there was an error the status will be less than zero -(and will contain the error code). -

The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). -

control consists of the following bits. -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. -

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bscXfer(&xfer);

if (status >= 0)
{
   // process transfer
}

int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)

-This function selects a set of GPIO for bit banging SPI with -a specified baud rate and mode. -

      CS: 0-31
    MISO: 0-31
    MOSI: 0-31
    SCLK: 0-31
    baud: 50-250000
spiFlags: see below


spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bbSPIClose(unsigned CS)

-This function stops bit banging SPI on a set of GPIO -opened with bbSPIOpen. -

CS: 0-31, the CS GPIO used in a prior call to bbSPIOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

int bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)

-This function executes a bit banged SPI transfer. -

    CS: 0-31 (as used in a prior call to bbSPIOpen)
 inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
 count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. -

Example

// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
// sudo ./bbSPIx_test

#include <stdio.h>

#include "pigpio.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if (gpioInitialise() < 0)
   {
      fprintf(stderr, "pigpio initialisation failed.\n");
      return 1;
   }

   bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bbSPIClose(CE0);
   bbSPIClose(CE1);

   gpioTerminate();

   return 0;
}

int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


 spiChan: 0-1 (0-2 for the auxiliary SPI)
    baud: 32K-125M (values above 30M are unlikely to work)
spiFlags: see below


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 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. -

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 spiRead, spiWrite, and spiXfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per word.
-For bits 9-16 there will be two bytes per word.
-For bits 17-32 there will be four bytes per word. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spiClose(unsigned handle)

-This functions closes the SPI device identified by the handle. -

handle: >=0, as returned by a call to spiOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spiRead(unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spiOpen
   buf: an array to receive the read data bytes
 count: the number of bytes to read


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spiWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spiOpen
   buf: the data bytes to write
 count: the number of bytes to write


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

handle: >=0, as returned by a call to spiOpen
 txBuf: the data bytes to write
 rxBuf: the received data bytes
 count: the number of bytes to transfer


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serOpen(char *sertty, unsigned baud, unsigned serFlags)

-This function opens a serial device at a specified baud rate -and with specified flags. The device name must start with -/dev/tty or /dev/serial. -

  sertty: the serial device to open
    baud: the baud rate in bits per second, see below
serFlags: 0


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serClose(unsigned handle)

-This function closes the serial device associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serWriteByte(unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serReadByte(unsigned handle)

-This function reads a byte from the serial port associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

handle: >=0, as returned by a call to serOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serRead(unsigned handle, char *buf, unsigned count)

-This function reads up count bytes from the the serial port -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to serOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_SER_READ_NO_DATA. -

If no data is ready zero is returned. -

int serDataAvailable(unsigned handle)

-This function returns the number of bytes available -to be read from the device associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

user_gpio: 0-31
 pulseLen: 1-100
    level: 0,1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -or PI_BAD_PULSELEN. -

int gpioSetWatchdog(unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

user_gpio: 0-31
  timeout: 0-60000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

One watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Until cancelled a timeout will be reported every timeout milliseconds -after the last GPIO activity. -

In particular: -

1) any registered alert function for the GPIO will be called with - the level set to PI_TIMEOUT. -

2) any notification for the GPIO will have a report written to the - fifo with the flags set to indicate a watchdog timeout. -

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state
gpioSetAlertFunc(4, aFunction);

//  or approximately every 5 millis
gpioSetWatchdog(4, 5);

int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, -and gpioSetGetSamplesFuncEx. -

It does not affect interrupts set up with gpioSetISRFunc, -gpioSetISRFuncEx, or levels read by gpioRead, -gpioRead_Bits_0_31, or gpioRead_Bits_32_53. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

int gpioGlitchFilter(unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, -and gpioSetGetSamplesFuncEx. -

It does not affect interrupts set up with gpioSetISRFunc, -gpioSetISRFuncEx, or levels read by gpioRead, -gpioRead_Bits_0_31, or gpioRead_Bits_32_53. -

Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)

-Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. -

   f: the function to call
bits: the GPIO of interest


Returns 0 if OK. -

The function is passed a pointer to the samples (an array of -gpioSample_t), and the number of samples. -

Only one function can be registered. -

The callback may be cancelled by passing NULL as the function. -

The samples returned will be the union of bits, plus any active alerts, -plus any active notifications. -

e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO -8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO -7, 8, 9, 10, 17, 23, and 24 will be reported. -

int gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)

-Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. -

       f: the function to call
    bits: the GPIO of interest
userdata: a pointer to arbitrary user data


Returns 0 if OK. -

The function is passed a pointer to the samples (an array of -gpioSample_t), the number of samples, and the userdata pointer. -

Only one of gpioGetSamplesFunc or gpioGetSamplesFuncEx can be -registered. -

See gpioSetGetSamplesFunc for further details. -

int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)

-Registers a function to be called (a callback) every millis milliseconds. -

 timer: 0-9
millis: 10-60000
     f: the function to call


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. -

10 timers are supported numbered 0 to 9. -

One function may be registered per timer. -

The timer may be cancelled by passing NULL as the function. -

Example

void bFunction(void)
{
   printf("two seconds have elapsed");
}

// call bFunction every 2000 milliseconds
gpioSetTimerFunc(0, 2000, bFunction);

int gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) every millis milliseconds. -

   timer: 0-9.
  millis: 10-60000
       f: the function to call
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. -

The function is passed the userdata pointer. -

Only one of gpioSetTimerFunc or gpioSetTimerFuncEx can be -registered per timer. -

See gpioSetTimerFunc for further details. -

pthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)

-Starts a new thread of execution with f as the main routine. -

       f: the main function for the new thread
userdata: a pointer to arbitrary user data


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument arg. -

The thread can be cancelled by passing the pointer to pthread_t to -gpioStopThread. -

Example

#include <stdio.h>
#include <pigpio.h>

void *myfunc(void *arg)
{
   while (1)
   {
      printf("%s", arg);
      sleep(1);
   }
}

int main(int argc, char *argv[])
{
   pthread_t *p1, *p2, *p3;

   if (gpioInitialise() < 0) return 1;

   p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);

   p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);

   p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);

   gpioStopThread(p3); sleep(3);

   gpioStopThread(p2); sleep(3);

   gpioStopThread(p1); sleep(3);

   gpioTerminate();
}

void gpioStopThread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: a thread pointer returned by gpioStartThread


No value is returned. -

The thread to be stopped should have been started with gpioStartThread. -

int gpioStoreScript(char *script)

-This function stores a null terminated script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

script: the text of the script


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioScriptStatus(unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well as -the current values of parameters 0 to 9. -

script_id: >=0, as returned by gpioStoreScript
    param: an array to hold the returned 10 parameters


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int gpioStopScript(unsigned script_id)

-This function stops a running script. -

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int gpioDeleteScript(unsigned script_id)

-This function deletes a stored script. -

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)

-Registers a function to be called (a callback) when a signal occurs. -

signum: 0-63
     f: the callback function


Returns 0 if OK, otherwise PI_BAD_SIGNUM. -

The function is passed the signal number. -

One function may be registered per signal. -

The callback may be cancelled by passing NULL. -

By default all signals are treated as fatal and cause the library -to call gpioTerminate and then exit. -

int gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when a signal occurs. -

  signum: 0-63
       f: the callback function
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_SIGNUM. -

The function is passed the signal number and the userdata pointer. -

Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be -registered per signal. -

See gpioSetSignalFunc for further details. -

uint32_t gpioRead_Bits_0_31(void)

-Returns the current level of GPIO 0-31. -

uint32_t gpioRead_Bits_32_53(void)

-Returns the current level of GPIO 32-53. -

int gpioWrite_Bits_0_31_Clear(uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask of GPIO to clear


Returns 0 if OK. -

Example

// To clear (set to 0) GPIO 4, 7, and 15
gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );

int gpioWrite_Bits_32_53_Clear(uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask of GPIO to clear


Returns 0 if OK. -

int gpioWrite_Bits_0_31_Set(uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask of GPIO to set


Returns 0 if OK. -

int gpioWrite_Bits_32_53_Set(uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask of GPIO to set


Returns 0 if OK. -

Example

// To set (set to 1) GPIO 32, 40, and 53
gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));

int gpioHardwareClock(unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

   gpio: see description
clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, -PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by gpioWaveTxSend, or -gpioWaveChain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden by a call to -gpioCfgClock. -

   gpio: see description
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, -PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. -

int gpioTime(unsigned timetype, int *seconds, int *micros)

-Updates the seconds and micros variables with the current time. -

timetype: 0 (relative), 1 (absolute)
 seconds: a pointer to an int to hold seconds
  micros: a pointer to an int to hold microseconds


Returns 0 if OK, otherwise PI_BAD_TIMETYPE. -

If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the -number of seconds and microseconds since the epoch (1st January 1970). -

If timetype is PI_TIME_RELATIVE updates seconds and micros with the -number of seconds and microseconds since the library was initialised. -

Example

int secs, mics;

// print the number of seconds since the library was started
gpioTime(PI_TIME_RELATIVE, &secs, &mics);
printf("library started %d.%03d seconds ago", secs, mics/1000);

int gpioSleep(unsigned timetype, int seconds, int micros)

-Sleeps for the number of seconds and microseconds specified by seconds -and micros. -

timetype: 0 (relative), 1 (absolute)
 seconds: seconds to sleep
  micros: microseconds to sleep


Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, -or PI_BAD_MICROS. -

If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds -and microseconds since the epoch (1st January 1970) has elapsed. System -clock changes are taken into account. -

If timetype is PI_TIME_RELATIVE the sleep is for the specified number -of seconds and microseconds. System clock changes do not effect the -sleep length. -

For short delays (say, 50 microseonds or less) use gpioDelay. -

Example

gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds

gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds

gpioSleep(PI_TIME_RELATIVE, 60, 0);     // sleep for one minute

uint32_t gpioDelay(uint32_t micros)

-Delays for at least the number of microseconds specified by micros. -

micros: the number of microseconds to sleep


Returns the actual length of the delay in microseconds. -

Delays of 100 microseconds or less use busy waits. -

uint32_t gpioTick(void)

-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. -

You don't need to worry about the wrap around as long as you -take a tick (uint32_t) from another tick, i.e. the following -code will always provide the correct difference. -

Example

uint32_t startTick, endTick;
int diffTick;

startTick = gpioTick();

// do some processing

endTick = gpioTick();

diffTick = endTick - startTick;

printf("some processing took %d microseconds", diffTick);

unsigned gpioHardwareRevision(void)

-Returns the hardware revision. -

If the hardware revision can not be found or is not a valid hexadecimal -number the function returns 0. -

The hardware revision is the last few characters on the Revision line of -/proc/cpuinfo. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

for "Revision : 0002" the function returns 2.
-for "Revision : 000f" the function returns 15.
-for "Revision : 000g" the function returns 0. -

unsigned gpioVersion(void)

-Returns the pigpio version. -

int gpioGetPad(unsigned pad)

-This function returns the pad drive strength in mA. -

pad: 0-2, the pad to get


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = gpioGetPad(1); // get pad 1 strength

int gpioSetPad(unsigned pad, unsigned padStrength)

-This function sets the pad drive strength in mA. -

        pad: 0-2, the pad to set
padStrength: 1-16 mA


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

gpioSetPad(0, 16); // set pad 0 strength to 16 mA

int eventMonitor(unsigned handle, uint32_t bits)

-This function selects the events to be reported on a previously -opened handle. -

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the events of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

A report is sent each time an event is triggered providing the -corresponding bit in bits is set. -

See gpioNotifyBegin for the notification format. -

Example

// Start reporting events 3, 6, and 7.

//  bit      76543210
// (0xC8 = 0b11001000)

eventMonitor(h, 0xC8);

int eventSetFunc(unsigned event, eventFunc_t f)

-Registers a function to be called (a callback) when the specified -event occurs. -

event: 0-31
    f: the callback function


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

One function may be registered per event. -

The function is passed the event, and the tick. -

The callback may be cancelled by passing NULL as the function. -

int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when the specified -event occurs. -

   event: 0-31
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

One function may be registered per event. -

The function is passed the event, the tick, and the ueserdata pointer. -

The callback may be cancelled by passing NULL as the function. -

Only one of eventSetFunc or eventSetFuncEx can be -registered per event. -

int eventTrigger(unsigned event)

-This function signals the occurrence of an event. -

event: 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling eventSetFunc) will be informed by -a callback. -

One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

int shell(char *scriptName, char *scriptString)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name
scriptString: the string to pass to the script


The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. -

scriptName must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell("scr1", "\"hello string with spaces world\"");

int fileOpen(char *file, unsigned mode)

-This function returns a handle to a file opened in a specified mode. -

file: the file to open
mode: the file open mode


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


The following values may be or'd into the mode. -

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int handle, c;
   char buf[60000];

   if (gpioInitialise() < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   handle = fileOpen("/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=fileRead(handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      fileClose(handle);
   }

   gpioTerminate();
}

int fileClose(unsigned handle)

-This function closes the file associated with handle. -

handle: >=0, as returned by a call to fileOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

fileClose(h);

int fileWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the file -associated with handle. -

handle: >=0, as returned by a call to fileOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. -

Example

status = fileWrite(h, buf, count);
if (status == 0)
{
   // okay
}
else
{
   // error
}

int fileRead(unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the file -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to fileOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. -

Example

if (fileRead(h, buf, sizeof(buf)) > 0)
{
   // process read data
}

int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)

-This function seeks to a position within the file associated -with handle. -

    handle: >=0, as returned by a call to fileOpen
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2)


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. -

Example

fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20

size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size

pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position

int fileList(char *fpat, char *buf, unsigned count)

-This function returns a list of files which match a pattern. The -pattern may contain wildcards. -

 fpat: file pattern to match
  buf: an array to receive the matching file names
count: the maximum number of bytes to read


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See fileOpen. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int c;
   char buf[1000];

   if (gpioInitialise() < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   c = fileList("/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      // terminate string
      buf[c] = 0;
      printf("%s", buf);
   }

   gpioTerminate();
}

int gpioCfgBufferSize(unsigned cfgMillis)

-Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. -

This function is only effective if called before gpioInitialise. -

cfgMillis: 100-10000


The default setting is 120 milliseconds. -

The intention is to allow for bursts of data and protection against -other processes hogging cpu time. -

I haven't seen a process locked out for more than 100 milliseconds. -

Making the buffer bigger uses a LOT of memory at the more frequent -sampling rates as shown in the following table in MBs. -

                     buffer milliseconds
               120 250 500 1sec 2sec 4sec 8sec

         1      16  31  55  107  ---  ---  ---
         2      10  18  31   55  107  ---  ---
sample   4       8  12  18   31   55  107  ---
 rate    5       8  10  14   24   45   87  ---
 (us)    8       6   8  12   18   31   55  107
        10       6   8  10   14   24   45   87

int gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)

-Configures pigpio to use a particular sample rate timed by a specified -peripheral. -

This function is only effective if called before gpioInitialise. -

    cfgMicros: 1, 2, 4, 5, 8, 10
cfgPeripheral: 0 (PWM), 1 (PCM)
    cfgSource: deprecated, value is ignored


The timings are provided by the specified peripheral (PWM or PCM). -

The default setting is 5 microseconds using the PCM peripheral. -

The approximate CPU percentage used for each sample rate is: -

sample  cpu
 rate    %

  1     25
  2     16
  4     11
  5     10
  8     15
 10     14


A sample rate of 5 microseconds seeems to be the sweet spot. -

int gpioCfgDMAchannel(unsigned DMAchannel)

-Configures pigpio to use the specified DMA channel. -

This function is only effective if called before gpioInitialise. -

DMAchannel: 0-14


The default setting is to use channel 14. -

int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)

-Configures pigpio to use the specified DMA channels. -

This function is only effective if called before gpioInitialise. -

  primaryChannel: 0-14
secondaryChannel: 0-14


The default setting depends on whether the Pi has a BCM2711 chip or -not (currently only the Pi4B has a BCM2711). -

The default setting for a non-BCM2711 is to use channel 14 for the -primary channel and channel 6 for the secondary channel. -

The default setting for a BCM2711 is to use channel 7 for the -primary channel and channel 6 for the secondary channel. -

The secondary channel is only used for the transmission of waves. -

If possible use one of channels 0 to 6 for the secondary channel -(a full channel). -

A full channel only requires one DMA control block regardless of the -length of a pulse delay. Channels 7 to 14 (lite channels) require -one DMA control block for each 16383 microseconds of delay. I.e. -a 10 second pulse delay requires one control block on a full channel -and 611 control blocks on a lite channel. -

int gpioCfgPermissions(uint64_t updateMask)

-Configures pigpio to restrict GPIO updates via the socket or pipe -interfaces to the GPIO specified by the mask. Programs directly -calling the pigpio library (i.e. linked with -lpigpio are not -affected). A GPIO update is a write to a GPIO or a GPIO mode -change or any function which would force such an action. -

This function is only effective if called before gpioInitialise. -

updateMask: bit (1<<n) is set for each GPIO n which may be updated


The default setting depends upon the Pi model. The user GPIO are -added to the mask. -

If the board revision is not recognised then GPIO 2-27 are allowed. -

Unknown boardPI_DEFAULT_UPDATE_MASK_UNKNOWN0x0FFFFFFC
Type 1 boardPI_DEFAULT_UPDATE_MASK_B10x03E6CF93
Type 2 boardPI_DEFAULT_UPDATE_MASK_A_B20xFBC6CF9C
Type 3 boardPI_DEFAULT_UPDATE_MASK_R30x0FFFFFFC

int gpioCfgSocketPort(unsigned port)

-Configures pigpio to use the specified socket port. -

This function is only effective if called before gpioInitialise. -

port: 1024-32000


The default setting is to use port 8888. -

int gpioCfgInterfaces(unsigned ifFlags)

-Configures pigpio support of the fifo and socket interfaces. -

This function is only effective if called before gpioInitialise. -

ifFlags: 0-7


The default setting (0) is that both interfaces are enabled. -

Or in PI_DISABLE_FIFO_IF to disable the pipe interface. -

Or in PI_DISABLE_SOCK_IF to disable the socket interface. -

Or in PI_LOCALHOST_SOCK_IF to disable remote socket -access (this means that the socket interface is only -usable from the local Pi). -

int gpioCfgMemAlloc(unsigned memAllocMode)

-Selects the method of DMA memory allocation. -

This function is only effective if called before gpioInitialise. -

memAllocMode: 0-2


There are two methods of DMA memory allocation. The original method -uses the /proc/self/pagemap file to allocate bus memory. The new -method uses the mailbox property interface to allocate bus memory. -

Auto will use the mailbox method unless a larger than default buffer -size is requested with gpioCfgBufferSize. -

int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)

-Sets the network addresses which are allowed to talk over the -socket interface. -

This function is only effective if called before gpioInitialise. -

numSockAddr: 0-256 (0 means all addresses allowed)
   sockAddr: an array of permitted network addresses.

int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)

-Used to tune internal settings. -

cfgWhat: see source code
 cfgVal: see source code

uint32_t gpioCfgGetInternals(void)

-This function returns the current library internal configuration -settings. -

int gpioCfgSetInternals(uint32_t cfgVal)

-This function sets the current library internal configuration -settings. -

cfgVal: see source code

int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from gpioCustom1 in that it returns an array of bytes -rather than just an integer. -

The returned value is an integer indicating the number of returned bytes. -  arg1: >=0
  argx: extra (byte) arguments
  argc: number of extra arguments
retBuf: buffer for returned bytes
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

The number of returned bytes must be retMax or less. -

int rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)

-This function adds a waveform representing SPI data to the -existing waveform (if any). -

        spi: a pointer to a spi object
     offset: microseconds from the start of the waveform
      spiSS: the slave select GPIO
        buf: the bits to transmit, most significant bit first
  spiTxBits: the number of bits to write
spiBitFirst: the first bit to read
 spiBitLast: the last bit to read
    spiBits: the number of bits to transfer


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. -

Not intended for general use. -

int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses
   pulses: the array containing the pulses


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The advantage of this function over gpioWaveAddGeneric is that it -allows the setting of the flags field. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. -

Not intended for general use. -

unsigned rawWaveCB(void)

-Returns the number of the cb being currently output. -

Not intended for general use. -

rawCbs_t *rawWaveCBAdr(int cbNum)

-Return the (Linux) address of contol block cbNum. -

cbNum: the cb of interest


Not intended for general use. -

uint32_t rawWaveGetOOL(int pos)

-Gets the OOL parameter stored at pos. -

pos: the position of interest.


Not intended for general use. -

void rawWaveSetOOL(int pos, uint32_t lVal)

-Sets the OOL parameter stored at pos to value. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

uint32_t rawWaveGetOut(int pos)

-Gets the wave output parameter stored at pos. -

DEPRECATED: use rawWaveGetOOL instead. -

pos: the position of interest.


Not intended for general use. -

void rawWaveSetOut(int pos, uint32_t lVal)

-Sets the wave output parameter stored at pos to value. -

DEPRECATED: use rawWaveSetOOL instead. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

uint32_t rawWaveGetIn(int pos)

-Gets the wave input value parameter stored at pos. -

DEPRECATED: use rawWaveGetOOL instead. -

pos: the position of interest


Not intended for general use. -

void rawWaveSetIn(int pos, uint32_t lVal)

-Sets the wave input value stored at pos to value. -

DEPRECATED: use rawWaveSetOOL instead. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

rawWaveInfo_t rawWaveInfo(int wave_id)

-Gets details about the wave with id wave_id. -

wave_id: the wave of interest


Not intended for general use. -

int getBitInBytes(int bitPos, char *buf, int numBits)

-Returns the value of the bit bitPos bits from the start of buf. Returns -0 if bitPos is greater than or equal to numBits. -

 bitPos: bit index from the start of buf
    buf: array of bits
numBits: number of valid bits in buf

void putBitInBytes(int bitPos, char *buf, int bit)

-Sets the bit bitPos bits from the start of buf to bit. -

bitPos: bit index from the start of buf
   buf: array of bits
   bit: 0-1, value to set

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds -

seconds: the number of seconds to sleep

void rawDumpWave(void)

-Used to print a readable version of the current waveform to stderr. -

Not intended for general use. -

void rawDumpScript(unsigned script_id)

-Used to print a readable version of a script to stderr. -

script_id: >=0, a script_id returned by gpioStoreScript


Not intended for general use. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bitPos

-A bit position within a byte or word. The least significant bit is -position 0. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

*bsc_xfer

-A pointer to a bsc_xfer_t object used to control a BSC transfer. -

bsc_xfer_t

-typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

cbNum

-A number identifying a DMA contol block. -

cfgMicros

-The GPIO sample rate in microseconds. The default is 5us, or 200 thousand -samples per second. -

cfgMillis: 100-10000

-The size of the sample buffer in milliseconds. Generally this should be -left at the default of 120ms. If you expect intense bursts of signals it -might be necessary to increase the buffer size. -

cfgPeripheral

-One of the PWM or PCM peripherals used to pace DMA transfers for timing -purposes. -

cfgSource

-Deprecated. -

cfgVal

-A number specifying the value of a configuration item. See cfgWhat. -

cfgWhat

-A number specifying a configuration item. -

562484977: print enhanced statistics at termination.
-984762879: set the initial debug level. -

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

-The hardware clock frequency. -

PI_HW_CLK_MIN_FREQ 4689
PI_HW_CLK_MAX_FREQ 250000000
PI_HW_CLK_MAX_FREQ_2711 375000000

count

-The number of bytes to be transferred in an I2C, SPI, or Serial -command. -

CS

-The GPIO used for the slave select signal when bit banging SPI. -

data_bits: 1-32

-The number of data bits to be used when adding serial data to a -waveform. -

PI_MIN_WAVE_DATABITS 1
PI_MAX_WAVE_DATABITS 32

DMAchannel: 0-15

-PI_MIN_DMA_CHANNEL 0
PI_MAX_DMA_CHANNEL 15

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge: 0-2

-The type of GPIO edge to generate an interrupt. See gpioSetISRFunc -and gpioSetISRFuncEx. -

RISING_EDGE 0
FALLING_EDGE 1
EITHER_EDGE 2

event: 0-31

-An event is a signal used to inform one or more consumers -to start an action. -

eventFunc_t

-typedef void (*eventFunc_t) (int event, uint32_t tick);

eventFuncEx_t

-typedef void (*eventFuncEx_t)
   (int event, uint32_t tick, void *userdata);

f

-A function. -

*file

-A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. -

*fpat

-A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 gpioHardwareRevision. -

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  -  -  -  -

gpioAlertFunc_t

-typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);

gpioAlertFuncEx_t

-typedef void (*eventFuncEx_t)
   (int event, int level, uint32_t tick, void *userdata);

gpioCfg*

-These functions are only effective if called before gpioInitialise. -

gpioCfgBufferSize
-gpioCfgClock
-gpioCfgDMAchannel
-gpioCfgDMAchannels
-gpioCfgPermissions
-gpioCfgInterfaces
-gpioCfgSocketPort
-gpioCfgMemAlloc -

gpioGetSamplesFunc_t

-typedef void (*gpioGetSamplesFunc_t)
   (const gpioSample_t *samples, int numSamples);

gpioGetSamplesFuncEx_t

-typedef void (*gpioGetSamplesFuncEx_t)
   (const gpioSample_t *samples, int numSamples, void *userdata);

gpioISRFunc_t

-typedef void (*gpioISRFunc_t)
   (int gpio, int level, uint32_t tick);

gpioISRFuncEx_t

-typedef void (*gpioISRFuncEx_t)
   (int gpio, int level, uint32_t tick, void *userdata);

gpioPulse_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioSample_t

-typedef struct
{
   uint32_t tick;
   uint32_t level;
} gpioSample_t;

gpioSignalFunc_t

-typedef void (*gpioSignalFunc_t) (int signum);

gpioSignalFuncEx_t

-typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

gpioTimerFunc_t

-typedef void (*gpioTimerFunc_t) (void);

gpioTimerFuncEx_t

-typedef void (*gpioTimerFuncEx_t) (void *userdata);

gpioWaveAdd*

-One of -

gpioWaveAddNew
-gpioWaveAddGeneric
-gpioWaveAddSerial -

handle: >=0

-A number referencing an object opened by one of -

fileOpen
-gpioNotifyOpen
-i2cOpen
-serOpen
-spiOpen -

i2cAddr: 0-0x7F

-The address of a device on the I2C bus. -

i2cBus: >=0

-An I2C bus number. -

i2cFlags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2cReg: 0-255

-A register of an I2C device. -

ifFlags: 0-3

-PI_DISABLE_FIFO_IF 1
PI_DISABLE_SOCK_IF 2

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

int32_t

-A 32-bit signed value. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See gpioSetWatchdog. -

PI_TIMEOUT 2

lVal: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)

-A 32-bit word value. -

memAllocMode: 0-2

-The DMA memory allocation mode. -

PI_MEM_ALLOC_AUTO    0
PI_MEM_ALLOC_PAGEMAP 1
PI_MEM_ALLOC_MAILBOX 2

*micros

-A value representing microseconds. -

micros

-A value representing microseconds. -

millis

-A value representing milliseconds. -

MISO

-The GPIO used for the MISO signal when bit banging SPI. -

mode

-1. The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. A file open mode. -

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


The following values can be or'd into the mode. -

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

-The GPIO used for the MOSI signal when bit banging SPI. -

numBits

-The number of bits stored in a buffer. -

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

numSegs

-The number of segments in a combined I2C transaction. -

numSockAddr

-The number of network addresses allowed to use the socket interface. -

0 means all addresses allowed. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

pad: 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

-The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

*param

-An array of script parameters. -

pctBOOL: 0-100

-percent On-Off-Level (OOL) buffer to consume for wave output. -

pctCB: 0-100

-the percent of all DMA control blocks to consume. -

pctTOOL: 0-100

-the percent of OOL buffer to consume for wave input (flags). -

pi_i2c_msg_t

-typedef struct
{
   uint16_t addr;  // slave address
   uint16_t flags;
   uint16_t len;   // msg length
   uint8_t  *buf;  // pointer to msg data
} pi_i2c_msg_t;

port: 1024-32000

-The port used to bind to the pigpio socket. Defaults to 8888. -

pos

-The position of an item. -

primaryChannel: 0-15

-The DMA channel used to time the sampling of GPIO and to time servo and -PWM pulses. -

*pth

-A thread identifier, returned by gpioStartThread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -

PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

-The hardware PWM frequency. -

PI_HW_PWM_MIN_FREQ 1
PI_HW_PWM_MAX_FREQ 125000000
PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

-PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

rawCbs_t

-typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
{
   unsigned long info;
   unsigned long src;
   unsigned long dst;
   unsigned long length;
   unsigned long stride;
   unsigned long next;
   unsigned long pad[2];
} rawCbs_t;

rawSPI_t

-typedef struct
{
   int clk;     // GPIO for clock
   int mosi;    // GPIO for MOSI
   int miso;    // GPIO for MISO
   int ss_pol;  // slave select off state
   int ss_us;   // delay after slave select
   int clk_pol; // clock off state
   int clk_pha; // clock phase
   int clk_us;  // clock micros
} rawSPI_t;

rawWave_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
   uint32_t flags;
} rawWave_t;

rawWaveInfo_t

-typedef struct
{
   uint16_t botCB;  // first CB used by wave
   uint16_t topCB;  // last CB used by wave
   uint16_t botOOL; // last OOL used by wave
   uint16_t topOOL; // first OOL used by wave
   uint16_t deleted;
   uint16_t numCB;
   uint16_t numBOOL;
   uint16_t numTOOL;
} rawWaveInfo_t;

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

SCLK

-The GPIO used for the SCLK signal when bit banging SPI. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by gpioStoreScript. -

*scriptName

-The name of a shell script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. -

*scriptString

-The string to be passed to a shell script to be executed. -

SDA

-The user GPIO to use for data when bit banging I2C. -

secondaryChannel: 0-6

-The DMA channel used to time output waveforms. -

*seconds

-A pointer to a uint32_t to store the second component of -a returned time. -

seconds

-The number of seconds. -

seekFrom

-PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

-The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). -

*segs

-An array of segments which make up a combined I2C transaction. -

serFlags

-Flags which modify a serial open command. None are currently defined. -

*sertty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

setting

-A value used to set a flag, 0 for false, non-zero for true. -

signum: 0-63

-PI_MIN_SIGNUM 0
PI_MAX_SIGNUM 63

size_t

-A standard type used to indicate the size of an object in bytes. -

*sockAddr

-An array of network addresses allowed to use the socket interface encoded -as 32 bit numbers. -

E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. -

*spi

-A pointer to a rawSPI_t structure. -

spiBitFirst

-GPIO reads are made from spiBitFirst to spiBitLast. -

spiBitLast

-GPIO reads are made from spiBitFirst to spiBitLast. -

spiBits

-The number of bits to transfer in a raw SPI transaction. -

spiChan

-A SPI channel, 0-2. -

spiFlags

-See spiOpen and bbSPIOpen. -

spiSS

-The SPI slave select GPIO in a raw SPI transaction. -

spiTxBits

-The number of bits to transfer dring a raw SPI transaction -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (gpioGlitchFilter) or triggering -the active part of a noise filter (gpioNoiseFilter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

PI_MIN_WAVE_HALFSTOPBITS 2
PI_MAX_WAVE_HALFSTOPBITS 8

*str

-An array of characters. -

timeout

-A GPIO level change timeout in milliseconds. -

gpioSetWatchdog -PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000


gpioSetISRFunc and gpioSetISRFuncEx -<=0 cancel timeout
>0 timeout after specified milliseconds

timer

-PI_MIN_TIMER 0
PI_MAX_TIMER 9

timetype

-PI_TIME_RELATIVE 0
PI_TIME_ABSOLUTE 1

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

uint64_t: 0-(2^64)-1

-A 64-bit unsigned value. -

unsigned

-A whole number >= 0. -

updateMask

-A 64 bit mask indicating which GPIO may be written to by the user. -

If GPIO#n may be written then bit (1<<n) is set. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. -

In the calling function: -

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: -

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

-Denoting no parameter is required -

wave_id

-A number identifying a waveform created by gpioWaveCreate. -

wave_mode

-The mode determines if the waveform is sent once or cycles -repeatedly. The SYNC variants wait for the current waveform -to reach the end of a cycle or finish before starting the new -waveform. -

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

Socket Command Codes


#define PI_CMD_MODES  0
#define PI_CMD_MODEG  1
#define PI_CMD_PUD    2
#define PI_CMD_READ   3
#define PI_CMD_WRITE  4
#define PI_CMD_PWM    5
#define PI_CMD_PRS    6
#define PI_CMD_PFS    7
#define PI_CMD_SERVO  8
#define PI_CMD_WDOG   9
#define PI_CMD_BR1   10
#define PI_CMD_BR2   11
#define PI_CMD_BC1   12
#define PI_CMD_BC2   13
#define PI_CMD_BS1   14
#define PI_CMD_BS2   15
#define PI_CMD_TICK  16
#define PI_CMD_HWVER 17
#define PI_CMD_NO    18
#define PI_CMD_NB    19
#define PI_CMD_NP    20
#define PI_CMD_NC    21
#define PI_CMD_PRG   22
#define PI_CMD_PFG   23
#define PI_CMD_PRRG  24
#define PI_CMD_HELP  25
#define PI_CMD_PIGPV 26
#define PI_CMD_WVCLR 27
#define PI_CMD_WVAG  28
#define PI_CMD_WVAS  29
#define PI_CMD_WVGO  30
#define PI_CMD_WVGOR 31
#define PI_CMD_WVBSY 32
#define PI_CMD_WVHLT 33
#define PI_CMD_WVSM  34
#define PI_CMD_WVSP  35
#define PI_CMD_WVSC  36
#define PI_CMD_TRIG  37
#define PI_CMD_PROC  38
#define PI_CMD_PROCD 39
#define PI_CMD_PROCR 40
#define PI_CMD_PROCS 41
#define PI_CMD_SLRO  42
#define PI_CMD_SLR   43
#define PI_CMD_SLRC  44
#define PI_CMD_PROCP 45
#define PI_CMD_MICS  46
#define PI_CMD_MILS  47
#define PI_CMD_PARSE 48
#define PI_CMD_WVCRE 49
#define PI_CMD_WVDEL 50
#define PI_CMD_WVTX  51
#define PI_CMD_WVTXR 52
#define PI_CMD_WVNEW 53

#define PI_CMD_I2CO  54
#define PI_CMD_I2CC  55
#define PI_CMD_I2CRD 56
#define PI_CMD_I2CWD 57
#define PI_CMD_I2CWQ 58
#define PI_CMD_I2CRS 59
#define PI_CMD_I2CWS 60
#define PI_CMD_I2CRB 61
#define PI_CMD_I2CWB 62
#define PI_CMD_I2CRW 63
#define PI_CMD_I2CWW 64
#define PI_CMD_I2CRK 65
#define PI_CMD_I2CWK 66
#define PI_CMD_I2CRI 67
#define PI_CMD_I2CWI 68
#define PI_CMD_I2CPC 69
#define PI_CMD_I2CPK 70

#define PI_CMD_SPIO  71
#define PI_CMD_SPIC  72
#define PI_CMD_SPIR  73
#define PI_CMD_SPIW  74
#define PI_CMD_SPIX  75

#define PI_CMD_SERO  76
#define PI_CMD_SERC  77
#define PI_CMD_SERRB 78
#define PI_CMD_SERWB 79
#define PI_CMD_SERR  80
#define PI_CMD_SERW  81
#define PI_CMD_SERDA 82

#define PI_CMD_GDC   83
#define PI_CMD_GPW   84

#define PI_CMD_HC    85
#define PI_CMD_HP    86

#define PI_CMD_CF1   87
#define PI_CMD_CF2   88

#define PI_CMD_BI2CC 89
#define PI_CMD_BI2CO 90
#define PI_CMD_BI2CZ 91

#define PI_CMD_I2CZ  92

#define PI_CMD_WVCHA 93

#define PI_CMD_SLRI  94

#define PI_CMD_CGI   95
#define PI_CMD_CSI   96

#define PI_CMD_FG    97
#define PI_CMD_FN    98

#define PI_CMD_NOIB  99

#define PI_CMD_WVTXM 100
#define PI_CMD_WVTAT 101

#define PI_CMD_PADS  102
#define PI_CMD_PADG  103

#define PI_CMD_FO    104
#define PI_CMD_FC    105
#define PI_CMD_FR    106
#define PI_CMD_FW    107
#define PI_CMD_FS    108
#define PI_CMD_FL    109

#define PI_CMD_SHELL 110

#define PI_CMD_BSPIC 111
#define PI_CMD_BSPIO 112
#define PI_CMD_BSPIX 113

#define PI_CMD_BSCX  114

#define PI_CMD_EVM   115
#define PI_CMD_EVT   116

#define PI_CMD_PROCU 117
#define PI_CMD_WVCAP 118

Error Codes


#define PI_INIT_FAILED       -1 // gpioInitialise failed
#define PI_BAD_USER_GPIO     -2 // GPIO not 0-31
#define PI_BAD_GPIO          -3 // GPIO not 0-53
#define PI_BAD_MODE          -4 // mode not 0-7
#define PI_BAD_LEVEL         -5 // level not 0-1
#define PI_BAD_PUD           -6 // pud not 0-2
#define PI_BAD_PULSEWIDTH    -7 // pulsewidth not 0 or 500-2500
#define PI_BAD_DUTYCYCLE     -8 // dutycycle outside set range
#define PI_BAD_TIMER         -9 // timer not 0-9
#define PI_BAD_MS           -10 // ms not 10-60000
#define PI_BAD_TIMETYPE     -11 // timetype not 0-1
#define PI_BAD_SECONDS      -12 // seconds < 0
#define PI_BAD_MICROS       -13 // micros not 0-999999
#define PI_TIMER_FAILED     -14 // gpioSetTimerFunc failed
#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
#define PI_NO_ALERT_FUNC    -16 // DEPRECATED
#define PI_BAD_CLK_PERIPH   -17 // clock peripheral not 0-1
#define PI_BAD_CLK_SOURCE   -18 // DEPRECATED
#define PI_BAD_CLK_MICROS   -19 // clock micros not 1, 2, 4, 5, 8, or 10
#define PI_BAD_BUF_MILLIS   -20 // buf millis not 100-10000
#define PI_BAD_DUTYRANGE    -21 // dutycycle range not 25-40000
#define PI_BAD_DUTY_RANGE   -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
#define PI_BAD_SIGNUM       -22 // signum not 0-63
#define PI_BAD_PATHNAME     -23 // can't open pathname
#define PI_NO_HANDLE        -24 // no handle available
#define PI_BAD_HANDLE       -25 // unknown handle
#define PI_BAD_IF_FLAGS     -26 // ifFlags > 4
#define PI_BAD_CHANNEL      -27 // DMA channel not 0-15
#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15
#define PI_BAD_SOCKET_PORT  -28 // socket port not 1024-32000
#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15
#define PI_NOT_INITIALISED  -31 // function called before gpioInitialise
#define PI_INITIALISED      -32 // function called after gpioInitialise
#define PI_BAD_WAVE_MODE    -33 // waveform mode not 0-3
#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
#define PI_BAD_WAVE_BAUD    -35 // baud rate not 50-250K(RX)/50-1M(TX)
#define PI_TOO_MANY_PULSES  -36 // waveform has too many pulses
#define PI_TOO_MANY_CHARS   -37 // waveform has too many chars
#define PI_NOT_SERIAL_GPIO  -38 // no bit bang serial read on GPIO
#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
#define PI_BAD_SERIAL_BUF   -40 // bad (null) serial buf parameter
#define PI_NOT_PERMITTED    -41 // GPIO operation not permitted
#define PI_SOME_PERMITTED   -42 // one or more GPIO not permitted
#define PI_BAD_WVSC_COMMND  -43 // bad WVSC subcommand
#define PI_BAD_WVSM_COMMND  -44 // bad WVSM subcommand
#define PI_BAD_WVSP_COMMND  -45 // bad WVSP subcommand
#define PI_BAD_PULSELEN     -46 // trigger pulse length not 1-100
#define PI_BAD_SCRIPT       -47 // invalid script
#define PI_BAD_SCRIPT_ID    -48 // unknown script id
#define PI_BAD_SER_OFFSET   -49 // add serial data offset > 30 minutes
#define PI_GPIO_IN_USE      -50 // GPIO already in use
#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
#define PI_BAD_PARAM_NUM    -52 // script parameter id not 0-9
#define PI_DUP_TAG          -53 // script has duplicate tag
#define PI_TOO_MANY_TAGS    -54 // script has too many tags
#define PI_BAD_SCRIPT_CMD   -55 // illegal script command
#define PI_BAD_VAR_NUM      -56 // script variable id not 0-149
#define PI_NO_SCRIPT_ROOM   -57 // no more room for scripts
#define PI_NO_MEMORY        -58 // can't allocate temporary memory
#define PI_SOCK_READ_FAILED -59 // socket read failed
#define PI_SOCK_WRIT_FAILED -60 // socket write failed
#define PI_TOO_MANY_PARAM   -61 // too many script parameters (> 10)
#define PI_NOT_HALTED       -62 // DEPRECATED
#define PI_SCRIPT_NOT_READY -62 // script initialising
#define PI_BAD_TAG          -63 // script has unresolved tag
#define PI_BAD_MICS_DELAY   -64 // bad MICS delay (too large)
#define PI_BAD_MILS_DELAY   -65 // bad MILS delay (too large)
#define PI_BAD_WAVE_ID      -66 // non existent wave id
#define PI_TOO_MANY_CBS     -67 // No more CBs for waveform
#define PI_TOO_MANY_OOL     -68 // No more OOL for waveform
#define PI_EMPTY_WAVEFORM   -69 // attempt to create an empty waveform
#define PI_NO_WAVEFORM_ID   -70 // no more waveforms
#define PI_I2C_OPEN_FAILED  -71 // can't open I2C device
#define PI_SER_OPEN_FAILED  -72 // can't open serial device
#define PI_SPI_OPEN_FAILED  -73 // can't open SPI device
#define PI_BAD_I2C_BUS      -74 // bad I2C bus
#define PI_BAD_I2C_ADDR     -75 // bad I2C address
#define PI_BAD_SPI_CHANNEL  -76 // bad SPI channel
#define PI_BAD_FLAGS        -77 // bad i2c/spi/ser open flags
#define PI_BAD_SPI_SPEED    -78 // bad SPI speed
#define PI_BAD_SER_DEVICE   -79 // bad serial device name
#define PI_BAD_SER_SPEED    -80 // bad serial baud rate
#define PI_BAD_PARAM        -81 // bad i2c/spi/ser parameter
#define PI_I2C_WRITE_FAILED -82 // i2c write failed
#define PI_I2C_READ_FAILED  -83 // i2c read failed
#define PI_BAD_SPI_COUNT    -84 // bad SPI count
#define PI_SER_WRITE_FAILED -85 // ser write failed
#define PI_SER_READ_FAILED  -86 // ser read failed
#define PI_SER_READ_NO_DATA -87 // ser read no data available
#define PI_UNKNOWN_COMMAND  -88 // unknown command
#define PI_SPI_XFER_FAILED  -89 // spi xfer/read/write failed
#define PI_BAD_POINTER      -90 // bad (NULL) pointer
#define PI_NO_AUX_SPI       -91 // no auxiliary SPI on Pi A or B
#define PI_NOT_PWM_GPIO     -92 // GPIO is not in use for PWM
#define PI_NOT_SERVO_GPIO   -93 // GPIO is not in use for servo pulses
#define PI_NOT_HCLK_GPIO    -94 // GPIO has no hardware clock
#define PI_NOT_HPWM_GPIO    -95 // GPIO has no hardware PWM
#define PI_BAD_HPWM_FREQ    -96 // invalid hardware PWM frequency
#define PI_BAD_HPWM_DUTY    -97 // hardware PWM dutycycle not 0-1M
#define PI_BAD_HCLK_FREQ    -98 // invalid hardware clock frequency
#define PI_BAD_HCLK_PASS    -99 // need password to use hardware clock 1
#define PI_HPWM_ILLEGAL    -100 // illegal, PWM in use for main clock
#define PI_BAD_DATABITS    -101 // serial data bits not 1-32
#define PI_BAD_STOPBITS    -102 // serial (half) stop bits not 2-8
#define PI_MSG_TOOBIG      -103 // socket/pipe message too big
#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode
#define PI_TOO_MANY_SEGS   -105 // too many I2C transaction segments
#define PI_BAD_I2C_SEG     -106 // an I2C transaction segment failed
#define PI_BAD_SMBUS_CMD   -107 // SMBus command not supported by driver
#define PI_NOT_I2C_GPIO    -108 // no bit bang I2C in progress on GPIO
#define PI_BAD_I2C_WLEN    -109 // bad I2C write length
#define PI_BAD_I2C_RLEN    -110 // bad I2C read length
#define PI_BAD_I2C_CMD     -111 // bad I2C command
#define PI_BAD_I2C_BAUD    -112 // bad I2C baud rate, not 50-500k
#define PI_CHAIN_LOOP_CNT  -113 // bad chain loop count
#define PI_BAD_CHAIN_LOOP  -114 // empty chain loop
#define PI_CHAIN_COUNTER   -115 // too many chain counters
#define PI_BAD_CHAIN_CMD   -116 // bad chain command
#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
#define PI_CHAIN_NESTING   -118 // chain counters nested too deeply
#define PI_CHAIN_TOO_BIG   -119 // chain is too long
#define PI_DEPRECATED      -120 // deprecated function removed
#define PI_BAD_SER_INVERT  -121 // bit bang serial invert not 0 or 1
#define PI_BAD_EDGE        -122 // bad ISR edge value, not 0-2
#define PI_BAD_ISR_INIT    -123 // bad ISR initialisation
#define PI_BAD_FOREVER     -124 // loop forever must be last command
#define PI_BAD_FILTER      -125 // bad filter parameter
#define PI_BAD_PAD         -126 // bad pad number
#define PI_BAD_STRENGTH    -127 // bad pad drive strength
#define PI_FIL_OPEN_FAILED -128 // file open failed
#define PI_BAD_FILE_MODE   -129 // bad file mode
#define PI_BAD_FILE_FLAG   -130 // bad file flag
#define PI_BAD_FILE_READ   -131 // bad file read
#define PI_BAD_FILE_WRITE  -132 // bad file write
#define PI_FILE_NOT_ROPEN  -133 // file not open for read
#define PI_FILE_NOT_WOPEN  -134 // file not open for write
#define PI_BAD_FILE_SEEK   -135 // bad file seek
#define PI_NO_FILE_MATCH   -136 // no files match pattern
#define PI_NO_FILE_ACCESS  -137 // no permission to access file
#define PI_FILE_IS_A_DIR   -138 // file is a directory
#define PI_BAD_SHELL_STATUS -139 // bad shell return status
#define PI_BAD_SCRIPT_NAME -140 // bad script name
#define PI_BAD_SPI_BAUD    -141 // bad SPI baud rate, not 50-500k
#define PI_NOT_SPI_GPIO    -142 // no bit bang SPI in progress on GPIO
#define PI_BAD_EVENT_ID    -143 // bad event id
#define PI_CMD_INTERRUPTED -144 // Used by Python
#define PI_NOT_ON_BCM2711  -145 // not available on BCM2711
#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711

#define PI_PIGIF_ERR_0    -2000
#define PI_PIGIF_ERR_99   -2099

#define PI_CUSTOM_ERR_0   -3000
#define PI_CUSTOM_ERR_999 -3999

Defaults


#define PI_DEFAULT_BUFFER_MILLIS           120
#define PI_DEFAULT_CLK_MICROS              5
#define PI_DEFAULT_CLK_PERIPHERAL          PI_CLOCK_PCM
#define PI_DEFAULT_IF_FLAGS                0
#define PI_DEFAULT_FOREGROUND              0
#define PI_DEFAULT_DMA_CHANNEL             14
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL     14
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL   6
#define PI_DEFAULT_DMA_PRIMARY_CH_2711     7
#define PI_DEFAULT_DMA_SECONDARY_CH_2711   6
#define PI_DEFAULT_DMA_NOT_SET             15
#define PI_DEFAULT_SOCKET_PORT             8888
#define PI_DEFAULT_SOCKET_PORT_STR         "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR         "localhost"
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN     0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_B1          0x03E7CF93
#define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_ZERO        0x0080000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI2B        0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI3B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI4B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_COMPUTE     0x00FFFFFFFFFFFFLL
#define PI_DEFAULT_MEM_ALLOC_MODE          PI_MEM_ALLOC_AUTO

#define PI_DEFAULT_CFG_INTERNALS           0

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/download.html b/DOC/HTML/download.html deleted file mode 100644 index 84ec4da..0000000 --- a/DOC/HTML/download.html +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Download & Install

-If the pigpio daemon is running it should be killed (sudo killall -pigpiod) before make install and restarted afterwards (sudo -pigpiod).
-
-The initial part of the make, the -compilation of pigpio.c, takes 100 seconds on early model -Pis.  Be patient.  The overall install takes just over 3 -minutes.
-

Download and install (V75)

-wget https://github.com/joan2937/pigpio/archive/v75.zip
-unzip v75.zip
-cd pigpio-75
-make
-sudo make install

-
-If the Python part of the install fails it may be because you need -the setup tools.
-
-sudo apt install python-setuptools -python3-setuptools

-
-

To check the library

-These tests make extensive use of GPIO 25 (pin 22).  Make sure -nothing, or only a LED, is connected to the GPIO before running the -tests.  Most tests are statistical in nature and so may on -occasion fail.  Repeated failures on the same test or many -failures in a group of tests indicate a problem.
-
-sudo ./x_pigpio # check C I/F
-
-sudo pigpiod    # start daemon
-
-./x_pigpiod_if2 # check C      I/F to -daemon
-./x_pigpio.py   # check Python I/F to daemon
-./x_pigs        # check -pigs   I/F to daemon
-./x_pipe        # check -pipe   I/F to daemon
-
-
-

To compile, link, and run a C program

-gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
-sudo ./foobar


-

To start the pigpio daemon

-sudo pigpiod
-

To stop the pigpio daemon

-sudo killall pigpiod

-

github

-git clone https://github.com/joan2937/pigpio
-

Raspbian (raspberrypi.org image)

-

This may not be the most recent version.  You can check the -version with the command pigpiod -v.

-sudo apt-get update
-sudo apt-get install pigpio python-pigpio python3-pigpio

-
-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_LDR.html b/DOC/HTML/ex_LDR.html deleted file mode 100644 index 6b1cf23..0000000 --- a/DOC/HTML/ex_LDR.html +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

LDR Example

-

The following code shows a method of reading analogue sensors on -the digital input only Pi.  A Light Dependent Resistor (LDR) -varies its resistance according to the incident light -intensisty.

-

SETUP

-fritzing diagramThe LDR -used is a Cadmium Sulphide device with a 1MOhm dark resistance and -2-4KOhm at 100 lux.  The capacitor is a 104 -ceramic.
-
-One end of the capacitor is connected to Pi ground.
-
-One end of the LDR is connected to Pi 3V3.
-
-The other ends of the capacitor and LDR are connected to a spare -gpio.

-

Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18 -(P1-12) is used for the gpio.

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/* ------------------------------------------------------------------------
- -
-   3V3 ----- Light Dependent Resistor --+-- Capacitor ------ Ground
-                                        -|
-                                        -+-- gpio
-
-
-  cc -o LDR LDR.c -lpigpio -lpthread -lrt
-  sudo ./LDR
-
-*/
-
-#define LDR 18
-
-/* forward declaration */
-
-void alert(int pin, int level, uint32_t tick);
-
-int main (int argc, char *argv[])
-{
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetAlertFunc(LDR, alert); /* call alert when LDR -changes state */
-    
-   while (1)
-   {
-      gpioSetMode(LDR, PI_OUTPUT); /* -drain capacitor */
-
-      gpioWrite(LDR, PI_OFF);
-
-      gpioDelay(200); /* 50 micros is -enough, 200 is overkill */
-
-      gpioSetMode(LDR, PI_INPUT); /* start -capacitor recharge */
-
-      gpioDelay(10000); /* nominal 100 -readings per second */
-   }
-
-   gpioTerminate();
-}
-
-void alert(int pin, int level, uint32_t tick)
-{
-   static uint32_t inited = 0;
-   static uint32_t lastTick, firstTick;
-
-   uint32_t diffTick;
-
-   if (inited)
-   {
-      diffTick = tick - lastTick;
-      lastTick = tick;
-
-      if (level == 1) printf("%u %d\ ", -tick-firstTick, diffTick);
-   }
-   else
-   {
-      inited = 1;
-      firstTick = tick;
-      lastTick = firstTick;
-   }
-}
-

BUILD

-cc -o LDR LDR.c -lpigpio -lrt -lpthread
-

RUN

-sudo ./LDR >LDR.dat &
-
-While the program is running you can capture the waveform using the -notification feature built in to pigpio.  Issue the following -commands on the Pi.
-
-pigs no
-pig2vcd  </dev/pigpio0 >LDR.vcd &
-pigs nb 0 0x40000 # set bit for gpio 18
-

Change the light falling on the LDR for a few seconds (e.g. -shine a torch on it or shade it with your hands).

-pigs nc 0
-

The file LDR.vcd will contain the captured waveform, which can -be viewed using GTKWave.

-

Overview

-LDR waveform 1
-

Reading circa every 10ms

-LDR waveform 2
-

One reading, circa 400us

-LDR waveform 3
-

The file LDR.dat will contain pairs of timestamps and recharge -time (in us).  The following  script will convert the -timestamps into seconds.

-

awk '{print $1/1000000, $2}' LDR.dat ->LDR-secs.dat

-

Gnuplot is a useful tool to graph data.

-plot [14:24] 'LDR-secs.dat' with lines title 'LDR' -

Gnuplot readings 14-24 seconds

-

gnuplot 1

-plot [18:21] 'LDR-secs.dat' with lines title 'LDR'
-
-Gnuplot readings 18-21 seconds -

Gnuplot 2

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_ir_remote.html b/DOC/HTML/ex_ir_remote.html deleted file mode 100644 index 5f548cb..0000000 --- a/DOC/HTML/ex_ir_remote.html +++ /dev/null @@ -1,308 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

IR Remote Example

-

The following code shows one way to read an infrared remote -control device (the sort used in TVs and stereo systems).

-

SETUP

-fritzing diagramThe device used -is a SFH5110 (IR Receiver for remote control, -carrier 38 kHz).
-
Pin 1 (left from front) may be connected to any spare -gpio.  Here it's connected via a 4K7 current limiting -resistor.  This isn't really needed as the device has an -internal 23K resistor in-line.  It does no harm though.
-
-Pin 2 should be connected to a Pi ground pin.
-
-Pin 3 should be connected to a Pi 5V pin.
-

Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground -(P1-14), and pin 3 to 5V (P1-2).

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-#define IR_PIN 7
-
-#define OUTSIDE_CODE 0
-#define INSIDE_CODE  1
-
-#define MIN_MESSAGE_GAP 3000
-#define MAX_MESSAGE_END 3000
-
-#define MAX_TRANSITIONS 500
-
-/*
-   using the FNV-1a -hash                
- -   from -http://isthe.com/chongo/tech/comp/fnv/#FNV-param
-*/
-
-#define FNV_PRIME_32 16777619
-#define FNV_BASIS_32 2166136261U
-
-static volatile uint32_t ir_hash = 0;
-
-typedef struct
-{
-   int state;
-   int count;
-   int level;
-   uint16_t micros[MAX_TRANSITIONS];
-} decode_t;
-
-/* forward declarations */
-
-void     alert(int gpio, int level, uint32_t -tick);
-uint32_t getHash(decode_t * decode);
-void     updateState(decode_t * decode, int -level, uint32_t micros);
-
-int main(int argc, char * argv[])
-{
-   if (gpioInitialise()<0)
-   {
-      return 1 ;
-   }
-
-   /* IR pin as input */
-
-   gpioSetMode(IR_PIN, PI_INPUT);
-
-   /* 5ms max gap after last pulse */
-
-   gpioSetWatchdog(IR_PIN, 5);
-
-   /* monitor IR level changes */
-
-   gpioSetAlertFunc(IR_PIN, alert);
-
-   while (1)
-   {
-      if (ir_hash)
-      {
-         /* non-zero means -new decode */
-         printf("ir code is -%u\ ", ir_hash);
-         ir_hash = 0;
-      }
-
-      gpioDelay(100000); /* check remote -10 times per second */
-   }
-
-   gpioTerminate();
-}
-
-void alert(int gpio, int level, uint32_t tick)
-{
-   static int inited = 0;
-
-   static decode_t activeHigh, activeLow;
-
-   static uint32_t lastTick;
-
-   uint32_t diffTick;
-
-   if (!inited)
-   {
-      inited = 1;
-
-      activeHigh.state = OUTSIDE_CODE; -activeHigh.level = PI_LOW;
-      activeLow.state  = -OUTSIDE_CODE; activeLow.level  = PI_HIGH;
-
-      lastTick = tick;
-      return;
-   }
-
-   diffTick = tick - lastTick;
-
-   if (level != PI_TIMEOUT) lastTick = tick;
-
-   updateState(&activeHigh, level, diffTick);
-   updateState(&activeLow, level, diffTick);
-}
-
-void updateState(decode_t * decode, int level, uint32_t micros)
-{
-   /*
-      We are dealing with active high as -well as active low
-      remotes.  Abstract the common -functionality.
-   */
-
-   if (decode->state == OUTSIDE_CODE)
-   {
-      if (level == decode->level)
-      {
-         if (micros > -MIN_MESSAGE_GAP)
-         {
-            -decode->state = INSIDE_CODE;
-            -decode->count = 0;
-         }
-      }
-   }
-   else
-   {
-      if (micros > MAX_MESSAGE_END)
-      {
-         /* end of message -*/
-
-         /* ignore if last -code not consumed */
-
-         if (!ir_hash) -ir_hash = getHash(decode);
-
-         decode->state = -OUTSIDE_CODE;
-      }
-      else
-      {
-         if -(decode->count < (MAX_TRANSITIONS-1))
-         {
-            -if (level != PI_TIMEOUT)
-               -decode->micros[decode->count++] = micros;
-         }
-      }
-   }
-}
-
-int compare(unsigned int oldval, unsigned int newval)
-{
-   if      (newval < (oldval -* 0.75)) {return 1;}
-   else if (oldval < (newval * 0.75)) {return 2;}
-   -else                               -{return 4;}
-}
-
-uint32_t getHash(decode_t * decode)
-{
-   /* use FNV-1a */
-
-   uint32_t hash;
-   int i, value;
-
-   if (decode->count < 6) {return 0;}
-
-   hash = FNV_BASIS_32;
-
-   for (i=0; i<(decode->count-2); i++)
-   {
-      value = -compare(decode->micros[i], decode->micros[i+2]);
-
-      hash = hash ^ value;
-      hash = (hash * FNV_PRIME_32);
-   }
-
-   return hash;
-}
-

BUILD

-cc -o ir_remote ir_remote.c -lpigpio -lrt --lpthread
-

RUN

-sudo ./ir_remote
-

A hash code is formed from the level transitions detected during -a remote key press.  This is likely to be unique over multiple -remotes and keys.

-

While the program is running you can capture the waveform using -the notification feature built in to pigpio.  Issue the -following commands on the Pi.

-pigs no
-pig2vcd  </dev/pigpio0 >ir.vcd &
-pigs nb 0 0x80 # set bits for gpios 7 (0x80)
-

Press a few different remotes and keys.  Then enter

-pigs nc 0
-

The file ir.vcd will contain the captured waveform, which can be -viewed using GTKWave.

-

Overview

-ir remote waveform 1
-

Remote A typical waveform

-ir remote waveform 2
-

Remote B typical waveform

--"ir -
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_motor_shield.html b/DOC/HTML/ex_motor_shield.html deleted file mode 100644 index e5d28f0..0000000 --- a/DOC/HTML/ex_motor_shield.html +++ /dev/null @@ -1,309 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Arduino Motor Shield

-The following example demonstrates the use of an Arduino shield -from the Rasperry Pi.
-
-The shield used is a clone of the Adafruit motor shield.  See -shieldlist.org -for details.
-
-For the demonstration DC motors 3 and 4 are being driven forwards -and backwards with changing speeds (speeds are controlled via -PWM).
-
-Seven connections are made between the Pi and the shield.  -Four to latch the motor states (latch, enable, data, clock); Two to -control motor speed (PWM 3 and 4); and ground.
-
-The code used was ported from the Adafruit Arduino code and -converted to use the pigpio library.  Only the DC motor code -was ported.
-
-A video of the shield in use is available at youtube.com
-
-#include <stdio.h>

-
-#include <pigpio.h>
-
-/*
-   This code may be used to drive the Adafruit (or -clones) Motor Shield.
-
-   The code as written only supports DC motors.
-
-   http://shieldlist.org/adafruit/motor
-
-   The shield pinouts are
-
-   D12 MOTORLATCH
-   D11 PMW motor 1
-   D10 Servo 1
-   D9  Servo 2
-   D8  MOTORDATA
-
-   D7  MOTORENABLE
-   D6  PWM motor 4
-   D5  PWM motor 3
-   D4  MOTORCLK
-   D3  PWM motor 2
-
-   The motor states (forward, backward, brake, release) -are encoded using the
-   MOTOR_ latch pins.  This saves four gpios.
-*/
-
-typedef unsigned char uint8_t;
-
-#define BIT(bit) (1 << (bit))
-
-/* assign gpios to drive the shield pins */
-
-/*      -Shield      Pi */
-
-#define MOTORLATCH  14
-#define MOTORCLK    24
-#define MOTORENABLE 25
-#define MOTORDATA   15
-
-#define MOTOR_3_PWM  7
-#define MOTOR_4_PWM  8
-
-/*
-   The only other connection needed between the Pi and -the shield
-   is ground to ground. I used Pi P1-6 to shield gnd -(next to D13).
-*/
-
-/* assignment of motor states to latch */
-
-#define MOTOR1_A 2
-#define MOTOR1_B 3
-#define MOTOR2_A 1
-#define MOTOR2_B 4
-#define MOTOR4_A 0
-#define MOTOR4_B 6
-#define MOTOR3_A 5
-#define MOTOR3_B 7
-
-#define FORWARD  1
-#define BACKWARD 2
-#define BRAKE    3
-#define RELEASE  4
-
-static uint8_t latch_state;
-
-void latch_tx(void)
-{
-   unsigned char i;
-
-   gpioWrite(MOTORLATCH, PI_LOW);
-
-   gpioWrite(MOTORDATA, PI_LOW);
-
-   for (i=0; i<8; i++)
-   {
-      gpioDelay(10);  // 10 micros -delay
-
-      gpioWrite(MOTORCLK, PI_LOW);
-
-      if (latch_state & BIT(7-i)) -gpioWrite(MOTORDATA, PI_HIGH);
-      -else                        -gpioWrite(MOTORDATA, PI_LOW);
-
-      gpioDelay(10);  // 10 micros -delay
-
-      gpioWrite(MOTORCLK, PI_HIGH);
-   }
-
-   gpioWrite(MOTORLATCH, PI_HIGH);
-}
-
-void init(void)
-{
-   latch_state = 0;
-
-   latch_tx();
-
-   gpioWrite(MOTORENABLE, PI_LOW);
-}
-
-void DCMotorInit(uint8_t num)
-{
-   switch (num)
-   {
-      case 1: latch_state &= -~BIT(MOTOR1_A) & ~BIT(MOTOR1_B); break;
-      case 2: latch_state &= -~BIT(MOTOR2_A) & ~BIT(MOTOR2_B); break;
-      case 3: latch_state &= -~BIT(MOTOR3_A) & ~BIT(MOTOR3_B); break;
-      case 4: latch_state &= -~BIT(MOTOR4_A) & ~BIT(MOTOR4_B); break;
-      default: return;
-   }
-
-   latch_tx();
-
-   printf("Latch=%08X\ ", latch_state);
-}
-
-void DCMotorRun(uint8_t motornum, uint8_t cmd)
-{
-   uint8_t a, b;
-
-   switch (motornum)
-   {
-      case 1: a = MOTOR1_A; b = MOTOR1_B; -break;
-      case 2: a = MOTOR2_A; b = MOTOR2_B; -break;
-      case 3: a = MOTOR3_A; b = MOTOR3_B; -break;
-      case 4: a = MOTOR4_A; b = MOTOR4_B; -break;
-      default: return;
-   }

-   switch (cmd)
-   {
-      case FORWARD:  latch_state -|=  BIT(a); latch_state &= ~BIT(b); break;
-      case BACKWARD: latch_state &= -~BIT(a); latch_state |=  BIT(b); break;
-      case RELEASE:  latch_state -&= ~BIT(a); latch_state &= ~BIT(b); break;
-      default: return;
-   }
-
-   latch_tx();
-
-   printf("Latch=%08X\ ", latch_state);
-}
-
-int main (int argc, char *argv[])
-{
-   int i;
-
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(MOTORLATCH,  PI_OUTPUT);
-   gpioSetMode(MOTORENABLE, PI_OUTPUT);
-   gpioSetMode(MOTORDATA,   PI_OUTPUT);
-   gpioSetMode(MOTORCLK,    -PI_OUTPUT);
-
-   gpioSetMode(MOTOR_3_PWM, PI_OUTPUT);
-   gpioSetMode(MOTOR_4_PWM, PI_OUTPUT);
-
-   gpioPWM(MOTOR_3_PWM, 0);
-   gpioPWM(MOTOR_4_PWM, 0);
-
-   init();
-
-   for (i=60; i<160; i+=20)
-   {
-      gpioPWM(MOTOR_3_PWM, i);
-      gpioPWM(MOTOR_4_PWM, 220-i);
-
-      DCMotorRun(3, FORWARD);
-      DCMotorRun(4, BACKWARD);
-
-      sleep(2);
-
-      DCMotorRun(3, RELEASE);
-      DCMotorRun(4, RELEASE);
-
-      sleep(2);
-
-      gpioPWM(MOTOR_4_PWM, i);
-      gpioPWM(MOTOR_3_PWM, 220-i);
-
-      DCMotorRun(3, BACKWARD);
-      DCMotorRun(4, FORWARD);
-
-      sleep(2);
-
-      DCMotorRun(3, RELEASE);
-      DCMotorRun(4, RELEASE);
-
-      sleep(2);
-   }
-
-   gpioPWM(MOTOR_4_PWM, 0);
-   gpioPWM(MOTOR_3_PWM, 0);
-
-   DCMotorRun(3, RELEASE);
-   DCMotorRun(4, RELEASE);
-
-   gpioTerminate();
-}
-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_rotary_encoder.html b/DOC/HTML/ex_rotary_encoder.html deleted file mode 100644 index b15b354..0000000 --- a/DOC/HTML/ex_rotary_encoder.html +++ /dev/null @@ -1,240 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Rotary Encoder Example

-

The following code shows one way to read an incremental -mechanical rotary enoder (the sort used for volume control in audio -systems).  These rotary encoders have two switches A and B -which return a quadrature output, i.e. they are 90 degrees out of -phase.

-

SETUP

-fritzing diagramThe common -(centre) terminal should be connected to a Pi ground. -

The A and B terminals may be connected to any spare gpios.

-

Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7 -(P1-26).

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/*
-   Rotary encoder connections:
-
-   Encoder A      - gpio -18   (pin P1-12)
-   Encoder B      - gpio -7    (pin P1-26)
-   Encoder Common - Pi ground (pin P1-20)
-*/
-
-#define ENCODER_A 18
-#define ENCODER_B  7
-
-static volatile int encoderPos;
-
-/* forward declaration */
-
-void encoderPulse(int gpio, int lev, uint32_t tick);
-
-int main(int argc, char * argv[])
-{
-   int pos=0;
-
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(ENCODER_A, PI_INPUT);
-   gpioSetMode(ENCODER_B, PI_INPUT);
-
-   /* pull up is needed as encoder common is grounded -*/
-
-   gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);
-   gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);
-
-   encoderPos = pos;
-
-   /* monitor encoder level changes */
-
-   gpioSetAlertFunc(ENCODER_A, encoderPulse);
-   gpioSetAlertFunc(ENCODER_B, encoderPulse);
-
-   while (1)
-   {
-      if (pos != encoderPos)
-      {
-         pos = -encoderPos;
-         printf("pos=%d\ ", -pos);
-      }
-      gpioDelay(20000); /* check pos 50 -times per second */
-   }
-
-   gpioTerminate();
-}
-
-void encoderPulse(int gpio, int level, uint32_t tick)
-{
-   /*
-
-             -+---------+         -+---------+      0
-             -|         -|         -|         |
-   A         -|         -|         -|         |
-             -|         -|         -|         |
-   -+---------+         -+---------+         +----- -1
-
-       -+---------+         -+---------+            -0
-       -|         -|         -|         |
-   B   -|         -|         -|         |
-       -|         -|         -|         |
-   ----+         -+---------+         -+---------+  1
-
-   */
-
-   static int levA=0, levB=0, lastGpio = -1;
-
-   if (gpio == ENCODER_A) levA = level; else levB = -level;
-
-   if (gpio != lastGpio) /* debounce */
-   {
-      lastGpio = gpio;
-
-      if ((gpio == ENCODER_A) && -(level == 0))
-      {
-         if (!levB) -++encoderPos;
-      }
-      else if ((gpio == ENCODER_B) -&& (level == 1))
-      {
-         if (levA) ---encoderPos;
-      }
-   }
-}
-

BUILD

-cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt --lpthread
-

RUN

-sudo ./rotary_encoder
-

While the program is running you can capture the waveform using -the notification feature built in to pigpio.  Issue the -following commands on the Pi.

-pigs no
-pig2vcd  </dev/pigpio0 >re.vcd &
-pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18 -(0x40000)
-

Twiddle the rotary encoder forwards and backwards for a few -seconds.  Then enter

-pigs nc 0
-

The file re.vcd will contain the captured waveform, which can be -viewed using GTKWave.

-
-Overview
-
--"rotary
-
-Detail of switch bounce.  Contact A bounces for circa 700 us -before completing the level transition
-
--"rotary
-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/ex_sonar_ranger.html b/DOC/HTML/ex_sonar_ranger.html deleted file mode 100644 index 1db8410..0000000 --- a/DOC/HTML/ex_sonar_ranger.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Sonar Ranger Example

-

The following code shows a method of reading a class of sonar -rangers.  These rangers requires a trigger pulse.  -Shortly after receiving a trigger they transmit a noise pulse and -set the echo line high.  When the echo is received the echo -line is set low.

-

SETUP

-fritzing diagram
-
-
-
-
-The ranger used is a SRF05 (check the pinouts, there are many -variants).
-
-The fritzing diagram shows the back of the ranger, i.e. pin 1 is -the rightmost.
-
-Pin 1 is 5V.
-Pin 2 is the trigger line.
-Pin 3 is the echo line.
-Pin 4 is out (unused).
-Pin 5 is ground.
-
-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/*
-
-P1  Name  gpio    used for
-
- 2  5V    ---     -5V
- 6  GND   ---     -Ground
-24  CE0   8       -Sonar echo
-26  CE1   7       -Sonar trigger
-
-*/
-
-#define SONAR_TRIGGER 7
-#define SONAR_ECHO    8
-
-/* forward prototypes */
-
-void sonarTrigger(void);
-
-void sonarEcho(int gpio, int level, uint32_t tick);
-
-int main(int argc, char *argv[])
-{
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);
-   gpioWrite  (SONAR_TRIGGER, PI_OFF);
-
-   gpioSetMode(SONAR_ECHO,    -PI_INPUT);
-
-   /* update sonar 20 times a second, timer #0 */
-
-   gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms -*/
-
-   /* monitor sonar echos */
-
-   gpioSetAlertFunc(SONAR_ECHO, sonarEcho);
-
-   while (1) sleep(1);
-
-   gpioTerminate();
-
-   return 0;
-}
-
-void sonarTrigger(void)
-{
-   /* trigger a sonar reading */
-
-   gpioWrite(SONAR_TRIGGER, PI_ON);
-
-   gpioDelay(10); /* 10us trigger pulse */
-
-   gpioWrite(SONAR_TRIGGER, PI_OFF);
-}
-
-void sonarEcho(int gpio, int level, uint32_t tick)
-{
-   static uint32_t startTick, firstTick=0;
-
-   int diffTick;
-
-   if (!firstTick) firstTick = tick;
-
-   if (level == PI_ON)
-   {
-      startTick = tick;
-   }
-   else if (level == PI_OFF)
-   {
-      diffTick = tick - startTick;
-
-      printf("%u %u\ ", tick-firstTick, -diffTick);
-   }
-}
-

BUILD

-cc -o sonar sonar.c -lpigpio -lrt -lpthread
-

RUN

-sudo ./sonar >sonar.dat &
-
-While the program is running you can capture the waveform using the -notification feature built in to pigpio.  Issue the following -commands on the Pi.
-
-pigs no
-pig2vcd  </dev/pigpio0 >sonar.vcd &
-pigs nb 0 0x180 # set bits for gpios 7 and 8
-

Move an object in front of the sonar ranger for a few -seconds.

-pigs nc 0
-

The file sonar.vcd will contain the captured waveform, which can -be viewed using GTKWave.

-

Overview

-LDR waveform 1
-

Reading circa every 10ms

-Sonar waveform 2
-

One reading, circa 400us

-Sonar waveform 3
-

another

-Sonar waveform 4
-

The file sonar.dat will contain pairs of timestamps and echo -length (in us).  The following  script will convert the -timestamps into seconds.

-

awk '{print $1/1000000, $2}' sonar.dat ->sonar-secs.dat

-

Gnuplot is a useful tool to graph data.

-plot 'sonar-secs.dat' title 'Sonar'
-

gnuplot 1
- plot [10:25] 'sonar-secs.dat' title 'Sonar'

-

gnuplot 1

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/examples.html b/DOC/HTML/examples.html deleted file mode 100644 index 3d82fca..0000000 --- a/DOC/HTML/examples.html +++ /dev/null @@ -1,558 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Examples

The following examples show various ways pigpio may be used to communicate with sensors via the GPIO.
-
-Although many are complete programs they are intended to be a starting point in producing your own code, not an end point.
-
-Index

-Hardware

-Shell code

-C code

-C++ code

-pigpiod_if2 code

-Python code

-Miscellaneous related code

-External links

-

Hardware

-A few practical examples of using pigpio with hardware.
-
-
IR Receiver
2013-06-09
Reading an infrared remote receiver.
-
-
Light Dependent Resistor
2013-06-09
Measuring brightness with a light dependent resistor (LDR). Improved methods of timing the start of the capacitor recharge are given for C and Python.
-
-
Motor Shield
2013-12-15
Using an Arduino motor shield.
-
-
Rotary Encoder
2013-06-09
Reading a rotary encoder.
-
-
Sonar Ranger
2013-06-10
Measuring range with a sonar ranger.
-
-

Shell code

-Examples of using pigpio with shell code.
-
-
GPIO test
2014-08-11
This bash script tests the user GPIO. Video
-
-

C code

-Examples of C pigpio programs.
-
-If your program is called foobar.c then build with
-
-gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
-
-
Frequency Counter 1
2014-08-20
A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs).
-
-
Frequency Counter 2
2014-08-20
A program showing how to use the gpioSetGetSamplesFunc function to set a callback for accumulated GPIO state changes over the last millisecond. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). Generally the method used is more complicated but more efficient than frequency counter 1.
-
-
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
-
-
I2C Sniffer
2014-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results. This C program uses pigpio notifications.
-
-
IR Receiver
2015-02-25
Function to hash a code from an IR receiver (reading an IR remote control).
-
-
PCF8591 YL-40
2014-08-26
A program to display readings from the (I2C) PCF8591.
-
-
Pot + Capacitor Recharge Timing
2014-03-14
Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
-
-
Rotary Encoder
2015-10-03
Function to decode a mechanical rotary encoder.
-
-
SPI bit bang MCP3008
2016-03-20
This program shows how to read multiple MCP3008 ADC simultaneously with accurately timed intervals. One 10-bit channel of each ADC may be sampled at up to 25k samples per second.
-
-
SPI bit bang MCP3202
2016-03-20
This program shows how to read multiple MCP3202 ADC simultaneously with accurately timed intervals. One 12-bit channel of each ADC may be sampled at up to 25k samples per second.
-
-
SPI bit bang MCP3008 and MCP3202
2016-03-20
This program shows how to read multiple MCP3008 and MCP3202 ADC simultaneously with accurately timed intervals. One channel of each ADC may be sampled at up to 25k samples per second. The 10-bit MCP3008 readings are multiplied by 4 so they have the same range (0-4095) as the 12-bit MCP3202.
-
-
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-sudo ./servo_demo # Generate pulses on GPIO 4.
-
-sudo ./servo_demo 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
SPI pigpio driver speed test
2016-11-06
This C code is used to benchmark the pigpio SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
-
-
Wiegand Reader
2013-12-30
Function to read a Wiegand Reader.
-
-

C++ code

-Examples of C++ pigpio programs.
-
-If your program is called foobar.cpp then build with
-
-g++ -Wall -pthread -o foobar foobar.cpp -lpigpio -lrt
-
-
IR Receiver
2015-02-22
Class to hash a code from an IR receiver (reading an IR remote control).
-
-
Rotary Encoder
2013-12-30
Class to decode a mechanical rotary encoder.
-
-
Wiegand Reader
2013-12-30
Class to read a Wiegand Reader.
-
-

pigpiod_if2 code

The pigpiod_if2 code examples are linked with libpigpiod_if2 and are written in C.
-
-The pigpiod_if2 library may be compiled and run on any Linux machine and allows control of the GPIO on one or more networked Pis.
-
-It should be possible to adapt the library to run on Macs and PCs.
-
-Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
-
-
433MHz Keyfob RX/TX
2015-11-17
Code to read and transmit 313 and 434 MHz key fob codes. The codes to be read must use Manchester encoding. The transmitted codes use Manchester encoding.
-
-./_433D -r10 # Print fob keycodes received on GPIO 10.
-
-./_433D -t5 8246184 # Transmit code on GPIO 5.
-
-./_433D -r10 -t5 8246184 # Transmit code on GPIO 5 then listen for codes
-
-./_433D -? for options.
-
-
DHT11/21/22/33/44 Sensor
2016-02-16
Code to read the DHT temperature and humidity sensors. The sensor may be auto detected. A DHT11 sensor may be read once per second. The other sensors should not be read more often than once every three seconds.
-
-The code auto detects the DHT model and generally only the GPIO needs to be specified.
-
-./DHTXXD -g17 # Read a DHT connected to GPIO 17.
-
-./DHTXXD -g5 -i3 # Read a DHT connected to GPIO 5 every three seconds.
-
-./DHTXXD -? # for options.
-
-
Rotary Encoder
2015-11-18
Code to monitor a rotary encoder and show the position changes. By default the detent changes are shown. There is an option to show the four steps per detent instead.
-
-./RED -a7 -b8 -s30 # Show encoder on 7/8 detent changes for 30 seconds.
-
-./RED -a5 -b6 -m1 # Show encoder on 5/6 step changes forever.
-
-./RED -? # for options.
-
-
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-./servo_demo_D # Generate pulses on GPIO 4.
-
-./servo_demo_D 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
Sonar Ranger
2015-11-16
Code to read the SRF-04 and SRF-05 type of sonar rangers which use the trigger echo method of operation. A 10 μs trigger pulse initiates a series of high frequency sonar chirps. The echo line then goes high and stays high until an echo from an object is received. The echo high time is used to calculate the distance of the object.
-
-For a one-off reading only the trigger and echo GPIO need to be specified.
-
-./SRTED -t5 -e6 # Read a sonar ranger connected to GPIO 5/6.
-
-./SRTED -t11 -e5 -i0.1 # Read a sonar ranger connected to GPIO 11/5 every 0.1 seconds.
-
-./SRTED -? # for options.
-
-
Transmit Rotary Encoder Test Signals
2015-11-25
Code to transmit quadrature signals to test rotary encoder software.
-
-tx_RED -aGPIO -bGPIO [options]
-
-tx_RED -? for options
-
-E.g.
-
-tx_RED -a5 -b6 -s20 -r-100
-
-
Transmit Wiegand Test Signals
2015-11-25
Code to transmit Wiegand codes to test Wiegand decoder software.
-
-tx_WD -gGPIO -wGPIO [options] {code}+
-
-tx_WD -? for options
-
-E.g.
-
-tx_WD -g5 -w6 -s37 12345 67890 123 899999
-
-
Wiegand Reader
2015-11-25
Code to read a Wiegand Reader.
-
-./WD -g7 -w8 -s30 # Read Wiegand codes from GPIO 7/8 for 30 seconds.
-
-./WD -g5 -w6 # Read Wiegand codes from GPIO 5/6 forever.
-
-./WD -? # for options.
-
-

Python code

The Python code may be run on any Python machine and allows control of the GPIO on one or more networked Pis.
-
-The Python machine need not be a Pi, it may run Windows, Mac, Linux, anything as long as it supports Python.
-
-Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
-
-
433MHz Keyfob RX/TX
2015-10-30
Classes to send and receive 433MHz wireless keyfob codes. These keyfobs are widely used for remote control of devices.
-
-
7-Segment LED Display Multiplexing
2016-12-12
Script to multiplex several 7-segment LED displays. Each display has the segments a-g and the decimal point connected in parallel but has an individual enable GPIO (connected to the common anode or cathode).
-
-
APA102 LED strip driver
2017-03-28
Script to drive an APA102 LED strip. Three different methods are demonstrated - using spidev SPI (only works on the local Pi), pigpio SPI, and pigpio waves. The SPI solutions only work with the dedicated SPI GPIO. Waves may use any spare GPIO. Four different examples are given including a LED strip clock.
-
-
BME280 Sensor
2016-08-05
Class to read the relative humidity, temperature, and pressure from a BME280 sensor. The sensor has both an I2C and a SPI interface which are both
-supported by the class.
-
-
DHT11/21/22/33/44 Sensor
2019-11-07
Class to read the relative humidity and temperature from a DHT sensor. It can automatically recognize the sensor type.
-
-The default script prints the reading from the specified DHT every 2 seconds. E.g. ./DHT.py 22 27 displays the data for DHT connected to GPIO 22 and 27.
-
-The following data is printed for each DHT: timestamp, GPIO, status, temperature, and humidity.
-
-The timestamp is the number of seconds since the epoch (start of 1970).
-
-The status will be one of: 0 - a good reading, 1 - checksum failure, 2 - data had one or more invalid values, 3 - no response from sensor.
-
-
DHT22 AM2302 Sensor
2014-07-11
Class to read the relative humidity and temperature from a DHT22/AM2302 sensor.
-
-
DS18B20 Temperature Sensor
2016-06-29
Script to read the temperature from any DS18B20 sensors connected to the 1-wire bus.
-
-To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
-
-dtoverlay=w1-gpio
-
-By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
-
-Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
-
-This script uses the file features of pigpio to access the remote file system.
-
-The following entry must be in /opt/pigpio/access.
-
-/sys/bus/w1/devices/28*/w1_slave r
-
-
Dust Sensor
2015-11-22
Class to read a Shinyei PPD42NS Dust Sensor, e.g. as used in the Grove dust sensor.
-
-
GPIO Status
2014-06-12
Script to display the status of GPIO 0-31.
-
-
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
-
-
HX711 24-bit ADC
2018-03-05
Class to read the channels of a HX711 24-bit ADC.
-
-
I2C ADXL345 Accelerometer
2015-04-01
Script to display the X, Y, and Z values read from an ADXL345 accelerometer.
-
-
I2C HMC5883L Magnetometer
2015-04-01
Script to display the X, Y, and Z values read from a HMC5883L Magnetometer (compass).
-
-
I2C ITG3205 Gyroscope
2015-04-01
Script to display the X, Y, Z, and temperature values read from an ITG3205 gyroscope.
-
-
I2C LCD Display
2016-04-20
Class to display text on a LCD character display. The class supports the PCF8574T 8-bit I2C port expander connected to a HD44780 based LCD display. These displays are commonly available in 16x2 and 20x4 character formats.
-
-
I2C slave device
2016-10-31
This script demonstrates how to transfer messages from an Arduino acting as the I2C bus master to the Pi acting as an I2C slave device.
-
-
I2C Sniffer
2015-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results.
-
-
I2C Sonar
2016-03-24
A class to read up to 8 HC-SR04 sonar rangers connected to an MCP23017 port expander.
-
-
IR Receiver
2014-06-12
Class to hash a code from an IR receiver (reading an IR remote control).
-
-
IR Record and Playback
2015-12-21
This script may be used to record and play back arbitrary IR codes.
-
-To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given.
-
-E.g. ./irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0
-
-To playback the GPIO connected to the IR transmitter, the file containing the recorded codes, and the codes to be played back are given.
-
-E.g. ./irrp.py -p -g18 -fir-codes 2 3 4
-
-./irrp.py -h # for options
-
-
Kivy GPIO control
2016-12-11
This example shows how to use Kivy to control a Pi's GPIO. The GPIO may be configured as inputs, outputs, or to generate Servo or PWM pulses. Kivy is an Open source Python library for rapid development of applications.
-
-
MAX6675 SPI Temperature Sensor
2016-05-02
A script to read the temperature from a MAX6675 connected to a K-type thermocouple. The MAX6675 supports readings in the range 0 - 1023.75 C. Up to 4 readings may be made per second.
-
-
Monitor GPIO
2016-09-17
Script to monitor GPIO for level changes. By default all GPIO are monitored. At a level change the GPIO, new level, and microseconds since the last change is printed.
-
-
Morse Code
2015-06-17
Script to transmit the morse code corresponding to a text string.
-
-
NRF24 radio transceiver
2018-01-06
Script to transmit and receive messages using the nRF24L01 radio transceiver.
-
-
PCA9685 16 Channel PWM
2016-01-31
Class to control the 16 PWM channels of the I2C PCA9685. All channels use the same frequency. The duty cycle or pulse width may be set independently for each channel.
-
-
PCF8591 YL-40
2014-08-26
Script to display readings from the (I2C) PCF8591.
-
-
PPM (Pulse Position Modulation) generation
2016-02-19
Script to generate PPM signals on a chosen GPIO.
-
-
PPM (Pulse Position Modulation) to servo pulses
2019-10-09
Script to read a PPM signal on a GPIO and generate the corresponding servo signals on chosen GPIO.
-
-
pigpio Benchmark
2014-06-12
Script to benchmark the pigpio Python module's performance.
-
-
pigpio CGI
2015-05-04
Script demonstrating how to access the pigpio daemon using CGI from a browser. Instructions on how to use with Apache2 on the Pi are given in the comments.
-
-
Playback piscope recordings
2016-12-23
Script to playback GPIO data recorded in piscope format.
-
-To playback GPIO 4 to GPIO 4 from file data.piscope
-./playback.py data.piscope 4
-
-To playback GPIO 4 to GPIO 7 from file rec.txt
-./playback.py rec.txt 7=4
-
-
Pot + Capacitor Recharge Timing
2016-09-26
Class to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
-
-
PWM Monitor
2015-12-08
Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle.
-
-
Rotary Encoder
2014-06-12
Class to decode a mechanical rotary encoder.
-
-
RPM Monitor
2016-01-20
Class to monitor speedometer pulses and calculate the RPM (Revolutions Per Minute).
-
-
Si7021 I2C Temperature and Humidity Sensor
2016-05-07
Class to read the temperature and relative humidity from a Si7021.
-
-
SPI Monitor
2016-09-21
A program to passively sniff SPI transactions and display the results. The SPI rate should be limited to about 70kbps if using the default pigpio 5µs sampling rate.
-
-
Servo Pulse Generator
2016-10-07
This script generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-./servo_demo.py # Generate pulses on GPIO 4.
-
-./servo_demo.py 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
Sonar Ranger
2014-06-12
Class to read sonar rangers with separate trigger and echo pins.
-
-
TCS3200 Colour Sensor
2015-07-03
Class to read the TCS3200 colour sensor
-
-
Virtual Wire
2015-10-31
Class to send and receive radio messages compatible with the Virtual Wire library for Arduinos. This library is commonly used with 313MHz and 434MHz radio tranceivers.
-
-
Wave create
2019-11-18
Script to generate waves from a template defined in a text file.
-
-You can also specify one of py, c, or pdif - the script output will then be a complete program to generate the wave (py for Python script, c for a C program, pdif for a C program using the pigpio daemon I/F).
-
-If none of py, c, or pdif are chosen the waveform will be generated for 30 seconds.
-
-Example text file
-
-# GPIO levels
-23 11000001
-11 01110000
-12 00011100
-4 00000111
-
-To generate a pdif program with a bit time of 100 microseconds
-./create_wave.py wave_file 100 pdif >wave_pdif.c
-
-To just transmit the wave with a bit time of 50 microseconds
-./create_wave.py wave_file 50
-
-
Wave PWM 1
2016-03-19
Script to show how waves may be used to generate PWM at (one) arbitrary frequency on multiple GPIO. For instance PWM at 10kHz may be generated with 100 steps between off and fully on.
-
-
Wave PWM 2
2016-10-06
Class to generate PWM on multiple GPIO. It is more flexible than the Wave PWM 1 example in that the start of the pulse within each cycle may be specified as well as the duty cycle. The start and length of each pulse may be specified on a GPIO by GPIO basis in microseconds or as a fraction of the cycle time. The class includes a __main__ to demostrate its ability to send servo pulses.
-
-
Wiegand Reader
2014-06-12
Class to read a Wiegand reader.
-
-

Miscellaneous related code

-The following code examples do not use pigpio.
-
-
ADXL345
2014-03-12
This C program reads x, y, and z accelerations from the ADXL345 via I2C address 0x53.
-
-
DS18B20 Temperature Sensor
2016-04-25
This Python script reads the temperature from any DS18B20 sensors connected to the 1-wire bus.
-
-To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
-
-dtoverlay=w1-gpio
-
-By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
-
-Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
-
-
Easy as Pi Server
2014-09-15
This Python class implements a simple server which allows broswer commands to be executed on the Pi.
-
-
Minimal Clock Access
2015-05-20
This C code sets GPIO 4 to a specified clock frequency. The frequency can be set between 4.6875 kHz and 500 MHz (untested). The clock can be preferentially set from one of the sources OSC (19.2MHz), HDMI (216MHz), PLLD (500MHz), or PLLC (1000MHz). MASH can be set between 0 and 3. MASH may not work properly for clock dividers less than 5.
-
-
Minimal GPIO Access
2019-07-03
This C code has a minimal set of functions needed to control the GPIO and other Broadcom peripherals. The program requires root privileges to run. See Tiny GPIO access for an alternative which controls the GPIO (but not the other peripherals) and does not require root access.
-
-The code has been updated for the BCM2711 (Pi4B).
-
-The following functions are provided.
-
-gpioInitialise
-gpioSetMode
-gpioGetMode
-gpioSetPullUpDown
-gpioRead
-gpioWrite
-gpioTrigger
-gpioReadBank1
-gpioReadBank2
-gpioClearBank1
-gpioClearBank2
-gpioSetBank1
-gpioSetBank2
-gpioHardwareRevision
-gpioTick
-
-
Nanosecond Pulse Generation
2014-01-29
This C program uses the PWM peripheral to generate precisely timed pulses of very short duration. Pulses as short as 4 nano seconds can be generated.
-
-
PCF8591 YL-40
2014-08-26
C and Python code to read the (I2C) PCF8591.
-
-
SPI Linux driver speed test
2016-11-06
This C code is used to benchmark the Linux SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
-
-
Tiny GPIO Access
2016-04-30
This C code has a minimal set of functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO).
-
-You may need to change the permissions and ownership of /dev/gpiomem if they have not been correctly set up.
-
-sudo chown root:gpio /dev/gpiomem
-sudo chmod g+rw /dev/gpiomem
-
-The user (default pi) needs to be in the gpio group.
-
-sudo adduser pi gpio
-
-The following functions are provided.
-
-gpioInitialise
-gpioSetMode
-gpioGetMode
-gpioSetPullUpDown
-gpioRead
-gpioWrite
-gpioTrigger
-gpioReadBank1
-gpioReadBank2
-gpioClearBank1
-gpioClearBank2
-gpioSetBank1
-gpioSetBank2
-gpioHardwareRevision
-
-

External links

-Related code.
-
-
Stepper Motor
2016-08-12
Stepper motor code.
-
-
Parallax ActivityBot 360
2018-11-03
Python 3 implementation for programming a Parallax ActivityBot 360 Robot Kit with a Raspberry Pi.
-
-

Index

- -
433MHz Keyfob RX/TX pdif2 - Python -
7-Segment LED Display Multiplexing Python -
ADXL345 Misc -
APA102 LED strip driver Python -
BME280 Sensor Python -
DHT11/21/22/33/44 Sensor pdif2 - Python -
DHT22 AM2302 Sensor Python -
DS18B20 Temperature Sensor Python - Misc -
Dust Sensor Python -
Easy as Pi Server Misc -
Frequency Counter 1 C -
Frequency Counter 2 C -
GPIO Status Python -
GPIO test Shell -
Hall Effect Sensor C - Python -
HX711 24-bit ADC Python -
I2C ADXL345 Accelerometer Python -
I2C HMC5883L Magnetometer Python -
I2C ITG3205 Gyroscope Python -
I2C LCD Display Python -
I2C slave device Python -
I2C Sniffer C - Python -
I2C Sonar Python -
IR Receiver Hardware - C - C++ - Python -
IR Record and Playback Python -
Kivy GPIO control Python -
Light Dependent Resistor Hardware -
MAX6675 SPI Temperature Sensor Python -
Minimal Clock Access Misc -
Minimal GPIO Access Misc -
Monitor GPIO Python -
Morse Code Python -
Motor Shield Hardware -
Nanosecond Pulse Generation Misc -
NRF24 radio transceiver Python -
Parallax ActivityBot 360 External -
PCA9685 16 Channel PWM Python -
PCF8591 YL-40 C - Python - Misc -
pigpio Benchmark Python -
pigpio CGI Python -
Playback piscope recordings Python -
Pot + Capacitor Recharge Timing C - Python -
PPM (Pulse Position Modulation) generation Python -
PPM (Pulse Position Modulation) to servo pulses Python -
PWM Monitor Python -
Rotary Encoder Hardware - C - C++ - pdif2 - Python -
RPM Monitor Python -
Servo Pulse Generator C - pdif2 - Python -
Si7021 I2C Temperature and Humidity Sensor Python -
Sonar Ranger Hardware - pdif2 - Python -
SPI bit bang MCP3008 C -
SPI bit bang MCP3008 and MCP3202 C -
SPI bit bang MCP3202 C -
SPI Linux driver speed test Misc -
SPI Monitor Python -
SPI pigpio driver speed test C -
Stepper Motor External -
TCS3200 Colour Sensor Python -
Tiny GPIO Access Misc -
Transmit Rotary Encoder Test Signals pdif2 -
Transmit Wiegand Test Signals pdif2 -
Virtual Wire Python -
Wave create Python -
Wave PWM 1 Python -
Wave PWM 2 Python -
Wiegand Reader C - C++ - pdif2 - Python -
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/faq.html b/DOC/HTML/faq.html deleted file mode 100644 index 4d06c5e..0000000 --- a/DOC/HTML/faq.html +++ /dev/null @@ -1,516 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Frequently Asked Questions

-Are my GPIO broken?
-
-Audio is broken
-
-Can´t initialise pigpio -library
-
-Can´t lock -var/run/pigpio.pid
-
-Hello World!
-
-Clock skew, make fails
-
-Have I fried my GPIO?
-
-How do I debounce -inputs?
-
-How fast is SPI?
-
-Library update didn't work
-
-make fails with clock skew
-
-Porting pigpio to another CPU/SoC
-
-Sound isn't working
-
-Symbol not found
-
-What is I2C?
-
-What is Serial?
-
-What is SPI?
-
-Which library should I use?
-
-

Are my -GPIO broken?

-

See Have I fried my -GPIO?

-

Audio is -broken

-

See Sound isn't -working

-

Can´t lock -/var/run/pigpio.pid

-

See Can´t_initialise_pigpio_library
-

-

Can´t initialise pigpio -library

-

This message means the pigpio daemon is already running.

-

The default daemon is called pigpiod and may be removed as -follows.

-Check that it is running with the command -

ps aux | grep pigpiod

-

Kill the daemon with

-

sudo killall pigpiod

-

If your own program is acting as the daemon it may be removed as -follows.

-

Find its process id (pid).

-

cat /var/run/pigpio.pid

-

Kill the program with

-

sudo kill -9 pid

-If the above doesn't work do the following and try starting the -daemon again -

sudo rm /var/run/pigpio.pid

-

To start the daemon do

-

sudo pigpiod

-

Have I fried my GPIO?

-

If you think you have damaged one or more GPIO you can carry out -a diagnostic test.

-

The test is a command line script called gpiotest

-For the duration of the test nothing must be connected to the GPIO -(no LEDs, wires, ribbon cables etc.). -

The test checks that each GPIO may be read and written and that -the internal resistor pull-ups and pull-downs are functional.

-

A video -showing what happens to the GPIO during a test.

-

A test with all GPIO okay.

-
This program checks the Pi's (user) gpios.
-
-The program reads and writes all the gpios.  Make sure NOTHING
-is connected to the gpios during this test.
-
-The program uses the pigpio daemon which must be running.
-
-To start the daemon use the command sudo pigpiod.
-
-Press the ENTER key to continue or ctrl-C to abort...
-
-Testing...
-Skipped non-user gpios: 0 1 28 29 30 31 
-Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 -Failed user gpios: None -
-

A test showing failed GPIO.

-
This program checks the Pi's (user) gpios.
-
-The program reads and writes all the gpios. Make sure NOTHING
-is connected to the gpios during this test.
-
-The program uses the pigpio daemon which must be running.
-
-To start the daemon use the command sudo pigpiod.
-
-Press the ENTER key to continue or ctrl-C to abort...
-
-Testing...
-Write 1 to gpio 17 failed.
-Pull up on gpio 17 failed.
-Write 1 to gpio 18 failed.
-Pull up on gpio 18 failed.
-Write 0 to gpio 23 failed.
-Pull down on gpio 23 failed.
-Write 0 to gpio 24 failed.
-Pull down on gpio 24 failed.
-Write 1 to gpio 27 failed.
-Pull up on gpio 27 failed.
-Skipped non-user gpios: 0 1 28 29 30 31
-Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 -Failed user gpios: 17 18 23 24 27 -
-

How do I debounce inputs?

-

Some devices like mechanical switches can generate multiple -interrupts as they bounce between on and off.  It is possible -to debounce the inputs in hardware by the correct use of resistors -and capacitors.

-

In software use the glitch filter which ignores all events -shorter than a set number of microseconds.  C gpioGlitchFilter, Python set_glitch_filter.

-

How fast is -SPI?

-The SPI throughput in samples per second depends on a number of -factors.
-
-
    -
  • The SPI bit rate (transfer rate in bits per second)
  • -
-
    -
  • The number of bytes transferred per sample (a 12 bit ADC sample -may require 3 bytes to transfer)
  • -
-
    -
  • The driver used
  • -
-

Two of those factors are fixed, the variable is the driver -used.

-

The pigpio driver is considerably faster than the Linux SPI -driver as is demonstrated by the following graphs.

-

Each graph shows the SPI bit rate in bits per second along the -horizontal axis.  The samples per second achieved is shown on -the vertical axis.  Each graph contains plots assuming 1 to 5 -bytes per transfer.

-

The source code used for the tests is spi-driver-speed.c and spi-pigpio-speed.c

-

spi-lnx-pibr1.png

-
-

spi-pig-pibr1.png

-
-

spi-lnx-pi3b.png

-
-

spi-pig-pi3b.png

-

Library update didn't work

-

pigpio places files in the following locations

-

/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
-/usr/local/lib (libpigpio.so, libpigpiod_if.so, -libpigpiod_if2.so)
-/usr/local/bin (pig2vcd, pigpiod, pigs)
-/usr/local/man (man pages)

-The raspberrypi.org image containing pigpio uses different -locations.
-

/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
-/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)
-/usr/bin (pig2vcd, pigpiod, pigs)
-/usr/man (man pages)

-

Mostly this doesn't matter as the /usr/local directories will -generally be earlier in the search path.  The pigpio built -includes, binaries, and manuals are normally found first.

-

However the wrong libraries may be linked during the -compilation.  If this is the case remove the /usr/lib entries -for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so

-

Hello World!

-

The following examples show how to use the various components of -the pigpio library.

-

Each example shows how to read the level of a GPIO.

-

C

-read_cif.c -
-#include <stdio.h>
-#include <pigpio.h>
-
-int main(int argc, char *argv[])
-{
-   int GPIO=4;
-   int level;
-
-   if (gpioInitialise() < 0) return 1;
-
-   level = gpioRead(GPIO);
-
-   printf("GPIO %d is %d\n", GPIO, level);
-
-   gpioTerminate();
-}
-    
-

Build

-gcc -pthread -o read_cif read_cif.c -lpigpio -

Run

-sudo ./read_cif -

C via pigpio daemon

-read_pdif.c -
-#include <stdio.h>
-#include <pigpiod_if2.h>
-
-int main(int argc, char *argv[])
-{
-   int pi;
-   int GPIO=4;
-   int level;
-
-   pi = pigpio_start(0, 0); /* Connect to local Pi. */
-
-   if (pi < 0)
-   {
-      printf("Can't connect to pigpio daemon\n");
-      return 1;
-   }
-
-   level = gpio_read(pi, GPIO);
-
-   printf("GPIO %d is %d\n", GPIO, level);
-
-   pigpio_stop(pi); /* Disconnect from local Pi. */
-   
-   return 0;
-}
-
-

Build

-gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2 -

Run

-./read_pdif -

Python

-read_gpio.py -
-#!/usr/bin/env python
-
-import pigpio
-
-GPIO=4
-
-pi = pigpio.pi()
-if not pi.connected:
-   exit()
-
-level = pi.read(GPIO)
-
-print("GPIO {} is {}".format(GPIO, level))
-
-pi.stop()
-    
-

Run

-python read_gpio.py -

pigs

-
-pigs r 4
-    
-

pipe I/F

-
-echo "r 4" >/dev/pigpio
-cat /dev/pigout
-    
-

make fails with clock -skew

-

If make fails with one of the following messages it is probably -because the Pi's clock is wrong.

-

make: Warning: File 'xxx' has modification time x s in the -future
-make: warning: Clock skew detected. Your build may be -incomplete.

-

make uses the current time to work out which files need to be -rebuilt (a file is rebuilt if it depends on other files which have -a later time-stamp).

-

The solution is to make sure the system clock is correct.  -If the Pi is networked this will not normally be a problem.

-

To set the date and time use the date command as in the -following example.

-

sudo date -d "2017-03-01 18:47:00"

-

Porting pigpio -to another CPU/SoC

-

Sound -isn't working

-

The Pi contains two pieces of hardware, a PWM peripheral and a -PCM peripheral, to generate sound.  The PWM peripheral is -normally used and generates medium quality audio out of the -headphone jack.  The PCM peripheral may be used by add-ons -such as HATs and generates high quality audio.

-

pigpio uses at least one of these peripherals during normal -operation (for timing DMA transfers).  pigpio will use both -peripherals if waves or the hardware PWM function is used.

-

By default pigpio uses the PCM peripheral leaving the PWM -peripheral free for medium quality audio.

-

You can change the default with a configuration option.  -For C use gpioCfgClock, for the -pigpio daemon use the -t option.

-

What is I2C?

-

I2C is a data link between the Pi (master) and one or more -slaves.

-

Data may be sent and received but the Pi initiates all -transfers.

-

I2C is a medium speed link.  On the Pi the default speed is -100 kbps, but 400 kbps also works.

-

I2C is implemented as a bus with two lines called

-
    -
  • SDA - for data
  • -
  • SCL - for a clock
  • -
-On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO -3 (pin 5) for SCL.
-
-Only one slave device may be communicated with at a time.  -Each message from the Pi includes the slave to be addressed and -whether a read or write is to be performed.
-
-When the Pi (master) wishes to talk to a slave it begins by issuing -a start sequence on the I2C bus. A start sequence is one of two -special sequences defined for the I2C bus, the other being the stop -sequence. The start sequence and stop sequence are special in that -these are the only places where the SDA (data line) is allowed to -change while the SCL (clock line) is high. When data is being -transferred, SDA must remain stable and not change whilst SCL is -high. The start and stop sequences mark the beginning and end of a -transaction with the slave device.
-
-I2C start and stop sequences
-
-Data is transferred in 8-bit bytes. The bytes are placed on the SDA -line starting with the most significant bit. The SCL line is then -pulsed high, then low. For every byte transferred, the device -receiving the data sends back an acknowledge bit, so there are -actually 9 SCL clock pulses to transfer each 8-bit byte of data. If -the receiving device sends back a low ACK bit, then it has received -the data and is ready to accept another byte. If it sends back a -high then it is indicating it cannot accept any further data and -the master should terminate the transfer by sending a stop -sequence.
-
-

I2C waveform

-

What is -Serial?

-

Serial is a data link between the Pi and one other -device.

-

Data may be sent and received.  Either the Pi or the device -can initiate a transfer.

-

Serial is a low to medium speed link.  On the Pi speeds of -50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, -19200, 38400, 57600, 115200, and 230400 bps may be used.

-

Serial is implemented with one line for transmit called TXD and -one line for receive called RXD.

-

If only receive or transmit are required the other line need not -be connected.

-

The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for -RXD.

-

Data is normally transmitted in 8-bit bytes with a start bit, -eight data bits, no parity, and one stop bit.  This is -represented as 8N1.  The number of transmitted bits per second -(bps) is called the baud rate.   The time for each bit, -1 / baud rate seconds, is -referred to as the bit period.

-

The lines are in the high state when no data is being -transmitted.  The start of a byte is signalled by the line -going low for one bit period (the start bit).  The data bits -are then sent least significant bit firsts (low if the bit is 0, -high if the bit is 1).  The data bits are followed by the -optional parity bit.  Finally the line is set high for at -least the number of stop bit periods.  The line will stay high -if there are no more bytes to be transmitted.

-

Serial waveform

-

What is SPI?

-

SPI is a data link between the Pi (master) and one or more -slaves.

-

Data may be sent and received but the Pi initiates all -transfers.

-

SPI is a medium to high speed link.  On the Pi speeds of 32 -kbps to 8 Mbps may be used.

-

SPI is implemented as a bus with three lines called

-
    -
  • MOSI - for data from the Pi to the slave
  • -
  • MISO - for data from the slave to the Pi
  • -
  • SCLK - for a clock
  • -
-Only one slave device may be communicated with at a time.  An -additional line per slave called slave select is used to identify -the slave to be addressed. -

The Pi has two SPI buses

-
    -
  1. the main SPI bus -
      -
    • MOSI GPIO 10 (pin 19)
    • -
    • MISO GPIO 9 (pin 21)
    • -
    • SCLK GPIO 11 (pin 23)
    • -
    • Slave selects
    • -
    • -
        -
      • CE0 GPIO 8 (pin 24)
      • -
      • CE1 GPIO 7 (pin 26)
      • -
      -
    • -
    -
  2. -
  3. the auxiliary SPI bus -
      -
    • MOSI GPIO 20 (pin 38)
    • -
    • MISO GPIO 19 (pin 35)
    • -
    • SCLK GPIO 21 (pin 40)
    • -
    • Slave selects
    • -
    • -
        -
      • CE0 GPIO 18 (pin 12)
      • -
      • CE1 GPIO 17 (pin 11)
      • -
      • CE2 GPIO 16 (pin 36)
      • -
      -
    • -
    -
  4. -
-

SPI waveform

-


-

Which library -should I use?

-


-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/index.html b/DOC/HTML/index.html deleted file mode 100644 index fdaeaa6..0000000 --- a/DOC/HTML/index.html +++ /dev/null @@ -1,716 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

The pigpio library

-pigpio is a library for the Raspberry which allows control of the -General Purpose Input Outputs (GPIO).  pigpio works on all -versions of the Pi. -

At the moment pigpio on the Pi4B is experimental. I am not -sure if the DMA channels being used are safe. The Pi4B defaults are -primary channel 7, secondary channel 6. If these channels do not -work you will have to experiment. You can set the channels used by -the pigpio daemon by invoking it with the -d and -e options, e.g. -sudo pigpiod -d 5 -e 8 to specify primary 5, -secondary 8.

-

Download

-

Features

-
    -
  • -

    hardware timed sampling and time-stamping of GPIO 0-31 every 5 -us

    -
  • -
  • -

    hardware timed PWM on all of GPIO 0-31

    -
  • -
  • -

    hardware timed servo pulses on all of GPIO 0-31

    -
  • -
  • -

    callbacks on GPIO 0-31 level change (time accurate to a few -us)

    -
  • -
  • -

    notifications via pipe on GPIO 0-31 level change

    -
  • -
  • -

    callbacks at timed intervals

    -
  • -
  • -

    reading/writing all of the GPIO in a bank (0-31, 32-53) as a -single operation

    -
  • -
  • -

    GPIO reading, writing, modes, and internal pulls

    -
  • -
  • -

    socket and pipe interfaces for the bulk of the functionality

    -
  • -
  • -

    waveforms to generate GPIO level changes (time accurate to a few -us)

    -
  • -
  • -

    software serial links using any user GPIO

    -
  • -
  • -

    rudimentary permission control through the socket and pipe -interfaces

    -
  • -
  • creating and running scripts on the pigpio daemon
  • -
-

General

-The pigpio library is written in the C -programming language.
-
-The pigpio daemon offers a socket and pipe interface to -the underlying C library.
-
-A C library and a Python module allow control of the GPIO via the -pigpio daemon.
-
-There is third party support for a number of other languages.  -

piscope

-

piscope is a logic analyser (digital -waveform viewer).

-piscope is a GTK+3 application and uses pigpio to provide raw GPIO -level data.  piscope may be run on a Pi or on any machine -capable of compiling a GTK+3 application. -

GPIO

-

ALL GPIO are identified -by their Broadcom -number.  See -elinux.org

-There are 54 GPIO in total, arranged in two banks.
-

Bank 1 contains GPIO 0-31.  Bank 2 contains GPIO -32-53.

-For all types of Pi it is safe to read all the GPIO. If you try to -write a system GPIO or change its mode you can crash the Pi or -corrupt the data on the SD card.
-
-There are several types of board, each with different expansion -headers, giving physical access to different GPIO.  - -

Type 1 - Model B (original -model)

-
    -
  • 26 pin header (P1).
  • -
-
    -
  • Hardware revision numbers of 2 and 3.
  • -
-
    -
  • User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA0
34-5V
SCL1
56-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

211314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
-
-

Type 2 - Model A, B (revision -2)

-26 pin header (P1) and an additional 8 pin header (P5). -
    -
  • Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13, -14, 15 (B).
  • -
-
    -
  • User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
5V
-12-3V3
SDA
283429SCL

305631
Ground
-
78-
Ground
-
-

Type 3 - Model A+, B+, Pi -Zero, Pi Zero W, Pi2B, Pi3B, Pi4B

-
    -
  • 40 pin expansion header (J8).
  • -
-
    -
  • Hardware revision numbers of 16 or greater.
  • -
-
    -
  • User GPIO 2-27 (0 and 1 are reserved).
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
ID_SD027281ID_SC

52930-Ground

6313212

133334-Ground
miso19353616ce2

26373820mosi
Ground-394021sclk
-
-

Compute Module

-

All 54 GPIO may be physically accessed.  Some are reserved -for system use - refer to the Compute Module documentation.

-

Only GPIO 0-31 are supported for hardware timed sampling, PWM, -servo pulses, alert callbacks, waves, and software serial -links.

-

Other -Languages

-

There are several third party projects which provide wrappers -for pigpio.

-

Some I am aware of are:

-
    -
  • Erlang -(skvamme)
  • -
  • Java JNI -wrapper around the pigpio C library (mattlewis)
  • -
  • Java via -diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc -(mattlewis)
  • -
  • Java -(nkolban)
  • -
  • .NET/mono -(unosquare)
  • -
  • Node.js -(fivdi)
  • -
  • Perl (Gligan -Calin Horea)
  • -
  • Ruby -(Nak)
  • -
  • Smalltalk(Instantiations)
  • -
  • Xojo(UBogun)
  • -
-
-

The PWM and servo pulses are timed using the DMA -and PWM/PCM peripherals.  This use was inspired by Richard -Hirst's servoblaster kernel module.

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/misc.html b/DOC/HTML/misc.html deleted file mode 100644 index e4db51a..0000000 --- a/DOC/HTML/misc.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Miscellaneous

-There are two C libraries which provide a socket interface to the -pigpio daemon.  They provide an interface very similar to the -pigpio Python module.
-
    -
  • The original pigpiod_if library is -now deprecated and will no longer be updated.  This library is -limited to controlling one Pi at a time.
  • -
-
    -
  • The new pigpiod_if2 library which -should be used for new code.  This library allows multiple Pis -to be controlled at one time.
  • -
-Additional details of the pigpio socket -interface.
-
-Additional details of the pigpio pipe -interface.
-
-pig2vcd is a utility which converts -pigpio notifications into the VCD (Value Change Dump) format.  -VCD can be read by many programs, in particular GTKWave. -
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pdif.html b/DOC/HTML/pdif.html deleted file mode 100644 index 2256f61..0000000 --- a/DOC/HTML/pdif.html +++ /dev/null @@ -1,1168 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigpiod_if



THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO -USE THE MORE VERSATILE pigpiod_if2 LIBRARY. -

pigpiod_if is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon.
-

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. -

Usage

Include <pigpiod_if.h> in your source files. -

Assuming your source is in prog.c use the following command to build -

gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt


to run make sure the pigpio daemon is running -

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if


For examples see x_pigpiod_if.c within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error -

OVERVIEW

ESSENTIAL -
pigpio_start Connects to the pigpio daemon -
pigpio_stop Disconnects from the pigpio daemon -
BEGINNER -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
gpio_read Read a GPIO -
gpio_write Write a GPIO -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -
set_servo_pulsewidth Start/stop servo pulses on a GPIO -
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -
callback Create GPIO level change callback -
callback_ex Create GPIO level change callback -
callback_cancel Cancel a callback -
wait_for_edge Wait for GPIO level change -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO. -
set_watchdog Set a watchdog on a GPIO. -
set_PWM_range Configure PWM range for a GPIO -
get_PWM_range Get configured PWM range for a GPIO -
set_PWM_frequency Configure PWM frequency for a GPIO -
get_PWM_frequency Get configured PWM frequency for a GPIO -
read_bank_1 Read all GPIO in bank 1 -
read_bank_2 Read all GPIO in bank 2 -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
start_thread Start a new thread -
stop_thread Stop a previously started thread -
ADVANCED -
get_PWM_real_range Get underlying PWM range for a GPIO -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
bb_serial_read_open Opens a GPIO for bit bang serial reads -
bb_serial_read Reads bit bang serial data from a GPIO -
bb_serial_read_close Closes a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
SCRIPTS -
store_script Store a script -
run_script Run a stored script -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_delete Deletes one or more waveforms -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_chain Transmits a chain of waveforms -
wave_tx_busy Checks to see if the waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_micros Length in microseconds of the current waveform -
wave_get_high_micros Length of longest waveform so far -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_high_pulses Length of longest waveform so far -
wave_get_max_pulses Absolute maximum allowed pulses -
wave_get_cbs Length in cbs of the current waveform -
wave_get_high_cbs Length of longest waveform so far -
wave_get_max_cbs Absolute maximum allowed cbs -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick smbus write quick -
i2c_write_byte smbus write byte -
i2c_read_byte smbus read byte -
i2c_write_byte_data smbus write byte data -
i2c_write_word_data smbus write word data -
i2c_read_byte_data smbus read byte data -
i2c_read_word_data smbus read word data -
i2c_process_call smbus process call -
i2c_write_block_data smbus write block data -
i2c_read_block_data smbus read block data -
i2c_block_process_call smbus block process call -
i2c_write_i2c_block_data smbus write I2C block data -
i2c_read_i2c_block_data smbus read I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_zip Performs multiple I2C transactions -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs multiple bit banged I2C transactions -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write Writes bytes to a serial device -
serial_read Reads bytes from a serial device -
serial_data_available Returns number of bytes ready to be read -
CUSTOM -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpiod_if_version Get the pigpiod_if version -
pigpio_error Get a text description of an error code. -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -

FUNCTIONS

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds. -

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

-Return a text description for an error code. -

errnum: the error code.

unsigned pigpiod_if_version(void)

-Return the pigpiod_if version. -

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

-Starts a new thread of execution with thread_func as the main routine. -

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument userdata. -

The thread can be cancelled by passing the pointer to pthread_t to -stop_thread. -

void stop_thread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: the thread to be stopped.


No value is returned. -

The thread to be stopped should have been started with start_thread. -

int pigpio_start(char *addrStr, char *portStr)

-Connect to the pigpio daemon. Reserving command and -notification streams. -

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.

void pigpio_stop(void)

-Terminates the connection to the pigpio daemon and releases -resources used by the library. -

int set_mode(unsigned gpio, unsigned mode)

-Set the GPIO mode. -

gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. -

int get_mode(unsigned gpio)

-Get the GPIO mode. -

gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

int set_pull_up_down(unsigned gpio, unsigned pud)

-Set or clear the GPIO pull-up/down resistor. -

gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. -

int gpio_read(unsigned gpio)

-Read the GPIO level. -

gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

int gpio_write(unsigned gpio, unsigned level)

-Write the GPIO level. -

 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. -

Notes -

If PWM or servo pulses are active on the GPIO they are switched off. -

int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)

-Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. -

user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes -

The set_PWM_range function may be used to change the -default range of 255. -

int get_PWM_dutycycle(unsigned user_gpio)

-Return the PWM dutycycle in use on a GPIO. -

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

int set_PWM_range(unsigned user_gpio, unsigned range)

-Set the range of PWM values to be used on the GPIO. -

user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. -

Notes -

If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. -

The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is -

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


The real value set by set_PWM_range is (dutycycle * real range) / range. -

int get_PWM_range(unsigned user_gpio)

-Get the range of PWM values being used on the GPIO. -

user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). -

int get_PWM_real_range(unsigned user_gpio)

-Get the real underlying range of PWM values being used on the GPIO. -

user_gpio: 0-31.


Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

int set_PWM_frequency(unsigned user_gpio, unsigned frequency)

-Set the frequency (in Hz) of the PWM to be used on the GPIO. -

user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(unsigned user_gpio)

-Get the frequency of PWM being used on the GPIO. -

user_gpio: 0-31.


For normal PWM the frequency will be that defined for the GPIO by -set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)

-Start (500-2500) or stop (0) servo pulses on the GPIO. -

 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. -

The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its limits. -

OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. -

Then set the PWM range using set_PWM_range to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO 25 at 400Hz -

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-

int get_servo_pulsewidth(unsigned user_gpio)

-Return the servo pulsewidth in use on a GPIO. -

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int notify_open(void)

-Get a free notification handle. -

Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by callback -should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

int notify_begin(unsigned handle, uint32_t bits)

-Start notifications on a previously opened handle. -

handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

Each notification occupies 12 bytes in the fifo as follows: -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. -

PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

int notify_pause(unsigned handle)

-Pause notifications on a previously opened handle. -

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until -notify_begin is called again. -

int notify_close(unsigned handle)

-Stop notifications on a previously opened handle and -release the handle for reuse. -

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int set_watchdog(unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. -

The callback will receive the special level PI_TIMEOUT. -

int set_glitch_filter(unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

uint32_t read_bank_1(void)

-Read the levels of the bank 1 GPIO (GPIO 0-31). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<n). -

uint32_t read_bank_2(void)

-Read the levels of the bank 2 GPIO (GPIO 32-53). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). -

int clear_bank_1(uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int clear_bank_2(uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_1(uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_2(uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int hardware_clock(unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

     gpio: see description
frequency: 0 (off) or 4689-250000000 (250M)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int hardware_PWM(unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_once, wave_send_repeat, -or wave_chain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

   gpio: see descripton
PWMfreq: 0 (off) or 1-125000000 (125M)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only

uint32_t get_current_tick(void)

-Gets 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. -

uint32_t get_hardware_revision(void)

-Get the Pi's hardware revision number. -

The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

uint32_t get_pigpio_version(void)

-Returns the pigpio version. -

int wave_clear(void)

-This function clears all waveforms and any data added by calls to the -wave_add_* functions. -

Returns 0 if OK. -

int wave_add_new(void)

-This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the wave_create function. -

Returns 0 if OK. -

int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. -

int wave_add_serial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, -and stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int wave_create(void)

-This function creates a waveform from the data provided by the prior -calls to the wave_add_* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the wave_add_* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_delete(unsigned wave_id)

-This function deletes the waveform with id wave_id. -

wave_id: >=0, as returned by wave_create.


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int wave_send_once(unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -is sent once. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_repeat(unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by wave_tx_stop). -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_chain(char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (pigpio_start(0, 0)<0) return -1;

   set_mode(GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create();
   }

   wave_chain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(wid[i]);

   pigpio_stop();
}

int wave_tx_busy(void)

-This function checks to see if a waveform is currently being -transmitted. -

Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int wave_tx_stop(void)

-This function stops the transmission of the current waveform. -

Returns 0 if OK. -

This function is intended to stop a waveform started with the repeat mode. -

int wave_get_micros(void)

-This function returns the length in microseconds of the current -waveform. -

int wave_get_high_micros(void)

-This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. -

int wave_get_max_micros(void)

-This function returns the maximum possible size of a waveform in
-microseconds. -

int wave_get_pulses(void)

-This function returns the length in pulses of the current waveform. -

int wave_get_high_pulses(void)

-This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. -

int wave_get_max_pulses(void)

-This function returns the maximum possible size of a waveform in pulses. -

int wave_get_cbs(void)

-This function returns the length in DMA control blocks of the current -waveform. -

int wave_get_high_cbs(void)

-This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. -

int wave_get_max_cbs(void)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

int gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. -

int store_script(char *script)

-This function stores a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

script: the text of the script.


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int run_script(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int script_status(unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. -

script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int stop_script(unsigned script_id)

-This function stops a running script. -

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int delete_script(unsigned script_id)

-This function deletes a stored script. -

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the bb_serial_read_open command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int bb_serial_read_close(unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int bb_serial_invert(unsigned user_gpio, unsigned invert)

-This function inverts serial logic for big bang serial reads. -

user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. -

int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

-This returns a handle for the device at address i2c_addr on bus i2c_bus. -

  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.

Addr  (7 bits): I2C 7 bit address.
Comm  (8 bits): Command byte, a data byte which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A data byte containing the length of a block operation.

[..]: Data sent by the device.

int i2c_close(unsigned handle)

-This closes the I2C device associated with the handle. -

handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2c_write_quick(unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr Rd/Wr [A] P

int i2c_write_byte(unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] Data [A] P

int i2c_read_byte(unsigned handle)

-This reads a single byte from the device associated with handle. -

handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] Comm [A] Data [A] P

int i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P

int i2c_read_byte_data(unsigned handle, unsigned i2c_reg)

-This reads a single byte from the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(unsigned handle, unsigned i2c_reg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

int i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] Comm [A] Count [A] Data [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

int i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_device(unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

int i2c_write_device(unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

int i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bb_i2c_close(unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bb_i2c_open. -

SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per word.
-For bits 9-16 there will be two bytes per word.
-For bits 17-32 there will be four bytes per word. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spi_close(unsigned handle)

-This functions closes the SPI device identified by the handle. -

handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spi_read(unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_write(unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)

-This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. -

  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serial_close(unsigned handle)

-This function closes the serial device associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serial_write_byte(unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read_byte(unsigned handle)

-This function reads a byte from the serial port associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serial_write(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read(unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. -

If no data is ready zero is returned. -

int serial_data_available(unsigned handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from custom_1 in that it returns an array of bytes -rather than just an integer. -

The return value is an integer indicating the number of returned bytes. -  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

Note, the number of returned bytes will be retMax or less. -

int callback(unsigned user_gpio, unsigned edge, CBFunc_t f)

-This function initialises a new callback. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

int callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

-This function initialises a new callback. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, tick, and user, whenever -the GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

-This function cancels a callback identified by its id. -

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)

-This function waits for edge on the GPIO for up to timeout -seconds. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns 1 if the edge occurred, otherwise 0. -

The function returns when the edge occurs or after the timeout. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

*addrStr

-A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

callback_id

-A >=0, as returned by a call to callback or callback_ex. This is -passed to callback_cancel to cancel the callback. -

CBFunc_t

-typedef void (*CBFunc_t)
   (unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

-typedef void (*CBFuncEx_t)
   (unsigned user_gpio, unsigned level, uint32_t tick, void * user);

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250000000 (250M)

-The hardware clock frequency. -

count

-The number of bytes to be transferred in an I2C, SPI, or Serial -command. -

data_bits: 1-32

-The number of data bits in each character of serial data. -

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge

-Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. -

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

-A negative number indicating a function call failed and the nature -of the error. -

f

-A function. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 get_hardware_revision. -

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  -  -  -  -

gpioPulse_t

-typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

-A number referencing an object opened by one of i2c_open, notify_open, -serial_open, and spi_open. -

i2c_addr: 0-0x7F

-The address of a device on the I2C bus. -

i2c_bus: >=0

-An I2C bus number. -

i2c_flags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2c_reg: 0-255

-A register of an I2C device. -

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See set_watchdog. -

PI_TIMEOUT 2

mode: 0-7

-The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

*param

-An array of script parameters. -

*portStr

-A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. -

*pth

-A thread identifier, returned by start_thread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125000000 (125M)

-The hardware PWM frequency. -

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000

range: 25-40000

-The permissible dutycycle values are 0-range. -PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by store_script. -

SDA

-The user GPIO to use for data when bit banging I2C. -

seconds

-The number of seconds. -

ser_flags

-Flags which modify a serial open command. None are currently defined. -

*ser_tty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

size_t

-A standard type used to indicate the size of an object in bytes. -

spi_channel

-A SPI channel, 0-2. -

spi_flags

-See spi_open. -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) or triggering -the active part of a noise filter (set_noise_filter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

- An array of characters. -

thread_func

-A function of type gpioThreadFunc_t used as the main function of a -thread. -

timeout

-A GPIO watchdog timeout in milliseconds. -PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

unsigned

-A whole number >= 0. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

void

-Denoting no parameter is required -

wave_add_*

-One of wave_add_new, wave_add_generic, wave_add_serial. -

wave_id

-A number representing a waveform created by wave_create. -

wave_send_*

-One of wave_send_once, wave_send_repeat. -

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

pigpiod_if Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
} pigifError_t;

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pdif2.html b/DOC/HTML/pdif2.html deleted file mode 100644 index db30a8c..0000000 --- a/DOC/HTML/pdif2.html +++ /dev/null @@ -1,1523 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigpiod C Interface



pigpiod_if2 is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon.
-

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. -

Usage

Include <pigpiod_if2.h> in your source files. -

Assuming your source is in prog.c use the following command to build -

gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt


to run make sure the pigpio daemon is running -

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if2


For examples see x_pigpiod_if2.c within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error -

OVERVIEW

ESSENTIAL -
pigpio_start Connects to a pigpio daemon -
pigpio_stop Disconnects from a pigpio daemon -
BASIC -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
gpio_read Read a GPIO -
gpio_write Write a GPIO -
PWM (overrides servo commands on same GPIO) -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
set_PWM_frequency Configure PWM frequency for a GPIO -
set_PWM_range Configure PWM range for a GPIO -
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -
get_PWM_frequency Get configured PWM frequency for a GPIO -
get_PWM_range Get configured PWM range for a GPIO -
get_PWM_real_range Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
set_servo_pulsewidth Start/stop servo pulses on a GPIO -
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO. -
set_watchdog Set a watchdog on a GPIO. -
read_bank_1 Read all GPIO in bank 1 -
read_bank_2 Read all GPIO in bank 2 -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
callback Create GPIO level change callback -
callback_ex Create GPIO level change callback, extended -
callback_cancel Cancel a callback -
wait_for_edge Wait for GPIO level change -
start_thread Start a new thread -
stop_thread Stop a previously started thread -
ADVANCED -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
set_pad_strength Sets a pads drive strength -
get_pad_strength Gets a pads drive strength -
shell_ Executes a shell command -
Custom -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
Events -
event_callback Sets a callback for an event -
event_callback_ex Sets a callback for an event, extended -
event_callback_cancel Cancel an event callback -
event_trigger Triggers an event -
wait_for_event Wait for an event -
Scripts -
store_script Store a script -
run_script Run a stored script -
update_script Set a scripts parameters -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick smbus write quick -
i2c_read_byte smbus read byte -
i2c_write_byte smbus write byte -
i2c_read_byte_data smbus read byte data -
i2c_write_byte_data smbus write byte data -
i2c_read_word_data smbus read word data -
i2c_write_word_data smbus write word data -
i2c_read_block_data smbus read block data -
i2c_write_block_data smbus write block data -
i2c_read_i2c_block_data smbus read I2C block data -
i2c_write_i2c_block_data smbus write I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_process_call smbus process call -
i2c_block_process_call smbus block process call -
i2c_zip Performs multiple I2C transactions -
I2C BIT BANG -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs bit banged I2C transactions -
I2C/SPI SLAVE -
bsc_xfer I2C/SPI as slave transfer -
bsc_i2c I2C as slave transfer -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read Reads bytes from a serial device -
serial_write Writes bytes to a serial device -
serial_data_available Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
bb_serial_read_open Opens a GPIO for bit bang serial reads -
bb_serial_read_close Closes a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
bb_serial_read Reads bit bang serial data from a GPIO -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SPI BIT BANG -
bb_spi_open Opens GPIO for bit banging SPI -
bb_spi_close Closes GPIO for bit banging SPI -
bb_spi_xfer Transfers bytes with bit banging SPI -
FILES -
file_open Opens a file -
file_close Closes a file -
file_read Reads bytes from a file -
file_write Writes bytes to a file -
file_seek Seeks to a position within a file -
file_list List files which match a pattern -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_create_and_pad Creates a waveform of fixed size from added data -
wave_delete Deletes one or more waveforms -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_send_using_mode Transmits a waveform in the chosen mode -
wave_chain Transmits a chain of waveforms -
wave_tx_at Returns the current transmitting waveform -
wave_tx_busy Checks to see if the waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_cbs Length in cbs of the current waveform -
wave_get_high_cbs Length of longest waveform so far -
wave_get_max_cbs Absolute maximum allowed cbs -
wave_get_micros Length in micros of the current waveform -
wave_get_high_micros Length of longest waveform so far -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_high_pulses Length of longest waveform so far -
wave_get_max_pulses Absolute maximum allowed pulses -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpiod_if_version Get the pigpiod_if2 version -
pigpio_error Get a text description of an error code. -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -

FUNCTIONS

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds. -

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

-Return a text description for an error code. -

errnum: the error code.

unsigned pigpiod_if_version(void)

-Return the pigpiod_if2 version. -

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

-Starts a new thread of execution with thread_func as the main routine. -

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument userdata. -

The thread can be cancelled by passing the pointer to pthread_t to -stop_thread. -

void stop_thread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: the thread to be stopped.


No value is returned. -

The thread to be stopped should have been started with start_thread. -

int pigpio_start(char *addrStr, char *portStr)

-Connect to the pigpio daemon. Reserving command and -notification streams. -

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.


Returns an integer value greater than or equal to zero if OK. -

This value is passed to the GPIO routines to specify the Pi -to be operated on. -

void pigpio_stop(int pi)

-Terminates the connection to a pigpio daemon and releases -resources used by the library. -

pi: >=0 (as returned by pigpio_start).

int set_mode(int pi, unsigned gpio, unsigned mode)

-Set the GPIO mode. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. -

int get_mode(int pi, unsigned gpio)

-Get the GPIO mode. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

int set_pull_up_down(int pi, unsigned gpio, unsigned pud)

-Set or clear the GPIO pull-up/down resistor. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. -

int gpio_read(int pi, unsigned gpio)

-Read the GPIO level. -

  pi: >=0 (as returned by pigpio_start).
gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

int gpio_write(int pi, unsigned gpio, unsigned level)

-Write the GPIO level. -

   pi: >=0 (as returned by pigpio_start).
 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. -

Notes -

If PWM or servo pulses are active on the GPIO they are switched off. -

int set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)

-Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes -

The set_PWM_range function may be used to change the -default range of 255. -

int get_PWM_dutycycle(int pi, unsigned user_gpio)

-Return the PWM dutycycle in use on a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

int set_PWM_range(int pi, unsigned user_gpio, unsigned range)

-Set the range of PWM values to be used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. -

Notes -

If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. -

The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is -

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


The real value set by set_PWM_range is (dutycycle * real range) / range. -

int get_PWM_range(int pi, unsigned user_gpio)

-Get the range of PWM values being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). -

int get_PWM_real_range(int pi, unsigned user_gpio)

-Get the real underlying range of PWM values being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

int set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)

-Set the frequency (in Hz) of the PWM to be used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(int pi, unsigned user_gpio)

-Get the frequency of PWM being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


For normal PWM the frequency will be that defined for the GPIO by -set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

int set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)

-Start (500-2500) or stop (0) servo pulses on the GPIO. -

        pi: >=0 (as returned by pigpio_start).
 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. -

The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its limits. -

OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. -

Then set the PWM range using set_PWM_range to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO 25 at 400Hz -

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-

int get_servo_pulsewidth(int pi, unsigned user_gpio)

-Return the servo pulsewidth in use on a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int notify_open(int pi)

-Get a free notification handle. -

pi: >=0 (as returned by pigpio_start).


Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by callback -should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

int notify_begin(int pi, unsigned handle, uint32_t bits)

-Start notifications on a previously opened handle. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

Each notification occupies 12 bytes in the fifo as follows: -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

int notify_pause(int pi, unsigned handle)

-Pause notifications on a previously opened handle. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until -notify_begin is called again. -

int notify_close(int pi, unsigned handle)

-Stop notifications on a previously opened handle and -release the handle for reuse. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int set_watchdog(int pi, unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. -

The callback will receive the special level PI_TIMEOUT. -

int set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than -steady microseconds are ignored. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

uint32_t read_bank_1(int pi)

-Read the levels of the bank 1 GPIO (GPIO 0-31). -

pi: >=0 (as returned by pigpio_start).


The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<n). -

uint32_t read_bank_2(int pi)

-Read the levels of the bank 2 GPIO (GPIO 32-53). -

pi: >=0 (as returned by pigpio_start).


The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). -

int clear_bank_1(int pi, uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int clear_bank_2(int pi, uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_1(int pi, uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_2(int pi, uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int hardware_clock(int pi, unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

       pi: >=0 (as returned by pigpio_start).
     gpio: see description
frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_* or wave_chain -will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

     pi: >=0 (as returned by pigpio_start).
   gpio: see descripton
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. -

uint32_t get_current_tick(int pi)

-Gets the current system tick. -

pi: >=0 (as returned by pigpio_start).


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. -

uint32_t get_hardware_revision(int pi)

-Get the Pi's hardware revision number. -

pi: >=0 (as returned by pigpio_start).


The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

uint32_t get_pigpio_version(int pi)

-Returns the pigpio version. -

pi: >=0 (as returned by pigpio_start).

int wave_clear(int pi)

-This function clears all waveforms and any data added by calls to the -wave_add_* functions. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

int wave_add_new(int pi)

-This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the wave_create function. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

int wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

       pi: >=0 (as returned by pigpio_start).
numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. -

int wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, -and stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int wave_create(int pi)

-This function creates a waveform from the data provided by the prior -calls to the wave_add_* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_create_and_pad(int pi, int percent)

-This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use (in terms -of the theoretical maximum, not the current amount free). This allows the reuse
-of deleted waves while a transmission is active. -

pi: >=0 (as returned by pigpio_start).
percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Normal usage: -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create_and_pad to create a waveform of uniform size. -

Step 4. wave_send_* with the id of the waveform to transmit. -

Repeat steps 2-4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_delete(int pi, unsigned wave_id)

-This function deletes the waveform with id wave_id. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int wave_send_once(int pi, unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -is sent once. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_repeat(int pi, unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by wave_tx_stop). -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)

-Transmits the waveform with id wave_id using mode mode. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.
   mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
         PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC.


PI_WAVE_MODE_ONE_SHOT: same as wave_send_once. -

PI_WAVE_MODE_REPEAT same as wave_send_repeat. -

PI_WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries -to sync with the previous waveform. -

PI_WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries -to sync with the previous waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_chain(int pi, char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

     pi: >=0 (as returned by pigpio_start).
    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if2.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, pi, wid[WAVES];

   pi = pigpio_start(0, 0);
   if (pi<0) return -1;

   set_mode(pi, GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(pi, 2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create(pi);
   }

   wave_chain(pi, (char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy(pi)) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(pi, wid[i]);

   pigpio_stop(pi);
}

int wave_tx_at(int pi)

-This function returns the id of the waveform currently being -transmitted. -

pi: >=0 (as returned by pigpio_start).


Returns the waveform id or one of the following special values: -

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
-PI_NO_TX_WAVE (9999) - no wave being transmitted. -

int wave_tx_busy(int pi)

-This function checks to see if a waveform is currently being -transmitted. -

pi: >=0 (as returned by pigpio_start).


Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int wave_tx_stop(int pi)

-This function stops the transmission of the current waveform. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

This function is intended to stop a waveform started with the repeat mode. -

int wave_get_micros(int pi)

-This function returns the length in microseconds of the current -waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_micros(int pi)

-This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_micros(int pi)

-This function returns the maximum possible size of a waveform in
-microseconds. -

pi: >=0 (as returned by pigpio_start).

int wave_get_pulses(int pi)

-This function returns the length in pulses of the current waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_pulses(int pi)

-This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_pulses(int pi)

-This function returns the maximum possible size of a waveform in pulses. -

pi: >=0 (as returned by pigpio_start).

int wave_get_cbs(int pi)

-This function returns the length in DMA control blocks of the current -waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_cbs(int pi)

-This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_cbs(int pi)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

pi: >=0 (as returned by pigpio_start).

int gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. -

int store_script(int pi, char *script)

-This function stores a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

    pi: >=0 (as returned by pigpio_start).
script: the text of the script.


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

-This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int script_status(int pi, unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int stop_script(int pi, unsigned script_id)

-This function stops a running script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int delete_script(int pi, unsigned script_id)

-This function deletes a stored script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the bb_serial_read_open command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int bb_serial_read_close(int pi, unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)

-This function inverts serial logic for big bang serial reads. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. -

int i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

-This returns a handle for the device at address i2c_addr on bus i2c_bus. -

       pi: >=0 (as returned by pigpio_start).
  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S       (1 bit) : Start bit
P       (1 bit) : Stop bit
Rd/Wr   (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA   (1 bit) : Accept and not accept bit.

Addr    (7 bits): I2C 7 bit address.
i2c_reg (8 bits): A byte which often selects a register.
Data    (8 bits): A data byte.
Count   (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2c_close(int pi, unsigned handle)

-This closes the I2C device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2c_write_quick(int pi, unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr bit [A] P

int i2c_write_byte(int pi, unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] bVal [A] P

int i2c_read_byte(int pi, unsigned handle)

-This reads a single byte from the device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] i2c_reg [A] bVal [A] P

int i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P

int i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)

-This reads a single byte from the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ...
   [A] bufn [A] P

int i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

  pi: >=0 (as returned by pigpio_start).
 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bb_i2c_close(int pi, unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bb_i2c_open. -

 pi: >=0 (as returned by pigpio_start).
SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

    pi: >=0 (as returned by pigpio_start).
   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)

-This function selects a set of GPIO for bit banging SPI at a -specified baud rate. -

       pi: >=0 (as returned by pigpio_start).
       CS: 0-31
     MISO: 0-31
     MOSI: 0-31
     SCLK: 0-31
     baud: 50-250000
spi_flags: see below


spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bb_spi_close(int pi, unsigned CS)

-This function stops bit banging SPI on a set of GPIO -opened with bbSPIOpen. -

pi: >=0 (as returned by pigpio_start).
CS: 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

int bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)

-This function executes a bit banged SPI transfer. -

   pi: >=0 (as returned by pigpio_start).
   CS: 0-31 (as used in a prior call to bb_spi_open)
txBuf: pointer to buffer to hold data to be sent
rxBuf: pointer to buffer to hold returned data
count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. -

Example

// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2
// ./bb_spi_x_test

#include <stdio.h>

#include "pigpiod_if2.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, pi, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if ((pi = pigpio_start(0, 0)) < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bb_spi_close(pi, CE0);
   bb_spi_close(pi, CE1);

   pigpio_stop(pi);
}

int spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


         pi: >=0 (as returned by pigpio_start).
spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per character.
-For bits 9-16 there will be two bytes per character.
-For bits 17-32 there will be four bytes per character. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spi_close(int pi, unsigned handle)

-This functions closes the SPI device identified by the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spi_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)

-This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. -

       pi: >=0 (as returned by pigpio_start).
  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serial_close(int pi, unsigned handle)

-This function closes the serial device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serial_write_byte(int pi, unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read_byte(int pi, unsigned handle)

-This function reads a byte from the serial port associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serial_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. -

If no data is ready zero is returned. -

int serial_data_available(int pi, unsigned handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

  pi: >=0 (as returned by pigpio_start).
arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from custom_1 in that it returns an array of bytes -rather than just an integer. -

The return value is an integer indicating the number of returned bytes. -    pi: >=0 (as returned by pigpio_start).
  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

Note, the number of returned bytes will be retMax or less. -

int get_pad_strength(int pi, unsigned pad)

-This function returns the pad drive strength in mA. -

 pi: >=0 (as returned by pigpio_start).
pad: 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = get_pad_strength(pi, 0); //  get pad 0 strength

int set_pad_strength(int pi, unsigned pad, unsigned padStrength)

-This function sets the pad drive strength in mA. -

         pi: >=0 (as returned by pigpio_start).
        pad: 0-2, the pad to set.
padStrength: 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA

int shell_(int pi, char *scriptName, char *scriptString)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

          pi: >=0 (as returned by pigpio_start).
  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name.
scriptString: the string to pass to the script.


The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. -

scriptName must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell_(pi, "scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell_(pi, "scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell_(pi, "scr1", "\"hello string with spaces world\"");

int file_open(int pi, char *file, unsigned mode)

-This function returns a handle to a file opened in a specified mode. -

  pi: >=0 (as returned by pigpio_start).
file: the file to open.
mode: the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


The following values may be or'd into the mode. -

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=file_read(pi, handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      file_close(pi, handle);
   }

   pigpio_stop(pi);
}

int file_close(int pi, unsigned handle)

-This function closes the file associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

file_close(pi, handle);

int file_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the file -associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. -

Example

if (file_write(pi, handle, buf, 100) == 0)
{
   // file written okay
}
else
{
   // error
}

int file_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the file -associated with handle and writes them to buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. -

Example

   bytes = file_read(pi, handle, buf, sizeof(buf));

   if (bytes >= 0)
   {
      // process read data
   }

int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)

-This function seeks to a position within the file associated -with handle. -

        pi: >=0 (as returned by pigpio_start).
    handle: >=0 (as returned by file_open).
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2).


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. -

Example

file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123

size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size

pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position

int file_list(int pi, char *fpat, char *buf, unsigned count)

-This function returns a list of files which match a pattern. -

   pi: >=0 (as returned by pigpio_start).
 fpat: file pattern to match.
  buf: an array to receive the matching file names.
count: the maximum number of bytes to read.


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See file_open. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   c = file_list(pi, "/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      buf[c] = 0;
      printf("%s", buf);
   }

   pigpio_stop(pi);
}

int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)

-This function initialises a new callback. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. -

The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use gpio_read. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

int callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

-This function initialises a new callback. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, tick, and the userdata -pointer, whenever the GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

-This function cancels a callback identified by its id. -

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)

-This function waits for an edge on the GPIO for up to timeout -seconds. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns when the edge occurs or after the timeout. -

Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a callback function. -

The function returns 1 if the edge occurred, otherwise 0. -

int bsc_xfer(int pi, bsc_xfer_t *bscxfer)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

     pi: >=0 (as returned by pigpio_start).
bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. -

Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. -

The returned function value is the status of the transfer (see below). -

If there was an error the status will be less than zero -(and will contain the error code). -

The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

control consists of the following bits. -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. -

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bsc_xfer(pi, &xfer);

if (status >= 0)
{
   // process transfer
}

int bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)

-This function allows the Pi to act as a slave I2C device. -

This function is not available on the BCM2711 (e.g.as -used in the Pi4B). -

The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. -

      pi: >=0 (as returned by pigpio_start).
i2c_addr: 0-0x7F.
 bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // N/A
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


txCnt is set to the number of bytes to be transmitted, possibly -zero. The data itself should be copied to txBuf. -

Any received data will be written to rxBuf with rxCnt set. -

See bsc_xfer for details of the returned status value. -

If there was an error the status will be less than zero -(and will contain the error code). -

Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. -

int event_callback(int pi, unsigned event, evtCBFunc_t f)

-This function initialises an event callback. -

   pi: >=0 (as returned by pigpio_start).
event: 0-31.
    f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the event id, and tick, whenever the -event occurs. -

int event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)

-This function initialises an event callback. -

      pi: >=0 (as returned by pigpio_start).
   event: 0-31.
       f: the callback function.
userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the event id, the tick, and the userdata -pointer whenever the event occurs. -

int event_callback_cancel(unsigned callback_id)

-This function cancels an event callback identified by its id. -

callback_id: >=0, as returned by a call to event_callback or
event_callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_event(int pi, unsigned event, double timeout)

-This function waits for an event for up to timeout seconds. -

     pi: >=0 (as returned by pigpio_start).
  event: 0-31.
timeout: >=0.


The function returns when the event occurs or after the timeout. -

The function returns 1 if the event occurred, otherwise 0. -

int event_trigger(int pi, unsigned event)

-This function signals the occurrence of an event. -

   pi: >=0 (as returned by pigpio_start).
event: 0-31.


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling event_callback) will be informed by -a callback. -

One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

*addrStr

-A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

bsc_xfer_t

-typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*bscxfer

-A pointer to a bsc_xfer_t object used to control a BSC transfer. -

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

callback_id

-A value >=0, as returned by a call to a callback function, one of -

callback
-callback_ex
-event_callback
-event_callback_ex -

The id is passed to callback_cancel or event_callback_cancel -to cancel the callback. -

CBFunc_t

-typedef void (*CBFunc_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

-typedef void (*CBFuncEx_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata);

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

-The hardware clock frequency. -

count

-The number of bytes to be transferred in a file, I2C, SPI, or serial -command. -

CS

-The GPIO used for the slave select signal when bit banging SPI. -

data_bits: 1-32

-The number of data bits in each character of serial data. -

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge

-Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. -

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

-A negative number indicating a function call failed and the nature -of the error. -

event: 0-31

-An event is a signal used to inform one or more consumers -to start an action. -

evtCBFunc_t

-typedef void (*evtCBFunc_t)
   (int pi, unsigned event, uint32_t tick);

evtCBFuncEx_t

-typedef void (*evtCBFuncEx_t)
   (int pi, unsigned event, uint32_t tick, void *userdata);

f

-A function. -

*file

-A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. -

*fpat

-A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 get_hardware_revision. -

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  -  -  -  -

gpioPulse_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

-A number referencing an object opened by one of -

file_open
-i2c_open
-notify_open
-serial_open
-spi_open -

i2c_addr: 0-0x7F

-The address of a device on the I2C bus. -

i2c_bus: >=0

-An I2C bus number. -

i2c_flags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2c_reg: 0-255

-A register of an I2C device. -

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

int32_t

-A 32-bit signed value. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See set_watchdog. -

PI_TIMEOUT 2

MISO

-The GPIO used for the MISO signal when bit banging SPI. -

mode

-1. The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. The mode of waveform transmission. -

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3


3. A file open mode. -

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


The following values can be or'd into the mode. -

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

-The GPIO used for the MOSI signal when bit banging SPI. -

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

pad: 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

-The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

*param

-An array of script parameters. -

percent: 0-100

-The size of waveform as percentage of maximum available. -

pi

-An integer defining a connected Pi. The value is returned by -pigpio_start upon success. -

*portStr

-A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. -

*pth

-A thread identifier, returned by start_thread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

-The hardware PWM frequency. -

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000
#define PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

-The permissible dutycycle values are 0-range. -

PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

SCLK

-The GPIO used for the SCLK signal when bit banging SPI. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by store_script. -

*scriptName

-The name of a shell_ script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. -

*scriptString

-The string to be passed to a shell_ script to be executed. -

SDA

-The user GPIO to use for data when bit banging I2C. -

seconds

-The number of seconds. -

seekFrom

-PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

-The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). -

ser_flags

-Flags which modify a serial open command. None are currently defined. -

*ser_tty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

size_t

-A standard type used to indicate the size of an object in bytes. -

spi_channel

-A SPI channel, 0-2. -

spi_flags

-See spi_open and bb_spi_open. -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) or triggering -the active part of a noise filter (set_noise_filter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

- An array of characters. -

thread_func

-A function of type gpioThreadFunc_t used as the main function of a -thread. -

timeout

-A GPIO watchdog timeout in milliseconds. -

PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

unsigned

-A whole number >= 0. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. -

In the calling function: -

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: -

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

-Denoting no parameter is required -

wave_add_*

-One of -

wave_add_new
-wave_add_generic
-wave_add_serial -

wave_id

-A number representing a waveform created by wave_create. -

wave_send_*

-One of -

wave_send_once
-wave_send_repeat -

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

pigpiod_if2 Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
   pigif_unconnected_pi     = -2011,
   pigif_too_many_pis       = -2012,
} pigifError_t;

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pif.html b/DOC/HTML/pif.html deleted file mode 100644 index 1cc3c17..0000000 --- a/DOC/HTML/pif.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Pipe Interface

-pigpio provides a pipe interface to many of its functions.
-
-The pipe interface is available whenever pigpio is running, either -because it has been started as a daemon, or it has been linked in -to a running user program.  The pipe interface can be disabled -by the program which initialises the library.  pigpiod offers -the -f option to disable the pipe interface.  User programs -should call gpioCfgInterfaces -if they wish to disable the pipe interface.
-
-pigpio listens for commands on pipe /dev/pigpio.  The commands -consist of a command identifier with, depending on the command, -zero, one, or two parameters.  The result, if any, may be read -from pipe /dev/pigout.  If any errors are detected a message -will be written to pipe /dev/pigerr.
-
-
-The format of the commands is identical to those used by pigs. -
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pig2vcd.html b/DOC/HTML/pig2vcd.html deleted file mode 100644 index e64a2fb..0000000 --- a/DOC/HTML/pig2vcd.html +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pig2vcd

pig2vcd is a utility which reads notifications on stdin and writes the -output as a Value Change Dump (VCD) file on stdout. -

The VCD file can be viewed using GTKWave. -

Notifications

Notifications consist of 12 bytes with the following binary format. -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments by one for each report. -

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. -

tick: the number of microseconds since system boot. It wraps around after 1h12m. -

level: indicates the level of each gpio. If bit 1<<x is set then gpio x is high. pig2vcd takes these notifications and outputs a text format VCD. -

VCD format

The VCD starts with a header. -

$date 2013-05-31 18:49:36 $end
$version pig2vcd V1 $end
$timescale 1 us $end
$scope module top $end
$var wire 1 A 0 $end
$var wire 1 B 1 $end
$var wire 1 C 2 $end
$var wire 1 D 3 $end
$var wire 1 E 4 $end
$var wire 1 F 5 $end
$var wire 1 G 6 $end
$var wire 1 H 7 $end
$var wire 1 I 8 $end
$var wire 1 J 9 $end
$var wire 1 K 10 $end
$var wire 1 L 11 $end
$var wire 1 M 12 $end
$var wire 1 N 13 $end
$var wire 1 O 14 $end
$var wire 1 P 15 $end
$var wire 1 Q 16 $end
$var wire 1 R 17 $end
$var wire 1 S 18 $end
$var wire 1 T 19 $end
$var wire 1 U 20 $end
$var wire 1 V 21 $end
$var wire 1 W 22 $end
$var wire 1 X 23 $end
$var wire 1 Y 24 $end
$var wire 1 Z 25 $end
$var wire 1 a 26 $end
$var wire 1 b 27 $end
$var wire 1 c 28 $end
$var wire 1 d 29 $end
$var wire 1 e 30 $end
$var wire 1 f 31 $end
$upscope $end
$enddefinitions $end


The header defines gpio identifiers and their name. Each gpio identifier -must be unique. pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0 -through 25, and 'a' through 'f' for gpios 26 through 31. -The corresponding names are 0 through 31.
-

The VCD file may be edited to give a frendlier name, e.g. 8 could be -changed to ENCODER_A if an encoder switch A is connected to gpio 8. -

Following the header pig2vcd takes notifications and outputs a timestamp -followed by a list of one or more gpios which have changed state. -The timestamp consists of a '#' followed by the microsecond tick. -The state lines contain the new state followed by the gpio identifier. -

#1058747
0H
0I
#1059012
1H
#1079777
1I
#1079782
0I
#1079852
1I
#1079857
0I
0H
#1165113
1H
#1165118
0H
#1165153
1H
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pigpiod.html b/DOC/HTML/pigpiod.html deleted file mode 100644 index d522889..0000000 --- a/DOC/HTML/pigpiod.html +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigpio Daemon

pigpiod is a utility which launches the pigpio library as a daemon.
-
-Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.
-
-The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.
-
-pigpiod accepts the following configuration options
-
-
-a valueDMA memory allocation mode0=AUTO, 1=PMAP, 2=MBOXDefault AUTO -
-b valueGPIO sample buffer size in milliseconds100-10000Default 120 -
-c valueLibrary internal settingsDefault 0 -
-d valuePrimary DMA channel0-14Default 14 -
-e valueSecondary DMA channel0-14Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel -
-fDisable fifo interfaceDefault enabled -
-gRun in foreground (do not fork)Default disabled -
-kDisable local and remote socket interfaceDefault enabled -
-lDisable remote socket interfaceDefault enabled -
-mDisable alerts (sampling)Default enabled -
-n IP addressAllow IP address to use the socket interfaceName (e.g. paul) or dotted quad (e.g. 192.168.1.66)If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect -
-p valueSocket port1024-32000Default 8888 -
-s valueSample rate1, 2, 4, 5, 8, or 10 microsecondsDefault 5 -
-t valueClock peripheral0=PWM 1=PCMDefault PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. -
-v -VDisplay pigpio version and exit -
-x maskGPIO which may be updatedA 54 bit mask with (1<<n) set if the user may update GPIO #nDefault is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO -

Example

sudo pigpiod -s 2 -b 200 -f


Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer. Disable the fifo interface. -

Permissions

pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces. -

All GPIO may be read. -

Only the user GPIO for the board type or those specified by the -x option may be updated. -

Type 1 boards 0x03E6CF93 (26 pin header)
Type 2 boards 0xFBC6CF9C (26 pin + 8 pin header)
Type 3 boards 0x0FFFFFFC (40 pin header)


In this context an update includes the following: -

GPIO mode set
-GPIO pull/up down
-GPIO write
-GPIO set PWM (including range and frequency)
-GPIO set servo -

In addition the bank clear and set commands, and the wave commands will only -affect updateable GPIO. -

Exceptions

The following exceptions are made for particular models. -

Models A and B

The green activity LED (GPIO 16) may be written.
-
Models A+ and B+

The green activity LED (GPIO 47) may be written.
-The red power LED (GPIO 35) may be written.
-The high USB power mode (GPIO 38) may be written.
-
Pi Zero

The green activity LED (GPIO 47) may be written.
-
Pi2B

The green activity LED (GPIO 47) may be written.
-The red power LED (GPIO 35) may be written.
-The high USB power mode (GPIO 38) may be written.
-
Pi3B

The green activity LED and the red power LED are not writable.
-The USB power mode is fixed at 1.2 amps (high power).
-

DMA Channels

The secondary channel is only used for the transmission of waves. -

If possible use one of channels 0 to 6 for the secondary channel (a full channel). -

A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel. -

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/pigs.html b/DOC/HTML/pigs.html deleted file mode 100644 index d4b4079..0000000 --- a/DOC/HTML/pigs.html +++ /dev/null @@ -1,1268 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

pigs

Introduction

-The socket and pipe interfaces allow control of the Pi's GPIO by -passing messages to the running pigpio library. -

The normal way to start the pigpio library would be as a daemon during boot. -

sudo pigpiod

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

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. -

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 $?). -

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). -

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. -

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. -

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 mSet GPIO mode gpioSetMode
MG/MODEG gGet GPIO mode gpioGetMode
PUD g pSet GPIO pull up/down gpioSetPullUpDown
R/READ gRead GPIO level gpioRead
W/WRITE g LWrite GPIO level gpioWrite
PWM (overrides servo commands on same GPIO) -
P/PWM u vSet GPIO PWM value gpioPWM
PFS u vSet GPIO PWM frequency gpioSetPWMfrequency
PRS u vSet GPIO PWM range gpioSetPWMrange
GDC uGet GPIO PWM dutycycle gpioGetPWMdutycycle
PFG uGet GPIO PWM frequency gpioGetPWMfrequency
PRG uGet GPIO PWM range gpioGetPWMrange
PRRG uGet GPIO PWM real range gpioGetPWMrealRange
Servo (overrides PWM commands on same GPIO) -
S/SERVO u vSet GPIO servo pulsewidth gpioServo
GPW uGet GPIO servo pulsewidth gpioGetServoPulsewidth
INTERMEDIATE -
TRIG u pl LSend a trigger pulse gpioTrigger
WDOG u vSet GPIO watchdog gpioSetWatchdog
BR1Read bank 1 GPIO gpioRead_Bits_0_31
BR2Read bank 2 GPIO gpioRead_Bits_32_53
BC1 bitsClear specified GPIO in bank 1 gpioWrite_Bits_0_31_Clear
BC2 bitsClear specified GPIO in bank 2 gpioWrite_Bits_32_53_Clear
BS1 bitsSet specified GPIO in bank 1 gpioWrite_Bits_0_31_Set
BS2 bitsSet specified GPIO in bank 2 gpioWrite_Bits_32_53_Set
ADVANCED -
NORequest a notification gpioNotifyOpen
NC hClose notification gpioNotifyClose
NB h bitsStart notification gpioNotifyBegin
NP hPause notification gpioNotifyPause
HC g cfSet hardware clock frequency gpioHardwareClock
HP g pf pdcSet hardware PWM frequency and dutycycle gpioHardwarePWM
FG u stdySet a glitch filter on a GPIO gpioGlitchFilter
FN u stdy actvSet a noise filter on a GPIO gpioNoiseFilter
PADS pad padmaSet pad drive strength gpioSetPad
PADG padGet pad drive strength gpioGetPad
SHELL name strExecute a shell command shell
Custom -
CF1 uvsCustom function 1 gpioCustom1
CF2 uvsCustom function 2 gpioCustom1
Events -
EVM h bitsSet events to monitor eventMonitor
EVT eventTrigger event eventTrigger
Scripts -
PROC tStore script gpioStoreScript
PROCR sid parsRun script gpioRunScript
PROCU sid parsSet script parameters gpioUpdateScript
PROCP sidGet script status and parameters gpioScriptStatus
PROCS sidStop script gpioStopScript
PROCD sidDelete script gpioDeleteScript
PARSE tValidate script gpioParseScript
I2C -
I2CO ib id ifOpen I2C bus and device with flags i2cOpen
I2CC hClose I2C handle i2cClose
I2CWQ h bitsmb Write Quick: write bit i2cWriteQuick
I2CRS hsmb Read Byte: read byte i2cReadByte
I2CWS h bvsmb Write Byte: write byte i2cWriteByte
I2CRB h rsmb Read Byte Data: read byte from register i2cReadByteData
I2CWB h r bvsmb Write Byte Data: write byte to register i2cWriteByteData
I2CRW h rsmb Read Word Data: read word from register i2cReadWordData
I2CWW h r wvsmb Write Word Data: write word to register i2cWriteWordData
I2CRK h rsmb Read Block Data: read data from register i2cReadBlockData
I2CWK h r bvssmb Write Block Data: write data to register i2cWriteBlockData
I2CWI h r bvssmb Write I2C Block Data i2cWriteI2CBlockData
I2CRI h r numsmb Read I2C Block Data: read bytes from register i2cReadI2CBlockData
I2CRD h numi2c Read device i2cReadDevice
I2CWD h bvsi2c Write device i2cWriteDevice
I2CPC h r wvsmb Process Call: exchange register with word i2cProcessCall
I2CPK h r bvssmb Block Process Call: exchange data bytes with register i2cBlockProcessCall
I2CZ h bvsPerforms multiple I2C transactions i2cZip
I2C BIT BANG -
BI2CO sda scl bOpen bit bang I2C bbI2COpen
BI2CC sdaClose bit bang I2C bbI2CClose
BI2CZ sda bvsI2C bit bang multiple transactions bbI2CZip
I2C/SPI SLAVE -
BSCX bctl bvsBSC I2C/SPI transfer bscXfer
SERIAL -
SERO dev b sefOpen serial device dev at baud b with flags serOpen
SERC hClose serial handle serClose
SERRBRead byte from serial handle serReadByte
SERWB h bvWrite byte to serial handle serWriteByte
SERR h numRead bytes from serial handle serRead
SERW h bvsWrite bytes to serial handle serWrite
SERDA hCheck for serial data ready to read serDataAvailable
SERIAL BIT BANG (read only) -
SLRO u b dbOpen GPIO for bit bang serial data gpioSerialReadOpen
SLRC uClose GPIO for bit bang serial data gpioSerialReadClose
SLRI u vSets bit bang serial data logic levels gpioSerialReadInvert
SLR u numRead bit bang serial data from GPIO gpioSerialRead
SPI -
SPIO c b spfSPI open channel at baud b with flags spiOpen
SPIC hSPI close handle spiClose
SPIR h numSPI read bytes from handle spiRead
SPIW h bvsSPI write bytes to handle spiWrite
SPIX h bvsSPI transfer bytes to handle spiXfer
SPI BIT BANG -
BSPIO cs miso mosi sclk b spfOpen bit bang SPI bbSPIOpen
BSPIC csClose bit bang SPI bbSPIClose
BSPIX cs bvsSPI bit bang transfer bbSPIXfer
FILES -
FO file modeOpen a file in mode fileOpen
FC hClose file handle fileClose
FR h numRead bytes from file handle fileRead
FW h bvsWrite bytes to file handle fileWrite
FS h num fromSeek to file handle position fileSeek
FL pat numList files which match pattern fileList
WAVES -
WVCLRClear all waveforms gpioWaveClear
WVNEWInitialise a new waveform gpioWaveAddNew
WVAG tripsAdd generic pulses to waveform gpioWaveAddGeneric
WVAS u b db sb o bvsAdd serial data to waveform gpioWaveAddSerial
WVCRECreate a waveform gpioWaveCreate
WVCAPCreate a waveform of fixed size gpioWaveCreatePad
WVDEL widDelete selected waveform gpioWaveDelete
WVTX widTransmits waveform once gpioWaveTxSend
WVTXM wid wmdeTransmits waveform using mode gpioWaveTxSend
WVTXR widTransmits waveform repeatedly gpioWaveTxSend
WVCHA bvsTransmits a chain of waveforms gpioWaveChain
WVTATReturns the current transmitting waveform gpioWaveTxAt
WVBSYCheck if waveform is being transmitted gpioWaveTxBusy
WVHLTStop waveform gpioWaveTxStop
WVSC wsGet waveform DMA CB stats gpioWaveGetCbs
WVSM wsGet waveform time stats gpioWaveGetMicros
WVSP wsGet waveform pulse stats gpioWaveGetPulses
UTILITIES -
H/HELPDisplay command help
HWVERGet hardware version gpioHardwareRevision
MICS vMicroseconds delay gpioDelay
MILS vMilliseconds delay gpioDelay
PIGPVGet pigpio library version gpioVersion
T/TICKGet current tick gpioTick
CONFIGURATION -
CGIConfiguration get internals gpioCfgGetInternals
CSI vConfiguration set internals gpioCfgSetInternals

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. -

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. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o 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. -

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: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

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 read GPIO 0-31 (bank 1) and returns the levels as a -32-bit hexadecimal value. -

Example

$ pigs br1
1001C1CF

BR2 - - Read bank 2 GPIO

This command read 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 (sets high) 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 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

This command sets (sets high) 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 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

This command performs a BSC I2C/SPI slave transfer as defined by -bctl with data bvs. -

This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

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, followed by any data bytes -read from the BSC receive FIFO. -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

For I2C use a control word of (I2C address << 16) + 0x305. -

E.g. to talk as I2C slave with address 0x13 use 0x130305. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

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. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit 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 -opened with BSPIO. -

The set of GPIO is specifed by cs. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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 command starts bit banging SPI on a group of GPIO with slave -select cs, MISO miso, MOSI mosi, and clock sclk. -

Data will be transferred at baud b bits per second (which may -be set in the range 50-250000). -

The flags spf may be used to modify the default behaviour of -mode 0, active low chip select. -

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
 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 (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. -

Upon success 0 is returned. On error a negative status code -will be returned. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

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. It returns the same -number of bytes read from the device. -

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 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

This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. -

CF2 - uvs - Custom function 2

This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. -

CGI - - Configuration get internals

This command returns the value of the internal library -configuration settings. -

CSI - v - Configuration set internals

This command sets the value of the internal library -configuration settings to v. -

EVM - h bits - Set events to monitor

This command starts event reporting 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 reports for each 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

This command triggers event event. -

One event, number 31, is predefined. This event is -auto generated on BSC slave activity. -

Example

$ pigs evt 12
$ pigs evt 5

$ pigs evt 32
-143
ERROR: bad event id

FC - h - Close file handle

This command closes a file handle h previously opened with FO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs fc 0 # First close okay.

$ pigs fc 0 # Second fails.
-25
ERROR: unknown handle

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. The -level is then reported. Level changes of less than stdy -microseconds are ignored. -

The filter only affects callbacks (including pipe notifications). -

The R/READ, BR1, and BR2 commands are not affected. -

Note, each (stable) edge will be timestamped stdy microseconds -after it was first detected. -

Example

$ pigs fg 4 250

$ pigs fg 4 1000000
-125
ERROR: bad filter parameter

FL - pat num - List files which match pattern

This command returns a list of the files matching pat. Up -to num bytes may be returned. -

Upon success the count of returned bytes followed by the matching -files is returned. On error a negative status code will be returned. -

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 are ignored until a level which has -been stable for stdy microseconds is detected. Level -changes on the GPIO are then reported for actv microseconds -after which the process repeats. -

The filter only affects callbacks (including pipe notifications). -

The R/READ, BR1, and BR2 commands are not affected. -

Note, level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

Example

$ pigs fn 7 250 1000

$ pigs fn 7 2500000 1000
-125
ERROR: bad filter parameter

FO - file mode - Open a file in mode

This function 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 -will be returned. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


The following values may be or'd into the mode. -

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

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

This command 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 will be returned. -

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

This command 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 backwards. The move start -position is determined by from as follows. -

From
0start
1current position
2end


Upon success the new byte position within the file (>=0) is -returned. On error a negative status code will be returned. -

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

This command writes bytes bvs to the file -associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs fw 0 23 45 67 89

GDC - u - Get GPIO PWM dutycycle

This command returns the PWM dutycycle in use on GPIO u. -

Upon success the dutycycle is returned. On error a negative -status code will be returned. -

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

This command returns the servo pulsewidth in use on GPIO u. -

Upon success the servo pulsewidth is returned. On error a negative -status code will be returned. -

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

This command displays a brief list of the commands and their parameters. -

Example

$ pigs h

$ pigs help

HC - g cf - Set hardware clock frequency

This command sets the hardware clock associated with GPIO g to -frequency cf. Frequencies above 30MHz are unlikely to work. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

The GPIO must be one of the following. -

4clock 0All models
5clock 1All models but A and B (reserved for system use)
6clock 2All models but A and B
20clock 0All models but A and B
21clock 1All models but A and B Rev.2 (reserved for system use)


32clock 0Compute module only
34clock 0Compute module only
42clock 1Compute module only (reserved for system use)
43clock 2Compute module only
44clock 1Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. -

HP - g pf pdc - Set hardware PWM frequency and dutycycle

This command sets the hardware PWM associated with GPIO g to -frequency pf with dutycycle pdc. Frequencies above 30MHz -are unlikely to work. -

NOTE: Any waveform started by WVTX, WVTXR, or WVCHA -will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

Upon success nothing is returned. On error a negative status code -will be returned. -

$ 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


The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12PWM channel 0All models but A and B
13PWM channel 1All models but A and B
18PWM channel 0All models
19PWM channel 1All models but A and B


40PWM channel 0Compute module only
41PWM channel 1Compute module only
45PWM channel 1Compute module only
52PWM channel 0Compute module only
53PWM channel 1Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/pf (375M/pf for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a pf of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. pdc is -automatically scaled to take this into account. -

HWVER - - Get hardware version

This command returns the hardware revision of the Pi. -

The hardware revision is found in the last 4 characters on the revision -line of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid hexadecimal -number the command returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see g). -

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

This command closes an I2C handle h previously opened with I2CO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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 command returns a handle to access device id on I2C bus ib. -The device is opened with flags if. -

Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


No flags are currently defined. The parameter if should be 0. -

Upon success the next free handle (>=0) is returned. On error a -negative status code will be returned. -

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

This command writes wv to register r of the I2C device -associated with handle h and returns a 16-bit word read from the -device. -

Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. -

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

This command writes the data bytes bvs to register r of the I2C device -associated with handle h and returns a device specific number of 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 i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0

I2CRB - h r - smb Read Byte Data: read byte from register

This command returns a single byte read from register r of the I2C device -associated with handle h. -

Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crb 0 0
6

I2CRD - h num - i2c Read device

This command returns num bytes read from the I2C 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. -

This command operates on the raw I2C device. The maximum value of the -parameter num is dependent on the I2C drivers and the device -itself. pigs imposes a limit of 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

This command returns num bytes from register r of the I2C 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. -

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

This command returns between 1 and 32 bytes read from register r of -the I2C 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. -

The number of bytes of returned data is specific to the device and -register. -

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

This command returns a single byte read from the I2C device -associated with handle h. -

Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crs 0
0

I2CRW - h r - smb Read Word Data: read word from register

This command returns a single 16 bit word read from register r of -the I2C device associated with handle h. -

Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crw 0 0
6150

I2CWB - h r bv - smb Write Byte Data: write byte to register

This command writes a single byte bv to register r of the -I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwb 0 10 0x54

I2CWD - h bvs - i2c Write device

This command writes a block of bytes bvs to the I2C device -associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

The number of bytes which may be written in one transaction is -dependent on the I2C drivers and the device itself. pigs imposes -a limit of about 500 bytes. -

This command operates on the raw I2C device. -

Example

$ pigs i2cwd 0 0x01 0x02 0x03 0x04

I2CWI - h r bvs - smb Write I2C Block Data

This command writes between 1 and 32 bytes bvs to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwi 0 4 0x01 0x04 0xc0

I2CWK - h r bvs - smb Write Block Data: write data to register

This command writes between 1 and 32 bytes bvs to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

pigs i2cwk 0 4 0x01 0x04 0xc0

I2CWQ - h bit - smb Write Quick: write bit

This command writes a single bit to the I2C device associated -with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwq 0 1

I2CWS - h bv - smb Write Byte: write byte

This command writes a single byte bv to the I2C device associated -with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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

This command writes a single 16 bit word wv to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cww 0 0 0xffff

I2CZ - h bvs - Performs multiple I2C transactions

This command executes a sequence of 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: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle h. -The flags default to 0. The address and flags maintain their -previous value until updated. -

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/MODES - g m - Set GPIO mode

This command sets GPIO g to mode m, typically input (read) -or output (write). -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345


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. -

Value01234567
ModeInputOutputALT5ALT4ALT0ALT1ALT2ALT3


Example

$ pigs mg 4
1

MICS - v - Microseconds delay

This command delays execution for v microseconds. -

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. -

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. -

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. -

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. -

PadGPIO
00-27
128-45
246-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. -

PadGPIO
00-27
128-45
246-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. -

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. -

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

       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


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). -

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. -

Upon success the script status and parameters are returned. -On error a negative status code will be returned. -

The script status may be one of -

0being initialised
1halted
2running
3waiting
4failed


See Scripts. -

Example

$ pigs procp 0
1 0 0 0 0 0 0 0 0 0 0

PROCR - sid pars - Run script

This command runs stored script sid passing it up to 10 optional -parameters. -

Upon success nothing is returned. 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 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

This command stops a running script sid. -

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

This command sets the parameters of a stored script sid passing -it up to 10 parameters. -

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 used by GPIO u. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

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 command sets the dutycycle range v to be used for GPIO u. -Subsequent uses of command P/PWM will use a dutycycle between 0 (off) -and v (fully on). -

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 will be scaled to -reflect the new range. -

The real range, the number of steps between fully off and fully on -for each frequency, is given in the following table. -

#1#2#3#4#5#6#7#8#9
2550100125200250400500625
#10#11#12#13#14#15#16#17#18
8001000125020002500400050001000020000


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

This command 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 may 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

This 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

This command 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 may be 0 (off), 500 (most anti-clockwise) -to 2500 (most clockwise). -

The range supported by servos varies and should probably be determined -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. -

You can DAMAGE a servo if you command it to move beyond its limits. -

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

This command closes a serial handle h 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

This command 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). 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

This command 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. -

Example

$ pigs sero /dev/ttyAMA0 9600 0
0

$ pigs sero /dev/tty1 38400 0
1

SERR - h num - Read bytes from serial handle

This command 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

This command 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

This command 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

This command 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 command 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. -

The returned exit status is normally 256 times that set -by the shell script exit function. If the script can't -be found 32512 will be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


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 "\"hello string with spaces world\""
256

# non-existent script
$ pigs shell scr78 par1
32512

SLR - u num - Read bit bang serial data from GPIO

This command 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. -

The GPIO u should have been initialised with the SLRO command. -

The bytes returned for each character depend upon the number of -data bits db 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

This command 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

This command 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

This command 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 may be between 50 and 250000 bits per second. -

The received data is held in a cyclic buffer. -

It is the user's responsibility to read the data (with SLR) -in a timely fashion. -

Example

$ pigs slro 23 19200 8

$ pigs slro 23 19200 8
-50
ERROR: GPIO already in use

SPIC - h - SPI close handle

This command closes the SPI handle h returned by a prior -call to SPIO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

Data will be transferred at b bits per second. The flags spf -may be used to modify the default behaviour of 4-wire operation, -mode 0, active low chip select. -

Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps -are unlikely to work. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


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. -

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. -

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. -

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. -

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. -

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

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. -

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. -

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. -

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. -

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. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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 \
   ${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

WVCLR - - Clear all waveforms

This command clears all waveforms. -

Nothing is returned. -

Example

$ pigs wvclr

WVCRE - - Create a waveform

This command creates a waveform from the data provided by the prior -calls to the WVAG and WVAS commands. -

Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. -

The data provided by the WVAG and WVAS commands is -consumed by this command. -

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 -

Step 1. WVCLR to clear all waveforms and added data. -

Step 2. WVAG/WVAS calls to supply the waveform data. -

Step 3. WVCRE to create the waveform and get a unique id. -

Repeat steps 2 and 3 as needed. -

Step 4. WVTX or WVTXR with the id of the waveform to transmit. -

A waveform comprises of one or more pulses. -

A pulse specifies -

1) the GPIO to be switched on at the start of the pulse.
-2) the GPIO to be switched off at the start of the pulse.
-3) the delay in microseconds before the next pulse. -

Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). -

When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. -

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

WVCAP - - 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 total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. -

Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. -

The data provided by the WVAG and WVAS commands are -consumed by this command. -

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 -

Step 1. WVCLR to clear all waveforms and added data. -

Step 2. WVAG/WVAS calls to supply the waveform data. -

Step 3. WVCAP to create a waveform of a uniform size. -

Step 4. WVTX or WVTXR with the id of the waveform to transmit. -

Repeat steps 2 - 4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

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

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

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. -

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

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. -

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), or 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. -

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. -

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

-

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. -

From
0start
1current position
2end

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. -

0123456789101112131415
Type 1XX--X--XXXXX--XX
Type 2--XXX--XXXXX--XX
Type 3XXXXXXXXXXXXXX
16171819202122232425262728293031
Type 1-XX--XXXXX------
Type 2-XX---XXXX-XXXXX
Type 3XXXXXXXXXXXX----


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. -

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345
Value01456732

miso - GPIO (0-31)

-The GPIO used for the MISO signal when bit banging SPI. -

mode - file open mode

-One of the following values. -

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


The following values can be or'd into the mode. -

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The 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 DownOffPull DownPull Up
Command CharacterODU


There is no mechanism to read the pull up down state. -

pad - 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-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. -

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 onGPIO offdelay
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

-Scripts are programs to be stored and executed by the pigpio daemon. -They are intended to mitigate any performance problems associated with -the pigpio daemon server/client model. -

Example

A trivial example might be useful. Suppose you want to toggle a GPIO -on and off as fast as possible. -

From the command line you could write -

for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done


Timing that you will see it takes about 14 seconds, or roughly -70 toggles per second. -

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. -

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. -

Let's time the script running. -

Again, ignore the details for now. -

time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
 do sleep 0.2; done)


The script takes roughly 12 seconds to complete, or 800,000 toggles per second. -

That is the advantage of a stored script. -

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 ]];\
 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. -

Virtual machine

A script runs within a virtual machine with -

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. -

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: -

CommandDescriptionDefinition
ADD xAdd x to accumulatorA+=x; F=A
AND xAnd x with accumulatorA&=x; F=A
CALL LCall subroutine at tag Lpush(PC+1); PC=L
CMP xCompare x with accumulatorF=A-x
DCR yDecrement register--*y; F=*y
DCRADecrement accumulator--A; F=A
DIV xDivide x into accumulatorA/=x; F=A
EVTWTWait for an event to occurA=wait(x); F=A
HALTHaltHalt
INR yIncrement register++*y; F=*y
INRAIncrement accumulator++A; F=A
JM LJump if minus to tag Lif (F<0) PC=L
JMP LJump to tag LPC=L
JNZ LJump if non-zero to tag Lif (F) PC=L
JP LJump if positive to tag Lif (F>=0) PC=L
JZ LJump if zero to tag Lif (!F) PC=L
LD y xLoad register with x*y=x
LDA xLoad accumulator with xA=x
MLT xMultiply x with accumulatorA*=x; F=A
MOD xModulus x with accumulatorA%=x; F=A
OR xOr x with accumulatorA|=x; F=A
POP yPop registery=pop()
POPAPop accumulatorA=pop()
PUSH yPush registerpush(y)
PUSHAPush accumulatorpush(A)
RETReturn from subroutinePC=pop()
RL y xRotate left register x bits*y<<=x; F=*y
RLA xRotate left accumulator x bitsA<<=x; F=A
RR y xRotate right register x bits*y>>=x; F=*y
RRA xRotate right accumulator x bitsA>>=x; F=A
STA yStore accumulator in registery=A
SUB xSubtract x from accumulatorA-=x; F=A
SYS strRun external script (/opt/pigpio/cgi/str)system(str); F=A
TAG LLabel the current script positionN/A
WAIT xWait for a GPIO in x to change stateA=wait(x); F=A
X y1 y2Exchange contents of registers y1 and y2t=*y1;*y1=*y2;*y2=t
XA yExchange contents of accumulator and registert=A;A=*y;*y=t
XOR xXor x with accumulatorA^=x; F=A


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. -

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/piscope.html b/DOC/HTML/piscope.html deleted file mode 100644 index 9236731..0000000 --- a/DOC/HTML/piscope.html +++ /dev/null @@ -1,269 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

piscope

-

Introduction

-piscope is a logic analyser (digital -waveform viewer) for the Raspberry.  It shows the state (high -or low) of selected GPIO in real-time.
-
-See video.
-
-piscope uses the services of the pigpio library.  pigpio needs to be running on -the Pi whose GPIO are to be monitored.
-
-The pigpio library may be started as a daemon (background process) -by the following command.
-
-sudo pigpiod

-piscope may be invoked in several different ways
-
- - - - - - - - - - - - - - - - - - - - - - - -
Pi
pi_host ~ $ piscope -&
Pi captures -data
-Pi processes data
-Pi displays data
Pi plus Linux PC
-
-(with the
-display on a remote
-  Linux PC)
remote_host ~ $ ssh -X pi_host
pi_host ~ $ piscope -&
Pi captures data
-Pi processes data
-Remote Linux PC displays data
Pi plus Windows PC
-
-(with the
-display on a remote
-  Windows PC)
You need to install an SSH -client (putty suggested) and a X11 server (xming suggested).
-
-Run Program Files -> Xming -> XLaunch and accept the -defaults.
-
-Run putty and enter the Pi's host name or IP address.  Click -on SSH X11 and tick Enable X11 forwarding and then select -Open.

-
pi_host ~ $ piscope -&
Pi captures data
-Pi processes data
-Remote Windows PC displays data
Pi plus Linux PC
-
-(with the display and processing on a remote Linux -PC)
remote_host ~ $ export -PIGPIO_ADDR=pi_host
-remote_host ~ $ piscope -&
Pi captures data
-Remote processes data
-Remote displays data
-
-piscope operates in one of three modes
-
- - - - - - - - - - - - - - - - - - -
Live
The latest GPIO samples are -displayed.
-
-The mode will automatically change to Pause if a sampling trigger -is detected.
-
-There are four triggers.  Each trigger is made up of a -combination of GPIO states (one of don't care, low, high, edge, -falling, or rising per GPIO).  Triggers are always -counted.  In addition a trigger may be sample to, sample -around, or sample from, a so called sampling trigger.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full the oldest samples are discarded.
Play
Recorded GPIO samples are -displayed.
-
-The play speed may be varied between 64 times real-time to 1/32768 -of real-time.
-
-The page up key increases the play speed by a factor of 2.  -The page down key decreases the play speed by a factor of 2.  -The home key sets the play speed to 1X.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full new samples are discarded.
Pause
Recorded GPIO samples are -displayed.
-
-The left and right cursor keys move the blue marker to the previous -or next edge.  By default all GPIO edges are considered.  -Clicking on a GPIO name will limit edge searches to the highlighted -GPIO only.
-
-The left and right square bracket keys move the blue marker to the -previous or next trigger.
-
-The time between the blue and gold markers is displayed.  The -gold marker is set to the blue marker by a press of the 'g' -key.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full new samples are discarded.
-
-In all modes the down and up cursor keys zoom the time scale in and -out.
-
-Samples can be saved with File Save All Samples or File Save -Selected Samples. -

To select samples enter pause mode. Press 1 to specify the start -of the samples (green marker) and 2 to specify the end of the -samples (red marker).

-

The samples may be saved in the native piscope format or in VCD -format.

-

Data saved in VCD format may be viewed and further processed -with GTKWave.

-

Data saved in the native piscope format may be restored later -with File Restore Saved Data.

-

Installation

-

To download and install piscope.

-

Pi (pre-built image)

-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make hf
-make install

-

Linux 64 bit X86/AMD (pre-built image)

-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make x86_64
-make install
-

All machines (building from source)

-You only need to perform this step if you want to build the -executable from the source files.  This is not needed if you -use a pre-built image.
-
-WARNING
: Installing gtk+-3.0 uses a lot of SD card -space.
-
-Most of the space used by gtk+-3.0 is taken up by unneeded *-dbg -packages.
-
-With *-dbg packages an additional 3753MB SD space is required.
-
-If you edit the list of packages to be downloaded and remove the -*-dbg packages only 134MB of additional SD space is needed (as at -the time of writing).
-
-#
# *** This may take a lot of time and use -a lot of SD card space ***
#
-sudo apt-get install gtk+-3.0
#
-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make
-make install

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/python.html b/DOC/HTML/python.html deleted file mode 100644 index f6b5f22..0000000 --- a/DOC/HTML/python.html +++ /dev/null @@ -1,1294 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Python Interface

pigpio is a Python module for the Raspberry which talks to -the pigpio daemon to allow control of the general purpose -input outputs (GPIO). -

Features

o the pigpio Python module can run on Windows, Macs, or Linux -

o controls one or more Pi's -

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o creating and transmitting precisely timed waveforms -

o reading/writing GPIO and setting their modes -

o wrappers for I2C, SPI, and serial links -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

Transmitted waveforms are accurate to a microsecond. -

Callback level changes are time-stamped and will be -accurate to within a few microseconds. -

Settings

A number of settings are determined when the pigpio daemon is started. -

o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). -

o the set of GPIO which may be updated (generally written to). The - default set is those available on the Pi board revision. -

o the available PWM frequencies (see set_PWM_frequency). -

Exceptions

By default a fatal exception is raised if you pass an invalid -argument to a pigpio function. -

If you wish to handle the returned status yourself you should set -pigpio.exceptions to False. -

You may prefer to check the returned status in only a few parts -of your code. In that case do the following: -

Example

pigpio.exceptions = False

# Code where you want to test the error status.

pigpio.exceptions = True

Usage

This module uses the services of the C pigpio library. pigpio -must be running on the Pi(s) whose GPIO are to be manipulated. -

The normal way to start pigpio is as a daemon (during system -start). -

sudo pigpiod -

Your Python program must import pigpio and create one or more -instances of the pigpio.pi class. This class gives access to -a specified Pi's GPIO. -

Example

pi1 = pigpio.pi()       # pi1 accesses the local Pi's GPIO
pi2 = pigpio.pi('tom')  # pi2 accesses tom's GPIO
pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO

pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4)     # get level of dick's GPIO 4


The later example code snippets assume that pi is an instance of -the pigpio.pi class. -

OVERVIEW

ESSENTIAL -
pigpio.pi Initialise Pi connection -
stop Stop a Pi connection -
BASIC -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
read Read a GPIO -
write Write a GPIO -
PWM (overrides servo commands on same GPIO) -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
set_PWM_frequency Set PWM frequency of a GPIO -
set_PWM_range Configure PWM range of a GPIO -
get_PWM_dutycycle Get PWM dutycycle set on a GPIO -
get_PWM_frequency Get PWM frequency of a GPIO -
get_PWM_range Get configured PWM range of a GPIO -
get_PWM_real_range Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
set_servo_pulsewidth Start/Stop servo pulses on a GPIO -
get_servo_pulsewidth Get servo pulsewidth set on a GPIO -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO -
set_watchdog Set a watchdog on a GPIO -
read_bank_1 Read all bank 1 GPIO -
read_bank_2 Read all bank 2 GPIO -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
callback Create GPIO level change callback -
wait_for_edge Wait for GPIO level change -
ADVANCED -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
set_pad_strength Sets a pads drive strength -
get_pad_strength Gets a pads drive strength -
shell Executes a shell command -
Custom -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
Events -
event_callback Sets a callback for an event -
event_trigger Triggers an event -
wait_for_event Wait for an event -
Scripts -
store_script Store a script -
run_script Run a stored script -
update_script Set a scripts parameters -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick SMBus write quick -
i2c_read_byte SMBus read byte -
i2c_write_byte SMBus write byte -
i2c_read_byte_data SMBus read byte data -
i2c_write_byte_data SMBus write byte data -
i2c_read_word_data SMBus read word data -
i2c_write_word_data SMBus write word data -
i2c_read_block_data SMBus read block data -
i2c_write_block_data SMBus write block data -
i2c_read_i2c_block_data SMBus read I2C block data -
i2c_write_i2c_block_data SMBus write I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_process_call SMBus process call -
i2c_block_process_call SMBus block process call -
i2c_zip Performs multiple I2C transactions -
I2C BIT BANG -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs multiple bit banged I2C transactions -
I2C/SPI SLAVE -
bsc_xfer I2C/SPI as slave transfer -
bsc_i2c I2C as slave transfer -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read Reads bytes from a serial device -
serial_write Writes bytes to a serial device -
serial_data_available Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
bb_serial_read_open Open a GPIO for bit bang serial reads -
bb_serial_read_close Close a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
bb_serial_read Read bit bang serial data from a GPIO -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SPI BIT BANG -
bb_spi_open Opens GPIO for bit banging SPI -
bb_spi_close Closes GPIO for bit banging SPI -
bb_spi_xfer Transfers bytes with bit banging SPI -
FILES -
file_open Opens a file -
file_close Closes a file -
file_read Reads bytes from a file -
file_write Writes bytes to a file -
file_seek Seeks to a position within a file -
file_list List files which match a pattern -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_create_and_pad Creates a waveform of fixed size from added data -
wave_delete Deletes a waveform -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_send_using_mode Transmits a waveform in the chosen mode -
wave_chain Transmits a chain of waveforms -
wave_tx_at Returns the current transmitting waveform -
wave_tx_busy Checks to see if a waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_cbs Length in cbs of the current waveform -
wave_get_max_cbs Absolute maximum allowed cbs -
wave_get_micros Length in microseconds of the current waveform -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_max_pulses Absolute maximum allowed pulses -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpio.error_text Gets error text from error number -
pigpio.tickDiff Returns difference between two ticks -

class pi -

pigpio.pi(host, port, show_errors)

-Grants access to a Pi's GPIO. -

Parameters

host:= the host name of the Pi on which the pigpio daemon is
       running.  The default is localhost unless overridden by
       the PIGPIO_ADDR environment variable.


Parameters

port:= the port number on which the pigpio daemon is listening.
       The default is 8888 unless overridden by the PIGPIO_PORT
       environment variable.  The pigpio daemon must have been
       started with the same port number.


This connects to the pigpio daemon and reserves resources -to be used for sending commands and receiving notifications. -

An instance attribute connected may be used to check the -success of the connection. If the connection is established -successfully connected will be True, otherwise False. -

Example

pi = pigio.pi()              # use defaults
pi = pigpio.pi('mypi')       # specify host, default port
pi = pigpio.pi('mypi', 7777) # specify host and port

pi = pigpio.pi()             # exit script if no connection
if not pi.connected:
   exit()

__repr__()

-

bb_i2c_close(SDA)

-This function stops bit banging I2C on a pair of GPIO -previously opened with bb_i2c_open. -

Parameters

SDA:= 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

Example

pi.bb_i2c_close(SDA)

bb_i2c_open(SDA, SCL, baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50 -o repeated starts -o clock stretching -o I2C on any pair of spare GPIO -

Parameters

 SDA:= 0-31
 SCL:= 0-31
baud:= 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. -As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

Example

h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps

bb_i2c_zip(SDA, data)

-This function executes a sequence of bit banged I2C operations. -The operations to be performed are specified by the contents -of data which contains the concatenated command codes and -associated data. -

Parameters

 SDA:= 0-31 (as used in a prior call to bb_i2c_open)
data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.bb_i2c_zip(
                   SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0])


The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

Any read I2C data is concatenated in the returned bytearray. -

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

bb_serial_invert(user_gpio, invert)

-Invert serial logic. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)
    invert:= 0-1 (1 invert, 0 normal)


Example

status = pi.bb_serial_invert(17, 1)

bb_serial_read(user_gpio)

-Returns data from the bit bang serial cyclic buffer. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

The bytes returned for each character depend upon the number of -data bits bb_bits specified in the bb_serial_read_open -command. -

For bb_bits 1-8 there will be one byte per character. -For bb_bits 9-16 there will be two bytes per character. -For bb_bits 17-32 there will be four bytes per character. -

Example

(count, data) = pi.bb_serial_read(4)

bb_serial_read_close(user_gpio)

-Closes a GPIO for bit bang reading of serial data. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


Example

status = pi.bb_serial_read_close(17)

bb_serial_read_open(user_gpio, baud, bb_bits)

-Opens a GPIO for bit bang reading of serial data. -

Parameters

user_gpio:= 0-31, the GPIO to use.
     baud:= 50-250000, the baud rate.
  bb_bits:= 1-32, the number of bits per word, default 8.


The serial data is held in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic -buffer in a timely fashion. -

Example

status = pi.bb_serial_read_open(4, 19200)
status = pi.bb_serial_read_open(17, 9600)

bb_spi_close(CS)

-This function stops bit banging SPI on a set of GPIO -opened with bb_spi_open. -

Parameters

CS:= 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

Example

pi.bb_spi_close(CS)

bb_spi_open(CS, MISO, MOSI, SCLK, baud, spi_flags)

-This function selects a set of GPIO for bit banging SPI at a -specified baud rate. -

Parameters

      CS := 0-31
    MISO := 0-31
    MOSI := 0-31
    SCLK := 0-31
    baud := 50-250000
spiFlags := see below


spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0     0    0
 1     0    1
 2     1    0
 3     1    1


The following constants may be used to set the mode: -

pigpio.SPI_MODE_0
pigpio.SPI_MODE_1
pigpio.SPI_MODE_2
pigpio.SPI_MODE_3


Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA -may be used. -

p is 0 if CS is active low (default) and 1 for active high. -pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag. -

T is 1 if the least significant bit is transmitted on MOSI first, -the default (0) shifts the most significant bit out first. -pigpio.SPI_TX_LSBFIRST may be used to set this flag. -

R is 1 if the least significant bit is received on MISO first, -the default (0) receives the most significant bit first. -pigpio.SPI_RX_LSBFIRST may be used to set this flag. -

The other bits in spiFlags should be set to zero. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2

bb_spi_xfer(CS, data)

-This function executes a bit banged SPI transfer. -

Parameters

  CS:= 0-31 (as used in a prior call to bb_spi_open)
data:= data to be sent


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

#!/usr/bin/env python

import pigpio

CE0=5
CE1=6
MISO=13
MOSI=19
SCLK=12

pi = pigpio.pi()
if not pi.connected:
   exit()

pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC
pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC

for i in range(256):

   count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value

   if count == 2:

      count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC

      if count == 2:

         set_val = data[1]

         count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC

         if count == 3:

            read_val = ((data[1]&3)<<8) | data[2]

            print("{} {}".format(set_val, read_val))

pi.bb_spi_close(CE0)
pi.bb_spi_close(CE1)

pi.stop()

bsc_i2c(i2c_address, data)

-This function allows the Pi to act as a slave I2C device. -

This function is not available on the BCM2711 (e.g. as -used in the Pi4B). -

The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. -

Parameters

i2c_address:= the I2C slave address.
       data:= the data bytes to transmit.


The returned value is a tuple of the status, the number -of bytes read, and a bytearray containing the read bytes. -

See bsc_xfer for details of the status value. -

If there was an error the status will be less than zero -(and will contain the error code). -

Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. -

This example assumes GPIO 2/3 are connected to GPIO 18/19 -(GPIO 10/11 on the BCM2711). -

Example

#!/usr/bin/env python
import time
import pigpio

I2C_ADDR=0x13

def i2c(id, tick):
    global pi

    s, b, d = pi.bsc_i2c(I2C_ADDR)
    if b:
        if d[0] == ord('t'): # 116 send 'HH:MM:SS*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[11:19]))

        elif d[0] == ord('d'): # 100 send 'Sun Oct 30*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[:10]))

pi = pigpio.pi()

if not pi.connected:
    exit()

# Respond to BSC slave activity

e = pi.event_callback(pigpio.EVENT_BSC, i2c)

pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave

time.sleep(600)

e.cancel()

pi.bsc_i2c(0) # Disable BSC peripheral

pi.stop()


While running the above. -

$ i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

$ pigs i2co 1 0x13 0
0

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:13:58*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:14:29*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:23:16*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

bsc_xfer(bsc_control, data)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

Parameters

bsc_control:= see below
       data:= the data bytes to place in the transmit FIFO.


The returned value is a tuple of the status (see below), -the number of bytes read, and a bytearray containing the -read bytes. If there was an error the status will be less -than zero (and will contain the error code). -

Note that the control word sets the BSC mode. The BSC will -stay in that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

bsc_control consists of the following bits: -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable BSC peripheral


The status has the following format: -

20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 S  S  S  S  S  R  R  R  R  R  T  T  T  T  T RB TE RF TF RE TB


Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


Example

(status, count, data) = pi.bsc_xfer(0x330305, "Hello!")

callback(user_gpio, edge, func)

-Calls a user supplied function (a callback) whenever the -specified GPIO edge is detected. -

Parameters

user_gpio:= 0-31.
     edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.
     func:= user supplied callback function.


The user supplied callback receives three parameters, the GPIO, -the level, and the tick. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


If a user callback is not specified a default tally callback is -provided which simply counts edges. The count may be retrieved -by calling the tally function. The count may be reset to zero -by calling the reset_tally function. -

The callback may be cancelled by calling the cancel function. -

A GPIO may have multiple callbacks (although I can't think of -a reason to do so). -

The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. -

The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use read. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

Example

def cbf(gpio, level, tick):
   print(gpio, level, tick)

cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf)

cb2 = pi.callback(4, pigpio.EITHER_EDGE)

cb3 = pi.callback(17)

print(cb3.tally())

cb3.reset_tally()

cb1.cancel() # To cancel callback cb1.

clear_bank_1(bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.clear_bank_1(int("111110010000",2))

clear_bank_2(bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.clear_bank_2(0x1010)

custom_1(arg1, arg2, argx)

-Calls a pigpio function customised by the user. -

Parameters

arg1:= >=0, default 0.
arg2:= >=0, default 0.
argx:= extra arguments (each 0-255), default empty.


The returned value is an integer which by convention -should be >=0 for OK and <0 for error. -

Example

value = pi.custom_1()

value = pi.custom_1(23)

value = pi.custom_1(0, 55)

value = pi.custom_1(23, 56, [1, 5, 7])

value = pi.custom_1(23, 56, b"hello")

value = pi.custom_1(23, 56, "hello")

custom_2(arg1, argx, retMax)

-Calls a pigpio function customised by the user. -

Parameters

  arg1:= >=0, default 0.
  argx:= extra arguments (each 0-255), default empty.
retMax:= >=0, maximum number of bytes to return, default 8192.


The returned value is a tuple of the number of bytes -returned and a bytearray containing the bytes. If -there was an error the number of bytes read will be -less than zero (and will contain the error code). -

Example

(count, data) = pi.custom_2()

(count, data) = pi.custom_2(23)

(count, data) = pi.custom_2(23, [1, 5, 7])

(count, data) = pi.custom_2(23, b"hello")

(count, data) = pi.custom_2(23, "hello", 128)

delete_script(script_id)

-Deletes a stored script. -

Parameters

script_id:= id of stored script.


Example

status = pi.delete_script(sid)

event_callback(event, func)

-Calls a user supplied function (a callback) whenever the -specified event is signalled. -

Parameters

event:= 0-31.
 func:= user supplied callback function.


The user supplied callback receives two parameters, the event id, -and the tick. -

If a user callback is not specified a default tally callback is -provided which simply counts events. The count may be retrieved -by calling the tally function. The count may be reset to zero -by calling the reset_tally function. -

The callback may be cancelled by calling the event_cancel function. -

An event may have multiple callbacks (although I can't think of -a reason to do so). -

Example

def cbf(event, tick):
   print(event, tick)

cb1 = pi.event_callback(22, cbf)

cb2 = pi.event_callback(4)

print(cb2.tally())

cb2.reset_tally()

cb1.event_cancel() # To cancel callback cb1.

event_trigger(event)

-This function signals the occurrence of an event. -

Parameters

event:= 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an -interest in the event (e.g. by calling event_callback) will -be informed by a callback. -

One event, EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

Example

pi.event_trigger(23)

file_close(handle)

-Closes the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).


Example

pi.file_close(handle)

file_list(fpattern)

-Returns a list of files which match a pattern. -

Parameters

fpattern:= file pattern to match.


Returns the number of returned bytes if OK, otherwise -PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The -pattern may contain wildcards. See file_open. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

# Assumes /opt/pigpio/access contains the following line:
# /ram/*.c r

c, d = pi.file_list("/ram/p*.c")
if c > 0:
   print(d)

pi.stop()

file_open(file_name, file_mode)

-This function returns a handle to a file opened in a specified mode. -

Parameters

file_name:= the file to open.
file_mode:= the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, -PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE, -PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

Example

h = pi.file_open("/home/pi/shared/dir_3/file.txt",
        pigpio.FILE_WRITE | pigpio.FILE_CREATE)

pi.file_write(h, "Hello world")

pi.file_close(h)


File -

A file may only be opened if permission is granted by an entry -in /opt/pigpio/access. This is intended to allow remote access -to files in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries: -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files -may be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access: -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values: -

ConstantValueMeaning
FILE_READ1open file for reading
FILE_WRITE2open file for writing
FILE_RW3open file for reading and writing


The following values may be or'd into the mode: -

NameValueMeaning
FILE_APPEND4All writes append data to the end of the file
FILE_CREATE8The file is created if it doesn't exist
FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner -read and write. -

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

# Assumes /opt/pigpio/access contains the following line:
# /ram/*.c r

handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ)

done = False

while not done:
   c, d = pi.file_read(handle, 60000)
   if c > 0:
      print(d)
   else:
      done = True

pi.file_close(handle)

pi.stop()

file_read(handle, count)

-Reads up to count bytes from the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.file_read(h2, 100)
if b > 0:
   # process read data

file_seek(handle, seek_offset, seek_from)

-Seeks to a position relative to the start, current position, -or end of the file. Returns the new position. -

Parameters

     handle:= >=0 (as returned by a prior call to file_open).
seek_offset:= byte offset.
  seek_from:= FROM_START, FROM_CURRENT, or FROM_END.


Example

new_pos = pi.file_seek(h, 100, pigpio.FROM_START)

cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT)

file_size = pi.file_seek(h, 0, pigpio.FROM_END)

file_write(handle, data)

-Writes the data bytes to the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).
  data:= the bytes to write.


Example

pi.file_write(h1, b'\x02\x03\x04')

pi.file_write(h2, b'help')

pi.file_write(h2, "hello")

pi.file_write(h1, [2, 3, 4])

get_PWM_dutycycle(user_gpio)

-Returns the PWM dutycycle being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the PWM dutycycle. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported -dutycycle will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

Example

pi.set_PWM_dutycycle(4, 25)
print(pi.get_PWM_dutycycle(4))
25

pi.set_PWM_dutycycle(4, 203)
print(pi.get_PWM_dutycycle(4))
203

get_PWM_frequency(user_gpio)

-Returns the frequency of PWM being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the frequency (in Hz) used for the GPIO. -

For normal PWM the frequency will be that defined for the GPIO -by set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_frequency(4))
800

get_PWM_range(user_gpio)

-Returns the range of PWM values being used on the GPIO. -

Parameters

user_gpio:= 0-31.


If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). -

Example

pi.set_PWM_range(9, 500)
print(pi.get_PWM_range(9))
500

get_PWM_real_range(user_gpio)

-Returns the real (underlying) range of PWM values being -used on the GPIO. -

Parameters

user_gpio:= 0-31.


If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

Example

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_real_range(4))
250

get_current_tick()

-Returns the current system tick. -

Tick is the number of microseconds since system boot. As an -unsigned 32 bit quantity tick wraps around approximately -every 71.6 minutes. -

Example

t1 = pi.get_current_tick()
time.sleep(1)
t2 = pi.get_current_tick()

get_hardware_revision()

-Returns the Pi's hardware revision number. -

The hardware revision is the last few characters on the -Revision line of /proc/cpuinfo. -

The revision number can be used to determine the assignment -of GPIO to pins (see
gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

Example

print(pi.get_hardware_revision())
2

get_mode(gpio)

-Returns the GPIO mode. -

Parameters

gpio:= 0-53.


Returns a value as follows -

0 = INPUT
1 = OUTPUT
2 = ALT5
3 = ALT4
4 = ALT0
5 = ALT1
6 = ALT2
7 = ALT3


Example

print(pi.get_mode(0))
4

get_pad_strength(pad)

-This function returns the pad drive strength in mA. -

Parameters

pad:= 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = pi.get_pad_strength(0) # Get pad 0 strength.

get_pigpio_version()

-Returns the pigpio software version. -

Example

v = pi.get_pigpio_version()

get_servo_pulsewidth(user_gpio)

-Returns the servo pulsewidth being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the servo pulsewidth. -

Example

pi.set_servo_pulsewidth(4, 525)
print(pi.get_servo_pulsewidth(4))
525

pi.set_servo_pulsewidth(4, 2130)
print(pi.get_servo_pulsewidth(4))
2130

gpio_trigger(user_gpio, pulse_len, level)

-Send a trigger pulse to a GPIO. The GPIO is set to -level for pulse_len microseconds and then reset to not level. -

Parameters

user_gpio:= 0-31
pulse_len:= 1-100
    level:= 0-1


Example

pi.gpio_trigger(23, 10, 1)

hardware_PWM(gpio, PWMfreq, PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency -and dutycycle. Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_once, -wave_send_repeat, or wave_chain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. -The main clock defaults to PCM but may be overridden when the -pigpio daemon is started (option -t). -

Parameters

   gpio:= see descripton
PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711).
PWMduty:= 0 (off) to 1000000 (1M)(fully on).


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. -

The same PWM channel is available on multiple GPIO. -The latest frequency and dutycycle setting will be used -by all GPIO which share a PWM channel. -

The GPIO must be one of the following: -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps -for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 -(375 for the BCM2711). Lower frequencies will have more -steps and higher frequencies will have fewer steps. -PWMduty is automatically scaled to take this into account. -

Example

pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle

pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle

hardware_clock(gpio, clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

Parameters

   gpio:= see description
clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following: -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. -

Example

pi.hardware_clock(4, 5000) # 5 KHz clock on GPIO 4

pi.hardware_clock(4, 40000000) # 40 MHz clock on GPIO 4

i2c_block_process_call(handle, reg, data)

-Writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


The SMBus 2.0 documentation states that a minimum of 1 byte may -be sent and a minimum of 1 byte may be received. The total -number of bytes sent/received must be 32 or less. -

SMBus 2.0 5.5.8 - Block write-block read. -S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A]
   S Addr Rd [A] [Count] A [Data] ... A P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00')

(b, d) = pi.i2c_block_process_call(h, 10, b'abcdr')

(b, d) = pi.i2c_block_process_call(h, 10, "abracad")

(b, d) = pi.i2c_block_process_call(h, 10, [2, 5, 16])

i2c_close(handle)

-Closes the I2C device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).


Example

pi.i2c_close(h)

i2c_open(i2c_bus, i2c_address, i2c_flags)

-Returns a handle (>=0) for the device at the I2C bus address. -

Parameters

    i2c_bus:= >=0.
i2c_address:= 0-0x7F.
  i2c_flags:= 0, no flags are currently defined.


Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


For the SMBus commands the low level transactions are shown -at the end of the function description. The following -abbreviations are used: -

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.
Addr  (7 bits): I2C 7 bit address.
reg   (8 bits): Command byte, which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.


Example

h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1

i2c_process_call(handle, reg, word_val)

-Writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.6 - Process call. -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

r = pi.i2c_process_call(h, 4, 0x1231)
r = pi.i2c_process_call(h, 6, 0)

i2c_read_block_data(handle, reg)

-Reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.7 - Block read. -S Addr Wr [A] reg [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P


The amount of returned data is set by the device. -

The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_read_block_data(h, 10)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_byte(handle)

-Reads a single byte from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).


SMBus 2.0 5.5.3 - Receive byte. -S Addr Rd [A] [Data] NA P


Example

b = pi.i2c_read_byte(2) # read a byte from device 2

i2c_read_byte_data(handle, reg)

-Reads a single byte from the specified register of the device -associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read byte. -S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P


Example

# read byte from reg 17 of device 2
b = pi.i2c_read_byte_data(2, 17)

# read byte from reg  1 of device 0
b = pi.i2c_read_byte_data(0, 1)

i2c_read_device(handle, count)

-Returns count bytes read from the raw device associated -with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
 count:= >0, the number of bytes to read.


S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.i2c_read_device(h, 12)

i2c_read_i2c_block_data(handle, reg, count)

-Reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
 count:= >0, the number of bytes to read.


S Addr Wr [A] reg [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_read_i2c_block_data(h, 4, 32)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_word_data(handle, reg)

-Reads a single 16 bit word from the specified register of the -device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read word. -S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

# read word from reg 2 of device 3
w = pi.i2c_read_word_data(3, 2)

# read word from reg 7 of device 2
w = pi.i2c_read_word_data(2, 7)

i2c_write_block_data(handle, reg, data)

-Writes up to 32 bytes to the specified register of the device -associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


SMBus 2.0 5.5.7 - Block write. -S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A]
   datan [A] P


Example

pi.i2c_write_block_data(4, 5, b'hello')

pi.i2c_write_block_data(4, 5, "data bytes")

pi.i2c_write_block_data(5, 0, b'\x00\x01\x22')

pi.i2c_write_block_data(6, 2, [0, 1, 0x22])

i2c_write_byte(handle, byte_val)

-Sends a single byte to the device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.2 - Send byte. -S Addr Wr [A] byte_val [A] P


Example

pi.i2c_write_byte(1, 17)   # send byte   17 to device 1
pi.i2c_write_byte(2, 0x23) # send byte 0x23 to device 2

i2c_write_byte_data(handle, reg, byte_val)

-Writes a single byte to the specified register of the device -associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.4 - Write byte. -S Addr Wr [A] reg [A] byte_val [A] P


Example

# send byte 0xC5 to reg 2 of device 1
pi.i2c_write_byte_data(1, 2, 0xC5)

# send byte 9 to reg 4 of device 2
pi.i2c_write_byte_data(2, 4, 9)

i2c_write_device(handle, data)

-Writes the data bytes to the raw device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the bytes to write.


S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P


Example

pi.i2c_write_device(h, b"\x12\x34\xA8")

pi.i2c_write_device(h, b"help")

pi.i2c_write_device(h, 'help')

pi.i2c_write_device(h, [23, 56, 231])

i2c_write_i2c_block_data(handle, reg, data)

-Writes data bytes to the specified register of the device -associated with handle . 1-32 bytes may be written. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P


Example

pi.i2c_write_i2c_block_data(4, 5, 'hello')

pi.i2c_write_i2c_block_data(4, 5, b'hello')

pi.i2c_write_i2c_block_data(5, 0, b'\x00\x01\x22')

pi.i2c_write_i2c_block_data(6, 2, [0, 1, 0x22])

i2c_write_quick(handle, bit)

-Sends a single bit to the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   bit:= 0 or 1, the value to write.


SMBus 2.0 5.5.1 - Quick command. -S Addr bit [A] P


Example

pi.i2c_write_quick(0, 1) # send 1 to device 0
pi.i2c_write_quick(3, 0) # send 0 to device 3

i2c_write_word_data(handle, reg, word_val)

-Writes a single 16 bit word to the specified register of the -device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.4 - Write word. -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P


Example

# send word 0xA0C5 to reg 5 of device 4
pi.i2c_write_word_data(4, 5, 0xA0C5)

# send word 2 to reg 2 of device 5
pi.i2c_write_word_data(5, 2, 23)

i2c_zip(handle, data)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of data -which contains the concatenated command codes and associated data. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0])


The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

Any read I2C data is concatenated in the returned bytearray. -

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

notify_begin(handle, bits)

-Starts notifications on a handle. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)
  bits:= a 32 bit mask indicating the GPIO to be notified.


The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

The following code starts notifications for GPIO 1, 4, -6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_close(handle)

-Stops notifications on a handle and releases the handle for reuse. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)


Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_close(h)
   ...

notify_open()

-Returns a notification handle (>=0). -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this -function serves no purpose if you are using Python from a -remote machine. The in-built (socket) notifications -provided by
callback should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -

E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

Notifications have the following structure: -

H seqno
H flags
I tick
I level


seqno: starts at 0 each time the handle is opened and then -increments by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the -flags indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep -alive signal on the pipe/socket and is sent once a minute -in the absence of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the -flags indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps -around after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set -then GPIO x is high. -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_pause(handle)

-Pauses notifications on a handle. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)


Notifications for the handle are suspended until -notify_begin is called again. -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_pause(h)
   ...
   pi.notify_begin(h, 1234)
   ...

read(gpio)

-Returns the GPIO level. -

Parameters

gpio:= 0-53.


Example

pi.set_mode(23, pigpio.INPUT)

pi.set_pull_up_down(23, pigpio.PUD_DOWN)
print(pi.read(23))
0

pi.set_pull_up_down(23, pigpio.PUD_UP)
print(pi.read(23))
1

read_bank_1()

-Returns the levels of the bank 1 GPIO (GPIO 0-31). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is high. GPIO n has bit value (1<<n). -

Example

print(bin(pi.read_bank_1()))
0b10010100000011100100001001111

read_bank_2()

-Returns the levels of the bank 2 GPIO (GPIO 32-53). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is high. GPIO n has bit value (1<<(n-32)). -

Example

print(bin(pi.read_bank_2()))
0b1111110000000000000000

run_script(script_id, params)

-Runs a stored script. -

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.run_script(sid, [par1, par2])

s = pi.run_script(sid)

s = pi.run_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

script_status(script_id)

-Returns the run status of a stored script as well as the -current values of parameters 0 to 9. -

Parameters

script_id:= id of stored script.


The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The return value is a tuple of run status and a list of -the 10 parameters. On error the run status will be negative -and the parameter list will be empty. -

Example

(s, pars) = pi.script_status(sid)

serial_close(handle)

-Closes the serial device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


Example

pi.serial_close(h1)

serial_data_available(handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


Example

rdy = pi.serial_data_available(h1)

if rdy > 0:
   (b, d) = pi.serial_read(h1, rdy)

serial_open(tty, baud, ser_flags)

-Returns a handle for the serial tty device opened -at baud bits per second. The device name must start -with /dev/tty or /dev/serial. -

Parameters

      tty:= the serial device to open.
     baud:= baud rate in bits per second, see below.
ser_flags:= 0, no flags are currently defined.


Normally you would only use the serial_* functions if -you are or will be connecting to the Pi over a network. If -you will always run on the local Pi use the standard serial -module instead. -

The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. -

Example

h1 = pi.serial_open("/dev/ttyAMA0", 300)

h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0)

h3 = pi.serial_open("/dev/serial0", 9600)

serial_read(handle, count)

-Reads up to count bytes from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
 count:= >0, the number of bytes to read (defaults to 1000).


The returned value is a tuple of the number of bytes read and -a bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

If no data is ready a bytes read of zero is returned. -Example

(b, d) = pi.serial_read(h2, 100)
if b > 0:
   # process read data

serial_read_byte(handle)

-Returns a single byte from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


If no data is ready a negative error code will be returned. -

Example

b = pi.serial_read_byte(h1)

serial_write(handle, data)

-Writes the data bytes to the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
  data:= the bytes to write.


Example

pi.serial_write(h1, b'\x02\x03\x04')

pi.serial_write(h2, b'help')

pi.serial_write(h2, "hello")

pi.serial_write(h1, [2, 3, 4])

serial_write_byte(handle, byte_val)

-Writes a single byte to the device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to serial_open).
byte_val:= 0-255, the value to write.


Example

pi.serial_write_byte(h1, 23)

pi.serial_write_byte(h1, ord('Z'))

set_PWM_dutycycle(user_gpio, dutycycle)

-Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. -

Parameters

user_gpio:= 0-31.
dutycycle:= 0-range (range defaults to 255).


The set_PWM_range function can change the default range of 255. -

Example

pi.set_PWM_dutycycle(4,   0) # PWM off
pi.set_PWM_dutycycle(4,  64) # PWM 1/4 on
pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on
pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on
pi.set_PWM_dutycycle(4, 255) # PWM full on

set_PWM_frequency(user_gpio, frequency)

-Sets the frequency (in Hz) of the PWM to be used on the GPIO. -

Parameters

user_gpio:= 0-31.
frequency:= >=0 Hz


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4,100000)
print(pi.get_PWM_frequency(4))
8000

set_PWM_range(user_gpio, range_)

-Sets the range of PWM values to be used on the GPIO. -

Parameters

user_gpio:= 0-31.
   range_:= 25-40000.


Example

pi.set_PWM_range(9, 100)  # now  25 1/4,   50 1/2,   75 3/4 on
pi.set_PWM_range(9, 500)  # now 125 1/4,  250 1/2,  375 3/4 on
pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on

set_bank_1(bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.set_bank_1(int("111110010000",2))

set_bank_2(bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.set_bank_2(0x303)

set_glitch_filter(user_gpio, steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

Parameters

user_gpio:= 0-31
   steady:= 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback and wait_for_edge. -

It does not affect levels read by read, -read_bank_1, or read_bank_2. -

Each (stable) edge will be timestamped steady -microseconds after it was first detected. -

Example

pi.set_glitch_filter(23, 100)

set_mode(gpio, mode)

-Sets the GPIO mode. -

Parameters

gpio:= 0-53.
mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5.


Example

pi.set_mode( 4, pigpio.INPUT)  # GPIO  4 as input
pi.set_mode(17, pigpio.OUTPUT) # GPIO 17 as output
pi.set_mode(24, pigpio.ALT2)   # GPIO 24 as ALT2

set_noise_filter(user_gpio, steady, active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level -changes on the GPIO are then reported for active -microseconds after which the process repeats. -

Parameters

user_gpio:= 0-31
   steady:= 0-300000
   active:= 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback and wait_for_edge. -

It does not affect levels read by read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

Example

pi.set_noise_filter(23, 1000, 5000)

set_pad_strength(pad, pad_strength)

-This function sets the pad drive strength in mA. -

Parameters

         pad:= 0-2, the pad to set.
pad_strength:= 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA.

set_pull_up_down(gpio, pud)

-Sets or clears the internal GPIO pull-up/down resistor. -

Parameters

gpio:= 0-53.
 pud:= PUD_UP, PUD_DOWN, PUD_OFF.


Example

pi.set_pull_up_down(17, pigpio.PUD_OFF)
pi.set_pull_up_down(23, pigpio.PUD_UP)
pi.set_pull_up_down(24, pigpio.PUD_DOWN)

set_servo_pulsewidth(user_gpio, pulsewidth)

-Starts (500-2500) or stops (0) servo pulses on the GPIO. -

Parameters

 user_gpio:= 0-31.
pulsewidth:= 0 (off),
             500 (most anti-clockwise) - 2500 (most clockwise).


The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably -be determined by experiment. A value of 1500 should always be -safe and represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its -limits. -

Example

pi.set_servo_pulsewidth(17, 0)    # off
pi.set_servo_pulsewidth(17, 1000) # safe anti-clockwise
pi.set_servo_pulsewidth(17, 1500) # centre
pi.set_servo_pulsewidth(17, 2000) # safe clockwise

set_watchdog(user_gpio, wdog_timeout)

-Sets a watchdog timeout for a GPIO. -

Parameters

   user_gpio:= 0-31.
wdog_timeout:= 0-60000.


The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO -will be triggered every timeout interval after the last -GPIO activity. -

The callback will receive the special level TIMEOUT. -

Example

pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23
pi.set_watchdog(23, 0)    # cancel watchdog on GPIO 23

shell(shellscr, pstring)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

Parameters

shellscr:= the name of the script, only alphanumerics,
              '-' and '_' are allowed in the name
pstring := the parameter string to pass to the script


The exit status of the system call is returned if OK, -otherwise PI_BAD_SHELL_STATUS. -

shellscr must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by -the shell script exit function. If the script can't be -found 32512 will be returned. -

The following table gives some example returned statuses: -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = pi.shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = pi.shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = pi.shell("scr1", "\"hello string with spaces world\"");

spi_close(handle)

-Closes the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).


Example

pi.spi_close(h)

spi_open(spi_channel, baud, spi_flags)

-Returns a handle for the SPI device on the channel. Data -will be transferred at baud bits per second. The flags -may be used to modify the default behaviour of 4-wire -operation, mode 0, active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


Parameters

spi_channel:= 0-1 (0-2 for the auxiliary SPI).
       baud:= 32K-125M (values above 30M are unlikely to work).
  spi_flags:= see below.


spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

WARNING: modes 1 and 3 do not appear to work on -the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per character. -For bits 9-16 there will be two bytes per character. -For bits 17-32 there will be four bytes per character. -

Multi-byte transfers are made in least significant byte -first order. -

E.g. to transfer 32 11-bit words data should -contain 64 bytes. -

E.g. to transfer the 14 bit value 0x1ABC send the -bytes 0xBC followed by 0x1A. -

The other bits in flags should be set to zero. -

Example

# open SPI device on channel 1 in mode 3 at 50000 bits per second

h = pi.spi_open(1, 50000, 3)

spi_read(handle, count)

-Reads count bytes from the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.spi_read(h, 60) # read 60 bytes from device h
if b == 60:
   # process read data
else:
   # error path

spi_write(handle, data)

-Writes the data bytes to the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


Example

pi.spi_write(0, b'\x02\xc0\x80') # write 3 bytes to device 0

pi.spi_write(0, b'defgh')        # write 5 bytes to device 0

pi.spi_write(0, "def")           # write 3 bytes to device 0

pi.spi_write(1, [2, 192, 128])   # write 3 bytes to device 1

spi_xfer(handle, data)

-Writes the data bytes to the SPI device associated with handle, -returning the data bytes read from the device. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00')

(count, rx_data) = pi.spi_xfer(h, [1, 128, 0])

(count, rx_data) = pi.spi_xfer(h, b"hello")

(count, rx_data) = pi.spi_xfer(h, "hello")

stop()

-Release pigpio resources. -

Example

pi.stop()

stop_script(script_id)

-Stops a running script. -

Parameters

script_id:= id of stored script.


Example

status = pi.stop_script(sid)

store_script(script)

-Store a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for -details. -

Parameters

script:= the script text as a series of bytes.


Returns a >=0 script id if OK. -

Example

sid = pi.store_script(
   b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0')

update_script(script_id, params)

-Sets the parameters of a script. The script may or -may not be running. The first parameters of the script are -overwritten with the new values. -

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.update_script(sid, [par1, par2])

s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

wait_for_edge(user_gpio, edge, wait_timeout)

-Wait for an edge event on a GPIO. -

Parameters

   user_gpio:= 0-31.
        edge:= EITHER_EDGE, RISING_EDGE (default), or
               FALLING_EDGE.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the edge is detected or after -the number of seconds specified by timeout has expired. -

Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a callback function. -

The function returns True if the edge is detected, -otherwise False. -

Example

if pi.wait_for_edge(23):
   print("Rising edge detected")
else:
   print("wait for edge timed out")

if pi.wait_for_edge(23, pigpio.FALLING_EDGE, 5.0):
   print("Falling edge detected")
else:
   print("wait for falling edge timed out")

wait_for_event(event, wait_timeout)

-Wait for an event. -

Parameters

       event:= 0-31.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the event is signalled or after -the number of seconds specified by timeout has expired. -

The function returns True if the event is detected, -otherwise False. -

Example

if pi.wait_for_event(23):
   print("event detected")
else:
   print("wait for event timed out")

wave_add_generic(pulses)

-Adds a list of pulses to the current waveform. -

Parameters

pulses:= list of pulses to add to the waveform.


Returns the new total number of pulses in the current waveform. -

The pulses are interleaved in time order within the existing -waveform (if any). -

Merging allows the waveform to be built in parts, that is the -settings for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within -the existing waveform then the first pulse should consist -solely of a delay. -

Example

G1=4
G2=24

pi.set_mode(G1, pigpio.OUTPUT)
pi.set_mode(G2, pigpio.OUTPUT)

flash_500=[] # flash every 500 ms
flash_100=[] # flash every 100 ms

#                              ON     OFF  DELAY

flash_500.append(pigpio.pulse(1<<G1, 1<<G2, 500000))
flash_500.append(pigpio.pulse(1<<G2, 1<<G1, 500000))

flash_100.append(pigpio.pulse(1<<G1, 1<<G2, 100000))
flash_100.append(pigpio.pulse(1<<G2, 1<<G1, 100000))

pi.wave_clear() # clear any existing waveforms

pi.wave_add_generic(flash_500) # 500 ms flashes
f500 = pi.wave_create() # create and save id

pi.wave_add_generic(flash_100) # 100 ms flashes
f100 = pi.wave_create() # create and save id

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_send_repeat(f100)

time.sleep(4)

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_tx_stop() # stop waveform

pi.wave_clear() # clear all waveforms

wave_add_new()

-Starts a new empty waveform. -

You would not normally need to call this function as it is -automatically called after a waveform is created with the -
wave_create function. -

Example

pi.wave_add_new()

wave_add_serial(user_gpio, baud, data, offset, bb_bits, bb_stop)

-Adds a waveform representing serial data to the existing -waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

Parameters

user_gpio:= GPIO to transmit data.  You must set the GPIO mode
            to output.
     baud:= 50-1000000 bits per second.
     data:= the bytes to write.
   offset:= number of microseconds from the start of the
            waveform, default 0.
  bb_bits:= number of data bits, default 8.
  bb_stop:= number of stop half bits, default 2.


Returns the new total number of pulses in the current waveform. -

The serial data is formatted as one start bit, bb_bits -data bits, and bb_stop/2 stop bits. -

It is legal to add serial data streams with different baud -rates to the same waveform. -

The bytes required for each character depend upon bb_bits. -

For bb_bits 1-8 there will be one byte per character. -For bb_bits 9-16 there will be two bytes per character. -For bb_bits 17-32 there will be four bytes per character. -

Example

pi.wave_add_serial(4, 300, 'Hello world')

pi.wave_add_serial(4, 300, b"Hello world")

pi.wave_add_serial(4, 300, b'\x23\x01\x00\x45')

pi.wave_add_serial(17, 38400, [23, 128, 234], 5000)

wave_chain(data)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM -will be cancelled. -

The waves to be transmitted are specified by the contents -of data which contains an ordered list of wave_ids -and optional command codes and related data. -

Returns 0 if OK, otherwise PI_CHAIN_NESTING, -PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, -PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, -or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave -may occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by -using the loop commands. The block is bracketed by loop -start and end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#!/usr/bin/env python

import time
import pigpio

WAVES=5
GPIO=4

wid=[0]*WAVES

pi = pigpio.pi() # Connect to local Pi.

pi.set_mode(GPIO, pigpio.OUTPUT);

for i in range(WAVES):
   pi.wave_add_generic([
      pigpio.pulse(1<<GPIO, 0, 20),
      pigpio.pulse(0, 1<<GPIO, (i+1)*200)]);

   wid[i] = pi.wave_create();

pi.wave_chain([
   wid[4], wid[3], wid[2],       # transmit waves 4+3+2
   255, 0,                       # loop start
      wid[0], wid[0], wid[0],    # transmit waves 0+0+0
      255, 0,                    # loop start
         wid[0], wid[1],         # transmit waves 0+1
         255, 2, 0x88, 0x13,     # delay 5000us
      255, 1, 30, 0,             # loop end (repeat 30 times)
      255, 0,                    # loop start
         wid[2], wid[3], wid[0], # transmit waves 2+3+0
         wid[3], wid[1], wid[2], # transmit waves 3+1+2
      255, 1, 10, 0,             # loop end (repeat 10 times)
   255, 1, 5, 0,                 # loop end (repeat 5 times)
   wid[4], wid[4], wid[4],       # transmit waves 4+4+4
   255, 2, 0x20, 0x4E,           # delay 20000us
   wid[0], wid[0], wid[0],       # transmit waves 0+0+0
   ])

while pi.wave_tx_busy():
   time.sleep(0.1);

for i in range(WAVES):
   pi.wave_delete(wid[i])

pi.stop()

wave_clear()

-Clears all waveforms and any data added by calls to the -wave_add_* functions. -

Example

pi.wave_clear()

wave_create()

-Creates a waveform from the data provided by the prior calls -to the wave_add_* functions. -

Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the wave_add_* functions is consumed by -this function. -

As many waveforms may be created as there is space available. -The wave id is passed to wave_send_* to specify the waveform -to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. -

A pulse specifies -

1) the GPIO to be switched on at the start of the pulse. -2) the GPIO to be switched off at the start of the pulse. -3) the delay in microseconds before the next pulse. -

Any or all the fields can be zero. It doesn't make any sense -to set all the fields to zero (the pulse will be ignored). -

When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. -

Example

wid = pi.wave_create()

wave_create_and_pad(percent)

-This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use -(in terms of the theoretical maximum, not the current amount free). -This allows the reuse of deleted waves while a transmission is active. -

Upon success a wave id greater than or equal to 0 is returned, otherwise -PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

A usage would be the creation of two waves where one is filled while the -other is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Normal usage: -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create_and_pad to create a waveform of uniform size. -

Step 4. wave_send_* with the id of the waveform to transmit. -

Repeat steps 2-4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

Example

wid = pi.wave_create_and_pad(50)

wave_delete(wave_id)

-This function deletes the waveform with id wave_id. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Example

pi.wave_delete(6) # delete waveform with id 6

pi.wave_delete(0) # delete waveform with id 0

wave_get_cbs()

-Returns the length in DMA control blocks of the current -waveform. -

Example

cbs = pi.wave_get_cbs()

wave_get_max_cbs()

-Returns the maximum possible size of a waveform in DMA -control blocks. -

Example

cbs = pi.wave_get_max_cbs()

wave_get_max_micros()

-Returns the maximum possible size of a waveform in microseconds. -

Example

micros = pi.wave_get_max_micros()

wave_get_max_pulses()

-Returns the maximum possible size of a waveform in pulses. -

Example

pulses = pi.wave_get_max_pulses()

wave_get_micros()

-Returns the length in microseconds of the current waveform. -

Example

micros = pi.wave_get_micros()

wave_get_pulses()

-Returns the length in pulses of the current waveform. -

Example

pulses = pi.wave_get_pulses()

wave_send_once(wave_id)

-Transmits the waveform with id wave_id. The waveform is sent -once. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_once(wid)

wave_send_repeat(wave_id)

-Transmits the waveform with id wave_id. The waveform repeats -until wave_tx_stop is called or another call to wave_send_* -is made. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_repeat(wid)

wave_send_using_mode(wave_id, mode)

-Transmits the waveform with id wave_id using mode mode. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).
   mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT,
          WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC.


WAVE_MODE_ONE_SHOT: same as wave_send_once. -

WAVE_MODE_REPEAT same as wave_send_repeat. -

WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries -to sync with the previous waveform. -

WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries -to sync with the previous waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC)

wave_tx_at()

-Returns the id of the waveform currently being -transmitted. -

Returns the waveform id or one of the following special -values: -

WAVE_NOT_FOUND (9998) - transmitted wave not found. -NO_TX_WAVE (9999) - no wave being transmitted. -

Example

wid = pi.wave_tx_at()

wave_tx_busy()

-Returns 1 if a waveform is currently being transmitted, -otherwise 0. -

Example

pi.wave_send_once(0) # send first waveform

while pi.wave_tx_busy(): # wait for waveform to be sent
   time.sleep(0.1)

pi.wave_send_once(1) # send next waveform

wave_tx_repeat()

-This function is deprecated and has beeen removed. -

Use
wave_create/wave_send_* instead. -

wave_tx_start()

-This function is deprecated and has been removed. -

Use
wave_create/wave_send_* instead. -

wave_tx_stop()

-Stops the transmission of the current waveform. -

This function is intended to stop a waveform started with -wave_send_repeat. -

Example

pi.wave_send_repeat(3)

time.sleep(5)

pi.wave_tx_stop()

write(gpio, level)

-Sets the GPIO level. -

Parameters

 GPIO:= 0-53.
level:= 0, 1.


If PWM or servo pulses are active on the GPIO they are -switched off. -

Example

pi.set_mode(17, pigpio.OUTPUT)

pi.write(17,0)
print(pi.read(17))
0

pi.write(17,1)
print(pi.read(17))
1

class pulse -

pigpio.pulse(gpio_on, gpio_off, delay)

-Initialises a pulse. -

Parameters

 gpio_on:= the GPIO to switch on at the start of the pulse.
gpio_off:= the GPIO to switch off at the start of the pulse.
   delay:= the delay in microseconds before the next pulse.

FUNCTIONS

pigpio.error_text(errnum)

-Returns a text description of a pigpio error. -

Parameters

errnum:= <0, the error number


Example

print(pigpio.error_text(-5))
level not 0-1

pigpio.tickDiff(t1, t2)

-Returns the microsecond difference between two ticks. -

Parameters

t1:= the earlier tick
t2:= the later tick


Example

print(pigpio.tickDiff(4294967272, 12))
36

pigpio.u2i(uint32)

-Converts a 32 bit unsigned number to signed. -

Parameters

uint32:= an unsigned 32 bit number


Example

print(u2i(4294967272))
-24
print(u2i(37))
37

PARAMETERS

active: 0-1000000

The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

arg1:

An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2:

An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argx:

An array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud:

The speed of serial communication (I2C, SPI, serial link, waves) -in bits per second. -

bb_bits: 1-32

The number of data bits to be used when adding serial data to a -waveform. -

bb_stop: 2-8

The number of (half) stop bits to be used when adding serial data -to a waveform. -

bit: 0-1

A value of 0 or 1. -

bits: 32 bit number

A mask used to select GPIO to be operated on. If bit n is set -then GPIO n is selected. A convenient way of setting bit n is to -bit or in the value (1<<n). -

To select GPIO 1, 7, 23 -

bits = (1<<1) | (1<<7) | (1<<23) -

bsc_control:

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) -

Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document. -

byte_val: 0-255

A whole number. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

The hardware clock frequency. -

connected:

True if a connection was established, False otherwise. -

count:

The number of bytes of data to be transferred. -

CS:

The GPIO used for the slave select signal when bit banging SPI. -

data:

Data to be transmitted, a series of bytes. -

delay: >=1

The length of a pulse in microseconds. -

dutycycle: 0-range_

A number between 0 and range_. -

The dutycycle sets the proportion of time on versus time off during each -PWM cycle. -

DutycycleOn time
0Off
range_ * 0.2525% On
range_ * 0.5050% On
range_ * 0.7575% On
range_Fully On

edge: 0-2

EITHER_EDGE = 2
FALLING_EDGE = 1
RISING_EDGE = 0

errnum: <0

PI_BAD_USER_GPIO = -2
PI_BAD_GPIO = -3
PI_BAD_MODE = -4
PI_BAD_LEVEL = -5
PI_BAD_PUD = -6
PI_BAD_PULSEWIDTH = -7
PI_BAD_DUTYCYCLE = -8
PI_BAD_WDOG_TIMEOUT = -15
PI_BAD_DUTYRANGE = -21
PI_NO_HANDLE = -24
PI_BAD_HANDLE = -25
PI_BAD_WAVE_BAUD = -35
PI_TOO_MANY_PULSES = -36
PI_TOO_MANY_CHARS = -37
PI_NOT_SERIAL_GPIO = -38
PI_NOT_PERMITTED = -41
PI_SOME_PERMITTED = -42
PI_BAD_WVSC_COMMND = -43
PI_BAD_WVSM_COMMND = -44
PI_BAD_WVSP_COMMND = -45
PI_BAD_PULSELEN = -46
PI_BAD_SCRIPT = -47
PI_BAD_SCRIPT_ID = -48
PI_BAD_SER_OFFSET = -49
PI_GPIO_IN_USE = -50
PI_BAD_SERIAL_COUNT = -51
PI_BAD_PARAM_NUM = -52
PI_DUP_TAG = -53
PI_TOO_MANY_TAGS = -54
PI_BAD_SCRIPT_CMD = -55
PI_BAD_VAR_NUM = -56
PI_NO_SCRIPT_ROOM = -57
PI_NO_MEMORY = -58
PI_SOCK_READ_FAILED = -59
PI_SOCK_WRIT_FAILED = -60
PI_TOO_MANY_PARAM = -61
PI_SCRIPT_NOT_READY = -62
PI_BAD_TAG = -63
PI_BAD_MICS_DELAY = -64
PI_BAD_MILS_DELAY = -65
PI_BAD_WAVE_ID = -66
PI_TOO_MANY_CBS = -67
PI_TOO_MANY_OOL = -68
PI_EMPTY_WAVEFORM = -69
PI_NO_WAVEFORM_ID = -70
PI_I2C_OPEN_FAILED = -71
PI_SER_OPEN_FAILED = -72
PI_SPI_OPEN_FAILED = -73
PI_BAD_I2C_BUS = -74
PI_BAD_I2C_ADDR = -75
PI_BAD_SPI_CHANNEL = -76
PI_BAD_FLAGS = -77
PI_BAD_SPI_SPEED = -78
PI_BAD_SER_DEVICE = -79
PI_BAD_SER_SPEED = -80
PI_BAD_PARAM = -81
PI_I2C_WRITE_FAILED = -82
PI_I2C_READ_FAILED = -83
PI_BAD_SPI_COUNT = -84
PI_SER_WRITE_FAILED = -85
PI_SER_READ_FAILED = -86
PI_SER_READ_NO_DATA = -87
PI_UNKNOWN_COMMAND = -88
PI_SPI_XFER_FAILED = -89
PI_NO_AUX_SPI = -91
PI_NOT_PWM_GPIO = -92
PI_NOT_SERVO_GPIO = -93
PI_NOT_HCLK_GPIO = -94
PI_NOT_HPWM_GPIO = -95
PI_BAD_HPWM_FREQ = -96
PI_BAD_HPWM_DUTY = -97
PI_BAD_HCLK_FREQ = -98
PI_BAD_HCLK_PASS = -99
PI_HPWM_ILLEGAL = -100
PI_BAD_DATABITS = -101
PI_BAD_STOPBITS = -102
PI_MSG_TOOBIG = -103
PI_BAD_MALLOC_MODE = -104
PI_BAD_SMBUS_CMD = -107
PI_NOT_I2C_GPIO = -108
PI_BAD_I2C_WLEN = -109
PI_BAD_I2C_RLEN = -110
PI_BAD_I2C_CMD = -111
PI_BAD_I2C_BAUD = -112
PI_CHAIN_LOOP_CNT = -113
PI_BAD_CHAIN_LOOP = -114
PI_CHAIN_COUNTER = -115
PI_BAD_CHAIN_CMD = -116
PI_BAD_CHAIN_DELAY = -117
PI_CHAIN_NESTING = -118
PI_CHAIN_TOO_BIG = -119
PI_DEPRECATED = -120
PI_BAD_SER_INVERT = -121
PI_BAD_FOREVER = -124
PI_BAD_FILTER = -125
PI_BAD_PAD = -126
PI_BAD_STRENGTH = -127
PI_FIL_OPEN_FAILED = -128
PI_BAD_FILE_MODE = -129
PI_BAD_FILE_FLAG = -130
PI_BAD_FILE_READ = -131
PI_BAD_FILE_WRITE = -132
PI_FILE_NOT_ROPEN = -133
PI_FILE_NOT_WOPEN = -134
PI_BAD_FILE_SEEK = -135
PI_NO_FILE_MATCH = -136
PI_NO_FILE_ACCESS = -137
PI_FILE_IS_A_DIR = -138
PI_BAD_SHELL_STATUS = -139
PI_BAD_SCRIPT_NAME = -140
PI_BAD_SPI_BAUD = -141
PI_NOT_SPI_GPIO = -142
PI_BAD_EVENT_ID = -143
PI_CMD_INTERRUPTED = -144
PI_NOT_ON_BCM2711   = -145
PI_ONLY_ON_BCM2711  = -146

event: 0-31

An event is a signal used to inform one or more consumers -to start an action. -

file_mode:

The mode may have the following values -

FILE_READ   1
FILE_WRITE  2
FILE_RW     3


The following values can be or'd into the file open mode -

FILE_APPEND 4
FILE_CREATE 8
FILE_TRUNC  16

file_name:

A full file path. To be accessible the path must match -an entry in /opt/pigpio/access. -

fpattern:

A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: 0-40000

Defines the frequency to be used for PWM on a GPIO. -The closest permitted frequency will be used. -

func:

A user supplied callback function. -

gpio: 0-53

A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. -

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 get_hardware_revision. -

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  -  -  -  -

gpio_off:

A mask used to select GPIO to be operated on. See bits. -

This mask selects the GPIO to be switched off at the start -of a pulse. -

gpio_on:

A mask used to select GPIO to be operated on. See bits. -

This mask selects the GPIO to be switched on at the start -of a pulse. -

handle: >=0

A number referencing an object opened by one of the following -

file_open -i2c_open -notify_open -serial_open -spi_open -

host:

The name or IP address of the Pi running the pigpio daemon. -

i2c_address: 0-0x7F

The address of a device on the I2C bus. -

i2c_bus: >=0

An I2C bus number. -

i2c_flags: 0

No I2C flags are currently defined. -

invert: 0-1

A flag used to set normal or inverted bit bang serial data -level logic. -

level: 0-1 (2)

CLEAR = 0
HIGH = 1
LOW = 0
OFF = 0
ON = 1
SET = 1
TIMEOUT = 2 # only returned for a watchdog timeout

MISO:

The GPIO used for the MISO signal when bit banging SPI. -

mode:

1.The operational mode of a GPIO, normally INPUT or OUTPUT. -

ALT0 = 4
ALT1 = 5
ALT2 = 6
ALT3 = 7
ALT4 = 3
ALT5 = 2
INPUT = 0
OUTPUT = 1


2. The mode of waveform transmission. -

WAVE_MODE_ONE_SHOT = 0
WAVE_MODE_REPEAT = 1
WAVE_MODE_ONE_SHOT_SYNC = 2
WAVE_MODE_REPEAT_SYNC = 3

MOSI:

The GPIO used for the MOSI signal when bit banging SPI. -

offset: >=0

The offset wave data starts from the beginning of the waveform -being currently defined. -

pad: 0-2

A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

pad_strength: 1-16

The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

params: 32 bit number

When scripts are started they can receive up to 10 parameters -to define their operation. -

percent: : 0-100

The size of waveform as percentage of maximum available. -

port:

The port used by the pigpio daemon, defaults to 8888. -

pstring:

The string to be passed to a shell script to be executed. -

pud: 0-2

PUD_DOWN = 1
PUD_OFF = 0
PUD_UP = 2

pulse_len: 1-100

The length of the trigger pulse in microseconds. -

pulses:

A list of class pulse objects defining the characteristics of a -waveform. -

pulsewidth:

The servo pulsewidth in microseconds. 0 switches pulses off. -

PWMduty: 0-1000000 (1M)

The hardware PWM dutycycle. -

PWMfreq: 1-125M (1-187.5M for the BCM2711)

The hardware PWM frequency. -

range_: 25-40000

Defines the limits for the dutycycle parameter. -

range_ defaults to 255. -

reg: 0-255

An I2C device register. The usable registers depend on the -actual device. -

retMax: >=0

The maximum number of bytes a user customised function -should return, default 8192. -

SCL:

The user GPIO to use for the clock when bit banging I2C. -

SCLK: :

The GPIO used for the SCLK signal when bit banging SPI. -

script:

The text of a script to store on the pigpio daemon. -

script_id: >=0

A number referencing a script created by store_script. -

SDA:

The user GPIO to use for data when bit banging I2C. -

seek_from: 0-2

Direction to seek for file_seek. -

FROM_START=0
FROM_CURRENT=1
FROM_END=2

seek_offset:

The number of bytes to move forward (positive) or backwards -(negative) from the seek position (start, current, or end of file). -

ser_flags: 32 bit

No serial flags are currently defined. -

serial_*:

One of the serial_ functions. -

shellscr:

The name of a shell script. The script must exist -in /opt/pigpio/cgi and must be executable. -

show_errors:

Controls the display of pigpio daemon connection failures. -The default of True prints the probable failure reasons to -standard output. -

spi_channel: 0-2

A SPI channel. -

spi_flags: 32 bit

See spi_open. -

steady: 0-300000

The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) -or triggering the active part of a noise filter -(set_noise_filter). -

t1:

A tick (earlier). -

t2:

A tick (later). -

tty:

A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0 -

uint32:

An unsigned 32 bit number. -

user_gpio: 0-31

A Broadcom numbered GPIO. -

All the user GPIO are in the range 0-31. -

Not all the GPIO within this range are usable, some are reserved -for system use. -

See gpio. -

wait_timeout: 0.0 -

The number of seconds to wait in wait_for_edge before timing out. -

wave_add_*:

One of the following -

wave_add_new -wave_add_generic -wave_add_serial -

wave_id: >=0

A number referencing a wave created by wave_create. -

wave_send_*:

One of the following -

wave_send_once -wave_send_repeat -

wdog_timeout: 0-60000

Defines a GPIO watchdog timeout in milliseconds. If no level -change is detected on the GPIO for timeout millisecond a watchdog -timeout report is issued (with level TIMEOUT). -

word_val: 0-65535

A whole number. -

- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/sif.html b/DOC/HTML/sif.html deleted file mode 100644 index bbaa6e1..0000000 --- a/DOC/HTML/sif.html +++ /dev/null @@ -1,2058 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Socket Interface

-pigpio provides a socket interface to many of its functions.
-
-The socket interface is available whenever pigpio is running, -either because it has been started as a daemon, or it has been -linked in to a running user program.
-
-The socket interface can be disabled by the program which -initialises the library.  pigpiod offers the -k option to -disable the socket interface.  User programs should call -gpioCfgInterfaces if they -wish to disable the socket interface.
-
-pigpio listens for connections on port 8888 by default.  This -default may be overridden when pigpio starts by the gpioCfgSocketPort function -call.  The pigpio daemon uses this function to provide an -option to change the port number.
-
-The pigs utility is an example of using the socket interface from -C.
-

Request

-

pigpio expects messages of type cmdCmd_t immediately followed with an -extension for a few commands.
-
-The caller should fill in cmd, p1, p2, p3/res, and any extension as -needed.  p3 will always be zero unless the command requires an -extension in which case p3 will be the length in bytes of the -extension.
-
-The cmdCmd_t is echoed back with -the result, if any, in p3/res, and an extension immediately -afterwards for a few commands.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
COMMANDcmd
p1p2p3Extension
MODES0gpiomode0-
MODEG1gpio00-
PUD2gpiopud0-
READ3gpio00-
WRITE4gpiolevel0-
PWM5gpiodutycycle0-
PRS6gpiorange0-
PFS7gpiofrequency0-
SERVO8gpiopulsewidth0-
WDOG9gpiotimeout0-
BR110000-
BR211000-
BC112bits00-
BC213bits00-
BS114bits00-
BS215bits00-
TICK16000-
HWVER17000-
NO18000-
NB19handlebits0-
NP20handle00-
NC21handle00-
PRG22gpio00-
PFG23gpio00-
PRRG24gpio00-
HELP
25N/A
N/A
N/A
N/A
PIGPV26000-
WVCLR27000-
WVAG280012*XgpioPulse_t pulse[X]
WVAS29gpiobaud12+Xuint32_t databits
-uint32_t stophalfbits
-uint32_t offset
-uint8_t data[X]
N/A
30000-
N/A
31000-
WVBSY32000-
WVHLT33000-
WVSM34subcmd00-
WVSP35subcmd00-
WVSC36subcmd00-
TRIG37gpiopulselen4uint32_t level
PROC3800Xuint8_t text[X]
PROCD39script_id00-
PROCR40script_id04*X
uint32_t pars[X]
PROCS41script_id00-
SLRO42gpiobaud4uint32_t databits
SLR43gpiocount0-
SLRC44gpio00-
PROCP45script_id00-
MICS46micros00-
MILS47millis00-
PARSE48N/AN/A
N/A
N/A
WVCRE49000-
WVDEL50wave_id00-
WVTX51wave_id00-
WVTXR52wave_id00-
WVNEW53000-
I2CO54busdevice4uint32_t flags
I2CC55handle00-
I2CRD56handlecount0-
I2CWD57handle0Xuint8_t data[X]
I2CWQ58handlebit0-
I2CRS59handle00-
I2CWS60handlebyte0-
I2CRB61handleregister0-
I2CWB62handleregister4uint32_t byte
I2CRW63handleregister0-
I2CWW64handleregister4uint32_t word
I2CRK65handleregister
0-
I2CWK66handleregister
Xuint8_t bvs[X]
I2CRI67handleregister
4uint32_t num
I2CWI68handleregister
X
uint8_t bvs[X]
I2CPC69handleregister
4uint32_t word
I2CPK70handleregister
X
uint8_t data[X]
SPIO
71channelbaud4uint32_t flags
SPIC72handle00-
SPIR73handlecount0-
SPIW74handle0Xuint8_t data[X]
SPIX75handle0Xuint8_t data[X]
SERO76baudflagsXuint8_t device[X]
SERC77handle00-
SERRB78handle00-
SERWB79handlebyte0-
SERR80handlecount0-
SERW81handle0Xuint8_t data[X]
SERDA82handle00-
GDC
83
gpio
0
0
-
GPW
84
gpio
0
0
-
HC
85
gpio
frequency
0
-
HP
86
gpio
frequency
4
uint32_t dutycycle
CF1
87
arg1
arg2
X
uint8_t argx[X]
CF2
88
arg1
retMax
X
uint8_t argx[X]
BI2CC
89
sda
0
0
-
BI2CO
90
sda
scl
4
uint32_t baud
BI2CZ
91
sda
0
X
uint8_t data[X]
I2CZ
92
handle
0
X
uint8_t data[X]
WVCHA
93
0
0
X
uint8_t data[X]
SLRI
94
gpio
invert
0
-
CGI
95
0
0
0
-
CSI
96
config
0
0
-
FG
97
gpio
steady
0
-
FN
98
gpio
steady
4
uint32_t active
NOIB99000-
WVTXM
100
wave_id
mode
0
-
WVTAT
101
0
0
0
-
PADS
102
pad
strength
0
-
PADG
103
pad
0
0
-
FO
104
mode
0
X
uint8_t file[X]
FC
105
handle
0
0
-
FR
106
handle
count
0
-
FW
107
handle
0
X
uint8_t data[X]
FS
108
handle
offset
4
uint32_t from
FL
109
count
0
X
uint8_t pattern[X]
SHELL
110
len(name)
0
len(name)+
-1+
-len(string)
uint8_t name[len(name)]
-uint8_t null (0)
-uint8_t string[len(string)]
BSPIC
111
CS
0
0
-
BSPIO
112
CS
0
20
uint32_t MISO
-uint32_t MOSI
-uint32_t SCLK
-uint32_t baud
-uint32_t spi_flags
BSPIX
113
CS
0
X
uint8_t data[X]
BSCX
114
control
0
X
uint8_t data[X]
EVM
115
handle
bits
0
-
EVT
116
event
0
0
-
PROCU
117
script_id
0
4*X
uint32_t pars[X]
-

Response

-

The response has cmd/p1/p2 as in the request.  p3/res holds -the return value.  If the command returns additional values -they will be in the immediately following extension.

-Normally res should be treated as a 32 bit signed value and will be -greater than or equal to zero.  Upon failure res will be less -than 0 and contains an error code.
-

There are a few commands where the returned value should be -treated as a 32 bit unsigned value.  These commands can not -fail.  They are indicated with a * after the command -name.

-

Commands with an extension have the size of the extension in -bytes returned in res (or <0 on error as above).

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
COMMANDcmd
p1
p2
res
Extension
MODES0-
-
0-
MODEG1-
-
mode
-
PUD2-
-
0-
READ3-
-
level
-
WRITE4-
-
0-
PWM5-
-
0-
PRS6-
-
0-
PFS7-
-
0-
SERVO8-
-
0-
WDOG9-
-
0-
BR1 *10-
-
bits
-
BR2 *11-
-
bits
-
BC112-
-
0-
BC213-
-
0-
BS114-
-
0-
BS215-
-
0-
TICK *
16-
-
tick
-
HWVER *
17-
-
version
-
NO18-
-
handle
-
NB19-
-
0-
NP20-
-
0-
NC21-
-
0-
PRG22-
-
range
-
PFG23-
-
frequency
-
PRRG24-
-
real range
-
HELP25-
-
N/A
N/A
PIGPV *
26-
-
version
-
WVCLR27-
-
0-
WVAG28-
-
wave pulses
-
WVAS29-
-
wave pulses
-
N/A
30-
-
-
-
N/A
31-
-
-
-
WVBSY32-
-
busy (1) or not busy (0)
-
WVHLT33-
-
0-
WVSM34-
-
wave micros
-wave micros - high
-wave micros - max
-
WVSP35-
-
wave pulses
-wave pulses - high
-wave pulses - max
-
WVSC36-
-
wave DMA CBs
-wave DMA CBs - high
-wave DMA CBs - max
-
TRIG37-
-
0
-
PROC38-
-
script id
-
PROCD39-
-
0-
PROCR40-
-
script status
-
PROCS41-
-
0-
SLRO42-
-
0
-
SLR43-
-
X
uint8_t data[X]
SLRC44-
-
0-
PROCP45-
-
44uint32_t script_status
-uint32_t pars[10]
MICS46-
-
0-
MILS47-
-
0-
PARSE48-
-
N/A
-
WVCRE49-
-
wave id
-
WVDEL50-
-
0-
WVTX51-
-
wave DMA CBs
-
WVTXR52-
-
wave DMA CBs
-
WVNEW53-
-
0-
I2CO54-
-
handle-
I2CC55-
-
0-
I2CRD56-
-
X
uint8_t data[X]
I2CWD57-
-
0
-
I2CWQ58-
-
0-
I2CRS59-
-
byte value
-
I2CWS60-
-
0-
I2CRB61-
-
byte value
-
I2CWB62-
-
0
-
I2CRW63-
-
word value
-
I2CWW64-
-
0
-
I2CRK65-
-
0-
I2CWK66-
-
0
-
I2CRI67-
-
X
uint8_t data[X]
I2CWI68-
-
0
-
I2CPC69-
-
word value
-
I2CPK70-
-
X
uint8_t data[X]
SPIO
71-
-
handle
-
SPIC72-
-
0-
SPIR73-
-
X
uint8_t data[X]
SPIW74-
-
0
-
SPIX75-
-
Xuint8_t data[X]
SERO76-
-
handle
-
SERC77-
-
0-
SERRB78-
-
byte value
-
SERWB79-
-
0-
SERR80-
-
X
uint8_t data[X]
SERW81-
-
0
-
SERDA82-
-
data ready count
-
GDC
83
-
-
dutycycle
-
GPW
84
-
-
pulsewidth
-
HC
85
-
-
0
-
HP
86
-
-
0
-
CF1
87
-
-
value
-
CF2
88
-
-
X
uint8_t retBuf[X]
BI2CC
89
-
-
0
-
BI2CO
90
-
-
handle
-
BI2CZ
91
-
-
X
uint8_t data[X]
I2CZ
92
-
-
X
uint8_t data[X]
WVCHA
93
-
-
0
-
SLRI
94
-
-
0
-
CGI
95
-
-
config
-
CSI
96
-
-
0
-
FG
97
-
-
0
-
FN
98
-
-
0
-
NOIB99-
-
0-
WVTXM
100
-
-
wave DMA CBs
-
WVTAT
101
-
-
wave id
-
PADS
102
-
-
0
-
PADG
103
-
-
strength
-
FO
104
-
-
handle
-
FC
105
-
-
0
-
FR
106
-
-
X
uint8_t data[X]
FW
107
-
-
0
-
FS
108
-
-
position
-
FL
109
-
-
X
uint8_t filenames[X]
SHELL
110
-
-
exit status
-
BSPIC
111
-
-
0
-
BSPIO
112
-
-
0
-
BSPIX
113
-
-
X
uint8_t data[X]
BSCX
114
-
-
X+4
uint32_t status
-uint8_t data[X]
EVM
115
-
-
0
-
EVT
116
-
-
0
-
PROCU
117
-
-
0
-
-
-

cmdCmd_t

-typedef struct
-{
-   uint32_t cmd;
-   uint32_t p1;
-   uint32_t p2;
-   union
-   {
-      uint32_t p3;
-      uint32_t ext_len;
-      uint32_t res;
-   };
-} cmdCmd_t;

-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/HTML/sitemap.html b/DOC/HTML/sitemap.html deleted file mode 100644 index b2706b1..0000000 --- a/DOC/HTML/sitemap.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - pigpio library - - - - - - - - - -
- -
pigpio library
-
-
-
- - -
- - - -
pigpio -pigpio C I/F -pigpiod -pigpiod C I/F -Python -pigs -piscope -Misc -Examples -Download -FAQ -Site Map -

Site Map

pigpio
-pigpio C I/F
-pigpiod
-pigpiod C I/F
-Python
-pigs
-piscope
-Misc
-----Socket I/F
-----Pipe I/F
-----pigpiod_if
-----pig2vcd
-Examples
-----Rotary Encoder
-----IR Remote
-----Light Dependent Resitor
-----Sonar Ranger
-----Arduino Motor Shield
-Download
-FAQ
-Site Map
-
- - - - - -
© 2012-2020
e-mail: pigpio @ abyz.me.uk
Updated: 30/04/2020
-
- - diff --git a/DOC/MAN/pig2vcd.1 b/DOC/MAN/pig2vcd.1 deleted file mode 100644 index eacce19..0000000 --- a/DOC/MAN/pig2vcd.1 +++ /dev/null @@ -1,246 +0,0 @@ - -." Process this file with -." groff -man -Tascii pig2vcd.1 -." -.TH pig2vcd 1 2012-2020 Linux "pigpio archive" -.SH NAME -pig2vd - A utility to convert pigpio notifications to VCD. - -.SH SYNOPSIS - -pig2vcd file.VCD -.SH DESCRIPTION - - -.ad l - -.nh -pig2vcd is a utility which reads notifications on stdin and writes the -output as a Value Change Dump (VCD) file on stdout. - -.br - -.br -The VCD file can be viewed using GTKWave. - -.br - -.br -.SS Notifications -.br - -.br -Notifications consist of 12 bytes with the following binary format. - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint16_t seqno; -.br - uint16_t flags; -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioReport_t; -.br - -.EE - -.br - -.br -seqno: starts at 0 each time the handle is opened and then increments by one for each report. - -.br - -.br -flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. - -.br - -.br -tick: the number of microseconds since system boot. It wraps around after 1h12m. - -.br - -.br -level: indicates the level of each gpio. If bit 1< - - -gcc -Wall -pthread -o prog prog.c -lpigpio -lrt - -sudo ./prog -.SH DESCRIPTION - - -.ad l - -.nh - -.br - -.br -pigpio is a C library for the Raspberry which allows control of the GPIO. - -.br - -.br -.SS Features -.br - -.br -o hardware timed PWM on any of GPIO 0-31 - -.br - -.br -o hardware timed servo pulses on any of GPIO 0-31 - -.br - -.br -o callbacks when any of GPIO 0-31 change state - -.br - -.br -o callbacks at timed intervals - -.br - -.br -o reading/writing all of the GPIO in a bank as one operation - -.br - -.br -o individually setting GPIO modes, reading and writing - -.br - -.br -o notifications when any of GPIO 0-31 change state - -.br - -.br -o the construction of output waveforms with microsecond timing - -.br - -.br -o rudimentary permission control over GPIO - -.br - -.br -o a simple interface to start and stop new threads - -.br - -.br -o I2C, SPI, and serial link wrappers - -.br - -.br -o creating and running scripts - -.br - -.br -.SS GPIO -.br - -.br -ALL GPIO are identified by their Broadcom number. - -.br - -.br -.SS Credits -.br - -.br -The PWM and servo pulses are timed using the DMA and PWM peripherals. - -.br - -.br -This use was inspired by Richard Hirst's servoblaster kernel module. - -.br - -.br -.SS Usage -.br - -.br -Include in your source files. - -.br - -.br -Assuming your source is in prog.c use the following command to build and -run the executable. - -.br - -.br - -.EX -gcc -Wall -pthread -o prog prog.c -lpigpio -lrt -.br -sudo ./prog -.br - -.EE - -.br - -.br -For examples of usage see the C programs within the pigpio archive file. - -.br - -.br -.SS Notes -.br - -.br -All the functions which return an int return < 0 on error. - -.br - -.br -\fBgpioInitialise\fP must be called before all other library functions -with the following exceptions: - -.br - -.br - -.EX -\fBgpioCfg*\fP -.br -\fBgpioVersion\fP -.br -\fBgpioHardwareRevision\fP -.br - -.EE - -.br - -.br -If the library is not initialised all but the \fBgpioCfg*\fP, -\fBgpioVersion\fP, and \fBgpioHardwareRevision\fP functions will -return error PI_NOT_INITIALISED. - -.br - -.br -If the library is initialised the \fBgpioCfg*\fP functions will return -error PI_INITIALISED. - -.br - -.br - -.SH OVERVIEW - -.br -.SS ESSENTIAL -.br - -.br -gpioInitialise Initialise library -.br -gpioTerminate Stop library -.br -.SS BASIC -.br - -.br -gpioSetMode Set a GPIO mode -.br -gpioGetMode Get a GPIO mode -.br - -.br -gpioSetPullUpDown Set/clear GPIO pull up/down resistor -.br - -.br -gpioRead Read a GPIO -.br -gpioWrite Write a GPIO -.br -.SS PWM (overrides servo commands on same GPIO) -.br - -.br -gpioPWM Start/stop PWM pulses on a GPIO -.br -gpioSetPWMfrequency Configure PWM frequency for a GPIO -.br -gpioSetPWMrange Configure PWM range for a GPIO -.br - -.br -gpioGetPWMdutycycle Get dutycycle setting on a GPIO -.br -gpioGetPWMfrequency Get configured PWM frequency for a GPIO -.br -gpioGetPWMrange Get configured PWM range for a GPIO -.br - -.br -gpioGetPWMrealRange Get underlying PWM range for a GPIO -.br -.SS Servo (overrides PWM commands on same GPIO) -.br - -.br -gpioServo Start/stop servo pulses on a GPIO -.br - -.br -gpioGetServoPulsewidth Get pulsewidth setting on a GPIO -.br -.SS INTERMEDIATE -.br - -.br -gpioTrigger Send a trigger pulse to a GPIO -.br - -.br -gpioSetWatchdog Set a watchdog on a GPIO -.br - -.br -gpioRead_Bits_0_31 Read all GPIO in bank 1 -.br -gpioRead_Bits_32_53 Read all GPIO in bank 2 -.br - -.br -gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 -.br -gpioWrite_Bits_32_53_Clear Clear selected GPIO in bank 2 -.br - -.br -gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 -.br -gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 -.br - -.br -gpioSetAlertFunc Request a GPIO level change callback -.br -gpioSetAlertFuncEx Request a GPIO change callback, extended -.br - -.br -gpioSetTimerFunc Request a regular timed callback -.br -gpioSetTimerFuncEx Request a regular timed callback, extended -.br - -.br -gpioStartThread Start a new thread -.br -gpioStopThread Stop a previously started thread -.br -.SS ADVANCED -.br - -.br -gpioNotifyOpen Request a notification handle -.br -gpioNotifyClose Close a notification -.br -gpioNotifyOpenWithSize Request a notification with sized pipe -.br -gpioNotifyBegin Start notifications for selected GPIO -.br -gpioNotifyPause Pause notifications -.br - -.br -gpioHardwareClock Start hardware clock on supported GPIO -.br - -.br -gpioHardwarePWM Start hardware PWM on supported GPIO -.br - -.br -gpioGlitchFilter Set a glitch filter on a GPIO -.br -gpioNoiseFilter Set a noise filter on a GPIO -.br - -.br -gpioSetPad Sets a pads drive strength -.br -gpioGetPad Gets a pads drive strength -.br - -.br -shell Executes a shell command -.br - -.br -gpioSetISRFunc Request a GPIO interrupt callback -.br -gpioSetISRFuncEx Request a GPIO interrupt callback, extended -.br - -.br -gpioSetSignalFunc Request a signal callback -.br -gpioSetSignalFuncEx Request a signal callback, extended -.br - -.br -gpioSetGetSamplesFunc Requests a GPIO samples callback -.br -gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended -.br -.SS Custom -.br - -.br -gpioCustom1 User custom function 1 -.br -gpioCustom2 User custom function 2 -.br -.SS Events -.br - -.br -eventMonitor Sets the events to monitor -.br -eventSetFunc Request an event callback -.br -eventSetFuncEx Request an event callback, extended -.br - -.br -eventTrigger Trigger an event -.br -.SS Scripts -.br - -.br -gpioStoreScript Store a script -.br -gpioRunScript Run a stored script -.br -gpioUpdateScript Set a scripts parameters -.br -gpioScriptStatus Get script status and parameters -.br -gpioStopScript Stop a running script -.br -gpioDeleteScript Delete a stored script -.br -.SS I2C -.br - -.br -i2cOpen Opens an I2C device -.br -i2cClose Closes an I2C device -.br - -.br -i2cWriteQuick SMBus write quick -.br - -.br -i2cReadByte SMBus read byte -.br -i2cWriteByte SMBus write byte -.br - -.br -i2cReadByteData SMBus read byte data -.br -i2cWriteByteData SMBus write byte data -.br - -.br -i2cReadWordData SMBus read word data -.br -i2cWriteWordData SMBus write word data -.br - -.br -i2cReadBlockData SMBus read block data -.br -i2cWriteBlockData SMBus write block data -.br - -.br -i2cReadI2CBlockData SMBus read I2C block data -.br -i2cWriteI2CBlockData SMBus write I2C block data -.br - -.br -i2cReadDevice Reads the raw I2C device -.br -i2cWriteDevice Writes the raw I2C device -.br - -.br -i2cProcessCall SMBus process call -.br -i2cBlockProcessCall SMBus block process call -.br - -.br -i2cSwitchCombined Sets or clears the combined flag -.br - -.br -i2cSegments Performs multiple I2C transactions -.br - -.br -i2cZip Performs multiple I2C transactions -.br -.SS I2C BIT BANG -.br - -.br -bbI2COpen Opens GPIO for bit banging I2C -.br -bbI2CClose Closes GPIO for bit banging I2C -.br - -.br -bbI2CZip Performs bit banged I2C transactions -.br -.SS I2C/SPI SLAVE -.br - -.br -bscXfer I2C/SPI as slave transfer -.br -.SS SERIAL -.br - -.br -serOpen Opens a serial device -.br -serClose Closes a serial device -.br - -.br -serReadByte Reads a byte from a serial device -.br -serWriteByte Writes a byte to a serial device -.br - -.br -serRead Reads bytes from a serial device -.br -serWrite Writes bytes to a serial device -.br - -.br -serDataAvailable Returns number of bytes ready to be read -.br -.SS SERIAL BIT BANG (read only) -.br - -.br -gpioSerialReadOpen Opens a GPIO for bit bang serial reads -.br -gpioSerialReadClose Closes a GPIO for bit bang serial reads -.br - -.br -gpioSerialReadInvert Configures normal/inverted for serial reads -.br - -.br -gpioSerialRead Reads bit bang serial data from a GPIO -.br -.SS SPI -.br - -.br -spiOpen Opens a SPI device -.br -spiClose Closes a SPI device -.br - -.br -spiRead Reads bytes from a SPI device -.br -spiWrite Writes bytes to a SPI device -.br -spiXfer Transfers bytes with a SPI device -.br -.SS SPI BIT BANG -.br - -.br -bbSPIOpen Opens GPIO for bit banging SPI -.br -bbSPIClose Closes GPIO for bit banging SPI -.br - -.br -bbSPIXfer Performs bit banged SPI transactions -.br -.SS FILES -.br - -.br -fileOpen Opens a file -.br -fileClose Closes a file -.br - -.br -fileRead Reads bytes from a file -.br -fileWrite Writes bytes to a file -.br - -.br -fileSeek Seeks to a position within a file -.br - -.br -fileList List files which match a pattern -.br -.SS WAVES -.br - -.br -gpioWaveClear Deletes all waveforms -.br - -.br -gpioWaveAddNew Starts a new waveform -.br -gpioWaveAddGeneric Adds a series of pulses to the waveform -.br -gpioWaveAddSerial Adds serial data to the waveform -.br - -.br -gpioWaveCreate Creates a waveform from added data -.br -gpioWaveCreatePad Creates a waveform of fixed size from added data -.br -gpioWaveDelete Deletes a waveform -.br - -.br -gpioWaveTxSend Transmits a waveform -.br - -.br -gpioWaveChain Transmits a chain of waveforms -.br - -.br -gpioWaveTxAt Returns the current transmitting waveform -.br - -.br -gpioWaveTxBusy Checks to see if the waveform has ended -.br - -.br -gpioWaveTxStop Aborts the current waveform -.br - -.br -gpioWaveGetCbs Length in CBs of the current waveform -.br -gpioWaveGetHighCbs Length of longest waveform so far -.br -gpioWaveGetMaxCbs Absolute maximum allowed CBs -.br - -.br -gpioWaveGetMicros Length in micros of the current waveform -.br -gpioWaveGetHighMicros Length of longest waveform so far -.br -gpioWaveGetMaxMicros Absolute maximum allowed micros -.br - -.br -gpioWaveGetPulses Length in pulses of the current waveform -.br -gpioWaveGetHighPulses Length of longest waveform so far -.br -gpioWaveGetMaxPulses Absolute maximum allowed pulses -.br -.SS UTILITIES -.br - -.br -gpioDelay Delay for a number of microseconds -.br - -.br -gpioTick Get current tick (microseconds) -.br - -.br -gpioHardwareRevision Get hardware revision -.br -gpioVersion Get the pigpio version -.br - -.br -getBitInBytes Get the value of a bit -.br -putBitInBytes Set the value of a bit -.br - -.br -gpioTime Get current time -.br -gpioSleep Sleep for specified time -.br - -.br -time_sleep Sleeps for a float number of seconds -.br -time_time Float number of seconds since the epoch -.br -.SS CONFIGURATION -.br - -.br -gpioCfgBufferSize Configure the GPIO sample buffer size -.br -gpioCfgClock Configure the GPIO sample rate -.br -gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) -.br -gpioCfgDMAchannels Configure the DMA channels -.br -gpioCfgPermissions Configure the GPIO access permissions -.br -gpioCfgInterfaces Configure user interfaces -.br -gpioCfgSocketPort Configure socket port -.br -gpioCfgMemAlloc Configure DMA memory allocation mode -.br -gpioCfgNetAddr Configure allowed network addresses -.br - -.br -gpioCfgInternals Configure misc. internals (DEPRECATED) -.br -gpioCfgGetInternals Get internal configuration settings -.br -gpioCfgSetInternals Set internal configuration settings -.br -.SS EXPERT -.br - -.br -rawWaveAddSPI Not intended for general use -.br -rawWaveAddGeneric Not intended for general use -.br -rawWaveCB Not intended for general use -.br -rawWaveCBAdr Not intended for general use -.br -rawWaveGetOOL Not intended for general use -.br -rawWaveSetOOL Not intended for general use -.br -rawWaveGetOut Not intended for general use -.br -rawWaveSetOut Not intended for general use -.br -rawWaveGetIn Not intended for general use -.br -rawWaveSetIn Not intended for general use -.br -rawWaveInfo Not intended for general use -.br -rawDumpWave Not intended for general use -.br -rawDumpScript Not intended for general use -.br -.SH FUNCTIONS - -.IP "\fBint gpioInitialise(void)\fP" -.IP "" 4 -Initialises the library. - -.br - -.br -Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. - -.br - -.br -gpioInitialise must be called before using the other library functions -with the following exceptions: - -.br - -.br - -.EX -\fBgpioCfg*\fP -.br -\fBgpioVersion\fP -.br -\fBgpioHardwareRevision\fP -.br - -.EE - -.br - -.br -\fBExample\fP -.br - -.EX -if (gpioInitialise() < 0) -.br -{ -.br - // pigpio initialisation failed. -.br -} -.br -else -.br -{ -.br - // pigpio initialised okay. -.br -} -.br - -.EE - -.IP "\fBvoid gpioTerminate(void)\fP" -.IP "" 4 -Terminates the library. - -.br - -.br -Returns nothing. - -.br - -.br -Call before program exit. - -.br - -.br -This function resets the used DMA channels, releases memory, and -terminates any running threads. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioTerminate(); -.br - -.EE - -.IP "\fBint gpioSetMode(unsigned gpio, unsigned mode)\fP" -.IP "" 4 -Sets the GPIO mode, typically input or output. - -.br - -.br - -.EX -gpio: 0-53 -.br -mode: 0-7 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. - -.br - -.br -Arduino style: pinMode. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetMode(17, PI_INPUT); // Set GPIO17 as input. -.br - -.br -gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output. -.br - -.br -gpioSetMode(22,PI_ALT0); // Set GPIO22 to alternative mode 0. -.br - -.EE - -.br - -.br -See \fBhttp://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf\fP page 102 for an overview of the modes. - -.IP "\fBint gpioGetMode(unsigned gpio)\fP" -.IP "" 4 -Gets the GPIO mode. - -.br - -.br - -.EX -gpio: 0-53 -.br - -.EE - -.br - -.br -Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. - -.br - -.br -\fBExample\fP -.br - -.EX -if (gpioGetMode(17) != PI_ALT0) -.br -{ -.br - gpioSetMode(17, PI_ALT0); // set GPIO17 to ALT0 -.br -} -.br - -.EE - -.IP "\fBint gpioSetPullUpDown(unsigned gpio, unsigned pud)\fP" -.IP "" 4 -Sets or clears resistor pull ups or downs on the GPIO. - -.br - -.br - -.EX -gpio: 0-53 -.br - pud: 0-2 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetPullUpDown(17, PI_PUD_UP); // Sets a pull-up. -.br - -.br -gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down. -.br - -.br -gpioSetPullUpDown(23, PI_PUD_OFF); // Clear any pull-ups/downs. -.br - -.EE - -.IP "\fBint gpioRead(unsigned gpio)\fP" -.IP "" 4 -Reads the GPIO level, on or off. - -.br - -.br - -.EX -gpio: 0-53 -.br - -.EE - -.br - -.br -Returns the GPIO level if OK, otherwise PI_BAD_GPIO. - -.br - -.br -Arduino style: digitalRead. - -.br - -.br -\fBExample\fP -.br - -.EX -printf("GPIO24 is level %d", gpioRead(24)); -.br - -.EE - -.IP "\fBint gpioWrite(unsigned gpio, unsigned level)\fP" -.IP "" 4 -Sets the GPIO level, on or off. - -.br - -.br - -.EX - gpio: 0-53 -.br -level: 0-1 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. - -.br - -.br -If PWM or servo pulses are active on the GPIO they are switched off. - -.br - -.br -Arduino style: digitalWrite - -.br - -.br -\fBExample\fP -.br - -.EX -gpioWrite(24, 1); // Set GPIO24 high. -.br - -.EE - -.IP "\fBint gpioPWM(unsigned user_gpio, unsigned dutycycle)\fP" -.IP "" 4 -Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). -Range defaults to 255. - -.br - -.br - -.EX -user_gpio: 0-31 -.br -dutycycle: 0-range -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. - -.br - -.br -Arduino style: analogWrite - -.br - -.br -This and the servo functionality use the DMA and PWM or PCM peripherals -to control and schedule the pulse lengths and dutycycles. - -.br - -.br -The \fBgpioSetPWMrange\fP function may be used to change the default -range of 255. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioPWM(17, 255); // Sets GPIO17 full on. -.br - -.br -gpioPWM(18, 128); // Sets GPIO18 half on. -.br - -.br -gpioPWM(23, 0); // Sets GPIO23 full off. -.br - -.EE - -.IP "\fBint gpioGetPWMdutycycle(unsigned user_gpio)\fP" -.IP "" 4 -Returns the PWM dutycycle setting for the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -Returns between 0 (off) and range (fully on) if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. - -.br - -.br -For normal PWM the dutycycle will be out of the defined range -for the GPIO (see \fBgpioGetPWMrange\fP). - -.br - -.br -If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). - -.br - -.br -Normal PWM range defaults to 255. - -.IP "\fBint gpioSetPWMrange(unsigned user_gpio, unsigned range)\fP" -.IP "" 4 -Selects the dutycycle range to be used for the GPIO. Subsequent calls -to gpioPWM will use a dutycycle between 0 (off) and range (fully on). - -.br - -.br - -.EX -user_gpio: 0-31 -.br - range: 25-40000 -.br - -.EE - -.br - -.br -Returns the real range for the given GPIO's frequency if OK, -otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. - -.br - -.br -If PWM is currently active on the GPIO its dutycycle will be scaled -to reflect the new range. - -.br - -.br -The real range, the number of steps between fully off and fully -on for each frequency, is given in the following table. - -.br - -.br - -.EX - 25, 50, 100, 125, 200, 250, 400, 500, 625, -.br - 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000 -.br - -.EE - -.br - -.br -The real value set by \fBgpioPWM\fP is (dutycycle * real range) / range. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetPWMrange(24, 2000); // Now 2000 is fully on -.br - // 1000 is half on -.br - // 500 is quarter on, etc. -.br - -.EE - -.IP "\fBint gpioGetPWMrange(unsigned user_gpio)\fP" -.IP "" 4 -Returns the dutycycle range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). - -.br - -.br -\fBExample\fP -.br - -.EX -r = gpioGetPWMrange(23); -.br - -.EE - -.IP "\fBint gpioGetPWMrealRange(unsigned user_gpio)\fP" -.IP "" 4 -Returns the real range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -If a hardware clock is active on the GPIO the reported real -range will be 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. - -.br - -.br -\fBExample\fP -.br - -.EX -rr = gpioGetPWMrealRange(17); -.br - -.EE - -.IP "\fBint gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)\fP" -.IP "" 4 -Sets the frequency in hertz to be used for the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br -frequency: >=0 -.br - -.EE - -.br - -.br -Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO. - -.br - -.br -If PWM is currently active on the GPIO it will be -switched off and then back on at the new frequency. - -.br - -.br -Each GPIO can be independently set to one of 18 different PWM -frequencies. - -.br - -.br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). - -.br - -.br -The frequencies for each sample rate are: - -.br - -.br - -.EX - Hertz -.br - -.br - 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 -.br - 1250 1000 800 500 400 250 200 100 50 -.br - -.br - 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 -.br - 625 500 400 250 200 125 100 50 25 -.br - -.br - 4: 10000 5000 2500 2000 1250 1000 625 500 400 -.br - 313 250 200 125 100 63 50 25 13 -.br -sample -.br - rate -.br - (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 -.br - 250 200 160 100 80 50 40 20 10 -.br - -.br - 8: 5000 2500 1250 1000 625 500 313 250 200 -.br - 156 125 100 63 50 31 25 13 6 -.br - -.br - 10: 4000 2000 1000 800 500 400 250 200 160 -.br - 125 100 80 50 40 25 20 10 5 -.br - -.EE - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency. -.br - -.br -gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz. -.br - -.br -gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency. -.br - -.EE - -.IP "\fBint gpioGetPWMfrequency(unsigned user_gpio)\fP" -.IP "" 4 -Returns the frequency (in hertz) used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -For normal PWM the frequency will be that defined for the GPIO by -\fBgpioSetPWMfrequency\fP. - -.br - -.br -If a hardware clock is active on the GPIO the reported frequency -will be that set by \fBgpioHardwareClock\fP. - -.br - -.br -If hardware PWM is active on the GPIO the reported frequency -will be that set by \fBgpioHardwarePWM\fP. - -.br - -.br -\fBExample\fP -.br - -.EX -f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23. -.br - -.EE - -.IP "\fBint gpioServo(unsigned user_gpio, unsigned pulsewidth)\fP" -.IP "" 4 -Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to -2500 (most clockwise). - -.br - -.br - -.EX - user_gpio: 0-31 -.br -pulsewidth: 0, 500-2500 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. - -.br - -.br -The range supported by servos varies and should probably be determined -by experiment. A value of 1500 should always be safe and represents -the mid-point of rotation. You can DAMAGE a servo if you command it -to move beyond its limits. - -.br - -.br -The following 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. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioServo(17, 1000); // Move servo to safe position anti-clockwise. -.br - -.br -gpioServo(23, 1500); // Move servo to centre position. -.br - -.br -gpioServo(25, 2000); // Move servo to safe position clockwise. -.br - -.EE - -.br - -.br -OTHER UPDATE RATES: - -.br - -.br -This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. - -.br - -.br - -.EX -PWM Hz 50 100 200 400 500 -.br -1E6/Hz 20000 10000 5000 2500 2000 -.br - -.EE - -.br - -.br -Firstly set the desired PWM frequency using \fBgpioSetPWMfrequency\fP. - -.br - -.br -Then set the PWM range using \fBgpioSetPWMrange\fP to 1E6/frequency. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. - -.br - -.br -E.g. If you want to update a servo connected to GPIO25 at 400Hz - -.br - -.br - -.EX -gpioSetPWMfrequency(25, 400); -.br - -.br -gpioSetPWMrange(25, 2500); -.br - -.EE - -.br - -.br -Thereafter use the PWM command to move the servo, -e.g. gpioPWM(25, 1500) will set a 1500 us pulse. - -.IP "\fBint gpioGetServoPulsewidth(unsigned user_gpio)\fP" -.IP "" 4 -Returns the servo pulsewidth setting for the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - -.EE - -.br - -.br -Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) -if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. - -.IP "\fBint gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) when the specified -GPIO changes state. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - f: the callback function -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO. - -.br - -.br -One callback may be registered per GPIO. - -.br - -.br -The callback is passed the GPIO, the new level, and the tick. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -level 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.EE - -.br - -.br -The alert may be cancelled by passing NULL as the function. - -.br - -.br -The GPIO are sampled at a rate set when the library is started. - -.br - -.br -If a value isn't specifically set the default of 5 us is used. - -.br - -.br -The number of samples per second is given in the following table. - -.br - -.br - -.EX - samples -.br - per sec -.br - -.br - 1 1,000,000 -.br - 2 500,000 -.br -sample 4 250,000 -.br -rate 5 200,000 -.br -(us) 8 125,000 -.br - 10 100,000 -.br - -.EE - -.br - -.br -Level changes shorter than the sample rate may be missed. - -.br - -.br -The thread which calls the alert functions is triggered nominally -1000 times per second. The active alert functions will be called -once per level change since the last time the thread was activated. -i.e. The active alert functions will get all level changes but there -will be a latency. - -.br - -.br -If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use \fBgpioRead\fP. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. - -.br - -.br -The tick value is the time stamp of the sample in microseconds, see -\fBgpioTick\fP for more details. - -.br - -.br -\fBExample\fP -.br - -.EX -void aFunction(int gpio, int level, uint32_t tick) -.br -{ -.br - printf("GPIO %d became %d at %d", gpio, level, tick); -.br -} -.br - -.br -// call aFunction whenever GPIO 4 changes state -.br - -.br -gpioSetAlertFunc(4, aFunction); -.br - -.EE - -.IP "\fBint gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) when the specified -GPIO changes state. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - f: the callback function -.br - userdata: pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO. - -.br - -.br -One callback may be registered per GPIO. - -.br - -.br -The callback is passed the GPIO, the new level, the tick, and -the userdata pointer. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -level 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.br -userdata pointer Pointer to an arbitrary object -.br - -.EE - -.br - -.br -See \fBgpioSetAlertFunc\fP for further details. - -.br - -.br -Only one of \fBgpioSetAlertFunc\fP or \fBgpioSetAlertFuncEx\fP can be -registered per GPIO. - -.IP "\fBint gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. - -.br - -.br - -.EX - gpio: 0-53 -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE -.br -timeout: interrupt timeout in milliseconds (<=0 to cancel) -.br - f: the callback function -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. - -.br - -.br -One function may be registered per GPIO. - -.br - -.br -The function is passed the GPIO, the current level, and the -current tick. The level will be PI_TIMEOUT if the optional -interrupt timeout expires. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-53 The GPIO which has changed state -.br - -.br -level 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (interrupt timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.EE - -.br - -.br -The underlying Linux sysfs GPIO interface is used to provide -the interrupt services. - -.br - -.br -The first time the function is called, with a non-NULL f, the -GPIO is exported, set to be an input, and set to interrupt -on the given edge and timeout. - -.br - -.br -Subsequent calls, with a non-NULL f, can vary one or more of the -edge, timeout, or function. - -.br - -.br -The ISR may be cancelled by passing a NULL f, in which case the -GPIO is unexported. - -.br - -.br -The tick is that read at the time the process was informed of -the interrupt. This will be a variable number of microseconds -after the interrupt occurred. Typically the latency will be of -the order of 50 microseconds. The latency is not guaranteed -and will vary with system load. - -.br - -.br -The level is that read at the time the process was informed of -the interrupt, or PI_TIMEOUT if the optional interrupt timeout -expired. It may not be the same as the expected edge as -interrupts happening in rapid succession may be missed by the -kernel (i.e. this mechanism can not be used to capture several -interrupts only a few microseconds apart). - -.IP "\fBint gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. - -.br - -.br - -.EX - gpio: 0-53 -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE -.br - timeout: interrupt timeout in milliseconds (<=0 to cancel) -.br - f: the callback function -.br -userdata: pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. - -.br - -.br -The function is passed the GPIO, the current level, the -current tick, and the userdata pointer. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-53 The GPIO which has changed state -.br - -.br -level 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (interrupt timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.br -userdata pointer Pointer to an arbitrary object -.br - -.EE - -.br - -.br -Only one of \fBgpioSetISRFunc\fP or \fBgpioSetISRFuncEx\fP can be -registered per GPIO. - -.br - -.br -See \fBgpioSetISRFunc\fP for further details. - -.IP "\fBint gpioNotifyOpen(void)\fP" -.IP "" 4 -This function requests a free notification handle. - -.br - -.br -Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. - -.br - -.br -A notification is a method for being notified of GPIO state changes -via a pipe or socket. - -.br - -.br -Pipe notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). E.g. if the -function returns 15 then the notifications must be read -from /dev/pigpio15. - -.br - -.br -Socket notifications are returned to the socket which requested the -handle. - -.br - -.br -\fBExample\fP -.br - -.EX -h = gpioNotifyOpen(); -.br - -.br -if (h >= 0) -.br -{ -.br - sprintf(str, "/dev/pigpio%d", h); -.br - -.br - fd = open(str, O_RDONLY); -.br - -.br - if (fd >= 0) -.br - { -.br - // Okay. -.br - } -.br - else -.br - { -.br - // Error. -.br - } -.br -} -.br -else -.br -{ -.br - // Error. -.br -} -.br - -.EE - -.IP "\fBint gpioNotifyOpenWithSize(int bufSize)\fP" -.IP "" 4 -This function requests a free notification handle. - -.br - -.br -It differs from \fBgpioNotifyOpen\fP in that the pipe size may be -specified, whereas \fBgpioNotifyOpen\fP uses the default pipe size. - -.br - -.br -See \fBgpioNotifyOpen\fP for further details. - -.IP "\fBint gpioNotifyBegin(unsigned handle, uint32_t bits)\fP" -.IP "" 4 -This function starts notifications on a previously opened handle. - -.br - -.br - -.EX -handle: >=0, as returned by \fBgpioNotifyOpen\fP -.br - bits: a bit mask indicating the GPIO of interest -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -The notification sends state changes for each GPIO whose corresponding -bit in bits is set. - -.br - -.br -Each notification occupies 12 bytes in the fifo and has the -following structure. - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint16_t seqno; -.br - uint16_t flags; -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioReport_t; -.br - -.EE - -.br - -.br -seqno: starts at 0 each time the handle is opened and then increments -by one for each report. - -.br - -.br -flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. - -.br - -.br -If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. - -.br - -.br -If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. - -.br - -.br -If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. - -.br - -.br -tick: the number of microseconds since system boot. It wraps around -after 1h12m. - -.br - -.br -level: indicates the level of each GPIO. If bit 1<=0, as returned by \fBgpioNotifyOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -Notifications for the handle are suspended until \fBgpioNotifyBegin\fP -is called again. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioNotifyPause(h); -.br - -.EE - -.IP "\fBint gpioNotifyClose(unsigned handle)\fP" -.IP "" 4 -This function stops notifications on a previously opened handle -and releases the handle for reuse. - -.br - -.br - -.EX -handle: >=0, as returned by \fBgpioNotifyOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioNotifyClose(h); -.br - -.EE - -.IP "\fBint gpioWaveClear(void)\fP" -.IP "" 4 -This function clears all waveforms and any data added by calls to the -\fBgpioWaveAdd*\fP functions. - -.br - -.br -Returns 0 if OK. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioWaveClear(); -.br - -.EE - -.IP "\fBint gpioWaveAddNew(void)\fP" -.IP "" 4 -This function starts a new empty waveform. - -.br - -.br -You wouldn't normally need to call this function as it is automatically -called after a waveform is created with the \fBgpioWaveCreate\fP function. - -.br - -.br -Returns 0 if OK. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioWaveAddNew(); -.br - -.EE - -.IP "\fBint gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)\fP" -.IP "" 4 -This function adds a number of pulses to the current waveform. - -.br - -.br - -.EX -numPulses: the number of pulses -.br - pulses: an array of pulses -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. - -.br - -.br -The pulses are interleaved in time order within the existing waveform -(if any). - -.br - -.br -Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. - -.br - -.br -If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. - -.br - -.br -\fBExample\fP -.br - -.EX -// Construct and send a 30 microsecond square wave. -.br - -.br -gpioSetMode(gpio, PI_OUTPUT); -.br - -.br -pulse[0].gpioOn = (1<= 0) -.br -{ -.br - gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT); -.br - -.br - // Transmit for 30 seconds. -.br - -.br - sleep(30); -.br - -.br - gpioWaveTxStop(); -.br -} -.br -else -.br -{ -.br - // Wave create failed. -.br -} -.br - -.EE - -.IP "\fBint gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)\fP" -.IP "" 4 -This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - baud: 50-1000000 -.br -data_bits: 1-32 -.br -stop_bits: 2-8 -.br - offset: >=0 -.br - numBytes: >=1 -.br - str: an array of chars (which may contain nulls) -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. - -.br - -.br -NOTES: - -.br - -.br -The serial data is formatted as one start bit, data_bits data bits, and -stop_bits/2 stop bits. - -.br - -.br -It is legal to add serial data streams with different baud rates to -the same waveform. - -.br - -.br -numBytes is the number of bytes of data in str. - -.br - -.br -The bytes required for each character depend upon data_bits. - -.br - -.br -For data_bits 1-8 there will be one byte per character. -.br -For data_bits 9-16 there will be two bytes per character. -.br -For data_bits 17-32 there will be four bytes per character. - -.br - -.br -\fBExample\fP -.br - -.EX -#define MSG_LEN 8 -.br - -.br -int i; -.br -char *str; -.br -char data[MSG_LEN]; -.br - -.br -str = "Hello world!"; -.br - -.br -gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str); -.br - -.br -for (i=0; i=0, as returned by \fBgpioWaveCreate\fP -.br - -.EE - -.br - -.br -Wave ids are allocated in order, 0, 1, 2, etc. - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_WAVE_ID. - -.IP "\fBint gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The mode -determines whether the waveform is sent once or cycles endlessly. -The SYNC variants wait for the current waveform to reach the -end of a cycle or finish before starting the new waveform. - -.br - -.br -WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. - -.br - -.br -NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled. - -.br - -.br - -.EX - wave_id: >=0, as returned by \fBgpioWaveCreate\fP -.br -wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT, -.br - PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint gpioWaveChain(char *buf, unsigned bufSize)\fP" -.IP "" 4 -This function transmits a chain of waveforms. - -.br - -.br -NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled. - -.br - -.br -The waves to be transmitted are specified by the contents of buf -which contains an ordered list of \fBwave_id\fPs and optional command -codes and related data. - -.br - -.br - -.EX - buf: pointer to the wave_ids and optional command codes -.br -bufSize: the number of bytes in buf -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. - -.br - -.br -Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. - -.br - -.br -A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. - -.br - -.br -Delays between waves may be added with the delay command. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -Loop Start 255 0 Identify start of a wave block -.br -Loop Repeat 255 1 x y loop x + y*256 times -.br -Delay 255 2 x y delay x + y*256 microseconds -.br -Loop Forever 255 3 loop forever -.br - -.br - -.br -If present Loop Forever must be the last entry in the chain. - -.br - -.br -The code is currently dimensioned to support a chain with roughly -600 entries and 20 loop counters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -#define WAVES 5 -.br -#define GPIO 4 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, wid[WAVES]; -.br - -.br - if (gpioInitialise()<0) return -1; -.br - -.br - gpioSetMode(GPIO, PI_OUTPUT); -.br - -.br - printf("start piscope, press return"); getchar(); -.br - -.br - for (i=0; i=0 -.br - -.EE - -.br - -.br -Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. - -.br - -.br -The bytes returned for each character depend upon the number of -data bits \fBdata_bits\fP specified in the \fBgpioSerialReadOpen\fP command. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint gpioSerialReadClose(unsigned user_gpio)\fP" -.IP "" 4 -This function closes a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX -user_gpio: 0-31, previously opened with \fBgpioSerialReadOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. - -.IP "\fBint i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)\fP" -.IP "" 4 -This returns a handle for the device at the address on the I2C bus. - -.br - -.br - -.EX - i2cBus: >=0 -.br - i2cAddr: 0-0x7F -.br -i2cFlags: 0 -.br - -.EE - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.br - -.br -Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - SDA SCL -.br -I2C 0 0 1 -.br -I2C 1 2 3 -.br - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. - -.br - -.br -For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. - -.br - -.br - -.EX -S (1 bit) : Start bit -.br -P (1 bit) : Stop bit -.br -Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. -.br -A, NA (1 bit) : Accept and not accept bit. -.br -.br -.br -Addr (7 bits): I2C 7 bit address. -.br -i2cReg (8 bits): Command byte, a byte which often selects a register. -.br -Data (8 bits): A data byte. -.br -Count (8 bits): A byte defining the length of a block operation. -.br - -.br -[..]: Data sent by the device. -.br - -.EE - -.IP "\fBint i2cClose(unsigned handle)\fP" -.IP "" 4 -This closes the I2C device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint i2cWriteQuick(unsigned handle, unsigned bit)\fP" -.IP "" 4 -This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - bit: 0-1, the value to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Quick command. SMBus 2.0 5.5.1 - -.EX -S Addr bit [A] P -.br - -.EE - -.IP "\fBint i2cWriteByte(unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This sends a single byte to the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - bVal: 0-0xFF, the value to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Send byte. SMBus 2.0 5.5.2 - -.EX -S Addr Wr [A] bVal [A] P -.br - -.EE - -.IP "\fBint i2cReadByte(unsigned handle)\fP" -.IP "" 4 -This reads a single byte from the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. - -.br - -.br -Receive byte. SMBus 2.0 5.5.3 - -.EX -S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)\fP" -.IP "" 4 -This writes a single byte to the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write -.br - bVal: 0-0xFF, the value to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write byte. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] i2cReg [A] bVal [A] P -.br - -.EE - -.IP "\fBint i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)\fP" -.IP "" 4 -This writes a single 16 bit word to the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write -.br - wVal: 0-0xFFFF, the value to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write word. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P -.br - -.EE - -.IP "\fBint i2cReadByteData(unsigned handle, unsigned i2cReg)\fP" -.IP "" 4 -This reads a single byte from the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to read -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read byte. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2cReadWordData(unsigned handle, unsigned i2cReg)\fP" -.IP "" 4 -This reads a single 16 bit word from the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to read -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read word. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)\fP" -.IP "" 4 -This writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write/read -.br - wVal: 0-0xFFFF, the value to write -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Process call. SMBus 2.0 5.5.6 - -.EX -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] -.br - S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes up to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write -.br - buf: an array with the data to send -.br - count: 1-32, the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Block write. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] i2cReg [A] count [A] -.br - buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)\fP" -.IP "" 4 -This reads a block of up to 32 bytes from the specified register of -the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to read -.br - buf: an array to receive the read data -.br - -.EE - -.br - -.br -The amount of returned data is set by the device. - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Block read. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] i2cReg [A] -.br - S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write/read -.br - buf: an array with the data to send and to receive the read data -.br - count: 1-32, the number of bytes to write -.br - -.EE - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -The SMBus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. - -.br - -.br -Block write-block read. SMBus 2.0 5.5.8 - -.EX -S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A] -.br - S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P -.br - -.EE - -.IP "\fBint i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to read -.br - buf: an array to receive the read data -.br - count: 1-32, the number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] i2cReg [A] -.br - S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes 1 to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br -i2cReg: 0-255, the register to write -.br - buf: the data to write -.br - count: 1-32, the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2cReadDevice(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the raw device into buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - buf: an array to receive the read data bytes -.br - count: >0, the number of bytes to read -.br - -.EE - -.br - -.br -Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2cWriteDevice(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This writes count bytes from buf to the raw device. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - buf: an array containing the data bytes to write -.br - count: >0, the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBvoid i2cSwitchCombined(int setting)\fP" -.IP "" 4 -This sets the I2C (i2c-bcm2708) module "use combined transactions" -parameter on or off. - -.br - -.br - -.EX -setting: 0 to set the parameter off, non-zero to set it on -.br - -.EE - -.br - -.br - -.br - -.br -NOTE: when the flag is on a write followed by a read to the same -slave address will use a repeated start (rather than a stop/start). - -.IP "\fBint i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)\fP" -.IP "" 4 -This function executes multiple I2C segments in one transaction by -calling the I2C_RDWR ioctl. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - segs: an array of I2C segments -.br -numSegs: >0, the number of I2C segments -.br - -.EE - -.br - -.br -Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. - -.IP "\fBint i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -On 2 Switch combined flag on -.br -Off 3 Switch combined flag off -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53, write 0x32, read 6 bytes -.br -Set address 0x1E, write 0x03, read 6 bytes -.br -Set address 0x68, write 0x1B, read 8 bytes -.br -End -.br - -.br -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -.br -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -.br -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -.br -0x00 -.br - -.EE - -.IP "\fBint bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)\fP" -.IP "" 4 -This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. - -.br - -.br -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -.br - -.br -o baud rates as low as 50 -.br -o repeated starts -.br -o clock stretching -.br -o I2C on any pair of spare GPIO - -.br - -.br - -.EX - SDA: 0-31 -.br - SCL: 0-31 -.br -baud: 50-500000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -NOTE: - -.br - -.br -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -.IP "\fBint bbI2CClose(unsigned SDA)\fP" -.IP "" 4 -This function stops bit banging I2C on a pair of GPIO previously -opened with \fBbbI2COpen\fP. - -.br - -.br - -.EX -SDA: 0-31, the SDA GPIO used in a prior call to \fBbbI2COpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - -.IP "\fBint bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX - SDA: 0-31 (as used in a prior call to \fBbbI2COpen\fP) -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -Start 2 Start condition -.br -Stop 3 Stop condition -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -.br - -.br -No flags are currently defined. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53 -.br -start, write 0x32, (re)start, read 6 bytes, stop -.br -Set address 0x1E -.br -start, write 0x03, (re)start, read 6 bytes, stop -.br -Set address 0x68 -.br -start, write 0x1B, (re)start, read 8 bytes, stop -.br -End -.br - -.br -0x04 0x53 -.br -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x1E -.br -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x68 -.br -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 -.br - -.br -0x00 -.br - -.EE - -.IP "\fBint bscXfer(bsc_xfer_t *bsc_xfer)\fP" -.IP "" 4 -This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. - -.br - -.br -This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. - -.br - -.br -This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. - -.br - -.br -The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. - -.br - -.br -I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. - -.br - -.br -The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. - -.br - -.br - -.EX -bsc_xfer:= a structure defining the transfer -.br - -.br -typedef struct -.br -{ -.br - uint32_t control; // Write -.br - int rxCnt; // Read only -.br - char rxBuf[BSC_FIFO_SIZE]; // Read only -.br - int txCnt; // Write -.br - char txBuf[BSC_FIFO_SIZE]; // Write -.br -} bsc_xfer_t; -.br - -.EE - -.br - -.br -To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. - -.br - -.br -Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. - -.br - -.br -Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. - -.br - -.br -GPIO used for models other than those based on the BCM2711. - -.br - -.br - SDA SCL MOSI SCLK MISO CE -.br -I2C 18 19 - - - - -.br -SPI - - 18 19 20 21 -.br - -.br - -.br -GPIO used for models based on the BCM2711 (e.g. the Pi4B). - -.br - -.br - SDA SCL MOSI SCLK MISO CE -.br -I2C 10 11 - - - - -.br -SPI - - 10 11 9 8 -.br - -.br - -.br -When a zero control word is received the used GPIO will be reset -to INPUT mode. - -.br - -.br -The returned function value is the status of the transfer (see below). - -.br - -.br -If there was an error the status will be less than zero -(and will contain the error code). - -.br - -.br -The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). - -.br - -.br -control consists of the following bits. - -.br - -.br - -.EX -22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN -.br - -.EE - -.br - -.br -Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. - -.br - -.br -aaaaaaa defines the I2C slave address (only relevant in I2C mode) -.br -IT invert transmit status flags -.br -HC enable host control -.br -TF enable test FIFO -.br -IR invert receive status flags -.br -RE enable receive -.br -TE enable transmit -.br -BK abort operation and clear FIFOs -.br -EC send control register as first I2C byte -.br -ES send status register as first I2C byte -.br -PL set SPI polarity high -.br -PH set SPI phase high -.br -I2 enable I2C mode -.br -SP enable SPI mode -.br -EN enable BSC peripheral -.br - -.br - -.br -The returned status has the following format - -.br - -.br - -.EX -20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - S S S S S R R R R R T T T T T RB TE RF TF RE TB -.br - -.EE - -.br - -.br -Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. - -.br - -.br -SSSSS number of bytes successfully copied to transmit FIFO -.br -RRRRR number of bytes in receieve FIFO -.br -TTTTT number of bytes in transmit FIFO -.br -RB receive busy -.br -TE transmit FIFO empty -.br -RF receive FIFO full -.br -TF transmit FIFO full -.br -RE receive FIFO empty -.br -TB transmit busy -.br - -.br - -.br -The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. - -.br - -.br -\fBExample\fP -.br - -.EX -bsc_xfer_t xfer; -.br - -.br -xfer.control = (0x13<<16) | 0x305; -.br - -.br -memcpy(xfer.txBuf, "ABCD", 4); -.br -xfer.txCnt = 4; -.br - -.br -status = bscXfer(&xfer); -.br - -.br -if (status >= 0) -.br -{ -.br - // process transfer -.br -} -.br - -.EE - -.IP "\fBint bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)\fP" -.IP "" 4 -This function selects a set of GPIO for bit banging SPI with -a specified baud rate and mode. - -.br - -.br - -.EX - CS: 0-31 -.br - MISO: 0-31 -.br - MOSI: 0-31 -.br - SCLK: 0-31 -.br - baud: 50-250000 -.br -spiFlags: see below -.br - -.EE - -.br - -.br -spiFlags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m -.br - -.EE - -.br - -.br -mm defines the SPI mode, defaults to 0 - -.br - -.br - -.EX -Mode CPOL CPHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -p is 0 if CS is active low (default) and 1 for active high. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. - -.br - -.br -The other bits in flags should be set to zero. - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. - -.br - -.br -\fBExample\fP -.br - -.EX -bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1 -.br -bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2 -.br - -.EE - -.IP "\fBint bbSPIClose(unsigned CS)\fP" -.IP "" 4 -This function stops bit banging SPI on a set of GPIO -opened with \fBbbSPIOpen\fP. - -.br - -.br - -.EX -CS: 0-31, the CS GPIO used in a prior call to \fBbbSPIOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. - -.IP "\fBint bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)\fP" -.IP "" 4 -This function executes a bit banged SPI transfer. - -.br - -.br - -.EX - CS: 0-31 (as used in a prior call to \fBbbSPIOpen\fP) -.br - inBuf: pointer to buffer to hold data to be sent -.br -outBuf: pointer to buffer to hold returned data -.br - count: size of data transfer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. - -.br - -.br -\fBExample\fP -.br - -.EX -// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio -.br -// sudo ./bbSPIx_test -.br - -.br - -.br -#include -.br - -.br -#include "pigpio.h" -.br - -.br -#define CE0 5 -.br -#define CE1 6 -.br -#define MISO 13 -.br -#define MOSI 19 -.br -#define SCLK 12 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, count, set_val, read_val; -.br - unsigned char inBuf[3]; -.br - char cmd1[] = {0, 0}; -.br - char cmd2[] = {12, 0}; -.br - char cmd3[] = {1, 128, 0}; -.br - -.br - if (gpioInitialise() < 0) -.br - { -.br - fprintf(stderr, "pigpio initialisation failed.\n"); -.br - return 1; -.br - } -.br - -.br - bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC -.br - bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC -.br - -.br - for (i=0; i<256; i++) -.br - { -.br - cmd1[1] = i; -.br - -.br - count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC -.br - -.br - if (count == 2) -.br - { -.br - count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC -.br - -.br - if (count == 2) -.br - { -.br - set_val = inBuf[1]; -.br - -.br - count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC -.br - -.br - if (count == 3) -.br - { -.br - read_val = ((inBuf[1]&3)<<8) | inBuf[2]; -.br - printf("%d %d\n", set_val, read_val); -.br - } -.br - } -.br - } -.br - } -.br - -.br - bbSPIClose(CE0); -.br - bbSPIClose(CE1); -.br - -.br - gpioTerminate(); -.br - -.br - return 0; -.br -} -.br - -.EE - -.IP "\fBint spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)\fP" -.IP "" 4 -This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. - -.br - -.br -The Pi has two SPI peripherals: main and auxiliary. - -.br - -.br -The main SPI has two chip selects (channels), the auxiliary has -three. - -.br - -.br -The auxiliary SPI is available on all models but the A and B. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - MISO MOSI SCLK CE0 CE1 CE2 -.br -Main SPI 9 10 11 8 7 - -.br -Aux SPI 19 20 21 18 17 16 -.br - -.br - -.br - -.EX - spiChan: 0-1 (0-2 for the auxiliary SPI) -.br - baud: 32K-125M (values above 30M are unlikely to work) -.br -spiFlags: see below -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. - -.br - -.br -spiFlags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -.br - -.EE - -.br - -.br -mm defines the SPI mode. - -.br - -.br -Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. - -.br - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -px is 0 if CEx is active low (default) and 1 for active high. - -.br - -.br -ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. - -.br - -.br -A is 0 for the main SPI, 1 for the auxiliary SPI. - -.br - -.br -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main -SPI only. - -.br - -.br -nnnn defines the number of bytes (0-15) to write before switching -the MOSI line to MISO to read data. This field is ignored -if W is not set. Main SPI only. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. Auxiliary SPI -only. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. Auxiliary SPI -only. - -.br - -.br -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI only. - -.br - -.br -The \fBspiRead\fP, \fBspiWrite\fP, and \fBspiXfer\fP functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. - -.br - -.br -For bits 1-8 there will be one byte per word. -.br -For bits 9-16 there will be two bytes per word. -.br -For bits 17-32 there will be four bytes per word. - -.br - -.br -Multi-byte transfers are made in least significant byte first order. - -.br - -.br -E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. - -.br - -.br -E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed -by 0x1A. - -.br - -.br -The other bits in flags should be set to zero. - -.IP "\fBint spiClose(unsigned handle)\fP" -.IP "" 4 -This functions closes the SPI device identified by the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspiOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint spiRead(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads count bytes of data from the SPI -device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspiOpen\fP -.br - buf: an array to receive the read data bytes -.br - count: the number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spiWrite(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes of data from buf to the SPI -device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspiOpen\fP -.br - buf: the data bytes to write -.br - count: the number of bytes to write -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" -.IP "" 4 -This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspiOpen\fP -.br - txBuf: the data bytes to write -.br - rxBuf: the received data bytes -.br - count: the number of bytes to transfer -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint serOpen(char *sertty, unsigned baud, unsigned serFlags)\fP" -.IP "" 4 -This function opens a serial device at a specified baud rate -and with specified flags. The device name must start with -/dev/tty or /dev/serial. - -.br - -.br - -.EX - sertty: the serial device to open -.br - baud: the baud rate in bits per second, see below -.br -serFlags: 0 -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. - -.br - -.br -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.IP "\fBint serClose(unsigned handle)\fP" -.IP "" 4 -This function closes the serial device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint serWriteByte(unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This function writes bVal to the serial port associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serReadByte(unsigned handle)\fP" -.IP "" 4 -This function reads a byte from the serial port associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - -.EE - -.br - -.br -Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. - -.br - -.br -If no data is ready PI_SER_READ_NO_DATA is returned. - -.IP "\fBint serWrite(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the serial port -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - buf: the array of bytes to write -.br - count: the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serRead(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up count bytes from the the serial port -associated with handle and writes them to buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - buf: an array to receive the read data -.br - count: the maximum number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_SER_READ_NO_DATA. - -.br - -.br -If no data is ready zero is returned. - -.IP "\fBint serDataAvailable(unsigned handle)\fP" -.IP "" 4 -This function returns the number of bytes available -to be read from the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserOpen\fP -.br - -.EE - -.br - -.br -Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. - -.IP "\fBint gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)\fP" -.IP "" 4 -This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - pulseLen: 1-100 -.br - level: 0,1 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -or PI_BAD_PULSELEN. - -.IP "\fBint gpioSetWatchdog(unsigned user_gpio, unsigned timeout)\fP" -.IP "" 4 -Sets a watchdog for a GPIO. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - timeout: 0-60000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. - -.br - -.br -The watchdog is nominally in milliseconds. - -.br - -.br -One watchdog may be registered per GPIO. - -.br - -.br -The watchdog may be cancelled by setting timeout to 0. - -.br - -.br -Until cancelled a timeout will be reported every timeout milliseconds -after the last GPIO activity. - -.br - -.br -In particular: - -.br - -.br -1) any registered alert function for the GPIO will be called with - the level set to PI_TIMEOUT. - -.br - -.br -2) any notification for the GPIO will have a report written to the - fifo with the flags set to indicate a watchdog timeout. - -.br - -.br -\fBExample\fP -.br - -.EX -void aFunction(int gpio, int level, uint32_t tick) -.br -{ -.br - printf("GPIO %d became %d at %d", gpio, level, tick); -.br -} -.br - -.br -// call aFunction whenever GPIO 4 changes state -.br -gpioSetAlertFunc(4, aFunction); -.br - -.br -// or approximately every 5 millis -.br -gpioSetWatchdog(4, 5); -.br - -.EE - -.IP "\fBint gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)\fP" -.IP "" 4 -Sets a noise filter on a GPIO. - -.br - -.br -Level changes on the GPIO are ignored until a level which has -been stable for \fBsteady\fP microseconds is detected. Level changes -on the GPIO are then reported for \fBactive\fP microseconds after -which the process repeats. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - steady: 0-300000 -.br - active: 0-1000000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - -.br - -.br -This filter affects the GPIO samples returned to callbacks set up -with \fBgpioSetAlertFunc\fP, \fBgpioSetAlertFuncEx\fP, \fBgpioSetGetSamplesFunc\fP, -and \fBgpioSetGetSamplesFuncEx\fP. - -.br - -.br -It does not affect interrupts set up with \fBgpioSetISRFunc\fP, -\fBgpioSetISRFuncEx\fP, or levels read by \fBgpioRead\fP, -\fBgpioRead_Bits_0_31\fP, or \fBgpioRead_Bits_32_53\fP. - -.br - -.br -Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. - -.IP "\fBint gpioGlitchFilter(unsigned user_gpio, unsigned steady)\fP" -.IP "" 4 -Sets a glitch filter on a GPIO. - -.br - -.br -Level changes on the GPIO are not reported unless the level -has been stable for at least \fBsteady\fP microseconds. The -level is then reported. Level changes of less than \fBsteady\fP -microseconds are ignored. - -.br - -.br - -.EX -user_gpio: 0-31 -.br - steady: 0-300000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - -.br - -.br -This filter affects the GPIO samples returned to callbacks set up -with \fBgpioSetAlertFunc\fP, \fBgpioSetAlertFuncEx\fP, \fBgpioSetGetSamplesFunc\fP, -and \fBgpioSetGetSamplesFuncEx\fP. - -.br - -.br -It does not affect interrupts set up with \fBgpioSetISRFunc\fP, -\fBgpioSetISRFuncEx\fP, or levels read by \fBgpioRead\fP, -\fBgpioRead_Bits_0_31\fP, or \fBgpioRead_Bits_32_53\fP. - -.br - -.br -Each (stable) edge will be timestamped \fBsteady\fP microseconds -after it was first detected. - -.IP "\fBint gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)\fP" -.IP "" 4 -Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. - -.br - -.br - -.EX - f: the function to call -.br -bits: the GPIO of interest -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -The function is passed a pointer to the samples (an array of -\fBgpioSample_t\fP), and the number of samples. - -.br - -.br -Only one function can be registered. - -.br - -.br -The callback may be cancelled by passing NULL as the function. - -.br - -.br -The samples returned will be the union of bits, plus any active alerts, -plus any active notifications. - -.br - -.br -e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO -8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO -7, 8, 9, 10, 17, 23, and 24 will be reported. - -.IP "\fBint gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. - -.br - -.br - -.EX - f: the function to call -.br - bits: the GPIO of interest -.br -userdata: a pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -The function is passed a pointer to the samples (an array of -\fBgpioSample_t\fP), the number of samples, and the userdata pointer. - -.br - -.br -Only one of \fBgpioGetSamplesFunc\fP or \fBgpioGetSamplesFuncEx\fP can be -registered. - -.br - -.br -See \fBgpioSetGetSamplesFunc\fP for further details. - -.IP "\fBint gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) every millis milliseconds. - -.br - -.br - -.EX - timer: 0-9 -.br -millis: 10-60000 -.br - f: the function to call -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. - -.br - -.br -10 timers are supported numbered 0 to 9. - -.br - -.br -One function may be registered per timer. - -.br - -.br -The timer may be cancelled by passing NULL as the function. - -.br - -.br -\fBExample\fP -.br - -.EX -void bFunction(void) -.br -{ -.br - printf("two seconds have elapsed"); -.br -} -.br - -.br -// call bFunction every 2000 milliseconds -.br -gpioSetTimerFunc(0, 2000, bFunction); -.br - -.EE - -.IP "\fBint gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) every millis milliseconds. - -.br - -.br - -.EX - timer: 0-9. -.br - millis: 10-60000 -.br - f: the function to call -.br -userdata: a pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. - -.br - -.br -The function is passed the userdata pointer. - -.br - -.br -Only one of \fBgpioSetTimerFunc\fP or \fBgpioSetTimerFuncEx\fP can be -registered per timer. - -.br - -.br -See \fBgpioSetTimerFunc\fP for further details. - -.IP "\fBpthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)\fP" -.IP "" 4 -Starts a new thread of execution with f as the main routine. - -.br - -.br - -.EX - f: the main function for the new thread -.br -userdata: a pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns a pointer to pthread_t if OK, otherwise NULL. - -.br - -.br -The function is passed the single argument arg. - -.br - -.br -The thread can be cancelled by passing the pointer to pthread_t to -\fBgpioStopThread\fP. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -void *myfunc(void *arg) -.br -{ -.br - while (1) -.br - { -.br - printf("%s", arg); -.br - sleep(1); -.br - } -.br -} -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - pthread_t *p1, *p2, *p3; -.br - -.br - if (gpioInitialise() < 0) return 1; -.br - -.br - p1 = gpioStartThread(myfunc, "thread 1"); sleep(3); -.br - -.br - p2 = gpioStartThread(myfunc, "thread 2"); sleep(3); -.br - -.br - p3 = gpioStartThread(myfunc, "thread 3"); sleep(3); -.br - -.br - gpioStopThread(p3); sleep(3); -.br - -.br - gpioStopThread(p2); sleep(3); -.br - -.br - gpioStopThread(p1); sleep(3); -.br - -.br - gpioTerminate(); -.br -} -.br - -.EE - -.IP "\fBvoid gpioStopThread(pthread_t *pth)\fP" -.IP "" 4 -Cancels the thread pointed at by pth. - -.br - -.br - -.EX -pth: a thread pointer returned by \fBgpioStartThread\fP -.br - -.EE - -.br - -.br -No value is returned. - -.br - -.br -The thread to be stopped should have been started with \fBgpioStartThread\fP. - -.IP "\fBint gpioStoreScript(char *script)\fP" -.IP "" 4 -This function stores a null terminated script for later execution. - -.br - -.br -See \fBhttp://abyz.me.uk/rpi/pigpio/pigs.html#Scripts\fP for details. - -.br - -.br - -.EX -script: the text of the script -.br - -.EE - -.br - -.br -The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. - -.IP "\fBint gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function runs a stored script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - numPar: 0-10, the number of parameters -.br - param: an array of parameters -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function runs a stored script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - numPar: 0-10, the number of parameters -.br - param: an array of parameters -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - numPar: 0-10, the number of parameters -.br - param: an array of parameters -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint gpioScriptStatus(unsigned script_id, uint32_t *param)\fP" -.IP "" 4 -This function returns the run status of a stored script as well as -the current values of parameters 0 to 9. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - param: an array to hold the returned 10 parameters -.br - -.EE - -.br - -.br -The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. - -.br - -.br -The run status may be - -.br - -.br - -.EX -PI_SCRIPT_INITING -.br -PI_SCRIPT_HALTED -.br -PI_SCRIPT_RUNNING -.br -PI_SCRIPT_WAITING -.br -PI_SCRIPT_FAILED -.br - -.EE - -.br - -.br -The current value of script parameters 0 to 9 are returned in param. - -.IP "\fBint gpioStopScript(unsigned script_id)\fP" -.IP "" 4 -This function stops a running script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint gpioDeleteScript(unsigned script_id)\fP" -.IP "" 4 -This function deletes a stored script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBgpioStoreScript\fP -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) when a signal occurs. - -.br - -.br - -.EX -signum: 0-63 -.br - f: the callback function -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_SIGNUM. - -.br - -.br -The function is passed the signal number. - -.br - -.br -One function may be registered per signal. - -.br - -.br -The callback may be cancelled by passing NULL. - -.br - -.br -By default all signals are treated as fatal and cause the library -to call gpioTerminate and then exit. - -.IP "\fBint gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) when a signal occurs. - -.br - -.br - -.EX - signum: 0-63 -.br - f: the callback function -.br -userdata: a pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_SIGNUM. - -.br - -.br -The function is passed the signal number and the userdata pointer. - -.br - -.br -Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be -registered per signal. - -.br - -.br -See gpioSetSignalFunc for further details. - -.IP "\fBuint32_t gpioRead_Bits_0_31(void)\fP" -.IP "" 4 -Returns the current level of GPIO 0-31. - -.IP "\fBuint32_t gpioRead_Bits_32_53(void)\fP" -.IP "" 4 -Returns the current level of GPIO 32-53. - -.IP "\fBint gpioWrite_Bits_0_31_Clear(uint32_t bits)\fP" -.IP "" 4 -Clears GPIO 0-31 if the corresponding bit in bits is set. - -.br - -.br - -.EX -bits: a bit mask of GPIO to clear -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -\fBExample\fP -.br - -.EX -// To clear (set to 0) GPIO 4, 7, and 15 -.br -gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) ); -.br - -.EE - -.IP "\fBint gpioWrite_Bits_32_53_Clear(uint32_t bits)\fP" -.IP "" 4 -Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. - -.br - -.br - -.EX -bits: a bit mask of GPIO to clear -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.IP "\fBint gpioWrite_Bits_0_31_Set(uint32_t bits)\fP" -.IP "" 4 -Sets GPIO 0-31 if the corresponding bit in bits is set. - -.br - -.br - -.EX -bits: a bit mask of GPIO to set -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.IP "\fBint gpioWrite_Bits_32_53_Set(uint32_t bits)\fP" -.IP "" 4 -Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. - -.br - -.br - -.EX -bits: a bit mask of GPIO to set -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -\fBExample\fP -.br - -.EX -// To set (set to 1) GPIO 32, 40, and 53 -.br -gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32))); -.br - -.EE - -.IP "\fBint gpioHardwareClock(unsigned gpio, unsigned clkfreq)\fP" -.IP "" 4 -Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. - -.br - -.br - -.EX - gpio: see description -.br -clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, -PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. - -.br - -.br -The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. - -.br - -.br -The GPIO must be one of the following. - -.br - -.br - -.EX -4 clock 0 All models -.br -5 clock 1 All models but A and B (reserved for system use) -.br -6 clock 2 All models but A and B -.br -20 clock 0 All models but A and B -.br -21 clock 1 All models but A and Rev.2 B (reserved for system use) -.br - -.br -32 clock 0 Compute module only -.br -34 clock 0 Compute module only -.br -42 clock 1 Compute module only (reserved for system use) -.br -43 clock 2 Compute module only -.br -44 clock 1 Compute module only (reserved for system use) -.br - -.EE - -.br - -.br -Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. - -.IP "\fBint gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)\fP" -.IP "" 4 -Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. - -.br - -.br -NOTE: Any waveform started by \fBgpioWaveTxSend\fP, or -\fBgpioWaveChain\fP will be cancelled. - -.br - -.br -This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden by a call to -\fBgpioCfgClock\fP. - -.br - -.br - -.EX - gpio: see description -.br -PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) -.br -PWMduty: 0 (off) to 1000000 (1M)(fully on) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, -PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. - -.br - -.br -The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. - -.br - -.br -The GPIO must be one of the following. - -.br - -.br - -.EX -12 PWM channel 0 All models but A and B -.br -13 PWM channel 1 All models but A and B -.br -18 PWM channel 0 All models -.br -19 PWM channel 1 All models but A and B -.br - -.br -40 PWM channel 0 Compute module only -.br -41 PWM channel 1 Compute module only -.br -45 PWM channel 1 Compute module only -.br -52 PWM channel 0 Compute module only -.br -53 PWM channel 1 Compute module only -.br - -.EE - -.br - -.br -The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). - -.br - -.br -The actual frequency set is 250M/steps (375M/steps for the BCM2711). - -.br - -.br -There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. - -.IP "\fBint gpioTime(unsigned timetype, int *seconds, int *micros)\fP" -.IP "" 4 -Updates the seconds and micros variables with the current time. - -.br - -.br - -.EX -timetype: 0 (relative), 1 (absolute) -.br - seconds: a pointer to an int to hold seconds -.br - micros: a pointer to an int to hold microseconds -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_TIMETYPE. - -.br - -.br -If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the -number of seconds and microseconds since the epoch (1st January 1970). - -.br - -.br -If timetype is PI_TIME_RELATIVE updates seconds and micros with the -number of seconds and microseconds since the library was initialised. - -.br - -.br -\fBExample\fP -.br - -.EX -int secs, mics; -.br - -.br -// print the number of seconds since the library was started -.br -gpioTime(PI_TIME_RELATIVE, &secs, &mics); -.br -printf("library started %d.%03d seconds ago", secs, mics/1000); -.br - -.EE - -.IP "\fBint gpioSleep(unsigned timetype, int seconds, int micros)\fP" -.IP "" 4 -Sleeps for the number of seconds and microseconds specified by seconds -and micros. - -.br - -.br - -.EX -timetype: 0 (relative), 1 (absolute) -.br - seconds: seconds to sleep -.br - micros: microseconds to sleep -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, -or PI_BAD_MICROS. - -.br - -.br -If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds -and microseconds since the epoch (1st January 1970) has elapsed. System -clock changes are taken into account. - -.br - -.br -If timetype is PI_TIME_RELATIVE the sleep is for the specified number -of seconds and microseconds. System clock changes do not effect the -sleep length. - -.br - -.br -For short delays (say, 50 microseonds or less) use \fBgpioDelay\fP. - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds -.br - -.br -gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds -.br - -.br -gpioSleep(PI_TIME_RELATIVE, 60, 0); // sleep for one minute -.br - -.EE - -.IP "\fBuint32_t gpioDelay(uint32_t micros)\fP" -.IP "" 4 -Delays for at least the number of microseconds specified by micros. - -.br - -.br - -.EX -micros: the number of microseconds to sleep -.br - -.EE - -.br - -.br -Returns the actual length of the delay in microseconds. - -.br - -.br -Delays of 100 microseconds or less use busy waits. - -.IP "\fBuint32_t gpioTick(void)\fP" -.IP "" 4 -Returns the current system tick. - -.br - -.br -Tick is the number of microseconds since system boot. - -.br - -.br -As tick is an unsigned 32 bit quantity it wraps around after -2^32 microseconds, which is approximately 1 hour 12 minutes. - -.br - -.br -You don't need to worry about the wrap around as long as you -take a tick (uint32_t) from another tick, i.e. the following -code will always provide the correct difference. - -.br - -.br -\fBExample\fP -.br - -.EX -uint32_t startTick, endTick; -.br -int diffTick; -.br - -.br -startTick = gpioTick(); -.br - -.br -// do some processing -.br - -.br -endTick = gpioTick(); -.br - -.br -diffTick = endTick - startTick; -.br - -.br -printf("some processing took %d microseconds", diffTick); -.br - -.EE - -.IP "\fBunsigned gpioHardwareRevision(void)\fP" -.IP "" 4 -Returns the hardware revision. - -.br - -.br -If the hardware revision can not be found or is not a valid hexadecimal -number the function returns 0. - -.br - -.br -The hardware revision is the last few characters on the Revision line of -/proc/cpuinfo. - -.br - -.br -The revision number can be used to determine the assignment of GPIO -to pins (see \fBgpio\fP). - -.br - -.br -There are at least three types of board. - -.br - -.br -Type 1 boards have hardware revision numbers of 2 and 3. - -.br - -.br -Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. - -.br - -.br -Type 3 boards have hardware revision numbers of 16 or greater. - -.br - -.br -for "Revision : 0002" the function returns 2. -.br -for "Revision : 000f" the function returns 15. -.br -for "Revision : 000g" the function returns 0. - -.IP "\fBunsigned gpioVersion(void)\fP" -.IP "" 4 -Returns the pigpio version. - -.IP "\fBint gpioGetPad(unsigned pad)\fP" -.IP "" 4 -This function returns the pad drive strength in mA. - -.br - -.br - -.EX -pad: 0-2, the pad to get -.br - -.EE - -.br - -.br -Returns the pad drive strength if OK, otherwise PI_BAD_PAD. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -strength = gpioGetPad(1); // get pad 1 strength -.br - -.EE - -.IP "\fBint gpioSetPad(unsigned pad, unsigned padStrength)\fP" -.IP "" 4 -This function sets the pad drive strength in mA. - -.br - -.br - -.EX - pad: 0-2, the pad to set -.br -padStrength: 1-16 mA -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -gpioSetPad(0, 16); // set pad 0 strength to 16 mA -.br - -.EE - -.IP "\fBint eventMonitor(unsigned handle, uint32_t bits)\fP" -.IP "" 4 -This function selects the events to be reported on a previously -opened handle. - -.br - -.br - -.EX -handle: >=0, as returned by \fBgpioNotifyOpen\fP -.br - bits: a bit mask indicating the events of interest -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -A report is sent each time an event is triggered providing the -corresponding bit in bits is set. - -.br - -.br -See \fBgpioNotifyBegin\fP for the notification format. - -.br - -.br -\fBExample\fP -.br - -.EX -// Start reporting events 3, 6, and 7. -.br - -.br -// bit 76543210 -.br -// (0xC8 = 0b11001000) -.br - -.br -eventMonitor(h, 0xC8); -.br - -.EE - -.br - -.br - -.IP "\fBint eventSetFunc(unsigned event, eventFunc_t f)\fP" -.IP "" 4 -Registers a function to be called (a callback) when the specified -event occurs. - -.br - -.br - -.EX -event: 0-31 -.br - f: the callback function -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - -.br - -.br -One function may be registered per event. - -.br - -.br -The function is passed the event, and the tick. - -.br - -.br -The callback may be cancelled by passing NULL as the function. - -.IP "\fBint eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)\fP" -.IP "" 4 -Registers a function to be called (a callback) when the specified -event occurs. - -.br - -.br - -.EX - event: 0-31 -.br - f: the callback function -.br -userdata: pointer to arbitrary user data -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - -.br - -.br -One function may be registered per event. - -.br - -.br -The function is passed the event, the tick, and the ueserdata pointer. - -.br - -.br -The callback may be cancelled by passing NULL as the function. - -.br - -.br -Only one of \fBeventSetFunc\fP or \fBeventSetFuncEx\fP can be -registered per event. - -.IP "\fBint eventTrigger(unsigned event)\fP" -.IP "" 4 -This function signals the occurrence of an event. - -.br - -.br - -.EX -event: 0-31, the event -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - -.br - -.br -An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling \fBeventSetFunc\fP) will be informed by -a callback. - -.br - -.br -One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. - -.br - -.br -The meaning of other events is arbitrary. - -.br - -.br -Note that other than its id and its tick there is no data associated -with an event. - -.IP "\fBint shell(char *scriptName, char *scriptString)\fP" -.IP "" 4 -This function uses the system call to execute a shell script -with the given string as its parameter. - -.br - -.br - -.EX - scriptName: the name of the script, only alphanumeric characters, -.br - '-' and '_' are allowed in the name -.br -scriptString: the string to pass to the script -.br - -.EE - -.br - -.br -The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. - -.br - -.br -scriptName must exist in /opt/pigpio/cgi and must be executable. - -.br - -.br -The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. - -.br - -.br -The following table gives some example returned statuses. - -.br - -.br -Script exit status Returned system call status -.br -1 256 -.br -5 1280 -.br -10 2560 -.br -200 51200 -.br -script not found 32512 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -// pass two parameters, hello and world -.br -status = shell("scr1", "hello world"); -.br - -.br -// pass three parameters, hello, string with spaces, and world -.br -status = shell("scr1", "hello 'string with spaces' world"); -.br - -.br -// pass one parameter, hello string with spaces world -.br -status = shell("scr1", "\"hello string with spaces world\""); -.br - -.EE - -.IP "\fBint fileOpen(char *file, unsigned mode)\fP" -.IP "" 4 -This function returns a handle to a file opened in a specified mode. - -.br - -.br - -.EX -file: the file to open -.br -mode: the file open mode -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. - -.br - -.br -File - -.br - -.br -A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. - -.br - -.br -Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. - -.br - -.br -Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. - -.br - -.br -Suppose /opt/pigpio/access contains the following entries - -.br - -.br - -.EX -/home/* n -.br -/home/pi/shared/dir_1/* w -.br -/home/pi/shared/dir_2/* r -.br -/home/pi/shared/dir_3/* u -.br -/home/pi/shared/dir_1/file.txt n -.br - -.EE - -.br - -.br -Files may be written in directory dir_1 with the exception -of file.txt. - -.br - -.br -Files may be read in directory dir_2. - -.br - -.br -Files may be read and written in directory dir_3. - -.br - -.br -If a directory allows read, write, or read/write access then files may -be created in that directory. - -.br - -.br -In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. - -.br - -.br - -.EX -a path containing .. -.br -a path containing only wildcards (*?) -.br -a path containing less than two non-wildcard parts -.br - -.EE - -.br - -.br -Mode - -.br - -.br -The mode may have the following values. - -.br - -.br -Macro Value Meaning -.br -PI_FILE_READ 1 open file for reading -.br -PI_FILE_WRITE 2 open file for writing -.br -PI_FILE_RW 3 open file for reading and writing -.br - -.br - -.br -The following values may be or'd into the mode. - -.br - -.br -Macro Value Meaning -.br -PI_FILE_APPEND 4 Writes append data to the end of the file -.br -PI_FILE_CREATE 8 The file is created if it doesn't exist -.br -PI_FILE_TRUNC 16 The file is truncated -.br - -.br - -.br -Newly created files are owned by root with permissions owner read and write. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int handle, c; -.br - char buf[60000]; -.br - -.br - if (gpioInitialise() < 0) return 1; -.br - -.br - // assumes /opt/pigpio/access contains the following line -.br - // /ram/*.c r -.br - -.br - handle = fileOpen("/ram/pigpio.c", PI_FILE_READ); -.br - -.br - if (handle >= 0) -.br - { -.br - while ((c=fileRead(handle, buf, sizeof(buf)-1))) -.br - { -.br - buf[c] = 0; -.br - printf("%s", buf); -.br - } -.br - -.br - fileClose(handle); -.br - } -.br - -.br - gpioTerminate(); -.br -} -.br - -.EE - -.IP "\fBint fileClose(unsigned handle)\fP" -.IP "" 4 -This function closes the file associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBfileOpen\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -\fBExample\fP -.br - -.EX -fileClose(h); -.br - -.EE - -.IP "\fBint fileWrite(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the file -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBfileOpen\fP -.br - buf: the array of bytes to write -.br - count: the number of bytes to write -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. - -.br - -.br -\fBExample\fP -.br - -.EX -status = fileWrite(h, buf, count); -.br -if (status == 0) -.br -{ -.br - // okay -.br -} -.br -else -.br -{ -.br - // error -.br -} -.br - -.EE - -.IP "\fBint fileRead(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up to count bytes from the the file -associated with handle and writes them to buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBfileOpen\fP -.br - buf: an array to receive the read data -.br - count: the maximum number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. - -.br - -.br -\fBExample\fP -.br - -.EX -if (fileRead(h, buf, sizeof(buf)) > 0) -.br -{ -.br - // process read data -.br -} -.br - -.EE - -.IP "\fBint fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)\fP" -.IP "" 4 -This function seeks to a position within the file associated -with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBfileOpen\fP -.br -seekOffset: the number of bytes to move. Positive offsets -.br - move forward, negative offsets backwards. -.br - seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1), -.br - or PI_FROM_END (2) -.br - -.EE - -.br - -.br -Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. - -.br - -.br -\fBExample\fP -.br - -.EX -fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20 -.br - -.br -size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size -.br - -.br -pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position -.br - -.EE - -.IP "\fBint fileList(char *fpat, char *buf, unsigned count)\fP" -.IP "" 4 -This function returns a list of files which match a pattern. The -pattern may contain wildcards. - -.br - -.br - -.EX - fpat: file pattern to match -.br - buf: an array to receive the matching file names -.br -count: the maximum number of bytes to read -.br - -.EE - -.br - -.br -Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. - -.br - -.br -The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See \fBfileOpen\fP. - -.br - -.br -NOTE - -.br - -.br -The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int c; -.br - char buf[1000]; -.br - -.br - if (gpioInitialise() < 0) return 1; -.br - -.br - // assumes /opt/pigpio/access contains the following line -.br - // /ram/*.c r -.br - -.br - c = fileList("/ram/p*.c", buf, sizeof(buf)); -.br - -.br - if (c >= 0) -.br - { -.br - // terminate string -.br - buf[c] = 0; -.br - printf("%s", buf); -.br - } -.br - -.br - gpioTerminate(); -.br -} -.br - -.EE - -.IP "\fBint gpioCfgBufferSize(unsigned cfgMillis)\fP" -.IP "" 4 -Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX -cfgMillis: 100-10000 -.br - -.EE - -.br - -.br -The default setting is 120 milliseconds. - -.br - -.br -The intention is to allow for bursts of data and protection against -other processes hogging cpu time. - -.br - -.br -I haven't seen a process locked out for more than 100 milliseconds. - -.br - -.br -Making the buffer bigger uses a LOT of memory at the more frequent -sampling rates as shown in the following table in MBs. - -.br - -.br - -.EX - buffer milliseconds -.br - 120 250 500 1sec 2sec 4sec 8sec -.br - -.br - 1 16 31 55 107 --- --- --- -.br - 2 10 18 31 55 107 --- --- -.br -sample 4 8 12 18 31 55 107 --- -.br - rate 5 8 10 14 24 45 87 --- -.br - (us) 8 6 8 12 18 31 55 107 -.br - 10 6 8 10 14 24 45 87 -.br - -.EE - -.IP "\fBint gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)\fP" -.IP "" 4 -Configures pigpio to use a particular sample rate timed by a specified -peripheral. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX - cfgMicros: 1, 2, 4, 5, 8, 10 -.br -cfgPeripheral: 0 (PWM), 1 (PCM) -.br - cfgSource: deprecated, value is ignored -.br - -.EE - -.br - -.br -The timings are provided by the specified peripheral (PWM or PCM). - -.br - -.br -The default setting is 5 microseconds using the PCM peripheral. - -.br - -.br -The approximate CPU percentage used for each sample rate is: - -.br - -.br - -.EX -sample cpu -.br - rate % -.br - -.br - 1 25 -.br - 2 16 -.br - 4 11 -.br - 5 10 -.br - 8 15 -.br - 10 14 -.br - -.EE - -.br - -.br -A sample rate of 5 microseconds seeems to be the sweet spot. - -.IP "\fBint gpioCfgDMAchannel(unsigned DMAchannel)\fP" -.IP "" 4 -Configures pigpio to use the specified DMA channel. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX -DMAchannel: 0-14 -.br - -.EE - -.br - -.br -The default setting is to use channel 14. - -.IP "\fBint gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)\fP" -.IP "" 4 -Configures pigpio to use the specified DMA channels. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX - primaryChannel: 0-14 -.br -secondaryChannel: 0-14 -.br - -.EE - -.br - -.br -The default setting depends on whether the Pi has a BCM2711 chip or -not (currently only the Pi4B has a BCM2711). - -.br - -.br -The default setting for a non-BCM2711 is to use channel 14 for the -primary channel and channel 6 for the secondary channel. - -.br - -.br -The default setting for a BCM2711 is to use channel 7 for the -primary channel and channel 6 for the secondary channel. - -.br - -.br -The secondary channel is only used for the transmission of waves. - -.br - -.br -If possible use one of channels 0 to 6 for the secondary channel -(a full channel). - -.br - -.br -A full channel only requires one DMA control block regardless of the -length of a pulse delay. Channels 7 to 14 (lite channels) require -one DMA control block for each 16383 microseconds of delay. I.e. -a 10 second pulse delay requires one control block on a full channel -and 611 control blocks on a lite channel. - -.IP "\fBint gpioCfgPermissions(uint64_t updateMask)\fP" -.IP "" 4 -Configures pigpio to restrict GPIO updates via the socket or pipe -interfaces to the GPIO specified by the mask. Programs directly -calling the pigpio library (i.e. linked with -lpigpio are not -affected). A GPIO update is a write to a GPIO or a GPIO mode -change or any function which would force such an action. - -.br - -.br -This function is only effective if called before \fBgpioInitialise\fP. - -.br - -.br - -.EX -updateMask: bit (1<=0 -.br -arg2: >=0 -.br -argx: extra (byte) arguments -.br -argc: number of extra arguments -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.IP "\fBint gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It differs from gpioCustom1 in that it returns an array of bytes -rather than just an integer. - -.br - -.br -The returned value is an integer indicating the number of returned bytes. - -.EX - arg1: >=0 -.br - argx: extra (byte) arguments -.br - argc: number of extra arguments -.br -retBuf: buffer for returned bytes -.br -retMax: maximum number of bytes to return -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.br - -.br -The number of returned bytes must be retMax or less. - -.IP "\fBint rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)\fP" -.IP "" 4 -This function adds a waveform representing SPI data to the -existing waveform (if any). - -.br - -.br - -.EX - spi: a pointer to a spi object -.br - offset: microseconds from the start of the waveform -.br - spiSS: the slave select GPIO -.br - buf: the bits to transmit, most significant bit first -.br - spiTxBits: the number of bits to write -.br -spiBitFirst: the first bit to read -.br - spiBitLast: the last bit to read -.br - spiBits: the number of bits to transfer -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. - -.br - -.br -Not intended for general use. - -.IP "\fBint rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)\fP" -.IP "" 4 -This function adds a number of pulses to the current waveform. - -.br - -.br - -.EX -numPulses: the number of pulses -.br - pulses: the array containing the pulses -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. - -.br - -.br -The advantage of this function over gpioWaveAddGeneric is that it -allows the setting of the flags field. - -.br - -.br -The pulses are interleaved in time order within the existing waveform -(if any). - -.br - -.br -Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. - -.br - -.br -If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. - -.br - -.br -Not intended for general use. - -.IP "\fBunsigned rawWaveCB(void)\fP" -.IP "" 4 -Returns the number of the cb being currently output. - -.br - -.br -Not intended for general use. - -.IP "\fBrawCbs_t *rawWaveCBAdr(int cbNum)\fP" -.IP "" 4 -Return the (Linux) address of contol block cbNum. - -.br - -.br - -.EX -cbNum: the cb of interest -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBuint32_t rawWaveGetOOL(int pos)\fP" -.IP "" 4 -Gets the OOL parameter stored at pos. - -.br - -.br - -.EX -pos: the position of interest. -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBvoid rawWaveSetOOL(int pos, uint32_t lVal)\fP" -.IP "" 4 -Sets the OOL parameter stored at pos to value. - -.br - -.br - -.EX - pos: the position of interest -.br -lVal: the value to write -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBuint32_t rawWaveGetOut(int pos)\fP" -.IP "" 4 -Gets the wave output parameter stored at pos. - -.br - -.br -DEPRECATED: use rawWaveGetOOL instead. - -.br - -.br - -.EX -pos: the position of interest. -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBvoid rawWaveSetOut(int pos, uint32_t lVal)\fP" -.IP "" 4 -Sets the wave output parameter stored at pos to value. - -.br - -.br -DEPRECATED: use rawWaveSetOOL instead. - -.br - -.br - -.EX - pos: the position of interest -.br -lVal: the value to write -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBuint32_t rawWaveGetIn(int pos)\fP" -.IP "" 4 -Gets the wave input value parameter stored at pos. - -.br - -.br -DEPRECATED: use rawWaveGetOOL instead. - -.br - -.br - -.EX -pos: the position of interest -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBvoid rawWaveSetIn(int pos, uint32_t lVal)\fP" -.IP "" 4 -Sets the wave input value stored at pos to value. - -.br - -.br -DEPRECATED: use rawWaveSetOOL instead. - -.br - -.br - -.EX - pos: the position of interest -.br -lVal: the value to write -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBrawWaveInfo_t rawWaveInfo(int wave_id)\fP" -.IP "" 4 -Gets details about the wave with id wave_id. - -.br - -.br - -.EX -wave_id: the wave of interest -.br - -.EE - -.br - -.br -Not intended for general use. - -.IP "\fBint getBitInBytes(int bitPos, char *buf, int numBits)\fP" -.IP "" 4 -Returns the value of the bit bitPos bits from the start of buf. Returns -0 if bitPos is greater than or equal to numBits. - -.br - -.br - -.EX - bitPos: bit index from the start of buf -.br - buf: array of bits -.br -numBits: number of valid bits in buf -.br - -.EE - -.br - -.br - -.IP "\fBvoid putBitInBytes(int bitPos, char *buf, int bit)\fP" -.IP "" 4 -Sets the bit bitPos bits from the start of buf to bit. - -.br - -.br - -.EX -bitPos: bit index from the start of buf -.br - buf: array of bits -.br - bit: 0-1, value to set -.br - -.EE - -.br - -.br - -.IP "\fBdouble time_time(void)\fP" -.IP "" 4 -Return the current time in seconds since the Epoch. - -.IP "\fBvoid time_sleep(double seconds)\fP" -.IP "" 4 -Delay execution for a given number of seconds - -.br - -.br - -.EX -seconds: the number of seconds to sleep -.br - -.EE - -.IP "\fBvoid rawDumpWave(void)\fP" -.IP "" 4 -Used to print a readable version of the current waveform to stderr. - -.br - -.br -Not intended for general use. - -.IP "\fBvoid rawDumpScript(unsigned script_id)\fP" -.IP "" 4 -Used to print a readable version of a script to stderr. - -.br - -.br - -.EX -script_id: >=0, a script_id returned by \fBgpioStoreScript\fP -.br - -.EE - -.br - -.br -Not intended for general use. -.SH PARAMETERS - -.br - -.br - -.IP "\fBactive\fP: 0-1000000" 0 - -.br - -.br -The number of microseconds level changes are reported for once -a noise filter has been triggered (by \fBsteady\fP microseconds of -a stable level). - -.br - -.br - -.IP "\fBarg1\fP" 0 - -.br - -.br -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBarg2\fP" 0 - -.br - -.br -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBargc\fP" 0 -The count of bytes passed to a user customised function. - -.br - -.br - -.IP "\fB*argx\fP" 0 -A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. - -.br - -.br - -.IP "\fBbaud\fP" 0 -The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. - -.br - -.br - -.IP "\fBbit\fP" 0 -A value of 0 or 1. - -.br - -.br - -.IP "\fBbitPos\fP" 0 -A bit position within a byte or word. The least significant bit is -position 0. - -.br - -.br - -.IP "\fBbits\fP" 0 -A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. - -.br - -.br -A convenient way to set bit n is to or in (1<=0" 0 - -.br - -.br -The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. - -.br - -.br - -.IP "\fBgpio\fP" 0 - -.br - -.br -A Broadcom numbered GPIO, in the range 0-53. - -.br - -.br -There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through -GPIO53. - -.br - -.br -They are split into two banks. Bank 1 consists of GPIO0 through -GPIO31. Bank 2 consists of GPIO32 through GPIO53. - -.br - -.br -All the GPIO which are safe for the user to read and write are in -bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards -have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. - -.br - -.br -See \fBgpioHardwareRevision\fP. - -.br - -.br -The user GPIO are marked with an X in the following table. - -.br - -.br - -.EX - 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -.br -Type 1 X X - - X - - X X X X X - - X X -.br -Type 2 - - X X X - - X X X X X - - X X -.br -Type 3 X X X X X X X X X X X X X X -.br - -.br - 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 -.br -Type 1 - X X - - X X X X X - - - - - - -.br -Type 2 - X X - - - X X X X - X X X X X -.br -Type 3 X X X X X X X X X X X X - - - - -.br - -.EE - -.br - -.br - -.IP "\fBgpioAlertFunc_t\fP" 0 - -.EX -typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBgpioAlertFuncEx_t\fP" 0 - -.EX -typedef void (*eventFuncEx_t) -.br - (int event, int level, uint32_t tick, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioCfg*\fP" 0 - -.br - -.br -These functions are only effective if called before \fBgpioInitialise\fP. - -.br - -.br -\fBgpioCfgBufferSize\fP -.br -\fBgpioCfgClock\fP -.br -\fBgpioCfgDMAchannel\fP -.br -\fBgpioCfgDMAchannels\fP -.br -\fBgpioCfgPermissions\fP -.br -\fBgpioCfgInterfaces\fP -.br -\fBgpioCfgSocketPort\fP -.br -\fBgpioCfgMemAlloc\fP - -.br - -.br - -.IP "\fBgpioGetSamplesFunc_t\fP" 0 - -.EX -typedef void (*gpioGetSamplesFunc_t) -.br - (const gpioSample_t *samples, int numSamples); -.br - -.EE - -.br - -.br - -.IP "\fBgpioGetSamplesFuncEx_t\fP" 0 - -.EX -typedef void (*gpioGetSamplesFuncEx_t) -.br - (const gpioSample_t *samples, int numSamples, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioISRFunc_t\fP" 0 - -.EX -typedef void (*gpioISRFunc_t) -.br - (int gpio, int level, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBgpioISRFuncEx_t\fP" 0 - -.EX -typedef void (*gpioISRFuncEx_t) -.br - (int gpio, int level, uint32_t tick, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioPulse_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br - -.IP "\fBgpioSample_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioSample_t; -.br - -.EE - -.br - -.br - -.IP "\fBgpioSignalFunc_t\fP" 0 - -.EX -typedef void (*gpioSignalFunc_t) (int signum); -.br - -.EE - -.br - -.br - -.IP "\fBgpioSignalFuncEx_t\fP" 0 - -.EX -typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioThreadFunc_t\fP" 0 - -.EX -typedef void *(gpioThreadFunc_t) (void *); -.br - -.EE - -.br - -.br - -.IP "\fBgpioTimerFunc_t\fP" 0 - -.EX -typedef void (*gpioTimerFunc_t) (void); -.br - -.EE - -.br - -.br - -.IP "\fBgpioTimerFuncEx_t\fP" 0 - -.EX -typedef void (*gpioTimerFuncEx_t) (void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBgpioWaveAdd*\fP" 0 - -.br - -.br -One of - -.br - -.br -\fBgpioWaveAddNew\fP -.br -\fBgpioWaveAddGeneric\fP -.br -\fBgpioWaveAddSerial\fP - -.br - -.br - -.IP "\fBhandle\fP: >=0" 0 - -.br - -.br -A number referencing an object opened by one of - -.br - -.br -\fBfileOpen\fP -.br -\fBgpioNotifyOpen\fP -.br -\fBi2cOpen\fP -.br -\fBserOpen\fP -.br -\fBspiOpen\fP - -.br - -.br - -.IP "\fBi2cAddr\fP: 0-0x7F" 0 -The address of a device on the I2C bus. - -.br - -.br - -.IP "\fBi2cBus\fP: >=0" 0 - -.br - -.br -An I2C bus number. - -.br - -.br - -.IP "\fBi2cFlags\fP: 0" 0 - -.br - -.br -Flags which modify an I2C open command. None are currently defined. - -.br - -.br - -.IP "\fBi2cReg\fP: 0-255" 0 - -.br - -.br -A register of an I2C device. - -.br - -.br - -.IP "\fBifFlags\fP: 0-3" 0 - -.EX -PI_DISABLE_FIFO_IF 1 -.br -PI_DISABLE_SOCK_IF 2 -.br - -.EE - -.br - -.br - -.IP "\fB*inBuf\fP" 0 -A buffer used to pass data to a function. - -.br - -.br - -.IP "\fBinLen\fP" 0 -The number of bytes of data in a buffer. - -.br - -.br - -.IP "\fBint\fP" 0 -A whole number, negative or positive. - -.br - -.br - -.IP "\fBint32_t\fP" 0 -A 32-bit signed value. - -.br - -.br - -.IP "\fBinvert\fP" 0 -A flag used to set normal or inverted bit bang serial data level logic. - -.br - -.br - -.IP "\fBlevel\fP" 0 -The level of a GPIO. Low or High. - -.br - -.br - -.EX -PI_OFF 0 -.br -PI_ON 1 -.br - -.br -PI_CLEAR 0 -.br -PI_SET 1 -.br - -.br -PI_LOW 0 -.br -PI_HIGH 1 -.br - -.EE - -.br - -.br -There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See \fBgpioSetWatchdog\fP. - -.br - -.br - -.EX -PI_TIMEOUT 2 -.br - -.EE - -.br - -.br - -.br - -.br - -.IP "\fBlVal\fP: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)" 0 - -.br - -.br -A 32-bit word value. - -.br - -.br - -.IP "\fBmemAllocMode\fP: 0-2" 0 - -.br - -.br -The DMA memory allocation mode. - -.br - -.br - -.EX -PI_MEM_ALLOC_AUTO 0 -.br -PI_MEM_ALLOC_PAGEMAP 1 -.br -PI_MEM_ALLOC_MAILBOX 2 -.br - -.EE - -.br - -.br - -.IP "\fB*micros\fP" 0 - -.br - -.br -A value representing microseconds. - -.br - -.br - -.IP "\fBmicros\fP" 0 - -.br - -.br -A value representing microseconds. - -.br - -.br - -.IP "\fBmillis\fP" 0 - -.br - -.br -A value representing milliseconds. - -.br - -.br - -.IP "\fBMISO\fP" 0 -The GPIO used for the MISO signal when bit banging SPI. - -.br - -.br - -.IP "\fBmode\fP" 0 - -.br - -.br -1. The operational mode of a GPIO, normally INPUT or OUTPUT. - -.br - -.br - -.EX -PI_INPUT 0 -.br -PI_OUTPUT 1 -.br -PI_ALT0 4 -.br -PI_ALT1 5 -.br -PI_ALT2 6 -.br -PI_ALT3 7 -.br -PI_ALT4 3 -.br -PI_ALT5 2 -.br - -.EE - -.br - -.br -2. A file open mode. - -.br - -.br - -.EX -PI_FILE_READ 1 -.br -PI_FILE_WRITE 2 -.br -PI_FILE_RW 3 -.br - -.EE - -.br - -.br -The following values can be or'd into the mode. - -.br - -.br - -.EX -PI_FILE_APPEND 4 -.br -PI_FILE_CREATE 8 -.br -PI_FILE_TRUNC 16 -.br - -.EE - -.br - -.br - -.IP "\fBMOSI\fP" 0 -The GPIO used for the MOSI signal when bit banging SPI. - -.br - -.br - -.IP "\fBnumBits\fP" 0 - -.br - -.br -The number of bits stored in a buffer. - -.br - -.br - -.IP "\fBnumBytes\fP" 0 -The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. - -.br - -.br - -.IP "\fBnumPar\fP: 0-10" 0 -The number of parameters passed to a script. - -.br - -.br - -.IP "\fBnumPulses\fP" 0 -The number of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBnumSegs\fP" 0 -The number of segments in a combined I2C transaction. - -.br - -.br - -.IP "\fBnumSockAddr\fP" 0 -The number of network addresses allowed to use the socket interface. - -.br - -.br -0 means all addresses allowed. - -.br - -.br - -.IP "\fBoffset\fP" 0 -The associated data starts this number of microseconds from the start of -the waveform. - -.br - -.br - -.IP "\fB*outBuf\fP" 0 -A buffer used to return data from a function. - -.br - -.br - -.IP "\fBoutLen\fP" 0 -The size in bytes of an output buffer. - -.br - -.br - -.IP "\fBpad\fP: 0-2" 0 -A set of GPIO which share common drivers. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br - -.IP "\fBpadStrength\fP: 1-16" 0 -The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. - -.br - -.br - -.IP "\fB*param\fP" 0 -An array of script parameters. - -.br - -.br - -.IP "\fBpctBOOL\fP: 0-100" 0 -percent On-Off-Level (OOL) buffer to consume for wave output. - -.br - -.br - -.IP "\fBpctCB\fP: 0-100" 0 -the percent of all DMA control blocks to consume. - -.br - -.br - -.IP "\fBpctTOOL\fP: 0-100" 0 -the percent of OOL buffer to consume for wave input (flags). - -.br - -.br - -.IP "\fBpi_i2c_msg_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint16_t addr; // slave address -.br - uint16_t flags; -.br - uint16_t len; // msg length -.br - uint8_t *buf; // pointer to msg data -.br -} pi_i2c_msg_t; -.br - -.EE - -.br - -.br - -.IP "\fBport\fP: 1024-32000" 0 -The port used to bind to the pigpio socket. Defaults to 8888. - -.br - -.br - -.IP "\fBpos\fP" 0 -The position of an item. - -.br - -.br - -.IP "\fBprimaryChannel\fP: 0-15" 0 -The DMA channel used to time the sampling of GPIO and to time servo and -PWM pulses. - -.br - -.br - -.IP "\fB*pth\fP" 0 - -.br - -.br -A thread identifier, returned by \fBgpioStartThread\fP. - -.br - -.br - -.IP "\fBpthread_t\fP" 0 - -.br - -.br -A thread identifier. - -.br - -.br - -.IP "\fBpud\fP: 0-2" 0 - -.br - -.br -The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. - -.br - -.br - -.EX -PI_PUD_OFF 0 -.br -PI_PUD_DOWN 1 -.br -PI_PUD_UP 2 -.br - -.EE - -.br - -.br - -.IP "\fBpulseLen\fP" 0 - -.br - -.br -1-100, the length of a trigger pulse in microseconds. - -.br - -.br - -.IP "\fB*pulses\fP" 0 - -.br - -.br -An array of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBpulsewidth\fP: 0, 500-2500" 0 - -.EX -PI_SERVO_OFF 0 -.br -PI_MIN_SERVO_PULSEWIDTH 500 -.br -PI_MAX_SERVO_PULSEWIDTH 2500 -.br - -.EE - -.br - -.br - -.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 -The hardware PWM dutycycle. - -.br - -.br - -.EX -PI_HW_PWM_RANGE 1000000 -.br - -.EE - -.br - -.br - -.IP "\fBPWMfreq\fP: 1-125M (1-187.5M for the BCM2711)" 0 -The hardware PWM frequency. - -.br - -.br - -.EX -PI_HW_PWM_MIN_FREQ 1 -.br -PI_HW_PWM_MAX_FREQ 125000000 -.br -PI_HW_PWM_MAX_FREQ_2711 187500000 -.br - -.EE - -.br - -.br - -.IP "\fBrange\fP: 25-40000" 0 - -.EX -PI_MIN_DUTYCYCLE_RANGE 25 -.br -PI_MAX_DUTYCYCLE_RANGE 40000 -.br - -.EE - -.br - -.br - -.IP "\fBrawCbs_t\fP" 0 - -.EX -typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h -.br -{ -.br - unsigned long info; -.br - unsigned long src; -.br - unsigned long dst; -.br - unsigned long length; -.br - unsigned long stride; -.br - unsigned long next; -.br - unsigned long pad[2]; -.br -} rawCbs_t; -.br - -.EE - -.br - -.br - -.IP "\fBrawSPI_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - int clk; // GPIO for clock -.br - int mosi; // GPIO for MOSI -.br - int miso; // GPIO for MISO -.br - int ss_pol; // slave select off state -.br - int ss_us; // delay after slave select -.br - int clk_pol; // clock off state -.br - int clk_pha; // clock phase -.br - int clk_us; // clock micros -.br -} rawSPI_t; -.br - -.EE - -.br - -.br - -.IP "\fBrawWave_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br - uint32_t flags; -.br -} rawWave_t; -.br - -.EE - -.br - -.br - -.IP "\fBrawWaveInfo_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint16_t botCB; // first CB used by wave -.br - uint16_t topCB; // last CB used by wave -.br - uint16_t botOOL; // last OOL used by wave -.br - uint16_t topOOL; // first OOL used by wave -.br - uint16_t deleted; -.br - uint16_t numCB; -.br - uint16_t numBOOL; -.br - uint16_t numTOOL; -.br -} rawWaveInfo_t; -.br - -.EE - -.br - -.br - -.IP "\fB*retBuf\fP" 0 - -.br - -.br -A buffer to hold a number of bytes returned to a used customised function, - -.br - -.br - -.IP "\fBretMax\fP" 0 - -.br - -.br -The maximum number of bytes a user customised function should return. - -.br - -.br - -.IP "\fB*rxBuf\fP" 0 - -.br - -.br -A pointer to a buffer to receive data. - -.br - -.br - -.IP "\fBSCL\fP" 0 -The user GPIO to use for the clock when bit banging I2C. - -.br - -.br - -.IP "\fBSCLK\fP" 0 -The GPIO used for the SCLK signal when bit banging SPI. - -.br - -.br - -.IP "\fB*script\fP" 0 -A pointer to the text of a script. - -.br - -.br - -.IP "\fBscript_id\fP" 0 -An id of a stored script as returned by \fBgpioStoreScript\fP. - -.br - -.br - -.IP "\fB*scriptName\fP" 0 -The name of a \fBshell\fP script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. - -.br - -.br - -.IP "\fB*scriptString\fP" 0 -The string to be passed to a \fBshell\fP script to be executed. - -.br - -.br - -.IP "\fBSDA\fP" 0 -The user GPIO to use for data when bit banging I2C. - -.br - -.br - -.IP "\fBsecondaryChannel\fP: 0-6" 0 - -.br - -.br -The DMA channel used to time output waveforms. - -.br - -.br - -.IP "\fB*seconds\fP" 0 - -.br - -.br -A pointer to a uint32_t to store the second component of -a returned time. - -.br - -.br - -.IP "\fBseconds\fP" 0 -The number of seconds. - -.br - -.br - -.IP "\fBseekFrom\fP" 0 - -.br - -.br - -.EX -PI_FROM_START 0 -.br -PI_FROM_CURRENT 1 -.br -PI_FROM_END 2 -.br - -.EE - -.br - -.br - -.IP "\fBseekOffset\fP" 0 -The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). - -.br - -.br - -.IP "\fB*segs\fP" 0 -An array of segments which make up a combined I2C transaction. - -.br - -.br - -.IP "\fBserFlags\fP" 0 -Flags which modify a serial open command. None are currently defined. - -.br - -.br - -.IP "\fB*sertty\fP" 0 -The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. - -.br - -.br - -.IP "\fBsetting\fP" 0 -A value used to set a flag, 0 for false, non-zero for true. - -.br - -.br - -.IP "\fBsignum\fP: 0-63" 0 - -.EX -PI_MIN_SIGNUM 0 -.br -PI_MAX_SIGNUM 63 -.br - -.EE - -.br - -.br - -.IP "\fBsize_t\fP" 0 - -.br - -.br -A standard type used to indicate the size of an object in bytes. - -.br - -.br - -.IP "\fB*sockAddr\fP" 0 -An array of network addresses allowed to use the socket interface encoded -as 32 bit numbers. - -.br - -.br -E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. - -.br - -.br - -.IP "\fB*spi\fP" 0 -A pointer to a \fBrawSPI_t\fP structure. - -.br - -.br - -.IP "\fBspiBitFirst\fP" 0 -GPIO reads are made from spiBitFirst to spiBitLast. - -.br - -.br - -.IP "\fBspiBitLast\fP" 0 - -.br - -.br -GPIO reads are made from spiBitFirst to spiBitLast. - -.br - -.br - -.IP "\fBspiBits\fP" 0 -The number of bits to transfer in a raw SPI transaction. - -.br - -.br - -.IP "\fBspiChan\fP" 0 -A SPI channel, 0-2. - -.br - -.br - -.IP "\fBspiFlags\fP" 0 -See \fBspiOpen\fP and \fBbbSPIOpen\fP. - -.br - -.br - -.IP "\fBspiSS\fP" 0 -The SPI slave select GPIO in a raw SPI transaction. - -.br - -.br - -.IP "\fBspiTxBits\fP" 0 -The number of bits to transfer dring a raw SPI transaction - -.br - -.br - -.IP "\fBsteady\fP: 0-300000" 0 - -.br - -.br -The number of microseconds level changes must be stable for -before reporting the level changed (\fBgpioGlitchFilter\fP) or triggering -the active part of a noise filter (\fBgpioNoiseFilter\fP). - -.br - -.br - -.IP "\fBstop_bits\fP: 2-8" 0 -The number of (half) stop bits to be used when adding serial data -to a waveform. - -.br - -.br - -.EX -PI_MIN_WAVE_HALFSTOPBITS 2 -.br -PI_MAX_WAVE_HALFSTOPBITS 8 -.br - -.EE - -.br - -.br - -.IP "\fB*str\fP" 0 -An array of characters. - -.br - -.br - -.IP "\fBtimeout\fP" 0 -A GPIO level change timeout in milliseconds. - -.br - -.br -\fBgpioSetWatchdog\fP - -.EX -PI_MIN_WDOG_TIMEOUT 0 -.br -PI_MAX_WDOG_TIMEOUT 60000 -.br - -.EE - -.br - -.br -\fBgpioSetISRFunc\fP and \fBgpioSetISRFuncEx\fP - -.EX -<=0 cancel timeout -.br ->0 timeout after specified milliseconds -.br - -.EE - -.br - -.br - -.IP "\fBtimer\fP" 0 - -.EX -PI_MIN_TIMER 0 -.br -PI_MAX_TIMER 9 -.br - -.EE - -.br - -.br - -.IP "\fBtimetype\fP" 0 - -.EX -PI_TIME_RELATIVE 0 -.br -PI_TIME_ABSOLUTE 1 -.br - -.EE - -.br - -.br - -.IP "\fB*txBuf\fP" 0 - -.br - -.br -An array of bytes to transmit. - -.br - -.br - -.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 - -.br - -.br -A 32-bit unsigned value. - -.br - -.br - -.IP "\fBuint64_t\fP: 0-(2^64)-1" 0 - -.br - -.br -A 64-bit unsigned value. - -.br - -.br - -.IP "\fBunsigned\fP" 0 - -.br - -.br -A whole number >= 0. - -.br - -.br - -.IP "\fBupdateMask\fP" 0 - -.br - -.br -A 64 bit mask indicating which GPIO may be written to by the user. - -.br - -.br -If GPIO#n may be written then bit (1< 4 -.br -#define PI_BAD_CHANNEL -27 // DMA channel not 0-15 -.br -#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15 -.br -#define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000 -.br -#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command -.br -#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15 -.br -#define PI_NOT_INITIALISED -31 // function called before gpioInitialise -.br -#define PI_INITIALISED -32 // function called after gpioInitialise -.br -#define PI_BAD_WAVE_MODE -33 // waveform mode not 0-3 -.br -#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call -.br -#define PI_BAD_WAVE_BAUD -35 // baud rate not 50-250K(RX)/50-1M(TX) -.br -#define PI_TOO_MANY_PULSES -36 // waveform has too many pulses -.br -#define PI_TOO_MANY_CHARS -37 // waveform has too many chars -.br -#define PI_NOT_SERIAL_GPIO -38 // no bit bang serial read on GPIO -.br -#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter -.br -#define PI_BAD_SERIAL_BUF -40 // bad (null) serial buf parameter -.br -#define PI_NOT_PERMITTED -41 // GPIO operation not permitted -.br -#define PI_SOME_PERMITTED -42 // one or more GPIO not permitted -.br -#define PI_BAD_WVSC_COMMND -43 // bad WVSC subcommand -.br -#define PI_BAD_WVSM_COMMND -44 // bad WVSM subcommand -.br -#define PI_BAD_WVSP_COMMND -45 // bad WVSP subcommand -.br -#define PI_BAD_PULSELEN -46 // trigger pulse length not 1-100 -.br -#define PI_BAD_SCRIPT -47 // invalid script -.br -#define PI_BAD_SCRIPT_ID -48 // unknown script id -.br -#define PI_BAD_SER_OFFSET -49 // add serial data offset > 30 minutes -.br -#define PI_GPIO_IN_USE -50 // GPIO already in use -.br -#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time -.br -#define PI_BAD_PARAM_NUM -52 // script parameter id not 0-9 -.br -#define PI_DUP_TAG -53 // script has duplicate tag -.br -#define PI_TOO_MANY_TAGS -54 // script has too many tags -.br -#define PI_BAD_SCRIPT_CMD -55 // illegal script command -.br -#define PI_BAD_VAR_NUM -56 // script variable id not 0-149 -.br -#define PI_NO_SCRIPT_ROOM -57 // no more room for scripts -.br -#define PI_NO_MEMORY -58 // can't allocate temporary memory -.br -#define PI_SOCK_READ_FAILED -59 // socket read failed -.br -#define PI_SOCK_WRIT_FAILED -60 // socket write failed -.br -#define PI_TOO_MANY_PARAM -61 // too many script parameters (> 10) -.br -#define PI_NOT_HALTED -62 // DEPRECATED -.br -#define PI_SCRIPT_NOT_READY -62 // script initialising -.br -#define PI_BAD_TAG -63 // script has unresolved tag -.br -#define PI_BAD_MICS_DELAY -64 // bad MICS delay (too large) -.br -#define PI_BAD_MILS_DELAY -65 // bad MILS delay (too large) -.br -#define PI_BAD_WAVE_ID -66 // non existent wave id -.br -#define PI_TOO_MANY_CBS -67 // No more CBs for waveform -.br -#define PI_TOO_MANY_OOL -68 // No more OOL for waveform -.br -#define PI_EMPTY_WAVEFORM -69 // attempt to create an empty waveform -.br -#define PI_NO_WAVEFORM_ID -70 // no more waveforms -.br -#define PI_I2C_OPEN_FAILED -71 // can't open I2C device -.br -#define PI_SER_OPEN_FAILED -72 // can't open serial device -.br -#define PI_SPI_OPEN_FAILED -73 // can't open SPI device -.br -#define PI_BAD_I2C_BUS -74 // bad I2C bus -.br -#define PI_BAD_I2C_ADDR -75 // bad I2C address -.br -#define PI_BAD_SPI_CHANNEL -76 // bad SPI channel -.br -#define PI_BAD_FLAGS -77 // bad i2c/spi/ser open flags -.br -#define PI_BAD_SPI_SPEED -78 // bad SPI speed -.br -#define PI_BAD_SER_DEVICE -79 // bad serial device name -.br -#define PI_BAD_SER_SPEED -80 // bad serial baud rate -.br -#define PI_BAD_PARAM -81 // bad i2c/spi/ser parameter -.br -#define PI_I2C_WRITE_FAILED -82 // i2c write failed -.br -#define PI_I2C_READ_FAILED -83 // i2c read failed -.br -#define PI_BAD_SPI_COUNT -84 // bad SPI count -.br -#define PI_SER_WRITE_FAILED -85 // ser write failed -.br -#define PI_SER_READ_FAILED -86 // ser read failed -.br -#define PI_SER_READ_NO_DATA -87 // ser read no data available -.br -#define PI_UNKNOWN_COMMAND -88 // unknown command -.br -#define PI_SPI_XFER_FAILED -89 // spi xfer/read/write failed -.br -#define PI_BAD_POINTER -90 // bad (NULL) pointer -.br -#define PI_NO_AUX_SPI -91 // no auxiliary SPI on Pi A or B -.br -#define PI_NOT_PWM_GPIO -92 // GPIO is not in use for PWM -.br -#define PI_NOT_SERVO_GPIO -93 // GPIO is not in use for servo pulses -.br -#define PI_NOT_HCLK_GPIO -94 // GPIO has no hardware clock -.br -#define PI_NOT_HPWM_GPIO -95 // GPIO has no hardware PWM -.br -#define PI_BAD_HPWM_FREQ -96 // invalid hardware PWM frequency -.br -#define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M -.br -#define PI_BAD_HCLK_FREQ -98 // invalid hardware clock frequency -.br -#define PI_BAD_HCLK_PASS -99 // need password to use hardware clock 1 -.br -#define PI_HPWM_ILLEGAL -100 // illegal, PWM in use for main clock -.br -#define PI_BAD_DATABITS -101 // serial data bits not 1-32 -.br -#define PI_BAD_STOPBITS -102 // serial (half) stop bits not 2-8 -.br -#define PI_MSG_TOOBIG -103 // socket/pipe message too big -.br -#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode -.br -#define PI_TOO_MANY_SEGS -105 // too many I2C transaction segments -.br -#define PI_BAD_I2C_SEG -106 // an I2C transaction segment failed -.br -#define PI_BAD_SMBUS_CMD -107 // SMBus command not supported by driver -.br -#define PI_NOT_I2C_GPIO -108 // no bit bang I2C in progress on GPIO -.br -#define PI_BAD_I2C_WLEN -109 // bad I2C write length -.br -#define PI_BAD_I2C_RLEN -110 // bad I2C read length -.br -#define PI_BAD_I2C_CMD -111 // bad I2C command -.br -#define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k -.br -#define PI_CHAIN_LOOP_CNT -113 // bad chain loop count -.br -#define PI_BAD_CHAIN_LOOP -114 // empty chain loop -.br -#define PI_CHAIN_COUNTER -115 // too many chain counters -.br -#define PI_BAD_CHAIN_CMD -116 // bad chain command -.br -#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros -.br -#define PI_CHAIN_NESTING -118 // chain counters nested too deeply -.br -#define PI_CHAIN_TOO_BIG -119 // chain is too long -.br -#define PI_DEPRECATED -120 // deprecated function removed -.br -#define PI_BAD_SER_INVERT -121 // bit bang serial invert not 0 or 1 -.br -#define PI_BAD_EDGE -122 // bad ISR edge value, not 0-2 -.br -#define PI_BAD_ISR_INIT -123 // bad ISR initialisation -.br -#define PI_BAD_FOREVER -124 // loop forever must be last command -.br -#define PI_BAD_FILTER -125 // bad filter parameter -.br -#define PI_BAD_PAD -126 // bad pad number -.br -#define PI_BAD_STRENGTH -127 // bad pad drive strength -.br -#define PI_FIL_OPEN_FAILED -128 // file open failed -.br -#define PI_BAD_FILE_MODE -129 // bad file mode -.br -#define PI_BAD_FILE_FLAG -130 // bad file flag -.br -#define PI_BAD_FILE_READ -131 // bad file read -.br -#define PI_BAD_FILE_WRITE -132 // bad file write -.br -#define PI_FILE_NOT_ROPEN -133 // file not open for read -.br -#define PI_FILE_NOT_WOPEN -134 // file not open for write -.br -#define PI_BAD_FILE_SEEK -135 // bad file seek -.br -#define PI_NO_FILE_MATCH -136 // no files match pattern -.br -#define PI_NO_FILE_ACCESS -137 // no permission to access file -.br -#define PI_FILE_IS_A_DIR -138 // file is a directory -.br -#define PI_BAD_SHELL_STATUS -139 // bad shell return status -.br -#define PI_BAD_SCRIPT_NAME -140 // bad script name -.br -#define PI_BAD_SPI_BAUD -141 // bad SPI baud rate, not 50-500k -.br -#define PI_NOT_SPI_GPIO -142 // no bit bang SPI in progress on GPIO -.br -#define PI_BAD_EVENT_ID -143 // bad event id -.br -#define PI_CMD_INTERRUPTED -144 // Used by Python -.br -#define PI_NOT_ON_BCM2711 -145 // not available on BCM2711 -.br -#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711 -.br - -.br -#define PI_PIGIF_ERR_0 -2000 -.br -#define PI_PIGIF_ERR_99 -2099 -.br - -.br -#define PI_CUSTOM_ERR_0 -3000 -.br -#define PI_CUSTOM_ERR_999 -3999 -.br - -.br - -.EE -.SH Defaults - -.EX - -.br -#define PI_DEFAULT_BUFFER_MILLIS 120 -.br -#define PI_DEFAULT_CLK_MICROS 5 -.br -#define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM -.br -#define PI_DEFAULT_IF_FLAGS 0 -.br -#define PI_DEFAULT_FOREGROUND 0 -.br -#define PI_DEFAULT_DMA_CHANNEL 14 -.br -#define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14 -.br -#define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6 -.br -#define PI_DEFAULT_DMA_PRIMARY_CH_2711 7 -.br -#define PI_DEFAULT_DMA_SECONDARY_CH_2711 6 -.br -#define PI_DEFAULT_DMA_NOT_SET 15 -.br -#define PI_DEFAULT_SOCKET_PORT 8888 -.br -#define PI_DEFAULT_SOCKET_PORT_STR "8888" -.br -#define PI_DEFAULT_SOCKET_ADDR_STR "localhost" -.br -#define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_B1 0x03E7CF93 -.br -#define PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC7CF9C -.br -#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_ZERO 0x0080000FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_PI2B 0x0080480FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_PI3B 0x0000000FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_PI4B 0x0000000FFFFFFCLL -.br -#define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL -.br -#define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO -.br - -.br -#define PI_DEFAULT_CFG_INTERNALS 0 -.br - -.br - -.EE - -.SH SEE ALSO - -pigpiod(1), pig2vcd(1), pigs(1), pigpiod_if(3), pigpiod_if2(3) -.SH AUTHOR - -joan@abyz.me.uk diff --git a/DOC/MAN/pigpiod.1 b/DOC/MAN/pigpiod.1 deleted file mode 100644 index 29f8326..0000000 --- a/DOC/MAN/pigpiod.1 +++ /dev/null @@ -1,273 +0,0 @@ - -." Process this file with -." groff -man -Tascii pigpiod.1 -." -.TH pigpiod 1 2012-2020 Linux "pigpio archive" -.SH NAME -pigpiod - A utility to start the pigpio library as a daemon. - -.SH SYNOPSIS - -sudo pigpiod [OPTION]... -.SH DESCRIPTION - - -.ad l - -.nh -pigpiod is a utility which launches the pigpio library as a daemon. -.br - -.br -Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces. -.br - -.br -The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users. -.br - -.br -pigpiod accepts the following configuration options -.br - -.br -.SH OPTIONS - -.IP "\fB-a value\fP" -DMA memory allocation mode. -0=AUTO, 1=PMAP, 2=MBOX. -Default AUTO -. -.IP "\fB-b value\fP" -GPIO sample buffer size in milliseconds. -100-10000. -Default 120 -. -.IP "\fB-c value\fP" -Library internal settings. -. -Default 0 -. -.IP "\fB-d value\fP" -Primary DMA channel. -0-14. -Default 14 -. -.IP "\fB-e value\fP" -Secondary DMA channel. -0-14. -Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel -. -.IP "\fB-f\fP" -Disable fifo interface. -. -Default enabled -. -.IP "\fB-g\fP" -Run in foreground (do not fork). -. -Default disabled -. -.IP "\fB-k\fP" -Disable local and remote socket interface. -. -Default enabled -. -.IP "\fB-l\fP" -Disable remote socket interface. -. -Default enabled -. -.IP "\fB-m\fP" -Disable alerts (sampling). -. -Default enabled -. -.IP "\fB-n IP address\fP" -Allow IP address to use the socket interface. -Name (e.g. paul) or dotted quad (e.g. 192.168.1.66). -If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect -. -.IP "\fB-p value\fP" -Socket port. -1024-32000. -Default 8888 -. -.IP "\fB-s value\fP" -Sample rate. -1, 2, 4, 5, 8, or 10 microseconds. -Default 5 -. -.IP "\fB-t value\fP" -Clock peripheral. -0=PWM 1=PCM. -Default PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. -. -.IP "\fB-v -V\fP" -Display pigpio version and exit. -. - -. -.IP "\fB-x mask\fP" -GPIO which may be updated. -A 54 bit mask with (1< - - -gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt - - ./prog -.SH DESCRIPTION - - -.ad l - -.nh - -.br - -.br -THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO -USE THE MORE VERSATILE pigpiod_if2 LIBRARY. - -.br - -.br -pigpiod_if is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon. -.br - -.br - -.br -.SS Features -.br - -.br -o hardware timed PWM on any of GPIO 0-31 - -.br - -.br -o hardware timed servo pulses on any of GPIO 0-31 - -.br - -.br -o callbacks when any of GPIO 0-31 change state - -.br - -.br -o callbacks at timed intervals - -.br - -.br -o reading/writing all of the GPIO in a bank as one operation - -.br - -.br -o individually setting GPIO modes, reading and writing - -.br - -.br -o notifications when any of GPIO 0-31 change state - -.br - -.br -o the construction of output waveforms with microsecond timing - -.br - -.br -o rudimentary permission control over GPIO - -.br - -.br -o a simple interface to start and stop new threads - -.br - -.br -o I2C, SPI, and serial link wrappers - -.br - -.br -o creating and running scripts on the pigpio daemon - -.br - -.br -.SS GPIO -.br - -.br -ALL GPIO are identified by their Broadcom number. - -.br - -.br -.SS Notes -.br - -.br -The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. - -.br - -.br -.SS Usage -.br - -.br -Include in your source files. - -.br - -.br -Assuming your source is in prog.c use the following command to build - -.br - -.br - -.EX -gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt -.br - -.EE - -.br - -.br -to run make sure the pigpio daemon is running - -.br - -.br - -.EX -sudo pigpiod -.br - -.br - ./prog # sudo is not required to run programs linked to pigpiod_if -.br - -.EE - -.br - -.br -For examples see x_pigpiod_if.c within the pigpio archive file. - -.br - -.br -.SS Notes -.br - -.br -All the functions which return an int return < 0 on error - -.br - -.br - -.SH OVERVIEW - -.br -.SS ESSENTIAL -.br - -.br -pigpio_start Connects to the pigpio daemon -.br -pigpio_stop Disconnects from the pigpio daemon -.br -.SS BEGINNER -.br - -.br -set_mode Set a GPIO mode -.br -get_mode Get a GPIO mode -.br - -.br -set_pull_up_down Set/clear GPIO pull up/down resistor -.br - -.br -gpio_read Read a GPIO -.br -gpio_write Write a GPIO -.br - -.br -set_PWM_dutycycle Start/stop PWM pulses on a GPIO -.br -get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -.br - -.br -set_servo_pulsewidth Start/stop servo pulses on a GPIO -.br -get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -.br - -.br -callback Create GPIO level change callback -.br -callback_ex Create GPIO level change callback -.br -callback_cancel Cancel a callback -.br -wait_for_edge Wait for GPIO level change -.br -.SS INTERMEDIATE -.br - -.br -gpio_trigger Send a trigger pulse to a GPIO. -.br - -.br -set_watchdog Set a watchdog on a GPIO. -.br - -.br -set_PWM_range Configure PWM range for a GPIO -.br -get_PWM_range Get configured PWM range for a GPIO -.br - -.br -set_PWM_frequency Configure PWM frequency for a GPIO -.br -get_PWM_frequency Get configured PWM frequency for a GPIO -.br - -.br -read_bank_1 Read all GPIO in bank 1 -.br -read_bank_2 Read all GPIO in bank 2 -.br - -.br -clear_bank_1 Clear selected GPIO in bank 1 -.br -clear_bank_2 Clear selected GPIO in bank 2 -.br - -.br -set_bank_1 Set selected GPIO in bank 1 -.br -set_bank_2 Set selected GPIO in bank 2 -.br - -.br -start_thread Start a new thread -.br -stop_thread Stop a previously started thread -.br -.SS ADVANCED -.br - -.br -get_PWM_real_range Get underlying PWM range for a GPIO -.br - -.br -notify_open Request a notification handle -.br -notify_begin Start notifications for selected GPIO -.br -notify_pause Pause notifications -.br -notify_close Close a notification -.br - -.br -bb_serial_read_open Opens a GPIO for bit bang serial reads -.br -bb_serial_read Reads bit bang serial data from a GPIO -.br -bb_serial_read_close Closes a GPIO for bit bang serial reads -.br -bb_serial_invert Invert serial logic (1 invert, 0 normal) -.br - -.br -hardware_clock Start hardware clock on supported GPIO -.br -hardware_PWM Start hardware PWM on supported GPIO -.br - -.br -set_glitch_filter Set a glitch filter on a GPIO -.br -set_noise_filter Set a noise filter on a GPIO -.br -.SS SCRIPTS -.br - -.br -store_script Store a script -.br -run_script Run a stored script -.br -script_status Get script status and parameters -.br -stop_script Stop a running script -.br -delete_script Delete a stored script -.br -.SS WAVES -.br - -.br -wave_clear Deletes all waveforms -.br - -.br -wave_add_new Starts a new waveform -.br -wave_add_generic Adds a series of pulses to the waveform -.br -wave_add_serial Adds serial data to the waveform -.br - -.br -wave_create Creates a waveform from added data -.br -wave_delete Deletes one or more waveforms -.br - -.br -wave_send_once Transmits a waveform once -.br -wave_send_repeat Transmits a waveform repeatedly -.br - -.br -wave_chain Transmits a chain of waveforms -.br - -.br -wave_tx_busy Checks to see if the waveform has ended -.br -wave_tx_stop Aborts the current waveform -.br - -.br -wave_get_micros Length in microseconds of the current waveform -.br -wave_get_high_micros Length of longest waveform so far -.br -wave_get_max_micros Absolute maximum allowed micros -.br - -.br -wave_get_pulses Length in pulses of the current waveform -.br -wave_get_high_pulses Length of longest waveform so far -.br -wave_get_max_pulses Absolute maximum allowed pulses -.br - -.br -wave_get_cbs Length in cbs of the current waveform -.br -wave_get_high_cbs Length of longest waveform so far -.br -wave_get_max_cbs Absolute maximum allowed cbs -.br -.SS I2C -.br - -.br -i2c_open Opens an I2C device -.br -i2c_close Closes an I2C device -.br - -.br -i2c_write_quick smbus write quick -.br -i2c_write_byte smbus write byte -.br -i2c_read_byte smbus read byte -.br -i2c_write_byte_data smbus write byte data -.br -i2c_write_word_data smbus write word data -.br -i2c_read_byte_data smbus read byte data -.br -i2c_read_word_data smbus read word data -.br -i2c_process_call smbus process call -.br -i2c_write_block_data smbus write block data -.br -i2c_read_block_data smbus read block data -.br -i2c_block_process_call smbus block process call -.br - -.br -i2c_write_i2c_block_data smbus write I2C block data -.br -i2c_read_i2c_block_data smbus read I2C block data -.br - -.br -i2c_read_device Reads the raw I2C device -.br -i2c_write_device Writes the raw I2C device -.br - -.br -i2c_zip Performs multiple I2C transactions -.br - -.br -bb_i2c_open Opens GPIO for bit banging I2C -.br -bb_i2c_close Closes GPIO for bit banging I2C -.br -bb_i2c_zip Performs multiple bit banged I2C transactions -.br -.SS SPI -.br - -.br -spi_open Opens a SPI device -.br -spi_close Closes a SPI device -.br - -.br -spi_read Reads bytes from a SPI device -.br -spi_write Writes bytes to a SPI device -.br -spi_xfer Transfers bytes with a SPI device -.br -.SS SERIAL -.br - -.br -serial_open Opens a serial device -.br -serial_close Closes a serial device -.br - -.br -serial_write_byte Writes a byte to a serial device -.br -serial_read_byte Reads a byte from a serial device -.br -serial_write Writes bytes to a serial device -.br -serial_read Reads bytes from a serial device -.br - -.br -serial_data_available Returns number of bytes ready to be read -.br -.SS CUSTOM -.br - -.br -custom_1 User custom function 1 -.br -custom_2 User custom function 2 -.br -.SS UTILITIES -.br - -.br -get_current_tick Get current tick (microseconds) -.br - -.br -get_hardware_revision Get hardware revision -.br -get_pigpio_version Get the pigpio version -.br -pigpiod_if_version Get the pigpiod_if version -.br - -.br -pigpio_error Get a text description of an error code. -.br - -.br -time_sleep Sleeps for a float number of seconds -.br -time_time Float number of seconds since the epoch -.br -.SH FUNCTIONS - -.IP "\fBdouble time_time(void)\fP" -.IP "" 4 -Return the current time in seconds since the Epoch. - -.IP "\fBvoid time_sleep(double seconds)\fP" -.IP "" 4 -Delay execution for a given number of seconds. - -.br - -.br - -.EX -seconds: the number of seconds to delay. -.br - -.EE - -.IP "\fBchar *pigpio_error(int errnum)\fP" -.IP "" 4 -Return a text description for an error code. - -.br - -.br - -.EX -errnum: the error code. -.br - -.EE - -.IP "\fBunsigned pigpiod_if_version(void)\fP" -.IP "" 4 -Return the pigpiod_if version. - -.IP "\fBpthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)\fP" -.IP "" 4 -Starts a new thread of execution with thread_func as the main routine. - -.br - -.br - -.EX -thread_func: the main function for the new thread. -.br - userdata: a pointer to an arbitrary argument. -.br - -.EE - -.br - -.br -Returns a pointer to pthread_t if OK, otherwise NULL. - -.br - -.br -The function is passed the single argument userdata. - -.br - -.br -The thread can be cancelled by passing the pointer to pthread_t to -\fBstop_thread\fP. - -.IP "\fBvoid stop_thread(pthread_t *pth)\fP" -.IP "" 4 -Cancels the thread pointed at by pth. - -.br - -.br - -.EX -pth: the thread to be stopped. -.br - -.EE - -.br - -.br -No value is returned. - -.br - -.br -The thread to be stopped should have been started with \fBstart_thread\fP. - -.IP "\fBint pigpio_start(char *addrStr, char *portStr)\fP" -.IP "" 4 -Connect to the pigpio daemon. Reserving command and -notification streams. - -.br - -.br - -.EX -addrStr: specifies the host or IP address of the Pi running the -.br - pigpio daemon. It may be NULL in which case localhost -.br - is used unless overridden by the PIGPIO_ADDR environment -.br - variable. -.br - -.br -portStr: specifies the port address used by the Pi running the -.br - pigpio daemon. It may be NULL in which case "8888" -.br - is used unless overridden by the PIGPIO_PORT environment -.br - variable. -.br - -.EE - -.IP "\fBvoid pigpio_stop(void)\fP" -.IP "" 4 -Terminates the connection to the pigpio daemon and releases -resources used by the library. - -.IP "\fBint set_mode(unsigned gpio, unsigned mode)\fP" -.IP "" 4 -Set the GPIO mode. - -.br - -.br - -.EX -gpio: 0-53. -.br -mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, -.br - PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. - -.IP "\fBint get_mode(unsigned gpio)\fP" -.IP "" 4 -Get the GPIO mode. - -.br - -.br - -.EX -gpio: 0-53. -.br - -.EE - -.br - -.br -Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. - -.IP "\fBint set_pull_up_down(unsigned gpio, unsigned pud)\fP" -.IP "" 4 -Set or clear the GPIO pull-up/down resistor. - -.br - -.br - -.EX -gpio: 0-53. -.br - pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. - -.IP "\fBint gpio_read(unsigned gpio)\fP" -.IP "" 4 -Read the GPIO level. - -.br - -.br - -.EX -gpio:0-53. -.br - -.EE - -.br - -.br -Returns the GPIO level if OK, otherwise PI_BAD_GPIO. - -.IP "\fBint gpio_write(unsigned gpio, unsigned level)\fP" -.IP "" 4 -Write the GPIO level. - -.br - -.br - -.EX - gpio: 0-53. -.br -level: 0, 1. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. - -.br - -.br -Notes - -.br - -.br -If PWM or servo pulses are active on the GPIO they are switched off. - -.IP "\fBint set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)\fP" -.IP "" 4 -Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br -dutycycle: 0-range (range defaults to 255). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes - -.br - -.br -The \fBset_PWM_range\fP function may be used to change the -default range of 255. - -.IP "\fBint get_PWM_dutycycle(unsigned user_gpio)\fP" -.IP "" 4 -Return the PWM dutycycle in use on a GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. - -.br - -.br -For normal PWM the dutycycle will be out of the defined range -for the GPIO (see \fBget_PWM_range\fP). - -.br - -.br -If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). - -.IP "\fBint set_PWM_range(unsigned user_gpio, unsigned range)\fP" -.IP "" 4 -Set the range of PWM values to be used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - range: 25-40000. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. - -.br - -.br -Notes - -.br - -.br -If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. - -.br - -.br -The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is - -.br - -.br - -.EX - 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), -.br - 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12), -.br -2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18) -.br - -.EE - -.br - -.br -The real value set by set_PWM_range is (dutycycle * real range) / range. - -.IP "\fBint get_PWM_range(unsigned user_gpio)\fP" -.IP "" 4 -Get the range of PWM values being used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.br - -.br -If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). - -.IP "\fBint get_PWM_real_range(unsigned user_gpio)\fP" -.IP "" 4 -Get the real underlying range of PWM values being used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.br - -.br -If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. - -.br - -.br - -.IP "\fBint set_PWM_frequency(unsigned user_gpio, unsigned frequency)\fP" -.IP "" 4 -Set the frequency (in Hz) of the PWM to be used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br -frequency: >=0 (Hz). -.br - -.EE - -.br - -.br -Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. - -.br - -.br -If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. - -.br - -.br -Each GPIO can be independently set to one of 18 different -PWM frequencies. - -.br - -.br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. - -.br - -.br -The frequencies for each sample rate are: - -.br - -.br - -.EX - Hertz -.br - -.br - 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 -.br - 1250 1000 800 500 400 250 200 100 50 -.br - -.br - 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 -.br - 625 500 400 250 200 125 100 50 25 -.br - -.br - 4: 10000 5000 2500 2000 1250 1000 625 500 400 -.br - 313 250 200 125 100 63 50 25 13 -.br -sample -.br - rate -.br - (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 -.br - 250 200 160 100 80 50 40 20 10 -.br - -.br - 8: 5000 2500 1250 1000 625 500 313 250 200 -.br - 156 125 100 63 50 31 25 13 6 -.br - -.br - 10: 4000 2000 1000 800 500 400 250 200 160 -.br - 125 100 80 50 40 25 20 10 5 -.br - -.EE - -.IP "\fBint get_PWM_frequency(unsigned user_gpio)\fP" -.IP "" 4 -Get the frequency of PWM being used on the GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -For normal PWM the frequency will be that defined for the GPIO by -\fBset_PWM_frequency\fP. - -.br - -.br -If a hardware clock is active on the GPIO the reported frequency -will be that set by \fBhardware_clock\fP. - -.br - -.br -If hardware PWM is active on the GPIO the reported frequency -will be that set by \fBhardware_PWM\fP. - -.br - -.br -Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.IP "\fBint set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)\fP" -.IP "" 4 -Start (500-2500) or stop (0) servo pulses on the GPIO. - -.br - -.br - -.EX - user_gpio: 0-31. -.br -pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. - -.br - -.br -The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. - -.br - -.br -The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. - -.br - -.br -You can DAMAGE a servo if you command it to move beyond its limits. - -.br - -.br -OTHER UPDATE RATES: - -.br - -.br -This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. - -.br - -.br - -.EX -Update Rate (Hz) 50 100 200 400 500 -.br -1E6/Hz 20000 10000 5000 2500 2000 -.br - -.EE - -.br - -.br -Firstly set the desired PWM frequency using \fBset_PWM_frequency\fP. - -.br - -.br -Then set the PWM range using \fBset_PWM_range\fP to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. - -.br - -.br -E.g. If you want to update a servo connected to GPIO 25 at 400Hz - -.br - -.br - -.EX -set_PWM_frequency(25, 400); -.br -set_PWM_range(25, 2500); -.br - -.EE - -.br - -.br -Thereafter use the \fBset_PWM_dutycycle\fP function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse. -.br - -.IP "\fBint get_servo_pulsewidth(unsigned user_gpio)\fP" -.IP "" 4 -Return the servo pulsewidth in use on a GPIO. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. - -.IP "\fBint notify_open(void)\fP" -.IP "" 4 -Get a free notification handle. - -.br - -.br -Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. - -.br - -.br -A notification is a method for being notified of GPIO state -changes via a pipe. - -.br - -.br -Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by \fBcallback\fP -should be used instead. - -.br - -.br -Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. - -.IP "\fBint notify_begin(unsigned handle, uint32_t bits)\fP" -.IP "" 4 -Start notifications on a previously opened handle. - -.br - -.br - -.EX -handle: 0-31 (as returned by \fBnotify_open\fP) -.br - bits: a mask indicating the GPIO to be notified. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -The notification sends state changes for each GPIO whose -corresponding bit in bits is set. - -.br - -.br -Each notification occupies 12 bytes in the fifo as follows: - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint16_t seqno; -.br - uint16_t flags; -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioReport_t; -.br - -.EE - -.br - -.br -seqno: starts at 0 each time the handle is opened and then increments -by one for each report. - -.br - -.br -flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. - -.br - -.br -PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. - -.br - -.br -PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. - -.br - -.br -tick: the number of microseconds since system boot. It wraps around -after 1h12m. - -.br - -.br -level: indicates the level of each GPIO. If bit 1<=0 -.br - numBytes: >=1 -.br - str: an array of chars. -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. - -.br - -.br -NOTES: - -.br - -.br -The serial data is formatted as one start bit, \fBdata_bits\fP data bits, -and \fBstop_bits\fP/2 stop bits. - -.br - -.br -It is legal to add serial data streams with different baud rates to -the same waveform. - -.br - -.br -\fBnumBytes\fP is the number of bytes of data in str. - -.br - -.br -The bytes required for each character depend upon \fBdata_bits\fP. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint wave_create(void)\fP" -.IP "" 4 -This function creates a waveform from the data provided by the prior -calls to the \fBwave_add_*\fP functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - -.br - -.br -The data provided by the \fBwave_add_*\fP functions is consumed by this -function. - -.br - -.br -As many waveforms may be created as there is space available. The -wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. - -.br - -.br -Normal usage would be - -.br - -.br -Step 1. \fBwave_clear\fP to clear all waveforms and added data. - -.br - -.br -Step 2. \fBwave_add_*\fP calls to supply the waveform data. - -.br - -.br -Step 3. \fBwave_create\fP to create the waveform and get a unique id - -.br - -.br -Repeat steps 2 and 3 as needed. - -.br - -.br -Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. - -.br - -.br -A waveform comprises one or more pulses. Each pulse consists of a -\fBgpioPulse_t\fP structure. - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br -The fields specify - -.br - -.br -1) the GPIO to be switched on at the start of the pulse. -.br -2) the GPIO to be switched off at the start of the pulse. -.br -3) the delay in microseconds before the next pulse. -.br - -.br - -.br -Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). - -.br - -.br -When a waveform is started each pulse is executed in order with the -specified delay between the pulse and the next. - -.br - -.br -Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. - -.IP "\fBint wave_delete(unsigned wave_id)\fP" -.IP "" 4 -This function deletes the waveform with id wave_id. - -.br - -.br - -.EX -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Wave ids are allocated in order, 0, 1, 2, etc. - -.br - -.br -The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. - -.br - -.br -- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. - -.br - -.br -- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_WAVE_ID. - -.IP "\fBint wave_send_once(unsigned wave_id)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The waveform -is sent once. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br - -.EX -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_send_repeat(unsigned wave_id)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by \fBwave_tx_stop\fP). - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br - -.EX -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_chain(char *buf, unsigned bufSize)\fP" -.IP "" 4 -This function transmits a chain of waveforms. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br -The waves to be transmitted are specified by the contents of buf -which contains an ordered list of \fBwave_id\fPs and optional command -codes and related data. - -.br - -.br - -.EX - buf: pointer to the wave_ids and optional command codes -.br -bufSize: the number of bytes in buf -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. - -.br - -.br -Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. - -.br - -.br -A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. - -.br - -.br -Delays between waves may be added with the delay command. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -Loop Start 255 0 Identify start of a wave block -.br -Loop Repeat 255 1 x y loop x + y*256 times -.br -Delay 255 2 x y delay x + y*256 microseconds -.br -Loop Forever 255 3 loop forever -.br - -.br - -.br -If present Loop Forever must be the last entry in the chain. - -.br - -.br -The code is currently dimensioned to support a chain with roughly -600 entries and 20 loop counters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -#define WAVES 5 -.br -#define GPIO 4 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, wid[WAVES]; -.br - -.br - if (pigpio_start(0, 0)<0) return -1; -.br - -.br - set_mode(GPIO, PI_OUTPUT); -.br - -.br - for (i=0; i=0, as returned by \fBstore_script\fP. -.br - numPar: 0-10, the number of parameters. -.br - param: an array of parameters. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint script_status(unsigned script_id, uint32_t *param)\fP" -.IP "" 4 -This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBstore_script\fP. -.br - param: an array to hold the returned 10 parameters. -.br - -.EE - -.br - -.br -The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. - -.br - -.br -The run status may be - -.br - -.br - -.EX -PI_SCRIPT_INITING -.br -PI_SCRIPT_HALTED -.br -PI_SCRIPT_RUNNING -.br -PI_SCRIPT_WAITING -.br -PI_SCRIPT_FAILED -.br - -.EE - -.br - -.br -The current value of script parameters 0 to 9 are returned in param. - -.IP "\fBint stop_script(unsigned script_id)\fP" -.IP "" 4 -This function stops a running script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBstore_script\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint delete_script(unsigned script_id)\fP" -.IP "" 4 -This function deletes a stored script. - -.br - -.br - -.EX -script_id: >=0, as returned by \fBstore_script\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)\fP" -.IP "" 4 -This function opens a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - baud: 50-250000 -.br -data_bits: 1-32 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. - -.br - -.br -The serial data is returned in a cyclic buffer and is read using -bb_serial_read. - -.br - -.br -It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. - -.IP "\fBint bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)\fP" -.IP "" 4 -This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. - -.br - -.br - -.EX -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - buf: an array to receive the read bytes. -.br - bufSize: >=0 -.br - -.EE - -.br - -.br -Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. - -.br - -.br -The bytes returned for each character depend upon the number of -data bits \fBdata_bits\fP specified in the \fBbb_serial_read_open\fP command. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint bb_serial_read_close(unsigned user_gpio)\fP" -.IP "" 4 -This function closes a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. - -.IP "\fBint bb_serial_invert(unsigned user_gpio, unsigned invert)\fP" -.IP "" 4 -This function inverts serial logic for big bang serial reads. - -.br - -.br - -.EX -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - invert: 0-1, 1 invert, 0 normal. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. - -.IP "\fBint i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)\fP" -.IP "" 4 -This returns a handle for the device at address i2c_addr on bus i2c_bus. - -.br - -.br - -.EX - i2c_bus: >=0. -.br - i2c_addr: 0-0x7F. -.br -i2c_flags: 0. -.br - -.EE - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.br - -.br -Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - SDA SCL -.br -I2C 0 0 1 -.br -I2C 1 2 3 -.br - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. - -.br - -.br -For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. - -.br - -.br - -.EX -S (1 bit) : Start bit -.br -P (1 bit) : Stop bit -.br -Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. -.br -A, NA (1 bit) : Accept and not accept bit. -.br -.br -.br -Addr (7 bits): I2C 7 bit address. -.br -Comm (8 bits): Command byte, a data byte which often selects a register. -.br -Data (8 bits): A data byte. -.br -Count (8 bits): A data byte containing the length of a block operation. -.br - -.br -[..]: Data sent by the device. -.br - -.EE - -.IP "\fBint i2c_close(unsigned handle)\fP" -.IP "" 4 -This closes the I2C device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint i2c_write_quick(unsigned handle, unsigned bit)\fP" -.IP "" 4 -This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - bit: 0-1, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Quick command. SMBus 2.0 5.5.1 - -.EX -S Addr Rd/Wr [A] P -.br - -.EE - -.IP "\fBint i2c_write_byte(unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This sends a single byte to the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - bVal: 0-0xFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Send byte. SMBus 2.0 5.5.2 - -.EX -S Addr Wr [A] Data [A] P -.br - -.EE - -.IP "\fBint i2c_read_byte(unsigned handle)\fP" -.IP "" 4 -This reads a single byte from the device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. - -.br - -.br -Receive byte. SMBus 2.0 5.5.3 - -.EX -S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)\fP" -.IP "" 4 -This writes a single byte to the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - bVal: 0-0xFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write byte. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] Comm [A] Data [A] P -.br - -.EE - -.IP "\fBint i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" -.IP "" 4 -This writes a single 16 bit word to the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - wVal: 0-0xFFFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write word. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P -.br - -.EE - -.IP "\fBint i2c_read_byte_data(unsigned handle, unsigned i2c_reg)\fP" -.IP "" 4 -This reads a single byte from the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read byte. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2c_read_word_data(unsigned handle, unsigned i2c_reg)\fP" -.IP "" 4 -This reads a single 16 bit word from the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read word. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" -.IP "" 4 -This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write/read. -.br - wVal: 0-0xFFFF, the value to write. -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Process call. SMBus 2.0 5.5.6 - -.EX -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] -.br - S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes up to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - buf: an array with the data to send. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Block write. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P -.br - -.EE - -.IP "\fBint i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)\fP" -.IP "" 4 -This reads a block of up to 32 bytes from the specified register of -the device associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - buf: an array to receive the read data. -.br - -.EE - -.br - -.br -The amount of returned data is set by the device. - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Block read. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] Comm [A] -.br - S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P -.br - -.EE - -.IP "\fBint i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write/read. -.br - buf: an array with the data to send and to receive the read data. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. - -.br - -.br -Block write-block read. SMBus 2.0 5.5.8 - -.EX -S Addr Wr [A] Comm [A] Count [A] Data [A] ... -.br - S Addr Rd [A] [Count] A [Data] ... A P -.br - -.EE - -.IP "\fBint i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - buf: an array to receive the read data. -.br - count: 1-32, the number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] Comm [A] -.br - S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P -.br - -.EE - -.IP "\fBint i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes 1 to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - buf: the data to write. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P -.br - -.EE - -.IP "\fBint i2c_read_device(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the raw device into buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - buf: an array to receive the read data bytes. -.br - count: >0, the number of bytes to read. -.br - -.EE - -.br - -.br -Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. - -.IP "\fBint i2c_write_device(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This writes count bytes from buf to the raw device. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - buf: an array containing the data bytes to write. -.br - count: >0, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.IP "\fBint i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -On 2 Switch combined flag on -.br -Off 3 Switch combined flag off -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53, write 0x32, read 6 bytes -.br -Set address 0x1E, write 0x03, read 6 bytes -.br -Set address 0x68, write 0x1B, read 8 bytes -.br -End -.br - -.br -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -.br -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -.br -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -.br -0x00 -.br - -.EE - -.br - -.br - -.IP "\fBint bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)\fP" -.IP "" 4 -This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. - -.br - -.br -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -.br - -.br -o baud rates as low as 50 -.br -o repeated starts -.br -o clock stretching -.br -o I2C on any pair of spare GPIO - -.br - -.br - -.EX - SDA: 0-31 -.br - SCL: 0-31 -.br -baud: 50-500000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -NOTE: - -.br - -.br -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -.IP "\fBint bb_i2c_close(unsigned SDA)\fP" -.IP "" 4 -This function stops bit banging I2C on a pair of GPIO previously -opened with \fBbb_i2c_open\fP. - -.br - -.br - -.EX -SDA: 0-31, the SDA GPIO used in a prior call to \fBbb_i2c_open\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - -.IP "\fBint bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX - SDA: 0-31 (as used in a prior call to \fBbb_i2c_open\fP) -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -Start 2 Start condition -.br -Stop 3 Stop condition -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -.br - -.br -No flags are currently defined. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53 -.br -start, write 0x32, (re)start, read 6 bytes, stop -.br -Set address 0x1E -.br -start, write 0x03, (re)start, read 6 bytes, stop -.br -Set address 0x68 -.br -start, write 0x1B, (re)start, read 8 bytes, stop -.br -End -.br - -.br -0x04 0x53 -.br -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x1E -.br -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x68 -.br -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 -.br - -.br -0x00 -.br - -.EE - -.IP "\fBint spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)\fP" -.IP "" 4 -This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. - -.br - -.br -The Pi has two SPI peripherals: main and auxiliary. - -.br - -.br -The main SPI has two chip selects (channels), the auxiliary has -three. - -.br - -.br -The auxiliary SPI is available on all models but the A and B. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - MISO MOSI SCLK CE0 CE1 CE2 -.br -Main SPI 9 10 11 8 7 - -.br -Aux SPI 19 20 21 18 17 16 -.br - -.br - -.br - -.EX -spi_channel: 0-1 (0-2 for the auxiliary SPI). -.br - baud: 32K-125M (values above 30M are unlikely to work). -.br - spi_flags: see below. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. - -.br - -.br -spi_flags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -.br - -.EE - -.br - -.br -mm defines the SPI mode. - -.br - -.br -Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. - -.br - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -px is 0 if CEx is active low (default) and 1 for active high. - -.br - -.br -ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. - -.br - -.br -A is 0 for the main SPI, 1 for the auxiliary SPI. - -.br - -.br -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main -SPI only. - -.br - -.br -nnnn defines the number of bytes (0-15) to write before switching -the MOSI line to MISO to read data. This field is ignored -if W is not set. Main SPI only. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. Auxiliary SPI -only. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. Auxiliary SPI -only. - -.br - -.br -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI only. - -.br - -.br -The \fBspi_read\fP, \fBspi_write\fP, and \fBspi_xfer\fP functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. - -.br - -.br -For bits 1-8 there will be one byte per word. -.br -For bits 9-16 there will be two bytes per word. -.br -For bits 17-32 there will be four bytes per word. - -.br - -.br -Multi-byte transfers are made in least significant byte first order. - -.br - -.br -E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. - -.br - -.br -E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed -by 0x1A. - -.br - -.br -The other bits in flags should be set to zero. - -.IP "\fBint spi_close(unsigned handle)\fP" -.IP "" 4 -This functions closes the SPI device identified by the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint spi_read(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads count bytes of data from the SPI -device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - buf: an array to receive the read data bytes. -.br - count: the number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spi_write(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes of data from buf to the SPI -device associated with the handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - buf: the data bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" -.IP "" 4 -This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - txBuf: the data bytes to write. -.br - rxBuf: the received data bytes. -.br - count: the number of bytes to transfer. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)\fP" -.IP "" 4 -This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. - -.br - -.br - -.EX - ser_tty: the serial device to open. -.br - baud: the baud rate in bits per second, see below. -.br -ser_flags: 0. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. - -.br - -.br -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.IP "\fBint serial_close(unsigned handle)\fP" -.IP "" 4 -This function closes the serial device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint serial_write_byte(unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This function writes bVal to the serial port associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serial_read_byte(unsigned handle)\fP" -.IP "" 4 -This function reads a byte from the serial port associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. - -.br - -.br -If no data is ready PI_SER_READ_NO_DATA is returned. - -.IP "\fBint serial_write(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the serial port -associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - buf: the array of bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serial_read(unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - buf: an array to receive the read data. -.br - count: the maximum number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. - -.br - -.br -If no data is ready zero is returned. - -.IP "\fBint serial_data_available(unsigned handle)\fP" -.IP "" 4 -Returns the number of bytes available to be read from the -device associated with handle. - -.br - -.br - -.EX -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. - -.IP "\fBint custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It returns a single integer value. - -.br - -.br - -.EX -arg1: >=0 -.br -arg2: >=0 -.br -argx: extra (byte) arguments -.br -argc: number of extra arguments -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.IP "\fBint custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It differs from custom_1 in that it returns an array of bytes -rather than just an integer. - -.br - -.br -The return value is an integer indicating the number of returned bytes. - -.EX - arg1: >=0 -.br - argc: extra (byte) arguments -.br - count: number of extra arguments -.br -retBuf: buffer for returned data -.br -retMax: maximum number of bytes to return -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.br - -.br -Note, the number of returned bytes will be retMax or less. - -.IP "\fBint callback(unsigned user_gpio, unsigned edge, CBFunc_t f)\fP" -.IP "" 4 -This function initialises a new callback. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - f: the callback function. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -edge 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.EE - -.IP "\fBint callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP" -.IP "" 4 -This function initialises a new callback. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - f: the callback function. -.br - userdata: a pointer to arbitrary user data. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the GPIO, edge, tick, and user, whenever -the GPIO has the identified edge. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -edge 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.br -userdata pointer Pointer to an arbitrary object -.br - -.EE - -.IP "\fBint callback_cancel(unsigned callback_id)\fP" -.IP "" 4 -This function cancels a callback identified by its id. - -.br - -.br - -.EX -callback_id: >=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise pigif_callback_not_found. - -.IP "\fBint wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)\fP" -.IP "" 4 -This function waits for edge on the GPIO for up to timeout -seconds. - -.br - -.br - -.EX -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - timeout: >=0. -.br - -.EE - -.br - -.br -The function returns 1 if the edge occurred, otherwise 0. - -.br - -.br -The function returns when the edge occurs or after the timeout. -.SH PARAMETERS - -.br - -.br - -.IP "\fBactive\fP: 0-1000000" 0 - -.br - -.br -The number of microseconds level changes are reported for once -a noise filter has been triggered (by \fBsteady\fP microseconds of -a stable level). - -.br - -.br - -.IP "\fB*addrStr\fP" 0 -A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. - -.br - -.br - -.IP "\fBarg1\fP" 0 -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBarg2\fP" 0 -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBargc\fP" 0 -The count of bytes passed to a user customised function. - -.br - -.br - -.IP "\fB*argx\fP" 0 -A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. - -.br - -.br - -.IP "\fBbaud\fP" 0 -The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. - -.br - -.br - -.IP "\fBbit\fP" 0 -A value of 0 or 1. - -.br - -.br - -.IP "\fBbits\fP" 0 -A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. - -.br - -.br -A convenient way to set bit n is to or in (1<=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. This is -passed to \fBcallback_cancel\fP to cancel the callback. - -.br - -.br - -.IP "\fBCBFunc_t\fP" 0 - -.EX -typedef void (*CBFunc_t) -.br - (unsigned user_gpio, unsigned level, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBCBFuncEx_t\fP" 0 - -.EX -typedef void (*CBFuncEx_t) -.br - (unsigned user_gpio, unsigned level, uint32_t tick, void * user); -.br - -.EE - -.br - -.br - -.IP "\fBchar\fP" 0 -A single character, an 8 bit quantity able to store 0-255. - -.br - -.br - -.IP "\fBclkfreq\fP: 4689-250000000 (250M)" 0 -The hardware clock frequency. - -.br - -.br - -.IP "\fBcount\fP" 0 -The number of bytes to be transferred in an I2C, SPI, or Serial -command. - -.br - -.br - -.IP "\fBdata_bits\fP: 1-32" 0 -The number of data bits in each character of serial data. - -.br - -.br - -.EX -#define PI_MIN_WAVE_DATABITS 1 -.br -#define PI_MAX_WAVE_DATABITS 32 -.br - -.EE - -.br - -.br - -.IP "\fBdouble\fP" 0 -A floating point number. - -.br - -.br - -.IP "\fBdutycycle\fP: 0-range" 0 -A number representing the ratio of on time to off time for PWM. - -.br - -.br -The number may vary between 0 and range (default 255) where -0 is off and range is fully on. - -.br - -.br - -.IP "\fBedge\fP" 0 -Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. - -.br - -.br - -.EX -RISING_EDGE 0 -.br -FALLING_EDGE 1 -.br -EITHER_EDGE. 2 -.br - -.EE - -.br - -.br - -.IP "\fBerrnum\fP" 0 -A negative number indicating a function call failed and the nature -of the error. - -.br - -.br - -.IP "\fBf\fP" 0 -A function. - -.br - -.br - -.IP "\fBfrequency\fP: >=0" 0 -The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. - -.br - -.br - -.br - -.br - -.IP "\fBgpio\fP" 0 -A Broadcom numbered GPIO, in the range 0-53. - -.br - -.br -There are 54 General Purpose Input Outputs (GPIO) named gpio0 through -gpio53. - -.br - -.br -They are split into two banks. Bank 1 consists of gpio0 through -gpio31. Bank 2 consists of gpio32 through gpio53. - -.br - -.br -All the GPIO which are safe for the user to read and write are in -bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards -have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. - -.br - -.br -See \fBget_hardware_revision\fP. - -.br - -.br -The user GPIO are marked with an X in the following table. - -.br - -.br - -.EX - 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -.br -Type 1 X X - - X - - X X X X X - - X X -.br -Type 2 - - X X X - - X X X X X - - X X -.br -Type 3 X X X X X X X X X X X X X X -.br - -.br - 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 -.br -Type 1 - X X - - X X X X X - - - - - - -.br -Type 2 - X X - - - X X X X - X X X X X -.br -Type 3 X X X X X X X X X X X X - - - - -.br - -.EE - -.br - -.br - -.IP "\fBgpioPulse_t\fP" 0 - -.EX -typedef struct -.br -{ -.br -uint32_t gpioOn; -.br -uint32_t gpioOff; -.br -uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br - -.IP "\fBgpioThreadFunc_t\fP" 0 - -.EX -typedef void *(gpioThreadFunc_t) (void *); -.br - -.EE - -.br - -.br - -.IP "\fBhandle\fP: >=0" 0 -A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\fP, -\fBserial_open\fP, and \fBspi_open\fP. - -.br - -.br - -.IP "\fBi2c_addr\fP: 0-0x7F" 0 -The address of a device on the I2C bus. - -.br - -.br - -.IP "\fBi2c_bus\fP: >=0" 0 -An I2C bus number. - -.br - -.br - -.IP "\fBi2c_flags\fP: 0" 0 -Flags which modify an I2C open command. None are currently defined. - -.br - -.br - -.IP "\fBi2c_reg\fP: 0-255" 0 -A register of an I2C device. - -.br - -.br - -.IP "\fB*inBuf\fP" 0 -A buffer used to pass data to a function. - -.br - -.br - -.IP "\fBinLen\fP" 0 -The number of bytes of data in a buffer. - -.br - -.br - -.IP "\fBint\fP" 0 -A whole number, negative or positive. - -.br - -.br - -.IP "\fBinvert\fP" 0 -A flag used to set normal or inverted bit bang serial data level logic. - -.br - -.br - -.IP "\fBlevel\fP" 0 -The level of a GPIO. Low or High. - -.br - -.br - -.EX -PI_OFF 0 -.br -PI_ON 1 -.br - -.br -PI_CLEAR 0 -.br -PI_SET 1 -.br - -.br -PI_LOW 0 -.br -PI_HIGH 1 -.br - -.EE - -.br - -.br -There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See \fBset_watchdog\fP. - -.br - -.br - -.EX -PI_TIMEOUT 2 -.br - -.EE - -.br - -.br - -.IP "\fBmode\fP: 0-7" 0 -The operational mode of a GPIO, normally INPUT or OUTPUT. - -.br - -.br - -.EX -PI_INPUT 0 -.br -PI_OUTPUT 1 -.br -PI_ALT0 4 -.br -PI_ALT1 5 -.br -PI_ALT2 6 -.br -PI_ALT3 7 -.br -PI_ALT4 3 -.br -PI_ALT5 2 -.br - -.EE - -.br - -.br - -.IP "\fBnumBytes\fP" 0 -The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. - -.br - -.br - -.IP "\fBnumPar\fP: 0-10" 0 -The number of parameters passed to a script. - -.br - -.br - -.IP "\fBnumPulses\fP" 0 -The number of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBoffset\fP" 0 -The associated data starts this number of microseconds from the start of -the waveform. - -.br - -.br - -.IP "\fB*outBuf\fP" 0 -A buffer used to return data from a function. - -.br - -.br - -.IP "\fBoutLen\fP" 0 -The size in bytes of an output buffer. - -.br - -.br - -.IP "\fB*param\fP" 0 -An array of script parameters. - -.br - -.br - -.IP "\fB*portStr\fP" 0 -A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. - -.br - -.br - -.IP "\fB*pth\fP" 0 -A thread identifier, returned by \fBstart_thread\fP. - -.br - -.br - -.br - -.br - -.IP "\fBpthread_t\fP" 0 -A thread identifier. - -.br - -.br - -.IP "\fBpud\fP: 0-2" 0 -The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. - -.EX -PI_PUD_OFF 0 -.br -PI_PUD_DOWN 1 -.br -PI_PUD_UP 2 -.br - -.EE - -.br - -.br - -.IP "\fBpulseLen\fP" 0 -1-100, the length of a trigger pulse in microseconds. - -.br - -.br - -.IP "\fB*pulses\fP" 0 -An array of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBpulsewidth\fP: 0, 500-2500" 0 - -.EX -PI_SERVO_OFF 0 -.br -PI_MIN_SERVO_PULSEWIDTH 500 -.br -PI_MAX_SERVO_PULSEWIDTH 2500 -.br - -.EE - -.br - -.br - -.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 -The hardware PWM dutycycle. - -.br - -.br - -.EX -#define PI_HW_PWM_RANGE 1000000 -.br - -.EE - -.br - -.br - -.IP "\fBPWMfreq\fP: 1-125000000 (125M)" 0 -The hardware PWM frequency. - -.br - -.br - -.EX -#define PI_HW_PWM_MIN_FREQ 1 -.br -#define PI_HW_PWM_MAX_FREQ 125000000 -.br - -.EE - -.br - -.br - -.IP "\fBrange\fP: 25-40000" 0 -The permissible dutycycle values are 0-range. - -.EX -PI_MIN_DUTYCYCLE_RANGE 25 -.br -PI_MAX_DUTYCYCLE_RANGE 40000 -.br - -.EE - -.br - -.br - -.IP "\fB*retBuf\fP" 0 -A buffer to hold a number of bytes returned to a used customised function, - -.br - -.br - -.IP "\fBretMax\fP" 0 -The maximum number of bytes a user customised function should return. - -.br - -.br - -.br - -.br - -.IP "\fB*rxBuf\fP" 0 -A pointer to a buffer to receive data. - -.br - -.br - -.IP "\fBSCL\fP" 0 -The user GPIO to use for the clock when bit banging I2C. - -.br - -.br - -.IP "\fB*script\fP" 0 -A pointer to the text of a script. - -.br - -.br - -.IP "\fBscript_id\fP" 0 -An id of a stored script as returned by \fBstore_script\fP. - -.br - -.br - -.IP "\fBSDA\fP" 0 -The user GPIO to use for data when bit banging I2C. - -.br - -.br - -.IP "\fBseconds\fP" 0 -The number of seconds. - -.br - -.br - -.IP "\fBser_flags\fP" 0 -Flags which modify a serial open command. None are currently defined. - -.br - -.br - -.IP "\fB*ser_tty\fP" 0 -The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. - -.br - -.br - -.IP "\fBsize_t\fP" 0 -A standard type used to indicate the size of an object in bytes. - -.br - -.br - -.IP "\fBspi_channel\fP" 0 -A SPI channel, 0-2. - -.br - -.br - -.IP "\fBspi_flags\fP" 0 -See \fBspi_open\fP. - -.br - -.br - -.IP "\fBsteady\fP: 0-300000" 0 - -.br - -.br -The number of microseconds level changes must be stable for -before reporting the level changed (\fBset_glitch_filter\fP) or triggering -the active part of a noise filter (\fBset_noise_filter\fP). - -.br - -.br - -.IP "\fBstop_bits\fP: 2-8" 0 -The number of (half) stop bits to be used when adding serial data -to a waveform. - -.br - -.br - -.EX -#define PI_MIN_WAVE_HALFSTOPBITS 2 -.br -#define PI_MAX_WAVE_HALFSTOPBITS 8 -.br - -.EE - -.br - -.br - -.IP "\fB*str\fP" 0 - An array of characters. - -.br - -.br - -.IP "\fBthread_func\fP" 0 -A function of type gpioThreadFunc_t used as the main function of a -thread. - -.br - -.br - -.IP "\fBtimeout\fP" 0 -A GPIO watchdog timeout in milliseconds. - -.EX -PI_MIN_WDOG_TIMEOUT 0 -.br -PI_MAX_WDOG_TIMEOUT 60000 -.br - -.EE - -.br - -.br - -.IP "\fB*txBuf\fP" 0 -An array of bytes to transmit. - -.br - -.br - -.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 -A 32-bit unsigned value. - -.br - -.br - -.IP "\fBunsigned\fP" 0 -A whole number >= 0. - -.br - -.br - -.IP "\fBuser_gpio\fP" 0 -0-31, a Broadcom numbered GPIO. - -.br - -.br -See \fBgpio\fP. - -.br - -.br - -.IP "\fB*userdata\fP" 0 -A pointer to arbitrary user data. This may be used to identify the instance. - -.br - -.br - -.IP "\fBvoid\fP" 0 -Denoting no parameter is required - -.br - -.br - -.IP "\fBwave_add_*\fP" 0 -One of \fBwave_add_new\fP, \fBwave_add_generic\fP, \fBwave_add_serial\fP. - -.br - -.br - -.IP "\fBwave_id\fP" 0 -A number representing a waveform created by \fBwave_create\fP. - -.br - -.br - -.IP "\fBwave_send_*\fP" 0 -One of \fBwave_send_once\fP, \fBwave_send_repeat\fP. - -.br - -.br - -.IP "\fBwVal\fP: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)" 0 -A 16-bit word value. - -.br - -.br -.SH pigpiod_if Error Codes - -.EX - -.br -typedef enum -.br -{ -.br - pigif_bad_send = -2000, -.br - pigif_bad_recv = -2001, -.br - pigif_bad_getaddrinfo = -2002, -.br - pigif_bad_connect = -2003, -.br - pigif_bad_socket = -2004, -.br - pigif_bad_noib = -2005, -.br - pigif_duplicate_callback = -2006, -.br - pigif_bad_malloc = -2007, -.br - pigif_bad_callback = -2008, -.br - pigif_notify_failed = -2009, -.br - pigif_callback_not_found = -2010, -.br -} pigifError_t; -.br - -.br - -.EE - -.SH SEE ALSO - -pigpiod(1), pig2vcd(1), pigs(1), pigpio(3), pigpiod_if2(3) -.SH AUTHOR - -joan@abyz.me.uk diff --git a/DOC/MAN/pigpiod_if2.3 b/DOC/MAN/pigpiod_if2.3 deleted file mode 100644 index f07de8d..0000000 --- a/DOC/MAN/pigpiod_if2.3 +++ /dev/null @@ -1,8057 +0,0 @@ - -." Process this file with -." groff -man -Tascii pigpiod_if2.3 -." -.TH pigpiod_if2 3 2012-2020 Linux "pigpio archive" -.SH NAME -pigpiod_if2 - A C library to interface to the pigpio daemon. - -.SH SYNOPSIS - -#include - - -gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt - - ./prog -.SH DESCRIPTION - - -.ad l - -.nh - -.br - -.br -pigpiod_if2 is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon. -.br - -.br - -.br -.SS Features -.br - -.br -o hardware timed PWM on any of GPIO 0-31 - -.br - -.br -o hardware timed servo pulses on any of GPIO 0-31 - -.br - -.br -o callbacks when any of GPIO 0-31 change state - -.br - -.br -o callbacks at timed intervals - -.br - -.br -o reading/writing all of the GPIO in a bank as one operation - -.br - -.br -o individually setting GPIO modes, reading and writing - -.br - -.br -o notifications when any of GPIO 0-31 change state - -.br - -.br -o the construction of output waveforms with microsecond timing - -.br - -.br -o rudimentary permission control over GPIO - -.br - -.br -o a simple interface to start and stop new threads - -.br - -.br -o I2C, SPI, and serial link wrappers - -.br - -.br -o creating and running scripts on the pigpio daemon - -.br - -.br -.SS GPIO -.br - -.br -ALL GPIO are identified by their Broadcom number. - -.br - -.br -.SS Notes -.br - -.br -The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. - -.br - -.br -.SS Usage -.br - -.br -Include in your source files. - -.br - -.br -Assuming your source is in prog.c use the following command to build - -.br - -.br - -.EX -gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt -.br - -.EE - -.br - -.br -to run make sure the pigpio daemon is running - -.br - -.br - -.EX -sudo pigpiod -.br - -.br - ./prog # sudo is not required to run programs linked to pigpiod_if2 -.br - -.EE - -.br - -.br -For examples see x_pigpiod_if2.c within the pigpio archive file. - -.br - -.br -.SS Notes -.br - -.br -All the functions which return an int return < 0 on error - -.br - -.br - -.SH OVERVIEW - -.br -.SS ESSENTIAL -.br - -.br -pigpio_start Connects to a pigpio daemon -.br -pigpio_stop Disconnects from a pigpio daemon -.br -.SS BASIC -.br - -.br -set_mode Set a GPIO mode -.br -get_mode Get a GPIO mode -.br - -.br -set_pull_up_down Set/clear GPIO pull up/down resistor -.br - -.br -gpio_read Read a GPIO -.br -gpio_write Write a GPIO -.br -.SS PWM (overrides servo commands on same GPIO) -.br - -.br -set_PWM_dutycycle Start/stop PWM pulses on a GPIO -.br -set_PWM_frequency Configure PWM frequency for a GPIO -.br -set_PWM_range Configure PWM range for a GPIO -.br - -.br -get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -.br -get_PWM_frequency Get configured PWM frequency for a GPIO -.br -get_PWM_range Get configured PWM range for a GPIO -.br - -.br -get_PWM_real_range Get underlying PWM range for a GPIO -.br -.SS Servo (overrides PWM commands on same GPIO) -.br - -.br -set_servo_pulsewidth Start/stop servo pulses on a GPIO -.br - -.br -get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -.br -.SS INTERMEDIATE -.br - -.br -gpio_trigger Send a trigger pulse to a GPIO. -.br - -.br -set_watchdog Set a watchdog on a GPIO. -.br - -.br -read_bank_1 Read all GPIO in bank 1 -.br -read_bank_2 Read all GPIO in bank 2 -.br - -.br -clear_bank_1 Clear selected GPIO in bank 1 -.br -clear_bank_2 Clear selected GPIO in bank 2 -.br - -.br -set_bank_1 Set selected GPIO in bank 1 -.br -set_bank_2 Set selected GPIO in bank 2 -.br - -.br -callback Create GPIO level change callback -.br -callback_ex Create GPIO level change callback, extended -.br - -.br -callback_cancel Cancel a callback -.br - -.br -wait_for_edge Wait for GPIO level change -.br - -.br -start_thread Start a new thread -.br -stop_thread Stop a previously started thread -.br -.SS ADVANCED -.br - -.br -notify_open Request a notification handle -.br -notify_begin Start notifications for selected GPIO -.br -notify_pause Pause notifications -.br -notify_close Close a notification -.br - -.br -hardware_clock Start hardware clock on supported GPIO -.br - -.br -hardware_PWM Start hardware PWM on supported GPIO -.br - -.br -set_glitch_filter Set a glitch filter on a GPIO -.br -set_noise_filter Set a noise filter on a GPIO -.br - -.br -set_pad_strength Sets a pads drive strength -.br -get_pad_strength Gets a pads drive strength -.br - -.br -shell_ Executes a shell command -.br -.SS Custom -.br - -.br -custom_1 User custom function 1 -.br -custom_2 User custom function 2 -.br -.SS Events -.br - -.br -event_callback Sets a callback for an event -.br -event_callback_ex Sets a callback for an event, extended -.br - -.br -event_callback_cancel Cancel an event callback -.br - -.br -event_trigger Triggers an event -.br - -.br -wait_for_event Wait for an event -.br -.SS Scripts -.br - -.br -store_script Store a script -.br -run_script Run a stored script -.br -update_script Set a scripts parameters -.br -script_status Get script status and parameters -.br -stop_script Stop a running script -.br -delete_script Delete a stored script -.br -.SS I2C -.br - -.br -i2c_open Opens an I2C device -.br -i2c_close Closes an I2C device -.br - -.br -i2c_write_quick smbus write quick -.br - -.br -i2c_read_byte smbus read byte -.br -i2c_write_byte smbus write byte -.br - -.br -i2c_read_byte_data smbus read byte data -.br -i2c_write_byte_data smbus write byte data -.br - -.br -i2c_read_word_data smbus read word data -.br -i2c_write_word_data smbus write word data -.br - -.br -i2c_read_block_data smbus read block data -.br -i2c_write_block_data smbus write block data -.br - -.br -i2c_read_i2c_block_data smbus read I2C block data -.br -i2c_write_i2c_block_data smbus write I2C block data -.br - -.br -i2c_read_device Reads the raw I2C device -.br -i2c_write_device Writes the raw I2C device -.br - -.br -i2c_process_call smbus process call -.br -i2c_block_process_call smbus block process call -.br - -.br -i2c_zip Performs multiple I2C transactions -.br -.SS I2C BIT BANG -.br - -.br -bb_i2c_open Opens GPIO for bit banging I2C -.br -bb_i2c_close Closes GPIO for bit banging I2C -.br - -.br -bb_i2c_zip Performs bit banged I2C transactions -.br -.SS I2C/SPI SLAVE -.br - -.br -bsc_xfer I2C/SPI as slave transfer -.br -bsc_i2c I2C as slave transfer -.br -.SS SERIAL -.br - -.br -serial_open Opens a serial device -.br -serial_close Closes a serial device -.br - -.br -serial_read_byte Reads a byte from a serial device -.br -serial_write_byte Writes a byte to a serial device -.br - -.br -serial_read Reads bytes from a serial device -.br -serial_write Writes bytes to a serial device -.br - -.br -serial_data_available Returns number of bytes ready to be read -.br -.SS SERIAL BIT BANG (read only) -.br - -.br -bb_serial_read_open Opens a GPIO for bit bang serial reads -.br -bb_serial_read_close Closes a GPIO for bit bang serial reads -.br - -.br -bb_serial_invert Invert serial logic (1 invert, 0 normal) -.br - -.br -bb_serial_read Reads bit bang serial data from a GPIO -.br -.SS SPI -.br - -.br -spi_open Opens a SPI device -.br -spi_close Closes a SPI device -.br - -.br -spi_read Reads bytes from a SPI device -.br -spi_write Writes bytes to a SPI device -.br -spi_xfer Transfers bytes with a SPI device -.br -.SS SPI BIT BANG -.br - -.br -bb_spi_open Opens GPIO for bit banging SPI -.br -bb_spi_close Closes GPIO for bit banging SPI -.br - -.br -bb_spi_xfer Transfers bytes with bit banging SPI -.br -.SS FILES -.br - -.br -file_open Opens a file -.br -file_close Closes a file -.br - -.br -file_read Reads bytes from a file -.br -file_write Writes bytes to a file -.br - -.br -file_seek Seeks to a position within a file -.br - -.br -file_list List files which match a pattern -.br -.SS WAVES -.br - -.br -wave_clear Deletes all waveforms -.br - -.br -wave_add_new Starts a new waveform -.br -wave_add_generic Adds a series of pulses to the waveform -.br -wave_add_serial Adds serial data to the waveform -.br - -.br -wave_create Creates a waveform from added data -.br -wave_create_and_pad Creates a waveform of fixed size from added data -.br -wave_delete Deletes one or more waveforms -.br - -.br -wave_send_once Transmits a waveform once -.br -wave_send_repeat Transmits a waveform repeatedly -.br -wave_send_using_mode Transmits a waveform in the chosen mode -.br - -.br -wave_chain Transmits a chain of waveforms -.br - -.br -wave_tx_at Returns the current transmitting waveform -.br - -.br -wave_tx_busy Checks to see if the waveform has ended -.br - -.br -wave_tx_stop Aborts the current waveform -.br - -.br -wave_get_cbs Length in cbs of the current waveform -.br -wave_get_high_cbs Length of longest waveform so far -.br -wave_get_max_cbs Absolute maximum allowed cbs -.br - -.br -wave_get_micros Length in micros of the current waveform -.br -wave_get_high_micros Length of longest waveform so far -.br -wave_get_max_micros Absolute maximum allowed micros -.br - -.br -wave_get_pulses Length in pulses of the current waveform -.br -wave_get_high_pulses Length of longest waveform so far -.br -wave_get_max_pulses Absolute maximum allowed pulses -.br -.SS UTILITIES -.br - -.br -get_current_tick Get current tick (microseconds) -.br - -.br -get_hardware_revision Get hardware revision -.br -get_pigpio_version Get the pigpio version -.br -pigpiod_if_version Get the pigpiod_if2 version -.br - -.br -pigpio_error Get a text description of an error code. -.br - -.br -time_sleep Sleeps for a float number of seconds -.br -time_time Float number of seconds since the epoch -.br -.SH FUNCTIONS - -.IP "\fBdouble time_time(void)\fP" -.IP "" 4 -Return the current time in seconds since the Epoch. - -.IP "\fBvoid time_sleep(double seconds)\fP" -.IP "" 4 -Delay execution for a given number of seconds. - -.br - -.br - -.EX -seconds: the number of seconds to delay. -.br - -.EE - -.IP "\fBchar *pigpio_error(int errnum)\fP" -.IP "" 4 -Return a text description for an error code. - -.br - -.br - -.EX -errnum: the error code. -.br - -.EE - -.IP "\fBunsigned pigpiod_if_version(void)\fP" -.IP "" 4 -Return the pigpiod_if2 version. - -.IP "\fBpthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)\fP" -.IP "" 4 -Starts a new thread of execution with thread_func as the main routine. - -.br - -.br - -.EX -thread_func: the main function for the new thread. -.br - userdata: a pointer to an arbitrary argument. -.br - -.EE - -.br - -.br -Returns a pointer to pthread_t if OK, otherwise NULL. - -.br - -.br -The function is passed the single argument userdata. - -.br - -.br -The thread can be cancelled by passing the pointer to pthread_t to -\fBstop_thread\fP. - -.IP "\fBvoid stop_thread(pthread_t *pth)\fP" -.IP "" 4 -Cancels the thread pointed at by pth. - -.br - -.br - -.EX -pth: the thread to be stopped. -.br - -.EE - -.br - -.br -No value is returned. - -.br - -.br -The thread to be stopped should have been started with \fBstart_thread\fP. - -.IP "\fBint pigpio_start(char *addrStr, char *portStr)\fP" -.IP "" 4 -Connect to the pigpio daemon. Reserving command and -notification streams. - -.br - -.br - -.EX -addrStr: specifies the host or IP address of the Pi running the -.br - pigpio daemon. It may be NULL in which case localhost -.br - is used unless overridden by the PIGPIO_ADDR environment -.br - variable. -.br - -.br -portStr: specifies the port address used by the Pi running the -.br - pigpio daemon. It may be NULL in which case "8888" -.br - is used unless overridden by the PIGPIO_PORT environment -.br - variable. -.br - -.EE - -.br - -.br -Returns an integer value greater than or equal to zero if OK. - -.br - -.br -This value is passed to the GPIO routines to specify the Pi -to be operated on. - -.IP "\fBvoid pigpio_stop(int pi)\fP" -.IP "" 4 -Terminates the connection to a pigpio daemon and releases -resources used by the library. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint set_mode(int pi, unsigned gpio, unsigned mode)\fP" -.IP "" 4 -Set the GPIO mode. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -gpio: 0-53. -.br -mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, -.br - PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. - -.IP "\fBint get_mode(int pi, unsigned gpio)\fP" -.IP "" 4 -Get the GPIO mode. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -gpio: 0-53. -.br - -.EE - -.br - -.br -Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. - -.IP "\fBint set_pull_up_down(int pi, unsigned gpio, unsigned pud)\fP" -.IP "" 4 -Set or clear the GPIO pull-up/down resistor. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -gpio: 0-53. -.br - pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. - -.IP "\fBint gpio_read(int pi, unsigned gpio)\fP" -.IP "" 4 -Read the GPIO level. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -gpio:0-53. -.br - -.EE - -.br - -.br -Returns the GPIO level if OK, otherwise PI_BAD_GPIO. - -.IP "\fBint gpio_write(int pi, unsigned gpio, unsigned level)\fP" -.IP "" 4 -Write the GPIO level. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - gpio: 0-53. -.br -level: 0, 1. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. - -.br - -.br -Notes - -.br - -.br -If PWM or servo pulses are active on the GPIO they are switched off. - -.IP "\fBint set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)\fP" -.IP "" 4 -Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br -dutycycle: 0-range (range defaults to 255). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes - -.br - -.br -The \fBset_PWM_range\fP function may be used to change the -default range of 255. - -.IP "\fBint get_PWM_dutycycle(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Return the PWM dutycycle in use on a GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. - -.br - -.br -For normal PWM the dutycycle will be out of the defined range -for the GPIO (see \fBget_PWM_range\fP). - -.br - -.br -If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). - -.IP "\fBint set_PWM_range(int pi, unsigned user_gpio, unsigned range)\fP" -.IP "" 4 -Set the range of PWM values to be used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - range: 25-40000. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. - -.br - -.br -Notes - -.br - -.br -If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. - -.br - -.br -The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is - -.br - -.br - -.EX - 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), -.br - 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12), -.br -2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18) -.br - -.EE - -.br - -.br -The real value set by set_PWM_range is (dutycycle * real range) / range. - -.IP "\fBint get_PWM_range(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Get the range of PWM values being used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.br - -.br -If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). - -.IP "\fBint get_PWM_real_range(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Get the real underlying range of PWM values being used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.br - -.br -If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). - -.br - -.br -If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. - -.br - -.br - -.IP "\fBint set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)\fP" -.IP "" 4 -Set the frequency (in Hz) of the PWM to be used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br -frequency: >=0 (Hz). -.br - -.EE - -.br - -.br -Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. - -.br - -.br -If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. - -.br - -.br -Each GPIO can be independently set to one of 18 different -PWM frequencies. - -.br - -.br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. - -.br - -.br -The frequencies for each sample rate are: - -.br - -.br - -.EX - Hertz -.br - -.br - 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 -.br - 1250 1000 800 500 400 250 200 100 50 -.br - -.br - 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 -.br - 625 500 400 250 200 125 100 50 25 -.br - -.br - 4: 10000 5000 2500 2000 1250 1000 625 500 400 -.br - 313 250 200 125 100 63 50 25 13 -.br -sample -.br - rate -.br - (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 -.br - 250 200 160 100 80 50 40 20 10 -.br - -.br - 8: 5000 2500 1250 1000 625 500 313 250 200 -.br - 156 125 100 63 50 31 25 13 6 -.br - -.br - 10: 4000 2000 1000 800 500 400 250 200 160 -.br - 125 100 80 50 40 25 20 10 5 -.br - -.EE - -.IP "\fBint get_PWM_frequency(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Get the frequency of PWM being used on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -For normal PWM the frequency will be that defined for the GPIO by -\fBset_PWM_frequency\fP. - -.br - -.br -If a hardware clock is active on the GPIO the reported frequency -will be that set by \fBhardware_clock\fP. - -.br - -.br -If hardware PWM is active on the GPIO the reported frequency -will be that set by \fBhardware_PWM\fP. - -.br - -.br -Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. - -.IP "\fBint set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)\fP" -.IP "" 4 -Start (500-2500) or stop (0) servo pulses on the GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - user_gpio: 0-31. -.br -pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. - -.br - -.br -The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. - -.br - -.br -The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. - -.br - -.br -You can DAMAGE a servo if you command it to move beyond its limits. - -.br - -.br -OTHER UPDATE RATES: - -.br - -.br -This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. - -.br - -.br - -.EX -Update Rate (Hz) 50 100 200 400 500 -.br -1E6/Hz 20000 10000 5000 2500 2000 -.br - -.EE - -.br - -.br -Firstly set the desired PWM frequency using \fBset_PWM_frequency\fP. - -.br - -.br -Then set the PWM range using \fBset_PWM_range\fP to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. - -.br - -.br -E.g. If you want to update a servo connected to GPIO 25 at 400Hz - -.br - -.br - -.EX -set_PWM_frequency(25, 400); -.br -set_PWM_range(25, 2500); -.br - -.EE - -.br - -.br -Thereafter use the \fBset_PWM_dutycycle\fP function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse. -.br - -.IP "\fBint get_servo_pulsewidth(int pi, unsigned user_gpio)\fP" -.IP "" 4 -Return the servo pulsewidth in use on a GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. - -.IP "\fBint notify_open(int pi)\fP" -.IP "" 4 -Get a free notification handle. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. - -.br - -.br -A notification is a method for being notified of GPIO state -changes via a pipe. - -.br - -.br -Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by \fBcallback\fP -should be used instead. - -.br - -.br -Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. - -.IP "\fBint notify_begin(int pi, unsigned handle, uint32_t bits)\fP" -.IP "" 4 -Start notifications on a previously opened handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: 0-31 (as returned by \fBnotify_open\fP) -.br - bits: a mask indicating the GPIO to be notified. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -The notification sends state changes for each GPIO whose -corresponding bit in bits is set. - -.br - -.br -Each notification occupies 12 bytes in the fifo as follows: - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint16_t seqno; -.br - uint16_t flags; -.br - uint32_t tick; -.br - uint32_t level; -.br -} gpioReport_t; -.br - -.EE - -.br - -.br -seqno: starts at 0 each time the handle is opened and then increments -by one for each report. - -.br - -.br -flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. - -.br - -.br -If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. - -.br - -.br -If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. - -.br - -.br -If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. - -.br - -.br -tick: the number of microseconds since system boot. It wraps around -after 1h12m. - -.br - -.br -level: indicates the level of each GPIO. If bit 1<=0 (as returned by \fBpigpio_start\fP). -.br -handle: 0-31 (as returned by \fBnotify_open\fP) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -Notifications for the handle are suspended until -\fBnotify_begin\fP is called again. - -.IP "\fBint notify_close(int pi, unsigned handle)\fP" -.IP "" 4 -Stop notifications on a previously opened handle and -release the handle for reuse. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: 0-31 (as returned by \fBnotify_open\fP) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint set_watchdog(int pi, unsigned user_gpio, unsigned timeout)\fP" -.IP "" 4 -Sets a watchdog for a GPIO. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - timeout: 0-60000. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. - -.br - -.br -The watchdog is nominally in milliseconds. - -.br - -.br -Only one watchdog may be registered per GPIO. - -.br - -.br -The watchdog may be cancelled by setting timeout to 0. - -.br - -.br -Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. - -.br - -.br -The callback will receive the special level PI_TIMEOUT. - -.IP "\fBint set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)\fP" -.IP "" 4 -Sets a glitch filter on a GPIO. - -.br - -.br -Level changes on the GPIO are not reported unless the level -has been stable for at least \fBsteady\fP microseconds. The -level is then reported. Level changes of less than -\fBsteady\fP microseconds are ignored. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31 -.br - steady: 0-300000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - -.br - -.br -This filter affects the GPIO samples returned to callbacks set up -with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP. - -.br - -.br -It does not affect levels read by \fBgpio_read\fP, -\fBread_bank_1\fP, or \fBread_bank_2\fP. - -.br - -.br -Each (stable) edge will be timestamped \fBsteady\fP microseconds -after it was first detected. - -.IP "\fBint set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)\fP" -.IP "" 4 -Sets a noise filter on a GPIO. - -.br - -.br -Level changes on the GPIO are ignored until a level which has -been stable for \fBsteady\fP microseconds is detected. Level changes -on the GPIO are then reported for \fBactive\fP microseconds after -which the process repeats. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31 -.br - steady: 0-300000 -.br - active: 0-1000000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - -.br - -.br -This filter affects the GPIO samples returned to callbacks set up -with \fBcallback\fP, \fBcallback_ex\fP and \fBwait_for_edge\fP. - -.br - -.br -It does not affect levels read by \fBgpio_read\fP, -\fBread_bank_1\fP, or \fBread_bank_2\fP. - -.br - -.br -Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. - -.IP "\fBuint32_t read_bank_1(int pi)\fP" -.IP "" 4 -Read the levels of the bank 1 GPIO (GPIO 0-31). - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). - -.IP "\fBint clear_bank_1(int pi, uint32_t bits)\fP" -.IP "" 4 -Clears GPIO 0-31 if the corresponding bit in bits is set. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bits: a bit mask with 1 set if the corresponding GPIO is -.br - to be cleared. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_SOME_PERMITTED. - -.br - -.br -A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. - -.IP "\fBint clear_bank_2(int pi, uint32_t bits)\fP" -.IP "" 4 -Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bits: a bit mask with 1 set if the corresponding GPIO is -.br - to be cleared. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_SOME_PERMITTED. - -.br - -.br -A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. - -.IP "\fBint set_bank_1(int pi, uint32_t bits)\fP" -.IP "" 4 -Sets GPIO 0-31 if the corresponding bit in bits is set. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bits: a bit mask with 1 set if the corresponding GPIO is -.br - to be set. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_SOME_PERMITTED. - -.br - -.br -A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. - -.IP "\fBint set_bank_2(int pi, uint32_t bits)\fP" -.IP "" 4 -Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bits: a bit mask with 1 set if the corresponding GPIO is -.br - to be set. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_SOME_PERMITTED. - -.br - -.br -A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. - -.IP "\fBint hardware_clock(int pi, unsigned gpio, unsigned clkfreq)\fP" -.IP "" 4 -Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - gpio: see description -.br -frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. - -.br - -.br -The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. - -.br - -.br -The GPIO must be one of the following. - -.br - -.br - -.EX -4 clock 0 All models -.br -5 clock 1 All models but A and B (reserved for system use) -.br -6 clock 2 All models but A and B -.br -20 clock 0 All models but A and B -.br -21 clock 1 All models but A and Rev.2 B (reserved for system use) -.br - -.br -32 clock 0 Compute module only -.br -34 clock 0 Compute module only -.br -42 clock 1 Compute module only (reserved for system use) -.br -43 clock 2 Compute module only -.br -44 clock 1 Compute module only (reserved for system use) -.br - -.EE - -.br - -.br -Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. - -.IP "\fBint hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)\fP" -.IP "" 4 -Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. - -.br - -.br -NOTE: Any waveform started by \fBwave_send_*\fP or \fBwave_chain\fP -will be cancelled. - -.br - -.br -This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - gpio: see descripton -.br -PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711) -.br -PWMduty: 0 (off) to 1000000 (1M)(fully on) -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. - -.br - -.br -The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. - -.br - -.br -The GPIO must be one of the following. - -.br - -.br - -.EX -12 PWM channel 0 All models but A and B -.br -13 PWM channel 1 All models but A and B -.br -18 PWM channel 0 All models -.br -19 PWM channel 1 All models but A and B -.br - -.br -40 PWM channel 0 Compute module only -.br -41 PWM channel 1 Compute module only -.br -45 PWM channel 1 Compute module only -.br -52 PWM channel 0 Compute module only -.br -53 PWM channel 1 Compute module only -.br - -.EE - -.br - -.br -The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). - -.br - -.br -The actual frequency set is 250M/steps (375M/steps for the BCM2711). - -.br - -.br -There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. - -.IP "\fBuint32_t get_current_tick(int pi)\fP" -.IP "" 4 -Gets the current system tick. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Tick is the number of microseconds since system boot. - -.br - -.br -As tick is an unsigned 32 bit quantity it wraps around after -2**32 microseconds, which is approximately 1 hour 12 minutes. - -.br - -.br - -.IP "\fBuint32_t get_hardware_revision(int pi)\fP" -.IP "" 4 -Get the Pi's hardware revision number. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. - -.br - -.br -If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. - -.br - -.br -The revision number can be used to determine the assignment of GPIO -to pins (see \fBgpio\fP). - -.br - -.br -There are at least three types of board. - -.br - -.br -Type 1 boards have hardware revision numbers of 2 and 3. - -.br - -.br -Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. - -.br - -.br -Type 3 boards have hardware revision numbers of 16 or greater. - -.IP "\fBuint32_t get_pigpio_version(int pi)\fP" -.IP "" 4 -Returns the pigpio version. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_clear(int pi)\fP" -.IP "" 4 -This function clears all waveforms and any data added by calls to the -\fBwave_add_*\fP functions. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.IP "\fBint wave_add_new(int pi)\fP" -.IP "" 4 -This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the \fBwave_create\fP function. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.IP "\fBint wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)\fP" -.IP "" 4 -This function adds a number of pulses to the current waveform. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -numPulses: the number of pulses. -.br - pulses: an array of pulses. -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. - -.br - -.br -The pulses are interleaved in time order within the existing waveform -(if any). - -.br - -.br -Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. - -.br - -.br -If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. - -.IP "\fBint wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)\fP" -.IP "" 4 -This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - baud: 50-1000000 -.br -data_bits: number of data bits (1-32) -.br -stop_bits: number of stop half bits (2-8) -.br - offset: >=0 -.br - numBytes: >=1 -.br - str: an array of chars. -.br - -.EE - -.br - -.br -Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. - -.br - -.br -NOTES: - -.br - -.br -The serial data is formatted as one start bit, \fBdata_bits\fP data bits, -and \fBstop_bits\fP/2 stop bits. - -.br - -.br -It is legal to add serial data streams with different baud rates to -the same waveform. - -.br - -.br -\fBnumBytes\fP is the number of bytes of data in str. - -.br - -.br -The bytes required for each character depend upon \fBdata_bits\fP. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint wave_create(int pi)\fP" -.IP "" 4 -This function creates a waveform from the data provided by the prior -calls to the \fBwave_add_*\fP functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -The data provided by the \fBwave_add_*\fP functions is consumed by this -function. - -.br - -.br -As many waveforms may be created as there is space available. The -wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. - -.br - -.br -Normal usage would be - -.br - -.br -Step 1. \fBwave_clear\fP to clear all waveforms and added data. - -.br - -.br -Step 2. \fBwave_add_*\fP calls to supply the waveform data. - -.br - -.br -Step 3. \fBwave_create\fP to create the waveform and get a unique id - -.br - -.br -Repeat steps 2 and 3 as needed. - -.br - -.br -Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. - -.br - -.br -A waveform comprises one or more pulses. Each pulse consists of a -\fBgpioPulse_t\fP structure. - -.br - -.br - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br -The fields specify - -.br - -.br -1) the GPIO to be switched on at the start of the pulse. -.br -2) the GPIO to be switched off at the start of the pulse. -.br -3) the delay in microseconds before the next pulse. -.br - -.br - -.br -Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). - -.br - -.br -When a waveform is started each pulse is executed in order with the -specified delay between the pulse and the next. - -.br - -.br -Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. - -.IP "\fBint wave_create_and_pad(int pi, int percent)\fP" -.IP "" 4 -This function creates a waveform like \fBwave_create\fP but pads the consumed -resources. Where percent gives the percentage of the resources to use (in terms -of the theoretical maximum, not the current amount free). This allows the reuse -.br -of deleted waves while a transmission is active. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br -percent: 0-100, size of waveform as percentage of maximum available. -.br - -.EE - -.br - -.br -The data provided by the \fBwave_add_*\fP functions are consumed by this -function. - -.br - -.br -As many waveforms may be created as there is space available. The -wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit. - -.br - -.br -A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. - -.br - -.br -Normal usage: - -.br - -.br -Step 1. \fBwave_clear\fP to clear all waveforms and added data. - -.br - -.br -Step 2. \fBwave_add_*\fP calls to supply the waveform data. - -.br - -.br -Step 3. \fBwave_create_and_pad\fP to create a waveform of uniform size. - -.br - -.br -Step 4. \fBwave_send_*\fP with the id of the waveform to transmit. - -.br - -.br -Repeat steps 2-4 as needed. - -.br - -.br -Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. - -.br - -.br -Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. - -.IP "\fBint wave_delete(int pi, unsigned wave_id)\fP" -.IP "" 4 -This function deletes the waveform with id wave_id. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Wave ids are allocated in order, 0, 1, 2, etc. - -.br - -.br -The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. - -.br - -.br -- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. - -.br - -.br -- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_WAVE_ID. - -.IP "\fBint wave_send_once(int pi, unsigned wave_id)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The waveform -is sent once. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_send_repeat(int pi, unsigned wave_id)\fP" -.IP "" 4 -This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by \fBwave_tx_stop\fP). - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -wave_id: >=0, as returned by \fBwave_create\fP. -.br - -.EE - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)\fP" -.IP "" 4 -Transmits the waveform with id wave_id using mode mode. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -wave_id: >=0, as returned by \fBwave_create\fP. -.br - mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT, -.br - PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC. -.br - -.EE - -.br - -.br -PI_WAVE_MODE_ONE_SHOT: same as \fBwave_send_once\fP. - -.br - -.br -PI_WAVE_MODE_REPEAT same as \fBwave_send_repeat\fP. - -.br - -.br -PI_WAVE_MODE_ONE_SHOT_SYNC same as \fBwave_send_once\fP but tries -to sync with the previous waveform. - -.br - -.br -PI_WAVE_MODE_REPEAT_SYNC same as \fBwave_send_repeat\fP but tries -to sync with the previous waveform. - -.br - -.br -WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br -Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. - -.IP "\fBint wave_chain(int pi, char *buf, unsigned bufSize)\fP" -.IP "" 4 -This function transmits a chain of waveforms. - -.br - -.br -NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. - -.br - -.br -The waves to be transmitted are specified by the contents of buf -which contains an ordered list of \fBwave_id\fPs and optional command -codes and related data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - buf: pointer to the wave_ids and optional command codes -.br -bufSize: the number of bytes in buf -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. - -.br - -.br -Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. - -.br - -.br -A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. - -.br - -.br -Delays between waves may be added with the delay command. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -Loop Start 255 0 Identify start of a wave block -.br -Loop Repeat 255 1 x y loop x + y*256 times -.br -Delay 255 2 x y delay x + y*256 microseconds -.br -Loop Forever 255 3 loop forever -.br - -.br - -.br -If present Loop Forever must be the last entry in the chain. - -.br - -.br -The code is currently dimensioned to support a chain with roughly -600 entries and 20 loop counters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -#define WAVES 5 -.br -#define GPIO 4 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, pi, wid[WAVES]; -.br - -.br - pi = pigpio_start(0, 0); -.br - if (pi<0) return -1; -.br - -.br - set_mode(pi, GPIO, PI_OUTPUT); -.br - -.br - for (i=0; i=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns the waveform id or one of the following special values: - -.br - -.br -PI_WAVE_NOT_FOUND (9998) - transmitted wave not found. -.br -PI_NO_TX_WAVE (9999) - no wave being transmitted. - -.IP "\fBint wave_tx_busy(int pi)\fP" -.IP "" 4 -This function checks to see if a waveform is currently being -transmitted. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns 1 if a waveform is currently being transmitted, otherwise 0. - -.IP "\fBint wave_tx_stop(int pi)\fP" -.IP "" 4 -This function stops the transmission of the current waveform. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.br - -.br -Returns 0 if OK. - -.br - -.br -This function is intended to stop a waveform started with the repeat mode. - -.IP "\fBint wave_get_micros(int pi)\fP" -.IP "" 4 -This function returns the length in microseconds of the current -waveform. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_high_micros(int pi)\fP" -.IP "" 4 -This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_max_micros(int pi)\fP" -.IP "" 4 -This function returns the maximum possible size of a waveform in -.br -microseconds. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_pulses(int pi)\fP" -.IP "" 4 -This function returns the length in pulses of the current waveform. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_high_pulses(int pi)\fP" -.IP "" 4 -This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_max_pulses(int pi)\fP" -.IP "" 4 -This function returns the maximum possible size of a waveform in pulses. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_cbs(int pi)\fP" -.IP "" 4 -This function returns the length in DMA control blocks of the current -waveform. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_high_cbs(int pi)\fP" -.IP "" 4 -This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint wave_get_max_cbs(int pi)\fP" -.IP "" 4 -This function returns the maximum possible size of a waveform in DMA -control blocks. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br - -.EE - -.IP "\fBint gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)\fP" -.IP "" 4 -This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - pulseLen: 1-100. -.br - level: 0,1. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. - -.IP "\fBint store_script(int pi, char *script)\fP" -.IP "" 4 -This function stores a script for later execution. - -.br - -.br -See \fBhttp://abyz.me.uk/rpi/pigpio/pigs.html#Scripts\fP for details. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script: the text of the script. -.br - -.EE - -.br - -.br -The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. - -.IP "\fBint run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function runs a stored script. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - numPar: 0-10, the number of parameters. -.br - param: an array of parameters. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)\fP" -.IP "" 4 -This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - numPar: 0-10, the number of parameters. -.br - param: an array of parameters. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. - -.br - -.br -param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. - -.IP "\fBint script_status(int pi, unsigned script_id, uint32_t *param)\fP" -.IP "" 4 -This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - param: an array to hold the returned 10 parameters. -.br - -.EE - -.br - -.br -The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. - -.br - -.br -The run status may be - -.br - -.br - -.EX -PI_SCRIPT_INITING -.br -PI_SCRIPT_HALTED -.br -PI_SCRIPT_RUNNING -.br -PI_SCRIPT_WAITING -.br -PI_SCRIPT_FAILED -.br - -.EE - -.br - -.br -The current value of script parameters 0 to 9 are returned in param. - -.IP "\fBint stop_script(int pi, unsigned script_id)\fP" -.IP "" 4 -This function stops a running script. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint delete_script(int pi, unsigned script_id)\fP" -.IP "" 4 -This function deletes a stored script. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -script_id: >=0, as returned by \fBstore_script\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. - -.IP "\fBint bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)\fP" -.IP "" 4 -This function opens a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - baud: 50-250000 -.br -data_bits: 1-32 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. - -.br - -.br -The serial data is returned in a cyclic buffer and is read using -bb_serial_read. - -.br - -.br -It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. - -.IP "\fBint bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)\fP" -.IP "" 4 -This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - buf: an array to receive the read bytes. -.br - bufSize: >=0 -.br - -.EE - -.br - -.br -Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. - -.br - -.br -The bytes returned for each character depend upon the number of -data bits \fBdata_bits\fP specified in the \fBbb_serial_read_open\fP command. - -.br - -.br -For \fBdata_bits\fP 1-8 there will be one byte per character. -.br -For \fBdata_bits\fP 9-16 there will be two bytes per character. -.br -For \fBdata_bits\fP 17-32 there will be four bytes per character. - -.IP "\fBint bb_serial_read_close(int pi, unsigned user_gpio)\fP" -.IP "" 4 -This function closes a GPIO for bit bang reading of serial data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. - -.IP "\fBint bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)\fP" -.IP "" 4 -This function inverts serial logic for big bang serial reads. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. -.br - invert: 0-1, 1 invert, 0 normal. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. - -.IP "\fBint i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)\fP" -.IP "" 4 -This returns a handle for the device at address i2c_addr on bus i2c_bus. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - i2c_bus: >=0. -.br - i2c_addr: 0-0x7F. -.br -i2c_flags: 0. -.br - -.EE - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.br - -.br -Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - SDA SCL -.br -I2C 0 0 1 -.br -I2C 1 2 3 -.br - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. - -.br - -.br -For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. - -.br - -.br - -.EX -S (1 bit) : Start bit -.br -P (1 bit) : Stop bit -.br -Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. -.br -A, NA (1 bit) : Accept and not accept bit. -.br -.br -.br -Addr (7 bits): I2C 7 bit address. -.br -i2c_reg (8 bits): A byte which often selects a register. -.br -Data (8 bits): A data byte. -.br -Count (8 bits): A byte defining the length of a block operation. -.br - -.br -[..]: Data sent by the device. -.br - -.EE - -.IP "\fBint i2c_close(int pi, unsigned handle)\fP" -.IP "" 4 -This closes the I2C device associated with the handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint i2c_write_quick(int pi, unsigned handle, unsigned bit)\fP" -.IP "" 4 -This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - bit: 0-1, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Quick command. SMBus 2.0 5.5.1 - -.EX -S Addr bit [A] P -.br - -.EE - -.IP "\fBint i2c_write_byte(int pi, unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This sends a single byte to the device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - bVal: 0-0xFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Send byte. SMBus 2.0 5.5.2 - -.EX -S Addr Wr [A] bVal [A] P -.br - -.EE - -.IP "\fBint i2c_read_byte(int pi, unsigned handle)\fP" -.IP "" 4 -This reads a single byte from the device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. - -.br - -.br -Receive byte. SMBus 2.0 5.5.3 - -.EX -S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)\fP" -.IP "" 4 -This writes a single byte to the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - bVal: 0-0xFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write byte. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] i2c_reg [A] bVal [A] P -.br - -.EE - -.IP "\fBint i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" -.IP "" 4 -This writes a single 16 bit word to the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - wVal: 0-0xFFFF, the value to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Write word. SMBus 2.0 5.5.4 - -.EX -S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P -.br - -.EE - -.IP "\fBint i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)\fP" -.IP "" 4 -This reads a single byte from the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - -.EE - -.br - -.br -Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read byte. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P -.br - -.EE - -.IP "\fBint i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)\fP" -.IP "" 4 -This reads a single 16 bit word from the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Read word. SMBus 2.0 5.5.5 - -.EX -S Addr Wr [A] i2c_reg [A] -.br - S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)\fP" -.IP "" 4 -This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write/read. -.br - wVal: 0-0xFFFF, the value to write. -.br - -.EE - -.br - -.br -Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Process call. SMBus 2.0 5.5.6 - -.EX -S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A] -.br - S Addr Rd [A] [DataLow] A [DataHigh] NA P -.br - -.EE - -.IP "\fBint i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes up to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - buf: an array with the data to send. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br -Block write. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ... -.br - [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)\fP" -.IP "" 4 -This reads a block of up to 32 bytes from the specified register of -the device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - buf: an array to receive the read data. -.br - -.EE - -.br - -.br -The amount of returned data is set by the device. - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -Block read. SMBus 2.0 5.5.7 - -.EX -S Addr Wr [A] i2c_reg [A] -.br - S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write/read. -.br - buf: an array with the data to send and to receive the read data. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br -The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. - -.br - -.br -Block write-block read. SMBus 2.0 5.5.8 - -.EX -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ... -.br - S Addr Rd [A] [Count] A [Data] ... A P -.br - -.EE - -.IP "\fBint i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to read. -.br - buf: an array to receive the read data. -.br - count: 1-32, the number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] i2c_reg [A] -.br - S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP" -.IP "" 4 -This writes 1 to 32 bytes to the specified register of the device -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0, as returned by a call to \fBi2c_open\fP. -.br -i2c_reg: 0-255, the register to write. -.br - buf: the data to write. -.br - count: 1-32, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This reads count bytes from the raw device into buf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - buf: an array to receive the read data bytes. -.br - count: >0, the number of bytes to read. -.br - -.EE - -.br - -.br -Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. - -.br - -.br - -.EX -S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P -.br - -.EE - -.IP "\fBint i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This writes count bytes from buf to the raw device. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2c_open\fP. -.br - buf: an array containing the data bytes to write. -.br - count: >0, the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. - -.br - -.br - -.EX -S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P -.br - -.EE - -.IP "\fBint i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBi2cOpen\fP -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -On 2 Switch combined flag on -.br -Off 3 Switch combined flag off -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53, write 0x32, read 6 bytes -.br -Set address 0x1E, write 0x03, read 6 bytes -.br -Set address 0x68, write 0x1B, read 8 bytes -.br -End -.br - -.br -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -.br -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -.br -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -.br -0x00 -.br - -.EE - -.br - -.br - -.IP "\fBint bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)\fP" -.IP "" 4 -This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. - -.br - -.br -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -.br - -.br -o baud rates as low as 50 -.br -o repeated starts -.br -o clock stretching -.br -o I2C on any pair of spare GPIO - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - SDA: 0-31 -.br - SCL: 0-31 -.br -baud: 50-500000 -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -NOTE: - -.br - -.br -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -.IP "\fBint bb_i2c_close(int pi, unsigned SDA)\fP" -.IP "" 4 -This function stops bit banging I2C on a pair of GPIO previously -opened with \fBbb_i2c_open\fP. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -SDA: 0-31, the SDA GPIO used in a prior call to \fBbb_i2c_open\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - -.IP "\fBint bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)\fP" -.IP "" 4 -This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - SDA: 0-31 (as used in a prior call to \fBbb_i2c_open\fP) -.br - inBuf: pointer to the concatenated I2C commands, see below -.br - inLen: size of command buffer -.br -outBuf: pointer to buffer to hold returned data -.br -outLen: size of output buffer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. - -.br - -.br -The following command codes are supported: - -.br - -.br -Name Cmd & Data Meaning -.br -End 0 No more commands -.br -Escape 1 Next P is two bytes -.br -Start 2 Start condition -.br -Stop 3 Stop condition -.br -Address 4 P Set I2C address to P -.br -Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) -.br -Read 6 P Read P bytes of data -.br -Write 7 P ... Write P bytes of data -.br - -.br - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br - -.br -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -.br - -.br -No flags are currently defined. - -.br - -.br -The returned I2C data is stored in consecutive locations of outBuf. - -.br - -.br -\fBExample\fP -.br - -.EX -Set address 0x53 -.br -start, write 0x32, (re)start, read 6 bytes, stop -.br -Set address 0x1E -.br -start, write 0x03, (re)start, read 6 bytes, stop -.br -Set address 0x68 -.br -start, write 0x1B, (re)start, read 8 bytes, stop -.br -End -.br - -.br -0x04 0x53 -.br -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x1E -.br -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x68 -.br -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 -.br - -.br -0x00 -.br - -.EE - -.IP "\fBint bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)\fP" -.IP "" 4 -This function selects a set of GPIO for bit banging SPI at a -specified baud rate. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - CS: 0-31 -.br - MISO: 0-31 -.br - MOSI: 0-31 -.br - SCLK: 0-31 -.br - baud: 50-250000 -.br -spi_flags: see below -.br - -.EE - -.br - -.br -spi_flags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m -.br - -.EE - -.br - -.br -mm defines the SPI mode, defaults to 0 - -.br - -.br - -.EX -Mode CPOL CPHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -p is 0 if CS is active low (default) and 1 for active high. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. - -.br - -.br -The other bits in flags should be set to zero. - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. - -.br - -.br -If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. - -.br - -.br -\fBExample\fP -.br - -.EX -bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1 -.br -bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2 -.br - -.EE - -.IP "\fBint bb_spi_close(int pi, unsigned CS)\fP" -.IP "" 4 -This function stops bit banging SPI on a set of GPIO -opened with \fBbbSPIOpen\fP. - -.br - -.br - -.EX -pi: >=0 (as returned by \fBpigpio_start\fP). -.br -CS: 0-31, the CS GPIO used in a prior call to \fBbb_spi_open\fP -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. - -.IP "\fBint bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)\fP" -.IP "" 4 -This function executes a bit banged SPI transfer. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - CS: 0-31 (as used in a prior call to \fBbb_spi_open\fP) -.br -txBuf: pointer to buffer to hold data to be sent -.br -rxBuf: pointer to buffer to hold returned data -.br -count: size of data transfer -.br - -.EE - -.br - -.br -Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. - -.br - -.br -\fBExample\fP -.br - -.EX -// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2 -.br -// ./bb_spi_x_test -.br - -.br -#include -.br - -.br -#include "pigpiod_if2.h" -.br - -.br -#define CE0 5 -.br -#define CE1 6 -.br -#define MISO 13 -.br -#define MOSI 19 -.br -#define SCLK 12 -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int i, pi, count, set_val, read_val; -.br - unsigned char inBuf[3]; -.br - char cmd1[] = {0, 0}; -.br - char cmd2[] = {12, 0}; -.br - char cmd3[] = {1, 128, 0}; -.br - -.br - if ((pi = pigpio_start(0, 0)) < 0) -.br - { -.br - fprintf(stderr, "pigpio initialisation failed (%d).\n", pi); -.br - return 1; -.br - } -.br - -.br - bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC -.br - bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC -.br - -.br - for (i=0; i<256; i++) -.br - { -.br - cmd1[1] = i; -.br - -.br - count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC -.br - -.br - if (count == 2) -.br - { -.br - count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC -.br - -.br - if (count == 2) -.br - { -.br - set_val = inBuf[1]; -.br - -.br - count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC -.br - -.br - if (count == 3) -.br - { -.br - read_val = ((inBuf[1]&3)<<8) | inBuf[2]; -.br - printf("%d %d\n", set_val, read_val); -.br - } -.br - } -.br - } -.br - } -.br - -.br - bb_spi_close(pi, CE0); -.br - bb_spi_close(pi, CE1); -.br - -.br - pigpio_stop(pi); -.br -} -.br - -.EE - -.IP "\fBint spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)\fP" -.IP "" 4 -This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. - -.br - -.br -The Pi has two SPI peripherals: main and auxiliary. - -.br - -.br -The main SPI has two chip selects (channels), the auxiliary has -three. - -.br - -.br -The auxiliary SPI is available on all models but the A and B. - -.br - -.br -The GPIO used are given in the following table. - -.br - -.br - MISO MOSI SCLK CE0 CE1 CE2 -.br -Main SPI 9 10 11 8 7 - -.br -Aux SPI 19 20 21 18 17 16 -.br - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -spi_channel: 0-1 (0-2 for the auxiliary SPI). -.br - baud: 32K-125M (values above 30M are unlikely to work). -.br - spi_flags: see below. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. - -.br - -.br -spi_flags consists of the least significant 22 bits. - -.br - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -.br - -.EE - -.br - -.br -mm defines the SPI mode. - -.br - -.br -Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. - -.br - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br - -.br -px is 0 if CEx is active low (default) and 1 for active high. - -.br - -.br -ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. - -.br - -.br -A is 0 for the main SPI, 1 for the auxiliary SPI. - -.br - -.br -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main -SPI only. - -.br - -.br -nnnn defines the number of bytes (0-15) to write before switching -the MOSI line to MISO to read data. This field is ignored -if W is not set. Main SPI only. - -.br - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. Auxiliary SPI -only. - -.br - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. Auxiliary SPI -only. - -.br - -.br -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI only. - -.br - -.br -The \fBspi_read\fP, \fBspi_write\fP, and \fBspi_xfer\fP functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. - -.br - -.br -For bits 1-8 there will be one byte per character. -.br -For bits 9-16 there will be two bytes per character. -.br -For bits 17-32 there will be four bytes per character. - -.br - -.br -Multi-byte transfers are made in least significant byte first order. - -.br - -.br -E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. - -.br - -.br -E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed -by 0x1A. - -.br - -.br -The other bits in flags should be set to zero. - -.IP "\fBint spi_close(int pi, unsigned handle)\fP" -.IP "" 4 -This functions closes the SPI device identified by the handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint spi_read(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads count bytes of data from the SPI -device associated with the handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - buf: an array to receive the read data bytes. -.br - count: the number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spi_write(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes of data from buf to the SPI -device associated with the handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - buf: the data bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP" -.IP "" 4 -This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBspi_open\fP. -.br - txBuf: the data bytes to write. -.br - rxBuf: the received data bytes. -.br - count: the number of bytes to transfer. -.br - -.EE - -.br - -.br -Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. - -.IP "\fBint serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)\fP" -.IP "" 4 -This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. - -.br - -.br - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - ser_tty: the serial device to open. -.br - baud: the baud rate in bits per second, see below. -.br -ser_flags: 0. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. - -.br - -.br -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -.br - -.br -No flags are currently defined. This parameter should be set to zero. - -.IP "\fBint serial_close(int pi, unsigned handle)\fP" -.IP "" 4 -This function closes the serial device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.IP "\fBint serial_write_byte(int pi, unsigned handle, unsigned bVal)\fP" -.IP "" 4 -This function writes bVal to the serial port associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serial_read_byte(int pi, unsigned handle)\fP" -.IP "" 4 -This function reads a byte from the serial port associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. - -.br - -.br -If no data is ready PI_SER_READ_NO_DATA is returned. - -.IP "\fBint serial_write(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the serial port -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - buf: the array of bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. - -.IP "\fBint serial_read(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - buf: an array to receive the read data. -.br - count: the maximum number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. - -.br - -.br -If no data is ready zero is returned. - -.IP "\fBint serial_data_available(int pi, unsigned handle)\fP" -.IP "" 4 -Returns the number of bytes available to be read from the -device associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0, as returned by a call to \fBserial_open\fP. -.br - -.EE - -.br - -.br -Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. - -.IP "\fBint custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It returns a single integer value. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -arg1: >=0 -.br -arg2: >=0 -.br -argx: extra (byte) arguments -.br -argc: number of extra arguments -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.IP "\fBint custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" -.IP "" 4 -This function is available for user customisation. - -.br - -.br -It differs from custom_1 in that it returns an array of bytes -rather than just an integer. - -.br - -.br -The return value is an integer indicating the number of returned bytes. - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - arg1: >=0 -.br - argc: extra (byte) arguments -.br - count: number of extra arguments -.br -retBuf: buffer for returned data -.br -retMax: maximum number of bytes to return -.br - -.EE - -.br - -.br -Returns >= 0 if OK, less than 0 indicates a user defined error. - -.br - -.br -Note, the number of returned bytes will be retMax or less. - -.IP "\fBint get_pad_strength(int pi, unsigned pad)\fP" -.IP "" 4 -This function returns the pad drive strength in mA. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -pad: 0-2, the pad to get. -.br - -.EE - -.br - -.br -Returns the pad drive strength if OK, otherwise PI_BAD_PAD. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -strength = get_pad_strength(pi, 0); // get pad 0 strength -.br - -.EE - -.IP "\fBint set_pad_strength(int pi, unsigned pad, unsigned padStrength)\fP" -.IP "" 4 -This function sets the pad drive strength in mA. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - pad: 0-2, the pad to set. -.br -padStrength: 1-16 mA. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA -.br - -.EE - -.IP "\fBint shell_(int pi, char *scriptName, char *scriptString)\fP" -.IP "" 4 -This function uses the system call to execute a shell script -with the given string as its parameter. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - scriptName: the name of the script, only alphanumeric characters, -.br - '-' and '_' are allowed in the name. -.br -scriptString: the string to pass to the script. -.br - -.EE - -.br - -.br -The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. - -.br - -.br -scriptName must exist in /opt/pigpio/cgi and must be executable. - -.br - -.br -The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. - -.br - -.br -The following table gives some example returned statuses. - -.br - -.br -Script exit status Returned system call status -.br -1 256 -.br -5 1280 -.br -10 2560 -.br -200 51200 -.br -script not found 32512 -.br - -.br - -.br -\fBExample\fP -.br - -.EX -// pass two parameters, hello and world -.br -status = shell_(pi, "scr1", "hello world"); -.br - -.br -// pass three parameters, hello, string with spaces, and world -.br -status = shell_(pi, "scr1", "hello 'string with spaces' world"); -.br - -.br -// pass one parameter, hello string with spaces world -.br -status = shell_(pi, "scr1", "\"hello string with spaces world\""); -.br - -.EE - -.IP "\fBint file_open(int pi, char *file, unsigned mode)\fP" -.IP "" 4 -This function returns a handle to a file opened in a specified mode. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -file: the file to open. -.br -mode: the file open mode. -.br - -.EE - -.br - -.br -Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. - -.br - -.br -File - -.br - -.br -A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. - -.br - -.br -Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. - -.br - -.br -Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. - -.br - -.br -Suppose /opt/pigpio/access contains the following entries - -.br - -.br - -.EX -/home/* n -.br -/home/pi/shared/dir_1/* w -.br -/home/pi/shared/dir_2/* r -.br -/home/pi/shared/dir_3/* u -.br -/home/pi/shared/dir_1/file.txt n -.br - -.EE - -.br - -.br -Files may be written in directory dir_1 with the exception -of file.txt. - -.br - -.br -Files may be read in directory dir_2. - -.br - -.br -Files may be read and written in directory dir_3. - -.br - -.br -If a directory allows read, write, or read/write access then files may -be created in that directory. - -.br - -.br -In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. - -.br - -.br - -.EX -a path containing .. -.br -a path containing only wildcards (*?) -.br -a path containing less than two non-wildcard parts -.br - -.EE - -.br - -.br -Mode - -.br - -.br -The mode may have the following values. - -.br - -.br -Macro Value Meaning -.br -PI_FILE_READ 1 open file for reading -.br -PI_FILE_WRITE 2 open file for writing -.br -PI_FILE_RW 3 open file for reading and writing -.br - -.br - -.br -The following values may be or'd into the mode. - -.br - -.br -Macro Value Meaning -.br -PI_FILE_APPEND 4 Writes append data to the end of the file -.br -PI_FILE_CREATE 8 The file is created if it doesn't exist -.br -PI_FILE_TRUNC 16 The file is truncated -.br - -.br - -.br -Newly created files are owned by root with permissions owner read and write. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int pi, handle, c; -.br - char buf[60000]; -.br - -.br - pi = pigpio_start(NULL, NULL); -.br - -.br - if (pi < 0) return 1; -.br - -.br - // assumes /opt/pigpio/access contains the following line -.br - // /ram/*.c r -.br - -.br - handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ); -.br - -.br - if (handle >= 0) -.br - { -.br - while ((c=file_read(pi, handle, buf, sizeof(buf)-1))) -.br - { -.br - buf[c] = 0; -.br - printf("%s", buf); -.br - } -.br - -.br - file_close(pi, handle); -.br - } -.br - -.br - pigpio_stop(pi); -.br -} -.br - -.EE - -.IP "\fBint file_close(int pi, unsigned handle)\fP" -.IP "" 4 -This function closes the file associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0 (as returned by \fBfile_open\fP). -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE. - -.br - -.br -\fBExample\fP -.br - -.EX -file_close(pi, handle); -.br - -.EE - -.IP "\fBint file_write(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function writes count bytes from buf to the the file -associated with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0 (as returned by \fBfile_open\fP). -.br - buf: the array of bytes to write. -.br - count: the number of bytes to write. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. - -.br - -.br -\fBExample\fP -.br - -.EX -if (file_write(pi, handle, buf, 100) == 0) -.br -{ -.br - // file written okay -.br -} -.br -else -.br -{ -.br - // error -.br -} -.br - -.EE - -.IP "\fBint file_read(int pi, unsigned handle, char *buf, unsigned count)\fP" -.IP "" 4 -This function reads up to count bytes from the the file -associated with handle and writes them to buf. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -handle: >=0 (as returned by \fBfile_open\fP). -.br - buf: an array to receive the read data. -.br - count: the maximum number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. - -.br - -.br -\fBExample\fP -.br - -.EX - bytes = file_read(pi, handle, buf, sizeof(buf)); -.br - -.br - if (bytes >= 0) -.br - { -.br - // process read data -.br - } -.br - -.EE - -.IP "\fBint file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)\fP" -.IP "" 4 -This function seeks to a position within the file associated -with handle. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - handle: >=0 (as returned by \fBfile_open\fP). -.br -seekOffset: the number of bytes to move. Positive offsets -.br - move forward, negative offsets backwards. -.br - seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1), -.br - or PI_FROM_END (2). -.br - -.EE - -.br - -.br -Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. - -.br - -.br -\fBExample\fP -.br - -.EX -file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123 -.br - -.br -size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size -.br - -.br -pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position -.br - -.EE - -.IP "\fBint file_list(int pi, char *fpat, char *buf, unsigned count)\fP" -.IP "" 4 -This function returns a list of files which match a pattern. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - fpat: file pattern to match. -.br - buf: an array to receive the matching file names. -.br -count: the maximum number of bytes to read. -.br - -.EE - -.br - -.br -Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. - -.br - -.br -The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See \fBfile_open\fP. - -.br - -.br -NOTE - -.br - -.br -The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. - -.br - -.br -\fBExample\fP -.br - -.EX -#include -.br -#include -.br - -.br -int main(int argc, char *argv[]) -.br -{ -.br - int pi, handle, c; -.br - char buf[60000]; -.br - -.br - pi = pigpio_start(NULL, NULL); -.br - -.br - if (pi < 0) return 1; -.br - -.br - // assumes /opt/pigpio/access contains the following line -.br - // /ram/*.c r -.br - -.br - c = file_list(pi, "/ram/p*.c", buf, sizeof(buf)); -.br - -.br - if (c >= 0) -.br - { -.br - buf[c] = 0; -.br - printf("%s", buf); -.br - } -.br - -.br - pigpio_stop(pi); -.br -} -.br - -.EE - -.IP "\fBint callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)\fP" -.IP "" 4 -This function initialises a new callback. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - f: the callback function. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -edge 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.EE - -.br - -.br -The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). - -.br - -.br -The number of samples per second is given in the following table. - -.br - -.br - -.EX - samples -.br - per sec -.br - -.br - 1 1,000,000 -.br - 2 500,000 -.br -sample 4 250,000 -.br -rate 5 200,000 -.br -(us) 8 125,000 -.br - 10 100,000 -.br - -.EE - -.br - -.br -GPIO level changes shorter than the sample rate may be missed. - -.br - -.br -The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. - -.br - -.br -If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use \fBgpio_read\fP. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. - -.IP "\fBint callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP" -.IP "" 4 -This function initialises a new callback. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - f: the callback function. -.br - userdata: a pointer to arbitrary user data. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the GPIO, edge, tick, and the userdata -pointer, whenever the GPIO has the identified edge. - -.br - -.br - -.EX -Parameter Value Meaning -.br - -.br -GPIO 0-31 The GPIO which has changed state -.br - -.br -edge 0-2 0 = change to low (a falling edge) -.br - 1 = change to high (a rising edge) -.br - 2 = no level change (a watchdog timeout) -.br - -.br -tick 32 bit The number of microseconds since boot -.br - WARNING: this wraps around from -.br - 4294967295 to 0 roughly every 72 minutes -.br - -.br -userdata pointer Pointer to an arbitrary object -.br - -.EE - -.IP "\fBint callback_cancel(unsigned callback_id)\fP" -.IP "" 4 -This function cancels a callback identified by its id. - -.br - -.br - -.EX -callback_id: >=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise pigif_callback_not_found. - -.IP "\fBint wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)\fP" -.IP "" 4 -This function waits for an edge on the GPIO for up to timeout -seconds. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -user_gpio: 0-31. -.br - edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. -.br - timeout: >=0. -.br - -.EE - -.br - -.br -The function returns when the edge occurs or after the timeout. - -.br - -.br -Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a \fBcallback\fP function. - -.br - -.br -The function returns 1 if the edge occurred, otherwise 0. - -.IP "\fBint bsc_xfer(int pi, bsc_xfer_t *bscxfer)\fP" -.IP "" 4 -This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. - -.br - -.br -This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. - -.br - -.br -This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. - -.br - -.br -The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. - -.br - -.br -I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. - -.br - -.br -The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -bscxfer: a structure defining the transfer. -.br - -.br -typedef struct -.br -{ -.br - uint32_t control; // Write -.br - int rxCnt; // Read only -.br - char rxBuf[BSC_FIFO_SIZE]; // Read only -.br - int txCnt; // Write -.br - char txBuf[BSC_FIFO_SIZE]; // Write -.br -} bsc_xfer_t; -.br - -.EE - -.br - -.br -To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. - -.br - -.br -Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. - -.br - -.br -The returned function value is the status of the transfer (see below). - -.br - -.br -If there was an error the status will be less than zero -(and will contain the error code). - -.br - -.br -The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). - -.br - -.br -Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. - -.br - -.br -GPIO used for models other than those based on the BCM2711. - -.br - -.br - SDA SCL MOSI SCLK MISO CE -.br -I2C 18 19 - - - - -.br -SPI - - 18 19 20 21 -.br - -.br - -.br -GPIO used for models based on the BCM2711 (e.g. the Pi4B). - -.br - -.br - SDA SCL MOSI SCLK MISO CE -.br -I2C 10 11 - - - - -.br -SPI - - 10 11 9 8 -.br - -.br - -.br -When a zero control word is received the used GPIO will be reset -to INPUT mode. - -.br - -.br -control consists of the following bits. - -.br - -.br - -.EX -22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN -.br - -.EE - -.br - -.br -Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. - -.br - -.br -aaaaaaa defines the I2C slave address (only relevant in I2C mode) -.br -IT invert transmit status flags -.br -HC enable host control -.br -TF enable test FIFO -.br -IR invert receive status flags -.br -RE enable receive -.br -TE enable transmit -.br -BK abort operation and clear FIFOs -.br -EC send control register as first I2C byte -.br -ES send status register as first I2C byte -.br -PL set SPI polarity high -.br -PH set SPI phase high -.br -I2 enable I2C mode -.br -SP enable SPI mode -.br -EN enable BSC peripheral -.br - -.br - -.br -The returned status has the following format - -.br - -.br - -.EX -20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - S S S S S R R R R R T T T T T RB TE RF TF RE TB -.br - -.EE - -.br - -.br -Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. - -.br - -.br -SSSSS number of bytes successfully copied to transmit FIFO -.br -RRRRR number of bytes in receieve FIFO -.br -TTTTT number of bytes in transmit FIFO -.br -RB receive busy -.br -TE transmit FIFO empty -.br -RF receive FIFO full -.br -TF transmit FIFO full -.br -RE receive FIFO empty -.br -TB transmit busy -.br - -.br - -.br -The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. - -.br - -.br -\fBExample\fP -.br - -.EX -bsc_xfer_t xfer; -.br - -.br -xfer.control = (0x13<<16) | 0x305; -.br - -.br -memcpy(xfer.txBuf, "ABCD", 4); -.br -xfer.txCnt = 4; -.br - -.br -status = bsc_xfer(pi, &xfer); -.br - -.br -if (status >= 0) -.br -{ -.br - // process transfer -.br -} -.br - -.EE - -.IP "\fBint bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)\fP" -.IP "" 4 -This function allows the Pi to act as a slave I2C device. - -.br - -.br -This function is not available on the BCM2711 (e.g.as -used in the Pi4B). - -.br - -.br -The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -i2c_addr: 0-0x7F. -.br - bscxfer: a structure defining the transfer. -.br - -.br -typedef struct -.br -{ -.br - uint32_t control; // N/A -.br - int rxCnt; // Read only -.br - char rxBuf[BSC_FIFO_SIZE]; // Read only -.br - int txCnt; // Write -.br - char txBuf[BSC_FIFO_SIZE]; // Write -.br -} bsc_xfer_t; -.br - -.EE - -.br - -.br -txCnt is set to the number of bytes to be transmitted, possibly -zero. The data itself should be copied to txBuf. - -.br - -.br -Any received data will be written to rxBuf with rxCnt set. - -.br - -.br -See \fBbsc_xfer\fP for details of the returned status value. - -.br - -.br -If there was an error the status will be less than zero -(and will contain the error code). - -.br - -.br -Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. - -.IP "\fBint event_callback(int pi, unsigned event, evtCBFunc_t f)\fP" -.IP "" 4 -This function initialises an event callback. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -event: 0-31. -.br - f: the callback function. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the event id, and tick, whenever the -event occurs. - -.IP "\fBint event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)\fP" -.IP "" 4 -This function initialises an event callback. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - event: 0-31. -.br - f: the callback function. -.br -userdata: a pointer to arbitrary user data. -.br - -.EE - -.br - -.br -The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. - -.br - -.br -The callback is called with the event id, the tick, and the userdata -pointer whenever the event occurs. - -.IP "\fBint event_callback_cancel(unsigned callback_id)\fP" -.IP "" 4 -This function cancels an event callback identified by its id. - -.br - -.br - -.EX -callback_id: >=0, as returned by a call to \fBevent_callback\fP or -.br -\fBevent_callback_ex\fP. -.br - -.EE - -.br - -.br -The function returns 0 if OK, otherwise pigif_callback_not_found. - -.IP "\fBint wait_for_event(int pi, unsigned event, double timeout)\fP" -.IP "" 4 -This function waits for an event for up to timeout seconds. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br - event: 0-31. -.br -timeout: >=0. -.br - -.EE - -.br - -.br -The function returns when the event occurs or after the timeout. - -.br - -.br -The function returns 1 if the event occurred, otherwise 0. - -.IP "\fBint event_trigger(int pi, unsigned event)\fP" -.IP "" 4 -This function signals the occurrence of an event. - -.br - -.br - -.EX - pi: >=0 (as returned by \fBpigpio_start\fP). -.br -event: 0-31. -.br - -.EE - -.br - -.br -Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - -.br - -.br -An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling \fBevent_callback\fP) will be informed by -a callback. - -.br - -.br -One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. - -.br - -.br -The meaning of other events is arbitrary. - -.br - -.br -Note that other than its id and its tick there is no data associated -with an event. -.SH PARAMETERS - -.br - -.br - -.IP "\fBactive\fP: 0-1000000" 0 - -.br - -.br -The number of microseconds level changes are reported for once -a noise filter has been triggered (by \fBsteady\fP microseconds of -a stable level). - -.br - -.br - -.IP "\fB*addrStr\fP" 0 -A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. - -.br - -.br - -.IP "\fBarg1\fP" 0 -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBarg2\fP" 0 -An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. - -.br - -.br - -.IP "\fBargc\fP" 0 -The count of bytes passed to a user customised function. - -.br - -.br - -.IP "\fB*argx\fP" 0 -A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. - -.br - -.br - -.IP "\fBbaud\fP" 0 -The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. - -.br - -.br - -.IP "\fBbit\fP" 0 -A value of 0 or 1. - -.br - -.br - -.IP "\fBbits\fP" 0 -A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. - -.br - -.br -A convenient way to set bit n is to or in (1<=0, as returned by a call to a callback function, one of - -.br - -.br -\fBcallback\fP -.br -\fBcallback_ex\fP -.br -\fBevent_callback\fP -.br -\fBevent_callback_ex\fP - -.br - -.br -The id is passed to \fBcallback_cancel\fP or \fBevent_callback_cancel\fP -to cancel the callback. - -.br - -.br - -.IP "\fBCBFunc_t\fP" 0 - -.EX -typedef void (*CBFunc_t) -.br - (int pi, unsigned user_gpio, unsigned level, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBCBFuncEx_t\fP" 0 - -.EX -typedef void (*CBFuncEx_t) -.br - (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata); -.br - -.EE - -.br - -.br - -.IP "\fBchar\fP" 0 -A single character, an 8 bit quantity able to store 0-255. - -.br - -.br - -.IP "\fBclkfreq\fP: 4689-250M (13184-375M for the BCM2711)" 0 -The hardware clock frequency. - -.br - -.br - -.IP "\fBcount\fP" 0 -The number of bytes to be transferred in a file, I2C, SPI, or serial -command. - -.br - -.br - -.IP "\fBCS\fP" 0 -The GPIO used for the slave select signal when bit banging SPI. - -.br - -.br - -.IP "\fBdata_bits\fP: 1-32" 0 -The number of data bits in each character of serial data. - -.br - -.br - -.EX -#define PI_MIN_WAVE_DATABITS 1 -.br -#define PI_MAX_WAVE_DATABITS 32 -.br - -.EE - -.br - -.br - -.IP "\fBdouble\fP" 0 -A floating point number. - -.br - -.br - -.IP "\fBdutycycle\fP: 0-range" 0 -A number representing the ratio of on time to off time for PWM. - -.br - -.br -The number may vary between 0 and range (default 255) where -0 is off and range is fully on. - -.br - -.br - -.IP "\fBedge\fP" 0 -Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. - -.br - -.br - -.EX -RISING_EDGE 0 -.br -FALLING_EDGE 1 -.br -EITHER_EDGE. 2 -.br - -.EE - -.br - -.br - -.IP "\fBerrnum\fP" 0 -A negative number indicating a function call failed and the nature -of the error. - -.br - -.br - -.IP "\fBevent\fP: 0-31" 0 -An event is a signal used to inform one or more consumers -to start an action. - -.br - -.br - -.IP "\fBevtCBFunc_t\fP" 0 - -.br - -.br - -.EX -typedef void (*evtCBFunc_t) -.br - (int pi, unsigned event, uint32_t tick); -.br - -.EE - -.br - -.br - -.IP "\fBevtCBFuncEx_t\fP" 0 - -.br - -.br - -.EX -typedef void (*evtCBFuncEx_t) -.br - (int pi, unsigned event, uint32_t tick, void *userdata); -.br - -.EE - -.br - -.br - -.IP "\fBf\fP" 0 -A function. - -.br - -.br - -.IP "\fB*file\fP" 0 -A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. - -.br - -.br - -.IP "\fB*fpat\fP" 0 -A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. - -.br - -.br - -.IP "\fBfrequency\fP: >=0" 0 -The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. - -.br - -.br - -.IP "\fBgpio\fP" 0 -A Broadcom numbered GPIO, in the range 0-53. - -.br - -.br -There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through -GPIO53. - -.br - -.br -They are split into two banks. Bank 1 consists of GPIO0 through -GPIO31. Bank 2 consists of GPIO32 through GPIO53. - -.br - -.br -All the GPIO which are safe for the user to read and write are in -bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards -have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26. - -.br - -.br -See \fBget_hardware_revision\fP. - -.br - -.br -The user GPIO are marked with an X in the following table. - -.br - -.br - -.EX - 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -.br -Type 1 X X - - X - - X X X X X - - X X -.br -Type 2 - - X X X - - X X X X X - - X X -.br -Type 3 X X X X X X X X X X X X X X -.br - -.br - 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 -.br -Type 1 - X X - - X X X X X - - - - - - -.br -Type 2 - X X - - - X X X X - X X X X X -.br -Type 3 X X X X X X X X X X X X - - - - -.br - -.EE - -.br - -.br - -.IP "\fBgpioPulse_t\fP" 0 - -.EX -typedef struct -.br -{ -.br - uint32_t gpioOn; -.br - uint32_t gpioOff; -.br - uint32_t usDelay; -.br -} gpioPulse_t; -.br - -.EE - -.br - -.br - -.IP "\fBgpioThreadFunc_t\fP" 0 - -.EX -typedef void *(gpioThreadFunc_t) (void *); -.br - -.EE - -.br - -.br - -.IP "\fBhandle\fP: >=0" 0 -A number referencing an object opened by one of - -.br - -.br -\fBfile_open\fP -.br -\fBi2c_open\fP -.br -\fBnotify_open\fP -.br -\fBserial_open\fP -.br -\fBspi_open\fP - -.br - -.br - -.IP "\fBi2c_addr\fP: 0-0x7F" 0 -The address of a device on the I2C bus. - -.br - -.br - -.IP "\fBi2c_bus\fP: >=0" 0 -An I2C bus number. - -.br - -.br - -.IP "\fBi2c_flags\fP: 0" 0 -Flags which modify an I2C open command. None are currently defined. - -.br - -.br - -.IP "\fBi2c_reg\fP: 0-255" 0 -A register of an I2C device. - -.br - -.br - -.IP "\fB*inBuf\fP" 0 -A buffer used to pass data to a function. - -.br - -.br - -.IP "\fBinLen\fP" 0 -The number of bytes of data in a buffer. - -.br - -.br - -.IP "\fBint\fP" 0 -A whole number, negative or positive. - -.br - -.br - -.IP "\fBint32_t\fP" 0 -A 32-bit signed value. - -.br - -.br - -.IP "\fBinvert\fP" 0 -A flag used to set normal or inverted bit bang serial data level logic. - -.br - -.br - -.IP "\fBlevel\fP" 0 -The level of a GPIO. Low or High. - -.br - -.br - -.EX -PI_OFF 0 -.br -PI_ON 1 -.br - -.br -PI_CLEAR 0 -.br -PI_SET 1 -.br - -.br -PI_LOW 0 -.br -PI_HIGH 1 -.br - -.EE - -.br - -.br -There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See \fBset_watchdog\fP. - -.br - -.br - -.EX -PI_TIMEOUT 2 -.br - -.EE - -.br - -.br - -.IP "\fBMISO\fP" 0 -The GPIO used for the MISO signal when bit banging SPI. - -.br - -.br - -.IP "\fBmode\fP" 0 -1. The operational mode of a GPIO, normally INPUT or OUTPUT. - -.br - -.br - -.EX -PI_INPUT 0 -.br -PI_OUTPUT 1 -.br -PI_ALT0 4 -.br -PI_ALT1 5 -.br -PI_ALT2 6 -.br -PI_ALT3 7 -.br -PI_ALT4 3 -.br -PI_ALT5 2 -.br - -.EE - -.br - -.br -2. The mode of waveform transmission. - -.br - -.br - -.EX -PI_WAVE_MODE_ONE_SHOT 0 -.br -PI_WAVE_MODE_REPEAT 1 -.br -PI_WAVE_MODE_ONE_SHOT_SYNC 2 -.br -PI_WAVE_MODE_REPEAT_SYNC 3 -.br - -.EE - -.br - -.br -3. A file open mode. - -.br - -.br - -.EX -PI_FILE_READ 1 -.br -PI_FILE_WRITE 2 -.br -PI_FILE_RW 3 -.br - -.EE - -.br - -.br -The following values can be or'd into the mode. - -.br - -.br - -.EX -PI_FILE_APPEND 4 -.br -PI_FILE_CREATE 8 -.br -PI_FILE_TRUNC 16 -.br - -.EE - -.br - -.br - -.IP "\fBMOSI\fP" 0 -The GPIO used for the MOSI signal when bit banging SPI. - -.br - -.br - -.IP "\fBnumBytes\fP" 0 -The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. - -.br - -.br - -.IP "\fBnumPar\fP: 0-10" 0 -The number of parameters passed to a script. - -.br - -.br - -.IP "\fBnumPulses\fP" 0 -The number of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBoffset\fP" 0 -The associated data starts this number of microseconds from the start of -the waveform. - -.br - -.br - -.IP "\fB*outBuf\fP" 0 -A buffer used to return data from a function. - -.br - -.br - -.IP "\fBoutLen\fP" 0 -The size in bytes of an output buffer. - -.br - -.br - -.IP "\fBpad\fP: 0-2" 0 -A set of GPIO which share common drivers. - -.br - -.br -Pad GPIO -.br -0 0-27 -.br -1 28-45 -.br -2 46-53 -.br - -.br - -.br - -.IP "\fBpadStrength\fP: 1-16" 0 -The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. - -.br - -.br - -.IP "\fB*param\fP" 0 -An array of script parameters. - -.br - -.br - -.IP "\fBpercent\fP: 0-100" 0 -The size of waveform as percentage of maximum available. - -.br - -.br - -.IP "\fBpi\fP" 0 -An integer defining a connected Pi. The value is returned by -\fBpigpio_start\fP upon success. - -.br - -.br - -.IP "\fB*portStr\fP" 0 -A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. - -.br - -.br - -.IP "\fB*pth\fP" 0 -A thread identifier, returned by \fBstart_thread\fP. - -.br - -.br - -.br - -.br - -.IP "\fBpthread_t\fP" 0 -A thread identifier. - -.br - -.br - -.IP "\fBpud\fP: 0-2" 0 -The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. - -.EX -PI_PUD_OFF 0 -.br -PI_PUD_DOWN 1 -.br -PI_PUD_UP 2 -.br - -.EE - -.br - -.br - -.IP "\fBpulseLen\fP" 0 -1-100, the length of a trigger pulse in microseconds. - -.br - -.br - -.IP "\fB*pulses\fP" 0 -An array of pulses to be added to a waveform. - -.br - -.br - -.IP "\fBpulsewidth\fP: 0, 500-2500" 0 - -.EX -PI_SERVO_OFF 0 -.br -PI_MIN_SERVO_PULSEWIDTH 500 -.br -PI_MAX_SERVO_PULSEWIDTH 2500 -.br - -.EE - -.br - -.br - -.IP "\fBPWMduty\fP: 0-1000000 (1M)" 0 -The hardware PWM dutycycle. - -.br - -.br - -.EX -#define PI_HW_PWM_RANGE 1000000 -.br - -.EE - -.br - -.br - -.IP "\fBPWMfreq\fP: 1-125M (1-187.5M for the BCM2711)" 0 -The hardware PWM frequency. - -.br - -.br - -.EX -#define PI_HW_PWM_MIN_FREQ 1 -.br -#define PI_HW_PWM_MAX_FREQ 125000000 -.br -#define PI_HW_PWM_MAX_FREQ_2711 187500000 -.br - -.EE - -.br - -.br - -.IP "\fBrange\fP: 25-40000" 0 -The permissible dutycycle values are 0-range. - -.br - -.br - -.EX -PI_MIN_DUTYCYCLE_RANGE 25 -.br -PI_MAX_DUTYCYCLE_RANGE 40000 -.br - -.EE - -.br - -.br - -.IP "\fB*retBuf\fP" 0 -A buffer to hold a number of bytes returned to a used customised function, - -.br - -.br - -.IP "\fBretMax\fP" 0 -The maximum number of bytes a user customised function should return. - -.br - -.br - -.br - -.br - -.IP "\fB*rxBuf\fP" 0 -A pointer to a buffer to receive data. - -.br - -.br - -.IP "\fBSCL\fP" 0 -The user GPIO to use for the clock when bit banging I2C. - -.br - -.br - -.IP "\fBSCLK\fP" 0 -The GPIO used for the SCLK signal when bit banging SPI. - -.br - -.br - -.IP "\fB*script\fP" 0 -A pointer to the text of a script. - -.br - -.br - -.IP "\fBscript_id\fP" 0 -An id of a stored script as returned by \fBstore_script\fP. - -.br - -.br - -.IP "\fB*scriptName\fP" 0 -The name of a \fBshell_\fP script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. - -.br - -.br - -.IP "\fB*scriptString\fP" 0 -The string to be passed to a \fBshell_\fP script to be executed. - -.br - -.br - -.IP "\fBSDA\fP" 0 -The user GPIO to use for data when bit banging I2C. - -.br - -.br - -.IP "\fBseconds\fP" 0 -The number of seconds. - -.br - -.br - -.IP "\fBseekFrom\fP" 0 - -.br - -.br - -.EX -PI_FROM_START 0 -.br -PI_FROM_CURRENT 1 -.br -PI_FROM_END 2 -.br - -.EE - -.br - -.br - -.IP "\fBseekOffset\fP" 0 -The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). - -.br - -.br - -.IP "\fBser_flags\fP" 0 -Flags which modify a serial open command. None are currently defined. - -.br - -.br - -.IP "\fB*ser_tty\fP" 0 -The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. - -.br - -.br - -.IP "\fBsize_t\fP" 0 -A standard type used to indicate the size of an object in bytes. - -.br - -.br - -.IP "\fBspi_channel\fP" 0 -A SPI channel, 0-2. - -.br - -.br - -.IP "\fBspi_flags\fP" 0 -See \fBspi_open\fP and \fBbb_spi_open\fP. - -.br - -.br - -.IP "\fBsteady\fP: 0-300000" 0 - -.br - -.br -The number of microseconds level changes must be stable for -before reporting the level changed (\fBset_glitch_filter\fP) or triggering -the active part of a noise filter (\fBset_noise_filter\fP). - -.br - -.br - -.IP "\fBstop_bits\fP: 2-8" 0 -The number of (half) stop bits to be used when adding serial data -to a waveform. - -.br - -.br - -.EX -#define PI_MIN_WAVE_HALFSTOPBITS 2 -.br -#define PI_MAX_WAVE_HALFSTOPBITS 8 -.br - -.EE - -.br - -.br - -.IP "\fB*str\fP" 0 - An array of characters. - -.br - -.br - -.IP "\fBthread_func\fP" 0 -A function of type gpioThreadFunc_t used as the main function of a -thread. - -.br - -.br - -.IP "\fBtimeout\fP" 0 -A GPIO watchdog timeout in milliseconds. - -.br - -.br - -.EX -PI_MIN_WDOG_TIMEOUT 0 -.br -PI_MAX_WDOG_TIMEOUT 60000 -.br - -.EE - -.br - -.br - -.IP "\fB*txBuf\fP" 0 -An array of bytes to transmit. - -.br - -.br - -.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0 -A 32-bit unsigned value. - -.br - -.br - -.IP "\fBunsigned\fP" 0 -A whole number >= 0. - -.br - -.br - -.IP "\fBuser_gpio\fP" 0 -0-31, a Broadcom numbered GPIO. - -.br - -.br -See \fBgpio\fP. - -.br - -.br - -.IP "\fB*userdata\fP" 0 - -.br - -.br -A pointer to arbitrary user data. This may be used to identify the instance. - -.br - -.br -You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. - -.br - -.br -In the calling function: - -.br - -.br - -.EX -user_type *userdata; -.br -.br -.br -user_type my_userdata; -.br - -.br -userdata = malloc(sizeof(user_type)); -.br -.br -.br -*userdata = my_userdata; -.br - -.EE - -.br - -.br -In the receiving function: - -.br - -.br - -.EX -user_type my_userdata = *(user_type*)userdata; -.br - -.br -free(userdata); -.br - -.EE - -.br - -.br - -.IP "\fBvoid\fP" 0 -Denoting no parameter is required - -.br - -.br - -.IP "\fBwave_add_*\fP" 0 -One of - -.br - -.br -\fBwave_add_new\fP -.br -\fBwave_add_generic\fP -.br -\fBwave_add_serial\fP - -.br - -.br - -.IP "\fBwave_id\fP" 0 -A number representing a waveform created by \fBwave_create\fP. - -.br - -.br - -.IP "\fBwave_send_*\fP" 0 -One of - -.br - -.br -\fBwave_send_once\fP -.br -\fBwave_send_repeat\fP - -.br - -.br - -.IP "\fBwVal\fP: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)" 0 -A 16-bit word value. - -.br - -.br -.SH pigpiod_if2 Error Codes - -.EX - -.br -typedef enum -.br -{ -.br - pigif_bad_send = -2000, -.br - pigif_bad_recv = -2001, -.br - pigif_bad_getaddrinfo = -2002, -.br - pigif_bad_connect = -2003, -.br - pigif_bad_socket = -2004, -.br - pigif_bad_noib = -2005, -.br - pigif_duplicate_callback = -2006, -.br - pigif_bad_malloc = -2007, -.br - pigif_bad_callback = -2008, -.br - pigif_notify_failed = -2009, -.br - pigif_callback_not_found = -2010, -.br - pigif_unconnected_pi = -2011, -.br - pigif_too_many_pis = -2012, -.br -} pigifError_t; -.br - -.br - -.EE - -.SH SEE ALSO - -pigpiod(1), pig2vcd(1), pigs(1), pigpio(3), pigpiod_if(3) -.SH AUTHOR - -joan@abyz.me.uk diff --git a/DOC/MAN/pigs.1 b/DOC/MAN/pigs.1 deleted file mode 100644 index 9b6192c..0000000 --- a/DOC/MAN/pigs.1 +++ /dev/null @@ -1,6331 +0,0 @@ - -." Process this file with -." groff -man -Tascii foo.1 -." -.TH pigs 1 2012-2020 Linux "pigpio archive" -.SH NAME -pigs - command line socket access to the pigpio daemon. - -/dev/pigpio - command line pipe access to the pigpio daemon. - -.SH SYNOPSIS - -.B sudo pigpiod - -then - -.B pigs {command}+ - -or - -.B "echo {command}+ >/dev/pigpio" - -.SH DESCRIPTION - -.ad l - -.nh - - -.br -The socket and pipe interfaces allow control of the Pi's GPIO by -passing messages to the running pigpio library. - -.br -The normal way to start the pigpio library would be as a daemon during boot. - -.br - -.EX -sudo pigpiod -.br - -.EE - -.br -.SS Features -.br -o hardware timed PWM on any of GPIO 0-31 - -.br -o hardware timed servo pulses on any of GPIO 0-31 - -.br -o reading/writing all of the GPIO in a bank as one operation - -.br -o individually setting GPIO modes, reading and writing - -.br -o notifications when any of GPIO 0-31 change state - -.br -o the construction of output waveforms with microsecond timing - -.br -o I2C, SPI, and serial link wrappers - -.br -o creating and running scripts on the pigpio daemon - -.br -.SS GPIO -.br -ALL GPIO are identified by their Broadcom number. - -.br -.SS Usage -.br -pigs is a program and internally uses the socket interface to pigpio -whereas /dev/pigpio uses the pipe interface. - -.br -pigs and the pipe interface share the same commands and are invoked in -a similar fashion from the command line. - -.br -The pigpio library must be running, either by running a program linked -with the library or starting the pigpio daemon (sudo pigpiod). - -.br -pigs {command}+ - -.br -echo "{command}+" >/dev/pigpio - -.br -pigs will show the result of the command on screen. - -.br -The pigs process returns an exit status (which can be displayed with -the command echo $?). - -.br - -.EX -PIGS_OK 0 -.br -PIGS_CONNECT_ERR 255 -.br -PIGS_OPTION_ERR 254 -.br -PIGS_SCRIPT_ERR 253 -.br -.br -.br - -.EE - -.br -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). - -.br -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. - -.br -Several commands may be entered on a line. If present PROC and PARSE must -be the last command on a line. - -.br -E.g. - -.br - -.EX -pigs w 22 1 mils 1000 w 22 0 -.br - -.EE - -.br -is equivalent to - -.br - -.EX -pigs w 22 1 -.br -pigs mils 1000 -.br -pigs w 22 0 -.br - -.EE - -.br -and - -.br - -.EX -echo "m 4 w w 4 0 mils 250 m 4 r r 4" >/dev/pigpio -.br - -.EE - -.br -is equivalent to - -.br - -.EX -echo "m 4 w" >/dev/pigpio -.br -echo "w 4 0" >/dev/pigpio -.br -echo "mils 250" >/dev/pigpio -.br -echo "m 4 r" >/dev/pigpio -.br -echo "r 4" >/dev/pigpio -.br - -.EE - -.br -.SS Notes -.br -The examples from now on will show the pigs interface but the same -commands will also work on the pipe interface. - -.br -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. - -.br -The status/data of each command sent to the pipe interface should -be read from /dev/pigout. - -.br -When a command takes a number as a parameter it may be entered as hex -(precede by 0x), octal (precede by 0), or decimal. - -.br -E.g. 23 is 23 decimal, 0x100 is 256 decimal, 070 is 56 decimal. - -.br -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. - -.br -E.g. assuming the transmitted serial data is the letters ABCDEONM - -.br - -.EX -$ pigs slr 4 100 -.br -8 65 66 67 68 69 79 78 77 -.br - -.br -$ pigs -a slr 4 100 -.br -8 ABCDEONM -.br - -.br -$ pigs -x slr 4 100 -.br -8 41 42 43 44 45 4f 4e 4d -.br - -.EE - -.br - -.SH OVERVIEW -.SS BASIC -.B M/MODES g m -Set GPIO mode -.P -.B MG/MODEG g -Get GPIO mode -.P -.B PUD g p -Set GPIO pull up/down -.P -.B R/READ g -Read GPIO level -.P -.B W/WRITE g L -Write GPIO level -.P -.SS PWM (overrides servo commands on same GPIO) -.B P/PWM u v -Set GPIO PWM value -.P -.B PFS u v -Set GPIO PWM frequency -.P -.B PRS u v -Set GPIO PWM range -.P -.B GDC u -Get GPIO PWM dutycycle -.P -.B PFG u -Get GPIO PWM frequency -.P -.B PRG u -Get GPIO PWM range -.P -.B PRRG u -Get GPIO PWM real range -.P -.SS Servo (overrides PWM commands on same GPIO) -.B S/SERVO u v -Set GPIO servo pulsewidth -.P -.B GPW u -Get GPIO servo pulsewidth -.P -.SS INTERMEDIATE -.B TRIG u pl L -Send a trigger pulse -.P -.B WDOG u v -Set GPIO watchdog -.P -.B BR1 -Read bank 1 GPIO -.P -.B BR2 -Read bank 2 GPIO -.P -.B BC1 bits -Clear specified GPIO in bank 1 -.P -.B BC2 bits -Clear specified GPIO in bank 2 -.P -.B BS1 bits -Set specified GPIO in bank 1 -.P -.B BS2 bits -Set specified GPIO in bank 2 -.P -.SS ADVANCED -.B NO -Request a notification -.P -.B NC h -Close notification -.P -.B NB h bits -Start notification -.P -.B NP h -Pause notification -.P -.B HC g cf -Set hardware clock frequency -.P -.B HP g pf pdc -Set hardware PWM frequency and dutycycle -.P -.B FG u stdy -Set a glitch filter on a GPIO -.P -.B FN u stdy actv -Set a noise filter on a GPIO -.P -.B PADS pad padma -Set pad drive strength -.P -.B PADG pad -Get pad drive strength -.P -.B SHELL name str -Execute a shell command -.P -.SS Custom -.B CF1 uvs -Custom function 1 -.P -.B CF2 uvs -Custom function 2 -.P -.SS Events -.B EVM h bits -Set events to monitor -.P -.B EVT event -Trigger event -.P -.SS Scripts -.B PROC t -Store script -.P -.B PROCR sid pars -Run script -.P -.B PROCU sid pars -Set script parameters -.P -.B PROCP sid -Get script status and parameters -.P -.B PROCS sid -Stop script -.P -.B PROCD sid -Delete script -.P -.B PARSE t -Validate script -.P -.SS I2C -.B I2CO ib id if -Open I2C bus and device with flags -.P -.B I2CC h -Close I2C handle -.P -.B I2CWQ h bit -smb Write Quick: write bit -.P -.B I2CRS h -smb Read Byte: read byte -.P -.B I2CWS h bv -smb Write Byte: write byte -.P -.B I2CRB h r -smb Read Byte Data: read byte from register -.P -.B I2CWB h r bv -smb Write Byte Data: write byte to register -.P -.B I2CRW h r -smb Read Word Data: read word from register -.P -.B I2CWW h r wv -smb Write Word Data: write word to register -.P -.B I2CRK h r -smb Read Block Data: read data from register -.P -.B I2CWK h r bvs -smb Write Block Data: write data to register -.P -.B I2CWI h r bvs -smb Write I2C Block Data -.P -.B I2CRI h r num -smb Read I2C Block Data: read bytes from register -.P -.B I2CRD h num -i2c Read device -.P -.B I2CWD h bvs -i2c Write device -.P -.B I2CPC h r wv -smb Process Call: exchange register with word -.P -.B I2CPK h r bvs -smb Block Process Call: exchange data bytes with register -.P -.B I2CZ h bvs -Performs multiple I2C transactions -.P -.SS I2C BIT BANG -.B BI2CO sda scl b -Open bit bang I2C -.P -.B BI2CC sda -Close bit bang I2C -.P -.B BI2CZ sda bvs -I2C bit bang multiple transactions -.P -.SS I2C/SPI SLAVE -.B BSCX bctl bvs -BSC I2C/SPI transfer -.P -.SS SERIAL -.B SERO dev b sef -Open serial device dev at baud b with flags -.P -.B SERC h -Close serial handle -.P -.B SERRB -Read byte from serial handle -.P -.B SERWB h bv -Write byte to serial handle -.P -.B SERR h num -Read bytes from serial handle -.P -.B SERW h bvs -Write bytes to serial handle -.P -.B SERDA h -Check for serial data ready to read -.P -.SS SERIAL BIT BANG (read only) -.B SLRO u b db -Open GPIO for bit bang serial data -.P -.B SLRC u -Close GPIO for bit bang serial data -.P -.B SLRI u v -Sets bit bang serial data logic levels -.P -.B SLR u num -Read bit bang serial data from GPIO -.P -.SS SPI -.B SPIO c b spf -SPI open channel at baud b with flags -.P -.B SPIC h -SPI close handle -.P -.B SPIR h num -SPI read bytes from handle -.P -.B SPIW h bvs -SPI write bytes to handle -.P -.B SPIX h bvs -SPI transfer bytes to handle -.P -.SS SPI BIT BANG -.B BSPIO cs miso mosi sclk b spf -Open bit bang SPI -.P -.B BSPIC cs -Close bit bang SPI -.P -.B BSPIX cs bvs -SPI bit bang transfer -.P -.SS FILES -.B FO file mode -Open a file in mode -.P -.B FC h -Close file handle -.P -.B FR h num -Read bytes from file handle -.P -.B FW h bvs -Write bytes to file handle -.P -.B FS h num from -Seek to file handle position -.P -.B FL pat num -List files which match pattern -.P -.SS WAVES -.B WVCLR -Clear all waveforms -.P -.B WVNEW -Initialise a new waveform -.P -.B WVAG trips -Add generic pulses to waveform -.P -.B WVAS u b db sb o bvs -Add serial data to waveform -.P -.B WVCRE -Create a waveform -.P -.B WVCAP -Create a waveform of fixed size -.P -.B WVDEL wid -Delete selected waveform -.P -.B WVTX wid -Transmits waveform once -.P -.B WVTXM wid wmde -Transmits waveform using mode -.P -.B WVTXR wid -Transmits waveform repeatedly -.P -.B WVCHA bvs -Transmits a chain of waveforms -.P -.B WVTAT -Returns the current transmitting waveform -.P -.B WVBSY -Check if waveform is being transmitted -.P -.B WVHLT -Stop waveform -.P -.B WVSC ws -Get waveform DMA CB stats -.P -.B WVSM ws -Get waveform time stats -.P -.B WVSP ws -Get waveform pulse stats -.P -.SS UTILITIES -.B H/HELP -Display command help -.P -.B HWVER -Get hardware version -.P -.B MICS v -Microseconds delay -.P -.B MILS v -Milliseconds delay -.P -.B PIGPV -Get pigpio library version -.P -.B T/TICK -Get current tick -.P -.SS CONFIGURATION -.B CGI -Configuration get internals -.P -.B CSI v -Configuration set internals -.P - -.SH COMMANDS - -.br - -.IP "\fBBC1 bits\fP - Clear specified GPIO in bank 1" -.IP "" 4 -This command clears (sets low) the GPIO specified by \fBbits\fP in bank 1. -Bank 1 consists of GPIO 0-31. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bc1 0x400010 # clear GPIO 4 (1<<4) and 22 (1<<22) -.br - -.br -$ pigs bc1 32 # clear GPIO 5 (1<<5) -.br --42 -.br -ERROR: no permission to update one or more GPIO -.br - -.EE - -.br - -.IP "\fBBC2 bits\fP - Clear specified GPIO in bank 2" -.IP "" 4 -This command clears (sets low) the GPIO specified by \fBbits\fP in bank 2. -Bank 2 consists of GPIO 32-53. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bc2 0x8000 # clear GPIO 47 (activity LED on A+/B+/Pi2/Pi3) -.br - -.br -$ pigs bc2 1 # clear GPIO 32 (first in bank 2) -.br --42 -.br -ERROR: no permission to update one or more GPIO -.br - -.EE - -.br - -.IP "\fBBI2CC sda\fP - Close bit bang I2C" -.IP "" 4 -This command signals that bit banging I2C on \fBsda\fP (and \fBscl\fP) is no -longer required. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bi2cc 5 -.br - -.EE - -.br - -.IP "\fBBI2CO sda scl b\fP - Open bit bang I2C" -.IP "" 4 -This command signals that GPIO \fBsda\fP and \fBscl\fP are to be used -for bit banging I2C at \fBb\fP baud. - -.br -Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. - -.br -o baud rates as low as 50 -.br -o repeated starts -.br -o clock stretching -.br -o I2C on any pair of spare GPIO - -.br -The baud rate may be between 50 and 500000 bits per second. - -.br -The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - -.br - -.IP "\fBBI2CZ sda bvs\fP - I2C bit bang multiple transactions" -.IP "" 4 -This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of \fBbvs\fP -which contains the concatenated command codes and associated data. - -.br -The following command codes are supported: - -.br - -.EX -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 - -.EE - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br -The address and flags default to 0. The address and flags maintain -their previous value until updated. - -.br -No flags are currently defined. - -.br - -\fBExample\fP -.br - -.EX -Set address 0x53 -.br -start, write 0x32, (re)start, read 6 bytes, stop -.br -Set address 0x1E -.br -start, write 0x03, (re)start, read 6 bytes, stop -.br -Set address 0x68 -.br -start, write 0x1B, (re)start, read 8 bytes, stop -.br -End -.br - -.br -0x04 0x53 -.br -0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x1E -.br -0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 -.br - -.br -0x04 0x68 -.br -0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 -.br - -.br -0x00 -.br - -.EE - -.br - -.IP "\fBBR1 \fP - Read bank 1 GPIO" -.IP "" 4 -This command read GPIO 0-31 (bank 1) and returns the levels as a -32-bit hexadecimal value. - -.br - -\fBExample\fP -.br - -.EX -$ pigs br1 -.br -1001C1CF -.br - -.EE - -.br - -.IP "\fBBR2 \fP - Read bank 2 GPIO" -.IP "" 4 -This command read GPIO 32-53 (bank 2) and returns the levels as a -32-bit hexadecimal value. - -.br - -\fBExample\fP -.br - -.EX -$ pigs br2 -.br -003F0000 -.br - -.EE - -.br - -.IP "\fBBS1 bits\fP - Set specified GPIO in bank 1" -.IP "" 4 -This command sets (sets high) the GPIO specified by \fBbits\fP in bank 1. -Bank 1 consists of GPIO 0-31. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bs1 16 # set GPIO 4 (1<<4) -.br - -.br -$ pigs bs1 1 # set GPIO 1 (1<<0) -.br --42 -.br -ERROR: no permission to update one or more GPIO -.br - -.EE - -.br - -.IP "\fBBS2 bits\fP - Set specified GPIO in bank 2" -.IP "" 4 -This command sets (sets high) the GPIO specified by \fBbits\fP in bank 2. -Bank 2 consists of GPIO 32-53. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bs2 0x40 # set GPIO 38 (enable high current mode A+/B+/Pi2/Pi3) -.br - -.br -$ pigs bs2 1 # set GPIO 32 (first in bank 2) -.br --42 -.br -ERROR: no permission to update one or more GPIO -.br - -.EE - -.br - -.IP "\fBBSCX bctl bvs\fP - BSC I2C/SPI transfer" -.IP "" 4 - -.br -This command performs a BSC I2C/SPI slave transfer as defined by -\fBbctl\fP with data \fBbvs\fP. - -.br -This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. - -.br -This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. - -.br -This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. - -.br -The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. - -.br -I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. - -.br -The command sets the BSC mode and writes any data \fBbvs\fP -to the BSC transmit FIFO. It returns the data count (at least 1 -for the status word), the status word, followed by any data bytes -read from the BSC receive FIFO. - -.br -Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. - -.br -For I2C use a control word of (I2C address << 16) + 0x305. - -.br -E.g. to talk as I2C slave with address 0x13 use 0x130305. - -.br -GPIO used for models other than those based on the BCM2711. - -.br - -.EX - SDA SCL MOSI SCLK MISO CE -I2C 18 19 - - - - -SPI - - 18 19 20 21 - -.EE - -.br -GPIO used for models based on the BCM2711 (e.g. the Pi4B). - -.br - -.EX - SDA SCL MOSI SCLK MISO CE -I2C 10 11 - - - - -SPI - - 10 11 9 8 - -.EE - -.br -When a zero control word is received the used GPIO will be reset -to INPUT mode. - -.br -The control word consists of the following bits. - -.br - -.EX -22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN -.br - -.EE - -.br -Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. - -.br - -.EX -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 - -.EE - -.br -The returned status has the following format - -.br - -.EX -20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - S S S S S R R R R R T T T T T RB TE RF TF RE TB -.br - -.EE - -.br -Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. - -.br - -.EX -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 - -.EE - -.br -This example assumes that GPIO 2/3 are connected to GPIO 18/19 -(GPIO 10/11 on the BCM2711). - -.br - -\fBExample\fP -.br - -.EX -$ pigs bscx 0x130305 # start BSC as I2C slave 0x13 -.br -1 18 -.br - -.br -$ i2cdetect -y 1 -.br - 0 1 2 3 4 5 6 7 8 9 a b c d e f -.br -00: -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- -- -.br -20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -.br -70: -- -- -- -- -- -- -- -- -.br - -.br -$ pigs i2co 1 0x13 0 # get handle for device 0x13 on bus 1 -.br -0 -.br - -.br -$ pigs i2cwd 0 90 87 51 9 23 # write 5 bytes -.br - -.br -$ pigs bscx 0x130305 # check for data -.br -6 18 90 87 51 9 23 -.br - -.br -$ pigs bscx 0x130305 11 13 15 17 # check for data and send 4 bytes -.br -1 262338 -.br - -.br -$ pigs i2crd 0 4 # read 4 bytes -.br -4 11 13 15 17 -.br - -.br -$ pigs i2cwd 0 90 87 51 9 23 # write 5 bytes -.br -$ pigs bscx 0x130305 11 13 15 17 # check for data and send 4 bytes -.br -6 262338 90 87 51 9 23 -.br - -.br -$ pigs i2crd 0 4 -.br -4 11 13 15 17 -.br - -.br -$ pigs bscx 0x130305 22 33 44 55 66 -.br -1 327938 -.br -$ pigs i2crd 0 5 -.br -5 22 33 44 55 66 -.br - -.EE - -.br - -.IP "\fBBSPIC cs\fP - Close bit bang SPI" -.IP "" 4 - -.br -This command stops bit banging SPI on a set of GPIO -opened with \fBBSPIO\fP. - -.br -The set of GPIO is specifed by \fBcs\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bspic 10 -.br - -.br -$ pigs bspic 10 -.br --142 -.br -ERROR: no bit bang SPI in progress on GPIO -.br - -.EE - -.br - -.IP "\fBBSPIO cs miso mosi sclk b spf\fP - Open bit bang SPI" -.IP "" 4 - -.br -This command starts bit banging SPI on a group of GPIO with slave -select \fBcs\fP, MISO \fBmiso\fP, MOSI \fBmosi\fP, and clock \fBsclk\fP. - -.br -Data will be transferred at baud \fBb\fP bits per second (which may -be set in the range 50-250000). - -.br -The flags \fBspf\fP may be used to modify the default behaviour of -mode 0, active low chip select. - -.br -The flags consists of the least significant 22 bits. - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m -.br - -.EE - -.br -mm defines the SPI mode. - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br -p is 0 if CS is active low (default) and 1 for active high. - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. - -.br -The other bits in flags should be set to zero. - -.br -Upon success 0 is returned. On error a negative status code -will be returned. - -.br -If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bspio 9 11 12 13 50000 0 -.br - -.br -$ pigs bspio 10 11 12 13 50000 0 -.br - -.br -$ pigs bspio 29 19 20 21 50000 0 # GPIO 29 not avaialble on this Pi -.br --41 -.br -ERROR: no permission to update GPIO -.br - -.EE - -.br - -.IP "\fBBSPIX cs bvs\fP - SPI bit bang transfer" -.IP "" 4 - -.br -This command writes bytes \fBbvs\fP to the bit bang SPI device -associated with slave select \fBcs\fP. It returns the same -number of bytes read from the device. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs bspio 5 13 19 12 10000 0 # MCP4251 DAC -.br -$ pigs bspio 6 13 19 12 20000 3 # MCP3008 ADC -.br - -.br -$ pigs bspix 5 0 16 # set DAC to 16 -.br -2 255 255 -.br - -.br -$ pigs bspix 5 12 0 # read back DAC -.br -2 254 16 -.br - -.br -$ pigs bspix 6 1 128 0 # read ADC input 0 -.br -3 0 3 184 # 952 -.br - -.br -$ pigs bspix 5 0 240 # set DAC to 240 -.br -2 255 255 -.br - -.br -$ pigs bspix 5 12 0 # read back DAC -.br -2 254 240 -.br - -.br -$ pigs bspix 6 1 128 0 # read ADC input 0 -.br -3 0 0 63 # 63 -.br - -.br -$ pigs bspix 5 0 128 # set DAC to 128 -.br -2 255 255 -.br - -.br -$ pigs bspix 5 12 0 # read back DAC -.br -2 254 128 -.br - -.br -$ pigs bspix 6 1 128 0 # read ADC input 0 -.br -3 0 1 255 # 511 -.br - -.br -$ pigs bspic 5 # close SPI CS 5 -.br -$ pigs bspic 6 # close SPI CS 6 -.br - -.br -$ pigs bspic 5 # try to close SPI CS 5 again -.br --142 -.br -ERROR: no bit bang SPI in progress on GPIO -.br - -.EE - -.br - -.br - -.IP "\fBCF1 uvs\fP - Custom function 1" -.IP "" 4 - -.br -This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. - -.br - -.IP "\fBCF2 uvs\fP - Custom function 2" -.IP "" 4 - -.br -This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. - -.br - -.IP "\fBCGI \fP - Configuration get internals" -.IP "" 4 -This command returns the value of the internal library -configuration settings. - -.br - -.IP "\fBCSI v\fP - Configuration set internals" -.IP "" 4 -This command sets the value of the internal library -configuration settings to \fBv\fP. - -.br - -.IP "\fBEVM h bits\fP - Set events to monitor" -.IP "" 4 -This command starts event reporting on handle \fBh\fP (returned by -a prior call to \fBNO\fP). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The notification gets reports for each event specified by \fBbits\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs evm 0 -1 # Shorthand for events 0-31. -.br -$ pigs evm 0 0xf0 # Get notifications for events 4-7. -.br - -.br -$ pigs evm 1 0xf -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBEVT event\fP - Trigger event" -.IP "" 4 -This command triggers event \fBevent\fP. - -.br -One event, number 31, is predefined. This event is -auto generated on BSC slave activity. - -.br - -\fBExample\fP -.br - -.EX -$ pigs evt 12 -.br -$ pigs evt 5 -.br - -.br -$ pigs evt 32 -.br --143 -.br -ERROR: bad event id -.br - -.EE - -.br - -.IP "\fBFC h\fP - Close file handle" -.IP "" 4 -This command closes a file handle \fBh\fP previously opened with \fBFO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fc 0 # First close okay. -.br - -.br -$ pigs fc 0 # Second fails. -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBFG u stdy\fP - Set a glitch filter on a GPIO" -.IP "" 4 - -.br -Level changes on the GPIO \fBu\fP are not reported unless the level -has been stable for at least \fBstdy\fP microseconds. The -level is then reported. Level changes of less than \fBstdy\fP -microseconds are ignored. - -.br -The filter only affects callbacks (including pipe notifications). - -.br -The \fBR/READ\fP, \fBBR1\fP, and \fBBR2\fP commands are not affected. - -.br -Note, each (stable) edge will be timestamped \fBstdy\fP microseconds -after it was first detected. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fg 4 250 -.br - -.br -$ pigs fg 4 1000000 -.br --125 -.br -ERROR: bad filter parameter -.br - -.EE - -.br - -.IP "\fBFL pat num\fP - List files which match pattern" -.IP "" 4 -This command returns a list of the files matching \fBpat\fP. Up -to \fBnum\fP bytes may be returned. - -.br -Upon success the count of returned bytes followed by the matching -files is returned. On error a negative status code will be returned. - -.br -A newline (0x0a) character separates each file name. - -.br -Only files which have a matching entry in /opt/pigpio/access may -be listed. - -.br -Suppose /opt/pigpio/access contains - -.br -/sys/bus/w1/devices/28*/w1_slave r - -.br - -\fBExample\fP -.br - -.EX -$ pigs -a fl "/sys/bus/w1/devices/28*/w1_slave" 5000 -.br -90 /sys/bus/w1/devices/28-000005d34cd2/w1_slave -.br -/sys/bus/w1/devices/28-001414abbeff/w1_slave -.br - -.br -$ pigs -a fl "/sys/bus/*" 5000 -.br -ERROR: no permission to access file -.br --137 -.br - -.EE - -.br - -.IP "\fBFN u stdy actv\fP - Set a noise filter on a GPIO" -.IP "" 4 - -.br -Level changes on the GPIO \fBu\fP are ignored until a level which has -been stable for \fBstdy\fP microseconds is detected. Level -changes on the GPIO are then reported for \fBactv\fP microseconds -after which the process repeats. - -.br -The filter only affects callbacks (including pipe notifications). - -.br -The \fBR/READ\fP, \fBBR1\fP, and \fBBR2\fP commands are not affected. - -.br -Note, level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fn 7 250 1000 -.br - -.br -$ pigs fn 7 2500000 1000 -.br --125 -.br -ERROR: bad filter parameter -.br - -.EE - -.br - -.IP "\fBFO file mode\fP - Open a file in mode" -.IP "" 4 -This function returns a handle to a file \fBfile\fP opened -in a specified mode \fBmode\fP. - -.br -Upon success a handle (>=0) is returned. On error a negative status code -will be returned. - -.br -File - -.br -A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. - -.br -Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. - -.br -Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. - -.br -Suppose /opt/pigpio/access contains the following entries - -.br - -.EX -/home/* n -.br -/home/pi/shared/dir_1/* w -.br -/home/pi/shared/dir_2/* r -.br -/home/pi/shared/dir_3/* u -.br -/home/pi/shared/dir_1/file.txt n -.br - -.EE - -.br -Files may be written in directory dir_1 with the exception -of file.txt. - -.br -Files may be read in directory dir_2. - -.br -Files may be read and written in directory dir_3. - -.br -If a directory allows read, write, or read/write access then files may -be created in that directory. - -.br -In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. - -.br - -.EX -a path containing .. -.br -a path containing only wildcards (*?) -.br -a path containing less than two non-wildcard parts -.br - -.EE - -.br -Mode - -.br -The mode may have the following values. - -.br - -.EX - Value Meaning -READ 1 open file for reading -WRITE 2 open file for writing -RW 3 open file for reading and writing - -.EE - -.br -The following values may be or'd into the mode. - -.br - -.EX - 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 - -.EE - -.br -Newly created files are owned by root with permissions owner read and write. - -.br - -\fBExample\fP -.br - -.EX -$ ls /ram/*.c -.br -/ram/command.c /ram/pigpiod.c /ram/pigs.c -.br -/ram/x_pigpiod_if.c /ram/pig2vcd.c /ram/pigpiod_if2.c -.br -/ram/x_pigpio.c /ram/x_repeat.c /ram/pigpio.c -.br -/ram/pigpiod_if.c /ram/x_pigpiod_if2.c -.br - -.br -# assumes /opt/pigpio/access contains the following line -.br -# /ram/*.c r -.br - -.br -$ pigs fo /ram/pigpio.c 1 -.br -0 -.br - -.br -$ pigs fo /ram/new.c 1 -.br --128 -.br -ERROR: file open failed -.br - -.br -$ pigs fo /ram/new.c 9 -.br -1 -.br - -.br -$ ls /ram/*.c -l -.br --rw-r--r-- 1 joan joan 42923 Jul 10 11:22 /ram/command.c -.br --rw------- 1 root root 0 Jul 10 16:54 /ram/new.c -.br --rw-r--r-- 1 joan joan 2971 Jul 10 11:22 /ram/pig2vcd.c -.br --rw------- 1 joan joan 296235 Jul 10 11:22 /ram/pigpio.c -.br --rw-r--r-- 1 joan joan 9266 Jul 10 11:22 /ram/pigpiod.c -.br --rw-r--r-- 1 joan joan 37331 Jul 10 11:22 /ram/pigpiod_if2.c -.br --rw-r--r-- 1 joan joan 33088 Jul 10 11:22 /ram/pigpiod_if.c -.br --rw-r--r-- 1 joan joan 7990 Jul 10 11:22 /ram/pigs.c -.br --rw-r--r-- 1 joan joan 19970 Jul 10 11:22 /ram/x_pigpio.c -.br --rw-r--r-- 1 joan joan 20804 Jul 10 11:22 /ram/x_pigpiod_if2.c -.br --rw-r--r-- 1 joan joan 19844 Jul 10 11:22 /ram/x_pigpiod_if.c -.br --rw-r--r-- 1 joan joan 19907 Jul 10 11:22 /ram/x_repeat.c -.br - -.EE - -.br - -.IP "\fBFR h num\fP - Read bytes from file handle" -.IP "" 4 -This command returns up to \fBnum\fP bytes of data read from the -file associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fr 0 10 -.br -5 48 49 128 144 255 -.br - -.br -$ pigs fr 0 10 -.br -0 -.br - -.EE - -.br - -.IP "\fBFS h num from\fP - Seek to file handle position" -.IP "" 4 -This command seeks to a position within the file associated -with handle \fBh\fP. - -.br -The number of bytes to move is \fBnum\fP. Positive offsets -move forward, negative offsets backwards. The move start -position is determined by \fBfrom\fP as follows. - -.br - -.EX - From -0 start -1 current position -2 end - -.EE - -.br -Upon success the new byte position within the file (>=0) is -returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fs 0 200 0 # Seek to start of file plus 200 -.br -200 -.br - -.br -$ pigs fs 0 0 1 # Return current position -.br -200 -.br - -.br -$ pigs fs 0 0 2 # Seek to end of file, return size -.br -296235 -.br - -.EE - -.br - -.IP "\fBFW h bvs\fP - Write bytes to file handle" -.IP "" 4 -This command writes bytes \fBbvs\fP to the file -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs fw 0 23 45 67 89 -.br - -.EE - -.br - -.IP "\fBGDC u\fP - Get GPIO PWM dutycycle" -.IP "" 4 - -.br -This command returns the PWM dutycycle in use on GPIO \fBu\fP. - -.br -Upon success the dutycycle is returned. On error a negative -status code will be returned. - -.br -For normal PWM the dutycycle will be out of the defined range -for the GPIO (see \fBPRG\fP). - -.br -If a hardware clock is active on the GPIO the reported -dutycycle will be 500000 (500k) out of 1000000 (1M). - -.br -If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). - -.br - -\fBExample\fP -.br - -.EX -$ pigs p 4 129 -.br -$ pigs gdc 4 -.br -129 -.br - -.br -pigs gdc 5 -.br --92 -.br -ERROR: GPIO is not in use for PWM -.br - -.EE - -.br - -.IP "\fBGPW u\fP - Get GPIO servo pulsewidth" -.IP "" 4 - -.br -This command returns the servo pulsewidth in use on GPIO \fBu\fP. - -.br -Upon success the servo pulsewidth is returned. On error a negative -status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs s 4 1235 -.br -$ pigs gpw 4 -.br -1235 -.br - -.br -$ pigs gpw 9 -.br --93 -.br -ERROR: GPIO is not in use for servo pulses -.br - -.EE - -.br - -.IP "\fBH/HELP \fP - Display command help" -.IP "" 4 -This command displays a brief list of the commands and their parameters. - -.br - -\fBExample\fP -.br - -.EX -$ pigs h -.br - -.br -$ pigs help -.br - -.EE - -.br - -.IP "\fBHC g cf\fP - Set hardware clock frequency" -.IP "" 4 -This command sets the hardware clock associated with GPIO \fBg\fP to -frequency \fBcf\fP. Frequencies above 30MHz are unlikely to work. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs hc 4 5000 # start a 5 KHz clock on GPIO 4 (clock 0) -.br - -.br -$ pigs hc 5 5000000 # start a 5 MHz clcok on GPIO 5 (clock 1) -.br --99 -.br -ERROR: need password to use hardware clock 1 -.br - -.EE - -.br -The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. - -.br -The GPIO must be one of the following. - -.br - -.EX -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) - -.EE - -.br - -.EX -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) - -.EE - -.br -Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. - -.br - -.IP "\fBHP g pf pdc\fP - Set hardware PWM frequency and dutycycle" -.IP "" 4 -This command sets the hardware PWM associated with GPIO \fBg\fP to -frequency \fBpf\fP with dutycycle \fBpdc\fP. Frequencies above 30MHz -are unlikely to work. - -.br -NOTE: Any waveform started by \fBWVTX\fP, \fBWVTXR\fP, or \fBWVCHA\fP -will be cancelled. - -.br -This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -.EX -$ pigs hp 18 100 800000 # 80% dutycycle -.br - -.br -$ pigs hp 19 100 200000 # 20% dutycycle -.br - -.br -$ pigs hp 19 400000000 100000 -.br --96 -.br -ERROR: invalid hardware PWM frequency -.br - -.EE - -.br -The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. - -.br -The GPIO must be one of the following. - -.br - -.EX -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 - -.EE - -.br - -.EX -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 - -.EE - -.br -The actual number of steps beween off and fully on is the -integral part of 250M/\fBpf\fP (375M/\fBpf\fP for the BCM2711). - -.br -The actual frequency set is 250M/steps (375M/steps for the BCM2711). - -.br -There will only be a million steps for a \fBpf\fP of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. \fBpdc\fP is -automatically scaled to take this into account. - -.br - -.IP "\fBHWVER \fP - Get hardware version" -.IP "" 4 -This command returns the hardware revision of the Pi. - -.br -The hardware revision is found in the last 4 characters on the revision -line of /proc/cpuinfo. - -.br -If the hardware revision can not be found or is not a valid hexadecimal -number the command returns 0. - -.br -The revision number can be used to determine the assignment of GPIO -to pins (see \fBg\fP). - -.br -There are currently three types of board. - -.br -Type 1 boards have hardware revision numbers of 2 and 3. - -.br -Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. - -.br -Type 3 boards have hardware revision numbers of 16 or greater. - -.br -for "Revision : 0002" the command returns 2. - -.br -for "Revision : 000f" the command returns 15. - -.br -for "Revision : 000g" the command returns 0. - -.br - -\fBExample\fP -.br - -.EX -$ pigs hwver # On a B+ -.br -16 -.br - -.EE - -.br - -.IP "\fBI2CC h\fP - Close I2C handle" -.IP "" 4 -This command closes an I2C handle \fBh\fP previously opened with \fBI2CO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cc 0 # First close okay. -.br - -.br -$ pigs i2cc 0 # Second fails. -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBI2CO ib id if\fP - Open I2C bus and device with flags" -.IP "" 4 -This command returns a handle to access device \fBid\fP on I2C bus \fBib\fP. -The device is opened with flags \fBif\fP. - -.br -Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. - -.br -The GPIO used are given in the following table. - -.br - -.EX - SDA SCL -I2C 0 0 1 -I2C 1 2 3 - -.EE - -.br -No flags are currently defined. The parameter \fBif\fP should be 0. - -.br -Upon success the next free handle (>=0) is returned. On error a -negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2co 1 0x70 0 # Bus 1, device 0x70, flags 0. -.br -0 -.br - -.br -$ pigs i2co 1 0x53 0 # Bus 1, device 0x53, flags 0. -.br -1 -.br - -.EE - -.br - -.IP "\fBI2CPC h r wv\fP - smb Process Call: exchange register with word" -.IP "" 4 -This command writes \fBwv\fP to register \fBr\fP of the I2C device -associated with handle \fBh\fP and returns a 16-bit word read from the -device. - -.br -Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cpc 0 37 43210 -.br -39933 -.br - -.br -$ pigs i2cpc 0 256 43210 -.br -ERROR: bad i2c/spi/ser parameter -.br --81 -.br - -.EE - -.br - -.IP "\fBI2CPK h r bvs\fP - smb Block Process Call: exchange data bytes with register" -.IP "" 4 - -.br -This command writes the data bytes \fBbvs\fP to register \fBr\fP of the I2C device -associated with handle \fBh\fP and returns a device specific number of bytes. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cpk 0 0 0x11 0x12 -.br -6 0 0 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBI2CRB h r\fP - smb Read Byte Data: read byte from register" -.IP "" 4 - -.br -This command returns a single byte read from register \fBr\fP of the I2C device -associated with handle \fBh\fP. - -.br -Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crb 0 0 -.br -6 -.br - -.EE - -.br - -.IP "\fBI2CRD h num\fP - i2c Read device" -.IP "" 4 - -.br -This command returns \fBnum\fP bytes read from the I2C device associated with -handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br -This command operates on the raw I2C device. The maximum value of the -parameter \fBnum\fP is dependent on the I2C drivers and the device -itself. pigs imposes a limit of about 8000 bytes. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crd 0 16 -.br -16 6 24 0 0 0 0 0 0 0 0 0 0 0 0 32 78 -.br - -.EE - -.br - -.IP "\fBI2CRI h r num\fP - smb Read I2C Block Data: read bytes from register" -.IP "" 4 - -.br -This command returns \fBnum\fP bytes from register \fBr\fP of the I2C device -associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br -The parameter \fBnum\fP may be 1-32. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cri 0 0 16 -.br -16 237 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 -.br - -.EE - -.br - -.IP "\fBI2CRK h r\fP - smb Read Block Data: read data from register" -.IP "" 4 - -.br -This command returns between 1 and 32 bytes read from register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br -The number of bytes of returned data is specific to the device and -register. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crk 0 0 -.br -6 0 0 0 0 0 0 -.br - -.br -$ pigs i2crk 0 1 -.br -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 -.br - -.EE - -.br - -.IP "\fBI2CRS h\fP - smb Read Byte: read byte" -.IP "" 4 - -.br -This command returns a single byte read from the I2C device -associated with handle \fBh\fP. - -.br -Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crs 0 -.br -0 -.br - -.EE - -.br - -.IP "\fBI2CRW h r\fP - smb Read Word Data: read word from register" -.IP "" 4 - -.br -This command returns a single 16 bit word read from register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2crw 0 0 -.br -6150 -.br - -.EE - -.br - -.IP "\fBI2CWB h r bv\fP - smb Write Byte Data: write byte to register" -.IP "" 4 - -.br -This command writes a single byte \fBbv\fP to register \fBr\fP of the -I2C device associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cwb 0 10 0x54 -.br - -.EE - -.br - -.IP "\fBI2CWD h bvs\fP - i2c Write device" -.IP "" 4 - -.br -This command writes a block of bytes \fBbvs\fP to the I2C device -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The number of bytes which may be written in one transaction is -dependent on the I2C drivers and the device itself. pigs imposes -a limit of about 500 bytes. - -.br -This command operates on the raw I2C device. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cwd 0 0x01 0x02 0x03 0x04 -.br - -.EE - -.br - -.IP "\fBI2CWI h r bvs\fP - smb Write I2C Block Data" -.IP "" 4 - -.br -This command writes between 1 and 32 bytes \fBbvs\fP to register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cwi 0 4 0x01 0x04 0xc0 -.br - -.EE - -.br - -.IP "\fBI2CWK h r bvs\fP - smb Write Block Data: write data to register" -.IP "" 4 - -.br -This command writes between 1 and 32 bytes \fBbvs\fP to register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -pigs i2cwk 0 4 0x01 0x04 0xc0 -.br - -.EE - -.br - -.IP "\fBI2CWQ h bit\fP - smb Write Quick: write bit" -.IP "" 4 - -.br -This command writes a single \fBbit\fP to the I2C device associated -with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cwq 0 1 -.br - -.EE - -.br - -.IP "\fBI2CWS h bv\fP - smb Write Byte: write byte" -.IP "" 4 - -.br -This command writes a single byte \fBbv\fP to the I2C device associated -with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cws 0 0x12 -.br - -.br -$ pigs i2cws 0 0xff -.br --82 -.br -ERROR: I2C write failed -.br - -.EE - -.br - -.IP "\fBI2CWW h r wv\fP - smb Write Word Data: write word to register" -.IP "" 4 - -.br -This command writes a single 16 bit word \fBwv\fP to register \fBr\fP of -the I2C device associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs i2cww 0 0 0xffff -.br - -.EE - -.br - -.IP "\fBI2CZ h bvs\fP - Performs multiple I2C transactions" -.IP "" 4 -This command executes a sequence of I2C operations. The -operations to be performed are specified by the contents of \fBbvs\fP -which contains the concatenated command codes and associated data. - -.br -The following command codes are supported: - -.br - -.EX -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 - -.EE - -.br -The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). - -.br -The address defaults to that associated with the handle \fBh\fP. -The flags default to 0. The address and flags maintain their -previous value until updated. - -.br - -\fBExample\fP -.br - -.EX -Set address 0x53, write 0x32, read 6 bytes -.br -Set address 0x1E, write 0x03, read 6 bytes -.br -Set address 0x68, write 0x1B, read 8 bytes -.br -End -.br - -.br -0x04 0x53 0x07 0x01 0x32 0x06 0x06 -.br -0x04 0x1E 0x07 0x01 0x03 0x06 0x06 -.br -0x04 0x68 0x07 0x01 0x1B 0x06 0x08 -.br -0x00 -.br - -.EE - -.br - -.br - -.IP "\fBM/MODES g m\fP - Set GPIO mode" -.IP "" 4 - -.br -This command sets GPIO \fBg\fP to mode \fBm\fP, typically input (read) -or output (write). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -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. - -.br -To set the mode use the code for the mode. - -.br - -.EX -Mode Input Output ALT0 ALT1 ALT2 ALT3 ALT4 ALT5 -Code R W 0 1 2 3 4 5 - -.EE - -.br - -\fBExample\fP -.br - -.EX -$ pigs m 4 r # Input (read) -.br -$ pigs m 4 w # Output (write) -.br -$ pigs m 4 0 # ALT 0 -.br -$ pigs m 4 5 # ALT 5 -.br - -.EE - -.br - -.IP "\fBMG/MODEG g\fP - Get GPIO mode" -.IP "" 4 - -.br -This command returns the current mode of GPIO \fBg\fP. - -.br -Upon success the value of the GPIO mode is returned. -On error a negative status code will be returned. - -.br - -.EX -Value 0 1 2 3 4 5 6 7 -Mode Input Output ALT5 ALT4 ALT0 ALT1 ALT2 ALT3 - -.EE - -.br - -\fBExample\fP -.br - -.EX -$ pigs mg 4 -.br -1 -.br - -.EE - -.br - -.IP "\fBMICS v\fP - Microseconds delay" -.IP "" 4 -This command delays execution for \fBv\fP microseconds. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The main use of this command is expected to be within \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs mics 20 # Delay 20 microseconds. -.br -$ pigs mics 1000000 # Delay 1 second. -.br - -.br -$ pigs mics 2000000 -.br --64 -.br -ERROR: bad MICS delay (too large) -.br - -.EE - -.br - -.IP "\fBMILS v\fP - Milliseconds delay" -.IP "" 4 - -.br -This command delays execution for \fBv\fP milliseconds. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs mils 2000 # Delay 2 seconds. -.br - -.br -$ pigs mils 61000 -.br --65 -.br -ERROR: bad MILS delay (too large) -.br - -.EE - -.br - -.IP "\fBNB h bits\fP - Start notification" -.IP "" 4 - -.br -This command starts notifications on handle \fBh\fP returned by -a prior call to \fBNO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The notification gets state changes for each GPIO specified by \fBbits\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs nb 0 -1 # Shorthand for GPIO 0-31. -.br -$ pigs nb 0 0xf0 # Get notifications for GPIO 4-7. -.br - -.br -$ pigs nb 1 0xf -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBNC h\fP - Close notification" -.IP "" 4 - -.br -This command stops notifications on handle \fBh\fP returned by -a prior call to \fBNO\fP and releases the handle for reuse. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs nc 0 # First call succeeds. -.br - -.br -$ pigs nc 1 # Second call fails. -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBNO \fP - Request a notification" -.IP "" 4 - -.br -This command requests a free notification handle. - -.br -A notification is a method for being notified of GPIO state changes via a pipe. - -.br -Upon success the command returns a handle greater than or equal to zero. -On error a negative status code will be returned. - -.br -Notifications for handle x will be available at the pipe named /dev/pigpiox -(where x is the handle number). - -.br -E.g. if the command returns 15 then the notifications must be read -from /dev/pigpio15. - -.br - -\fBExample\fP -.br - -.EX -$ pigs no -.br -0 -.br - -.EE - -.br - -.IP "\fBNP h\fP - Pause notification" -.IP "" 4 - -.br -This command pauses notifications on handle \fBh\fP returned by -a prior call to \fBNO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -Notifications for the handle are suspended until a new \fBNB\fP command -is given for the handle. - -.br - -\fBExample\fP -.br - -.EX -$ pigs np 0 -.br - -.EE - -.br - -.IP "\fBP/PWM u v\fP - Set GPIO PWM value" -.IP "" 4 - -.br -This command starts PWM on GPIO \fBu\fP with dutycycle \fBv\fP. The dutycycle -varies from 0 (off) to range (fully on). The range defaults to 255. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -This and the servo functionality use the DMA and PWM or PCM peripherals -to control and schedule the pulsewidths and dutycycles. - -.br -The \fBPRS\fP command may be used to change the default range of 255. - -.br - -\fBExample\fP -.br - -.EX -$ pigs p 4 64 # Start PWM on GPIO 4 with 25% dutycycle -.br -$ pigs p 4 128 # 50% -.br -$ pigs p 4 192 # 75% -.br -$ pigs p 4 255 # 100% -.br - -.EE - -.br - -.IP "\fBPADG pad\fP - Get pad drive strength" -.IP "" 4 - -.br -This command gets the \fBpad\fP drive strength \fBpadma\fP in mA. - -.br -Returns the pad drive strength if OK. On error a negative status code -will be returned. - -.br - -.EX -Pad GPIO -0 0-27 -1 28-45 -2 46-53 - -.EE - -.br - -\fBExample\fP -.br - -.EX -$ pigs padg 0 -.br -8 -.br -$ pigs pads 0 16 -.br -$ pigs padg 0 -.br -16 -.br -pigs padg 3 -.br --126 -.br -ERROR: bad pad number -.br - -.EE - -.br - -.IP "\fBPADS pad padma\fP - Set pad drive strength" -.IP "" 4 - -.br -This command sets the \fBpad\fP drive strength \fBpadma\fP in mA. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -.EX -Pad GPIO -0 0-27 -1 28-45 -2 46-53 - -.EE - -.br - -\fBExample\fP -.br - -.EX -$ pigs pads 0 16 -.br -$ pigs padg 0 -.br -16 -.br -$ pigs pads 0 17 -.br --127 -.br -ERROR: bad pad drive strength -.br - -.EE - -.br - -.IP "\fBPARSE t\fP - Validate script" -.IP "" 4 - -.br -Validates the text \fBt\fP of a script without storing the script. - -.br -Upon success nothing is returned. On error a list of detected -script errors will be given. - -.br -See \fBScripts\fP. - -.br -This command may be used to find script syntax faults. - -.br - -\fBExample\fP -.br - -.EX -$ pigs parse tag 100 w 22 1 mils 200 w 22 0 mils 800 jmp 100 -.br - -.br -$ pigs parse tag 0 w 22 1 mills 50 w 22 0 dcr p10 jp 99 -.br -Unknown command: mills -.br -Unknown command: 50 -.br -Bad parameter to dcr -.br -Can't resolve tag 99 -.br - -.EE - -.br - -.IP "\fBPFG u\fP - Get GPIO PWM frequency" -.IP "" 4 - -.br -This command returns the PWM frequency in Hz used for GPIO \fBu\fP. - -.br -Upon success the PWM frequency is returned. On error a negative -status code will be returned. - -.br -For normal PWM the frequency will be that defined for the GPIO -by \fBPFS\fP. - -.br -If a hardware clock is active on the GPIO the reported frequency -will be that set by \fBHC\fP. - -.br -If hardware PWM is active on the GPIO the reported frequency -will be that set by \fBHP\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs pfg 4 -.br -800 -.br - -.br -$ pigs pfg 34 -.br -ERROR: GPIO not 0-31 -.br --2 -.br - -.EE - -.br - -.IP "\fBPFS u v\fP - Set GPIO PWM frequency" -.IP "" 4 -This command sets the PWM frequency \fBv\fP to be used for GPIO \fBu\fP. - -.br -The numerically closest frequency to \fBv\fP will be selected. - -.br -Upon success the new frequency is returned. On error a negative status code -will be returned. - -.br -If PWM is currently active on the GPIO it will be -switched off and then back on at the new frequency. - -.br -Each GPIO can be independently set to one of 18 different PWM -frequencies. - -.br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. - -.br -The frequencies for each sample rate are: - -.br - -.EX - Hertz -.br - -.br - 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 -.br - 1250 1000 800 500 400 250 200 100 50 -.br - -.br - 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 -.br - 625 500 400 250 200 125 100 50 25 -.br - -.br - 4: 10000 5000 2500 2000 1250 1000 625 500 400 -.br - 313 250 200 125 100 63 50 25 13 -.br -sample -.br - rate -.br - (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 -.br - 250 200 160 100 80 50 40 20 10 -.br - -.br - 8: 5000 2500 1250 1000 625 500 313 250 200 -.br - 156 125 100 63 50 31 25 13 6 -.br - -.br - 10: 4000 2000 1000 800 500 400 250 200 160 -.br - 125 100 80 50 40 25 20 10 5 -.br - -.EE - -.br - -\fBExample\fP -.br - -.EX -pigs pfs 4 0 # 0 selects the lowest frequency. -.br -10 -.br - -.br -$ pigs pfs 4 1000 # Set 1000Hz PWM. -.br -1000 -.br - -.br -$ pigs pfs 4 100000 # Very big number selects the highest frequency. -.br -8000 -.br - -.EE - -.br - -.IP "\fBPIGPV \fP - Get pigpio library version" -.IP "" 4 - -.br -This command returns the pigpio library version. - -.br - -\fBExample\fP -.br - -.EX -$ pigs pigpv -.br -17 -.br - -.EE - -.br - -.IP "\fBPRG u\fP - Get GPIO PWM range" -.IP "" 4 - -.br -This command returns the dutycycle range for GPIO \fBu\fP. - -.br -Upon success the range is returned. On error a negative status code -will be returned. - -.br -If a hardware clock or hardware PWM is active on the GPIO the reported -range will be 1000000 (1M). - -.br - -\fBExample\fP -.br - -.EX -$ pigs prg 4 -.br -255 -.br - -.EE - -.br - -.IP "\fBPROC t\fP - Store script" -.IP "" 4 - -.br -This command stores a script \fBt\fP for later execution. - -.br -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. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123 -.br -0 -.br - -.br -$ pigs proc tag 123 w 4 0 mils 5 w 4 1 mils 5 jmp 12 -.br -ERROR: script has unresolved tag -.br --63 -.br - -.EE - -.br - -.IP "\fBPROCD sid\fP - Delete script" -.IP "" 4 - -.br -This command deletes script \fBsid\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs procd 1 -.br - -.br -$ pigs procd 1 -.br -ERROR: unknown script id -.br --48 -.br - -.EE - -.br - -.IP "\fBPROCP sid\fP - Get script status and parameters" -.IP "" 4 - -.br -This command returns the status of script \fBsid\fP as well as the -current value of its 10 parameters. - -.br -Upon success the script status and parameters are returned. -On error a negative status code will be returned. - -.br -The script status may be one of - -.br - -.EX -0 being initialised -1 halted -2 running -3 waiting -4 failed - -.EE - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs procp 0 -.br -1 0 0 0 0 0 0 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBPROCR sid pars\fP - Run script" -.IP "" 4 - -.br -This command runs stored script \fBsid\fP passing it up to 10 optional -parameters. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123 -.br -0 -.br - -.br -$ pigs procr 0 50 # Run script 0 with parameter 0 of 50. -.br - -.br -$ pigs procp 0 -.br -2 44 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -2 37 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -2 10 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -2 5 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -2 2 0 0 0 0 0 0 0 0 0 -.br -$ pigs procp 0 -.br -1 -1 0 0 0 0 0 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBPROCS sid\fP - Stop script" -.IP "" 4 - -.br -This command stops a running script \fBsid\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs procs 0 -.br - -.br -$ pigs procs 1 -.br --48 -.br -ERROR: unknown script id -.br - -.EE - -.br - -.IP "\fBPROCU sid pars\fP - Set script parameters" -.IP "" 4 - -.br -This command sets the parameters of a stored script \fBsid\fP passing -it up to 10 parameters. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -See \fBScripts\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs proc tag 0 hp 18 p0 p1 mils 1000 jmp 0 -.br -0 -.br -$ pigs procu 0 50 500000 -.br -$ pigs procr 0 -.br -$ pigs procu 0 100 -.br -$ pigs procu 0 200 -.br -$ pigs procu 0 200 100000 -.br - -.EE - -.br - -.IP "\fBPRRG u\fP - Get GPIO PWM real range" -.IP "" 4 - -.br -This command returns the real underlying range used by GPIO \fBu\fP. - -.br -If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). - -.br -If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. - -.br -On error a negative status code will be returned. - -.br -See \fBPRS\fP. - -.br - -\fBExample\fP -.br - -.EX -$ pigs prrg 17 -.br -250 -.br - -.br -$ pigs pfs 17 0 -.br -10 -.br -$ pigs prrg 17 -.br -20000 -.br - -.br -$ pigs pfs 17 100000 -.br -8000 -.br -$ pigs prrg 17 -.br -25 -.br - -.EE - -.br - -.IP "\fBPRS u v\fP - Set GPIO PWM range" -.IP "" 4 - -.br -This command sets the dutycycle range \fBv\fP to be used for GPIO \fBu\fP. -Subsequent uses of command \fBP/PWM\fP will use a dutycycle between 0 (off) -and \fBv\fP (fully on). - -.br -Upon success the real underlying range used by the GPIO is returned. -On error a negative status code will be returned. - -.br -If PWM is currently active on the GPIO its dutycycle will be scaled to -reflect the new range. - -.br -The real range, the number of steps between fully off and fully on -for each frequency, is given in the following table. - -.br - -.EX - #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 - -.EE - -.br -The real value set by \fBPRS\fP is (dutycycle * real range) / range. - -.br -See \fBPRRG\fP - -.br - -\fBExample\fP -.br - -.EX -$ pigs prs 18 1000 -.br -250 -.br - -.EE - -.br - -.IP "\fBPUD g p\fP - Set GPIO pull up/down" -.IP "" 4 - -.br -This command sets the internal pull/up down for GPIO \fBg\fP to mode \fBp\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The mode may be pull-down (D), pull-up (U), or off (O). - -.br - -\fBExample\fP -.br - -.EX -$ pigs pud 4 d # Set pull-down on GPIO 4. -.br -$ pigs pud 4 u # Set pull-up on GPIO 4. -.br -$ pigs pud 4 o # No pull-up/down on GPIO 4. -.br - -.EE - -.br - -.IP "\fBR/READ g\fP - Read GPIO level" -.IP "" 4 - -.br -This reads the current level of GPIO \fBg\fP. - -.br -Upon success the current level is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs r 17 # Get level of GPIO 17. -.br -0 -.br - -.br -$ pigs r 4 # Get level of GPIO 4. -.br -1 -.br - -.EE - -.br - -.IP "\fBS/SERVO u v\fP - Set GPIO servo pulsewidth" -.IP "" 4 - -.br -This command starts servo pulses of \fBv\fP microseconds on GPIO \fBu\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The servo pulsewidth may be 0 (off), 500 (most anti-clockwise) -to 2500 (most clockwise). - -.br -The range supported by servos varies and should probably be determined -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. - -.br -You can DAMAGE a servo if you command it to move beyond its limits. - -.br - -\fBExample\fP -.br - -.EX -$ pigs SERVO 17 1500 -.br - -.EE - -.br -This example causes an on pulse of 1500 microseconds duration to be -transmitted on GPIO 17 at a rate of 50 times per second. - -.br -This will command a servo connected to GPIO 17 to rotate to its mid-point. - -.br - -\fBExample\fP -.br - -.EX -pigs s 17 0 # Switch servo pulses off. -.br - -.EE - -.br - -.IP "\fBSERC h\fP - Close serial handle" -.IP "" 4 - -.br -This command closes a serial handle \fBh\fP previously opened with \fBSERO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serc 0 # First close okay. -.br - -.br -$ pigs serc 0 # Second close gives error. -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBSERDA h\fP - Check for serial data ready to read" -.IP "" 4 - -.br -This command returns the number of bytes of data available -to be read from the serial device associated with handle \fBh\fP. - -.br -Upon success the count of bytes available to be read is -returned (which may be 0). On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serda 0 -.br -0 -.br - -.EE - -.br - -.IP "\fBSERO dev b sef\fP - Open serial device dev at baud b with flags" -.IP "" 4 - -.br -This command opens the serial \fBdev\fP at \fBb\fP bits per second. - -.br -No flags are currently defined. \fBsef\fP should be set to zero. - -.br -Upon success a handle (>=0) is returned. On error a negative status code -will be returned. - -.br -The device name must start with /dev/tty or /dev/serial. - -.br - -.br -The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. - -.br - -\fBExample\fP -.br - -.EX -$ pigs sero /dev/ttyAMA0 9600 0 -.br -0 -.br - -.br -$ pigs sero /dev/tty1 38400 0 -.br -1 -.br - -.EE - -.br - -.IP "\fBSERR h num\fP - Read bytes from serial handle" -.IP "" 4 - -.br -This command returns up to \fBnum\fP bytes of data read from the -serial device associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serr 0 10 -.br -5 48 49 128 144 255 -.br - -.br -$ pigs serr 0 10 -.br -0 -.br - -.EE - -.br - -.IP "\fBSERRB \fP - Read byte from serial handle" -.IP "" 4 - -.br -This command returns a byte of data read from the serial -device associated with handle \fBh\fP. - -.br -Upon success a number between 0 and 255 is returned. -On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serrb 0 -.br -23 -.br -$ pigs serrb 0 -.br -45 -.br - -.EE - -.br - -.IP "\fBSERW h bvs\fP - Write bytes to serial handle" -.IP "" 4 - -.br -This command writes bytes \fBbvs\fP to the serial device -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serw 0 23 45 67 89 -.br - -.EE - -.br - -.IP "\fBSERWB h bv\fP - Write byte to serial handle" -.IP "" 4 - -.br -This command writes a single byte \fBbv\fP to the serial device -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs serwb 0 23 -.br -$ pigs serwb 0 0xf0 -.br - -.EE - -.br - -.IP "\fBSHELL name str\fP - Execute a shell command" -.IP "" 4 - -.br -This command uses the system call to execute a shell script \fBname\fP -with the given string \fBstr\fP as its parameter. - -.br -The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. - -.br -\fBname\fP must exist in /opt/pigpio/cgi and must be executable. - -.br -The returned exit status is normally 256 times that set -by the shell script exit function. If the script can't -be found 32512 will be returned. - -.br -The following table gives some example returned statuses. - -.br - -.EX -Script exit status Returned system call status -1 256 -5 1280 -10 2560 -200 51200 -script not found 32512 - -.EE - -.br - -\fBExample\fP -.br - -.EX -# pass two parameters, hello and world -.br -$ pigs shell scr1 hello world -.br -256 -.br - -.br -# pass three parameters, hello, string with spaces, and world -.br -$ pigs shell scr1 "hello 'string with spaces' world" -.br -256 -.br - -.br -# pass one parameter, hello string with spaces world -.br -$ pigs shell scr1 "\"hello string with spaces world\"" -.br -256 -.br - -.br -# non-existent script -.br -$ pigs shell scr78 par1 -.br -32512 -.br - -.EE - -.br - -.IP "\fBSLR u num\fP - Read bit bang serial data from GPIO" -.IP "" 4 - -.br -This command returns up to \fBnum\fP bytes of bit bang serial data -read from GPIO \fBu\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br -The GPIO \fBu\fP should have been initialised with the \fBSLRO\fP command. - -.br -The bytes returned for each character depend upon the number of -data bits \fBdb\fP specified in the \fBSLRO\fP command. - -.br -For \fBdb\fP 1-8 there will be one byte per character. -.br -For \fBdb\fP 9-16 there will be two bytes per character. -.br -For \fBdb\fP 17-32 there will be four bytes per character. - -.br - -\fBExample\fP -.br - -.EX -$ pigs slr 15 20 -.br -6 1 0 23 45 89 0 -.br - -.EE - -.br - -.IP "\fBSLRC u\fP - Close GPIO for bit bang serial data" -.IP "" 4 - -.br -This command closes GPIO \fBu\fP for reading bit bang serial data. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs slrc 23 -.br - -.br -$ pigs slrc 23 -.br --38 -.br -ERROR: no serial read in progress on GPIO -.br - -.EE - -.br - -.IP "\fBSLRI u v\fP - Sets bit bang serial data logic levels" -.IP "" 4 - -.br -This command sets the logic level for reading bit bang serial data -on GPIO \fBu\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The invert parameter \fBv\fP is 1 for inverted signal, 0 for normal. - -.br - -\fBExample\fP -.br - -.EX -$ pigs slri 17 1 # invert logic on GPIO 17 -.br - -.br -$ pigs slri 23 0 # use normal logic on GPIO 23 -.br - -.EE - -.br - -.IP "\fBSLRO u b db\fP - Open GPIO for bit bang serial data" -.IP "" 4 - -.br -This command opens GPIO \fBu\fP for reading bit bang serial data -at \fBb\fP baud and \fBdb\fP data bits. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The baud rate may be between 50 and 250000 bits per second. - -.br -The received data is held in a cyclic buffer. - -.br -It is the user's responsibility to read the data (with \fBSLR\fP) -in a timely fashion. - -.br - -\fBExample\fP -.br - -.EX -$ pigs slro 23 19200 8 -.br - -.br -$ pigs slro 23 19200 8 -.br --50 -.br -ERROR: GPIO already in use -.br - -.EE - -.br - -.IP "\fBSPIC h\fP - SPI close handle" -.IP "" 4 - -.br -This command closes the SPI handle \fBh\fP returned by a prior -call to \fBSPIO\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spic 1 -.br - -.br -$ pigs spic 1 -.br --25 -.br -ERROR: unknown handle -.br - -.EE - -.br - -.IP "\fBSPIO c b spf\fP - SPI open channel at baud b with flags" -.IP "" 4 - -.br -This command returns a handle to a SPI device on channel \fBc\fP. - -.br -Data will be transferred at \fBb\fP bits per second. The flags \fBspf\fP -may be used to modify the default behaviour of 4-wire operation, -mode 0, active low chip select. - -.br -Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps -are unlikely to work. - -.br -The Pi has two SPI peripherals: main and auxiliary. - -.br -The main SPI has two chip selects (channels), the auxiliary has -three. - -.br -The auxiliary SPI is available on all models but the A and B. - -.br -The GPIO used are given in the following table. - -.br - -.EX - MISO MOSI SCLK CE0 CE1 CE2 -Main SPI 9 10 11 8 7 - -Aux SPI 19 20 21 18 17 16 - -.EE - -.br -The flags consists of the least significant 22 bits. - -.br - -.EX -21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -.br - b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m -.br - -.EE - -.br -mm defines the SPI mode. - -.br -Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. - -.br - -.EX -Mode POL PHA -.br - 0 0 0 -.br - 1 0 1 -.br - 2 1 0 -.br - 3 1 1 -.br - -.EE - -.br -px is 0 if CEx is active low (default) and 1 for active high. - -.br -ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. - -.br -A is 0 for the main SPI, 1 for the auxiliary SPI. - -.br -W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main -SPI only. - -.br -nnnn defines the number of bytes (0-15) to write before switching -the MOSI line to MISO to read data. This field is ignored -if W is not set. Main SPI only. - -.br -T is 1 if the least significant bit is transmitted on MOSI first, the -default (0) shifts the most significant bit out first. Auxiliary SPI -only. - -.br -R is 1 if the least significant bit is received on MISO first, the -default (0) receives the most significant bit first. Auxiliary SPI -only. - -.br -bbbbbb defines the word size in bits (0-32). The default (0) -sets 8 bits per word. Auxiliary SPI only. - -.br -The \fBSPIR\fP, \fBSPIW\fP, and \fBSPIX\fP commands transfer data -packed into 1, 2, or 4 bytes according to the word size in bits. - -.br -For bits 1-8 there will be one byte per character. -.br -For bits 9-16 there will be two bytes per character. -.br -For bits 17-32 there will be four bytes per character. - -.br -Multi-byte transfers are made in least significant byte first order. - -.br -E.g. to transfer 32 11-bit words 64 bytes need to be sent. - -.br -E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed -by 0x1A. - -.br -The other bits in flags should be set to zero. - -.br -Upon success a handle (>=0) is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spio 0 100000 3 # Open channel 0 at 100kbps in mode 3. -.br -0 -.br - -.br -$ pigs spio 0 32000 256 # Open channel 0 of auxiliary spi at 32kbps. -.br -1 -.br - -.EE - -.br - -.IP "\fBSPIR h num\fP - SPI read bytes from handle" -.IP "" 4 - -.br -This command returns \fBnum\fP bytes read from the SPI device -associated with handle \fBh\fP. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spir 0 10 # Read 10 bytes from the SPI device. -.br -10 0 0 0 0 0 0 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBSPIW h bvs\fP - SPI write bytes to handle" -.IP "" 4 - -.br -This command writes bytes \fBbvs\fP to the SPI device -associated with handle \fBh\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spiw 0 0x22 0x33 0xcc 0xff -.br - -.EE - -.br - -.IP "\fBSPIX h bvs\fP - SPI transfer bytes to handle" -.IP "" 4 - -.br -This command writes bytes \fBbvs\fP to the SPI device -associated with handle \fBh\fP. It returns the same -number of bytes read from the device. - -.br -Upon success the count of returned bytes followed by the bytes themselves -is returned. On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs spix 0 0x22 0x33 0xcc 0xff -.br -4 0 0 0 0 -.br - -.EE - -.br - -.IP "\fBT/TICK \fP - Get current tick" -.IP "" 4 - -.br -This command returns the current system tick. - -.br -Tick is the number of microseconds since system boot. - -.br -As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, -which is approximately 1 hour 12 minutes. - -.br - -\fBExample\fP -.br - -.EX -$ pigs t mils 1000 t -.br -3691823946 -.br -3692833987 -.br - -.EE - -.br - -.IP "\fBTRIG u pl L\fP - Send a trigger pulse" -.IP "" 4 - -.br -This command sends a trigger pulse of \fBpl\fP microseconds at level \fBL\fP -to GPIO \fBu\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The GPIO is set to not level at the end of the pulse. - -.br - -\fBExample\fP -.br - -.EX -$ pigs trig 4 10 1 -.br - -.br -$ pigs trig 4 51 1 -.br --46 -.br -ERROR: trigger pulse > 50 microseconds -.br - -.EE - -.br - -.IP "\fBW/WRITE g L\fP - Write GPIO level" -.IP "" 4 - -.br -This command sets GPIO \fBg\fP to level \fBL\fP. The level may be 0 -(low, off, clear) or 1 (high, on, set). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs w 23 0 -.br -$ pigs w 23 1 -.br - -.br -$ pigs w 23 2 -.br --5 -.br -ERROR: level not 0-1 -.br - -.EE - -.br - -.IP "\fBWDOG u v\fP - Set GPIO watchdog" -.IP "" 4 - -.br -This command sets a watchdog of \fBv\fP milliseconds on GPIO \fBu\fP. - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br -The watchdog is nominally in milliseconds. - -.br -One watchdog may be registered per GPIO. - -.br -The watchdog may be cancelled by setting timeout to 0. - -.br -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. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wdog 23 90000 -.br --15 -.br -ERROR: timeout not 0-60000 -.br - -.br -$ pigs wdog 23 9000 -.br - -.EE - -.br -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. - -.br - -.IP "\fBWVAG trips\fP - Add generic pulses to waveform" -.IP "" 4 - -.br -This command adds 1 one or more triplets \fBtrips\fP of GPIO on, GPIO off, -delay to the existing waveform (if any). - -.br -Upon success the total number of pulses in the waveform so far is -returned. On error a negative status code will be returned. - -.br -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. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvag 0x10 0x80 1000 0x80 0x10 9000 -.br -2 -.br - -.br -$ pigs wvag 0 0 10000 0x10 0x80 1000 0x80 0x10 9000 -.br -4 -.br - -.EE - -.br - -.IP "\fBWVAS u b db sb o bvs\fP - Add serial data to waveform" -.IP "" 4 - -.br -This command adds a waveform representing serial data \fBbvs\fP to -GPIO \fBu\fP at \fBb\fP baud to the existing waveform (if any). -The serial data starts \fBo\fP microseconds from the start of the -waveform. - -.br -Upon success the total number of pulses in the waveform so far is -returned. On error a negative status code will be returned. - -.br -The serial data is formatted as one start bit, \fBdb\fP data bits, and -\fBsb\fP/2 stop bits. - -.br -The baud rate may be between 50 and 1000000 bits per second. - -.br -It is legal to add serial data streams with different baud rates to -the same waveform. - -.br -The bytes required for each character depend upon \fBdb\fP. - -.br -For \fBdb\fP 1-8 there will be one byte per character. -.br -For \fBdb\fP 9-16 there will be two bytes per character. -.br -For \fBdb\fP 17-32 there will be four bytes per character. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvas 4 9600 8 2 0 0x30 0x31 0x32 0x33 -.br -23 -.br - -.br -$ pigs wvas 7 38400 8 2 0 0x41 0x42 -.br -35 -.br - -.EE - -.br - -.IP "\fBWVTAT \fP - Returns the current transmitting waveform" -.IP "" 4 - -.br -This command returns the id of the waveform currently -being transmitted. - -.br -Returns the waveform id or one of the following special -values: - -.br -9998 - transmitted wave not found -.br -9999 - no wave being transmitted - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvtat -.br -9999 -.br - -.EE - -.br - -.IP "\fBWVBSY \fP - Check if waveform is being transmitted" -.IP "" 4 - -.br -This command checks to see if a waveform is currently being transmitted. - -.br -Returns 1 if a waveform is currently being transmitted, otherwise 0. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvbsy -.br -0 -.br - -.EE - -.br - -.IP "\fBWVCHA bvs\fP - Transmits a chain of waveforms" -.IP "" 4 - -.br -This command transmits a chain of waveforms. - -.br -NOTE: Any hardware PWM started by \fBHP\fP will -be cancelled. - -.br -The waves to be transmitted are specified by the contents of -\fBbvs\fP which contains an ordered list of wave_ids and optional -command codes and related data. - -.br -Upon success 0 is returned. On error a negative status code -will be returned. - -.br -Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. - -.br -A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. - -.br -Delays between waves may be added with the delay command. - -.br -The following command codes are supported: - -.br - -.EX -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 - -.EE - -.br -If present Loop Forever must be the last entry in the chain. - -.br -The code is currently dimensioned to support a chain with roughly -600 entries and 20 loop counters. - -.br - -\fBExample\fP -.br - -.EX -#!/bin/bash -.br - -.br -GPIO=4 -.br -WAVES=5 -.br - -.br -pigs m $GPIO w -.br - -.br -for ((i=0; i<$WAVES; i++)) -.br -do -.br - pigs wvag $((1<=0) is returned. On error a negative status -code will be returned. - -.br -The data provided by the \fBWVAG\fP and \fBWVAS\fP commands is -consumed by this command. - -.br -As many waveforms may be created as there is space available. -The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the -waveform to transmit. - -.br -Normal usage would be - -.br -Step 1. \fBWVCLR\fP to clear all waveforms and added data. - -.br -Step 2. \fBWVAG\fP/\fBWVAS\fP calls to supply the waveform data. - -.br -Step 3. \fBWVCRE\fP to create the waveform and get a unique id. - -.br -Repeat steps 2 and 3 as needed. - -.br -Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit. - -.br -A waveform comprises of one or more pulses. - -.br -A pulse specifies - -.br -1) the GPIO to be switched on at the start of the pulse. -.br -2) the GPIO to be switched off at the start of the pulse. -.br -3) the delay in microseconds before the next pulse. - -.br -Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). - -.br -When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvas 4 9600 0 23 45 67 89 90 -.br -37 -.br -$ pigs wvcre -.br -0 -.br - -.br -$ pigs wvcre -.br --69 -.br -ERROR: attempt to create an empty waveform -.br - -.EE - -.br - -.IP "\fBWVCAP \fP - Create a waveform of fixed size" -.IP "" 4 - -.br -Similar to \fBWVCRE\fP, this command creates a waveform but pads the consumed -resources to a fixed size, specified as a percent of total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. - -.br -Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. - -.br -The data provided by the \fBWVAG\fP and \fBWVAS\fP commands are -consumed by this command. - -.br -As many waveforms may be created as there is space available. -The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the -waveform to transmit. - -.br -Normal usage would be - -.br -Step 1. \fBWVCLR\fP to clear all waveforms and added data. - -.br -Step 2. \fBWVAG\fP/\fBWVAS\fP calls to supply the waveform data. - -.br -Step 3. \fBWVCAP\fP to create a waveform of a uniform size. - -.br -Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit. - -.br -Repeat steps 2 - 4 as needed. - -.br -Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. - -.br - -\fBExample\fP -.br - -.EX -# Create a wave that consumes 50% of the total resource: -.br - -.br -$ pigs wvag 16 0 5000000 0 16 5000000 -.br -2 -.br -$ pigs wvcap 50 -.br -0 -.br -$ pigs wvtx 0 -.br -11918 -.br - -.EE - -.br - -.IP "\fBWVDEL wid\fP - Delete selected waveform" -.IP "" 4 - -.br -This command deletes the waveform with id \fBwid\fP. - -.br -The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. - -.br -- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. - -.br -- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). - -.br -Upon success nothing is returned. On error a negative status code -will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvdel 0 -.br - -.br -$ pigs wvdel 0 -.br --66 -.br -ERROR: non existent wave id -.br - -.EE - -.br - -.IP "\fBWVHLT \fP - Stop waveform" -.IP "" 4 - -.br -This command aborts the transmission of the current waveform. - -.br -Nothing is returned. - -.br -This command is intended to stop a waveform started in the repeat mode. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvhlt -.br - -.EE - -.br - -.IP "\fBWVNEW \fP - Initialise a new waveform" -.IP "" 4 - -.br -This clears any existing waveform data ready for the creation of a new -waveform. - -.br -Nothing is returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvnew -.br - -.EE - -.br - -.IP "\fBWVSC ws\fP - Get waveform DMA CB stats" -.IP "" 4 - -.br -The statistic requested by \fBws\fP is returned. - -.br -\fBws\fP identifies the subcommand as follows. - -.br -0 Get Cbs -.br -1 Get High Cbs -.br -2 Get Max Cbs - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvas 4 9600 0 23 45 67 89 90 -.br -37 -.br - -.br -$ pigs wvsc 0 -.br -74 -.br -$ pigs wvsc 1 -.br -74 -.br -$ pigs wvsc 2 -.br -25016 -.br - -.EE - -.br - -.IP "\fBWVSM ws\fP - Get waveform time stats" -.IP "" 4 - -.br -The statistic requested by \fBws\fP is returned. - -.br -\fBws\fP identifies the subcommand as follows. - -.br -0 Get Micros -.br -1 Get High Micros -.br -2 Get Max Micros - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvsm 0 -.br -5314 -.br -$ pigs wvsm 1 -.br -5314 -.br -$ pigs wvsm 2 -.br -1800000000 -.br - -.EE - -.br - -.IP "\fBWVSP ws\fP - Get waveform pulse stats" -.IP "" 4 - -.br -The statistic requested by \fBws\fP is returned. - -.br -\fBws\fP identifies the subcommand as follows. - -.br -0 Get Pulses -.br -1 Get High Pulses -.br -2 Get Max Pulses - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvsp 0 -.br -37 -.br -$ pigs wvsp 1 -.br -37 -.br -$ pigs wvsp 2 -.br -12000 -.br - -.EE - -.br - -.IP "\fBWVTX wid\fP - Transmits waveform once" -.IP "" 4 - -.br -This command transmits the waveform with id \fBwid\fP once. - -.br -NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. - -.br -Upon success the number of DMA control blocks in the waveform is returned. -On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvtx 1 -.br -75 -.br - -.br -$ pigs wvtx 2 -.br --66 -.br -ERROR: non existent wave id -.br - -.EE - -.br - -.IP "\fBWVTXM wid wmde\fP - Transmits waveform using mode" -.IP "" 4 - -.br -This command transmits the waveform with id \fBwid\fP using mode \fBwmde\fP. - -.br -The mode may be send once (0), send repeatedly (1), send once but -first sync with previous wave (2), or send repeatedly but first -sync with previous wave (3). - -.br -WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. - -.br -NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. - -.br -Upon success the number of DMA control blocks in the waveform is returned. -On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvtxm 1 3 -.br -75 -.br - -.br -$ pigs wvtxm 2 0 -.br --66 -.br -ERROR: non existent wave id -.br - -.EE - -.br - -.IP "\fBWVTXR wid\fP - Transmits waveform repeatedly" -.IP "" 4 - -.br -This command transmits the waveform with id \fBwid\fP repeatedly. - -.br -NOTE: Any hardware PWM started by \fBHP\fP will be cancelled. - -.br -Upon success the number of DMA control blocks in the waveform is returned. -On error a negative status code will be returned. - -.br - -\fBExample\fP -.br - -.EX -$ pigs wvtxr 1 -.br -75 -.br - -.br -$ pigs wvtxr 2 -.br --66 -.br -ERROR: non existent wave id -.br - -.EE - -.br - -.SH PARAMETERS - -.br - -.IP "\fBactv\fP - 0-1000000" 0 - -.br -The number of microseconds level changes are reported for once -a noise filter has been triggered (by \fBstdy\fP microseconds of -a stable level). - -.br - -.IP "\fBb\fP - baud" 0 -The command expects the baud rate in bits per second for -the transmission of serial data (I2C/SPI/serial link, waves). - -.br - -.IP "\fBbctl\fP - BSC control word" 0 -The command expects a BSC control word, see \fBBSCX\fP. - -.br - -.IP "\fBbit\fP - bit value (0-1)" 0 -The command expects 0 or 1. - -.br - -.IP "\fBbits\fP - a bit mask" 0 -A mask is used to select one or more GPIO. A GPIO is selected -if bit (1<=0)" 0 -The command expects a handle. - -.br -A handle is a number referencing an object opened by one of \fBFO\fP, -\fBI2CO\fP, \fBNO\fP, \fBSERO\fP, \fBSPIO\fP. - -.br - -.IP "\fBib\fP - I2C bus (>=0)" 0 -The command expects an I2C bus number. - -.br - -.IP "\fBid\fP - I2C device (0-0x7F)" 0 -The command expects the address of an I2C device. - -.br - -.IP "\fBif\fP - I2C flags (0)" 0 -The command expects an I2C flags value. No flags are currently defined. - -.br - -.IP "\fBL\fP - level (0-1)" 0 -The command expects a GPIO level. - -.br - -.IP "\fBm\fP - mode (RW540123)" 0 -The command expects a mode character. - -.br -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. - -.br -To set the mode use the code for the mode. - -.br -The value is returned by the mode get command. - -.br - -.EX -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 - -.EE - -.br - -.IP "\fBmiso\fP - GPIO (0-31)" 0 -The GPIO used for the MISO signal when bit banging SPI. - -.br - -.IP "\fBmode\fP - file open mode" 0 -One of the following values. - -.br - -.EX - Value Meaning -READ 1 open file for reading -WRITE 2 open file for writing -RW 3 open file for reading and writing - -.EE - -.br -The following values can be or'd into the mode. - -.br - -.EX - 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 - -.EE - -.br - -.IP "\fBmosi\fP - GPIO (0-31)" 0 -The GPIO used for the MOSI signal when bit banging SPI. - -.br - -.IP "\fBname\fP - the name of a script" 0 -Only alphanumeric characters, '-' and '_' are allowed in the name. - -.br - -.IP "\fBnum\fP - maximum number of bytes to return (1-)" 0 -The command expects the maximum number of bytes to return. - -.br -For the I2C and SPI commands the requested number of bytes will always -be returned. - -.br -For the serial and file commands the smaller of the number of -bytes available to be read (which may be zero) and \fBnum\fP bytes -will be returned. - -.br - -.IP "\fBo\fP - offset (>=0)" 0 -Serial data is stored offset microseconds from the start of the waveform. - -.br - -.IP "\fBp\fP - PUD (ODU)" 0 -The command expects a PUD character. - -.br -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. - -.br -A pull up will default the input to 1 (high). - -.br -A pull down will default the input to 0 (low). - -.br -To set the pull up down state use the command character for the state. - -.br - -.EX -Pull Up Down Off Pull Down Pull Up -Command Character O D U - -.EE - -.br -There is no mechanism to read the pull up down state. - -.br - -.IP "\fBpad\fP - 0-2" 0 -A set of GPIO which share common drivers. - -.br - -.EX -Pad GPIO -0 0-27 -1 28-45 -2 46-53 - -.EE - -.br - -.IP "\fBpadma\fP - 1-16" 0 -The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. - -.br - -.IP "\fBpars\fP - script parameters" 0 -The command expects 0 to 10 numbers as parameters to be passed to the script. - -.br - -.IP "\fBpat\fP - a file name pattern" 0 -A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. - -.br - -.IP "\fBpdc\fP - hardware PWM dutycycle (0-1000000)" 0 -The command expects a dutycycle. - -.br - -.IP "\fBpf\fP - hardware PWM frequency (1-125M, 1-187.5M for the BCM2711)" 0 -The command expects a frequency. - -.br - -.IP "\fBpl\fP - pulse length (1-100)" 0 -The command expects a pulse length in microseconds. - -.br - -.IP "\fBr\fP - register (0-255)" 0 -The command expects an I2C register number. - -.br - -.IP "\fBsb\fP - serial stop (half) bits (2-8)" 0 -The command expects the number of stop (half) bits per serial character. - -.br - -.IP "\fBscl\fP - user GPIO (0-31)" 0 -The command expects the number of the GPIO to be used for SCL -when bit banging I2C. - -.br - -.IP "\fBsclk\fP - user GPIO (0-31)" 0 -The GPIO used for the SCLK signal when bit banging SPI. - -.br - -.IP "\fBsda\fP - user GPIO (0-31)" 0 -The command expects the number of the GPIO to be used for SDA -when bit banging I2C. - -.br - -.IP "\fBsef\fP - serial flags (32 bits)" 0 -The command expects a flag value. No serial flags are currently defined. - -.br - -.IP "\fBsid\fP - script id (>= 0)" 0 -The command expects a script id as returned by a call to \fBPROC\fP. - -.br - -.IP "\fBspf\fP - SPI flags (32 bits)" 0 -See \fBSPIO\fP and \fBBSPIO\fP. - -.br - -.IP "\fBstdy\fP - 0-300000" 0 - -.br -The number of microseconds level changes must be stable for -before reporting the level changed (\fBFG\fP) or triggering -the active part of a noise filter (\fBFN\fP). - -.br - -.IP "\fBstr\fP - a string" 0 -The command expects a string. - -.br - -.IP "\fBt\fP - a string" 0 -The command expects a string. - -.br - -.IP "\fBtrips\fP - triplets" 0 -The command expects 1 or more triplets of GPIO on, GPIO off, delay. - -.br -E.g. 0x400000 0 100000 0 0x400000 900000 defines two pulses as follows - -.br - -.EX - GPIO on GPIO off delay -0x400000 (GPIO 22) 0 (None) 100000 (1/10th s) - 0 (None) 0x400000 (GPIO 22) 900000 (9/10th s) - -.EE - -.br - -.IP "\fBu\fP - user GPIO (0-31)" 0 -The command expects the number of a user GPIO. - -.br -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. - -.br -It is your responsibility to ensure that the PWM and servo commands -are only used on safe GPIO. - -.br -See \fBg\fP - -.br - -.IP "\fBuvs\fP - values" 0 -The command expects an arbitrary number of >=0 values (possibly none). -Any after the first two must be <= 255. - -.br - -.IP "\fBv\fP - value" 0 -The command expects a number. - -.br - -.IP "\fBwid\fP - wave id (>=0)" 0 -The command expects a wave id. - -.br -When a waveform is created it is given an id (0, 1, 2, ...). - -.br - -.IP "\fBwmde\fP - mode (0-3)" 0 -The command expects a wave transmission mode. - -.br -0 = send once -.br -1 = send repeatedly -.br -2 = send once but first sync with previous wave -.br -3 = send repeatedly but first sync with previous wave -.br - -.br - -.IP "\fBws\fP - wave stats sucommand (0-2)" 0 -The command expects a subcommand. - -.br -0 = current value. -.br -1 = highest value so far. -.br -2 = maximum possible value. - -.br - -.IP "\fBwv\fP - word value (0-65535)" 0 -The command expects a word value. - -.br - -.SH SCRIPTS - -.br -Scripts are programs to be stored and executed by the pigpio daemon. -They are intended to mitigate any performance problems associated with -the pigpio daemon server/client model. - -.br -.SS Example -.br -A trivial example might be useful. Suppose you want to toggle a GPIO -on and off as fast as possible. - -.br -From the command line you could write - -.br - -.EX -for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done -.br - -.EE - -.br -Timing that you will see it takes about 14 seconds, or roughly -70 toggles per second. - -.br -Using the pigpio Python module you could use code such as - -.br - -.EX -#!/usr/bin/env python -.br - -.br -import time -.br - -.br -import pigpio -.br - -.br -PIN=4 -.br - -.br -TOGGLE=10000 -.br - -.br -pi = pigpio.pi() # Connect to local Pi. -.br - -.br -s = time.time() -.br - -.br -for i in range(TOGGLE): -.br - pi.write(PIN, 1) -.br - pi.write(PIN, 0) -.br - -.br -e = time.time() -.br - -.br -print("pigpio did {} toggles per second".format(int(TOGGLE/(e-s)))) -.br - -.br -pi.stop() -.br - -.EE - -.br -Timing that shows a speed improvement to roughly 800 toggles per second. - -.br -Now let's use a script. - -.br - -.EX -pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999 -.br - -.EE - -.br -Ignore the details for now. - -.br -Let's time the script running. - -.br -Again, ignore the details for now. - -.br - -.EX -time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ -.br - do sleep 0.2; done) -.br - -.EE - -.br -The script takes roughly 12 seconds to complete, or 800,000 toggles per second. - -.br -That is the advantage of a stored script. - -.br -Some details. - -.br - -.EX -pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999 -.br - -.EE - -.br -proc introduces a script. Everything after proc is part of the script. -.br -tag 999 names the current position in the script. -.br -w 22 1 writes 1 to GPIO 22. -.br -w 22 0 writes 0 to GPIO 22. -.br -dcr p0 decrements parameter 0. -.br -jp 999 jumps to tag 999 if the result is positive. - -.br - -.EX -time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ -.br - do sleep 0.2; done) -.br - -.EE - -.br -pigs procr 0 10000000 starts script 0 with parameter 0 of 10 million. - -.br -The rest is bash apart from - -.br -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. - -.br -.SS Virtual machine -.br -A script runs within a virtual machine with - -.br -a 32 bit accumulator A. -.br -a flags register F. -.br -a program counter PC. - -.br -Each script has - -.br -10 parameters named 0 through 9. -.br -150 variables named 0 through 149. -.br -50 labels which are named by any unique number. - -.br -.SS Commands -.br -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. - -.br -The following commands are not permitted within a script: - -.br -File - FL FO FR FW - -.br -I2C - BI2CZ I2CPK I2CRD I2CRI I2CRK I2CWD I2CWI I2CWK I2CZ - -.br -Misc - BSCX CF1 CF2 SHELL - -.br -Script control - PARSE PROC PROCD PROCP PROCR PROCS PROCU - -.br -Serial - SERO SERR SERW SLR - -.br -SPI - BSPIO BSPIX SPIR SPIW SPIX - -.br -Waves - WVAG WVAS WVCHA WVGO WVGOR - -.br -The following commands are only permitted within a script: - -.br - -.EX -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 - -.EE - -.br -x may be a constant, a parameter (p0-p9), or a variable (v0-v149). - -.br -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. - -.br -The EVTWT command parameter is a bit-mask with 1 set for events of interest. - -.br -The WAIT command parameter is a bit-mask with 1 set for GPIO of interest. - -.br -The SYS script receives two unsigned parameters: the accumulator A and -the current GPIO levels. - -.br - -.SH SEE ALSO - -pigpiod(1), pig2vcd(1), pigpio(3), pigpiod_if(3), pigpiod_if2(3) -.SH AUTHOR - -joan@abyz.me.uk diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index 22ceb98..6ac1161 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 b/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 deleted file mode 100644 index 0820b48..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-16-40-23 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 b/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 deleted file mode 100644 index 93b1db0..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-20-52-04 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 b/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 deleted file mode 100644 index d89cd8f..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-21-11-13 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 b/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 deleted file mode 100644 index 79a4182..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-22-41-24 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 deleted file mode 100644 index 07931f1..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-09-20 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 deleted file mode 100644 index c9ca6e2..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-19-32 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 deleted file mode 100644 index 1630297..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-23-35 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 deleted file mode 100644 index 840f6a8..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-24-27 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 deleted file mode 100644 index ef77c96..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-26-47 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 deleted file mode 100644 index 125a0fc..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-29-09 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 b/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 deleted file mode 100644 index 70b41cd..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-29-23-32-20 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 b/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 deleted file mode 100644 index 98a0cb1..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-08-51-48 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 b/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 deleted file mode 100644 index d763ce9..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-08-59-05 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 deleted file mode 100644 index 23be3f5..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-09-37-19 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 deleted file mode 100644 index 1dc038e..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-09-44-25 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 deleted file mode 100644 index 03f11ba..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-09-45-49 and /dev/null differ diff --git a/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 b/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 deleted file mode 100644 index d37369e..0000000 Binary files a/DOC/dbase/pigpio.sqlite.2020-04-30-09-48-51 and /dev/null differ diff --git a/DOC/src/defs/examples.def b/DOC/src/defs/examples.def index cd793a4..5a54f92 100644 --- a/DOC/src/defs/examples.def +++ b/DOC/src/defs/examples.def @@ -501,6 +501,13 @@ gpioHardwareRevision Related code. +?4|https://pypi.org/project/nrf24/|2020-04-20|NRF24 +Python Package Index (Pypi) NRF24 module. +pip install nrf24 + +?4|https://github.com/bjarne-hansen/py-nrf24|2020-04-20|NRF24 +Code and example usage of the Pypi NRF24 module. Cleaned up and added support for reading from multiple pipes using open_reading_pipe(pipe, address) and open_writing_pipe(address) in order to be more "compatible" with the way NRF24 is used on Arduinos. + ?4|https://github.com/stripcode/pigpio-stepper-motor|2016-08-12|Stepper Motor Stepper motor code. diff --git a/DOC/tmp/body/cif.body b/DOC/tmp/body/cif.body deleted file mode 100644 index f20d1c4..0000000 --- a/DOC/tmp/body/cif.body +++ /dev/null @@ -1,1824 +0,0 @@ -

pigpio is a C library for the Raspberry which allows control of the GPIO. -

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts -

GPIO

ALL GPIO are identified by their Broadcom number. -

Credits

The PWM and servo pulses are timed using the DMA and PWM peripherals. -

This use was inspired by Richard Hirst's servoblaster kernel module. -

Usage

Include <pigpio.h> in your source files. -

Assuming your source is in prog.c use the following command to build and -run the executable. -

gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
sudo ./prog


For examples of usage see the C programs within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error. -

gpioInitialise must be called before all other library functions -with the following exceptions: -

gpioCfg*
gpioVersion
gpioHardwareRevision


If the library is not initialised all but the gpioCfg*, -gpioVersion, and gpioHardwareRevision functions will -return error PI_NOT_INITIALISED. -

If the library is initialised the gpioCfg* functions will return -error PI_INITIALISED. -

OVERVIEW

ESSENTIAL -
gpioInitialise Initialise library -
gpioTerminate Stop library -
BASIC -
gpioSetMode Set a GPIO mode -
gpioGetMode Get a GPIO mode -
gpioSetPullUpDown Set/clear GPIO pull up/down resistor -
gpioRead Read a GPIO -
gpioWrite Write a GPIO -
PWM (overrides servo commands on same GPIO) -
gpioPWM Start/stop PWM pulses on a GPIO -
gpioSetPWMfrequency Configure PWM frequency for a GPIO -
gpioSetPWMrange Configure PWM range for a GPIO -
gpioGetPWMdutycycle Get dutycycle setting on a GPIO -
gpioGetPWMfrequency Get configured PWM frequency for a GPIO -
gpioGetPWMrange Get configured PWM range for a GPIO -
gpioGetPWMrealRange Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
gpioServo Start/stop servo pulses on a GPIO -
gpioGetServoPulsewidth Get pulsewidth setting on a GPIO -
INTERMEDIATE -
gpioTrigger Send a trigger pulse to a GPIO -
gpioSetWatchdog Set a watchdog on a GPIO -
gpioRead_Bits_0_31 Read all GPIO in bank 1 -
gpioRead_Bits_32_53 Read all GPIO in bank 2 -
gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1 -
gpioWrite_Bits_32_53_ClearClear selected GPIO in bank 2 -
gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1 -
gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2 -
gpioSetAlertFunc Request a GPIO level change callback -
gpioSetAlertFuncEx Request a GPIO change callback, extended -
gpioSetTimerFunc Request a regular timed callback -
gpioSetTimerFuncEx Request a regular timed callback, extended -
gpioStartThread Start a new thread -
gpioStopThread Stop a previously started thread -
ADVANCED -
gpioNotifyOpen Request a notification handle -
gpioNotifyClose Close a notification -
gpioNotifyOpenWithSize Request a notification with sized pipe -
gpioNotifyBegin Start notifications for selected GPIO -
gpioNotifyPause Pause notifications -
gpioHardwareClock Start hardware clock on supported GPIO -
gpioHardwarePWM Start hardware PWM on supported GPIO -
gpioGlitchFilter Set a glitch filter on a GPIO -
gpioNoiseFilter Set a noise filter on a GPIO -
gpioSetPad Sets a pads drive strength -
gpioGetPad Gets a pads drive strength -
shell Executes a shell command -
gpioSetISRFunc Request a GPIO interrupt callback -
gpioSetISRFuncEx Request a GPIO interrupt callback, extended -
gpioSetSignalFunc Request a signal callback -
gpioSetSignalFuncEx Request a signal callback, extended -
gpioSetGetSamplesFunc Requests a GPIO samples callback -
gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended -
Custom -
gpioCustom1 User custom function 1 -
gpioCustom2 User custom function 2 -
Events -
eventMonitor Sets the events to monitor -
eventSetFunc Request an event callback -
eventSetFuncEx Request an event callback, extended -
eventTrigger Trigger an event -
Scripts -
gpioStoreScript Store a script -
gpioRunScript Run a stored script -
gpioUpdateScript Set a scripts parameters -
gpioScriptStatus Get script status and parameters -
gpioStopScript Stop a running script -
gpioDeleteScript Delete a stored script -
I2C -
i2cOpen Opens an I2C device -
i2cClose Closes an I2C device -
i2cWriteQuick SMBus write quick -
i2cReadByte SMBus read byte -
i2cWriteByte SMBus write byte -
i2cReadByteData SMBus read byte data -
i2cWriteByteData SMBus write byte data -
i2cReadWordData SMBus read word data -
i2cWriteWordData SMBus write word data -
i2cReadBlockData SMBus read block data -
i2cWriteBlockData SMBus write block data -
i2cReadI2CBlockData SMBus read I2C block data -
i2cWriteI2CBlockData SMBus write I2C block data -
i2cReadDevice Reads the raw I2C device -
i2cWriteDevice Writes the raw I2C device -
i2cProcessCall SMBus process call -
i2cBlockProcessCall SMBus block process call -
i2cSwitchCombined Sets or clears the combined flag -
i2cSegments Performs multiple I2C transactions -
i2cZip Performs multiple I2C transactions -
I2C BIT BANG -
bbI2COpen Opens GPIO for bit banging I2C -
bbI2CClose Closes GPIO for bit banging I2C -
bbI2CZip Performs bit banged I2C transactions -
I2C/SPI SLAVE -
bscXfer I2C/SPI as slave transfer -
SERIAL -
serOpen Opens a serial device -
serClose Closes a serial device -
serReadByte Reads a byte from a serial device -
serWriteByte Writes a byte to a serial device -
serRead Reads bytes from a serial device -
serWrite Writes bytes to a serial device -
serDataAvailable Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
gpioSerialReadOpen Opens a GPIO for bit bang serial reads -
gpioSerialReadClose Closes a GPIO for bit bang serial reads -
gpioSerialReadInvert Configures normal/inverted for serial reads -
gpioSerialRead Reads bit bang serial data from a GPIO -
SPI -
spiOpen Opens a SPI device -
spiClose Closes a SPI device -
spiRead Reads bytes from a SPI device -
spiWrite Writes bytes to a SPI device -
spiXfer Transfers bytes with a SPI device -
SPI BIT BANG -
bbSPIOpen Opens GPIO for bit banging SPI -
bbSPIClose Closes GPIO for bit banging SPI -
bbSPIXfer Performs bit banged SPI transactions -
FILES -
fileOpen Opens a file -
fileClose Closes a file -
fileRead Reads bytes from a file -
fileWrite Writes bytes to a file -
fileSeek Seeks to a position within a file -
fileList List files which match a pattern -
WAVES -
gpioWaveClear Deletes all waveforms -
gpioWaveAddNew Starts a new waveform -
gpioWaveAddGeneric Adds a series of pulses to the waveform -
gpioWaveAddSerial Adds serial data to the waveform -
gpioWaveCreate Creates a waveform from added data -
gpioWaveCreatePad Creates a waveform of fixed size from added data -
gpioWaveDelete Deletes a waveform -
gpioWaveTxSend Transmits a waveform -
gpioWaveChain Transmits a chain of waveforms -
gpioWaveTxAt Returns the current transmitting waveform -
gpioWaveTxBusy Checks to see if the waveform has ended -
gpioWaveTxStop Aborts the current waveform -
gpioWaveGetCbs Length in CBs of the current waveform -
gpioWaveGetHighCbs Length of longest waveform so far -
gpioWaveGetMaxCbs Absolute maximum allowed CBs -
gpioWaveGetMicros Length in micros of the current waveform -
gpioWaveGetHighMicros Length of longest waveform so far -
gpioWaveGetMaxMicros Absolute maximum allowed micros -
gpioWaveGetPulses Length in pulses of the current waveform -
gpioWaveGetHighPulses Length of longest waveform so far -
gpioWaveGetMaxPulses Absolute maximum allowed pulses -
UTILITIES -
gpioDelay Delay for a number of microseconds -
gpioTick Get current tick (microseconds) -
gpioHardwareRevision Get hardware revision -
gpioVersion Get the pigpio version -
getBitInBytes Get the value of a bit -
putBitInBytes Set the value of a bit -
gpioTime Get current time -
gpioSleep Sleep for specified time -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -
CONFIGURATION -
gpioCfgBufferSize Configure the GPIO sample buffer size -
gpioCfgClock Configure the GPIO sample rate -
gpioCfgDMAchannel Configure the DMA channel (DEPRECATED) -
gpioCfgDMAchannels Configure the DMA channels -
gpioCfgPermissions Configure the GPIO access permissions -
gpioCfgInterfaces Configure user interfaces -
gpioCfgSocketPort Configure socket port -
gpioCfgMemAlloc Configure DMA memory allocation mode -
gpioCfgNetAddr Configure allowed network addresses -
gpioCfgInternals Configure misc. internals (DEPRECATED) -
gpioCfgGetInternals Get internal configuration settings -
gpioCfgSetInternals Set internal configuration settings -
EXPERT -
rawWaveAddSPI Not intended for general use -
rawWaveAddGeneric Not intended for general use -
rawWaveCB Not intended for general use -
rawWaveCBAdr Not intended for general use -
rawWaveGetOOL Not intended for general use -
rawWaveSetOOL Not intended for general use -
rawWaveGetOut Not intended for general use -
rawWaveSetOut Not intended for general use -
rawWaveGetIn Not intended for general use -
rawWaveSetIn Not intended for general use -
rawWaveInfo Not intended for general use -
rawDumpWave Not intended for general use -
rawDumpScript Not intended for general use -

FUNCTIONS

int gpioInitialise(void)

-Initialises the library. -

Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. -

gpioInitialise must be called before using the other library functions -with the following exceptions: -

gpioCfg*
gpioVersion
gpioHardwareRevision


Example

if (gpioInitialise() < 0)
{
   // pigpio initialisation failed.
}
else
{
   // pigpio initialised okay.
}

void gpioTerminate(void)

-Terminates the library. -

Returns nothing. -

Call before program exit. -

This function resets the used DMA channels, releases memory, and -terminates any running threads. -

Example

gpioTerminate();

int gpioSetMode(unsigned gpio, unsigned mode)

-Sets the GPIO mode, typically input or output. -

gpio: 0-53
mode: 0-7


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. -

Arduino style: pinMode. -

Example

gpioSetMode(17, PI_INPUT);  // Set GPIO17 as input.

gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output.

gpioSetMode(22,PI_ALT0);    // Set GPIO22 to alternative mode 0.


See http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf page 102 for an overview of the modes. -

int gpioGetMode(unsigned gpio)

-Gets the GPIO mode. -

gpio: 0-53


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

Example

if (gpioGetMode(17) != PI_ALT0)
{
   gpioSetMode(17, PI_ALT0);  // set GPIO17 to ALT0
}

int gpioSetPullUpDown(unsigned gpio, unsigned pud)

-Sets or clears resistor pull ups or downs on the GPIO. -

gpio: 0-53
 pud: 0-2


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD. -

Example

gpioSetPullUpDown(17, PI_PUD_UP);   // Sets a pull-up.

gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.

gpioSetPullUpDown(23, PI_PUD_OFF);  // Clear any pull-ups/downs.

int gpioRead(unsigned gpio)

-Reads the GPIO level, on or off. -

gpio: 0-53


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

Arduino style: digitalRead. -

Example

printf("GPIO24 is level %d", gpioRead(24));

int gpioWrite(unsigned gpio, unsigned level)

-Sets the GPIO level, on or off. -

 gpio: 0-53
level: 0-1


Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. -

If PWM or servo pulses are active on the GPIO they are switched off. -

Arduino style: digitalWrite -

Example

gpioWrite(24, 1); // Set GPIO24 high.

int gpioPWM(unsigned user_gpio, unsigned dutycycle)

-Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). -Range defaults to 255. -

user_gpio: 0-31
dutycycle: 0-range


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE. -

Arduino style: analogWrite -

This and the servo functionality use the DMA and PWM or PCM peripherals -to control and schedule the pulse lengths and dutycycles. -

The gpioSetPWMrange function may be used to change the default -range of 255. -

Example

gpioPWM(17, 255); // Sets GPIO17 full on.

gpioPWM(18, 128); // Sets GPIO18 half on.

gpioPWM(23, 0);   // Sets GPIO23 full off.

int gpioGetPWMdutycycle(unsigned user_gpio)

-Returns the PWM dutycycle setting for the GPIO. -

user_gpio: 0-31


Returns between 0 (off) and range (fully on) if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see gpioGetPWMrange). -

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). -

Normal PWM range defaults to 255. -

int gpioSetPWMrange(unsigned user_gpio, unsigned range)

-Selects the dutycycle range to be used for the GPIO. Subsequent calls -to gpioPWM will use a dutycycle between 0 (off) and range (fully on). -

user_gpio: 0-31
    range: 25-40000


Returns the real range for the given GPIO's frequency if OK, -otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. -

If PWM is currently active on the GPIO its dutycycle will be scaled -to reflect the new range. -

The real range, the number of steps between fully off and fully -on for each frequency, is given in the following table. -

  25,   50,  100,  125,  200,  250,  400,   500,   625,
 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000


The real value set by gpioPWM is (dutycycle * real range) / range. -

Example

gpioSetPWMrange(24, 2000); // Now 2000 is fully on
                           //     1000 is half on
                           //      500 is quarter on, etc.

int gpioGetPWMrange(unsigned user_gpio)

-Returns the dutycycle range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). -

Example

r = gpioGetPWMrange(23);

int gpioGetPWMrealRange(unsigned user_gpio)

-Returns the real range used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


If a hardware clock is active on the GPIO the reported real -range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

Example

rr = gpioGetPWMrealRange(17);

int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)

-Sets the frequency in hertz to be used for the GPIO. -

user_gpio: 0-31
frequency: >=0


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO. -

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 frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency.

gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz.

gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency.

int gpioGetPWMfrequency(unsigned user_gpio)

-Returns the frequency (in hertz) used for the GPIO if OK, otherwise -PI_BAD_USER_GPIO. -

user_gpio: 0-31


For normal PWM the frequency will be that defined for the GPIO by -gpioSetPWMfrequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by gpioHardwareClock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by gpioHardwarePWM. -

Example

f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23.

int gpioServo(unsigned user_gpio, unsigned pulsewidth)

-Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to -2500 (most clockwise). -

 user_gpio: 0-31
pulsewidth: 0, 500-2500


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH. -

The range supported by servos varies and should probably be determined -by experiment. A value of 1500 should always be safe and represents -the mid-point of rotation. You can DAMAGE a servo if you command it -to move beyond its limits. -

The following 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

gpioServo(17, 1000); // Move servo to safe position anti-clockwise.

gpioServo(23, 1500); // Move servo to centre position.

gpioServo(25, 2000); // Move servo to safe position clockwise.


OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

PWM Hz    50   100  200  400  500
1E6/Hz 20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using gpioSetPWMfrequency. -

Then set the PWM range using gpioSetPWMrange to 1E6/frequency. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO25 at 400Hz -

gpioSetPWMfrequency(25, 400);

gpioSetPWMrange(25, 2500);


Thereafter use the PWM command to move the servo, -e.g. gpioPWM(25, 1500) will set a 1500 us pulse. -

int gpioGetServoPulsewidth(unsigned user_gpio)

-Returns the servo pulsewidth setting for the GPIO. -

user_gpio: 0-31


Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) -if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)

-Registers a function to be called (a callback) when the specified -GPIO changes state. -

user_gpio: 0-31
        f: the callback function


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -

One callback may be registered per GPIO. -

The callback is passed the GPIO, the new level, and the tick. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The alert may be cancelled by passing NULL as the function. -

The GPIO are sampled at a rate set when the library is started. -

If a value isn't specifically set the default of 5 us is used. -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


Level changes shorter than the sample rate may be missed. -

The thread which calls the alert functions is triggered nominally -1000 times per second. The active alert functions will be called -once per level change since the last time the thread was activated. -i.e. The active alert functions will get all level changes but there -will be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use gpioRead. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

The tick value is the time stamp of the sample in microseconds, see -gpioTick for more details. -

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state

gpioSetAlertFunc(4, aFunction);

int gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when the specified -GPIO changes state. -

user_gpio: 0-31
        f: the callback function
 userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -

One callback may be registered per GPIO. -

The callback is passed the GPIO, the new level, the tick, and -the userdata pointer. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


See gpioSetAlertFunc for further details. -

Only one of gpioSetAlertFunc or gpioSetAlertFuncEx can be -registered per GPIO. -

int gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)

-Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. -

   gpio: 0-53
   edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
timeout: interrupt timeout in milliseconds (<=0 to cancel)
      f: the callback function


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. -

One function may be registered per GPIO. -

The function is passed the GPIO, the current level, and the -current tick. The level will be PI_TIMEOUT if the optional -interrupt timeout expires. -

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The underlying Linux sysfs GPIO interface is used to provide -the interrupt services. -

The first time the function is called, with a non-NULL f, the -GPIO is exported, set to be an input, and set to interrupt -on the given edge and timeout. -

Subsequent calls, with a non-NULL f, can vary one or more of the -edge, timeout, or function. -

The ISR may be cancelled by passing a NULL f, in which case the -GPIO is unexported. -

The tick is that read at the time the process was informed of -the interrupt. This will be a variable number of microseconds -after the interrupt occurred. Typically the latency will be of -the order of 50 microseconds. The latency is not guaranteed -and will vary with system load. -

The level is that read at the time the process was informed of -the interrupt, or PI_TIMEOUT if the optional interrupt timeout -expired. It may not be the same as the expected edge as -interrupts happening in rapid succession may be missed by the -kernel (i.e. this mechanism can not be used to capture several -interrupts only a few microseconds apart). -

int gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) whenever the specified -GPIO interrupt occurs. -

    gpio: 0-53
    edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
 timeout: interrupt timeout in milliseconds (<=0 to cancel)
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE, -or PI_BAD_ISR_INIT. -

The function is passed the GPIO, the current level, the -current tick, and the userdata pointer. -

Parameter   Value    Meaning

GPIO        0-53     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (interrupt timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object


Only one of gpioSetISRFunc or gpioSetISRFuncEx can be -registered per GPIO. -

See gpioSetISRFunc for further details. -

int gpioNotifyOpen(void)

-This function requests a free notification handle. -

Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state changes -via a pipe or socket. -

Pipe notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). E.g. if the -function returns 15 then the notifications must be read -from /dev/pigpio15. -

Socket notifications are returned to the socket which requested the -handle. -

Example

h = gpioNotifyOpen();

if (h >= 0)
{
   sprintf(str, "/dev/pigpio%d", h);

   fd = open(str, O_RDONLY);

   if (fd >= 0)
   {
      // Okay.
   }
   else
   {
      // Error.
   }
}
else
{
   // Error.
}

int gpioNotifyOpenWithSize(int bufSize)

-This function requests a free notification handle. -

It differs from gpioNotifyOpen in that the pipe size may be -specified, whereas gpioNotifyOpen uses the default pipe size. -

See gpioNotifyOpen for further details. -

int gpioNotifyBegin(unsigned handle, uint32_t bits)

-This function starts notifications on a previously opened handle. -

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the GPIO of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose corresponding -bit in bits is set. -

Each notification occupies 12 bytes in the fifo and has the -following structure. -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

Example

// Start notifications for GPIO 1, 4, 6, 7, 10.

//                         1
//                         0  76 4  1
// (1234 = 0x04D2 = 0b0000010011010010)

gpioNotifyBegin(h, 1234);

int gpioNotifyPause(unsigned handle)

-This function pauses notifications on a previously opened handle. -

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until gpioNotifyBegin -is called again. -

Example

gpioNotifyPause(h);

int gpioNotifyClose(unsigned handle)

-This function stops notifications on a previously opened handle -and releases the handle for reuse. -

handle: >=0, as returned by gpioNotifyOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

gpioNotifyClose(h);

int gpioWaveClear(void)

-This function clears all waveforms and any data added by calls to the -gpioWaveAdd* functions. -

Returns 0 if OK. -

Example

gpioWaveClear();

int gpioWaveAddNew(void)

-This function starts a new empty waveform. -

You wouldn't normally need to call this function as it is automatically -called after a waveform is created with the gpioWaveCreate function. -

Returns 0 if OK. -

Example

gpioWaveAddNew();

int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses
   pulses: an array of pulses


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. -

Example

// Construct and send a 30 microsecond square wave.

gpioSetMode(gpio, PI_OUTPUT);

pulse[0].gpioOn = (1<<gpio);
pulse[0].gpioOff = 0;
pulse[0].usDelay = 15;

pulse[1].gpioOn = 0;
pulse[1].gpioOff = (1<<gpio);
pulse[1].usDelay = 15;

gpioWaveAddNew();

gpioWaveAddGeneric(2, pulse);

wave_id = gpioWaveCreate();

if (wave_id >= 0)
{
   gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);

   // Transmit for 30 seconds.

   sleep(30);

   gpioWaveTxStop();
}
else
{
   // Wave create failed.
}

int gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

user_gpio: 0-31
     baud: 50-1000000
data_bits: 1-32
stop_bits: 2-8
   offset: >=0
 numBytes: >=1
      str: an array of chars (which may contain nulls)


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, and -stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

Example

#define MSG_LEN 8

int i;
char *str;
char data[MSG_LEN];

str = "Hello world!";

gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str);

for (i=0; i<MSG_LEN; i++) data[i] = i;

// Data added is offset 1 second from the waveform start.
gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);

int gpioWaveCreate(void)

-This function creates a waveform from the data provided by the prior -calls to the gpioWaveAdd* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the gpioWaveAdd* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to gpioWaveTxSend to specify the waveform to transmit. -

Normal usage would be -

Step 1. gpioWaveClear to clear all waveforms and added data. -

Step 2. gpioWaveAdd* calls to supply the waveform data. -

Step 3. gpioWaveCreate to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. gpioWaveTxSend with the id of the waveform to transmit. -

A waveform comprises one of more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL)

-Similar to gpioWaveCreate, this function creates a waveform but pads the consumed -resources. Padded waves of equal dimension can be re-cycled efficiently allowing -newly created waves to re-use the resources of deleted waves of the same dimension. -

pctCB: 0-100, the percent of all DMA control blocks to consume.
pctBOOL: 0-100, percent On-Off-Level (OOL) buffer to consume for wave output.
pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags).


Upon success a wave id greater than or equal to 0 is returned, otherwise -PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

Waveform data provided by gpioWaveAdd* and rawWaveAdd* functions are -consumed by this function. -

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Example

  // get firstWaveChunk, somehow
  gpioWaveAddGeneric(firstWaveChunk);
  wid = gpioWaveCreatePad(50, 50, 0);
  gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
  // get nextWaveChunk

  while (nextWaveChunk) {
     gpioWaveAddGeneric(nextWaveChunk);
     nextWid = gpioWaveCreatePad(50, 50, 0);
     gpioWaveTxSend(nextWid, PI_WAVE_MODE_ONE_SHOT_SYNC);
     while(gpioWaveTxAt() == wid) time_sleep(0.1);
     gpioWaveDelete(wid);
     wid = nextWid;
     // get nextWaveChunk
  }

int gpioWaveDelete(unsigned wave_id)

-This function deletes the waveform with id wave_id. -

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). -

wave_id: >=0, as returned by gpioWaveCreate


Wave ids are allocated in order, 0, 1, 2, etc. -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)

-This function transmits the waveform with id wave_id. The mode -determines whether the waveform is sent once or cycles endlessly. -The SYNC variants wait for the current waveform to reach the -end of a cycle or finish before starting the new waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. -

  wave_id: >=0, as returned by gpioWaveCreate
wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
           PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int gpioWaveChain(char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by gpioHardwarePWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpio.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (gpioInitialise()<0) return -1;

   gpioSetMode(GPIO, PI_OUTPUT);

   printf("start piscope, press return"); getchar();

   for (i=0; i<WAVES; i++)
   {
      gpioWaveAddGeneric(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = gpioWaveCreate();
   }

   gpioWaveChain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (gpioWaveTxBusy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);

   printf("stop piscope, press return"); getchar();

   gpioTerminate();
}

int gpioWaveTxAt(void)

-This function returns the id of the waveform currently being -transmitted. -

Returns the waveform id or one of the following special values: -

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
-PI_NO_TX_WAVE (9999) - no wave being transmitted. -

int gpioWaveTxBusy(void)

-This function checks to see if a waveform is currently being -transmitted. -

Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int gpioWaveTxStop(void)

-This function aborts the transmission of the current waveform. -

Returns 0 if OK. -

This function is intended to stop a waveform started in repeat mode. -

int gpioWaveGetMicros(void)

-This function returns the length in microseconds of the current -waveform. -

int gpioWaveGetHighMicros(void)

-This function returns the length in microseconds of the longest waveform -created since gpioInitialise was called. -

int gpioWaveGetMaxMicros(void)

-This function returns the maximum possible size of a waveform in -microseconds. -

int gpioWaveGetPulses(void)

-This function returns the length in pulses of the current waveform. -

int gpioWaveGetHighPulses(void)

-This function returns the length in pulses of the longest waveform -created since gpioInitialise was called. -

int gpioWaveGetMaxPulses(void)

-This function returns the maximum possible size of a waveform in pulses. -

int gpioWaveGetCbs(void)

-This function returns the length in DMA control blocks of the current -waveform. -

int gpioWaveGetHighCbs(void)

-This function returns the length in DMA control blocks of the longest -waveform created since gpioInitialise was called. -

int gpioWaveGetMaxCbs(void)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

int gpioSerialReadOpen(unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

user_gpio: 0-31
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -PI_BAD_DATABITS, or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -gpioSerialRead. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int gpioSerialReadInvert(unsigned user_gpio, unsigned invert)

-This function configures the level logic for bit bang serial reads. -

Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for -normal logic. Default is PI_BB_SER_NORMAL. -

user_gpio: 0-31
   invert: 0-1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, -PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT. -

The GPIO must be opened for bit bang reading of serial data using -gpioSerialReadOpen prior to calling this function. -

int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

user_gpio: 0-31, previously opened with gpioSerialReadOpen
      buf: an array to receive the read bytes
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the gpioSerialReadOpen command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int gpioSerialReadClose(unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

user_gpio: 0-31, previously opened with gpioSerialReadOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)

-This returns a handle for the device at the address on the I2C bus. -

  i2cBus: >=0
 i2cAddr: 0-0x7F
i2cFlags: 0


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S      (1 bit) : Start bit
P      (1 bit) : Stop bit
Rd/Wr  (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA  (1 bit) : Accept and not accept bit.

Addr   (7 bits): I2C 7 bit address.
i2cReg (8 bits): Command byte, a byte which often selects a register.
Data   (8 bits): A data byte.
Count  (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2cClose(unsigned handle)

-This closes the I2C device associated with the handle. -

handle: >=0, as returned by a call to i2cOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2cWriteQuick(unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

handle: >=0, as returned by a call to i2cOpen
   bit: 0-1, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr bit [A] P

int i2cWriteByte(unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] bVal [A] P

int i2cReadByte(unsigned handle)

-This reads a single byte from the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  bVal: 0-0xFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] i2cReg [A] bVal [A] P

int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
  wVal: 0-0xFFFF, the value to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P

int i2cReadByteData(unsigned handle, unsigned i2cReg)

-This reads a single byte from the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P

int i2cReadWordData(unsigned handle, unsigned i2cReg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
  wVal: 0-0xFFFF, the value to write


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: an array with the data to send
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] i2cReg [A] count [A]
   buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
   buf: an array with the data to send and to receive the read data
 count: 1-32, the number of bytes to write


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The SMBus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A]
   S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P

int i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
   buf: an array to receive the read data
 count: 1-32, the number of bytes to read


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] i2cReg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
   buf: the data to write
 count: 1-32, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2cReadDevice(unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

handle: >=0, as returned by a call to i2cOpen
   buf: an array to receive the read data bytes
 count: >0, the number of bytes to read


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2cWriteDevice(unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

handle: >=0, as returned by a call to i2cOpen
   buf: an array containing the data bytes to write
 count: >0, the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

void i2cSwitchCombined(int setting)

-This sets the I2C (i2c-bcm2708) module "use combined transactions" -parameter on or off. -

setting: 0 to set the parameter off, non-zero to set it on


NOTE: when the flag is on a write followed by a read to the same -slave address will use a repeated start (rather than a stop/start). -

int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)

-This function executes multiple I2C segments in one transaction by -calling the I2C_RDWR ioctl. -

 handle: >=0, as returned by a call to i2cOpen
   segs: an array of I2C segments
numSegs: >0, the number of I2C segments


Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG. -

int i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bbI2CClose(unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bbI2COpen. -

SDA: 0-31, the SDA GPIO used in a prior call to bbI2COpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

   SDA: 0-31 (as used in a prior call to bbI2COpen)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bscXfer(bsc_xfer_t *bsc_xfer)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

bsc_xfer:= a structure defining the transfer

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. -

Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

The returned function value is the status of the transfer (see below). -

If there was an error the status will be less than zero -(and will contain the error code). -

The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). -

control consists of the following bits. -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. -

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bscXfer(&xfer);

if (status >= 0)
{
   // process transfer
}

int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)

-This function selects a set of GPIO for bit banging SPI with -a specified baud rate and mode. -

      CS: 0-31
    MISO: 0-31
    MOSI: 0-31
    SCLK: 0-31
    baud: 50-250000
spiFlags: see below


spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bbSPIClose(unsigned CS)

-This function stops bit banging SPI on a set of GPIO -opened with bbSPIOpen. -

CS: 0-31, the CS GPIO used in a prior call to bbSPIOpen


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

int bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)

-This function executes a bit banged SPI transfer. -

    CS: 0-31 (as used in a prior call to bbSPIOpen)
 inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
 count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. -

Example

// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
// sudo ./bbSPIx_test

#include <stdio.h>

#include "pigpio.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if (gpioInitialise() < 0)
   {
      fprintf(stderr, "pigpio initialisation failed.\n");
      return 1;
   }

   bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bbSPIClose(CE0);
   bbSPIClose(CE1);

   gpioTerminate();

   return 0;
}

int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


 spiChan: 0-1 (0-2 for the auxiliary SPI)
    baud: 32K-125M (values above 30M are unlikely to work)
spiFlags: see below


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 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. -

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 spiRead, spiWrite, and spiXfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per word.
-For bits 9-16 there will be two bytes per word.
-For bits 17-32 there will be four bytes per word. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spiClose(unsigned handle)

-This functions closes the SPI device identified by the handle. -

handle: >=0, as returned by a call to spiOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spiRead(unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spiOpen
   buf: an array to receive the read data bytes
 count: the number of bytes to read


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spiWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spiOpen
   buf: the data bytes to write
 count: the number of bytes to write


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

handle: >=0, as returned by a call to spiOpen
 txBuf: the data bytes to write
 rxBuf: the received data bytes
 count: the number of bytes to transfer


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serOpen(char *sertty, unsigned baud, unsigned serFlags)

-This function opens a serial device at a specified baud rate -and with specified flags. The device name must start with -/dev/tty or /dev/serial. -

  sertty: the serial device to open
    baud: the baud rate in bits per second, see below
serFlags: 0


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serClose(unsigned handle)

-This function closes the serial device associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serWriteByte(unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serReadByte(unsigned handle)

-This function reads a byte from the serial port associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

handle: >=0, as returned by a call to serOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serRead(unsigned handle, char *buf, unsigned count)

-This function reads up count bytes from the the serial port -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to serOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_SER_READ_NO_DATA. -

If no data is ready zero is returned. -

int serDataAvailable(unsigned handle)

-This function returns the number of bytes available -to be read from the device associated with handle. -

handle: >=0, as returned by a call to serOpen


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

user_gpio: 0-31
 pulseLen: 1-100
    level: 0,1


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -or PI_BAD_PULSELEN. -

int gpioSetWatchdog(unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

user_gpio: 0-31
  timeout: 0-60000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

One watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Until cancelled a timeout will be reported every timeout milliseconds -after the last GPIO activity. -

In particular: -

1) any registered alert function for the GPIO will be called with - the level set to PI_TIMEOUT. -

2) any notification for the GPIO will have a report written to the - fifo with the flags set to indicate a watchdog timeout. -

Example

void aFunction(int gpio, int level, uint32_t tick)
{
   printf("GPIO %d became %d at %d", gpio, level, tick);
}

// call aFunction whenever GPIO 4 changes state
gpioSetAlertFunc(4, aFunction);

//  or approximately every 5 millis
gpioSetWatchdog(4, 5);

int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, -and gpioSetGetSamplesFuncEx. -

It does not affect interrupts set up with gpioSetISRFunc, -gpioSetISRFuncEx, or levels read by gpioRead, -gpioRead_Bits_0_31, or gpioRead_Bits_32_53. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

int gpioGlitchFilter(unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with gpioSetAlertFunc, gpioSetAlertFuncEx, gpioSetGetSamplesFunc, -and gpioSetGetSamplesFuncEx. -

It does not affect interrupts set up with gpioSetISRFunc, -gpioSetISRFuncEx, or levels read by gpioRead, -gpioRead_Bits_0_31, or gpioRead_Bits_32_53. -

Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)

-Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. -

   f: the function to call
bits: the GPIO of interest


Returns 0 if OK. -

The function is passed a pointer to the samples (an array of -gpioSample_t), and the number of samples. -

Only one function can be registered. -

The callback may be cancelled by passing NULL as the function. -

The samples returned will be the union of bits, plus any active alerts, -plus any active notifications. -

e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO -8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO -7, 8, 9, 10, 17, 23, and 24 will be reported. -

int gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)

-Registers a function to be called (a callback) every millisecond -with the latest GPIO samples. -

       f: the function to call
    bits: the GPIO of interest
userdata: a pointer to arbitrary user data


Returns 0 if OK. -

The function is passed a pointer to the samples (an array of -gpioSample_t), the number of samples, and the userdata pointer. -

Only one of gpioGetSamplesFunc or gpioGetSamplesFuncEx can be -registered. -

See gpioSetGetSamplesFunc for further details. -

int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)

-Registers a function to be called (a callback) every millis milliseconds. -

 timer: 0-9
millis: 10-60000
     f: the function to call


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. -

10 timers are supported numbered 0 to 9. -

One function may be registered per timer. -

The timer may be cancelled by passing NULL as the function. -

Example

void bFunction(void)
{
   printf("two seconds have elapsed");
}

// call bFunction every 2000 milliseconds
gpioSetTimerFunc(0, 2000, bFunction);

int gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) every millis milliseconds. -

   timer: 0-9.
  millis: 10-60000
       f: the function to call
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED. -

The function is passed the userdata pointer. -

Only one of gpioSetTimerFunc or gpioSetTimerFuncEx can be -registered per timer. -

See gpioSetTimerFunc for further details. -

pthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata)

-Starts a new thread of execution with f as the main routine. -

       f: the main function for the new thread
userdata: a pointer to arbitrary user data


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument arg. -

The thread can be cancelled by passing the pointer to pthread_t to -gpioStopThread. -

Example

#include <stdio.h>
#include <pigpio.h>

void *myfunc(void *arg)
{
   while (1)
   {
      printf("%s", arg);
      sleep(1);
   }
}

int main(int argc, char *argv[])
{
   pthread_t *p1, *p2, *p3;

   if (gpioInitialise() < 0) return 1;

   p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);

   p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);

   p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);

   gpioStopThread(p3); sleep(3);

   gpioStopThread(p2); sleep(3);

   gpioStopThread(p1); sleep(3);

   gpioTerminate();
}

void gpioStopThread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: a thread pointer returned by gpioStartThread


No value is returned. -

The thread to be stopped should have been started with gpioStartThread. -

int gpioStoreScript(char *script)

-This function stores a null terminated script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

script: the text of the script


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)

-This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. -

script_id: >=0, as returned by gpioStoreScript
   numPar: 0-10, the number of parameters
    param: an array of parameters


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int gpioScriptStatus(unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well as -the current values of parameters 0 to 9. -

script_id: >=0, as returned by gpioStoreScript
    param: an array to hold the returned 10 parameters


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int gpioStopScript(unsigned script_id)

-This function stops a running script. -

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int gpioDeleteScript(unsigned script_id)

-This function deletes a stored script. -

script_id: >=0, as returned by gpioStoreScript


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)

-Registers a function to be called (a callback) when a signal occurs. -

signum: 0-63
     f: the callback function


Returns 0 if OK, otherwise PI_BAD_SIGNUM. -

The function is passed the signal number. -

One function may be registered per signal. -

The callback may be cancelled by passing NULL. -

By default all signals are treated as fatal and cause the library -to call gpioTerminate and then exit. -

int gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when a signal occurs. -

  signum: 0-63
       f: the callback function
userdata: a pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_SIGNUM. -

The function is passed the signal number and the userdata pointer. -

Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be -registered per signal. -

See gpioSetSignalFunc for further details. -

uint32_t gpioRead_Bits_0_31(void)

-Returns the current level of GPIO 0-31. -

uint32_t gpioRead_Bits_32_53(void)

-Returns the current level of GPIO 32-53. -

int gpioWrite_Bits_0_31_Clear(uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask of GPIO to clear


Returns 0 if OK. -

Example

// To clear (set to 0) GPIO 4, 7, and 15
gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );

int gpioWrite_Bits_32_53_Clear(uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask of GPIO to clear


Returns 0 if OK. -

int gpioWrite_Bits_0_31_Set(uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask of GPIO to set


Returns 0 if OK. -

int gpioWrite_Bits_32_53_Set(uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask of GPIO to set


Returns 0 if OK. -

Example

// To set (set to 1) GPIO 32, 40, and 53
gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));

int gpioHardwareClock(unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

   gpio: see description
clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, -PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by gpioWaveTxSend, or -gpioWaveChain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden by a call to -gpioCfgClock. -

   gpio: see description
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, -PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. -

int gpioTime(unsigned timetype, int *seconds, int *micros)

-Updates the seconds and micros variables with the current time. -

timetype: 0 (relative), 1 (absolute)
 seconds: a pointer to an int to hold seconds
  micros: a pointer to an int to hold microseconds


Returns 0 if OK, otherwise PI_BAD_TIMETYPE. -

If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the -number of seconds and microseconds since the epoch (1st January 1970). -

If timetype is PI_TIME_RELATIVE updates seconds and micros with the -number of seconds and microseconds since the library was initialised. -

Example

int secs, mics;

// print the number of seconds since the library was started
gpioTime(PI_TIME_RELATIVE, &secs, &mics);
printf("library started %d.%03d seconds ago", secs, mics/1000);

int gpioSleep(unsigned timetype, int seconds, int micros)

-Sleeps for the number of seconds and microseconds specified by seconds -and micros. -

timetype: 0 (relative), 1 (absolute)
 seconds: seconds to sleep
  micros: microseconds to sleep


Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, -or PI_BAD_MICROS. -

If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds -and microseconds since the epoch (1st January 1970) has elapsed. System -clock changes are taken into account. -

If timetype is PI_TIME_RELATIVE the sleep is for the specified number -of seconds and microseconds. System clock changes do not effect the -sleep length. -

For short delays (say, 50 microseonds or less) use gpioDelay. -

Example

gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds

gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds

gpioSleep(PI_TIME_RELATIVE, 60, 0);     // sleep for one minute

uint32_t gpioDelay(uint32_t micros)

-Delays for at least the number of microseconds specified by micros. -

micros: the number of microseconds to sleep


Returns the actual length of the delay in microseconds. -

Delays of 100 microseconds or less use busy waits. -

uint32_t gpioTick(void)

-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. -

You don't need to worry about the wrap around as long as you -take a tick (uint32_t) from another tick, i.e. the following -code will always provide the correct difference. -

Example

uint32_t startTick, endTick;
int diffTick;

startTick = gpioTick();

// do some processing

endTick = gpioTick();

diffTick = endTick - startTick;

printf("some processing took %d microseconds", diffTick);

unsigned gpioHardwareRevision(void)

-Returns the hardware revision. -

If the hardware revision can not be found or is not a valid hexadecimal -number the function returns 0. -

The hardware revision is the last few characters on the Revision line of -/proc/cpuinfo. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

for "Revision : 0002" the function returns 2.
-for "Revision : 000f" the function returns 15.
-for "Revision : 000g" the function returns 0. -

unsigned gpioVersion(void)

-Returns the pigpio version. -

int gpioGetPad(unsigned pad)

-This function returns the pad drive strength in mA. -

pad: 0-2, the pad to get


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = gpioGetPad(1); // get pad 1 strength

int gpioSetPad(unsigned pad, unsigned padStrength)

-This function sets the pad drive strength in mA. -

        pad: 0-2, the pad to set
padStrength: 1-16 mA


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

gpioSetPad(0, 16); // set pad 0 strength to 16 mA

int eventMonitor(unsigned handle, uint32_t bits)

-This function selects the events to be reported on a previously -opened handle. -

handle: >=0, as returned by gpioNotifyOpen
  bits: a bit mask indicating the events of interest


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

A report is sent each time an event is triggered providing the -corresponding bit in bits is set. -

See gpioNotifyBegin for the notification format. -

Example

// Start reporting events 3, 6, and 7.

//  bit      76543210
// (0xC8 = 0b11001000)

eventMonitor(h, 0xC8);

int eventSetFunc(unsigned event, eventFunc_t f)

-Registers a function to be called (a callback) when the specified -event occurs. -

event: 0-31
    f: the callback function


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

One function may be registered per event. -

The function is passed the event, and the tick. -

The callback may be cancelled by passing NULL as the function. -

int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)

-Registers a function to be called (a callback) when the specified -event occurs. -

   event: 0-31
       f: the callback function
userdata: pointer to arbitrary user data


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

One function may be registered per event. -

The function is passed the event, the tick, and the ueserdata pointer. -

The callback may be cancelled by passing NULL as the function. -

Only one of eventSetFunc or eventSetFuncEx can be -registered per event. -

int eventTrigger(unsigned event)

-This function signals the occurrence of an event. -

event: 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling eventSetFunc) will be informed by -a callback. -

One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

int shell(char *scriptName, char *scriptString)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name
scriptString: the string to pass to the script


The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. -

scriptName must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell("scr1", "\"hello string with spaces world\"");

int fileOpen(char *file, unsigned mode)

-This function returns a handle to a file opened in a specified mode. -

file: the file to open
mode: the file open mode


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


The following values may be or'd into the mode. -

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int handle, c;
   char buf[60000];

   if (gpioInitialise() < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   handle = fileOpen("/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=fileRead(handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      fileClose(handle);
   }

   gpioTerminate();
}

int fileClose(unsigned handle)

-This function closes the file associated with handle. -

handle: >=0, as returned by a call to fileOpen


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

fileClose(h);

int fileWrite(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the file -associated with handle. -

handle: >=0, as returned by a call to fileOpen
   buf: the array of bytes to write
 count: the number of bytes to write


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. -

Example

status = fileWrite(h, buf, count);
if (status == 0)
{
   // okay
}
else
{
   // error
}

int fileRead(unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the file -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to fileOpen
   buf: an array to receive the read data
 count: the maximum number of bytes to read


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. -

Example

if (fileRead(h, buf, sizeof(buf)) > 0)
{
   // process read data
}

int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)

-This function seeks to a position within the file associated -with handle. -

    handle: >=0, as returned by a call to fileOpen
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2)


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. -

Example

fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20

size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size

pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position

int fileList(char *fpat, char *buf, unsigned count)

-This function returns a list of files which match a pattern. The -pattern may contain wildcards. -

 fpat: file pattern to match
  buf: an array to receive the matching file names
count: the maximum number of bytes to read


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See fileOpen. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#include <stdio.h>
#include <pigpio.h>

int main(int argc, char *argv[])
{
   int c;
   char buf[1000];

   if (gpioInitialise() < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   c = fileList("/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      // terminate string
      buf[c] = 0;
      printf("%s", buf);
   }

   gpioTerminate();
}

int gpioCfgBufferSize(unsigned cfgMillis)

-Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. -

This function is only effective if called before gpioInitialise. -

cfgMillis: 100-10000


The default setting is 120 milliseconds. -

The intention is to allow for bursts of data and protection against -other processes hogging cpu time. -

I haven't seen a process locked out for more than 100 milliseconds. -

Making the buffer bigger uses a LOT of memory at the more frequent -sampling rates as shown in the following table in MBs. -

                     buffer milliseconds
               120 250 500 1sec 2sec 4sec 8sec

         1      16  31  55  107  ---  ---  ---
         2      10  18  31   55  107  ---  ---
sample   4       8  12  18   31   55  107  ---
 rate    5       8  10  14   24   45   87  ---
 (us)    8       6   8  12   18   31   55  107
        10       6   8  10   14   24   45   87

int gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)

-Configures pigpio to use a particular sample rate timed by a specified -peripheral. -

This function is only effective if called before gpioInitialise. -

    cfgMicros: 1, 2, 4, 5, 8, 10
cfgPeripheral: 0 (PWM), 1 (PCM)
    cfgSource: deprecated, value is ignored


The timings are provided by the specified peripheral (PWM or PCM). -

The default setting is 5 microseconds using the PCM peripheral. -

The approximate CPU percentage used for each sample rate is: -

sample  cpu
 rate    %

  1     25
  2     16
  4     11
  5     10
  8     15
 10     14


A sample rate of 5 microseconds seeems to be the sweet spot. -

int gpioCfgDMAchannel(unsigned DMAchannel)

-Configures pigpio to use the specified DMA channel. -

This function is only effective if called before gpioInitialise. -

DMAchannel: 0-14


The default setting is to use channel 14. -

int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)

-Configures pigpio to use the specified DMA channels. -

This function is only effective if called before gpioInitialise. -

  primaryChannel: 0-14
secondaryChannel: 0-14


The default setting depends on whether the Pi has a BCM2711 chip or -not (currently only the Pi4B has a BCM2711). -

The default setting for a non-BCM2711 is to use channel 14 for the -primary channel and channel 6 for the secondary channel. -

The default setting for a BCM2711 is to use channel 7 for the -primary channel and channel 6 for the secondary channel. -

The secondary channel is only used for the transmission of waves. -

If possible use one of channels 0 to 6 for the secondary channel -(a full channel). -

A full channel only requires one DMA control block regardless of the -length of a pulse delay. Channels 7 to 14 (lite channels) require -one DMA control block for each 16383 microseconds of delay. I.e. -a 10 second pulse delay requires one control block on a full channel -and 611 control blocks on a lite channel. -

int gpioCfgPermissions(uint64_t updateMask)

-Configures pigpio to restrict GPIO updates via the socket or pipe -interfaces to the GPIO specified by the mask. Programs directly -calling the pigpio library (i.e. linked with -lpigpio are not -affected). A GPIO update is a write to a GPIO or a GPIO mode -change or any function which would force such an action. -

This function is only effective if called before gpioInitialise. -

updateMask: bit (1<<n) is set for each GPIO n which may be updated


The default setting depends upon the Pi model. The user GPIO are -added to the mask. -

If the board revision is not recognised then GPIO 2-27 are allowed. -

Unknown boardPI_DEFAULT_UPDATE_MASK_UNKNOWN0x0FFFFFFC
Type 1 boardPI_DEFAULT_UPDATE_MASK_B10x03E6CF93
Type 2 boardPI_DEFAULT_UPDATE_MASK_A_B20xFBC6CF9C
Type 3 boardPI_DEFAULT_UPDATE_MASK_R30x0FFFFFFC

int gpioCfgSocketPort(unsigned port)

-Configures pigpio to use the specified socket port. -

This function is only effective if called before gpioInitialise. -

port: 1024-32000


The default setting is to use port 8888. -

int gpioCfgInterfaces(unsigned ifFlags)

-Configures pigpio support of the fifo and socket interfaces. -

This function is only effective if called before gpioInitialise. -

ifFlags: 0-7


The default setting (0) is that both interfaces are enabled. -

Or in PI_DISABLE_FIFO_IF to disable the pipe interface. -

Or in PI_DISABLE_SOCK_IF to disable the socket interface. -

Or in PI_LOCALHOST_SOCK_IF to disable remote socket -access (this means that the socket interface is only -usable from the local Pi). -

int gpioCfgMemAlloc(unsigned memAllocMode)

-Selects the method of DMA memory allocation. -

This function is only effective if called before gpioInitialise. -

memAllocMode: 0-2


There are two methods of DMA memory allocation. The original method -uses the /proc/self/pagemap file to allocate bus memory. The new -method uses the mailbox property interface to allocate bus memory. -

Auto will use the mailbox method unless a larger than default buffer -size is requested with gpioCfgBufferSize. -

int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)

-Sets the network addresses which are allowed to talk over the -socket interface. -

This function is only effective if called before gpioInitialise. -

numSockAddr: 0-256 (0 means all addresses allowed)
   sockAddr: an array of permitted network addresses.

int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)

-Used to tune internal settings. -

cfgWhat: see source code
 cfgVal: see source code

uint32_t gpioCfgGetInternals(void)

-This function returns the current library internal configuration -settings. -

int gpioCfgSetInternals(uint32_t cfgVal)

-This function sets the current library internal configuration -settings. -

cfgVal: see source code

int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from gpioCustom1 in that it returns an array of bytes -rather than just an integer. -

The returned value is an integer indicating the number of returned bytes. -  arg1: >=0
  argx: extra (byte) arguments
  argc: number of extra arguments
retBuf: buffer for returned bytes
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

The number of returned bytes must be retMax or less. -

int rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)

-This function adds a waveform representing SPI data to the -existing waveform (if any). -

        spi: a pointer to a spi object
     offset: microseconds from the start of the waveform
      spiSS: the slave select GPIO
        buf: the bits to transmit, most significant bit first
  spiTxBits: the number of bits to write
spiBitFirst: the first bit to read
 spiBitLast: the last bit to read
    spiBits: the number of bits to transfer


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. -

Not intended for general use. -

int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses
   pulses: the array containing the pulses


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The advantage of this function over gpioWaveAddGeneric is that it -allows the setting of the flags field. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist of a delay. -

Not intended for general use. -

unsigned rawWaveCB(void)

-Returns the number of the cb being currently output. -

Not intended for general use. -

rawCbs_t *rawWaveCBAdr(int cbNum)

-Return the (Linux) address of contol block cbNum. -

cbNum: the cb of interest


Not intended for general use. -

uint32_t rawWaveGetOOL(int pos)

-Gets the OOL parameter stored at pos. -

pos: the position of interest.


Not intended for general use. -

void rawWaveSetOOL(int pos, uint32_t lVal)

-Sets the OOL parameter stored at pos to value. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

uint32_t rawWaveGetOut(int pos)

-Gets the wave output parameter stored at pos. -

DEPRECATED: use rawWaveGetOOL instead. -

pos: the position of interest.


Not intended for general use. -

void rawWaveSetOut(int pos, uint32_t lVal)

-Sets the wave output parameter stored at pos to value. -

DEPRECATED: use rawWaveSetOOL instead. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

uint32_t rawWaveGetIn(int pos)

-Gets the wave input value parameter stored at pos. -

DEPRECATED: use rawWaveGetOOL instead. -

pos: the position of interest


Not intended for general use. -

void rawWaveSetIn(int pos, uint32_t lVal)

-Sets the wave input value stored at pos to value. -

DEPRECATED: use rawWaveSetOOL instead. -

 pos: the position of interest
lVal: the value to write


Not intended for general use. -

rawWaveInfo_t rawWaveInfo(int wave_id)

-Gets details about the wave with id wave_id. -

wave_id: the wave of interest


Not intended for general use. -

int getBitInBytes(int bitPos, char *buf, int numBits)

-Returns the value of the bit bitPos bits from the start of buf. Returns -0 if bitPos is greater than or equal to numBits. -

 bitPos: bit index from the start of buf
    buf: array of bits
numBits: number of valid bits in buf

void putBitInBytes(int bitPos, char *buf, int bit)

-Sets the bit bitPos bits from the start of buf to bit. -

bitPos: bit index from the start of buf
   buf: array of bits
   bit: 0-1, value to set

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds -

seconds: the number of seconds to sleep

void rawDumpWave(void)

-Used to print a readable version of the current waveform to stderr. -

Not intended for general use. -

void rawDumpScript(unsigned script_id)

-Used to print a readable version of a script to stderr. -

script_id: >=0, a script_id returned by gpioStoreScript


Not intended for general use. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bitPos

-A bit position within a byte or word. The least significant bit is -position 0. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

*bsc_xfer

-A pointer to a bsc_xfer_t object used to control a BSC transfer. -

bsc_xfer_t

-typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

cbNum

-A number identifying a DMA contol block. -

cfgMicros

-The GPIO sample rate in microseconds. The default is 5us, or 200 thousand -samples per second. -

cfgMillis: 100-10000

-The size of the sample buffer in milliseconds. Generally this should be -left at the default of 120ms. If you expect intense bursts of signals it -might be necessary to increase the buffer size. -

cfgPeripheral

-One of the PWM or PCM peripherals used to pace DMA transfers for timing -purposes. -

cfgSource

-Deprecated. -

cfgVal

-A number specifying the value of a configuration item. See cfgWhat. -

cfgWhat

-A number specifying a configuration item. -

562484977: print enhanced statistics at termination.
-984762879: set the initial debug level. -

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

-The hardware clock frequency. -

PI_HW_CLK_MIN_FREQ 4689
PI_HW_CLK_MAX_FREQ 250000000
PI_HW_CLK_MAX_FREQ_2711 375000000

count

-The number of bytes to be transferred in an I2C, SPI, or Serial -command. -

CS

-The GPIO used for the slave select signal when bit banging SPI. -

data_bits: 1-32

-The number of data bits to be used when adding serial data to a -waveform. -

PI_MIN_WAVE_DATABITS 1
PI_MAX_WAVE_DATABITS 32

DMAchannel: 0-15

-PI_MIN_DMA_CHANNEL 0
PI_MAX_DMA_CHANNEL 15

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge: 0-2

-The type of GPIO edge to generate an interrupt. See gpioSetISRFunc -and gpioSetISRFuncEx. -

RISING_EDGE 0
FALLING_EDGE 1
EITHER_EDGE 2

event: 0-31

-An event is a signal used to inform one or more consumers -to start an action. -

eventFunc_t

-typedef void (*eventFunc_t) (int event, uint32_t tick);

eventFuncEx_t

-typedef void (*eventFuncEx_t)
   (int event, uint32_t tick, void *userdata);

f

-A function. -

*file

-A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. -

*fpat

-A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 gpioHardwareRevision. -

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  -  -  -  -

gpioAlertFunc_t

-typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);

gpioAlertFuncEx_t

-typedef void (*eventFuncEx_t)
   (int event, int level, uint32_t tick, void *userdata);

gpioCfg*

-These functions are only effective if called before gpioInitialise. -

gpioCfgBufferSize
-gpioCfgClock
-gpioCfgDMAchannel
-gpioCfgDMAchannels
-gpioCfgPermissions
-gpioCfgInterfaces
-gpioCfgSocketPort
-gpioCfgMemAlloc -

gpioGetSamplesFunc_t

-typedef void (*gpioGetSamplesFunc_t)
   (const gpioSample_t *samples, int numSamples);

gpioGetSamplesFuncEx_t

-typedef void (*gpioGetSamplesFuncEx_t)
   (const gpioSample_t *samples, int numSamples, void *userdata);

gpioISRFunc_t

-typedef void (*gpioISRFunc_t)
   (int gpio, int level, uint32_t tick);

gpioISRFuncEx_t

-typedef void (*gpioISRFuncEx_t)
   (int gpio, int level, uint32_t tick, void *userdata);

gpioPulse_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioSample_t

-typedef struct
{
   uint32_t tick;
   uint32_t level;
} gpioSample_t;

gpioSignalFunc_t

-typedef void (*gpioSignalFunc_t) (int signum);

gpioSignalFuncEx_t

-typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

gpioTimerFunc_t

-typedef void (*gpioTimerFunc_t) (void);

gpioTimerFuncEx_t

-typedef void (*gpioTimerFuncEx_t) (void *userdata);

gpioWaveAdd*

-One of -

gpioWaveAddNew
-gpioWaveAddGeneric
-gpioWaveAddSerial -

handle: >=0

-A number referencing an object opened by one of -

fileOpen
-gpioNotifyOpen
-i2cOpen
-serOpen
-spiOpen -

i2cAddr: 0-0x7F

-The address of a device on the I2C bus. -

i2cBus: >=0

-An I2C bus number. -

i2cFlags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2cReg: 0-255

-A register of an I2C device. -

ifFlags: 0-3

-PI_DISABLE_FIFO_IF 1
PI_DISABLE_SOCK_IF 2

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

int32_t

-A 32-bit signed value. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See gpioSetWatchdog. -

PI_TIMEOUT 2

lVal: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)

-A 32-bit word value. -

memAllocMode: 0-2

-The DMA memory allocation mode. -

PI_MEM_ALLOC_AUTO    0
PI_MEM_ALLOC_PAGEMAP 1
PI_MEM_ALLOC_MAILBOX 2

*micros

-A value representing microseconds. -

micros

-A value representing microseconds. -

millis

-A value representing milliseconds. -

MISO

-The GPIO used for the MISO signal when bit banging SPI. -

mode

-1. The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. A file open mode. -

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


The following values can be or'd into the mode. -

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

-The GPIO used for the MOSI signal when bit banging SPI. -

numBits

-The number of bits stored in a buffer. -

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

numSegs

-The number of segments in a combined I2C transaction. -

numSockAddr

-The number of network addresses allowed to use the socket interface. -

0 means all addresses allowed. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

pad: 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

-The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

*param

-An array of script parameters. -

pctBOOL: 0-100

-percent On-Off-Level (OOL) buffer to consume for wave output. -

pctCB: 0-100

-the percent of all DMA control blocks to consume. -

pctTOOL: 0-100

-the percent of OOL buffer to consume for wave input (flags). -

pi_i2c_msg_t

-typedef struct
{
   uint16_t addr;  // slave address
   uint16_t flags;
   uint16_t len;   // msg length
   uint8_t  *buf;  // pointer to msg data
} pi_i2c_msg_t;

port: 1024-32000

-The port used to bind to the pigpio socket. Defaults to 8888. -

pos

-The position of an item. -

primaryChannel: 0-15

-The DMA channel used to time the sampling of GPIO and to time servo and -PWM pulses. -

*pth

-A thread identifier, returned by gpioStartThread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -

PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

-The hardware PWM frequency. -

PI_HW_PWM_MIN_FREQ 1
PI_HW_PWM_MAX_FREQ 125000000
PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

-PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

rawCbs_t

-typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
{
   unsigned long info;
   unsigned long src;
   unsigned long dst;
   unsigned long length;
   unsigned long stride;
   unsigned long next;
   unsigned long pad[2];
} rawCbs_t;

rawSPI_t

-typedef struct
{
   int clk;     // GPIO for clock
   int mosi;    // GPIO for MOSI
   int miso;    // GPIO for MISO
   int ss_pol;  // slave select off state
   int ss_us;   // delay after slave select
   int clk_pol; // clock off state
   int clk_pha; // clock phase
   int clk_us;  // clock micros
} rawSPI_t;

rawWave_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
   uint32_t flags;
} rawWave_t;

rawWaveInfo_t

-typedef struct
{
   uint16_t botCB;  // first CB used by wave
   uint16_t topCB;  // last CB used by wave
   uint16_t botOOL; // last OOL used by wave
   uint16_t topOOL; // first OOL used by wave
   uint16_t deleted;
   uint16_t numCB;
   uint16_t numBOOL;
   uint16_t numTOOL;
} rawWaveInfo_t;

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

SCLK

-The GPIO used for the SCLK signal when bit banging SPI. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by gpioStoreScript. -

*scriptName

-The name of a shell script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. -

*scriptString

-The string to be passed to a shell script to be executed. -

SDA

-The user GPIO to use for data when bit banging I2C. -

secondaryChannel: 0-6

-The DMA channel used to time output waveforms. -

*seconds

-A pointer to a uint32_t to store the second component of -a returned time. -

seconds

-The number of seconds. -

seekFrom

-PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

-The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). -

*segs

-An array of segments which make up a combined I2C transaction. -

serFlags

-Flags which modify a serial open command. None are currently defined. -

*sertty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

setting

-A value used to set a flag, 0 for false, non-zero for true. -

signum: 0-63

-PI_MIN_SIGNUM 0
PI_MAX_SIGNUM 63

size_t

-A standard type used to indicate the size of an object in bytes. -

*sockAddr

-An array of network addresses allowed to use the socket interface encoded -as 32 bit numbers. -

E.g. address 192.168.1.66 would be encoded as 0x4201a8c0. -

*spi

-A pointer to a rawSPI_t structure. -

spiBitFirst

-GPIO reads are made from spiBitFirst to spiBitLast. -

spiBitLast

-GPIO reads are made from spiBitFirst to spiBitLast. -

spiBits

-The number of bits to transfer in a raw SPI transaction. -

spiChan

-A SPI channel, 0-2. -

spiFlags

-See spiOpen and bbSPIOpen. -

spiSS

-The SPI slave select GPIO in a raw SPI transaction. -

spiTxBits

-The number of bits to transfer dring a raw SPI transaction -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (gpioGlitchFilter) or triggering -the active part of a noise filter (gpioNoiseFilter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

PI_MIN_WAVE_HALFSTOPBITS 2
PI_MAX_WAVE_HALFSTOPBITS 8

*str

-An array of characters. -

timeout

-A GPIO level change timeout in milliseconds. -

gpioSetWatchdog -PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000


gpioSetISRFunc and gpioSetISRFuncEx -<=0 cancel timeout
>0 timeout after specified milliseconds

timer

-PI_MIN_TIMER 0
PI_MAX_TIMER 9

timetype

-PI_TIME_RELATIVE 0
PI_TIME_ABSOLUTE 1

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

uint64_t: 0-(2^64)-1

-A 64-bit unsigned value. -

unsigned

-A whole number >= 0. -

updateMask

-A 64 bit mask indicating which GPIO may be written to by the user. -

If GPIO#n may be written then bit (1<<n) is set. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. -

In the calling function: -

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: -

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

-Denoting no parameter is required -

wave_id

-A number identifying a waveform created by gpioWaveCreate. -

wave_mode

-The mode determines if the waveform is sent once or cycles -repeatedly. The SYNC variants wait for the current waveform -to reach the end of a cycle or finish before starting the new -waveform. -

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

Socket Command Codes


#define PI_CMD_MODES  0
#define PI_CMD_MODEG  1
#define PI_CMD_PUD    2
#define PI_CMD_READ   3
#define PI_CMD_WRITE  4
#define PI_CMD_PWM    5
#define PI_CMD_PRS    6
#define PI_CMD_PFS    7
#define PI_CMD_SERVO  8
#define PI_CMD_WDOG   9
#define PI_CMD_BR1   10
#define PI_CMD_BR2   11
#define PI_CMD_BC1   12
#define PI_CMD_BC2   13
#define PI_CMD_BS1   14
#define PI_CMD_BS2   15
#define PI_CMD_TICK  16
#define PI_CMD_HWVER 17
#define PI_CMD_NO    18
#define PI_CMD_NB    19
#define PI_CMD_NP    20
#define PI_CMD_NC    21
#define PI_CMD_PRG   22
#define PI_CMD_PFG   23
#define PI_CMD_PRRG  24
#define PI_CMD_HELP  25
#define PI_CMD_PIGPV 26
#define PI_CMD_WVCLR 27
#define PI_CMD_WVAG  28
#define PI_CMD_WVAS  29
#define PI_CMD_WVGO  30
#define PI_CMD_WVGOR 31
#define PI_CMD_WVBSY 32
#define PI_CMD_WVHLT 33
#define PI_CMD_WVSM  34
#define PI_CMD_WVSP  35
#define PI_CMD_WVSC  36
#define PI_CMD_TRIG  37
#define PI_CMD_PROC  38
#define PI_CMD_PROCD 39
#define PI_CMD_PROCR 40
#define PI_CMD_PROCS 41
#define PI_CMD_SLRO  42
#define PI_CMD_SLR   43
#define PI_CMD_SLRC  44
#define PI_CMD_PROCP 45
#define PI_CMD_MICS  46
#define PI_CMD_MILS  47
#define PI_CMD_PARSE 48
#define PI_CMD_WVCRE 49
#define PI_CMD_WVDEL 50
#define PI_CMD_WVTX  51
#define PI_CMD_WVTXR 52
#define PI_CMD_WVNEW 53

#define PI_CMD_I2CO  54
#define PI_CMD_I2CC  55
#define PI_CMD_I2CRD 56
#define PI_CMD_I2CWD 57
#define PI_CMD_I2CWQ 58
#define PI_CMD_I2CRS 59
#define PI_CMD_I2CWS 60
#define PI_CMD_I2CRB 61
#define PI_CMD_I2CWB 62
#define PI_CMD_I2CRW 63
#define PI_CMD_I2CWW 64
#define PI_CMD_I2CRK 65
#define PI_CMD_I2CWK 66
#define PI_CMD_I2CRI 67
#define PI_CMD_I2CWI 68
#define PI_CMD_I2CPC 69
#define PI_CMD_I2CPK 70

#define PI_CMD_SPIO  71
#define PI_CMD_SPIC  72
#define PI_CMD_SPIR  73
#define PI_CMD_SPIW  74
#define PI_CMD_SPIX  75

#define PI_CMD_SERO  76
#define PI_CMD_SERC  77
#define PI_CMD_SERRB 78
#define PI_CMD_SERWB 79
#define PI_CMD_SERR  80
#define PI_CMD_SERW  81
#define PI_CMD_SERDA 82

#define PI_CMD_GDC   83
#define PI_CMD_GPW   84

#define PI_CMD_HC    85
#define PI_CMD_HP    86

#define PI_CMD_CF1   87
#define PI_CMD_CF2   88

#define PI_CMD_BI2CC 89
#define PI_CMD_BI2CO 90
#define PI_CMD_BI2CZ 91

#define PI_CMD_I2CZ  92

#define PI_CMD_WVCHA 93

#define PI_CMD_SLRI  94

#define PI_CMD_CGI   95
#define PI_CMD_CSI   96

#define PI_CMD_FG    97
#define PI_CMD_FN    98

#define PI_CMD_NOIB  99

#define PI_CMD_WVTXM 100
#define PI_CMD_WVTAT 101

#define PI_CMD_PADS  102
#define PI_CMD_PADG  103

#define PI_CMD_FO    104
#define PI_CMD_FC    105
#define PI_CMD_FR    106
#define PI_CMD_FW    107
#define PI_CMD_FS    108
#define PI_CMD_FL    109

#define PI_CMD_SHELL 110

#define PI_CMD_BSPIC 111
#define PI_CMD_BSPIO 112
#define PI_CMD_BSPIX 113

#define PI_CMD_BSCX  114

#define PI_CMD_EVM   115
#define PI_CMD_EVT   116

#define PI_CMD_PROCU 117
#define PI_CMD_WVCAP 118

Error Codes


#define PI_INIT_FAILED       -1 // gpioInitialise failed
#define PI_BAD_USER_GPIO     -2 // GPIO not 0-31
#define PI_BAD_GPIO          -3 // GPIO not 0-53
#define PI_BAD_MODE          -4 // mode not 0-7
#define PI_BAD_LEVEL         -5 // level not 0-1
#define PI_BAD_PUD           -6 // pud not 0-2
#define PI_BAD_PULSEWIDTH    -7 // pulsewidth not 0 or 500-2500
#define PI_BAD_DUTYCYCLE     -8 // dutycycle outside set range
#define PI_BAD_TIMER         -9 // timer not 0-9
#define PI_BAD_MS           -10 // ms not 10-60000
#define PI_BAD_TIMETYPE     -11 // timetype not 0-1
#define PI_BAD_SECONDS      -12 // seconds < 0
#define PI_BAD_MICROS       -13 // micros not 0-999999
#define PI_TIMER_FAILED     -14 // gpioSetTimerFunc failed
#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
#define PI_NO_ALERT_FUNC    -16 // DEPRECATED
#define PI_BAD_CLK_PERIPH   -17 // clock peripheral not 0-1
#define PI_BAD_CLK_SOURCE   -18 // DEPRECATED
#define PI_BAD_CLK_MICROS   -19 // clock micros not 1, 2, 4, 5, 8, or 10
#define PI_BAD_BUF_MILLIS   -20 // buf millis not 100-10000
#define PI_BAD_DUTYRANGE    -21 // dutycycle range not 25-40000
#define PI_BAD_DUTY_RANGE   -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
#define PI_BAD_SIGNUM       -22 // signum not 0-63
#define PI_BAD_PATHNAME     -23 // can't open pathname
#define PI_NO_HANDLE        -24 // no handle available
#define PI_BAD_HANDLE       -25 // unknown handle
#define PI_BAD_IF_FLAGS     -26 // ifFlags > 4
#define PI_BAD_CHANNEL      -27 // DMA channel not 0-15
#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15
#define PI_BAD_SOCKET_PORT  -28 // socket port not 1024-32000
#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15
#define PI_NOT_INITIALISED  -31 // function called before gpioInitialise
#define PI_INITIALISED      -32 // function called after gpioInitialise
#define PI_BAD_WAVE_MODE    -33 // waveform mode not 0-3
#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
#define PI_BAD_WAVE_BAUD    -35 // baud rate not 50-250K(RX)/50-1M(TX)
#define PI_TOO_MANY_PULSES  -36 // waveform has too many pulses
#define PI_TOO_MANY_CHARS   -37 // waveform has too many chars
#define PI_NOT_SERIAL_GPIO  -38 // no bit bang serial read on GPIO
#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
#define PI_BAD_SERIAL_BUF   -40 // bad (null) serial buf parameter
#define PI_NOT_PERMITTED    -41 // GPIO operation not permitted
#define PI_SOME_PERMITTED   -42 // one or more GPIO not permitted
#define PI_BAD_WVSC_COMMND  -43 // bad WVSC subcommand
#define PI_BAD_WVSM_COMMND  -44 // bad WVSM subcommand
#define PI_BAD_WVSP_COMMND  -45 // bad WVSP subcommand
#define PI_BAD_PULSELEN     -46 // trigger pulse length not 1-100
#define PI_BAD_SCRIPT       -47 // invalid script
#define PI_BAD_SCRIPT_ID    -48 // unknown script id
#define PI_BAD_SER_OFFSET   -49 // add serial data offset > 30 minutes
#define PI_GPIO_IN_USE      -50 // GPIO already in use
#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
#define PI_BAD_PARAM_NUM    -52 // script parameter id not 0-9
#define PI_DUP_TAG          -53 // script has duplicate tag
#define PI_TOO_MANY_TAGS    -54 // script has too many tags
#define PI_BAD_SCRIPT_CMD   -55 // illegal script command
#define PI_BAD_VAR_NUM      -56 // script variable id not 0-149
#define PI_NO_SCRIPT_ROOM   -57 // no more room for scripts
#define PI_NO_MEMORY        -58 // can't allocate temporary memory
#define PI_SOCK_READ_FAILED -59 // socket read failed
#define PI_SOCK_WRIT_FAILED -60 // socket write failed
#define PI_TOO_MANY_PARAM   -61 // too many script parameters (> 10)
#define PI_NOT_HALTED       -62 // DEPRECATED
#define PI_SCRIPT_NOT_READY -62 // script initialising
#define PI_BAD_TAG          -63 // script has unresolved tag
#define PI_BAD_MICS_DELAY   -64 // bad MICS delay (too large)
#define PI_BAD_MILS_DELAY   -65 // bad MILS delay (too large)
#define PI_BAD_WAVE_ID      -66 // non existent wave id
#define PI_TOO_MANY_CBS     -67 // No more CBs for waveform
#define PI_TOO_MANY_OOL     -68 // No more OOL for waveform
#define PI_EMPTY_WAVEFORM   -69 // attempt to create an empty waveform
#define PI_NO_WAVEFORM_ID   -70 // no more waveforms
#define PI_I2C_OPEN_FAILED  -71 // can't open I2C device
#define PI_SER_OPEN_FAILED  -72 // can't open serial device
#define PI_SPI_OPEN_FAILED  -73 // can't open SPI device
#define PI_BAD_I2C_BUS      -74 // bad I2C bus
#define PI_BAD_I2C_ADDR     -75 // bad I2C address
#define PI_BAD_SPI_CHANNEL  -76 // bad SPI channel
#define PI_BAD_FLAGS        -77 // bad i2c/spi/ser open flags
#define PI_BAD_SPI_SPEED    -78 // bad SPI speed
#define PI_BAD_SER_DEVICE   -79 // bad serial device name
#define PI_BAD_SER_SPEED    -80 // bad serial baud rate
#define PI_BAD_PARAM        -81 // bad i2c/spi/ser parameter
#define PI_I2C_WRITE_FAILED -82 // i2c write failed
#define PI_I2C_READ_FAILED  -83 // i2c read failed
#define PI_BAD_SPI_COUNT    -84 // bad SPI count
#define PI_SER_WRITE_FAILED -85 // ser write failed
#define PI_SER_READ_FAILED  -86 // ser read failed
#define PI_SER_READ_NO_DATA -87 // ser read no data available
#define PI_UNKNOWN_COMMAND  -88 // unknown command
#define PI_SPI_XFER_FAILED  -89 // spi xfer/read/write failed
#define PI_BAD_POINTER      -90 // bad (NULL) pointer
#define PI_NO_AUX_SPI       -91 // no auxiliary SPI on Pi A or B
#define PI_NOT_PWM_GPIO     -92 // GPIO is not in use for PWM
#define PI_NOT_SERVO_GPIO   -93 // GPIO is not in use for servo pulses
#define PI_NOT_HCLK_GPIO    -94 // GPIO has no hardware clock
#define PI_NOT_HPWM_GPIO    -95 // GPIO has no hardware PWM
#define PI_BAD_HPWM_FREQ    -96 // invalid hardware PWM frequency
#define PI_BAD_HPWM_DUTY    -97 // hardware PWM dutycycle not 0-1M
#define PI_BAD_HCLK_FREQ    -98 // invalid hardware clock frequency
#define PI_BAD_HCLK_PASS    -99 // need password to use hardware clock 1
#define PI_HPWM_ILLEGAL    -100 // illegal, PWM in use for main clock
#define PI_BAD_DATABITS    -101 // serial data bits not 1-32
#define PI_BAD_STOPBITS    -102 // serial (half) stop bits not 2-8
#define PI_MSG_TOOBIG      -103 // socket/pipe message too big
#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode
#define PI_TOO_MANY_SEGS   -105 // too many I2C transaction segments
#define PI_BAD_I2C_SEG     -106 // an I2C transaction segment failed
#define PI_BAD_SMBUS_CMD   -107 // SMBus command not supported by driver
#define PI_NOT_I2C_GPIO    -108 // no bit bang I2C in progress on GPIO
#define PI_BAD_I2C_WLEN    -109 // bad I2C write length
#define PI_BAD_I2C_RLEN    -110 // bad I2C read length
#define PI_BAD_I2C_CMD     -111 // bad I2C command
#define PI_BAD_I2C_BAUD    -112 // bad I2C baud rate, not 50-500k
#define PI_CHAIN_LOOP_CNT  -113 // bad chain loop count
#define PI_BAD_CHAIN_LOOP  -114 // empty chain loop
#define PI_CHAIN_COUNTER   -115 // too many chain counters
#define PI_BAD_CHAIN_CMD   -116 // bad chain command
#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
#define PI_CHAIN_NESTING   -118 // chain counters nested too deeply
#define PI_CHAIN_TOO_BIG   -119 // chain is too long
#define PI_DEPRECATED      -120 // deprecated function removed
#define PI_BAD_SER_INVERT  -121 // bit bang serial invert not 0 or 1
#define PI_BAD_EDGE        -122 // bad ISR edge value, not 0-2
#define PI_BAD_ISR_INIT    -123 // bad ISR initialisation
#define PI_BAD_FOREVER     -124 // loop forever must be last command
#define PI_BAD_FILTER      -125 // bad filter parameter
#define PI_BAD_PAD         -126 // bad pad number
#define PI_BAD_STRENGTH    -127 // bad pad drive strength
#define PI_FIL_OPEN_FAILED -128 // file open failed
#define PI_BAD_FILE_MODE   -129 // bad file mode
#define PI_BAD_FILE_FLAG   -130 // bad file flag
#define PI_BAD_FILE_READ   -131 // bad file read
#define PI_BAD_FILE_WRITE  -132 // bad file write
#define PI_FILE_NOT_ROPEN  -133 // file not open for read
#define PI_FILE_NOT_WOPEN  -134 // file not open for write
#define PI_BAD_FILE_SEEK   -135 // bad file seek
#define PI_NO_FILE_MATCH   -136 // no files match pattern
#define PI_NO_FILE_ACCESS  -137 // no permission to access file
#define PI_FILE_IS_A_DIR   -138 // file is a directory
#define PI_BAD_SHELL_STATUS -139 // bad shell return status
#define PI_BAD_SCRIPT_NAME -140 // bad script name
#define PI_BAD_SPI_BAUD    -141 // bad SPI baud rate, not 50-500k
#define PI_NOT_SPI_GPIO    -142 // no bit bang SPI in progress on GPIO
#define PI_BAD_EVENT_ID    -143 // bad event id
#define PI_CMD_INTERRUPTED -144 // Used by Python
#define PI_NOT_ON_BCM2711  -145 // not available on BCM2711
#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711

#define PI_PIGIF_ERR_0    -2000
#define PI_PIGIF_ERR_99   -2099

#define PI_CUSTOM_ERR_0   -3000
#define PI_CUSTOM_ERR_999 -3999

Defaults


#define PI_DEFAULT_BUFFER_MILLIS           120
#define PI_DEFAULT_CLK_MICROS              5
#define PI_DEFAULT_CLK_PERIPHERAL          PI_CLOCK_PCM
#define PI_DEFAULT_IF_FLAGS                0
#define PI_DEFAULT_FOREGROUND              0
#define PI_DEFAULT_DMA_CHANNEL             14
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL     14
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL   6
#define PI_DEFAULT_DMA_PRIMARY_CH_2711     7
#define PI_DEFAULT_DMA_SECONDARY_CH_2711   6
#define PI_DEFAULT_DMA_NOT_SET             15
#define PI_DEFAULT_SOCKET_PORT             8888
#define PI_DEFAULT_SOCKET_PORT_STR         "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR         "localhost"
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN     0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_B1          0x03E7CF93
#define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_ZERO        0x0080000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI2B        0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI3B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI4B        0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_COMPUTE     0x00FFFFFFFFFFFFLL
#define PI_DEFAULT_MEM_ALLOC_MODE          PI_MEM_ALLOC_AUTO

#define PI_DEFAULT_CFG_INTERNALS           0

\ No newline at end of file diff --git a/DOC/tmp/body/download.body b/DOC/tmp/body/download.body deleted file mode 100644 index cdabc9a..0000000 --- a/DOC/tmp/body/download.body +++ /dev/null @@ -1,57 +0,0 @@ - -If the pigpio daemon is running it should be killed (sudo killall -pigpiod) before make install and restarted afterwards (sudo -pigpiod).
-
-The initial part of the make, the -compilation of pigpio.c, takes 100 seconds on early model -Pis.  Be patient.  The overall install takes just over 3 -minutes.
-

Download and install (V75)

-wget https://github.com/joan2937/pigpio/archive/v75.zip
-unzip v75.zip
-cd pigpio-75
-make
-sudo make install

-
-If the Python part of the install fails it may be because you need -the setup tools.
-
-sudo apt install python-setuptools -python3-setuptools

-
-

To check the library

-These tests make extensive use of GPIO 25 (pin 22).  Make sure -nothing, or only a LED, is connected to the GPIO before running the -tests.  Most tests are statistical in nature and so may on -occasion fail.  Repeated failures on the same test or many -failures in a group of tests indicate a problem.
-
-sudo ./x_pigpio # check C I/F
-
-sudo pigpiod    # start daemon
-
-./x_pigpiod_if2 # check C      I/F to -daemon
-./x_pigpio.py   # check Python I/F to daemon
-./x_pigs        # check -pigs   I/F to daemon
-./x_pipe        # check -pipe   I/F to daemon
-
-
-

To compile, link, and run a C program

-gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
-sudo ./foobar


-

To start the pigpio daemon

-sudo pigpiod
-

To stop the pigpio daemon

-sudo killall pigpiod

-

github

-git clone https://github.com/joan2937/pigpio
-

Raspbian (raspberrypi.org image)

-

This may not be the most recent version.  You can check the -version with the command pigpiod -v.

-sudo apt-get update
-sudo apt-get install pigpio python-pigpio python3-pigpio

-
diff --git a/DOC/tmp/body/ex_LDR.body b/DOC/tmp/body/ex_LDR.body deleted file mode 100644 index 1b1911a..0000000 --- a/DOC/tmp/body/ex_LDR.body +++ /dev/null @@ -1,141 +0,0 @@ - -

The following code shows a method of reading analogue sensors on -the digital input only Pi.  A Light Dependent Resistor (LDR) -varies its resistance according to the incident light -intensisty.

-

SETUP

-fritzing diagramThe LDR -used is a Cadmium Sulphide device with a 1MOhm dark resistance and -2-4KOhm at 100 lux.  The capacitor is a 104 -ceramic.
-
-One end of the capacitor is connected to Pi ground.
-
-One end of the LDR is connected to Pi 3V3.
-
-The other ends of the capacitor and LDR are connected to a spare -gpio.

-

Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18 -(P1-12) is used for the gpio.

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/* ------------------------------------------------------------------------
- -
-   3V3 ----- Light Dependent Resistor --+-- Capacitor ------ Ground
-                                        -|
-                                        -+-- gpio
-
-
-  cc -o LDR LDR.c -lpigpio -lpthread -lrt
-  sudo ./LDR
-
-*/
-
-#define LDR 18
-
-/* forward declaration */
-
-void alert(int pin, int level, uint32_t tick);
-
-int main (int argc, char *argv[])
-{
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetAlertFunc(LDR, alert); /* call alert when LDR -changes state */
-    
-   while (1)
-   {
-      gpioSetMode(LDR, PI_OUTPUT); /* -drain capacitor */
-
-      gpioWrite(LDR, PI_OFF);
-
-      gpioDelay(200); /* 50 micros is -enough, 200 is overkill */
-
-      gpioSetMode(LDR, PI_INPUT); /* start -capacitor recharge */
-
-      gpioDelay(10000); /* nominal 100 -readings per second */
-   }
-
-   gpioTerminate();
-}
-
-void alert(int pin, int level, uint32_t tick)
-{
-   static uint32_t inited = 0;
-   static uint32_t lastTick, firstTick;
-
-   uint32_t diffTick;
-
-   if (inited)
-   {
-      diffTick = tick - lastTick;
-      lastTick = tick;
-
-      if (level == 1) printf("%u %d\ ", -tick-firstTick, diffTick);
-   }
-   else
-   {
-      inited = 1;
-      firstTick = tick;
-      lastTick = firstTick;
-   }
-}
-

BUILD

-cc -o LDR LDR.c -lpigpio -lrt -lpthread
-

RUN

-sudo ./LDR >LDR.dat &
-
-While the program is running you can capture the waveform using the -notification feature built in to pigpio.  Issue the following -commands on the Pi.
-
-pigs no
-pig2vcd  </dev/pigpio0 >LDR.vcd &
-pigs nb 0 0x40000 # set bit for gpio 18
-

Change the light falling on the LDR for a few seconds (e.g. -shine a torch on it or shade it with your hands).

-pigs nc 0
-

The file LDR.vcd will contain the captured waveform, which can -be viewed using GTKWave.

-

Overview

-LDR waveform 1
-

Reading circa every 10ms

-LDR waveform 2
-

One reading, circa 400us

-LDR waveform 3
-

The file LDR.dat will contain pairs of timestamps and recharge -time (in us).  The following  script will convert the -timestamps into seconds.

-

awk '{print $1/1000000, $2}' LDR.dat ->LDR-secs.dat

-

Gnuplot is a useful tool to graph data.

-plot [14:24] 'LDR-secs.dat' with lines title 'LDR' -

Gnuplot readings 14-24 seconds

-

gnuplot 1

-plot [18:21] 'LDR-secs.dat' with lines title 'LDR'
-
-Gnuplot readings 18-21 seconds -

Gnuplot 2

diff --git a/DOC/tmp/body/ex_ir_remote.body b/DOC/tmp/body/ex_ir_remote.body deleted file mode 100644 index cebc97f..0000000 --- a/DOC/tmp/body/ex_ir_remote.body +++ /dev/null @@ -1,244 +0,0 @@ - -

The following code shows one way to read an infrared remote -control device (the sort used in TVs and stereo systems).

-

SETUP

-fritzing diagramThe device used -is a SFH5110 (IR Receiver for remote control, -carrier 38 kHz).
-
Pin 1 (left from front) may be connected to any spare -gpio.  Here it's connected via a 4K7 current limiting -resistor.  This isn't really needed as the device has an -internal 23K resistor in-line.  It does no harm though.
-
-Pin 2 should be connected to a Pi ground pin.
-
-Pin 3 should be connected to a Pi 5V pin.
-

Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground -(P1-14), and pin 3 to 5V (P1-2).

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-#define IR_PIN 7
-
-#define OUTSIDE_CODE 0
-#define INSIDE_CODE  1
-
-#define MIN_MESSAGE_GAP 3000
-#define MAX_MESSAGE_END 3000
-
-#define MAX_TRANSITIONS 500
-
-/*
-   using the FNV-1a -hash                
- -   from -http://isthe.com/chongo/tech/comp/fnv/#FNV-param
-*/
-
-#define FNV_PRIME_32 16777619
-#define FNV_BASIS_32 2166136261U
-
-static volatile uint32_t ir_hash = 0;
-
-typedef struct
-{
-   int state;
-   int count;
-   int level;
-   uint16_t micros[MAX_TRANSITIONS];
-} decode_t;
-
-/* forward declarations */
-
-void     alert(int gpio, int level, uint32_t -tick);
-uint32_t getHash(decode_t * decode);
-void     updateState(decode_t * decode, int -level, uint32_t micros);
-
-int main(int argc, char * argv[])
-{
-   if (gpioInitialise()<0)
-   {
-      return 1 ;
-   }
-
-   /* IR pin as input */
-
-   gpioSetMode(IR_PIN, PI_INPUT);
-
-   /* 5ms max gap after last pulse */
-
-   gpioSetWatchdog(IR_PIN, 5);
-
-   /* monitor IR level changes */
-
-   gpioSetAlertFunc(IR_PIN, alert);
-
-   while (1)
-   {
-      if (ir_hash)
-      {
-         /* non-zero means -new decode */
-         printf("ir code is -%u\ ", ir_hash);
-         ir_hash = 0;
-      }
-
-      gpioDelay(100000); /* check remote -10 times per second */
-   }
-
-   gpioTerminate();
-}
-
-void alert(int gpio, int level, uint32_t tick)
-{
-   static int inited = 0;
-
-   static decode_t activeHigh, activeLow;
-
-   static uint32_t lastTick;
-
-   uint32_t diffTick;
-
-   if (!inited)
-   {
-      inited = 1;
-
-      activeHigh.state = OUTSIDE_CODE; -activeHigh.level = PI_LOW;
-      activeLow.state  = -OUTSIDE_CODE; activeLow.level  = PI_HIGH;
-
-      lastTick = tick;
-      return;
-   }
-
-   diffTick = tick - lastTick;
-
-   if (level != PI_TIMEOUT) lastTick = tick;
-
-   updateState(&activeHigh, level, diffTick);
-   updateState(&activeLow, level, diffTick);
-}
-
-void updateState(decode_t * decode, int level, uint32_t micros)
-{
-   /*
-      We are dealing with active high as -well as active low
-      remotes.  Abstract the common -functionality.
-   */
-
-   if (decode->state == OUTSIDE_CODE)
-   {
-      if (level == decode->level)
-      {
-         if (micros > -MIN_MESSAGE_GAP)
-         {
-            -decode->state = INSIDE_CODE;
-            -decode->count = 0;
-         }
-      }
-   }
-   else
-   {
-      if (micros > MAX_MESSAGE_END)
-      {
-         /* end of message -*/
-
-         /* ignore if last -code not consumed */
-
-         if (!ir_hash) -ir_hash = getHash(decode);
-
-         decode->state = -OUTSIDE_CODE;
-      }
-      else
-      {
-         if -(decode->count < (MAX_TRANSITIONS-1))
-         {
-            -if (level != PI_TIMEOUT)
-               -decode->micros[decode->count++] = micros;
-         }
-      }
-   }
-}
-
-int compare(unsigned int oldval, unsigned int newval)
-{
-   if      (newval < (oldval -* 0.75)) {return 1;}
-   else if (oldval < (newval * 0.75)) {return 2;}
-   -else                               -{return 4;}
-}
-
-uint32_t getHash(decode_t * decode)
-{
-   /* use FNV-1a */
-
-   uint32_t hash;
-   int i, value;
-
-   if (decode->count < 6) {return 0;}
-
-   hash = FNV_BASIS_32;
-
-   for (i=0; i<(decode->count-2); i++)
-   {
-      value = -compare(decode->micros[i], decode->micros[i+2]);
-
-      hash = hash ^ value;
-      hash = (hash * FNV_PRIME_32);
-   }
-
-   return hash;
-}
-

BUILD

-cc -o ir_remote ir_remote.c -lpigpio -lrt --lpthread
-

RUN

-sudo ./ir_remote
-

A hash code is formed from the level transitions detected during -a remote key press.  This is likely to be unique over multiple -remotes and keys.

-

While the program is running you can capture the waveform using -the notification feature built in to pigpio.  Issue the -following commands on the Pi.

-pigs no
-pig2vcd  </dev/pigpio0 >ir.vcd &
-pigs nb 0 0x80 # set bits for gpios 7 (0x80)
-

Press a few different remotes and keys.  Then enter

-pigs nc 0
-

The file ir.vcd will contain the captured waveform, which can be -viewed using GTKWave.

-

Overview

-ir remote waveform 1
-

Remote A typical waveform

-ir remote waveform 2
-

Remote B typical waveform

--"ir diff --git a/DOC/tmp/body/ex_motor_shield.body b/DOC/tmp/body/ex_motor_shield.body deleted file mode 100644 index fbadb3a..0000000 --- a/DOC/tmp/body/ex_motor_shield.body +++ /dev/null @@ -1,245 +0,0 @@ - -The following example demonstrates the use of an Arduino shield -from the Rasperry Pi.
-
-The shield used is a clone of the Adafruit motor shield.  See -shieldlist.org -for details.
-
-For the demonstration DC motors 3 and 4 are being driven forwards -and backwards with changing speeds (speeds are controlled via -PWM).
-
-Seven connections are made between the Pi and the shield.  -Four to latch the motor states (latch, enable, data, clock); Two to -control motor speed (PWM 3 and 4); and ground.
-
-The code used was ported from the Adafruit Arduino code and -converted to use the pigpio library.  Only the DC motor code -was ported.
-
-A video of the shield in use is available at youtube.com
-
-#include <stdio.h>

-
-#include <pigpio.h>
-
-/*
-   This code may be used to drive the Adafruit (or -clones) Motor Shield.
-
-   The code as written only supports DC motors.
-
-   http://shieldlist.org/adafruit/motor
-
-   The shield pinouts are
-
-   D12 MOTORLATCH
-   D11 PMW motor 1
-   D10 Servo 1
-   D9  Servo 2
-   D8  MOTORDATA
-
-   D7  MOTORENABLE
-   D6  PWM motor 4
-   D5  PWM motor 3
-   D4  MOTORCLK
-   D3  PWM motor 2
-
-   The motor states (forward, backward, brake, release) -are encoded using the
-   MOTOR_ latch pins.  This saves four gpios.
-*/
-
-typedef unsigned char uint8_t;
-
-#define BIT(bit) (1 << (bit))
-
-/* assign gpios to drive the shield pins */
-
-/*      -Shield      Pi */
-
-#define MOTORLATCH  14
-#define MOTORCLK    24
-#define MOTORENABLE 25
-#define MOTORDATA   15
-
-#define MOTOR_3_PWM  7
-#define MOTOR_4_PWM  8
-
-/*
-   The only other connection needed between the Pi and -the shield
-   is ground to ground. I used Pi P1-6 to shield gnd -(next to D13).
-*/
-
-/* assignment of motor states to latch */
-
-#define MOTOR1_A 2
-#define MOTOR1_B 3
-#define MOTOR2_A 1
-#define MOTOR2_B 4
-#define MOTOR4_A 0
-#define MOTOR4_B 6
-#define MOTOR3_A 5
-#define MOTOR3_B 7
-
-#define FORWARD  1
-#define BACKWARD 2
-#define BRAKE    3
-#define RELEASE  4
-
-static uint8_t latch_state;
-
-void latch_tx(void)
-{
-   unsigned char i;
-
-   gpioWrite(MOTORLATCH, PI_LOW);
-
-   gpioWrite(MOTORDATA, PI_LOW);
-
-   for (i=0; i<8; i++)
-   {
-      gpioDelay(10);  // 10 micros -delay
-
-      gpioWrite(MOTORCLK, PI_LOW);
-
-      if (latch_state & BIT(7-i)) -gpioWrite(MOTORDATA, PI_HIGH);
-      -else                        -gpioWrite(MOTORDATA, PI_LOW);
-
-      gpioDelay(10);  // 10 micros -delay
-
-      gpioWrite(MOTORCLK, PI_HIGH);
-   }
-
-   gpioWrite(MOTORLATCH, PI_HIGH);
-}
-
-void init(void)
-{
-   latch_state = 0;
-
-   latch_tx();
-
-   gpioWrite(MOTORENABLE, PI_LOW);
-}
-
-void DCMotorInit(uint8_t num)
-{
-   switch (num)
-   {
-      case 1: latch_state &= -~BIT(MOTOR1_A) & ~BIT(MOTOR1_B); break;
-      case 2: latch_state &= -~BIT(MOTOR2_A) & ~BIT(MOTOR2_B); break;
-      case 3: latch_state &= -~BIT(MOTOR3_A) & ~BIT(MOTOR3_B); break;
-      case 4: latch_state &= -~BIT(MOTOR4_A) & ~BIT(MOTOR4_B); break;
-      default: return;
-   }
-
-   latch_tx();
-
-   printf("Latch=%08X\ ", latch_state);
-}
-
-void DCMotorRun(uint8_t motornum, uint8_t cmd)
-{
-   uint8_t a, b;
-
-   switch (motornum)
-   {
-      case 1: a = MOTOR1_A; b = MOTOR1_B; -break;
-      case 2: a = MOTOR2_A; b = MOTOR2_B; -break;
-      case 3: a = MOTOR3_A; b = MOTOR3_B; -break;
-      case 4: a = MOTOR4_A; b = MOTOR4_B; -break;
-      default: return;
-   }

-   switch (cmd)
-   {
-      case FORWARD:  latch_state -|=  BIT(a); latch_state &= ~BIT(b); break;
-      case BACKWARD: latch_state &= -~BIT(a); latch_state |=  BIT(b); break;
-      case RELEASE:  latch_state -&= ~BIT(a); latch_state &= ~BIT(b); break;
-      default: return;
-   }
-
-   latch_tx();
-
-   printf("Latch=%08X\ ", latch_state);
-}
-
-int main (int argc, char *argv[])
-{
-   int i;
-
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(MOTORLATCH,  PI_OUTPUT);
-   gpioSetMode(MOTORENABLE, PI_OUTPUT);
-   gpioSetMode(MOTORDATA,   PI_OUTPUT);
-   gpioSetMode(MOTORCLK,    -PI_OUTPUT);
-
-   gpioSetMode(MOTOR_3_PWM, PI_OUTPUT);
-   gpioSetMode(MOTOR_4_PWM, PI_OUTPUT);
-
-   gpioPWM(MOTOR_3_PWM, 0);
-   gpioPWM(MOTOR_4_PWM, 0);
-
-   init();
-
-   for (i=60; i<160; i+=20)
-   {
-      gpioPWM(MOTOR_3_PWM, i);
-      gpioPWM(MOTOR_4_PWM, 220-i);
-
-      DCMotorRun(3, FORWARD);
-      DCMotorRun(4, BACKWARD);
-
-      sleep(2);
-
-      DCMotorRun(3, RELEASE);
-      DCMotorRun(4, RELEASE);
-
-      sleep(2);
-
-      gpioPWM(MOTOR_4_PWM, i);
-      gpioPWM(MOTOR_3_PWM, 220-i);
-
-      DCMotorRun(3, BACKWARD);
-      DCMotorRun(4, FORWARD);
-
-      sleep(2);
-
-      DCMotorRun(3, RELEASE);
-      DCMotorRun(4, RELEASE);
-
-      sleep(2);
-   }
-
-   gpioPWM(MOTOR_4_PWM, 0);
-   gpioPWM(MOTOR_3_PWM, 0);
-
-   DCMotorRun(3, RELEASE);
-   DCMotorRun(4, RELEASE);
-
-   gpioTerminate();
-}
diff --git a/DOC/tmp/body/ex_rotary_encoder.body b/DOC/tmp/body/ex_rotary_encoder.body deleted file mode 100644 index f399e29..0000000 --- a/DOC/tmp/body/ex_rotary_encoder.body +++ /dev/null @@ -1,176 +0,0 @@ - -

The following code shows one way to read an incremental -mechanical rotary enoder (the sort used for volume control in audio -systems).  These rotary encoders have two switches A and B -which return a quadrature output, i.e. they are 90 degrees out of -phase.

-

SETUP

-fritzing diagramThe common -(centre) terminal should be connected to a Pi ground. -

The A and B terminals may be connected to any spare gpios.

-

Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7 -(P1-26).

-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/*
-   Rotary encoder connections:
-
-   Encoder A      - gpio -18   (pin P1-12)
-   Encoder B      - gpio -7    (pin P1-26)
-   Encoder Common - Pi ground (pin P1-20)
-*/
-
-#define ENCODER_A 18
-#define ENCODER_B  7
-
-static volatile int encoderPos;
-
-/* forward declaration */
-
-void encoderPulse(int gpio, int lev, uint32_t tick);
-
-int main(int argc, char * argv[])
-{
-   int pos=0;
-
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(ENCODER_A, PI_INPUT);
-   gpioSetMode(ENCODER_B, PI_INPUT);
-
-   /* pull up is needed as encoder common is grounded -*/
-
-   gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);
-   gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);
-
-   encoderPos = pos;
-
-   /* monitor encoder level changes */
-
-   gpioSetAlertFunc(ENCODER_A, encoderPulse);
-   gpioSetAlertFunc(ENCODER_B, encoderPulse);
-
-   while (1)
-   {
-      if (pos != encoderPos)
-      {
-         pos = -encoderPos;
-         printf("pos=%d\ ", -pos);
-      }
-      gpioDelay(20000); /* check pos 50 -times per second */
-   }
-
-   gpioTerminate();
-}
-
-void encoderPulse(int gpio, int level, uint32_t tick)
-{
-   /*
-
-             -+---------+         -+---------+      0
-             -|         -|         -|         |
-   A         -|         -|         -|         |
-             -|         -|         -|         |
-   -+---------+         -+---------+         +----- -1
-
-       -+---------+         -+---------+            -0
-       -|         -|         -|         |
-   B   -|         -|         -|         |
-       -|         -|         -|         |
-   ----+         -+---------+         -+---------+  1
-
-   */
-
-   static int levA=0, levB=0, lastGpio = -1;
-
-   if (gpio == ENCODER_A) levA = level; else levB = -level;
-
-   if (gpio != lastGpio) /* debounce */
-   {
-      lastGpio = gpio;
-
-      if ((gpio == ENCODER_A) && -(level == 0))
-      {
-         if (!levB) -++encoderPos;
-      }
-      else if ((gpio == ENCODER_B) -&& (level == 1))
-      {
-         if (levA) ---encoderPos;
-      }
-   }
-}
-

BUILD

-cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt --lpthread
-

RUN

-sudo ./rotary_encoder
-

While the program is running you can capture the waveform using -the notification feature built in to pigpio.  Issue the -following commands on the Pi.

-pigs no
-pig2vcd  </dev/pigpio0 >re.vcd &
-pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18 -(0x40000)
-

Twiddle the rotary encoder forwards and backwards for a few -seconds.  Then enter

-pigs nc 0
-

The file re.vcd will contain the captured waveform, which can be -viewed using GTKWave.

-
-Overview
-
--"rotary
-
-Detail of switch bounce.  Contact A bounces for circa 700 us -before completing the level transition
-
--"rotary
diff --git a/DOC/tmp/body/ex_sonar_ranger.body b/DOC/tmp/body/ex_sonar_ranger.body deleted file mode 100644 index 8b3de67..0000000 --- a/DOC/tmp/body/ex_sonar_ranger.body +++ /dev/null @@ -1,155 +0,0 @@ - -

The following code shows a method of reading a class of sonar -rangers.  These rangers requires a trigger pulse.  -Shortly after receiving a trigger they transmit a noise pulse and -set the echo line high.  When the echo is received the echo -line is set low.

-

SETUP

-fritzing diagram
-
-
-
-
-The ranger used is a SRF05 (check the pinouts, there are many -variants).
-
-The fritzing diagram shows the back of the ranger, i.e. pin 1 is -the rightmost.
-
-Pin 1 is 5V.
-Pin 2 is the trigger line.
-Pin 3 is the echo line.
-Pin 4 is out (unused).
-Pin 5 is ground.
-
-

photo of set-up

-

CODE

-#include <stdio.h>
-
-#include <pigpio.h>
-
-/*
-
-P1  Name  gpio    used for
-
- 2  5V    ---     -5V
- 6  GND   ---     -Ground
-24  CE0   8       -Sonar echo
-26  CE1   7       -Sonar trigger
-
-*/
-
-#define SONAR_TRIGGER 7
-#define SONAR_ECHO    8
-
-/* forward prototypes */
-
-void sonarTrigger(void);
-
-void sonarEcho(int gpio, int level, uint32_t tick);
-
-int main(int argc, char *argv[])
-{
-   if (gpioInitialise()<0) return 1;
-
-   gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);
-   gpioWrite  (SONAR_TRIGGER, PI_OFF);
-
-   gpioSetMode(SONAR_ECHO,    -PI_INPUT);
-
-   /* update sonar 20 times a second, timer #0 */
-
-   gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms -*/
-
-   /* monitor sonar echos */
-
-   gpioSetAlertFunc(SONAR_ECHO, sonarEcho);
-
-   while (1) sleep(1);
-
-   gpioTerminate();
-
-   return 0;
-}
-
-void sonarTrigger(void)
-{
-   /* trigger a sonar reading */
-
-   gpioWrite(SONAR_TRIGGER, PI_ON);
-
-   gpioDelay(10); /* 10us trigger pulse */
-
-   gpioWrite(SONAR_TRIGGER, PI_OFF);
-}
-
-void sonarEcho(int gpio, int level, uint32_t tick)
-{
-   static uint32_t startTick, firstTick=0;
-
-   int diffTick;
-
-   if (!firstTick) firstTick = tick;
-
-   if (level == PI_ON)
-   {
-      startTick = tick;
-   }
-   else if (level == PI_OFF)
-   {
-      diffTick = tick - startTick;
-
-      printf("%u %u\ ", tick-firstTick, -diffTick);
-   }
-}
-

BUILD

-cc -o sonar sonar.c -lpigpio -lrt -lpthread
-

RUN

-sudo ./sonar >sonar.dat &
-
-While the program is running you can capture the waveform using the -notification feature built in to pigpio.  Issue the following -commands on the Pi.
-
-pigs no
-pig2vcd  </dev/pigpio0 >sonar.vcd &
-pigs nb 0 0x180 # set bits for gpios 7 and 8
-

Move an object in front of the sonar ranger for a few -seconds.

-pigs nc 0
-

The file sonar.vcd will contain the captured waveform, which can -be viewed using GTKWave.

-

Overview

-LDR waveform 1
-

Reading circa every 10ms

-Sonar waveform 2
-

One reading, circa 400us

-Sonar waveform 3
-

another

-Sonar waveform 4
-

The file sonar.dat will contain pairs of timestamps and echo -length (in us).  The following  script will convert the -timestamps into seconds.

-

awk '{print $1/1000000, $2}' sonar.dat ->sonar-secs.dat

-

Gnuplot is a useful tool to graph data.

-plot 'sonar-secs.dat' title 'Sonar'
-

gnuplot 1
- plot [10:25] 'sonar-secs.dat' title 'Sonar'

-

gnuplot 1

diff --git a/DOC/tmp/body/examples.body b/DOC/tmp/body/examples.body deleted file mode 100644 index 7df20a8..0000000 --- a/DOC/tmp/body/examples.body +++ /dev/null @@ -1,495 +0,0 @@ -The following examples show various ways pigpio may be used to communicate with sensors via the GPIO.
-
-Although many are complete programs they are intended to be a starting point in producing your own code, not an end point.
-
-Index

-Hardware

-Shell code

-C code

-C++ code

-pigpiod_if2 code

-Python code

-Miscellaneous related code

-External links

-

Hardware

-A few practical examples of using pigpio with hardware.
-
-
IR Receiver
2013-06-09
Reading an infrared remote receiver.
-
-
Light Dependent Resistor
2013-06-09
Measuring brightness with a light dependent resistor (LDR). Improved methods of timing the start of the capacitor recharge are given for C and Python.
-
-
Motor Shield
2013-12-15
Using an Arduino motor shield.
-
-
Rotary Encoder
2013-06-09
Reading a rotary encoder.
-
-
Sonar Ranger
2013-06-10
Measuring range with a sonar ranger.
-
-

Shell code

-Examples of using pigpio with shell code.
-
-
GPIO test
2014-08-11
This bash script tests the user GPIO. Video
-
-

C code

-Examples of C pigpio programs.
-
-If your program is called foobar.c then build with
-
-gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt
-
-
Frequency Counter 1
2014-08-20
A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs).
-
-
Frequency Counter 2
2014-08-20
A program showing how to use the gpioSetGetSamplesFunc function to set a callback for accumulated GPIO state changes over the last millisecond. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). Generally the method used is more complicated but more efficient than frequency counter 1.
-
-
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
-
-
I2C Sniffer
2014-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results. This C program uses pigpio notifications.
-
-
IR Receiver
2015-02-25
Function to hash a code from an IR receiver (reading an IR remote control).
-
-
PCF8591 YL-40
2014-08-26
A program to display readings from the (I2C) PCF8591.
-
-
Pot + Capacitor Recharge Timing
2014-03-14
Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
-
-
Rotary Encoder
2015-10-03
Function to decode a mechanical rotary encoder.
-
-
SPI bit bang MCP3008
2016-03-20
This program shows how to read multiple MCP3008 ADC simultaneously with accurately timed intervals. One 10-bit channel of each ADC may be sampled at up to 25k samples per second.
-
-
SPI bit bang MCP3202
2016-03-20
This program shows how to read multiple MCP3202 ADC simultaneously with accurately timed intervals. One 12-bit channel of each ADC may be sampled at up to 25k samples per second.
-
-
SPI bit bang MCP3008 and MCP3202
2016-03-20
This program shows how to read multiple MCP3008 and MCP3202 ADC simultaneously with accurately timed intervals. One channel of each ADC may be sampled at up to 25k samples per second. The 10-bit MCP3008 readings are multiplied by 4 so they have the same range (0-4095) as the 12-bit MCP3202.
-
-
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-sudo ./servo_demo # Generate pulses on GPIO 4.
-
-sudo ./servo_demo 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
SPI pigpio driver speed test
2016-11-06
This C code is used to benchmark the pigpio SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
-
-
Wiegand Reader
2013-12-30
Function to read a Wiegand Reader.
-
-

C++ code

-Examples of C++ pigpio programs.
-
-If your program is called foobar.cpp then build with
-
-g++ -Wall -pthread -o foobar foobar.cpp -lpigpio -lrt
-
-
IR Receiver
2015-02-22
Class to hash a code from an IR receiver (reading an IR remote control).
-
-
Rotary Encoder
2013-12-30
Class to decode a mechanical rotary encoder.
-
-
Wiegand Reader
2013-12-30
Class to read a Wiegand Reader.
-
-

pigpiod_if2 code

The pigpiod_if2 code examples are linked with libpigpiod_if2 and are written in C.
-
-The pigpiod_if2 library may be compiled and run on any Linux machine and allows control of the GPIO on one or more networked Pis.
-
-It should be possible to adapt the library to run on Macs and PCs.
-
-Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
-
-
433MHz Keyfob RX/TX
2015-11-17
Code to read and transmit 313 and 434 MHz key fob codes. The codes to be read must use Manchester encoding. The transmitted codes use Manchester encoding.
-
-./_433D -r10 # Print fob keycodes received on GPIO 10.
-
-./_433D -t5 8246184 # Transmit code on GPIO 5.
-
-./_433D -r10 -t5 8246184 # Transmit code on GPIO 5 then listen for codes
-
-./_433D -? for options.
-
-
DHT11/21/22/33/44 Sensor
2016-02-16
Code to read the DHT temperature and humidity sensors. The sensor may be auto detected. A DHT11 sensor may be read once per second. The other sensors should not be read more often than once every three seconds.
-
-The code auto detects the DHT model and generally only the GPIO needs to be specified.
-
-./DHTXXD -g17 # Read a DHT connected to GPIO 17.
-
-./DHTXXD -g5 -i3 # Read a DHT connected to GPIO 5 every three seconds.
-
-./DHTXXD -? # for options.
-
-
Rotary Encoder
2015-11-18
Code to monitor a rotary encoder and show the position changes. By default the detent changes are shown. There is an option to show the four steps per detent instead.
-
-./RED -a7 -b8 -s30 # Show encoder on 7/8 detent changes for 30 seconds.
-
-./RED -a5 -b6 -m1 # Show encoder on 5/6 step changes forever.
-
-./RED -? # for options.
-
-
Servo Pulse Generator
2016-10-08
This program generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-./servo_demo_D # Generate pulses on GPIO 4.
-
-./servo_demo_D 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
Sonar Ranger
2015-11-16
Code to read the SRF-04 and SRF-05 type of sonar rangers which use the trigger echo method of operation. A 10 μs trigger pulse initiates a series of high frequency sonar chirps. The echo line then goes high and stays high until an echo from an object is received. The echo high time is used to calculate the distance of the object.
-
-For a one-off reading only the trigger and echo GPIO need to be specified.
-
-./SRTED -t5 -e6 # Read a sonar ranger connected to GPIO 5/6.
-
-./SRTED -t11 -e5 -i0.1 # Read a sonar ranger connected to GPIO 11/5 every 0.1 seconds.
-
-./SRTED -? # for options.
-
-
Transmit Rotary Encoder Test Signals
2015-11-25
Code to transmit quadrature signals to test rotary encoder software.
-
-tx_RED -aGPIO -bGPIO [options]
-
-tx_RED -? for options
-
-E.g.
-
-tx_RED -a5 -b6 -s20 -r-100
-
-
Transmit Wiegand Test Signals
2015-11-25
Code to transmit Wiegand codes to test Wiegand decoder software.
-
-tx_WD -gGPIO -wGPIO [options] {code}+
-
-tx_WD -? for options
-
-E.g.
-
-tx_WD -g5 -w6 -s37 12345 67890 123 899999
-
-
Wiegand Reader
2015-11-25
Code to read a Wiegand Reader.
-
-./WD -g7 -w8 -s30 # Read Wiegand codes from GPIO 7/8 for 30 seconds.
-
-./WD -g5 -w6 # Read Wiegand codes from GPIO 5/6 forever.
-
-./WD -? # for options.
-
-

Python code

The Python code may be run on any Python machine and allows control of the GPIO on one or more networked Pis.
-
-The Python machine need not be a Pi, it may run Windows, Mac, Linux, anything as long as it supports Python.
-
-Each Pi needs the pigpio daemon to be running. The pigpio daemon may be started with the command sudo pigpiod.
-
-
433MHz Keyfob RX/TX
2015-10-30
Classes to send and receive 433MHz wireless keyfob codes. These keyfobs are widely used for remote control of devices.
-
-
7-Segment LED Display Multiplexing
2016-12-12
Script to multiplex several 7-segment LED displays. Each display has the segments a-g and the decimal point connected in parallel but has an individual enable GPIO (connected to the common anode or cathode).
-
-
APA102 LED strip driver
2017-03-28
Script to drive an APA102 LED strip. Three different methods are demonstrated - using spidev SPI (only works on the local Pi), pigpio SPI, and pigpio waves. The SPI solutions only work with the dedicated SPI GPIO. Waves may use any spare GPIO. Four different examples are given including a LED strip clock.
-
-
BME280 Sensor
2016-08-05
Class to read the relative humidity, temperature, and pressure from a BME280 sensor. The sensor has both an I2C and a SPI interface which are both
-supported by the class.
-
-
DHT11/21/22/33/44 Sensor
2019-11-07
Class to read the relative humidity and temperature from a DHT sensor. It can automatically recognize the sensor type.
-
-The default script prints the reading from the specified DHT every 2 seconds. E.g. ./DHT.py 22 27 displays the data for DHT connected to GPIO 22 and 27.
-
-The following data is printed for each DHT: timestamp, GPIO, status, temperature, and humidity.
-
-The timestamp is the number of seconds since the epoch (start of 1970).
-
-The status will be one of: 0 - a good reading, 1 - checksum failure, 2 - data had one or more invalid values, 3 - no response from sensor.
-
-
DHT22 AM2302 Sensor
2014-07-11
Class to read the relative humidity and temperature from a DHT22/AM2302 sensor.
-
-
DS18B20 Temperature Sensor
2016-06-29
Script to read the temperature from any DS18B20 sensors connected to the 1-wire bus.
-
-To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
-
-dtoverlay=w1-gpio
-
-By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
-
-Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
-
-This script uses the file features of pigpio to access the remote file system.
-
-The following entry must be in /opt/pigpio/access.
-
-/sys/bus/w1/devices/28*/w1_slave r
-
-
Dust Sensor
2015-11-22
Class to read a Shinyei PPD42NS Dust Sensor, e.g. as used in the Grove dust sensor.
-
-
GPIO Status
2014-06-12
Script to display the status of GPIO 0-31.
-
-
Hall Effect Sensor
2014-06-13
Program to show status changes for a Hall effect sensor.
-
-
HX711 24-bit ADC
2018-03-05
Class to read the channels of a HX711 24-bit ADC.
-
-
I2C ADXL345 Accelerometer
2015-04-01
Script to display the X, Y, and Z values read from an ADXL345 accelerometer.
-
-
I2C HMC5883L Magnetometer
2015-04-01
Script to display the X, Y, and Z values read from a HMC5883L Magnetometer (compass).
-
-
I2C ITG3205 Gyroscope
2015-04-01
Script to display the X, Y, Z, and temperature values read from an ITG3205 gyroscope.
-
-
I2C LCD Display
2016-04-20
Class to display text on a LCD character display. The class supports the PCF8574T 8-bit I2C port expander connected to a HD44780 based LCD display. These displays are commonly available in 16x2 and 20x4 character formats.
-
-
I2C slave device
2016-10-31
This script demonstrates how to transfer messages from an Arduino acting as the I2C bus master to the Pi acting as an I2C slave device.
-
-
I2C Sniffer
2015-06-15
A program to passively sniff I2C transactions (100kHz bus maximum) and display the results.
-
-
I2C Sonar
2016-03-24
A class to read up to 8 HC-SR04 sonar rangers connected to an MCP23017 port expander.
-
-
IR Receiver
2014-06-12
Class to hash a code from an IR receiver (reading an IR remote control).
-
-
IR Record and Playback
2015-12-21
This script may be used to record and play back arbitrary IR codes.
-
-To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given.
-
-E.g. ./irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0
-
-To playback the GPIO connected to the IR transmitter, the file containing the recorded codes, and the codes to be played back are given.
-
-E.g. ./irrp.py -p -g18 -fir-codes 2 3 4
-
-./irrp.py -h # for options
-
-
Kivy GPIO control
2016-12-11
This example shows how to use Kivy to control a Pi's GPIO. The GPIO may be configured as inputs, outputs, or to generate Servo or PWM pulses. Kivy is an Open source Python library for rapid development of applications.
-
-
MAX6675 SPI Temperature Sensor
2016-05-02
A script to read the temperature from a MAX6675 connected to a K-type thermocouple. The MAX6675 supports readings in the range 0 - 1023.75 C. Up to 4 readings may be made per second.
-
-
Monitor GPIO
2016-09-17
Script to monitor GPIO for level changes. By default all GPIO are monitored. At a level change the GPIO, new level, and microseconds since the last change is printed.
-
-
Morse Code
2015-06-17
Script to transmit the morse code corresponding to a text string.
-
-
NRF24 radio transceiver
2018-01-06
Script to transmit and receive messages using the nRF24L01 radio transceiver.
-
-
PCA9685 16 Channel PWM
2016-01-31
Class to control the 16 PWM channels of the I2C PCA9685. All channels use the same frequency. The duty cycle or pulse width may be set independently for each channel.
-
-
PCF8591 YL-40
2014-08-26
Script to display readings from the (I2C) PCF8591.
-
-
PPM (Pulse Position Modulation) generation
2016-02-19
Script to generate PPM signals on a chosen GPIO.
-
-
PPM (Pulse Position Modulation) to servo pulses
2019-10-09
Script to read a PPM signal on a GPIO and generate the corresponding servo signals on chosen GPIO.
-
-
pigpio Benchmark
2014-06-12
Script to benchmark the pigpio Python module's performance.
-
-
pigpio CGI
2015-05-04
Script demonstrating how to access the pigpio daemon using CGI from a browser. Instructions on how to use with Apache2 on the Pi are given in the comments.
-
-
Playback piscope recordings
2016-12-23
Script to playback GPIO data recorded in piscope format.
-
-To playback GPIO 4 to GPIO 4 from file data.piscope
-./playback.py data.piscope 4
-
-To playback GPIO 4 to GPIO 7 from file rec.txt
-./playback.py rec.txt 7=4
-
-
Pot + Capacitor Recharge Timing
2016-09-26
Class to time capacitor charging (through a resistance). The time can be used to estimate the resistance.
-
-
PWM Monitor
2015-12-08
Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle.
-
-
Rotary Encoder
2014-06-12
Class to decode a mechanical rotary encoder.
-
-
RPM Monitor
2016-01-20
Class to monitor speedometer pulses and calculate the RPM (Revolutions Per Minute).
-
-
Si7021 I2C Temperature and Humidity Sensor
2016-05-07
Class to read the temperature and relative humidity from a Si7021.
-
-
SPI Monitor
2016-09-21
A program to passively sniff SPI transactions and display the results. The SPI rate should be limited to about 70kbps if using the default pigpio 5µs sampling rate.
-
-
Servo Pulse Generator
2016-10-07
This script generates servo pulses on one or more GPIO. Each connected servo is swept between 1000µs and 2000µs at a different speed.
-
-./servo_demo.py # Generate pulses on GPIO 4.
-
-./servo_demo.py 5 9 20 # Generate pulses on GPIO 5, 9, and 20.
-
-
Sonar Ranger
2014-06-12
Class to read sonar rangers with separate trigger and echo pins.
-
-
TCS3200 Colour Sensor
2015-07-03
Class to read the TCS3200 colour sensor
-
-
Virtual Wire
2015-10-31
Class to send and receive radio messages compatible with the Virtual Wire library for Arduinos. This library is commonly used with 313MHz and 434MHz radio tranceivers.
-
-
Wave create
2019-11-18
Script to generate waves from a template defined in a text file.
-
-You can also specify one of py, c, or pdif - the script output will then be a complete program to generate the wave (py for Python script, c for a C program, pdif for a C program using the pigpio daemon I/F).
-
-If none of py, c, or pdif are chosen the waveform will be generated for 30 seconds.
-
-Example text file
-
-# GPIO levels
-23 11000001
-11 01110000
-12 00011100
-4 00000111
-
-To generate a pdif program with a bit time of 100 microseconds
-./create_wave.py wave_file 100 pdif >wave_pdif.c
-
-To just transmit the wave with a bit time of 50 microseconds
-./create_wave.py wave_file 50
-
-
Wave PWM 1
2016-03-19
Script to show how waves may be used to generate PWM at (one) arbitrary frequency on multiple GPIO. For instance PWM at 10kHz may be generated with 100 steps between off and fully on.
-
-
Wave PWM 2
2016-10-06
Class to generate PWM on multiple GPIO. It is more flexible than the Wave PWM 1 example in that the start of the pulse within each cycle may be specified as well as the duty cycle. The start and length of each pulse may be specified on a GPIO by GPIO basis in microseconds or as a fraction of the cycle time. The class includes a __main__ to demostrate its ability to send servo pulses.
-
-
Wiegand Reader
2014-06-12
Class to read a Wiegand reader.
-
-

Miscellaneous related code

-The following code examples do not use pigpio.
-
-
ADXL345
2014-03-12
This C program reads x, y, and z accelerations from the ADXL345 via I2C address 0x53.
-
-
DS18B20 Temperature Sensor
2016-04-25
This Python script reads the temperature from any DS18B20 sensors connected to the 1-wire bus.
-
-To enable the 1-wire bus add the following line to /boot/config.txt and reboot.
-
-dtoverlay=w1-gpio
-
-By default you should connect the DS18B20 data line to GPIO 4 (pin 7).
-
-Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.
-
-
Easy as Pi Server
2014-09-15
This Python class implements a simple server which allows broswer commands to be executed on the Pi.
-
-
Minimal Clock Access
2015-05-20
This C code sets GPIO 4 to a specified clock frequency. The frequency can be set between 4.6875 kHz and 500 MHz (untested). The clock can be preferentially set from one of the sources OSC (19.2MHz), HDMI (216MHz), PLLD (500MHz), or PLLC (1000MHz). MASH can be set between 0 and 3. MASH may not work properly for clock dividers less than 5.
-
-
Minimal GPIO Access
2019-07-03
This C code has a minimal set of functions needed to control the GPIO and other Broadcom peripherals. The program requires root privileges to run. See Tiny GPIO access for an alternative which controls the GPIO (but not the other peripherals) and does not require root access.
-
-The code has been updated for the BCM2711 (Pi4B).
-
-The following functions are provided.
-
-gpioInitialise
-gpioSetMode
-gpioGetMode
-gpioSetPullUpDown
-gpioRead
-gpioWrite
-gpioTrigger
-gpioReadBank1
-gpioReadBank2
-gpioClearBank1
-gpioClearBank2
-gpioSetBank1
-gpioSetBank2
-gpioHardwareRevision
-gpioTick
-
-
Nanosecond Pulse Generation
2014-01-29
This C program uses the PWM peripheral to generate precisely timed pulses of very short duration. Pulses as short as 4 nano seconds can be generated.
-
-
PCF8591 YL-40
2014-08-26
C and Python code to read the (I2C) PCF8591.
-
-
SPI Linux driver speed test
2016-11-06
This C code is used to benchmark the Linux SPI driver on the Pi. The code executes a given number of loops at a given baud rate and bytes per transfer.
-
-
Tiny GPIO Access
2016-04-30
This C code has a minimal set of functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO).
-
-You may need to change the permissions and ownership of /dev/gpiomem if they have not been correctly set up.
-
-sudo chown root:gpio /dev/gpiomem
-sudo chmod g+rw /dev/gpiomem
-
-The user (default pi) needs to be in the gpio group.
-
-sudo adduser pi gpio
-
-The following functions are provided.
-
-gpioInitialise
-gpioSetMode
-gpioGetMode
-gpioSetPullUpDown
-gpioRead
-gpioWrite
-gpioTrigger
-gpioReadBank1
-gpioReadBank2
-gpioClearBank1
-gpioClearBank2
-gpioSetBank1
-gpioSetBank2
-gpioHardwareRevision
-
-

External links

-Related code.
-
-
Stepper Motor
2016-08-12
Stepper motor code.
-
-
Parallax ActivityBot 360
2018-11-03
Python 3 implementation for programming a Parallax ActivityBot 360 Robot Kit with a Raspberry Pi.
-
-

Index

- -
433MHz Keyfob RX/TX pdif2 - Python -
7-Segment LED Display Multiplexing Python -
ADXL345 Misc -
APA102 LED strip driver Python -
BME280 Sensor Python -
DHT11/21/22/33/44 Sensor pdif2 - Python -
DHT22 AM2302 Sensor Python -
DS18B20 Temperature Sensor Python - Misc -
Dust Sensor Python -
Easy as Pi Server Misc -
Frequency Counter 1 C -
Frequency Counter 2 C -
GPIO Status Python -
GPIO test Shell -
Hall Effect Sensor C - Python -
HX711 24-bit ADC Python -
I2C ADXL345 Accelerometer Python -
I2C HMC5883L Magnetometer Python -
I2C ITG3205 Gyroscope Python -
I2C LCD Display Python -
I2C slave device Python -
I2C Sniffer C - Python -
I2C Sonar Python -
IR Receiver Hardware - C - C++ - Python -
IR Record and Playback Python -
Kivy GPIO control Python -
Light Dependent Resistor Hardware -
MAX6675 SPI Temperature Sensor Python -
Minimal Clock Access Misc -
Minimal GPIO Access Misc -
Monitor GPIO Python -
Morse Code Python -
Motor Shield Hardware -
Nanosecond Pulse Generation Misc -
NRF24 radio transceiver Python -
Parallax ActivityBot 360 External -
PCA9685 16 Channel PWM Python -
PCF8591 YL-40 C - Python - Misc -
pigpio Benchmark Python -
pigpio CGI Python -
Playback piscope recordings Python -
Pot + Capacitor Recharge Timing C - Python -
PPM (Pulse Position Modulation) generation Python -
PPM (Pulse Position Modulation) to servo pulses Python -
PWM Monitor Python -
Rotary Encoder Hardware - C - C++ - pdif2 - Python -
RPM Monitor Python -
Servo Pulse Generator C - pdif2 - Python -
Si7021 I2C Temperature and Humidity Sensor Python -
Sonar Ranger Hardware - pdif2 - Python -
SPI bit bang MCP3008 C -
SPI bit bang MCP3008 and MCP3202 C -
SPI bit bang MCP3202 C -
SPI Linux driver speed test Misc -
SPI Monitor Python -
SPI pigpio driver speed test C -
Stepper Motor External -
TCS3200 Colour Sensor Python -
Tiny GPIO Access Misc -
Transmit Rotary Encoder Test Signals pdif2 -
Transmit Wiegand Test Signals pdif2 -
Virtual Wire Python -
Wave create Python -
Wave PWM 1 Python -
Wave PWM 2 Python -
Wiegand Reader C - C++ - pdif2 - Python -
\ No newline at end of file diff --git a/DOC/tmp/body/faq.body b/DOC/tmp/body/faq.body deleted file mode 100644 index 7c505f0..0000000 --- a/DOC/tmp/body/faq.body +++ /dev/null @@ -1,452 +0,0 @@ - -Are my GPIO broken?
-
-Audio is broken
-
-Can´t initialise pigpio -library
-
-Can´t lock -var/run/pigpio.pid
-
-Hello World!
-
-Clock skew, make fails
-
-Have I fried my GPIO?
-
-How do I debounce -inputs?
-
-How fast is SPI?
-
-Library update didn't work
-
-make fails with clock skew
-
-Porting pigpio to another CPU/SoC
-
-Sound isn't working
-
-Symbol not found
-
-What is I2C?
-
-What is Serial?
-
-What is SPI?
-
-Which library should I use?
-
-

Are my -GPIO broken?

-

See Have I fried my -GPIO?

-

Audio is -broken

-

See Sound isn't -working

-

Can´t lock -/var/run/pigpio.pid

-

See Can´t_initialise_pigpio_library
-

-

Can´t initialise pigpio -library

-

This message means the pigpio daemon is already running.

-

The default daemon is called pigpiod and may be removed as -follows.

-Check that it is running with the command -

ps aux | grep pigpiod

-

Kill the daemon with

-

sudo killall pigpiod

-

If your own program is acting as the daemon it may be removed as -follows.

-

Find its process id (pid).

-

cat /var/run/pigpio.pid

-

Kill the program with

-

sudo kill -9 pid

-If the above doesn't work do the following and try starting the -daemon again -

sudo rm /var/run/pigpio.pid

-

To start the daemon do

-

sudo pigpiod

-

Have I fried my GPIO?

-

If you think you have damaged one or more GPIO you can carry out -a diagnostic test.

-

The test is a command line script called gpiotest

-For the duration of the test nothing must be connected to the GPIO -(no LEDs, wires, ribbon cables etc.). -

The test checks that each GPIO may be read and written and that -the internal resistor pull-ups and pull-downs are functional.

-

A video -showing what happens to the GPIO during a test.

-

A test with all GPIO okay.

-
This program checks the Pi's (user) gpios.
-
-The program reads and writes all the gpios.  Make sure NOTHING
-is connected to the gpios during this test.
-
-The program uses the pigpio daemon which must be running.
-
-To start the daemon use the command sudo pigpiod.
-
-Press the ENTER key to continue or ctrl-C to abort...
-
-Testing...
-Skipped non-user gpios: 0 1 28 29 30 31 
-Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 -Failed user gpios: None -
-

A test showing failed GPIO.

-
This program checks the Pi's (user) gpios.
-
-The program reads and writes all the gpios. Make sure NOTHING
-is connected to the gpios during this test.
-
-The program uses the pigpio daemon which must be running.
-
-To start the daemon use the command sudo pigpiod.
-
-Press the ENTER key to continue or ctrl-C to abort...
-
-Testing...
-Write 1 to gpio 17 failed.
-Pull up on gpio 17 failed.
-Write 1 to gpio 18 failed.
-Pull up on gpio 18 failed.
-Write 0 to gpio 23 failed.
-Pull down on gpio 23 failed.
-Write 0 to gpio 24 failed.
-Pull down on gpio 24 failed.
-Write 1 to gpio 27 failed.
-Pull up on gpio 27 failed.
-Skipped non-user gpios: 0 1 28 29 30 31
-Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 -Failed user gpios: 17 18 23 24 27 -
-

How do I debounce inputs?

-

Some devices like mechanical switches can generate multiple -interrupts as they bounce between on and off.  It is possible -to debounce the inputs in hardware by the correct use of resistors -and capacitors.

-

In software use the glitch filter which ignores all events -shorter than a set number of microseconds.  C gpioGlitchFilter, Python set_glitch_filter.

-

How fast is -SPI?

-The SPI throughput in samples per second depends on a number of -factors.
-
-
    -
  • The SPI bit rate (transfer rate in bits per second)
  • -
-
    -
  • The number of bytes transferred per sample (a 12 bit ADC sample -may require 3 bytes to transfer)
  • -
-
    -
  • The driver used
  • -
-

Two of those factors are fixed, the variable is the driver -used.

-

The pigpio driver is considerably faster than the Linux SPI -driver as is demonstrated by the following graphs.

-

Each graph shows the SPI bit rate in bits per second along the -horizontal axis.  The samples per second achieved is shown on -the vertical axis.  Each graph contains plots assuming 1 to 5 -bytes per transfer.

-

The source code used for the tests is spi-driver-speed.c and spi-pigpio-speed.c

-

spi-lnx-pibr1.png

-
-

spi-pig-pibr1.png

-
-

spi-lnx-pi3b.png

-
-

spi-pig-pi3b.png

-

Library update didn't work

-

pigpio places files in the following locations

-

/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
-/usr/local/lib (libpigpio.so, libpigpiod_if.so, -libpigpiod_if2.so)
-/usr/local/bin (pig2vcd, pigpiod, pigs)
-/usr/local/man (man pages)

-The raspberrypi.org image containing pigpio uses different -locations.
-

/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
-/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)
-/usr/bin (pig2vcd, pigpiod, pigs)
-/usr/man (man pages)

-

Mostly this doesn't matter as the /usr/local directories will -generally be earlier in the search path.  The pigpio built -includes, binaries, and manuals are normally found first.

-

However the wrong libraries may be linked during the -compilation.  If this is the case remove the /usr/lib entries -for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so

-

Hello World!

-

The following examples show how to use the various components of -the pigpio library.

-

Each example shows how to read the level of a GPIO.

-

C

-read_cif.c -
-#include <stdio.h>
-#include <pigpio.h>
-
-int main(int argc, char *argv[])
-{
-   int GPIO=4;
-   int level;
-
-   if (gpioInitialise() < 0) return 1;
-
-   level = gpioRead(GPIO);
-
-   printf("GPIO %d is %d\n", GPIO, level);
-
-   gpioTerminate();
-}
-    
-

Build

-gcc -pthread -o read_cif read_cif.c -lpigpio -

Run

-sudo ./read_cif -

C via pigpio daemon

-read_pdif.c -
-#include <stdio.h>
-#include <pigpiod_if2.h>
-
-int main(int argc, char *argv[])
-{
-   int pi;
-   int GPIO=4;
-   int level;
-
-   pi = pigpio_start(0, 0); /* Connect to local Pi. */
-
-   if (pi < 0)
-   {
-      printf("Can't connect to pigpio daemon\n");
-      return 1;
-   }
-
-   level = gpio_read(pi, GPIO);
-
-   printf("GPIO %d is %d\n", GPIO, level);
-
-   pigpio_stop(pi); /* Disconnect from local Pi. */
-   
-   return 0;
-}
-
-

Build

-gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2 -

Run

-./read_pdif -

Python

-read_gpio.py -
-#!/usr/bin/env python
-
-import pigpio
-
-GPIO=4
-
-pi = pigpio.pi()
-if not pi.connected:
-   exit()
-
-level = pi.read(GPIO)
-
-print("GPIO {} is {}".format(GPIO, level))
-
-pi.stop()
-    
-

Run

-python read_gpio.py -

pigs

-
-pigs r 4
-    
-

pipe I/F

-
-echo "r 4" >/dev/pigpio
-cat /dev/pigout
-    
-

make fails with clock -skew

-

If make fails with one of the following messages it is probably -because the Pi's clock is wrong.

-

make: Warning: File 'xxx' has modification time x s in the -future
-make: warning: Clock skew detected. Your build may be -incomplete.

-

make uses the current time to work out which files need to be -rebuilt (a file is rebuilt if it depends on other files which have -a later time-stamp).

-

The solution is to make sure the system clock is correct.  -If the Pi is networked this will not normally be a problem.

-

To set the date and time use the date command as in the -following example.

-

sudo date -d "2017-03-01 18:47:00"

-

Porting pigpio -to another CPU/SoC

-

Sound -isn't working

-

The Pi contains two pieces of hardware, a PWM peripheral and a -PCM peripheral, to generate sound.  The PWM peripheral is -normally used and generates medium quality audio out of the -headphone jack.  The PCM peripheral may be used by add-ons -such as HATs and generates high quality audio.

-

pigpio uses at least one of these peripherals during normal -operation (for timing DMA transfers).  pigpio will use both -peripherals if waves or the hardware PWM function is used.

-

By default pigpio uses the PCM peripheral leaving the PWM -peripheral free for medium quality audio.

-

You can change the default with a configuration option.  -For C use gpioCfgClock, for the -pigpio daemon use the -t option.

-

What is I2C?

-

I2C is a data link between the Pi (master) and one or more -slaves.

-

Data may be sent and received but the Pi initiates all -transfers.

-

I2C is a medium speed link.  On the Pi the default speed is -100 kbps, but 400 kbps also works.

-

I2C is implemented as a bus with two lines called

-
    -
  • SDA - for data
  • -
  • SCL - for a clock
  • -
-On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO -3 (pin 5) for SCL.
-
-Only one slave device may be communicated with at a time.  -Each message from the Pi includes the slave to be addressed and -whether a read or write is to be performed.
-
-When the Pi (master) wishes to talk to a slave it begins by issuing -a start sequence on the I2C bus. A start sequence is one of two -special sequences defined for the I2C bus, the other being the stop -sequence. The start sequence and stop sequence are special in that -these are the only places where the SDA (data line) is allowed to -change while the SCL (clock line) is high. When data is being -transferred, SDA must remain stable and not change whilst SCL is -high. The start and stop sequences mark the beginning and end of a -transaction with the slave device.
-
-I2C start and stop sequences
-
-Data is transferred in 8-bit bytes. The bytes are placed on the SDA -line starting with the most significant bit. The SCL line is then -pulsed high, then low. For every byte transferred, the device -receiving the data sends back an acknowledge bit, so there are -actually 9 SCL clock pulses to transfer each 8-bit byte of data. If -the receiving device sends back a low ACK bit, then it has received -the data and is ready to accept another byte. If it sends back a -high then it is indicating it cannot accept any further data and -the master should terminate the transfer by sending a stop -sequence.
-
-

I2C waveform

-

What is -Serial?

-

Serial is a data link between the Pi and one other -device.

-

Data may be sent and received.  Either the Pi or the device -can initiate a transfer.

-

Serial is a low to medium speed link.  On the Pi speeds of -50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, -19200, 38400, 57600, 115200, and 230400 bps may be used.

-

Serial is implemented with one line for transmit called TXD and -one line for receive called RXD.

-

If only receive or transmit are required the other line need not -be connected.

-

The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for -RXD.

-

Data is normally transmitted in 8-bit bytes with a start bit, -eight data bits, no parity, and one stop bit.  This is -represented as 8N1.  The number of transmitted bits per second -(bps) is called the baud rate.   The time for each bit, -1 / baud rate seconds, is -referred to as the bit period.

-

The lines are in the high state when no data is being -transmitted.  The start of a byte is signalled by the line -going low for one bit period (the start bit).  The data bits -are then sent least significant bit firsts (low if the bit is 0, -high if the bit is 1).  The data bits are followed by the -optional parity bit.  Finally the line is set high for at -least the number of stop bit periods.  The line will stay high -if there are no more bytes to be transmitted.

-

Serial waveform

-

What is SPI?

-

SPI is a data link between the Pi (master) and one or more -slaves.

-

Data may be sent and received but the Pi initiates all -transfers.

-

SPI is a medium to high speed link.  On the Pi speeds of 32 -kbps to 8 Mbps may be used.

-

SPI is implemented as a bus with three lines called

-
    -
  • MOSI - for data from the Pi to the slave
  • -
  • MISO - for data from the slave to the Pi
  • -
  • SCLK - for a clock
  • -
-Only one slave device may be communicated with at a time.  An -additional line per slave called slave select is used to identify -the slave to be addressed. -

The Pi has two SPI buses

-
    -
  1. the main SPI bus -
      -
    • MOSI GPIO 10 (pin 19)
    • -
    • MISO GPIO 9 (pin 21)
    • -
    • SCLK GPIO 11 (pin 23)
    • -
    • Slave selects
    • -
    • -
        -
      • CE0 GPIO 8 (pin 24)
      • -
      • CE1 GPIO 7 (pin 26)
      • -
      -
    • -
    -
  2. -
  3. the auxiliary SPI bus -
      -
    • MOSI GPIO 20 (pin 38)
    • -
    • MISO GPIO 19 (pin 35)
    • -
    • SCLK GPIO 21 (pin 40)
    • -
    • Slave selects
    • -
    • -
        -
      • CE0 GPIO 18 (pin 12)
      • -
      • CE1 GPIO 17 (pin 11)
      • -
      • CE2 GPIO 16 (pin 36)
      • -
      -
    • -
    -
  4. -
-

SPI waveform

-


-

Which library -should I use?

-


diff --git a/DOC/tmp/body/index.body b/DOC/tmp/body/index.body deleted file mode 100644 index f8a4d2e..0000000 --- a/DOC/tmp/body/index.body +++ /dev/null @@ -1,652 +0,0 @@ - -pigpio is a library for the Raspberry which allows control of the -General Purpose Input Outputs (GPIO).  pigpio works on all -versions of the Pi. -

At the moment pigpio on the Pi4B is experimental. I am not -sure if the DMA channels being used are safe. The Pi4B defaults are -primary channel 7, secondary channel 6. If these channels do not -work you will have to experiment. You can set the channels used by -the pigpio daemon by invoking it with the -d and -e options, e.g. -sudo pigpiod -d 5 -e 8 to specify primary 5, -secondary 8.

-

Download

-

Features

-
    -
  • -

    hardware timed sampling and time-stamping of GPIO 0-31 every 5 -us

    -
  • -
  • -

    hardware timed PWM on all of GPIO 0-31

    -
  • -
  • -

    hardware timed servo pulses on all of GPIO 0-31

    -
  • -
  • -

    callbacks on GPIO 0-31 level change (time accurate to a few -us)

    -
  • -
  • -

    notifications via pipe on GPIO 0-31 level change

    -
  • -
  • -

    callbacks at timed intervals

    -
  • -
  • -

    reading/writing all of the GPIO in a bank (0-31, 32-53) as a -single operation

    -
  • -
  • -

    GPIO reading, writing, modes, and internal pulls

    -
  • -
  • -

    socket and pipe interfaces for the bulk of the functionality

    -
  • -
  • -

    waveforms to generate GPIO level changes (time accurate to a few -us)

    -
  • -
  • -

    software serial links using any user GPIO

    -
  • -
  • -

    rudimentary permission control through the socket and pipe -interfaces

    -
  • -
  • creating and running scripts on the pigpio daemon
  • -
-

General

-The pigpio library is written in the C -programming language.
-
-The pigpio daemon offers a socket and pipe interface to -the underlying C library.
-
-A C library and a Python module allow control of the GPIO via the -pigpio daemon.
-
-There is third party support for a number of other languages.  -

piscope

-

piscope is a logic analyser (digital -waveform viewer).

-piscope is a GTK+3 application and uses pigpio to provide raw GPIO -level data.  piscope may be run on a Pi or on any machine -capable of compiling a GTK+3 application. -

GPIO

-

ALL GPIO are identified -by their Broadcom -number.  See -elinux.org

-There are 54 GPIO in total, arranged in two banks.
-

Bank 1 contains GPIO 0-31.  Bank 2 contains GPIO -32-53.

-For all types of Pi it is safe to read all the GPIO. If you try to -write a system GPIO or change its mode you can crash the Pi or -corrupt the data on the SD card.
-
-There are several types of board, each with different expansion -headers, giving physical access to different GPIO.  - -

Type 1 - Model B (original -model)

-
    -
  • 26 pin header (P1).
  • -
-
    -
  • Hardware revision numbers of 2 and 3.
  • -
-
    -
  • User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA0
34-5V
SCL1
56-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

211314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
-
-

Type 2 - Model A, B (revision -2)

-26 pin header (P1) and an additional 8 pin header (P5). -
    -
  • Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13, -14, 15 (B).
  • -
-
    -
  • User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
5V
-12-3V3
SDA
283429SCL

305631
Ground
-
78-
Ground
-
-

Type 3 - Model A+, B+, Pi -Zero, Pi Zero W, Pi2B, Pi3B, Pi4B

-
    -
  • 40 pin expansion header (J8).
  • -
-
    -
  • Hardware revision numbers of 16 or greater.
  • -
-
    -
  • User GPIO 2-27 (0 and 1 are reserved).
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-GPIOpinpin -GPIO
3V3-12-5V
SDA234-5V
SCL356-Ground

47814TXD
Ground-91015RXD
ce117111218ce0

271314-Ground

22151623
3V3-
171824
MOSI101920-Ground
MISO9212225
SCLK1123248CE0
Ground-25267CE1
ID_SD027281ID_SC

52930-Ground

6313212

133334-Ground
miso19353616ce2

26373820mosi
Ground-394021sclk
-
-

Compute Module

-

All 54 GPIO may be physically accessed.  Some are reserved -for system use - refer to the Compute Module documentation.

-

Only GPIO 0-31 are supported for hardware timed sampling, PWM, -servo pulses, alert callbacks, waves, and software serial -links.

-

Other -Languages

-

There are several third party projects which provide wrappers -for pigpio.

-

Some I am aware of are:

-
    -
  • Erlang -(skvamme)
  • -
  • Java JNI -wrapper around the pigpio C library (mattlewis)
  • -
  • Java via -diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc -(mattlewis)
  • -
  • Java -(nkolban)
  • -
  • .NET/mono -(unosquare)
  • -
  • Node.js -(fivdi)
  • -
  • Perl (Gligan -Calin Horea)
  • -
  • Ruby -(Nak)
  • -
  • Smalltalk(Instantiations)
  • -
  • Xojo(UBogun)
  • -
-
-

The PWM and servo pulses are timed using the DMA -and PWM/PCM peripherals.  This use was inspired by Richard -Hirst's servoblaster kernel module.

diff --git a/DOC/tmp/body/misc.body b/DOC/tmp/body/misc.body deleted file mode 100644 index 8bb3552..0000000 --- a/DOC/tmp/body/misc.body +++ /dev/null @@ -1,24 +0,0 @@ - -There are two C libraries which provide a socket interface to the -pigpio daemon.  They provide an interface very similar to the -pigpio Python module.
-
    -
  • The original pigpiod_if library is -now deprecated and will no longer be updated.  This library is -limited to controlling one Pi at a time.
  • -
-
    -
  • The new pigpiod_if2 library which -should be used for new code.  This library allows multiple Pis -to be controlled at one time.
  • -
-Additional details of the pigpio socket -interface.
-
-Additional details of the pigpio pipe -interface.
-
-pig2vcd is a utility which converts -pigpio notifications into the VCD (Value Change Dump) format.  -VCD can be read by many programs, in particular GTKWave. diff --git a/DOC/tmp/body/pdif.body b/DOC/tmp/body/pdif.body deleted file mode 100644 index 238e3f7..0000000 --- a/DOC/tmp/body/pdif.body +++ /dev/null @@ -1,1105 +0,0 @@ -

THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO -USE THE MORE VERSATILE pigpiod_if2 LIBRARY. -

pigpiod_if is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon.
-

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. -

Usage

Include <pigpiod_if.h> in your source files. -

Assuming your source is in prog.c use the following command to build -

gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt


to run make sure the pigpio daemon is running -

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if


For examples see x_pigpiod_if.c within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error -

OVERVIEW

ESSENTIAL -
pigpio_start Connects to the pigpio daemon -
pigpio_stop Disconnects from the pigpio daemon -
BEGINNER -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
gpio_read Read a GPIO -
gpio_write Write a GPIO -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -
set_servo_pulsewidth Start/stop servo pulses on a GPIO -
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -
callback Create GPIO level change callback -
callback_ex Create GPIO level change callback -
callback_cancel Cancel a callback -
wait_for_edge Wait for GPIO level change -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO. -
set_watchdog Set a watchdog on a GPIO. -
set_PWM_range Configure PWM range for a GPIO -
get_PWM_range Get configured PWM range for a GPIO -
set_PWM_frequency Configure PWM frequency for a GPIO -
get_PWM_frequency Get configured PWM frequency for a GPIO -
read_bank_1 Read all GPIO in bank 1 -
read_bank_2 Read all GPIO in bank 2 -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
start_thread Start a new thread -
stop_thread Stop a previously started thread -
ADVANCED -
get_PWM_real_range Get underlying PWM range for a GPIO -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
bb_serial_read_open Opens a GPIO for bit bang serial reads -
bb_serial_read Reads bit bang serial data from a GPIO -
bb_serial_read_close Closes a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
SCRIPTS -
store_script Store a script -
run_script Run a stored script -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_delete Deletes one or more waveforms -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_chain Transmits a chain of waveforms -
wave_tx_busy Checks to see if the waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_micros Length in microseconds of the current waveform -
wave_get_high_micros Length of longest waveform so far -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_high_pulses Length of longest waveform so far -
wave_get_max_pulses Absolute maximum allowed pulses -
wave_get_cbs Length in cbs of the current waveform -
wave_get_high_cbs Length of longest waveform so far -
wave_get_max_cbs Absolute maximum allowed cbs -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick smbus write quick -
i2c_write_byte smbus write byte -
i2c_read_byte smbus read byte -
i2c_write_byte_data smbus write byte data -
i2c_write_word_data smbus write word data -
i2c_read_byte_data smbus read byte data -
i2c_read_word_data smbus read word data -
i2c_process_call smbus process call -
i2c_write_block_data smbus write block data -
i2c_read_block_data smbus read block data -
i2c_block_process_call smbus block process call -
i2c_write_i2c_block_data smbus write I2C block data -
i2c_read_i2c_block_data smbus read I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_zip Performs multiple I2C transactions -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs multiple bit banged I2C transactions -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write Writes bytes to a serial device -
serial_read Reads bytes from a serial device -
serial_data_available Returns number of bytes ready to be read -
CUSTOM -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpiod_if_version Get the pigpiod_if version -
pigpio_error Get a text description of an error code. -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -

FUNCTIONS

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds. -

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

-Return a text description for an error code. -

errnum: the error code.

unsigned pigpiod_if_version(void)

-Return the pigpiod_if version. -

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

-Starts a new thread of execution with thread_func as the main routine. -

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument userdata. -

The thread can be cancelled by passing the pointer to pthread_t to -stop_thread. -

void stop_thread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: the thread to be stopped.


No value is returned. -

The thread to be stopped should have been started with start_thread. -

int pigpio_start(char *addrStr, char *portStr)

-Connect to the pigpio daemon. Reserving command and -notification streams. -

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.

void pigpio_stop(void)

-Terminates the connection to the pigpio daemon and releases -resources used by the library. -

int set_mode(unsigned gpio, unsigned mode)

-Set the GPIO mode. -

gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. -

int get_mode(unsigned gpio)

-Get the GPIO mode. -

gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

int set_pull_up_down(unsigned gpio, unsigned pud)

-Set or clear the GPIO pull-up/down resistor. -

gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. -

int gpio_read(unsigned gpio)

-Read the GPIO level. -

gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

int gpio_write(unsigned gpio, unsigned level)

-Write the GPIO level. -

 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. -

Notes -

If PWM or servo pulses are active on the GPIO they are switched off. -

int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)

-Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. -

user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes -

The set_PWM_range function may be used to change the -default range of 255. -

int get_PWM_dutycycle(unsigned user_gpio)

-Return the PWM dutycycle in use on a GPIO. -

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

int set_PWM_range(unsigned user_gpio, unsigned range)

-Set the range of PWM values to be used on the GPIO. -

user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. -

Notes -

If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. -

The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is -

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


The real value set by set_PWM_range is (dutycycle * real range) / range. -

int get_PWM_range(unsigned user_gpio)

-Get the range of PWM values being used on the GPIO. -

user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). -

int get_PWM_real_range(unsigned user_gpio)

-Get the real underlying range of PWM values being used on the GPIO. -

user_gpio: 0-31.


Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

int set_PWM_frequency(unsigned user_gpio, unsigned frequency)

-Set the frequency (in Hz) of the PWM to be used on the GPIO. -

user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(unsigned user_gpio)

-Get the frequency of PWM being used on the GPIO. -

user_gpio: 0-31.


For normal PWM the frequency will be that defined for the GPIO by -set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)

-Start (500-2500) or stop (0) servo pulses on the GPIO. -

 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. -

The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its limits. -

OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. -

Then set the PWM range using set_PWM_range to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO 25 at 400Hz -

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-

int get_servo_pulsewidth(unsigned user_gpio)

-Return the servo pulsewidth in use on a GPIO. -

user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int notify_open(void)

-Get a free notification handle. -

Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by callback -should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

int notify_begin(unsigned handle, uint32_t bits)

-Start notifications on a previously opened handle. -

handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

Each notification occupies 12 bytes in the fifo as follows: -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. -

PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

int notify_pause(unsigned handle)

-Pause notifications on a previously opened handle. -

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until -notify_begin is called again. -

int notify_close(unsigned handle)

-Stop notifications on a previously opened handle and -release the handle for reuse. -

handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int set_watchdog(unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. -

The callback will receive the special level PI_TIMEOUT. -

int set_glitch_filter(unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

uint32_t read_bank_1(void)

-Read the levels of the bank 1 GPIO (GPIO 0-31). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<n). -

uint32_t read_bank_2(void)

-Read the levels of the bank 2 GPIO (GPIO 32-53). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). -

int clear_bank_1(uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int clear_bank_2(uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_1(uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_2(uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int hardware_clock(unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

     gpio: see description
frequency: 0 (off) or 4689-250000000 (250M)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int hardware_PWM(unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_once, wave_send_repeat, -or wave_chain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

   gpio: see descripton
PWMfreq: 0 (off) or 1-125000000 (125M)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only

uint32_t get_current_tick(void)

-Gets 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. -

uint32_t get_hardware_revision(void)

-Get the Pi's hardware revision number. -

The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

uint32_t get_pigpio_version(void)

-Returns the pigpio version. -

int wave_clear(void)

-This function clears all waveforms and any data added by calls to the -wave_add_* functions. -

Returns 0 if OK. -

int wave_add_new(void)

-This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the wave_create function. -

Returns 0 if OK. -

int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. -

int wave_add_serial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, -and stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int wave_create(void)

-This function creates a waveform from the data provided by the prior -calls to the wave_add_* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the wave_add_* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_delete(unsigned wave_id)

-This function deletes the waveform with id wave_id. -

wave_id: >=0, as returned by wave_create.


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int wave_send_once(unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -is sent once. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_repeat(unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by wave_tx_stop). -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_chain(char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, wid[WAVES];

   if (pigpio_start(0, 0)<0) return -1;

   set_mode(GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create();
   }

   wave_chain((char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy()) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(wid[i]);

   pigpio_stop();
}

int wave_tx_busy(void)

-This function checks to see if a waveform is currently being -transmitted. -

Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int wave_tx_stop(void)

-This function stops the transmission of the current waveform. -

Returns 0 if OK. -

This function is intended to stop a waveform started with the repeat mode. -

int wave_get_micros(void)

-This function returns the length in microseconds of the current -waveform. -

int wave_get_high_micros(void)

-This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. -

int wave_get_max_micros(void)

-This function returns the maximum possible size of a waveform in
-microseconds. -

int wave_get_pulses(void)

-This function returns the length in pulses of the current waveform. -

int wave_get_high_pulses(void)

-This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. -

int wave_get_max_pulses(void)

-This function returns the maximum possible size of a waveform in pulses. -

int wave_get_cbs(void)

-This function returns the length in DMA control blocks of the current -waveform. -

int wave_get_high_cbs(void)

-This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. -

int wave_get_max_cbs(void)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

int gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. -

int store_script(char *script)

-This function stores a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

script: the text of the script.


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int run_script(unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int script_status(unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. -

script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int stop_script(unsigned script_id)

-This function stops a running script. -

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int delete_script(unsigned script_id)

-This function deletes a stored script. -

script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int bb_serial_read_open(unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the bb_serial_read_open command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int bb_serial_read_close(unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int bb_serial_invert(unsigned user_gpio, unsigned invert)

-This function inverts serial logic for big bang serial reads. -

user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. -

int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

-This returns a handle for the device at address i2c_addr on bus i2c_bus. -

  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.

Addr  (7 bits): I2C 7 bit address.
Comm  (8 bits): Command byte, a data byte which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A data byte containing the length of a block operation.

[..]: Data sent by the device.

int i2c_close(unsigned handle)

-This closes the I2C device associated with the handle. -

handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2c_write_quick(unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr Rd/Wr [A] P

int i2c_write_byte(unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] Data [A] P

int i2c_read_byte(unsigned handle)

-This reads a single byte from the device associated with handle. -

handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] Comm [A] Data [A] P

int i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P

int i2c_read_byte_data(unsigned handle, unsigned i2c_reg)

-This reads a single byte from the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(unsigned handle, unsigned i2c_reg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P

int i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] Comm [A] Count [A] Data [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] Comm [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P

int i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P

int i2c_read_device(unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

int i2c_write_device(unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

int i2c_zip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_i2c_open(unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bb_i2c_close(unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bb_i2c_open. -

SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bb_i2c_zip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int spi_open(unsigned spi_channel, unsigned baud, unsigned spi_flags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per word.
-For bits 9-16 there will be two bytes per word.
-For bits 17-32 there will be four bytes per word. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spi_close(unsigned handle)

-This functions closes the SPI device identified by the handle. -

handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spi_read(unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_write(unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serial_open(char *ser_tty, unsigned baud, unsigned ser_flags)

-This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. -

  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serial_close(unsigned handle)

-This function closes the serial device associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serial_write_byte(unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read_byte(unsigned handle)

-This function reads a byte from the serial port associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serial_write(unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read(unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. -

handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. -

If no data is ready zero is returned. -

int serial_data_available(unsigned handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int custom_1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int custom_2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from custom_1 in that it returns an array of bytes -rather than just an integer. -

The return value is an integer indicating the number of returned bytes. -  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

Note, the number of returned bytes will be retMax or less. -

int callback(unsigned user_gpio, unsigned edge, CBFunc_t f)

-This function initialises a new callback. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

int callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

-This function initialises a new callback. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, tick, and user, whenever -the GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

-This function cancels a callback identified by its id. -

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)

-This function waits for edge on the GPIO for up to timeout -seconds. -

user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns 1 if the edge occurred, otherwise 0. -

The function returns when the edge occurs or after the timeout. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

*addrStr

-A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

callback_id

-A >=0, as returned by a call to callback or callback_ex. This is -passed to callback_cancel to cancel the callback. -

CBFunc_t

-typedef void (*CBFunc_t)
   (unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

-typedef void (*CBFuncEx_t)
   (unsigned user_gpio, unsigned level, uint32_t tick, void * user);

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250000000 (250M)

-The hardware clock frequency. -

count

-The number of bytes to be transferred in an I2C, SPI, or Serial -command. -

data_bits: 1-32

-The number of data bits in each character of serial data. -

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge

-Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. -

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

-A negative number indicating a function call failed and the nature -of the error. -

f

-A function. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 get_hardware_revision. -

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  -  -  -  -

gpioPulse_t

-typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

-A number referencing an object opened by one of i2c_open, notify_open, -serial_open, and spi_open. -

i2c_addr: 0-0x7F

-The address of a device on the I2C bus. -

i2c_bus: >=0

-An I2C bus number. -

i2c_flags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2c_reg: 0-255

-A register of an I2C device. -

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See set_watchdog. -

PI_TIMEOUT 2

mode: 0-7

-The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

*param

-An array of script parameters. -

*portStr

-A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. -

*pth

-A thread identifier, returned by start_thread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125000000 (125M)

-The hardware PWM frequency. -

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000

range: 25-40000

-The permissible dutycycle values are 0-range. -PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by store_script. -

SDA

-The user GPIO to use for data when bit banging I2C. -

seconds

-The number of seconds. -

ser_flags

-Flags which modify a serial open command. None are currently defined. -

*ser_tty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

size_t

-A standard type used to indicate the size of an object in bytes. -

spi_channel

-A SPI channel, 0-2. -

spi_flags

-See spi_open. -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) or triggering -the active part of a noise filter (set_noise_filter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

- An array of characters. -

thread_func

-A function of type gpioThreadFunc_t used as the main function of a -thread. -

timeout

-A GPIO watchdog timeout in milliseconds. -PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

unsigned

-A whole number >= 0. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

void

-Denoting no parameter is required -

wave_add_*

-One of wave_add_new, wave_add_generic, wave_add_serial. -

wave_id

-A number representing a waveform created by wave_create. -

wave_send_*

-One of wave_send_once, wave_send_repeat. -

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

pigpiod_if Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
} pigifError_t;

\ No newline at end of file diff --git a/DOC/tmp/body/pdif2.body b/DOC/tmp/body/pdif2.body deleted file mode 100644 index 21d2b4b..0000000 --- a/DOC/tmp/body/pdif2.body +++ /dev/null @@ -1,1460 +0,0 @@ -

pigpiod_if2 is a C library for the Raspberry which allows control -of the GPIO via the socket interface to the pigpio daemon.
-

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o callbacks at timed intervals -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o rudimentary permission control over GPIO -

o a simple interface to start and stop new threads -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals. -

Usage

Include <pigpiod_if2.h> in your source files. -

Assuming your source is in prog.c use the following command to build -

gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt


to run make sure the pigpio daemon is running -

sudo pigpiod

 ./prog # sudo is not required to run programs linked to pigpiod_if2


For examples see x_pigpiod_if2.c within the pigpio archive file. -

Notes

All the functions which return an int return < 0 on error -

OVERVIEW

ESSENTIAL -
pigpio_start Connects to a pigpio daemon -
pigpio_stop Disconnects from a pigpio daemon -
BASIC -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
gpio_read Read a GPIO -
gpio_write Write a GPIO -
PWM (overrides servo commands on same GPIO) -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
set_PWM_frequency Configure PWM frequency for a GPIO -
set_PWM_range Configure PWM range for a GPIO -
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -
get_PWM_frequency Get configured PWM frequency for a GPIO -
get_PWM_range Get configured PWM range for a GPIO -
get_PWM_real_range Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
set_servo_pulsewidth Start/stop servo pulses on a GPIO -
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO. -
set_watchdog Set a watchdog on a GPIO. -
read_bank_1 Read all GPIO in bank 1 -
read_bank_2 Read all GPIO in bank 2 -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
callback Create GPIO level change callback -
callback_ex Create GPIO level change callback, extended -
callback_cancel Cancel a callback -
wait_for_edge Wait for GPIO level change -
start_thread Start a new thread -
stop_thread Stop a previously started thread -
ADVANCED -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
set_pad_strength Sets a pads drive strength -
get_pad_strength Gets a pads drive strength -
shell_ Executes a shell command -
Custom -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
Events -
event_callback Sets a callback for an event -
event_callback_ex Sets a callback for an event, extended -
event_callback_cancel Cancel an event callback -
event_trigger Triggers an event -
wait_for_event Wait for an event -
Scripts -
store_script Store a script -
run_script Run a stored script -
update_script Set a scripts parameters -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick smbus write quick -
i2c_read_byte smbus read byte -
i2c_write_byte smbus write byte -
i2c_read_byte_data smbus read byte data -
i2c_write_byte_data smbus write byte data -
i2c_read_word_data smbus read word data -
i2c_write_word_data smbus write word data -
i2c_read_block_data smbus read block data -
i2c_write_block_data smbus write block data -
i2c_read_i2c_block_data smbus read I2C block data -
i2c_write_i2c_block_data smbus write I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_process_call smbus process call -
i2c_block_process_call smbus block process call -
i2c_zip Performs multiple I2C transactions -
I2C BIT BANG -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs bit banged I2C transactions -
I2C/SPI SLAVE -
bsc_xfer I2C/SPI as slave transfer -
bsc_i2c I2C as slave transfer -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read Reads bytes from a serial device -
serial_write Writes bytes to a serial device -
serial_data_available Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
bb_serial_read_open Opens a GPIO for bit bang serial reads -
bb_serial_read_close Closes a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
bb_serial_read Reads bit bang serial data from a GPIO -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SPI BIT BANG -
bb_spi_open Opens GPIO for bit banging SPI -
bb_spi_close Closes GPIO for bit banging SPI -
bb_spi_xfer Transfers bytes with bit banging SPI -
FILES -
file_open Opens a file -
file_close Closes a file -
file_read Reads bytes from a file -
file_write Writes bytes to a file -
file_seek Seeks to a position within a file -
file_list List files which match a pattern -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_create_and_pad Creates a waveform of fixed size from added data -
wave_delete Deletes one or more waveforms -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_send_using_mode Transmits a waveform in the chosen mode -
wave_chain Transmits a chain of waveforms -
wave_tx_at Returns the current transmitting waveform -
wave_tx_busy Checks to see if the waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_cbs Length in cbs of the current waveform -
wave_get_high_cbs Length of longest waveform so far -
wave_get_max_cbs Absolute maximum allowed cbs -
wave_get_micros Length in micros of the current waveform -
wave_get_high_micros Length of longest waveform so far -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_high_pulses Length of longest waveform so far -
wave_get_max_pulses Absolute maximum allowed pulses -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpiod_if_version Get the pigpiod_if2 version -
pigpio_error Get a text description of an error code. -
time_sleep Sleeps for a float number of seconds -
time_time Float number of seconds since the epoch -

FUNCTIONS

double time_time(void)

-Return the current time in seconds since the Epoch. -

void time_sleep(double seconds)

-Delay execution for a given number of seconds. -

seconds: the number of seconds to delay.

char *pigpio_error(int errnum)

-Return a text description for an error code. -

errnum: the error code.

unsigned pigpiod_if_version(void)

-Return the pigpiod_if2 version. -

pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)

-Starts a new thread of execution with thread_func as the main routine. -

thread_func: the main function for the new thread.
   userdata: a pointer to an arbitrary argument.


Returns a pointer to pthread_t if OK, otherwise NULL. -

The function is passed the single argument userdata. -

The thread can be cancelled by passing the pointer to pthread_t to -stop_thread. -

void stop_thread(pthread_t *pth)

-Cancels the thread pointed at by pth. -

pth: the thread to be stopped.


No value is returned. -

The thread to be stopped should have been started with start_thread. -

int pigpio_start(char *addrStr, char *portStr)

-Connect to the pigpio daemon. Reserving command and -notification streams. -

addrStr: specifies the host or IP address of the Pi running the
         pigpio daemon.  It may be NULL in which case localhost
         is used unless overridden by the PIGPIO_ADDR environment
         variable.

portStr: specifies the port address used by the Pi running the
         pigpio daemon.  It may be NULL in which case "8888"
         is used unless overridden by the PIGPIO_PORT environment
         variable.


Returns an integer value greater than or equal to zero if OK. -

This value is passed to the GPIO routines to specify the Pi -to be operated on. -

void pigpio_stop(int pi)

-Terminates the connection to a pigpio daemon and releases -resources used by the library. -

pi: >=0 (as returned by pigpio_start).

int set_mode(int pi, unsigned gpio, unsigned mode)

-Set the GPIO mode. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
      PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, -or PI_NOT_PERMITTED. -

int get_mode(int pi, unsigned gpio)

-Get the GPIO mode. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.


Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. -

int set_pull_up_down(int pi, unsigned gpio, unsigned pud)

-Set or clear the GPIO pull-up/down resistor. -

  pi: >=0 (as returned by pigpio_start).
gpio: 0-53.
 pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD, -or PI_NOT_PERMITTED. -

int gpio_read(int pi, unsigned gpio)

-Read the GPIO level. -

  pi: >=0 (as returned by pigpio_start).
gpio:0-53.


Returns the GPIO level if OK, otherwise PI_BAD_GPIO. -

int gpio_write(int pi, unsigned gpio, unsigned level)

-Write the GPIO level. -

   pi: >=0 (as returned by pigpio_start).
 gpio: 0-53.
level: 0, 1.


Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL, -or PI_NOT_PERMITTED. -

Notes -

If PWM or servo pulses are active on the GPIO they are switched off. -

int set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)

-Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE, -or PI_NOT_PERMITTED. -Notes -

The set_PWM_range function may be used to change the -default range of 255. -

int get_PWM_dutycycle(int pi, unsigned user_gpio)

-Return the PWM dutycycle in use on a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported dutycycle -will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

int set_PWM_range(int pi, unsigned user_gpio, unsigned range)

-Set the range of PWM values to be used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
    range: 25-40000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE, -or PI_NOT_PERMITTED. -

Notes -

If PWM is currently active on the GPIO its dutycycle will be -scaled to reflect the new range. -

The real range, the number of steps between fully off and fully on -for each of the 18 available GPIO frequencies is -

  25(#1),    50(#2),   100(#3),   125(#4),    200(#5),    250(#6),
 400(#7),   500(#8),   625(#9),   800(#10),  1000(#11),  1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)


The real value set by set_PWM_range is (dutycycle * real range) / range. -

int get_PWM_range(int pi, unsigned user_gpio)

-Get the range of PWM values being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the dutycycle range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock or hardware PWM is active on the GPIO the -reported range will be 1000000 (1M). -

int get_PWM_real_range(int pi, unsigned user_gpio)

-Get the real underlying range of PWM values being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns the real range used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

int set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)

-Set the frequency (in Hz) of the PWM to be used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
frequency: >=0 (Hz).


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5

int get_PWM_frequency(int pi, unsigned user_gpio)

-Get the frequency of PWM being used on the GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


For normal PWM the frequency will be that defined for the GPIO by -set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Returns the frequency (in hertz) used for the GPIO if OK, -otherwise PI_BAD_USER_GPIO. -

int set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)

-Start (500-2500) or stop (0) servo pulses on the GPIO. -

        pi: >=0 (as returned by pigpio_start).
 user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or -PI_NOT_PERMITTED. -

The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably be -determined by experiment. A value of 1500 should always be safe and -represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its limits. -

OTHER UPDATE RATES: -

This function updates servos at 50Hz. If you wish to use a different -update frequency you will have to use the PWM functions. -

Update Rate (Hz)     50   100  200  400  500
1E6/Hz            20000 10000 5000 2500 2000


Firstly set the desired PWM frequency using set_PWM_frequency. -

Then set the PWM range using set_PWM_range to 1E6/Hz. -Doing this allows you to use units of microseconds when setting -the servo pulsewidth. -

E.g. If you want to update a servo connected to GPIO 25 at 400Hz -

set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);


Thereafter use the set_PWM_dutycycle function to move the servo, -e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-

int get_servo_pulsewidth(int pi, unsigned user_gpio)

-Return the servo pulsewidth in use on a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. -

int notify_open(int pi)

-Get a free notification handle. -

pi: >=0 (as returned by pigpio_start).


Returns a handle greater than or equal to zero if OK, -otherwise PI_NO_HANDLE. -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this function -serves no purpose if you are using the library from a remote machine. -The in-built (socket) notifications provided by callback -should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

int notify_begin(int pi, unsigned handle, uint32_t bits)

-Start notifications on a previously opened handle. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)
  bits: a mask indicating the GPIO to be notified.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

Each notification occupies 12 bytes in the fifo as follows: -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments -by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive -signal on the pipe/socket and is sent once a minute in the absence -of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags -indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps around -after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set then -GPIO x is high. -

int notify_pause(int pi, unsigned handle)

-Pause notifications on a previously opened handle. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Notifications for the handle are suspended until -notify_begin is called again. -

int notify_close(int pi, unsigned handle)

-Stop notifications on a previously opened handle and -release the handle for reuse. -

    pi: >=0 (as returned by pigpio_start).
handle: 0-31 (as returned by notify_open)


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int set_watchdog(int pi, unsigned user_gpio, unsigned timeout)

-Sets a watchdog for a GPIO. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
  timeout: 0-60000.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO -or PI_BAD_WDOG_TIMEOUT. -

The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO will be -triggered every timeout interval after the last GPIO activity. -

The callback will receive the special level PI_TIMEOUT. -

int set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than -steady microseconds are ignored. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Each (stable) edge will be timestamped steady microseconds -after it was first detected. -

int set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level changes -on the GPIO are then reported for active microseconds after -which the process repeats. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31
   steady: 0-300000
   active: 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback, callback_ex and wait_for_edge. -

It does not affect levels read by gpio_read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

uint32_t read_bank_1(int pi)

-Read the levels of the bank 1 GPIO (GPIO 0-31). -

pi: >=0 (as returned by pigpio_start).


The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<n). -

uint32_t read_bank_2(int pi)

-Read the levels of the bank 2 GPIO (GPIO 32-53). -

pi: >=0 (as returned by pigpio_start).


The returned 32 bit integer has a bit set if the corresponding -GPIO is logic 1. GPIO n has bit value (1<<(n-32)). -

int clear_bank_1(int pi, uint32_t bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int clear_bank_2(int pi, uint32_t bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be cleared.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_1(int pi, uint32_t bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int set_bank_2(int pi, uint32_t bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

  pi: >=0 (as returned by pigpio_start).
bits: a bit mask with 1 set if the corresponding GPIO is
      to be set.


Returns 0 if OK, otherwise PI_SOME_PERMITTED. -

A status of PI_SOME_PERMITTED indicates that the user is not -allowed to write to one or more of the GPIO. -

int hardware_clock(int pi, unsigned gpio, unsigned clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

       pi: >=0 (as returned by pigpio_start).
     gpio: see description
frequency: 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following. -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will likely -crash the Pi. The password is given by or'ing 0x5A000000 with the -GPIO number. -

int hardware_PWM(int pi, unsigned gpio, unsigned PWMfreq, uint32_t PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency and dutycycle. -Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_* or wave_chain -will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

     pi: >=0 (as returned by pigpio_start).
   gpio: see descripton
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, -or PI_HPWM_ILLEGAL. -

The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. PWMduty is -automatically scaled to take this into account. -

uint32_t get_current_tick(int pi)

-Gets the current system tick. -

pi: >=0 (as returned by pigpio_start).


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. -

uint32_t get_hardware_revision(int pi)

-Get the Pi's hardware revision number. -

pi: >=0 (as returned by pigpio_start).


The hardware revision is the last few characters on the Revision line -of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

uint32_t get_pigpio_version(int pi)

-Returns the pigpio version. -

pi: >=0 (as returned by pigpio_start).

int wave_clear(int pi)

-This function clears all waveforms and any data added by calls to the -wave_add_* functions. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

int wave_add_new(int pi)

-This function starts a new empty waveform. You wouldn't normally need -to call this function as it is automatically called after a waveform is -created with the wave_create function. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

int wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses)

-This function adds a number of pulses to the current waveform. -

       pi: >=0 (as returned by pigpio_start).
numPulses: the number of pulses.
   pulses: an array of pulses.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_TOO_MANY_PULSES. -

The pulses are interleaved in time order within the existing waveform -(if any). -

Merging allows the waveform to be built in parts, that is the settings -for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within the existing -waveform then the first pulse should consist solely of a delay. -

int wave_add_serial(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)

-This function adds a waveform representing serial data to the -existing waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-1000000
data_bits: number of data bits (1-32)
stop_bits: number of stop half bits (2-8)
   offset: >=0
 numBytes: >=1
      str: an array of chars.


Returns the new total number of pulses in the current waveform if OK, -otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, -PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, -or PI_TOO_MANY_PULSES. -

NOTES: -

The serial data is formatted as one start bit, data_bits data bits, -and stop_bits/2 stop bits. -

It is legal to add serial data streams with different baud rates to -the same waveform. -

numBytes is the number of bytes of data in str. -

The bytes required for each character depend upon data_bits. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int wave_create(int pi)

-This function creates a waveform from the data provided by the prior -calls to the wave_add_* functions. Upon success a wave id -greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

pi: >=0 (as returned by pigpio_start).


The data provided by the wave_add_* functions is consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. Each pulse consists of a -gpioPulse_t structure. -

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;


The fields specify -

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. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_create_and_pad(int pi, int percent)

-This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use (in terms -of the theoretical maximum, not the current amount free). This allows the reuse
-of deleted waves while a transmission is active. -

pi: >=0 (as returned by pigpio_start).
percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

A usage would be the creation of two waves where one is filled while the other -is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Normal usage: -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create_and_pad to create a waveform of uniform size. -

Step 4. wave_send_* with the id of the waveform to transmit. -

Repeat steps 2-4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM, -PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL. -

int wave_delete(int pi, unsigned wave_id)

-This function deletes the waveform with id wave_id. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Returns 0 if OK, otherwise PI_BAD_WAVE_ID. -

int wave_send_once(int pi, unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -is sent once. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_repeat(int pi, unsigned wave_id)

-This function transmits the waveform with id wave_id. The waveform -cycles until cancelled (either by the sending of a new waveform or -by wave_tx_stop). -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.


Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_send_using_mode(int pi, unsigned wave_id, unsigned mode)

-Transmits the waveform with id wave_id using mode mode. -

     pi: >=0 (as returned by pigpio_start).
wave_id: >=0, as returned by wave_create.
   mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
         PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC.


PI_WAVE_MODE_ONE_SHOT: same as wave_send_once. -

PI_WAVE_MODE_REPEAT same as wave_send_repeat. -

PI_WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries -to sync with the previous waveform. -

PI_WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries -to sync with the previous waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

Returns the number of DMA control blocks in the waveform if OK, -otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE. -

int wave_chain(int pi, char *buf, unsigned bufSize)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM will be cancelled. -

The waves to be transmitted are specified by the contents of buf -which contains an ordered list of wave_ids and optional command -codes and related data. -

     pi: >=0 (as returned by pigpio_start).
    buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf


Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER, -PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave may -occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by using -the loop commands. The block is bracketed by loop start and -end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#include <stdio.h>
#include <pigpiod_if2.h>

#define WAVES 5
#define GPIO 4

int main(int argc, char *argv[])
{
   int i, pi, wid[WAVES];

   pi = pigpio_start(0, 0);
   if (pi<0) return -1;

   set_mode(pi, GPIO, PI_OUTPUT);

   for (i=0; i<WAVES; i++)
   {
      wave_add_generic(pi, 2, (gpioPulse_t[])
         {{1<<GPIO, 0,        20},
          {0, 1<<GPIO, (i+1)*200}});

      wid[i] = wave_create(pi);
   }

   wave_chain(pi, (char []) {
      wid[4], wid[3], wid[2],       // transmit waves 4+3+2
      255, 0,                       // loop start
         wid[0], wid[0], wid[0],    // transmit waves 0+0+0
         255, 0,                    // loop start
            wid[0], wid[1],         // transmit waves 0+1
            255, 2, 0x88, 0x13,     // delay 5000us
         255, 1, 30, 0,             // loop end (repeat 30 times)
         255, 0,                    // loop start
            wid[2], wid[3], wid[0], // transmit waves 2+3+0
            wid[3], wid[1], wid[2], // transmit waves 3+1+2
         255, 1, 10, 0,             // loop end (repeat 10 times)
      255, 1, 5, 0,                 // loop end (repeat 5 times)
      wid[4], wid[4], wid[4],       // transmit waves 4+4+4
      255, 2, 0x20, 0x4E,           // delay 20000us
      wid[0], wid[0], wid[0],       // transmit waves 0+0+0

      }, 46);

   while (wave_tx_busy(pi)) time_sleep(0.1);

   for (i=0; i<WAVES; i++) wave_delete(pi, wid[i]);

   pigpio_stop(pi);
}

int wave_tx_at(int pi)

-This function returns the id of the waveform currently being -transmitted. -

pi: >=0 (as returned by pigpio_start).


Returns the waveform id or one of the following special values: -

PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
-PI_NO_TX_WAVE (9999) - no wave being transmitted. -

int wave_tx_busy(int pi)

-This function checks to see if a waveform is currently being -transmitted. -

pi: >=0 (as returned by pigpio_start).


Returns 1 if a waveform is currently being transmitted, otherwise 0. -

int wave_tx_stop(int pi)

-This function stops the transmission of the current waveform. -

pi: >=0 (as returned by pigpio_start).


Returns 0 if OK. -

This function is intended to stop a waveform started with the repeat mode. -

int wave_get_micros(int pi)

-This function returns the length in microseconds of the current -waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_micros(int pi)

-This function returns the length in microseconds of the longest waveform -created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_micros(int pi)

-This function returns the maximum possible size of a waveform in
-microseconds. -

pi: >=0 (as returned by pigpio_start).

int wave_get_pulses(int pi)

-This function returns the length in pulses of the current waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_pulses(int pi)

-This function returns the length in pulses of the longest waveform -created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_pulses(int pi)

-This function returns the maximum possible size of a waveform in pulses. -

pi: >=0 (as returned by pigpio_start).

int wave_get_cbs(int pi)

-This function returns the length in DMA control blocks of the current -waveform. -

pi: >=0 (as returned by pigpio_start).

int wave_get_high_cbs(int pi)

-This function returns the length in DMA control blocks of the longest -waveform created since the pigpio daemon was started. -

pi: >=0 (as returned by pigpio_start).

int wave_get_max_cbs(int pi)

-This function returns the maximum possible size of a waveform in DMA -control blocks. -

pi: >=0 (as returned by pigpio_start).

int gpio_trigger(int pi, unsigned user_gpio, unsigned pulseLen, unsigned level)

-This function sends a trigger pulse to a GPIO. The GPIO is set to -level for pulseLen microseconds and then reset to not level. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
 pulseLen: 1-100.
    level: 0,1.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, -PI_BAD_PULSELEN, or PI_NOT_PERMITTED. -

int store_script(int pi, char *script)

-This function stores a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for details. -

    pi: >=0 (as returned by pigpio_start).
script: the text of the script.


The function returns a script id if the script is valid, -otherwise PI_BAD_SCRIPT. -

int run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

-This function runs a stored script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int update_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param)

-This function sets the parameters of a script. The script may or -may not be running. The first numPar parameters of the script are -overwritten with the new values. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
   numPar: 0-10, the number of parameters.
    param: an array of parameters.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or -PI_TOO_MANY_PARAM. -

param is an array of up to 10 parameters which may be referenced in -the script as p0 to p9. -

int script_status(int pi, unsigned script_id, uint32_t *param)

-This function returns the run status of a stored script as well -as the current values of parameters 0 to 9. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.
    param: an array to hold the returned 10 parameters.


The function returns greater than or equal to 0 if OK, -otherwise PI_BAD_SCRIPT_ID. -

The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The current value of script parameters 0 to 9 are returned in param. -

int stop_script(int pi, unsigned script_id)

-This function stops a running script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int delete_script(int pi, unsigned script_id)

-This function deletes a stored script. -

       pi: >=0 (as returned by pigpio_start).
script_id: >=0, as returned by store_script.


The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID. -

int bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data_bits)

-This function opens a GPIO for bit bang reading of serial data. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     baud: 50-250000
data_bits: 1-32


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, -or PI_GPIO_IN_USE. -

The serial data is returned in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic buffer -in a timely fashion. -

int bb_serial_read(int pi, unsigned user_gpio, void *buf, size_t bufSize)

-This function copies up to bufSize bytes of data read from the -bit bang serial cyclic buffer to the buffer starting at buf. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
      buf: an array to receive the read bytes.
  bufSize: >=0


Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO -or PI_NOT_SERIAL_GPIO. -

The bytes returned for each character depend upon the number of -data bits data_bits specified in the bb_serial_read_open command. -

For data_bits 1-8 there will be one byte per character.
-For data_bits 9-16 there will be two bytes per character.
-For data_bits 17-32 there will be four bytes per character. -

int bb_serial_read_close(int pi, unsigned user_gpio)

-This function closes a GPIO for bit bang reading of serial data. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. -

int bb_serial_invert(int pi, unsigned user_gpio, unsigned invert)

-This function inverts serial logic for big bang serial reads. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31, previously opened with bb_serial_read_open.
   invert: 0-1, 1 invert, 0 normal.


Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT. -

int i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)

-This returns a handle for the device at address i2c_addr on bus i2c_bus. -

       pi: >=0 (as returned by pigpio_start).
  i2c_bus: >=0.
 i2c_addr: 0-0x7F.
i2c_flags: 0.


No flags are currently defined. This parameter should be set to zero. -

Physically buses 0 and 1 are available on the Pi. Higher numbered buses -will be available if a kernel supported bus multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR, -PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED. -

For the SMBus commands the low level transactions are shown at the end -of the function description. The following abbreviations are used. -

S       (1 bit) : Start bit
P       (1 bit) : Stop bit
Rd/Wr   (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA   (1 bit) : Accept and not accept bit.

Addr    (7 bits): I2C 7 bit address.
i2c_reg (8 bits): A byte which often selects a register.
Data    (8 bits): A data byte.
Count   (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.

int i2c_close(int pi, unsigned handle)

-This closes the I2C device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int i2c_write_quick(int pi, unsigned handle, unsigned bit)

-This sends a single bit (in the Rd/Wr bit) to the device associated -with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   bit: 0-1, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Quick command. SMBus 2.0 5.5.1 -S Addr bit [A] P

int i2c_write_byte(int pi, unsigned handle, unsigned bVal)

-This sends a single byte to the device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
  bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Send byte. SMBus 2.0 5.5.2 -S Addr Wr [A] bVal [A] P

int i2c_read_byte(int pi, unsigned handle)

-This reads a single byte from the device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -or PI_I2C_READ_FAILED. -

Receive byte. SMBus 2.0 5.5.3 -S Addr Rd [A] [Data] NA P

int i2c_write_byte_data(int pi, unsigned handle, unsigned i2c_reg, unsigned bVal)

-This writes a single byte to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   bVal: 0-0xFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write byte. SMBus 2.0 5.5.4 -S Addr Wr [A] i2c_reg [A] bVal [A] P

int i2c_write_word_data(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes a single 16 bit word to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
   wVal: 0-0xFFFF, the value to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Write word. SMBus 2.0 5.5.4 -S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P

int i2c_read_byte_data(int pi, unsigned handle, unsigned i2c_reg)

-This reads a single byte from the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read byte. SMBus 2.0 5.5.5 -S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P

int i2c_read_word_data(int pi, unsigned handle, unsigned i2c_reg)

-This reads a single 16 bit word from the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Read word. SMBus 2.0 5.5.5 -S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_process_call(int pi, unsigned handle, unsigned i2c_reg, unsigned wVal)

-This writes 16 bits of data to the specified register of the device -associated with handle and and reads 16 bits of data in return. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
   wVal: 0-0xFFFF, the value to write.


Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Process call. SMBus 2.0 5.5.6 -S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P

int i2c_write_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes up to 32 bytes to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: an array with the data to send.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

Block write. SMBus 2.0 5.5.7 -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ...
   [A] bufn [A] P

int i2c_read_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf)

-This reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.


The amount of returned data is set by the device. -

Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

Block read. SMBus 2.0 5.5.7 -S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P

int i2c_block_process_call(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write/read.
    buf: an array with the data to send and to receive the read data.
  count: 1-32, the number of bytes to write.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

The smbus 2.0 documentation states that a minimum of 1 byte may be -sent and a minimum of 1 byte may be received. The total number of -bytes sent/received must be 32 or less. -

Block write-block read. SMBus 2.0 5.5.8 -S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ...
   S Addr Rd [A] [Count] A [Data] ... A P

int i2c_read_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to read.
    buf: an array to receive the read data.
  count: 1-32, the number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, or PI_I2C_READ_FAILED. -

S Addr Wr [A] i2c_reg [A]
   S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_i2c_block_data(int pi, unsigned handle, unsigned i2c_reg, char *buf, unsigned count)

-This writes 1 to 32 bytes to the specified register of the device -associated with handle. -

     pi: >=0 (as returned by pigpio_start).
 handle: >=0, as returned by a call to i2c_open.
i2c_reg: 0-255, the register to write.
    buf: the data to write.
  count: 1-32, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_read_device(int pi, unsigned handle, char *buf, unsigned count)

-This reads count bytes from the raw device into buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array to receive the read data bytes.
 count: >0, the number of bytes to read.


Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_READ_FAILED. -

S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P

int i2c_write_device(int pi, unsigned handle, char *buf, unsigned count)

-This writes count bytes from buf to the raw device. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2c_open.
   buf: an array containing the data bytes to write.
 count: >0, the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_I2C_WRITE_FAILED. -

S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P

int i2c_zip(int pi, unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to i2cOpen
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN. -PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_i2c_open(int pi, unsigned SDA, unsigned SCL, unsigned baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o I2C on any pair of spare GPIO -

  pi: >=0 (as returned by pigpio_start).
 SDA: 0-31
 SCL: 0-31
baud: 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As -a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

int bb_i2c_close(int pi, unsigned SDA)

-This function stops bit banging I2C on a pair of GPIO previously -opened with bb_i2c_open. -

 pi: >=0 (as returned by pigpio_start).
SDA: 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

int bb_i2c_zip(int pi, unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)

-This function executes a sequence of bit banged I2C operations. The -operations to be performed are specified by the contents of inBuf -which contains the concatenated command codes and associated data. -

    pi: >=0 (as returned by pigpio_start).
   SDA: 0-31 (as used in a prior call to bb_i2c_open)
 inBuf: pointer to the concatenated I2C commands, see below
 inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER, -PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN, -PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED. -

The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

The returned I2C data is stored in consecutive locations of outBuf. -

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

int bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)

-This function selects a set of GPIO for bit banging SPI at a -specified baud rate. -

       pi: >=0 (as returned by pigpio_start).
       CS: 0-31
     MISO: 0-31
     MOSI: 0-31
     SCLK: 0-31
     baud: 50-250000
spi_flags: see below


spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0    0    0
 1    0    1
 2    1    0
 3    1    1


p is 0 if CS is active low (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. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2

int bb_spi_close(int pi, unsigned CS)

-This function stops bit banging SPI on a set of GPIO -opened with bbSPIOpen. -

pi: >=0 (as returned by pigpio_start).
CS: 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

int bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)

-This function executes a bit banged SPI transfer. -

   pi: >=0 (as returned by pigpio_start).
   CS: 0-31 (as used in a prior call to bb_spi_open)
txBuf: pointer to buffer to hold data to be sent
rxBuf: pointer to buffer to hold returned data
count: size of data transfer


Returns >= 0 if OK (the number of bytes read), otherwise -PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. -

Example

// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2
// ./bb_spi_x_test

#include <stdio.h>

#include "pigpiod_if2.h"

#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12

int main(int argc, char *argv[])
{
   int i, pi, count, set_val, read_val;
   unsigned char inBuf[3];
   char cmd1[] = {0, 0};
   char cmd2[] = {12, 0};
   char cmd3[] = {1, 128, 0};

   if ((pi = pigpio_start(0, 0)) < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
   bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC

   for (i=0; i<256; i++)
   {
      cmd1[1] = i;

      count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC

      if (count == 2)
      {
         count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC

         if (count == 2)
         {
            set_val = inBuf[1];

            count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC

            if (count == 3)
            {
               read_val = ((inBuf[1]&3)<<8) | inBuf[2];
               printf("%d %d\n", set_val, read_val);
            }
         }
      }
   }

   bb_spi_close(pi, CE0);
   bb_spi_close(pi, CE1);

   pigpio_stop(pi);
}

int spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)

-This function returns a handle for the SPI device on the channel. -Data will be transferred at baud bits per second. The flags may -be used to modify the default behaviour of 4-wire operation, mode 0, -active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


         pi: >=0 (as returned by pigpio_start).
spi_channel: 0-1 (0-2 for the auxiliary SPI).
       baud: 32K-125M (values above 30M are unlikely to work).
  spi_flags: see below.


Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, -PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. -

spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

Warning: modes 1 and 3 do not appear to work on the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per character.
-For bits 9-16 there will be two bytes per character.
-For bits 17-32 there will be four bytes per character. -

Multi-byte transfers are made in least significant byte first order. -

E.g. to transfer 32 11-bit words buf should contain 64 bytes -and count should be 64. -

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. -

int spi_close(int pi, unsigned handle)

-This functions closes the SPI device identified by the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int spi_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads count bytes of data from the SPI -device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: an array to receive the read data bytes.
 count: the number of bytes to read.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes of data from buf to the SPI -device associated with the handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
   buf: the data bytes to write.
 count: the number of bytes to write.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int spi_xfer(int pi, unsigned handle, char *txBuf, char *rxBuf, unsigned count)

-This function transfers count bytes of data from txBuf to the SPI -device associated with the handle. Simultaneously count bytes of -data are read from the device and placed in rxBuf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to spi_open.
 txBuf: the data bytes to write.
 rxBuf: the received data bytes.
 count: the number of bytes to transfer.


Returns the number of bytes transferred if OK, otherwise -PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. -

int serial_open(int pi, char *ser_tty, unsigned baud, unsigned ser_flags)

-This function opens a serial device at a specified baud rate -with specified flags. The device name must start with -/dev/tty or /dev/serial. -

       pi: >=0 (as returned by pigpio_start).
  ser_tty: the serial device to open.
     baud: the baud rate in bits per second, see below.
ser_flags: 0.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or -PI_SER_OPEN_FAILED. -

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. -

No flags are currently defined. This parameter should be set to zero. -

int serial_close(int pi, unsigned handle)

-This function closes the serial device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

int serial_write_byte(int pi, unsigned handle, unsigned bVal)

-This function writes bVal to the serial port associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read_byte(int pi, unsigned handle)

-This function reads a byte from the serial port associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. -

If no data is ready PI_SER_READ_NO_DATA is returned. -

int serial_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the serial port -associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or -PI_SER_WRITE_FAILED. -

int serial_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the serial port -associated with handle and writes them to buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, -PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. -

If no data is ready zero is returned. -

int serial_data_available(int pi, unsigned handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0, as returned by a call to serial_open.


Returns the number of bytes of data available (>=0) if OK, -otherwise PI_BAD_HANDLE. -

int custom_1(int pi, unsigned arg1, unsigned arg2, char *argx, unsigned argc)

-This function is available for user customisation. -

It returns a single integer value. -

  pi: >=0 (as returned by pigpio_start).
arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments


Returns >= 0 if OK, less than 0 indicates a user defined error. -

int custom_2(int pi, unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)

-This function is available for user customisation. -

It differs from custom_1 in that it returns an array of bytes -rather than just an integer. -

The return value is an integer indicating the number of returned bytes. -    pi: >=0 (as returned by pigpio_start).
  arg1: >=0
  argc: extra (byte) arguments
 count: number of extra arguments
retBuf: buffer for returned data
retMax: maximum number of bytes to return


Returns >= 0 if OK, less than 0 indicates a user defined error. -

Note, the number of returned bytes will be retMax or less. -

int get_pad_strength(int pi, unsigned pad)

-This function returns the pad drive strength in mA. -

 pi: >=0 (as returned by pigpio_start).
pad: 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = get_pad_strength(pi, 0); //  get pad 0 strength

int set_pad_strength(int pi, unsigned pad, unsigned padStrength)

-This function sets the pad drive strength in mA. -

         pi: >=0 (as returned by pigpio_start).
        pad: 0-2, the pad to set.
padStrength: 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA

int shell_(int pi, char *scriptName, char *scriptString)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

          pi: >=0 (as returned by pigpio_start).
  scriptName: the name of the script, only alphanumeric characters,
              '-' and '_' are allowed in the name.
scriptString: the string to pass to the script.


The exit status of the system call is returned if OK, otherwise -PI_BAD_SHELL_STATUS. -

scriptName must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by the -shell script exit function. If the script can't be found 32512 will -be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = shell_(pi, "scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = shell_(pi, "scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = shell_(pi, "scr1", "\"hello string with spaces world\"");

int file_open(int pi, char *file, unsigned mode)

-This function returns a handle to a file opened in a specified mode. -

  pi: >=0 (as returned by pigpio_start).
file: the file to open.
mode: the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, -PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

MacroValueMeaning
PI_FILE_READ1open file for reading
PI_FILE_WRITE2open file for writing
PI_FILE_RW3open file for reading and writing


The following values may be or'd into the mode. -

MacroValueMeaning
PI_FILE_APPEND4Writes append data to the end of the file
PI_FILE_CREATE8The file is created if it doesn't exist
PI_FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ);

   if (handle >= 0)
   {
      while ((c=file_read(pi, handle, buf, sizeof(buf)-1)))
      {
         buf[c] = 0;
         printf("%s", buf);
      }

      file_close(pi, handle);
   }

   pigpio_stop(pi);
}

int file_close(int pi, unsigned handle)

-This function closes the file associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).


Returns 0 if OK, otherwise PI_BAD_HANDLE. -

Example

file_close(pi, handle);

int file_write(int pi, unsigned handle, char *buf, unsigned count)

-This function writes count bytes from buf to the the file -associated with handle. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: the array of bytes to write.
 count: the number of bytes to write.


Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, -PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. -

Example

if (file_write(pi, handle, buf, 100) == 0)
{
   // file written okay
}
else
{
   // error
}

int file_read(int pi, unsigned handle, char *buf, unsigned count)

-This function reads up to count bytes from the the file -associated with handle and writes them to buf. -

    pi: >=0 (as returned by pigpio_start).
handle: >=0 (as returned by file_open).
   buf: an array to receive the read data.
 count: the maximum number of bytes to read.


Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. -

Example

   bytes = file_read(pi, handle, buf, sizeof(buf));

   if (bytes >= 0)
   {
      // process read data
   }

int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)

-This function seeks to a position within the file associated -with handle. -

        pi: >=0 (as returned by pigpio_start).
    handle: >=0 (as returned by file_open).
seekOffset: the number of bytes to move.  Positive offsets
            move forward, negative offsets backwards.
  seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
            or PI_FROM_END (2).


Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. -

Example

file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123

size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size

pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position

int file_list(int pi, char *fpat, char *buf, unsigned count)

-This function returns a list of files which match a pattern. -

   pi: >=0 (as returned by pigpio_start).
 fpat: file pattern to match.
  buf: an array to receive the matching file names.
count: the maximum number of bytes to read.


Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, -or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The pattern -may contain wildcards. See file_open. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#include <stdio.h>
#include <pigpiod_if2.h>

int main(int argc, char *argv[])
{
   int pi, handle, c;
   char buf[60000];

   pi = pigpio_start(NULL, NULL);

   if (pi < 0) return 1;

   // assumes /opt/pigpio/access contains the following line
   // /ram/*.c r

   c = file_list(pi, "/ram/p*.c", buf, sizeof(buf));

   if (c >= 0)
   {
      buf[c] = 0;
      printf("%s", buf);
   }

   pigpio_stop(pi);
}

int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)

-This function initialises a new callback. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, and tick, whenever the -GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. -

The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use gpio_read. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

int callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)

-This function initialises a new callback. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
        f: the callback function.
 userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the GPIO, edge, tick, and the userdata -pointer, whenever the GPIO has the identified edge. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

edge        0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes

userdata    pointer  Pointer to an arbitrary object

int callback_cancel(unsigned callback_id)

-This function cancels a callback identified by its id. -

callback_id: >=0, as returned by a call to callback or callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout)

-This function waits for an edge on the GPIO for up to timeout -seconds. -

       pi: >=0 (as returned by pigpio_start).
user_gpio: 0-31.
     edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
  timeout: >=0.


The function returns when the edge occurs or after the timeout. -

Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a callback function. -

The function returns 1 if the edge occurred, otherwise 0. -

int bsc_xfer(int pi, bsc_xfer_t *bscxfer)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

     pi: >=0 (as returned by pigpio_start).
bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


To start a transfer set control (see below), copy the bytes to -be added to the transmit FIFO (if any) to txBuf and set txCnt to -the number of copied bytes. -

Upon return rxCnt will be set to the number of received bytes placed -in rxBuf. -

The returned function value is the status of the transfer (see below). -

If there was an error the status will be less than zero -(and will contain the error code). -

The most significant word of the returned status contains the number -of bytes actually copied from txBuf to the BSC transmit FIFO (may be -less than requested if the FIFO already contained untransmitted data). -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

control consists of the following bits. -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


The following example shows how to configure the BSC peripheral as -an I2C slave with address 0x13 and send four bytes. -

Example

bsc_xfer_t xfer;

xfer.control = (0x13<<16) | 0x305;

memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;

status = bsc_xfer(pi, &xfer);

if (status >= 0)
{
   // process transfer
}

int bsc_i2c(int pi, int i2c_addr, bsc_xfer_t *bscxfer)

-This function allows the Pi to act as a slave I2C device. -

This function is not available on the BCM2711 (e.g.as -used in the Pi4B). -

The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. -

      pi: >=0 (as returned by pigpio_start).
i2c_addr: 0-0x7F.
 bscxfer: a structure defining the transfer.

typedef struct
{
   uint32_t control;          // N/A
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;


txCnt is set to the number of bytes to be transmitted, possibly -zero. The data itself should be copied to txBuf. -

Any received data will be written to rxBuf with rxCnt set. -

See bsc_xfer for details of the returned status value. -

If there was an error the status will be less than zero -(and will contain the error code). -

Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. -

int event_callback(int pi, unsigned event, evtCBFunc_t f)

-This function initialises an event callback. -

   pi: >=0 (as returned by pigpio_start).
event: 0-31.
    f: the callback function.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the event id, and tick, whenever the -event occurs. -

int event_callback_ex(int pi, unsigned event, evtCBFuncEx_t f, void *userdata)

-This function initialises an event callback. -

      pi: >=0 (as returned by pigpio_start).
   event: 0-31.
       f: the callback function.
userdata: a pointer to arbitrary user data.


The function returns a callback id if OK, otherwise pigif_bad_malloc, -pigif_duplicate_callback, or pigif_bad_callback. -

The callback is called with the event id, the tick, and the userdata -pointer whenever the event occurs. -

int event_callback_cancel(unsigned callback_id)

-This function cancels an event callback identified by its id. -

callback_id: >=0, as returned by a call to event_callback or
event_callback_ex.


The function returns 0 if OK, otherwise pigif_callback_not_found. -

int wait_for_event(int pi, unsigned event, double timeout)

-This function waits for an event for up to timeout seconds. -

     pi: >=0 (as returned by pigpio_start).
  event: 0-31.
timeout: >=0.


The function returns when the event occurs or after the timeout. -

The function returns 1 if the event occurred, otherwise 0. -

int event_trigger(int pi, unsigned event)

-This function signals the occurrence of an event. -

   pi: >=0 (as returned by pigpio_start).
event: 0-31.


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an interest -in the event (e.g. by calling event_callback) will be informed by -a callback. -

One event, PI_EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

PARAMETERS

active: 0-1000000

-The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

*addrStr

-A string specifying the host or IP address of the Pi running -the pigpio daemon. It may be NULL in which case localhost -is used unless overridden by the PIGPIO_ADDR environment -variable. -

arg1

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2

-An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argc

-The count of bytes passed to a user customised function. -

*argx

-A pointer to an array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud

-The speed of serial communication (I2C, SPI, serial link, waves) in -bits per second. -

bit

-A value of 0 or 1. -

bits

-A value used to select GPIO. If bit n of bits is set then GPIO n is -selected. -

A convenient way to set bit n is to or in (1<<n). -

e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23). -

bsc_xfer_t

-typedef struct
{
   uint32_t control;          // Write
   int rxCnt;                 // Read only
   char rxBuf[BSC_FIFO_SIZE]; // Read only
   int txCnt;                 // Write
   char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;

*bscxfer

-A pointer to a bsc_xfer_t object used to control a BSC transfer. -

*buf

-A buffer to hold data being sent or being received. -

bufSize

-The size in bytes of a buffer. -

bVal: 0-255 (Hex 0x0-0xFF, Octal 0-0377)

-An 8-bit byte value. -

callback_id

-A value >=0, as returned by a call to a callback function, one of -

callback
-callback_ex
-event_callback
-event_callback_ex -

The id is passed to callback_cancel or event_callback_cancel -to cancel the callback. -

CBFunc_t

-typedef void (*CBFunc_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick);

CBFuncEx_t

-typedef void (*CBFuncEx_t)
   (int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata);

char

-A single character, an 8 bit quantity able to store 0-255. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

-The hardware clock frequency. -

count

-The number of bytes to be transferred in a file, I2C, SPI, or serial -command. -

CS

-The GPIO used for the slave select signal when bit banging SPI. -

data_bits: 1-32

-The number of data bits in each character of serial data. -

#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32

double

-A floating point number. -

dutycycle: 0-range

-A number representing the ratio of on time to off time for PWM. -

The number may vary between 0 and range (default 255) where -0 is off and range is fully on. -

edge

-Used to identify a GPIO level transition of interest. A rising edge is -a level change from 0 to 1. A falling edge is a level change from 1 to 0. -

RISING_EDGE  0
FALLING_EDGE 1
EITHER_EDGE. 2

errnum

-A negative number indicating a function call failed and the nature -of the error. -

event: 0-31

-An event is a signal used to inform one or more consumers -to start an action. -

evtCBFunc_t

-typedef void (*evtCBFunc_t)
   (int pi, unsigned event, uint32_t tick);

evtCBFuncEx_t

-typedef void (*evtCBFuncEx_t)
   (int pi, unsigned event, uint32_t tick, void *userdata);

f

-A function. -

*file

-A full file path. To be accessible the path must match an entry in -/opt/pigpio/access. -

*fpat

-A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: >=0

-The number of times a GPIO is swiched on and off per second. This -can be set per GPIO and may be as little as 5Hz or as much as -40KHz. The GPIO will be on for a proportion of the time as defined -by its dutycycle. -

gpio

-A Broadcom numbered GPIO, in the range 0-53. -

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 get_hardware_revision. -

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  -  -  -  -

gpioPulse_t

-typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

gpioThreadFunc_t

-typedef void *(gpioThreadFunc_t) (void *);

handle: >=0

-A number referencing an object opened by one of -

file_open
-i2c_open
-notify_open
-serial_open
-spi_open -

i2c_addr: 0-0x7F

-The address of a device on the I2C bus. -

i2c_bus: >=0

-An I2C bus number. -

i2c_flags: 0

-Flags which modify an I2C open command. None are currently defined. -

i2c_reg: 0-255

-A register of an I2C device. -

*inBuf

-A buffer used to pass data to a function. -

inLen

-The number of bytes of data in a buffer. -

int

-A whole number, negative or positive. -

int32_t

-A 32-bit signed value. -

invert

-A flag used to set normal or inverted bit bang serial data level logic. -

level

-The level of a GPIO. Low or High. -

PI_OFF 0
PI_ON 1

PI_CLEAR 0
PI_SET 1

PI_LOW 0
PI_HIGH 1


There is one exception. If a watchdog expires on a GPIO the level will be -reported as PI_TIMEOUT. See set_watchdog. -

PI_TIMEOUT 2

MISO

-The GPIO used for the MISO signal when bit banging SPI. -

mode

-1. The operational mode of a GPIO, normally INPUT or OUTPUT. -

PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2


2. The mode of waveform transmission. -

PI_WAVE_MODE_ONE_SHOT      0
PI_WAVE_MODE_REPEAT        1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC   3


3. A file open mode. -

PI_FILE_READ  1
PI_FILE_WRITE 2
PI_FILE_RW    3


The following values can be or'd into the mode. -

PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC  16

MOSI

-The GPIO used for the MOSI signal when bit banging SPI. -

numBytes

-The number of bytes used to store characters in a string. Depending -on the number of bits per character there may be 1, 2, or 4 bytes -per character. -

numPar: 0-10

-The number of parameters passed to a script. -

numPulses

-The number of pulses to be added to a waveform. -

offset

-The associated data starts this number of microseconds from the start of -the waveform. -

*outBuf

-A buffer used to return data from a function. -

outLen

-The size in bytes of an output buffer. -

pad: 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

padStrength: 1-16

-The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

*param

-An array of script parameters. -

percent: 0-100

-The size of waveform as percentage of maximum available. -

pi

-An integer defining a connected Pi. The value is returned by -pigpio_start upon success. -

*portStr

-A string specifying the port address used by the Pi running -the pigpio daemon. It may be NULL in which case "8888" -is used unless overridden by the PIGPIO_PORT environment -variable. -

*pth

-A thread identifier, returned by start_thread. -

pthread_t

-A thread identifier. -

pud: 0-2

-The setting of the pull up/down resistor for a GPIO, which may be off, -pull-up, or pull-down. -PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2

pulseLen

-1-100, the length of a trigger pulse in microseconds. -

*pulses

-An array of pulses to be added to a waveform. -

pulsewidth: 0, 500-2500

-PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500

PWMduty: 0-1000000 (1M)

-The hardware PWM dutycycle. -

#define PI_HW_PWM_RANGE 1000000

PWMfreq: 1-125M (1-187.5M for the BCM2711)

-The hardware PWM frequency. -

#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000
#define PI_HW_PWM_MAX_FREQ_2711 187500000

range: 25-40000

-The permissible dutycycle values are 0-range. -

PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000

*retBuf

-A buffer to hold a number of bytes returned to a used customised function, -

retMax

-The maximum number of bytes a user customised function should return. -

*rxBuf

-A pointer to a buffer to receive data. -

SCL

-The user GPIO to use for the clock when bit banging I2C. -

SCLK

-The GPIO used for the SCLK signal when bit banging SPI. -

*script

-A pointer to the text of a script. -

script_id

-An id of a stored script as returned by store_script. -

*scriptName

-The name of a shell_ script to be executed. The script must be present in -/opt/pigpio/cgi and must have execute permission. -

*scriptString

-The string to be passed to a shell_ script to be executed. -

SDA

-The user GPIO to use for data when bit banging I2C. -

seconds

-The number of seconds. -

seekFrom

-PI_FROM_START   0
PI_FROM_CURRENT 1
PI_FROM_END     2

seekOffset

-The number of bytes to move forward (positive) or backwards (negative) -from the seek position (start, current, or end of file). -

ser_flags

-Flags which modify a serial open command. None are currently defined. -

*ser_tty

-The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1. -

size_t

-A standard type used to indicate the size of an object in bytes. -

spi_channel

-A SPI channel, 0-2. -

spi_flags

-See spi_open and bb_spi_open. -

steady: 0-300000

-The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) or triggering -the active part of a noise filter (set_noise_filter). -

stop_bits: 2-8

-The number of (half) stop bits to be used when adding serial data -to a waveform. -

#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8

*str

- An array of characters. -

thread_func

-A function of type gpioThreadFunc_t used as the main function of a -thread. -

timeout

-A GPIO watchdog timeout in milliseconds. -

PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000

*txBuf

-An array of bytes to transmit. -

uint32_t: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)

-A 32-bit unsigned value. -

unsigned

-A whole number >= 0. -

user_gpio

-0-31, a Broadcom numbered GPIO. -

See gpio. -

*userdata

-A pointer to arbitrary user data. This may be used to identify the instance. -

You must ensure that the pointer is in scope at the time it is processed. If -it is a pointer to a global this is automatic. Do not pass the address of a -local variable. If you want to pass a transient object then use the -following technique. -

In the calling function: -

user_type *userdata;

user_type my_userdata;

userdata = malloc(sizeof(user_type));

*userdata = my_userdata;


In the receiving function: -

user_type my_userdata = *(user_type*)userdata;

free(userdata);

void

-Denoting no parameter is required -

wave_add_*

-One of -

wave_add_new
-wave_add_generic
-wave_add_serial -

wave_id

-A number representing a waveform created by wave_create. -

wave_send_*

-One of -

wave_send_once
-wave_send_repeat -

wVal: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)

-A 16-bit word value. -

pigpiod_if2 Error Codes


typedef enum
{
   pigif_bad_send           = -2000,
   pigif_bad_recv           = -2001,
   pigif_bad_getaddrinfo    = -2002,
   pigif_bad_connect        = -2003,
   pigif_bad_socket         = -2004,
   pigif_bad_noib           = -2005,
   pigif_duplicate_callback = -2006,
   pigif_bad_malloc         = -2007,
   pigif_bad_callback       = -2008,
   pigif_notify_failed      = -2009,
   pigif_callback_not_found = -2010,
   pigif_unconnected_pi     = -2011,
   pigif_too_many_pis       = -2012,
} pigifError_t;

\ No newline at end of file diff --git a/DOC/tmp/body/pif.body b/DOC/tmp/body/pif.body deleted file mode 100644 index d72d3f8..0000000 --- a/DOC/tmp/body/pif.body +++ /dev/null @@ -1,21 +0,0 @@ - -pigpio provides a pipe interface to many of its functions.
-
-The pipe interface is available whenever pigpio is running, either -because it has been started as a daemon, or it has been linked in -to a running user program.  The pipe interface can be disabled -by the program which initialises the library.  pigpiod offers -the -f option to disable the pipe interface.  User programs -should call gpioCfgInterfaces -if they wish to disable the pipe interface.
-
-pigpio listens for commands on pipe /dev/pigpio.  The commands -consist of a command identifier with, depending on the command, -zero, one, or two parameters.  The result, if any, may be read -from pipe /dev/pigout.  If any errors are detected a message -will be written to pipe /dev/pigerr.
-
-
-The format of the commands is identical to those used by pigs. diff --git a/DOC/tmp/body/pig2vcd.body b/DOC/tmp/body/pig2vcd.body deleted file mode 100644 index a6a7719..0000000 --- a/DOC/tmp/body/pig2vcd.body +++ /dev/null @@ -1,20 +0,0 @@ -pig2vcd is a utility which reads notifications on stdin and writes the -output as a Value Change Dump (VCD) file on stdout. -

The VCD file can be viewed using GTKWave. -

Notifications

Notifications consist of 12 bytes with the following binary format. -

typedef struct
{
   uint16_t seqno;
   uint16_t flags;
   uint32_t tick;
   uint32_t level;
} gpioReport_t;


seqno: starts at 0 each time the handle is opened and then increments by one for each report. -

flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. -

tick: the number of microseconds since system boot. It wraps around after 1h12m. -

level: indicates the level of each gpio. If bit 1<<x is set then gpio x is high. pig2vcd takes these notifications and outputs a text format VCD. -

VCD format

The VCD starts with a header. -

$date 2013-05-31 18:49:36 $end
$version pig2vcd V1 $end
$timescale 1 us $end
$scope module top $end
$var wire 1 A 0 $end
$var wire 1 B 1 $end
$var wire 1 C 2 $end
$var wire 1 D 3 $end
$var wire 1 E 4 $end
$var wire 1 F 5 $end
$var wire 1 G 6 $end
$var wire 1 H 7 $end
$var wire 1 I 8 $end
$var wire 1 J 9 $end
$var wire 1 K 10 $end
$var wire 1 L 11 $end
$var wire 1 M 12 $end
$var wire 1 N 13 $end
$var wire 1 O 14 $end
$var wire 1 P 15 $end
$var wire 1 Q 16 $end
$var wire 1 R 17 $end
$var wire 1 S 18 $end
$var wire 1 T 19 $end
$var wire 1 U 20 $end
$var wire 1 V 21 $end
$var wire 1 W 22 $end
$var wire 1 X 23 $end
$var wire 1 Y 24 $end
$var wire 1 Z 25 $end
$var wire 1 a 26 $end
$var wire 1 b 27 $end
$var wire 1 c 28 $end
$var wire 1 d 29 $end
$var wire 1 e 30 $end
$var wire 1 f 31 $end
$upscope $end
$enddefinitions $end


The header defines gpio identifiers and their name. Each gpio identifier -must be unique. pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0 -through 25, and 'a' through 'f' for gpios 26 through 31. -The corresponding names are 0 through 31.
-

The VCD file may be edited to give a frendlier name, e.g. 8 could be -changed to ENCODER_A if an encoder switch A is connected to gpio 8. -

Following the header pig2vcd takes notifications and outputs a timestamp -followed by a list of one or more gpios which have changed state. -The timestamp consists of a '#' followed by the microsecond tick. -The state lines contain the new state followed by the gpio identifier. -

#1058747
0H
0I
#1059012
1H
#1079777
1I
#1079782
0I
#1079852
1I
#1079857
0I
0H
#1165113
1H
#1165118
0H
#1165153
1H
\ No newline at end of file diff --git a/DOC/tmp/body/pigpiod.body b/DOC/tmp/body/pigpiod.body deleted file mode 100644 index 1aed926..0000000 --- a/DOC/tmp/body/pigpiod.body +++ /dev/null @@ -1,51 +0,0 @@ -pigpiod is a utility which launches the pigpio library as a daemon.
-
-Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.
-
-The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.
-
-pigpiod accepts the following configuration options
-
-
-a valueDMA memory allocation mode0=AUTO, 1=PMAP, 2=MBOXDefault AUTO -
-b valueGPIO sample buffer size in milliseconds100-10000Default 120 -
-c valueLibrary internal settingsDefault 0 -
-d valuePrimary DMA channel0-14Default 14 -
-e valueSecondary DMA channel0-14Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel -
-fDisable fifo interfaceDefault enabled -
-gRun in foreground (do not fork)Default disabled -
-kDisable local and remote socket interfaceDefault enabled -
-lDisable remote socket interfaceDefault enabled -
-mDisable alerts (sampling)Default enabled -
-n IP addressAllow IP address to use the socket interfaceName (e.g. paul) or dotted quad (e.g. 192.168.1.66)If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect -
-p valueSocket port1024-32000Default 8888 -
-s valueSample rate1, 2, 4, 5, 8, or 10 microsecondsDefault 5 -
-t valueClock peripheral0=PWM 1=PCMDefault PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio. -
-v -VDisplay pigpio version and exit -
-x maskGPIO which may be updatedA 54 bit mask with (1<<n) set if the user may update GPIO #nDefault is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO -

Example

sudo pigpiod -s 2 -b 200 -f


Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer. Disable the fifo interface. -

Permissions

pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces. -

All GPIO may be read. -

Only the user GPIO for the board type or those specified by the -x option may be updated. -

Type 1 boards 0x03E6CF93 (26 pin header)
Type 2 boards 0xFBC6CF9C (26 pin + 8 pin header)
Type 3 boards 0x0FFFFFFC (40 pin header)


In this context an update includes the following: -

GPIO mode set
-GPIO pull/up down
-GPIO write
-GPIO set PWM (including range and frequency)
-GPIO set servo -

In addition the bank clear and set commands, and the wave commands will only -affect updateable GPIO. -

Exceptions

The following exceptions are made for particular models. -

Models A and B

The green activity LED (GPIO 16) may be written.
-
Models A+ and B+

The green activity LED (GPIO 47) may be written.
-The red power LED (GPIO 35) may be written.
-The high USB power mode (GPIO 38) may be written.
-
Pi Zero

The green activity LED (GPIO 47) may be written.
-
Pi2B

The green activity LED (GPIO 47) may be written.
-The red power LED (GPIO 35) may be written.
-The high USB power mode (GPIO 38) may be written.
-
Pi3B

The green activity LED and the red power LED are not writable.
-The USB power mode is fixed at 1.2 amps (high power).
-

DMA Channels

The secondary channel is only used for the transmission of waves. -

If possible use one of channels 0 to 6 for the secondary channel (a full channel). -

A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel. -

\ No newline at end of file diff --git a/DOC/tmp/body/pigs.body b/DOC/tmp/body/pigs.body deleted file mode 100644 index 4a88b42..0000000 --- a/DOC/tmp/body/pigs.body +++ /dev/null @@ -1,1205 +0,0 @@ -

Introduction

-The socket and pipe interfaces allow control of the Pi's GPIO by -passing messages to the running pigpio library. -

The normal way to start the pigpio library would be as a daemon during boot. -

sudo pigpiod

Features

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o reading/writing all of the GPIO in a bank as one operation -

o individually setting GPIO modes, reading and writing -

o notifications when any of GPIO 0-31 change state -

o the construction of output waveforms with microsecond timing -

o I2C, SPI, and serial link wrappers -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

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. -

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 $?). -

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). -

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. -

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. -

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 mSet GPIO mode gpioSetMode
MG/MODEG gGet GPIO mode gpioGetMode
PUD g pSet GPIO pull up/down gpioSetPullUpDown
R/READ gRead GPIO level gpioRead
W/WRITE g LWrite GPIO level gpioWrite
PWM (overrides servo commands on same GPIO) -
P/PWM u vSet GPIO PWM value gpioPWM
PFS u vSet GPIO PWM frequency gpioSetPWMfrequency
PRS u vSet GPIO PWM range gpioSetPWMrange
GDC uGet GPIO PWM dutycycle gpioGetPWMdutycycle
PFG uGet GPIO PWM frequency gpioGetPWMfrequency
PRG uGet GPIO PWM range gpioGetPWMrange
PRRG uGet GPIO PWM real range gpioGetPWMrealRange
Servo (overrides PWM commands on same GPIO) -
S/SERVO u vSet GPIO servo pulsewidth gpioServo
GPW uGet GPIO servo pulsewidth gpioGetServoPulsewidth
INTERMEDIATE -
TRIG u pl LSend a trigger pulse gpioTrigger
WDOG u vSet GPIO watchdog gpioSetWatchdog
BR1Read bank 1 GPIO gpioRead_Bits_0_31
BR2Read bank 2 GPIO gpioRead_Bits_32_53
BC1 bitsClear specified GPIO in bank 1 gpioWrite_Bits_0_31_Clear
BC2 bitsClear specified GPIO in bank 2 gpioWrite_Bits_32_53_Clear
BS1 bitsSet specified GPIO in bank 1 gpioWrite_Bits_0_31_Set
BS2 bitsSet specified GPIO in bank 2 gpioWrite_Bits_32_53_Set
ADVANCED -
NORequest a notification gpioNotifyOpen
NC hClose notification gpioNotifyClose
NB h bitsStart notification gpioNotifyBegin
NP hPause notification gpioNotifyPause
HC g cfSet hardware clock frequency gpioHardwareClock
HP g pf pdcSet hardware PWM frequency and dutycycle gpioHardwarePWM
FG u stdySet a glitch filter on a GPIO gpioGlitchFilter
FN u stdy actvSet a noise filter on a GPIO gpioNoiseFilter
PADS pad padmaSet pad drive strength gpioSetPad
PADG padGet pad drive strength gpioGetPad
SHELL name strExecute a shell command shell
Custom -
CF1 uvsCustom function 1 gpioCustom1
CF2 uvsCustom function 2 gpioCustom1
Events -
EVM h bitsSet events to monitor eventMonitor
EVT eventTrigger event eventTrigger
Scripts -
PROC tStore script gpioStoreScript
PROCR sid parsRun script gpioRunScript
PROCU sid parsSet script parameters gpioUpdateScript
PROCP sidGet script status and parameters gpioScriptStatus
PROCS sidStop script gpioStopScript
PROCD sidDelete script gpioDeleteScript
PARSE tValidate script gpioParseScript
I2C -
I2CO ib id ifOpen I2C bus and device with flags i2cOpen
I2CC hClose I2C handle i2cClose
I2CWQ h bitsmb Write Quick: write bit i2cWriteQuick
I2CRS hsmb Read Byte: read byte i2cReadByte
I2CWS h bvsmb Write Byte: write byte i2cWriteByte
I2CRB h rsmb Read Byte Data: read byte from register i2cReadByteData
I2CWB h r bvsmb Write Byte Data: write byte to register i2cWriteByteData
I2CRW h rsmb Read Word Data: read word from register i2cReadWordData
I2CWW h r wvsmb Write Word Data: write word to register i2cWriteWordData
I2CRK h rsmb Read Block Data: read data from register i2cReadBlockData
I2CWK h r bvssmb Write Block Data: write data to register i2cWriteBlockData
I2CWI h r bvssmb Write I2C Block Data i2cWriteI2CBlockData
I2CRI h r numsmb Read I2C Block Data: read bytes from register i2cReadI2CBlockData
I2CRD h numi2c Read device i2cReadDevice
I2CWD h bvsi2c Write device i2cWriteDevice
I2CPC h r wvsmb Process Call: exchange register with word i2cProcessCall
I2CPK h r bvssmb Block Process Call: exchange data bytes with register i2cBlockProcessCall
I2CZ h bvsPerforms multiple I2C transactions i2cZip
I2C BIT BANG -
BI2CO sda scl bOpen bit bang I2C bbI2COpen
BI2CC sdaClose bit bang I2C bbI2CClose
BI2CZ sda bvsI2C bit bang multiple transactions bbI2CZip
I2C/SPI SLAVE -
BSCX bctl bvsBSC I2C/SPI transfer bscXfer
SERIAL -
SERO dev b sefOpen serial device dev at baud b with flags serOpen
SERC hClose serial handle serClose
SERRBRead byte from serial handle serReadByte
SERWB h bvWrite byte to serial handle serWriteByte
SERR h numRead bytes from serial handle serRead
SERW h bvsWrite bytes to serial handle serWrite
SERDA hCheck for serial data ready to read serDataAvailable
SERIAL BIT BANG (read only) -
SLRO u b dbOpen GPIO for bit bang serial data gpioSerialReadOpen
SLRC uClose GPIO for bit bang serial data gpioSerialReadClose
SLRI u vSets bit bang serial data logic levels gpioSerialReadInvert
SLR u numRead bit bang serial data from GPIO gpioSerialRead
SPI -
SPIO c b spfSPI open channel at baud b with flags spiOpen
SPIC hSPI close handle spiClose
SPIR h numSPI read bytes from handle spiRead
SPIW h bvsSPI write bytes to handle spiWrite
SPIX h bvsSPI transfer bytes to handle spiXfer
SPI BIT BANG -
BSPIO cs miso mosi sclk b spfOpen bit bang SPI bbSPIOpen
BSPIC csClose bit bang SPI bbSPIClose
BSPIX cs bvsSPI bit bang transfer bbSPIXfer
FILES -
FO file modeOpen a file in mode fileOpen
FC hClose file handle fileClose
FR h numRead bytes from file handle fileRead
FW h bvsWrite bytes to file handle fileWrite
FS h num fromSeek to file handle position fileSeek
FL pat numList files which match pattern fileList
WAVES -
WVCLRClear all waveforms gpioWaveClear
WVNEWInitialise a new waveform gpioWaveAddNew
WVAG tripsAdd generic pulses to waveform gpioWaveAddGeneric
WVAS u b db sb o bvsAdd serial data to waveform gpioWaveAddSerial
WVCRECreate a waveform gpioWaveCreate
WVCAPCreate a waveform of fixed size gpioWaveCreatePad
WVDEL widDelete selected waveform gpioWaveDelete
WVTX widTransmits waveform once gpioWaveTxSend
WVTXM wid wmdeTransmits waveform using mode gpioWaveTxSend
WVTXR widTransmits waveform repeatedly gpioWaveTxSend
WVCHA bvsTransmits a chain of waveforms gpioWaveChain
WVTATReturns the current transmitting waveform gpioWaveTxAt
WVBSYCheck if waveform is being transmitted gpioWaveTxBusy
WVHLTStop waveform gpioWaveTxStop
WVSC wsGet waveform DMA CB stats gpioWaveGetCbs
WVSM wsGet waveform time stats gpioWaveGetMicros
WVSP wsGet waveform pulse stats gpioWaveGetPulses
UTILITIES -
H/HELPDisplay command help
HWVERGet hardware version gpioHardwareRevision
MICS vMicroseconds delay gpioDelay
MILS vMilliseconds delay gpioDelay
PIGPVGet pigpio library version gpioVersion
T/TICKGet current tick gpioTick
CONFIGURATION -
CGIConfiguration get internals gpioCfgGetInternals
CSI vConfiguration set internals gpioCfgSetInternals

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. -

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. -

o baud rates as low as 50
-o repeated starts
-o clock stretching
-o 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. -

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: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

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 read GPIO 0-31 (bank 1) and returns the levels as a -32-bit hexadecimal value. -

Example

$ pigs br1
1001C1CF

BR2 - - Read bank 2 GPIO

This command read 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 (sets high) 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 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

This command sets (sets high) 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 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

This command performs a BSC I2C/SPI slave transfer as defined by -bctl with data bvs. -

This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

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, followed by any data bytes -read from the BSC receive FIFO. -

Note that the control word sets the BSC mode. The BSC will stay in -that mode until a different control word is sent. -

For I2C use a control word of (I2C address << 16) + 0x305. -

E.g. to talk as I2C slave with address 0x13 use 0x130305. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

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. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable 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. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit 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 -opened with BSPIO. -

The set of GPIO is specifed by cs. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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 command starts bit banging SPI on a group of GPIO with slave -select cs, MISO miso, MOSI mosi, and clock sclk. -

Data will be transferred at baud b bits per second (which may -be set in the range 50-250000). -

The flags spf may be used to modify the default behaviour of -mode 0, active low chip select. -

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
 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 (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. -

Upon success 0 is returned. On error a negative status code -will be returned. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

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. It returns the same -number of bytes read from the device. -

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 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

This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. -

CF2 - uvs - Custom function 2

This command calls a user customised function. The meaning of -any paramaters and the returned value is defined by the -customiser. -

CGI - - Configuration get internals

This command returns the value of the internal library -configuration settings. -

CSI - v - Configuration set internals

This command sets the value of the internal library -configuration settings to v. -

EVM - h bits - Set events to monitor

This command starts event reporting 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 reports for each 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

This command triggers event event. -

One event, number 31, is predefined. This event is -auto generated on BSC slave activity. -

Example

$ pigs evt 12
$ pigs evt 5

$ pigs evt 32
-143
ERROR: bad event id

FC - h - Close file handle

This command closes a file handle h previously opened with FO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs fc 0 # First close okay.

$ pigs fc 0 # Second fails.
-25
ERROR: unknown handle

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. The -level is then reported. Level changes of less than stdy -microseconds are ignored. -

The filter only affects callbacks (including pipe notifications). -

The R/READ, BR1, and BR2 commands are not affected. -

Note, each (stable) edge will be timestamped stdy microseconds -after it was first detected. -

Example

$ pigs fg 4 250

$ pigs fg 4 1000000
-125
ERROR: bad filter parameter

FL - pat num - List files which match pattern

This command returns a list of the files matching pat. Up -to num bytes may be returned. -

Upon success the count of returned bytes followed by the matching -files is returned. On error a negative status code will be returned. -

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 are ignored until a level which has -been stable for stdy microseconds is detected. Level -changes on the GPIO are then reported for actv microseconds -after which the process repeats. -

The filter only affects callbacks (including pipe notifications). -

The R/READ, BR1, and BR2 commands are not affected. -

Note, level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

Example

$ pigs fn 7 250 1000

$ pigs fn 7 2500000 1000
-125
ERROR: bad filter parameter

FO - file mode - Open a file in mode

This function 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 -will be returned. -

File -

A file may only be opened if permission is granted by an entry in -/opt/pigpio/access. This is intended to allow remote access to files -in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files may -be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access. -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values. -

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


The following values may be or'd into the mode. -

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The file is truncated


Newly created files are owned by root with permissions owner read and write. -

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

This command 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 will be returned. -

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

This command 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 backwards. The move start -position is determined by from as follows. -

From
0start
1current position
2end


Upon success the new byte position within the file (>=0) is -returned. On error a negative status code will be returned. -

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

This command writes bytes bvs to the file -associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs fw 0 23 45 67 89

GDC - u - Get GPIO PWM dutycycle

This command returns the PWM dutycycle in use on GPIO u. -

Upon success the dutycycle is returned. On error a negative -status code will be returned. -

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

This command returns the servo pulsewidth in use on GPIO u. -

Upon success the servo pulsewidth is returned. On error a negative -status code will be returned. -

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

This command displays a brief list of the commands and their parameters. -

Example

$ pigs h

$ pigs help

HC - g cf - Set hardware clock frequency

This command sets the hardware clock associated with GPIO g to -frequency cf. Frequencies above 30MHz are unlikely to work. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

The GPIO must be one of the following. -

4clock 0All models
5clock 1All models but A and B (reserved for system use)
6clock 2All models but A and B
20clock 0All models but A and B
21clock 1All models but A and B Rev.2 (reserved for system use)


32clock 0Compute module only
34clock 0Compute module only
42clock 1Compute module only (reserved for system use)
43clock 2Compute module only
44clock 1Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. -

HP - g pf pdc - Set hardware PWM frequency and dutycycle

This command sets the hardware PWM associated with GPIO g to -frequency pf with dutycycle pdc. Frequencies above 30MHz -are unlikely to work. -

NOTE: Any waveform started by WVTX, WVTXR, or WVCHA -will be cancelled. -

This function is only valid if the pigpio main clock is PCM. The -main clock defaults to PCM but may be overridden when the pigpio -daemon is started (option -t). -

Upon success nothing is returned. On error a negative status code -will be returned. -

$ 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


The same PWM channel is available on multiple GPIO. The latest -frequency and dutycycle setting will be used by all GPIO which -share a PWM channel. -

The GPIO must be one of the following. -

12PWM channel 0All models but A and B
13PWM channel 1All models but A and B
18PWM channel 0All models
19PWM channel 1All models but A and B


40PWM channel 0Compute module only
41PWM channel 1Compute module only
45PWM channel 1Compute module only
52PWM channel 0Compute module only
53PWM channel 1Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/pf (375M/pf for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps for the BCM2711). -

There will only be a million steps for a pf of 250 (375 for -the BCM2711). Lower frequencies will have more steps and higher -frequencies will have fewer steps. pdc is -automatically scaled to take this into account. -

HWVER - - Get hardware version

This command returns the hardware revision of the Pi. -

The hardware revision is found in the last 4 characters on the revision -line of /proc/cpuinfo. -

If the hardware revision can not be found or is not a valid hexadecimal -number the command returns 0. -

The revision number can be used to determine the assignment of GPIO -to pins (see g). -

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

This command closes an I2C handle h previously opened with I2CO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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 command returns a handle to access device id on I2C bus ib. -The device is opened with flags if. -

Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


No flags are currently defined. The parameter if should be 0. -

Upon success the next free handle (>=0) is returned. On error a -negative status code will be returned. -

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

This command writes wv to register r of the I2C device -associated with handle h and returns a 16-bit word read from the -device. -

Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. -

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

This command writes the data bytes bvs to register r of the I2C device -associated with handle h and returns a device specific number of 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 i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0

I2CRB - h r - smb Read Byte Data: read byte from register

This command returns a single byte read from register r of the I2C device -associated with handle h. -

Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crb 0 0
6

I2CRD - h num - i2c Read device

This command returns num bytes read from the I2C 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. -

This command operates on the raw I2C device. The maximum value of the -parameter num is dependent on the I2C drivers and the device -itself. pigs imposes a limit of 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

This command returns num bytes from register r of the I2C 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. -

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

This command returns between 1 and 32 bytes read from register r of -the I2C 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. -

The number of bytes of returned data is specific to the device and -register. -

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

This command returns a single byte read from the I2C device -associated with handle h. -

Upon success a value between 0 and 255 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crs 0
0

I2CRW - h r - smb Read Word Data: read word from register

This command returns a single 16 bit word read from register r of -the I2C device associated with handle h. -

Upon success a value between 0 and 65535 will be returned. On error -a negative status code will be returned. -

Example

$ pigs i2crw 0 0
6150

I2CWB - h r bv - smb Write Byte Data: write byte to register

This command writes a single byte bv to register r of the -I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwb 0 10 0x54

I2CWD - h bvs - i2c Write device

This command writes a block of bytes bvs to the I2C device -associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

The number of bytes which may be written in one transaction is -dependent on the I2C drivers and the device itself. pigs imposes -a limit of about 500 bytes. -

This command operates on the raw I2C device. -

Example

$ pigs i2cwd 0 0x01 0x02 0x03 0x04

I2CWI - h r bvs - smb Write I2C Block Data

This command writes between 1 and 32 bytes bvs to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwi 0 4 0x01 0x04 0xc0

I2CWK - h r bvs - smb Write Block Data: write data to register

This command writes between 1 and 32 bytes bvs to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

pigs i2cwk 0 4 0x01 0x04 0xc0

I2CWQ - h bit - smb Write Quick: write bit

This command writes a single bit to the I2C device associated -with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cwq 0 1

I2CWS - h bv - smb Write Byte: write byte

This command writes a single byte bv to the I2C device associated -with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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

This command writes a single 16 bit word wv to register r of -the I2C device associated with handle h. -

Upon success nothing is returned. On error a negative status code -will be returned. -

Example

$ pigs i2cww 0 0 0xffff

I2CZ - h bvs - Performs multiple I2C transactions

This command executes a sequence of 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: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle h. -The flags default to 0. The address and flags maintain their -previous value until updated. -

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/MODES - g m - Set GPIO mode

This command sets GPIO g to mode m, typically input (read) -or output (write). -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345


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. -

Value01234567
ModeInputOutputALT5ALT4ALT0ALT1ALT2ALT3


Example

$ pigs mg 4
1

MICS - v - Microseconds delay

This command delays execution for v microseconds. -

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. -

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. -

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. -

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. -

PadGPIO
00-27
128-45
246-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. -

PadGPIO
00-27
128-45
246-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. -

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. -

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

       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


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). -

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. -

Upon success the script status and parameters are returned. -On error a negative status code will be returned. -

The script status may be one of -

0being initialised
1halted
2running
3waiting
4failed


See Scripts. -

Example

$ pigs procp 0
1 0 0 0 0 0 0 0 0 0 0

PROCR - sid pars - Run script

This command runs stored script sid passing it up to 10 optional -parameters. -

Upon success nothing is returned. 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 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

This command stops a running script sid. -

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

This command sets the parameters of a stored script sid passing -it up to 10 parameters. -

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 used by GPIO u. -

If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

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 command sets the dutycycle range v to be used for GPIO u. -Subsequent uses of command P/PWM will use a dutycycle between 0 (off) -and v (fully on). -

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 will be scaled to -reflect the new range. -

The real range, the number of steps between fully off and fully on -for each frequency, is given in the following table. -

#1#2#3#4#5#6#7#8#9
2550100125200250400500625
#10#11#12#13#14#15#16#17#18
8001000125020002500400050001000020000


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

This command 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 may 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

This 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

This command 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 may be 0 (off), 500 (most anti-clockwise) -to 2500 (most clockwise). -

The range supported by servos varies and should probably be determined -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. -

You can DAMAGE a servo if you command it to move beyond its limits. -

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

This command closes a serial handle h 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

This command 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). 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

This command 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. -

Example

$ pigs sero /dev/ttyAMA0 9600 0
0

$ pigs sero /dev/tty1 38400 0
1

SERR - h num - Read bytes from serial handle

This command 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

This command 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

This command 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

This command 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 command 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. -

The returned exit status is normally 256 times that set -by the shell script exit function. If the script can't -be found 32512 will be returned. -

The following table gives some example returned statuses. -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


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 "\"hello string with spaces world\""
256

# non-existent script
$ pigs shell scr78 par1
32512

SLR - u num - Read bit bang serial data from GPIO

This command 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. -

The GPIO u should have been initialised with the SLRO command. -

The bytes returned for each character depend upon the number of -data bits db 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

This command 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

This command 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

This command 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 may be between 50 and 250000 bits per second. -

The received data is held in a cyclic buffer. -

It is the user's responsibility to read the data (with SLR) -in a timely fashion. -

Example

$ pigs slro 23 19200 8

$ pigs slro 23 19200 8
-50
ERROR: GPIO already in use

SPIC - h - SPI close handle

This command closes the SPI handle h returned by a prior -call to SPIO. -

Upon success nothing is returned. On error a negative status code -will be returned. -

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. -

Data will be transferred at b bits per second. The flags spf -may be used to modify the default behaviour of 4-wire operation, -mode 0, active low chip select. -

Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps -are unlikely to work. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


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. -

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. -

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. -

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. -

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. -

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

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. -

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. -

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. -

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. -

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. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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 \
   ${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

WVCLR - - Clear all waveforms

This command clears all waveforms. -

Nothing is returned. -

Example

$ pigs wvclr

WVCRE - - Create a waveform

This command creates a waveform from the data provided by the prior -calls to the WVAG and WVAS commands. -

Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. -

The data provided by the WVAG and WVAS commands is -consumed by this command. -

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 -

Step 1. WVCLR to clear all waveforms and added data. -

Step 2. WVAG/WVAS calls to supply the waveform data. -

Step 3. WVCRE to create the waveform and get a unique id. -

Repeat steps 2 and 3 as needed. -

Step 4. WVTX or WVTXR with the id of the waveform to transmit. -

A waveform comprises of one or more pulses. -

A pulse specifies -

1) the GPIO to be switched on at the start of the pulse.
-2) the GPIO to be switched off at the start of the pulse.
-3) the delay in microseconds before the next pulse. -

Any or all the fields can be zero. It doesn't make any sense to -set all the fields to zero (the pulse will be ignored). -

When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. -

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

WVCAP - - 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 total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. -

Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. -

The data provided by the WVAG and WVAS commands are -consumed by this command. -

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 -

Step 1. WVCLR to clear all waveforms and added data. -

Step 2. WVAG/WVAS calls to supply the waveform data. -

Step 3. WVCAP to create a waveform of a uniform size. -

Step 4. WVTX or WVTXR with the id of the waveform to transmit. -

Repeat steps 2 - 4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

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

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

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. -

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

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. -

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), or 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. -

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. -

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

-

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. -

From
0start
1current position
2end

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. -

0123456789101112131415
Type 1XX--X--XXXXX--XX
Type 2--XXX--XXXXX--XX
Type 3XXXXXXXXXXXXXX
16171819202122232425262728293031
Type 1-XX--XXXXX------
Type 2-XX---XXXX-XXXXX
Type 3XXXXXXXXXXXX----


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. -

ModeInputOutputALT0ALT1ALT2ALT3ALT4ALT5
CodeRW012345
Value01456732

miso - GPIO (0-31)

-The GPIO used for the MISO signal when bit banging SPI. -

mode - file open mode

-One of the following values. -

ValueMeaning
READ1open file for reading
WRITE2open file for writing
RW3open file for reading and writing


The following values can be or'd into the mode. -

ValueMeaning
APPEND4All writes append data to the end of the file
CREATE8The file is created if it doesn't exist
TRUNC16The 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 DownOffPull DownPull Up
Command CharacterODU


There is no mechanism to read the pull up down state. -

pad - 0-2

-A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-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. -

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 onGPIO offdelay
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

-Scripts are programs to be stored and executed by the pigpio daemon. -They are intended to mitigate any performance problems associated with -the pigpio daemon server/client model. -

Example

A trivial example might be useful. Suppose you want to toggle a GPIO -on and off as fast as possible. -

From the command line you could write -

for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done


Timing that you will see it takes about 14 seconds, or roughly -70 toggles per second. -

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. -

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. -

Let's time the script running. -

Again, ignore the details for now. -

time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
 do sleep 0.2; done)


The script takes roughly 12 seconds to complete, or 800,000 toggles per second. -

That is the advantage of a stored script. -

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 ]];\
 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. -

Virtual machine

A script runs within a virtual machine with -

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. -

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: -

CommandDescriptionDefinition
ADD xAdd x to accumulatorA+=x; F=A
AND xAnd x with accumulatorA&=x; F=A
CALL LCall subroutine at tag Lpush(PC+1); PC=L
CMP xCompare x with accumulatorF=A-x
DCR yDecrement register--*y; F=*y
DCRADecrement accumulator--A; F=A
DIV xDivide x into accumulatorA/=x; F=A
EVTWTWait for an event to occurA=wait(x); F=A
HALTHaltHalt
INR yIncrement register++*y; F=*y
INRAIncrement accumulator++A; F=A
JM LJump if minus to tag Lif (F<0) PC=L
JMP LJump to tag LPC=L
JNZ LJump if non-zero to tag Lif (F) PC=L
JP LJump if positive to tag Lif (F>=0) PC=L
JZ LJump if zero to tag Lif (!F) PC=L
LD y xLoad register with x*y=x
LDA xLoad accumulator with xA=x
MLT xMultiply x with accumulatorA*=x; F=A
MOD xModulus x with accumulatorA%=x; F=A
OR xOr x with accumulatorA|=x; F=A
POP yPop registery=pop()
POPAPop accumulatorA=pop()
PUSH yPush registerpush(y)
PUSHAPush accumulatorpush(A)
RETReturn from subroutinePC=pop()
RL y xRotate left register x bits*y<<=x; F=*y
RLA xRotate left accumulator x bitsA<<=x; F=A
RR y xRotate right register x bits*y>>=x; F=*y
RRA xRotate right accumulator x bitsA>>=x; F=A
STA yStore accumulator in registery=A
SUB xSubtract x from accumulatorA-=x; F=A
SYS strRun external script (/opt/pigpio/cgi/str)system(str); F=A
TAG LLabel the current script positionN/A
WAIT xWait for a GPIO in x to change stateA=wait(x); F=A
X y1 y2Exchange contents of registers y1 and y2t=*y1;*y1=*y2;*y2=t
XA yExchange contents of accumulator and registert=A;A=*y;*y=t
XOR xXor x with accumulatorA^=x; F=A


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. -

\ No newline at end of file diff --git a/DOC/tmp/body/piscope.body b/DOC/tmp/body/piscope.body deleted file mode 100644 index dd0c7ce..0000000 --- a/DOC/tmp/body/piscope.body +++ /dev/null @@ -1,205 +0,0 @@ - -

Introduction

-piscope is a logic analyser (digital -waveform viewer) for the Raspberry.  It shows the state (high -or low) of selected GPIO in real-time.
-
-See video.
-
-piscope uses the services of the pigpio library.  pigpio needs to be running on -the Pi whose GPIO are to be monitored.
-
-The pigpio library may be started as a daemon (background process) -by the following command.
-
-sudo pigpiod

-piscope may be invoked in several different ways
-
- - - - - - - - - - - - - - - - - - - - - - - -
Pi
pi_host ~ $ piscope -&
Pi captures -data
-Pi processes data
-Pi displays data
Pi plus Linux PC
-
-(with the
-display on a remote
-  Linux PC)
remote_host ~ $ ssh -X pi_host
pi_host ~ $ piscope -&
Pi captures data
-Pi processes data
-Remote Linux PC displays data
Pi plus Windows PC
-
-(with the
-display on a remote
-  Windows PC)
You need to install an SSH -client (putty suggested) and a X11 server (xming suggested).
-
-Run Program Files -> Xming -> XLaunch and accept the -defaults.
-
-Run putty and enter the Pi's host name or IP address.  Click -on SSH X11 and tick Enable X11 forwarding and then select -Open.

-
pi_host ~ $ piscope -&
Pi captures data
-Pi processes data
-Remote Windows PC displays data
Pi plus Linux PC
-
-(with the display and processing on a remote Linux -PC)
remote_host ~ $ export -PIGPIO_ADDR=pi_host
-remote_host ~ $ piscope -&
Pi captures data
-Remote processes data
-Remote displays data
-
-piscope operates in one of three modes
-
- - - - - - - - - - - - - - - - - - -
Live
The latest GPIO samples are -displayed.
-
-The mode will automatically change to Pause if a sampling trigger -is detected.
-
-There are four triggers.  Each trigger is made up of a -combination of GPIO states (one of don't care, low, high, edge, -falling, or rising per GPIO).  Triggers are always -counted.  In addition a trigger may be sample to, sample -around, or sample from, a so called sampling trigger.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full the oldest samples are discarded.
Play
Recorded GPIO samples are -displayed.
-
-The play speed may be varied between 64 times real-time to 1/32768 -of real-time.
-
-The page up key increases the play speed by a factor of 2.  -The page down key decreases the play speed by a factor of 2.  -The home key sets the play speed to 1X.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full new samples are discarded.
Pause
Recorded GPIO samples are -displayed.
-
-The left and right cursor keys move the blue marker to the previous -or next edge.  By default all GPIO edges are considered.  -Clicking on a GPIO name will limit edge searches to the highlighted -GPIO only.
-
-The left and right square bracket keys move the blue marker to the -previous or next trigger.
-
-The time between the blue and gold markers is displayed.  The -gold marker is set to the blue marker by a press of the 'g' -key.
New samples are added to the -sample buffer.
-
-Once the sample buffer is full new samples are discarded.
-
-In all modes the down and up cursor keys zoom the time scale in and -out.
-
-Samples can be saved with File Save All Samples or File Save -Selected Samples. -

To select samples enter pause mode. Press 1 to specify the start -of the samples (green marker) and 2 to specify the end of the -samples (red marker).

-

The samples may be saved in the native piscope format or in VCD -format.

-

Data saved in VCD format may be viewed and further processed -with GTKWave.

-

Data saved in the native piscope format may be restored later -with File Restore Saved Data.

-

Installation

-

To download and install piscope.

-

Pi (pre-built image)

-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make hf
-make install

-

Linux 64 bit X86/AMD (pre-built image)

-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make x86_64
-make install
-

All machines (building from source)

-You only need to perform this step if you want to build the -executable from the source files.  This is not needed if you -use a pre-built image.
-
-WARNING
: Installing gtk+-3.0 uses a lot of SD card -space.
-
-Most of the space used by gtk+-3.0 is taken up by unneeded *-dbg -packages.
-
-With *-dbg packages an additional 3753MB SD space is required.
-
-If you edit the list of packages to be downloaded and remove the -*-dbg packages only 134MB of additional SD space is needed (as at -the time of writing).
-
-#
# *** This may take a lot of time and use -a lot of SD card space ***
#
-sudo apt-get install gtk+-3.0
#
-wget abyz.me.uk/rpi/pigpio/piscope.tar
-tar xvf piscope.tar
-cd PISCOPE
-make
-make install

diff --git a/DOC/tmp/body/python.body b/DOC/tmp/body/python.body deleted file mode 100644 index 4f756e4..0000000 --- a/DOC/tmp/body/python.body +++ /dev/null @@ -1,1231 +0,0 @@ -pigpio is a Python module for the Raspberry which talks to -the pigpio daemon to allow control of the general purpose -input outputs (GPIO). -

Features

o the pigpio Python module can run on Windows, Macs, or Linux -

o controls one or more Pi's -

o hardware timed PWM on any of GPIO 0-31 -

o hardware timed servo pulses on any of GPIO 0-31 -

o callbacks when any of GPIO 0-31 change state -

o creating and transmitting precisely timed waveforms -

o reading/writing GPIO and setting their modes -

o wrappers for I2C, SPI, and serial links -

o creating and running scripts on the pigpio daemon -

GPIO

ALL GPIO are identified by their Broadcom number. -

Notes

Transmitted waveforms are accurate to a microsecond. -

Callback level changes are time-stamped and will be -accurate to within a few microseconds. -

Settings

A number of settings are determined when the pigpio daemon is started. -

o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). -

o the set of GPIO which may be updated (generally written to). The - default set is those available on the Pi board revision. -

o the available PWM frequencies (see set_PWM_frequency). -

Exceptions

By default a fatal exception is raised if you pass an invalid -argument to a pigpio function. -

If you wish to handle the returned status yourself you should set -pigpio.exceptions to False. -

You may prefer to check the returned status in only a few parts -of your code. In that case do the following: -

Example

pigpio.exceptions = False

# Code where you want to test the error status.

pigpio.exceptions = True

Usage

This module uses the services of the C pigpio library. pigpio -must be running on the Pi(s) whose GPIO are to be manipulated. -

The normal way to start pigpio is as a daemon (during system -start). -

sudo pigpiod -

Your Python program must import pigpio and create one or more -instances of the pigpio.pi class. This class gives access to -a specified Pi's GPIO. -

Example

pi1 = pigpio.pi()       # pi1 accesses the local Pi's GPIO
pi2 = pigpio.pi('tom')  # pi2 accesses tom's GPIO
pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO

pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4)     # get level of dick's GPIO 4


The later example code snippets assume that pi is an instance of -the pigpio.pi class. -

OVERVIEW

ESSENTIAL -
pigpio.pi Initialise Pi connection -
stop Stop a Pi connection -
BASIC -
set_mode Set a GPIO mode -
get_mode Get a GPIO mode -
set_pull_up_down Set/clear GPIO pull up/down resistor -
read Read a GPIO -
write Write a GPIO -
PWM (overrides servo commands on same GPIO) -
set_PWM_dutycycle Start/stop PWM pulses on a GPIO -
set_PWM_frequency Set PWM frequency of a GPIO -
set_PWM_range Configure PWM range of a GPIO -
get_PWM_dutycycle Get PWM dutycycle set on a GPIO -
get_PWM_frequency Get PWM frequency of a GPIO -
get_PWM_range Get configured PWM range of a GPIO -
get_PWM_real_range Get underlying PWM range for a GPIO -
Servo (overrides PWM commands on same GPIO) -
set_servo_pulsewidth Start/Stop servo pulses on a GPIO -
get_servo_pulsewidth Get servo pulsewidth set on a GPIO -
INTERMEDIATE -
gpio_trigger Send a trigger pulse to a GPIO -
set_watchdog Set a watchdog on a GPIO -
read_bank_1 Read all bank 1 GPIO -
read_bank_2 Read all bank 2 GPIO -
clear_bank_1 Clear selected GPIO in bank 1 -
clear_bank_2 Clear selected GPIO in bank 2 -
set_bank_1 Set selected GPIO in bank 1 -
set_bank_2 Set selected GPIO in bank 2 -
callback Create GPIO level change callback -
wait_for_edge Wait for GPIO level change -
ADVANCED -
notify_open Request a notification handle -
notify_begin Start notifications for selected GPIO -
notify_pause Pause notifications -
notify_close Close a notification -
hardware_clock Start hardware clock on supported GPIO -
hardware_PWM Start hardware PWM on supported GPIO -
set_glitch_filter Set a glitch filter on a GPIO -
set_noise_filter Set a noise filter on a GPIO -
set_pad_strength Sets a pads drive strength -
get_pad_strength Gets a pads drive strength -
shell Executes a shell command -
Custom -
custom_1 User custom function 1 -
custom_2 User custom function 2 -
Events -
event_callback Sets a callback for an event -
event_trigger Triggers an event -
wait_for_event Wait for an event -
Scripts -
store_script Store a script -
run_script Run a stored script -
update_script Set a scripts parameters -
script_status Get script status and parameters -
stop_script Stop a running script -
delete_script Delete a stored script -
I2C -
i2c_open Opens an I2C device -
i2c_close Closes an I2C device -
i2c_write_quick SMBus write quick -
i2c_read_byte SMBus read byte -
i2c_write_byte SMBus write byte -
i2c_read_byte_data SMBus read byte data -
i2c_write_byte_data SMBus write byte data -
i2c_read_word_data SMBus read word data -
i2c_write_word_data SMBus write word data -
i2c_read_block_data SMBus read block data -
i2c_write_block_data SMBus write block data -
i2c_read_i2c_block_data SMBus read I2C block data -
i2c_write_i2c_block_data SMBus write I2C block data -
i2c_read_device Reads the raw I2C device -
i2c_write_device Writes the raw I2C device -
i2c_process_call SMBus process call -
i2c_block_process_call SMBus block process call -
i2c_zip Performs multiple I2C transactions -
I2C BIT BANG -
bb_i2c_open Opens GPIO for bit banging I2C -
bb_i2c_close Closes GPIO for bit banging I2C -
bb_i2c_zip Performs multiple bit banged I2C transactions -
I2C/SPI SLAVE -
bsc_xfer I2C/SPI as slave transfer -
bsc_i2c I2C as slave transfer -
SERIAL -
serial_open Opens a serial device -
serial_close Closes a serial device -
serial_read_byte Reads a byte from a serial device -
serial_write_byte Writes a byte to a serial device -
serial_read Reads bytes from a serial device -
serial_write Writes bytes to a serial device -
serial_data_available Returns number of bytes ready to be read -
SERIAL BIT BANG (read only) -
bb_serial_read_open Open a GPIO for bit bang serial reads -
bb_serial_read_close Close a GPIO for bit bang serial reads -
bb_serial_invert Invert serial logic (1 invert, 0 normal) -
bb_serial_read Read bit bang serial data from a GPIO -
SPI -
spi_open Opens a SPI device -
spi_close Closes a SPI device -
spi_read Reads bytes from a SPI device -
spi_write Writes bytes to a SPI device -
spi_xfer Transfers bytes with a SPI device -
SPI BIT BANG -
bb_spi_open Opens GPIO for bit banging SPI -
bb_spi_close Closes GPIO for bit banging SPI -
bb_spi_xfer Transfers bytes with bit banging SPI -
FILES -
file_open Opens a file -
file_close Closes a file -
file_read Reads bytes from a file -
file_write Writes bytes to a file -
file_seek Seeks to a position within a file -
file_list List files which match a pattern -
WAVES -
wave_clear Deletes all waveforms -
wave_add_new Starts a new waveform -
wave_add_generic Adds a series of pulses to the waveform -
wave_add_serial Adds serial data to the waveform -
wave_create Creates a waveform from added data -
wave_create_and_pad Creates a waveform of fixed size from added data -
wave_delete Deletes a waveform -
wave_send_once Transmits a waveform once -
wave_send_repeat Transmits a waveform repeatedly -
wave_send_using_mode Transmits a waveform in the chosen mode -
wave_chain Transmits a chain of waveforms -
wave_tx_at Returns the current transmitting waveform -
wave_tx_busy Checks to see if a waveform has ended -
wave_tx_stop Aborts the current waveform -
wave_get_cbs Length in cbs of the current waveform -
wave_get_max_cbs Absolute maximum allowed cbs -
wave_get_micros Length in microseconds of the current waveform -
wave_get_max_micros Absolute maximum allowed micros -
wave_get_pulses Length in pulses of the current waveform -
wave_get_max_pulses Absolute maximum allowed pulses -
UTILITIES -
get_current_tick Get current tick (microseconds) -
get_hardware_revision Get hardware revision -
get_pigpio_version Get the pigpio version -
pigpio.error_text Gets error text from error number -
pigpio.tickDiff Returns difference between two ticks -

class pi -

pigpio.pi(host, port, show_errors)

-Grants access to a Pi's GPIO. -

Parameters

host:= the host name of the Pi on which the pigpio daemon is
       running.  The default is localhost unless overridden by
       the PIGPIO_ADDR environment variable.


Parameters

port:= the port number on which the pigpio daemon is listening.
       The default is 8888 unless overridden by the PIGPIO_PORT
       environment variable.  The pigpio daemon must have been
       started with the same port number.


This connects to the pigpio daemon and reserves resources -to be used for sending commands and receiving notifications. -

An instance attribute connected may be used to check the -success of the connection. If the connection is established -successfully connected will be True, otherwise False. -

Example

pi = pigio.pi()              # use defaults
pi = pigpio.pi('mypi')       # specify host, default port
pi = pigpio.pi('mypi', 7777) # specify host and port

pi = pigpio.pi()             # exit script if no connection
if not pi.connected:
   exit()

__repr__()

-

bb_i2c_close(SDA)

-This function stops bit banging I2C on a pair of GPIO -previously opened with bb_i2c_open. -

Parameters

SDA:= 0-31, the SDA GPIO used in a prior call to bb_i2c_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. -

Example

pi.bb_i2c_close(SDA)

bb_i2c_open(SDA, SCL, baud)

-This function selects a pair of GPIO for bit banging I2C at a -specified baud rate. -

Bit banging I2C allows for certain operations which are not possible -with the standard I2C driver. -

o baud rates as low as 50 -o repeated starts -o clock stretching -o I2C on any pair of spare GPIO -

Parameters

 SDA:= 0-31
 SCL:= 0-31
baud:= 50-500000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or -PI_GPIO_IN_USE. -

NOTE: -

The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. -As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. -

Example

h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps

bb_i2c_zip(SDA, data)

-This function executes a sequence of bit banged I2C operations. -The operations to be performed are specified by the contents -of data which contains the concatenated command codes and -associated data. -

Parameters

 SDA:= 0-31 (as used in a prior call to bb_i2c_open)
data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.bb_i2c_zip(
                   SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0])


The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
Start2Start condition
Stop3Stop condition
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address and flags default to 0. The address and flags maintain -their previous value until updated. -

No flags are currently defined. -

Any read I2C data is concatenated in the returned bytearray. -

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

bb_serial_invert(user_gpio, invert)

-Invert serial logic. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)
    invert:= 0-1 (1 invert, 0 normal)


Example

status = pi.bb_serial_invert(17, 1)

bb_serial_read(user_gpio)

-Returns data from the bit bang serial cyclic buffer. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

The bytes returned for each character depend upon the number of -data bits bb_bits specified in the bb_serial_read_open -command. -

For bb_bits 1-8 there will be one byte per character. -For bb_bits 9-16 there will be two bytes per character. -For bb_bits 17-32 there will be four bytes per character. -

Example

(count, data) = pi.bb_serial_read(4)

bb_serial_read_close(user_gpio)

-Closes a GPIO for bit bang reading of serial data. -

Parameters

user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)


Example

status = pi.bb_serial_read_close(17)

bb_serial_read_open(user_gpio, baud, bb_bits)

-Opens a GPIO for bit bang reading of serial data. -

Parameters

user_gpio:= 0-31, the GPIO to use.
     baud:= 50-250000, the baud rate.
  bb_bits:= 1-32, the number of bits per word, default 8.


The serial data is held in a cyclic buffer and is read using -bb_serial_read. -

It is the caller's responsibility to read data from the cyclic -buffer in a timely fashion. -

Example

status = pi.bb_serial_read_open(4, 19200)
status = pi.bb_serial_read_open(17, 9600)

bb_spi_close(CS)

-This function stops bit banging SPI on a set of GPIO -opened with bb_spi_open. -

Parameters

CS:= 0-31, the CS GPIO used in a prior call to bb_spi_open


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. -

Example

pi.bb_spi_close(CS)

bb_spi_open(CS, MISO, MOSI, SCLK, baud, spi_flags)

-This function selects a set of GPIO for bit banging SPI at a -specified baud rate. -

Parameters

      CS := 0-31
    MISO := 0-31
    MOSI := 0-31
    SCLK := 0-31
    baud := 50-250000
spiFlags := see below


spiFlags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  0  0  0  0  0  R  T  0  0  0  0  0  0  0  0  0  0  0  p  m  m


mm defines the SPI mode, defaults to 0 -

Mode CPOL CPHA
 0     0    0
 1     0    1
 2     1    0
 3     1    1


The following constants may be used to set the mode: -

pigpio.SPI_MODE_0
pigpio.SPI_MODE_1
pigpio.SPI_MODE_2
pigpio.SPI_MODE_3


Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA -may be used. -

p is 0 if CS is active low (default) and 1 for active high. -pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag. -

T is 1 if the least significant bit is transmitted on MOSI first, -the default (0) shifts the most significant bit out first. -pigpio.SPI_TX_LSBFIRST may be used to set this flag. -

R is 1 if the least significant bit is received on MISO first, -the default (0) receives the most significant bit first. -pigpio.SPI_RX_LSBFIRST may be used to set this flag. -

The other bits in spiFlags should be set to zero. -

Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or -PI_GPIO_IN_USE. -

If more than one device is connected to the SPI bus (defined by -SCLK, MOSI, and MISO) each must have its own CS. -

Example

bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2

bb_spi_xfer(CS, data)

-This function executes a bit banged SPI transfer. -

Parameters

  CS:= 0-31 (as used in a prior call to bb_spi_open)
data:= data to be sent


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

#!/usr/bin/env python

import pigpio

CE0=5
CE1=6
MISO=13
MOSI=19
SCLK=12

pi = pigpio.pi()
if not pi.connected:
   exit()

pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC
pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC

for i in range(256):

   count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value

   if count == 2:

      count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC

      if count == 2:

         set_val = data[1]

         count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC

         if count == 3:

            read_val = ((data[1]&3)<<8) | data[2]

            print("{} {}".format(set_val, read_val))

pi.bb_spi_close(CE0)
pi.bb_spi_close(CE1)

pi.stop()

bsc_i2c(i2c_address, data)

-This function allows the Pi to act as a slave I2C device. -

This function is not available on the BCM2711 (e.g. as -used in the Pi4B). -

The data bytes (if any) are written to the BSC transmit -FIFO and the bytes in the BSC receive FIFO are returned. -

Parameters

i2c_address:= the I2C slave address.
       data:= the data bytes to transmit.


The returned value is a tuple of the status, the number -of bytes read, and a bytearray containing the read bytes. -

See bsc_xfer for details of the status value. -

If there was an error the status will be less than zero -(and will contain the error code). -

Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO as inputs. -

This example assumes GPIO 2/3 are connected to GPIO 18/19 -(GPIO 10/11 on the BCM2711). -

Example

#!/usr/bin/env python
import time
import pigpio

I2C_ADDR=0x13

def i2c(id, tick):
    global pi

    s, b, d = pi.bsc_i2c(I2C_ADDR)
    if b:
        if d[0] == ord('t'): # 116 send 'HH:MM:SS*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[11:19]))

        elif d[0] == ord('d'): # 100 send 'Sun Oct 30*'

            print("sent={} FR={} received={} [{}]".
               format(s>>16, s&0xfff,b,d))

            s, b, d = pi.bsc_i2c(I2C_ADDR,
               "{}*".format(time.asctime()[:10]))

pi = pigpio.pi()

if not pi.connected:
    exit()

# Respond to BSC slave activity

e = pi.event_callback(pigpio.EVENT_BSC, i2c)

pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave

time.sleep(600)

e.cancel()

pi.bsc_i2c(0) # Disable BSC peripheral

pi.stop()


While running the above. -

$ i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

$ pigs i2co 1 0x13 0
0

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:13:58*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:14:29*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

$ pigs i2cwd 0 116
$ pigs i2crd 0 9 -a
9 10:23:16*

$ pigs i2cwd 0 100
$ pigs i2crd 0 11 -a
11 Sun Oct 30*

bsc_xfer(bsc_control, data)

-This function provides a low-level interface to the SPI/I2C Slave -peripheral on the BCM chip. -

This peripheral allows the Pi to act as a hardware slave device -on an I2C or SPI bus. -

This is not a bit bang version and as such is OS timing -independent. The bus timing is handled directly by the chip. -

The output process is simple. You simply append data to the FIFO -buffer on the chip. This works like a queue, you add data to the -queue and the master removes it. -

I can't get SPI to work properly. I tried with a -control word of 0x303 and swapped MISO and MOSI. -

The function sets the BSC mode, writes any data in -the transmit buffer to the BSC transmit FIFO, and -copies any data in the BSC receive FIFO to the -receive buffer. -

Parameters

bsc_control:= see below
       data:= the data bytes to place in the transmit FIFO.


The returned value is a tuple of the status (see below), -the number of bytes read, and a bytearray containing the -read bytes. If there was an error the status will be less -than zero (and will contain the error code). -

Note that the control word sets the BSC mode. The BSC will -stay in that mode until a different control word is sent. -

GPIO used for models other than those based on the BCM2711. -

SDASCLMOSISCLKMISOCE
I2C1819----
SPI--18192021


GPIO used for models based on the BCM2711 (e.g. the Pi4B). -

SDASCLMOSISCLKMISOCE
I2C1011----
SPI--101198


When a zero control word is received the used GPIO will be reset -to INPUT mode. -

bsc_control consists of the following bits: -

22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 a  a  a  a  a  a  a  -  - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN


Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document for full -details. -

aaaaaaadefines the I2C slave address (only relevant in I2C mode)
ITinvert transmit status flags
HCenable host control
TFenable test FIFO
IRinvert receive status flags
REenable receive
TEenable transmit
BKabort operation and clear FIFOs
ECsend control register as first I2C byte
ESsend status register as first I2C byte
PLset SPI polarity high
PHset SPI phase high
I2enable I2C mode
SPenable SPI mode
ENenable BSC peripheral


The status has the following format: -

20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 S  S  S  S  S  R  R  R  R  R  T  T  T  T  T RB TE RF TF RE TB


Bits 0-15 are copied unchanged from the BSC FR register. See -pages 165-166 of the Broadcom peripherals document for full -details. -

SSSSSnumber of bytes successfully copied to transmit FIFO
RRRRRnumber of bytes in receieve FIFO
TTTTTnumber of bytes in transmit FIFO
RBreceive busy
TEtransmit FIFO empty
RFreceive FIFO full
TFtransmit FIFO full
REreceive FIFO empty
TBtransmit busy


Example

(status, count, data) = pi.bsc_xfer(0x330305, "Hello!")

callback(user_gpio, edge, func)

-Calls a user supplied function (a callback) whenever the -specified GPIO edge is detected. -

Parameters

user_gpio:= 0-31.
     edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.
     func:= user supplied callback function.


The user supplied callback receives three parameters, the GPIO, -the level, and the tick. -

Parameter   Value    Meaning

GPIO        0-31     The GPIO which has changed state

level       0-2      0 = change to low (a falling edge)
                     1 = change to high (a rising edge)
                     2 = no level change (a watchdog timeout)

tick        32 bit   The number of microseconds since boot
                     WARNING: this wraps around from
                     4294967295 to 0 roughly every 72 minutes


If a user callback is not specified a default tally callback is -provided which simply counts edges. The count may be retrieved -by calling the tally function. The count may be reset to zero -by calling the reset_tally function. -

The callback may be cancelled by calling the cancel function. -

A GPIO may have multiple callbacks (although I can't think of -a reason to do so). -

The GPIO are sampled at a rate set when the pigpio daemon -is started (default 5 us). -

The number of samples per second is given in the following table. -

              samples
              per sec

         1  1,000,000
         2    500,000
sample   4    250,000
rate     5    200,000
(us)     8    125,000
        10    100,000


GPIO level changes shorter than the sample rate may be missed. -

The daemon software which generates the callbacks is triggered -1000 times per second. The callbacks will be called once per -level change since the last time they were called. -i.e. The callbacks will get all level changes but there will -be a latency. -

If you want to track the level of more than one GPIO do so by -maintaining the state in the callback. Do not use read. -Remember the event that triggered the callback may have -happened several milliseconds before and the GPIO may have -changed level many times since then. -

Example

def cbf(gpio, level, tick):
   print(gpio, level, tick)

cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf)

cb2 = pi.callback(4, pigpio.EITHER_EDGE)

cb3 = pi.callback(17)

print(cb3.tally())

cb3.reset_tally()

cb1.cancel() # To cancel callback cb1.

clear_bank_1(bits)

-Clears GPIO 0-31 if the corresponding bit in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.clear_bank_1(int("111110010000",2))

clear_bank_2(bits)

-Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be cleared.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.clear_bank_2(0x1010)

custom_1(arg1, arg2, argx)

-Calls a pigpio function customised by the user. -

Parameters

arg1:= >=0, default 0.
arg2:= >=0, default 0.
argx:= extra arguments (each 0-255), default empty.


The returned value is an integer which by convention -should be >=0 for OK and <0 for error. -

Example

value = pi.custom_1()

value = pi.custom_1(23)

value = pi.custom_1(0, 55)

value = pi.custom_1(23, 56, [1, 5, 7])

value = pi.custom_1(23, 56, b"hello")

value = pi.custom_1(23, 56, "hello")

custom_2(arg1, argx, retMax)

-Calls a pigpio function customised by the user. -

Parameters

  arg1:= >=0, default 0.
  argx:= extra arguments (each 0-255), default empty.
retMax:= >=0, maximum number of bytes to return, default 8192.


The returned value is a tuple of the number of bytes -returned and a bytearray containing the bytes. If -there was an error the number of bytes read will be -less than zero (and will contain the error code). -

Example

(count, data) = pi.custom_2()

(count, data) = pi.custom_2(23)

(count, data) = pi.custom_2(23, [1, 5, 7])

(count, data) = pi.custom_2(23, b"hello")

(count, data) = pi.custom_2(23, "hello", 128)

delete_script(script_id)

-Deletes a stored script. -

Parameters

script_id:= id of stored script.


Example

status = pi.delete_script(sid)

event_callback(event, func)

-Calls a user supplied function (a callback) whenever the -specified event is signalled. -

Parameters

event:= 0-31.
 func:= user supplied callback function.


The user supplied callback receives two parameters, the event id, -and the tick. -

If a user callback is not specified a default tally callback is -provided which simply counts events. The count may be retrieved -by calling the tally function. The count may be reset to zero -by calling the reset_tally function. -

The callback may be cancelled by calling the event_cancel function. -

An event may have multiple callbacks (although I can't think of -a reason to do so). -

Example

def cbf(event, tick):
   print(event, tick)

cb1 = pi.event_callback(22, cbf)

cb2 = pi.event_callback(4)

print(cb2.tally())

cb2.reset_tally()

cb1.event_cancel() # To cancel callback cb1.

event_trigger(event)

-This function signals the occurrence of an event. -

Parameters

event:= 0-31, the event


Returns 0 if OK, otherwise PI_BAD_EVENT_ID. -

An event is a signal used to inform one or more consumers -to start an action. Each consumer which has registered an -interest in the event (e.g. by calling event_callback) will -be informed by a callback. -

One event, EVENT_BSC (31) is predefined. This event is -auto generated on BSC slave activity. -

The meaning of other events is arbitrary. -

Note that other than its id and its tick there is no data associated -with an event. -

Example

pi.event_trigger(23)

file_close(handle)

-Closes the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).


Example

pi.file_close(handle)

file_list(fpattern)

-Returns a list of files which match a pattern. -

Parameters

fpattern:= file pattern to match.


Returns the number of returned bytes if OK, otherwise -PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. -

The pattern must match an entry in /opt/pigpio/access. The -pattern may contain wildcards. See file_open. -

NOTE -

The returned value is not the number of files, it is the number -of bytes in the buffer. The file names are separated by newline -characters. -

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

# Assumes /opt/pigpio/access contains the following line:
# /ram/*.c r

c, d = pi.file_list("/ram/p*.c")
if c > 0:
   print(d)

pi.stop()

file_open(file_name, file_mode)

-This function returns a handle to a file opened in a specified mode. -

Parameters

file_name:= the file to open.
file_mode:= the file open mode.


Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, -PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE, -PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. -

Example

h = pi.file_open("/home/pi/shared/dir_3/file.txt",
        pigpio.FILE_WRITE | pigpio.FILE_CREATE)

pi.file_write(h, "Hello world")

pi.file_close(h)


File -

A file may only be opened if permission is granted by an entry -in /opt/pigpio/access. This is intended to allow remote access -to files in a more or less controlled manner. -

Each entry in /opt/pigpio/access takes the form of a file path -which may contain wildcards followed by a single letter permission. -The permission may be R for read, W for write, U for read/write, -and N for no access. -

Where more than one entry matches a file the most specific rule -applies. If no entry matches a file then access is denied. -

Suppose /opt/pigpio/access contains the following entries: -

/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n


Files may be written in directory dir_1 with the exception -of file.txt. -

Files may be read in directory dir_2. -

Files may be read and written in directory dir_3. -

If a directory allows read, write, or read/write access then files -may be created in that directory. -

In an attempt to prevent risky permissions the following paths are -ignored in /opt/pigpio/access: -

a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts


Mode -

The mode may have the following values: -

ConstantValueMeaning
FILE_READ1open file for reading
FILE_WRITE2open file for writing
FILE_RW3open file for reading and writing


The following values may be or'd into the mode: -

NameValueMeaning
FILE_APPEND4All writes append data to the end of the file
FILE_CREATE8The file is created if it doesn't exist
FILE_TRUNC16The file is truncated


Newly created files are owned by root with permissions owner -read and write. -

Example

#!/usr/bin/env python

import pigpio

pi = pigpio.pi()

if not pi.connected:
   exit()

# Assumes /opt/pigpio/access contains the following line:
# /ram/*.c r

handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ)

done = False

while not done:
   c, d = pi.file_read(handle, 60000)
   if c > 0:
      print(d)
   else:
      done = True

pi.file_close(handle)

pi.stop()

file_read(handle, count)

-Reads up to count bytes from the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.file_read(h2, 100)
if b > 0:
   # process read data

file_seek(handle, seek_offset, seek_from)

-Seeks to a position relative to the start, current position, -or end of the file. Returns the new position. -

Parameters

     handle:= >=0 (as returned by a prior call to file_open).
seek_offset:= byte offset.
  seek_from:= FROM_START, FROM_CURRENT, or FROM_END.


Example

new_pos = pi.file_seek(h, 100, pigpio.FROM_START)

cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT)

file_size = pi.file_seek(h, 0, pigpio.FROM_END)

file_write(handle, data)

-Writes the data bytes to the file associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to file_open).
  data:= the bytes to write.


Example

pi.file_write(h1, b'\x02\x03\x04')

pi.file_write(h2, b'help')

pi.file_write(h2, "hello")

pi.file_write(h1, [2, 3, 4])

get_PWM_dutycycle(user_gpio)

-Returns the PWM dutycycle being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the PWM dutycycle. -

For normal PWM the dutycycle will be out of the defined range -for the GPIO (see get_PWM_range). -

If a hardware clock is active on the GPIO the reported -dutycycle will be 500000 (500k) out of 1000000 (1M). -

If hardware PWM is active on the GPIO the reported dutycycle -will be out of a 1000000 (1M). -

Example

pi.set_PWM_dutycycle(4, 25)
print(pi.get_PWM_dutycycle(4))
25

pi.set_PWM_dutycycle(4, 203)
print(pi.get_PWM_dutycycle(4))
203

get_PWM_frequency(user_gpio)

-Returns the frequency of PWM being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the frequency (in Hz) used for the GPIO. -

For normal PWM the frequency will be that defined for the GPIO -by set_PWM_frequency. -

If a hardware clock is active on the GPIO the reported frequency -will be that set by hardware_clock. -

If hardware PWM is active on the GPIO the reported frequency -will be that set by hardware_PWM. -

Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_frequency(4))
800

get_PWM_range(user_gpio)

-Returns the range of PWM values being used on the GPIO. -

Parameters

user_gpio:= 0-31.


If a hardware clock or hardware PWM is active on the GPIO -the reported range will be 1000000 (1M). -

Example

pi.set_PWM_range(9, 500)
print(pi.get_PWM_range(9))
500

get_PWM_real_range(user_gpio)

-Returns the real (underlying) range of PWM values being -used on the GPIO. -

Parameters

user_gpio:= 0-31.


If a hardware clock is active on the GPIO the reported -real range will be 1000000 (1M). -

If hardware PWM is active on the GPIO the reported real range -will be approximately 250M divided by the set PWM frequency. -

Example

pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_real_range(4))
250

get_current_tick()

-Returns the current system tick. -

Tick is the number of microseconds since system boot. As an -unsigned 32 bit quantity tick wraps around approximately -every 71.6 minutes. -

Example

t1 = pi.get_current_tick()
time.sleep(1)
t2 = pi.get_current_tick()

get_hardware_revision()

-Returns the Pi's hardware revision number. -

The hardware revision is the last few characters on the -Revision line of /proc/cpuinfo. -

The revision number can be used to determine the assignment -of GPIO to pins (see
gpio). -

There are at least three types of board. -

Type 1 boards have hardware revision numbers of 2 and 3. -

Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. -

Type 3 boards have hardware revision numbers of 16 or greater. -

If the hardware revision can not be found or is not a valid -hexadecimal number the function returns 0. -

Example

print(pi.get_hardware_revision())
2

get_mode(gpio)

-Returns the GPIO mode. -

Parameters

gpio:= 0-53.


Returns a value as follows -

0 = INPUT
1 = OUTPUT
2 = ALT5
3 = ALT4
4 = ALT0
5 = ALT1
6 = ALT2
7 = ALT3


Example

print(pi.get_mode(0))
4

get_pad_strength(pad)

-This function returns the pad drive strength in mA. -

Parameters

pad:= 0-2, the pad to get.


Returns the pad drive strength if OK, otherwise PI_BAD_PAD. -

PadGPIO
00-27
128-45
246-53


Example

strength = pi.get_pad_strength(0) # Get pad 0 strength.

get_pigpio_version()

-Returns the pigpio software version. -

Example

v = pi.get_pigpio_version()

get_servo_pulsewidth(user_gpio)

-Returns the servo pulsewidth being used on the GPIO. -

Parameters

user_gpio:= 0-31.


Returns the servo pulsewidth. -

Example

pi.set_servo_pulsewidth(4, 525)
print(pi.get_servo_pulsewidth(4))
525

pi.set_servo_pulsewidth(4, 2130)
print(pi.get_servo_pulsewidth(4))
2130

gpio_trigger(user_gpio, pulse_len, level)

-Send a trigger pulse to a GPIO. The GPIO is set to -level for pulse_len microseconds and then reset to not level. -

Parameters

user_gpio:= 0-31
pulse_len:= 1-100
    level:= 0-1


Example

pi.gpio_trigger(23, 10, 1)

hardware_PWM(gpio, PWMfreq, PWMduty)

-Starts hardware PWM on a GPIO at the specified frequency -and dutycycle. Frequencies above 30MHz are unlikely to work. -

NOTE: Any waveform started by wave_send_once, -wave_send_repeat, or wave_chain will be cancelled. -

This function is only valid if the pigpio main clock is PCM. -The main clock defaults to PCM but may be overridden when the -pigpio daemon is started (option -t). -

Parameters

   gpio:= see descripton
PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711).
PWMduty:= 0 (off) to 1000000 (1M)(fully on).


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. -

The same PWM channel is available on multiple GPIO. -The latest frequency and dutycycle setting will be used -by all GPIO which share a PWM channel. -

The GPIO must be one of the following: -

12  PWM channel 0  All models but A and B
13  PWM channel 1  All models but A and B
18  PWM channel 0  All models
19  PWM channel 1  All models but A and B

40  PWM channel 0  Compute module only
41  PWM channel 1  Compute module only
45  PWM channel 1  Compute module only
52  PWM channel 0  Compute module only
53  PWM channel 1  Compute module only


The actual number of steps beween off and fully on is the -integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). -

The actual frequency set is 250M/steps (375M/steps -for the BCM2711). -

There will only be a million steps for a PWMfreq of 250 -(375 for the BCM2711). Lower frequencies will have more -steps and higher frequencies will have fewer steps. -PWMduty is automatically scaled to take this into account. -

Example

pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle

pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle

hardware_clock(gpio, clkfreq)

-Starts a hardware clock on a GPIO at the specified frequency. -Frequencies above 30MHz are unlikely to work. -

Parameters

   gpio:= see description
clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711)


Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, -PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. -

The same clock is available on multiple GPIO. The latest -frequency setting will be used by all GPIO which share a clock. -

The GPIO must be one of the following: -

4   clock 0  All models
5   clock 1  All models but A and B (reserved for system use)
6   clock 2  All models but A and B
20  clock 0  All models but A and B
21  clock 1  All models but A and Rev.2 B (reserved for system use)

32  clock 0  Compute module only
34  clock 0  Compute module only
42  clock 1  Compute module only (reserved for system use)
43  clock 2  Compute module only
44  clock 1  Compute module only (reserved for system use)


Access to clock 1 is protected by a password as its use will -likely crash the Pi. The password is given by or'ing 0x5A000000 -with the GPIO number. -

Example

pi.hardware_clock(4, 5000) # 5 KHz clock on GPIO 4

pi.hardware_clock(4, 40000000) # 40 MHz clock on GPIO 4

i2c_block_process_call(handle, reg, data)

-Writes data bytes to the specified register of the device -associated with handle and reads a device specified number -of bytes of data in return. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


The SMBus 2.0 documentation states that a minimum of 1 byte may -be sent and a minimum of 1 byte may be received. The total -number of bytes sent/received must be 32 or less. -

SMBus 2.0 5.5.8 - Block write-block read. -S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A]
   S Addr Rd [A] [Count] A [Data] ... A P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00')

(b, d) = pi.i2c_block_process_call(h, 10, b'abcdr')

(b, d) = pi.i2c_block_process_call(h, 10, "abracad")

(b, d) = pi.i2c_block_process_call(h, 10, [2, 5, 16])

i2c_close(handle)

-Closes the I2C device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).


Example

pi.i2c_close(h)

i2c_open(i2c_bus, i2c_address, i2c_flags)

-Returns a handle (>=0) for the device at the I2C bus address. -

Parameters

    i2c_bus:= >=0.
i2c_address:= 0-0x7F.
  i2c_flags:= 0, no flags are currently defined.


Physically buses 0 and 1 are available on the Pi. Higher -numbered buses will be available if a kernel supported bus -multiplexor is being used. -

The GPIO used are given in the following table. -

SDASCL
I2C 001
I2C 123


For the SMBus commands the low level transactions are shown -at the end of the function description. The following -abbreviations are used: -

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.
Addr  (7 bits): I2C 7 bit address.
reg   (8 bits): Command byte, which often selects a register.
Data  (8 bits): A data byte.
Count (8 bits): A byte defining the length of a block operation.

[..]: Data sent by the device.


Example

h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1

i2c_process_call(handle, reg, word_val)

-Writes 16 bits of data to the specified register of the device -associated with handle and reads 16 bits of data in return. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.6 - Process call. -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A]
   S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

r = pi.i2c_process_call(h, 4, 0x1231)
r = pi.i2c_process_call(h, 6, 0)

i2c_read_block_data(handle, reg)

-Reads a block of up to 32 bytes from the specified register of -the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.7 - Block read. -S Addr Wr [A] reg [A]
   S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P


The amount of returned data is set by the device. -

The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_read_block_data(h, 10)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_byte(handle)

-Reads a single byte from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).


SMBus 2.0 5.5.3 - Receive byte. -S Addr Rd [A] [Data] NA P


Example

b = pi.i2c_read_byte(2) # read a byte from device 2

i2c_read_byte_data(handle, reg)

-Reads a single byte from the specified register of the device -associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read byte. -S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P


Example

# read byte from reg 17 of device 2
b = pi.i2c_read_byte_data(2, 17)

# read byte from reg  1 of device 0
b = pi.i2c_read_byte_data(0, 1)

i2c_read_device(handle, count)

-Returns count bytes read from the raw device associated -with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
 count:= >0, the number of bytes to read.


S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.i2c_read_device(h, 12)

i2c_read_i2c_block_data(handle, reg, count)

-Reads count bytes from the specified register of the device -associated with handle . The count may be 1-32. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
 count:= >0, the number of bytes to read.


S Addr Wr [A] reg [A]
   S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.i2c_read_i2c_block_data(h, 4, 32)
if b >= 0:
   # process data
else:
   # process read failure

i2c_read_word_data(handle, reg)

-Reads a single 16 bit word from the specified register of the -device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.


SMBus 2.0 5.5.5 - Read word. -S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P


Example

# read word from reg 2 of device 3
w = pi.i2c_read_word_data(3, 2)

# read word from reg 7 of device 2
w = pi.i2c_read_word_data(2, 7)

i2c_write_block_data(handle, reg, data)

-Writes up to 32 bytes to the specified register of the device -associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


SMBus 2.0 5.5.7 - Block write. -S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A]
   datan [A] P


Example

pi.i2c_write_block_data(4, 5, b'hello')

pi.i2c_write_block_data(4, 5, "data bytes")

pi.i2c_write_block_data(5, 0, b'\x00\x01\x22')

pi.i2c_write_block_data(6, 2, [0, 1, 0x22])

i2c_write_byte(handle, byte_val)

-Sends a single byte to the device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.2 - Send byte. -S Addr Wr [A] byte_val [A] P


Example

pi.i2c_write_byte(1, 17)   # send byte   17 to device 1
pi.i2c_write_byte(2, 0x23) # send byte 0x23 to device 2

i2c_write_byte_data(handle, reg, byte_val)

-Writes a single byte to the specified register of the device -associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
byte_val:= 0-255, the value to write.


SMBus 2.0 5.5.4 - Write byte. -S Addr Wr [A] reg [A] byte_val [A] P


Example

# send byte 0xC5 to reg 2 of device 1
pi.i2c_write_byte_data(1, 2, 0xC5)

# send byte 9 to reg 4 of device 2
pi.i2c_write_byte_data(2, 4, 9)

i2c_write_device(handle, data)

-Writes the data bytes to the raw device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the bytes to write.


S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P


Example

pi.i2c_write_device(h, b"\x12\x34\xA8")

pi.i2c_write_device(h, b"help")

pi.i2c_write_device(h, 'help')

pi.i2c_write_device(h, [23, 56, 231])

i2c_write_i2c_block_data(handle, reg, data)

-Writes data bytes to the specified register of the device -associated with handle . 1-32 bytes may be written. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   reg:= >=0, the device register.
  data:= the bytes to write.


S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P


Example

pi.i2c_write_i2c_block_data(4, 5, 'hello')

pi.i2c_write_i2c_block_data(4, 5, b'hello')

pi.i2c_write_i2c_block_data(5, 0, b'\x00\x01\x22')

pi.i2c_write_i2c_block_data(6, 2, [0, 1, 0x22])

i2c_write_quick(handle, bit)

-Sends a single bit to the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
   bit:= 0 or 1, the value to write.


SMBus 2.0 5.5.1 - Quick command. -S Addr bit [A] P


Example

pi.i2c_write_quick(0, 1) # send 1 to device 0
pi.i2c_write_quick(3, 0) # send 0 to device 3

i2c_write_word_data(handle, reg, word_val)

-Writes a single 16 bit word to the specified register of the -device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to i2c_open).
     reg:= >=0, the device register.
word_val:= 0-65535, the value to write.


SMBus 2.0 5.5.4 - Write word. -S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P


Example

# send word 0xA0C5 to reg 5 of device 4
pi.i2c_write_word_data(4, 5, 0xA0C5)

# send word 2 to reg 2 of device 5
pi.i2c_write_word_data(5, 2, 23)

i2c_zip(handle, data)

-This function executes a sequence of I2C operations. The -operations to be performed are specified by the contents of data -which contains the concatenated command codes and associated data. -

Parameters

handle:= >=0 (as returned by a prior call to i2c_open).
  data:= the concatenated I2C commands, see below


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0])


The following command codes are supported: -

NameCmd & DataMeaning
End0No more commands
Escape1Next P is two bytes
On2Switch combined flag on
Off3Switch combined flag off
Address4 PSet I2C address to P
Flags5 lsb msbSet I2C flags to lsb + (msb << 8)
Read6 PRead P bytes of data
Write7 P ...Write P bytes of data


The address, read, and write commands take a parameter P. -Normally P is one byte (0-255). If the command is preceded by -the Escape command then P is two bytes (0-65535, least significant -byte first). -

The address defaults to that associated with the handle. -The flags default to 0. The address and flags maintain their -previous value until updated. -

Any read I2C data is concatenated in the returned bytearray. -

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

notify_begin(handle, bits)

-Starts notifications on a handle. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)
  bits:= a 32 bit mask indicating the GPIO to be notified.


The notification sends state changes for each GPIO whose -corresponding bit in bits is set. -

The following code starts notifications for GPIO 1, 4, -6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_close(handle)

-Stops notifications on a handle and releases the handle for reuse. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)


Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_close(h)
   ...

notify_open()

-Returns a notification handle (>=0). -

A notification is a method for being notified of GPIO state -changes via a pipe. -

Pipes are only accessible from the local machine so this -function serves no purpose if you are using Python from a -remote machine. The in-built (socket) notifications -provided by
callback should be used instead. -

Notifications for handle x will be available at the pipe -named /dev/pigpiox (where x is the handle number). -

E.g. if the function returns 15 then the notifications must be -read from /dev/pigpio15. -

Notifications have the following structure: -

H seqno
H flags
I tick
I level


seqno: starts at 0 each time the handle is opened and then -increments by one for each report. -

flags: three flags are defined, PI_NTFY_FLAGS_WDOG, -PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. -

If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the -flags indicate a GPIO which has had a watchdog timeout. -

If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep -alive signal on the pipe/socket and is sent once a minute -in the absence of other notification activity. -

If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the -flags indicate an event which has been triggered. -

tick: the number of microseconds since system boot. It wraps -around after 1h12m. -

level: indicates the level of each GPIO. If bit 1<<x is set -then GPIO x is high. -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)

notify_pause(handle)

-Pauses notifications on a handle. -

Parameters

handle:= >=0 (as returned by a prior call to notify_open)


Notifications for the handle are suspended until -notify_begin is called again. -

Example

h = pi.notify_open()
if h >= 0:
   pi.notify_begin(h, 1234)
   ...
   pi.notify_pause(h)
   ...
   pi.notify_begin(h, 1234)
   ...

read(gpio)

-Returns the GPIO level. -

Parameters

gpio:= 0-53.


Example

pi.set_mode(23, pigpio.INPUT)

pi.set_pull_up_down(23, pigpio.PUD_DOWN)
print(pi.read(23))
0

pi.set_pull_up_down(23, pigpio.PUD_UP)
print(pi.read(23))
1

read_bank_1()

-Returns the levels of the bank 1 GPIO (GPIO 0-31). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is high. GPIO n has bit value (1<<n). -

Example

print(bin(pi.read_bank_1()))
0b10010100000011100100001001111

read_bank_2()

-Returns the levels of the bank 2 GPIO (GPIO 32-53). -

The returned 32 bit integer has a bit set if the corresponding -GPIO is high. GPIO n has bit value (1<<(n-32)). -

Example

print(bin(pi.read_bank_2()))
0b1111110000000000000000

run_script(script_id, params)

-Runs a stored script. -

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.run_script(sid, [par1, par2])

s = pi.run_script(sid)

s = pi.run_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

script_status(script_id)

-Returns the run status of a stored script as well as the -current values of parameters 0 to 9. -

Parameters

script_id:= id of stored script.


The run status may be -

PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED


The return value is a tuple of run status and a list of -the 10 parameters. On error the run status will be negative -and the parameter list will be empty. -

Example

(s, pars) = pi.script_status(sid)

serial_close(handle)

-Closes the serial device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


Example

pi.serial_close(h1)

serial_data_available(handle)

-Returns the number of bytes available to be read from the -device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


Example

rdy = pi.serial_data_available(h1)

if rdy > 0:
   (b, d) = pi.serial_read(h1, rdy)

serial_open(tty, baud, ser_flags)

-Returns a handle for the serial tty device opened -at baud bits per second. The device name must start -with /dev/tty or /dev/serial. -

Parameters

      tty:= the serial device to open.
     baud:= baud rate in bits per second, see below.
ser_flags:= 0, no flags are currently defined.


Normally you would only use the serial_* functions if -you are or will be connecting to the Pi over a network. If -you will always run on the local Pi use the standard serial -module instead. -

The baud rate must be one of 50, 75, 110, 134, 150, -200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, -38400, 57600, 115200, or 230400. -

Example

h1 = pi.serial_open("/dev/ttyAMA0", 300)

h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0)

h3 = pi.serial_open("/dev/serial0", 9600)

serial_read(handle, count)

-Reads up to count bytes from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
 count:= >0, the number of bytes to read (defaults to 1000).


The returned value is a tuple of the number of bytes read and -a bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

If no data is ready a bytes read of zero is returned. -Example

(b, d) = pi.serial_read(h2, 100)
if b > 0:
   # process read data

serial_read_byte(handle)

-Returns a single byte from the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).


If no data is ready a negative error code will be returned. -

Example

b = pi.serial_read_byte(h1)

serial_write(handle, data)

-Writes the data bytes to the device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to serial_open).
  data:= the bytes to write.


Example

pi.serial_write(h1, b'\x02\x03\x04')

pi.serial_write(h2, b'help')

pi.serial_write(h2, "hello")

pi.serial_write(h1, [2, 3, 4])

serial_write_byte(handle, byte_val)

-Writes a single byte to the device associated with handle. -

Parameters

  handle:= >=0 (as returned by a prior call to serial_open).
byte_val:= 0-255, the value to write.


Example

pi.serial_write_byte(h1, 23)

pi.serial_write_byte(h1, ord('Z'))

set_PWM_dutycycle(user_gpio, dutycycle)

-Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. -

Parameters

user_gpio:= 0-31.
dutycycle:= 0-range (range defaults to 255).


The set_PWM_range function can change the default range of 255. -

Example

pi.set_PWM_dutycycle(4,   0) # PWM off
pi.set_PWM_dutycycle(4,  64) # PWM 1/4 on
pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on
pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on
pi.set_PWM_dutycycle(4, 255) # PWM full on

set_PWM_frequency(user_gpio, frequency)

-Sets the frequency (in Hz) of the PWM to be used on the GPIO. -

Parameters

user_gpio:= 0-31.
frequency:= >=0 Hz


Returns the numerically closest frequency if OK, otherwise -PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -

If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. -

Each GPIO can be independently set to one of 18 different -PWM frequencies. -

The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the pigpio daemon is started. -

The frequencies for each sample rate are: -

                       Hertz

       1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
           1250  1000   800  500  400  250  200  100   50

       2: 20000 10000  5000 4000 2500 2000 1250 1000  800
            625   500   400  250  200  125  100   50   25

       4: 10000  5000  2500 2000 1250 1000  625  500  400
            313   250   200  125  100   63   50   25   13
sample
 rate
 (us)  5:  8000  4000  2000 1600 1000  800  500  400  320
            250   200   160  100   80   50   40   20   10

       8:  5000  2500  1250 1000  625  500  313  250  200
            156   125   100   63   50   31   25   13    6

      10:  4000  2000  1000  800  500  400  250  200  160
            125   100    80   50   40   25   20   10    5


Example

pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
10

pi.set_PWM_frequency(4,100000)
print(pi.get_PWM_frequency(4))
8000

set_PWM_range(user_gpio, range_)

-Sets the range of PWM values to be used on the GPIO. -

Parameters

user_gpio:= 0-31.
   range_:= 25-40000.


Example

pi.set_PWM_range(9, 100)  # now  25 1/4,   50 1/2,   75 3/4 on
pi.set_PWM_range(9, 500)  # now 125 1/4,  250 1/2,  375 3/4 on
pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on

set_bank_1(bits)

-Sets GPIO 0-31 if the corresponding bit in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.set_bank_1(int("111110010000",2))

set_bank_2(bits)

-Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. -

Parameters

bits:= a 32 bit mask with 1 set if the corresponding GPIO is
       to be set.


A returned status of PI_SOME_PERMITTED indicates that the user -is not allowed to write to one or more of the GPIO. -

Example

pi.set_bank_2(0x303)

set_glitch_filter(user_gpio, steady)

-Sets a glitch filter on a GPIO. -

Level changes on the GPIO are not reported unless the level -has been stable for at least steady microseconds. The -level is then reported. Level changes of less than steady -microseconds are ignored. -

Parameters

user_gpio:= 0-31
   steady:= 0-300000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback and wait_for_edge. -

It does not affect levels read by read, -read_bank_1, or read_bank_2. -

Each (stable) edge will be timestamped steady -microseconds after it was first detected. -

Example

pi.set_glitch_filter(23, 100)

set_mode(gpio, mode)

-Sets the GPIO mode. -

Parameters

gpio:= 0-53.
mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5.


Example

pi.set_mode( 4, pigpio.INPUT)  # GPIO  4 as input
pi.set_mode(17, pigpio.OUTPUT) # GPIO 17 as output
pi.set_mode(24, pigpio.ALT2)   # GPIO 24 as ALT2

set_noise_filter(user_gpio, steady, active)

-Sets a noise filter on a GPIO. -

Level changes on the GPIO are ignored until a level which has -been stable for steady microseconds is detected. Level -changes on the GPIO are then reported for active -microseconds after which the process repeats. -

Parameters

user_gpio:= 0-31
   steady:= 0-300000
   active:= 0-1000000


Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. -

This filter affects the GPIO samples returned to callbacks set up -with callback and wait_for_edge. -

It does not affect levels read by read, -read_bank_1, or read_bank_2. -

Level changes before and after the active period may -be reported. Your software must be designed to cope with -such reports. -

Example

pi.set_noise_filter(23, 1000, 5000)

set_pad_strength(pad, pad_strength)

-This function sets the pad drive strength in mA. -

Parameters

         pad:= 0-2, the pad to set.
pad_strength:= 1-16 mA.


Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. -

PadGPIO
00-27
128-45
246-53


Example

pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA.

set_pull_up_down(gpio, pud)

-Sets or clears the internal GPIO pull-up/down resistor. -

Parameters

gpio:= 0-53.
 pud:= PUD_UP, PUD_DOWN, PUD_OFF.


Example

pi.set_pull_up_down(17, pigpio.PUD_OFF)
pi.set_pull_up_down(23, pigpio.PUD_UP)
pi.set_pull_up_down(24, pigpio.PUD_DOWN)

set_servo_pulsewidth(user_gpio, pulsewidth)

-Starts (500-2500) or stops (0) servo pulses on the GPIO. -

Parameters

 user_gpio:= 0-31.
pulsewidth:= 0 (off),
             500 (most anti-clockwise) - 2500 (most clockwise).


The selected pulsewidth will continue to be transmitted until -changed by a subsequent call to set_servo_pulsewidth. -

The pulsewidths supported by servos varies and should probably -be determined by experiment. A value of 1500 should always be -safe and represents the mid-point of rotation. -

You can DAMAGE a servo if you command it to move beyond its -limits. -

Example

pi.set_servo_pulsewidth(17, 0)    # off
pi.set_servo_pulsewidth(17, 1000) # safe anti-clockwise
pi.set_servo_pulsewidth(17, 1500) # centre
pi.set_servo_pulsewidth(17, 2000) # safe clockwise

set_watchdog(user_gpio, wdog_timeout)

-Sets a watchdog timeout for a GPIO. -

Parameters

   user_gpio:= 0-31.
wdog_timeout:= 0-60000.


The watchdog is nominally in milliseconds. -

Only one watchdog may be registered per GPIO. -

The watchdog may be cancelled by setting timeout to 0. -

Once a watchdog has been started callbacks for the GPIO -will be triggered every timeout interval after the last -GPIO activity. -

The callback will receive the special level TIMEOUT. -

Example

pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23
pi.set_watchdog(23, 0)    # cancel watchdog on GPIO 23

shell(shellscr, pstring)

-This function uses the system call to execute a shell script -with the given string as its parameter. -

Parameters

shellscr:= the name of the script, only alphanumerics,
              '-' and '_' are allowed in the name
pstring := the parameter string to pass to the script


The exit status of the system call is returned if OK, -otherwise PI_BAD_SHELL_STATUS. -

shellscr must exist in /opt/pigpio/cgi and must be executable. -

The returned exit status is normally 256 times that set by -the shell script exit function. If the script can't be -found 32512 will be returned. -

The following table gives some example returned statuses: -

Script exit statusReturned system call status
1256
51280
102560
20051200
script not found32512


Example

// pass two parameters, hello and world
status = pi.shell("scr1", "hello world");

// pass three parameters, hello, string with spaces, and world
status = pi.shell("scr1", "hello 'string with spaces' world");

// pass one parameter, hello string with spaces world
status = pi.shell("scr1", "\"hello string with spaces world\"");

spi_close(handle)

-Closes the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).


Example

pi.spi_close(h)

spi_open(spi_channel, baud, spi_flags)

-Returns a handle for the SPI device on the channel. Data -will be transferred at baud bits per second. The flags -may be used to modify the default behaviour of 4-wire -operation, mode 0, active low chip select. -

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. -

MISOMOSISCLKCE0CE1CE2
Main SPI9101187-
Aux SPI192021181716


Parameters

spi_channel:= 0-1 (0-2 for the auxiliary SPI).
       baud:= 32K-125M (values above 30M are unlikely to work).
  spi_flags:= see below.


spi_flags consists of the least significant 22 bits. -

21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 b  b  b  b  b  b  R  T  n  n  n  n  W  A u2 u1 u0 p2 p1 p0  m  m


mm defines the SPI mode. -

WARNING: modes 1 and 3 do not appear to work on -the auxiliary SPI. -

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 spi_read, spi_write, and spi_xfer functions -transfer data packed into 1, 2, or 4 bytes according to -the word size in bits. -

For bits 1-8 there will be one byte per character. -For bits 9-16 there will be two bytes per character. -For bits 17-32 there will be four bytes per character. -

Multi-byte transfers are made in least significant byte -first order. -

E.g. to transfer 32 11-bit words data should -contain 64 bytes. -

E.g. to transfer the 14 bit value 0x1ABC send the -bytes 0xBC followed by 0x1A. -

The other bits in flags should be set to zero. -

Example

# open SPI device on channel 1 in mode 3 at 50000 bits per second

h = pi.spi_open(1, 50000, 3)

spi_read(handle, count)

-Reads count bytes from the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
 count:= >0, the number of bytes to read.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(b, d) = pi.spi_read(h, 60) # read 60 bytes from device h
if b == 60:
   # process read data
else:
   # error path

spi_write(handle, data)

-Writes the data bytes to the SPI device associated with handle. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


Example

pi.spi_write(0, b'\x02\xc0\x80') # write 3 bytes to device 0

pi.spi_write(0, b'defgh')        # write 5 bytes to device 0

pi.spi_write(0, "def")           # write 3 bytes to device 0

pi.spi_write(1, [2, 192, 128])   # write 3 bytes to device 1

spi_xfer(handle, data)

-Writes the data bytes to the SPI device associated with handle, -returning the data bytes read from the device. -

Parameters

handle:= >=0 (as returned by a prior call to spi_open).
  data:= the bytes to write.


The returned value is a tuple of the number of bytes read and a -bytearray containing the bytes. If there was an error the -number of bytes read will be less than zero (and will contain -the error code). -

Example

(count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00')

(count, rx_data) = pi.spi_xfer(h, [1, 128, 0])

(count, rx_data) = pi.spi_xfer(h, b"hello")

(count, rx_data) = pi.spi_xfer(h, "hello")

stop()

-Release pigpio resources. -

Example

pi.stop()

stop_script(script_id)

-Stops a running script. -

Parameters

script_id:= id of stored script.


Example

status = pi.stop_script(sid)

store_script(script)

-Store a script for later execution. -

See http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts for -details. -

Parameters

script:= the script text as a series of bytes.


Returns a >=0 script id if OK. -

Example

sid = pi.store_script(
   b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0')

update_script(script_id, params)

-Sets the parameters of a script. The script may or -may not be running. The first parameters of the script are -overwritten with the new values. -

Parameters

script_id:= id of stored script.
   params:= up to 10 parameters required by the script.


Example

s = pi.update_script(sid, [par1, par2])

s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

wait_for_edge(user_gpio, edge, wait_timeout)

-Wait for an edge event on a GPIO. -

Parameters

   user_gpio:= 0-31.
        edge:= EITHER_EDGE, RISING_EDGE (default), or
               FALLING_EDGE.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the edge is detected or after -the number of seconds specified by timeout has expired. -

Do not use this function for precise timing purposes, -the edge is only checked 20 times a second. Whenever -you need to know the accurate time of GPIO events use -a callback function. -

The function returns True if the edge is detected, -otherwise False. -

Example

if pi.wait_for_edge(23):
   print("Rising edge detected")
else:
   print("wait for edge timed out")

if pi.wait_for_edge(23, pigpio.FALLING_EDGE, 5.0):
   print("Falling edge detected")
else:
   print("wait for falling edge timed out")

wait_for_event(event, wait_timeout)

-Wait for an event. -

Parameters

       event:= 0-31.
wait_timeout:= >=0.0 (default 60.0).


The function returns when the event is signalled or after -the number of seconds specified by timeout has expired. -

The function returns True if the event is detected, -otherwise False. -

Example

if pi.wait_for_event(23):
   print("event detected")
else:
   print("wait for event timed out")

wave_add_generic(pulses)

-Adds a list of pulses to the current waveform. -

Parameters

pulses:= list of pulses to add to the waveform.


Returns the new total number of pulses in the current waveform. -

The pulses are interleaved in time order within the existing -waveform (if any). -

Merging allows the waveform to be built in parts, that is the -settings for GPIO#1 can be added, and then GPIO#2 etc. -

If the added waveform is intended to start after or within -the existing waveform then the first pulse should consist -solely of a delay. -

Example

G1=4
G2=24

pi.set_mode(G1, pigpio.OUTPUT)
pi.set_mode(G2, pigpio.OUTPUT)

flash_500=[] # flash every 500 ms
flash_100=[] # flash every 100 ms

#                              ON     OFF  DELAY

flash_500.append(pigpio.pulse(1<<G1, 1<<G2, 500000))
flash_500.append(pigpio.pulse(1<<G2, 1<<G1, 500000))

flash_100.append(pigpio.pulse(1<<G1, 1<<G2, 100000))
flash_100.append(pigpio.pulse(1<<G2, 1<<G1, 100000))

pi.wave_clear() # clear any existing waveforms

pi.wave_add_generic(flash_500) # 500 ms flashes
f500 = pi.wave_create() # create and save id

pi.wave_add_generic(flash_100) # 100 ms flashes
f100 = pi.wave_create() # create and save id

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_send_repeat(f100)

time.sleep(4)

pi.wave_send_repeat(f500)

time.sleep(4)

pi.wave_tx_stop() # stop waveform

pi.wave_clear() # clear all waveforms

wave_add_new()

-Starts a new empty waveform. -

You would not normally need to call this function as it is -automatically called after a waveform is created with the -
wave_create function. -

Example

pi.wave_add_new()

wave_add_serial(user_gpio, baud, data, offset, bb_bits, bb_stop)

-Adds a waveform representing serial data to the existing -waveform (if any). The serial data starts offset -microseconds from the start of the waveform. -

Parameters

user_gpio:= GPIO to transmit data.  You must set the GPIO mode
            to output.
     baud:= 50-1000000 bits per second.
     data:= the bytes to write.
   offset:= number of microseconds from the start of the
            waveform, default 0.
  bb_bits:= number of data bits, default 8.
  bb_stop:= number of stop half bits, default 2.


Returns the new total number of pulses in the current waveform. -

The serial data is formatted as one start bit, bb_bits -data bits, and bb_stop/2 stop bits. -

It is legal to add serial data streams with different baud -rates to the same waveform. -

The bytes required for each character depend upon bb_bits. -

For bb_bits 1-8 there will be one byte per character. -For bb_bits 9-16 there will be two bytes per character. -For bb_bits 17-32 there will be four bytes per character. -

Example

pi.wave_add_serial(4, 300, 'Hello world')

pi.wave_add_serial(4, 300, b"Hello world")

pi.wave_add_serial(4, 300, b'\x23\x01\x00\x45')

pi.wave_add_serial(17, 38400, [23, 128, 234], 5000)

wave_chain(data)

-This function transmits a chain of waveforms. -

NOTE: Any hardware PWM started by hardware_PWM -will be cancelled. -

The waves to be transmitted are specified by the contents -of data which contains an ordered list of wave_ids -and optional command codes and related data. -

Returns 0 if OK, otherwise PI_CHAIN_NESTING, -PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, -PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, -or PI_BAD_WAVE_ID. -

Each wave is transmitted in the order specified. A wave -may occur multiple times per chain. -

A blocks of waves may be transmitted multiple times by -using the loop commands. The block is bracketed by loop -start and end commands. Loops may be nested. -

Delays between waves may be added with the delay command. -

The following command codes are supported: -

NameCmd & DataMeaning
Loop Start255 0Identify start of a wave block
Loop Repeat255 1 x yloop x + y*256 times
Delay255 2 x ydelay x + y*256 microseconds
Loop Forever255 3loop 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

#!/usr/bin/env python

import time
import pigpio

WAVES=5
GPIO=4

wid=[0]*WAVES

pi = pigpio.pi() # Connect to local Pi.

pi.set_mode(GPIO, pigpio.OUTPUT);

for i in range(WAVES):
   pi.wave_add_generic([
      pigpio.pulse(1<<GPIO, 0, 20),
      pigpio.pulse(0, 1<<GPIO, (i+1)*200)]);

   wid[i] = pi.wave_create();

pi.wave_chain([
   wid[4], wid[3], wid[2],       # transmit waves 4+3+2
   255, 0,                       # loop start
      wid[0], wid[0], wid[0],    # transmit waves 0+0+0
      255, 0,                    # loop start
         wid[0], wid[1],         # transmit waves 0+1
         255, 2, 0x88, 0x13,     # delay 5000us
      255, 1, 30, 0,             # loop end (repeat 30 times)
      255, 0,                    # loop start
         wid[2], wid[3], wid[0], # transmit waves 2+3+0
         wid[3], wid[1], wid[2], # transmit waves 3+1+2
      255, 1, 10, 0,             # loop end (repeat 10 times)
   255, 1, 5, 0,                 # loop end (repeat 5 times)
   wid[4], wid[4], wid[4],       # transmit waves 4+4+4
   255, 2, 0x20, 0x4E,           # delay 20000us
   wid[0], wid[0], wid[0],       # transmit waves 0+0+0
   ])

while pi.wave_tx_busy():
   time.sleep(0.1);

for i in range(WAVES):
   pi.wave_delete(wid[i])

pi.stop()

wave_clear()

-Clears all waveforms and any data added by calls to the -wave_add_* functions. -

Example

pi.wave_clear()

wave_create()

-Creates a waveform from the data provided by the prior calls -to the wave_add_* functions. -

Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM, -PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

The data provided by the wave_add_* functions is consumed by -this function. -

As many waveforms may be created as there is space available. -The wave id is passed to wave_send_* to specify the waveform -to transmit. -

Normal usage would be -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create to create the waveform and get a unique id -

Repeat steps 2 and 3 as needed. -

Step 4. wave_send_* with the id of the waveform to transmit. -

A waveform comprises one or more pulses. -

A pulse specifies -

1) the GPIO to be switched on at the start of the pulse. -2) the GPIO to be switched off at the start of the pulse. -3) the delay in microseconds before the next pulse. -

Any or all the fields can be zero. It doesn't make any sense -to set all the fields to zero (the pulse will be ignored). -

When a waveform is started each pulse is executed in order with -the specified delay between the pulse and the next. -

Example

wid = pi.wave_create()

wave_create_and_pad(percent)

-This function creates a waveform like wave_create but pads the consumed -resources. Where percent gives the percentage of the resources to use -(in terms of the theoretical maximum, not the current amount free). -This allows the reuse of deleted waves while a transmission is active. -

Upon success a wave id greater than or equal to 0 is returned, otherwise -PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. -

percent: 0-100, size of waveform as percentage of maximum available.


The data provided by the wave_add_* functions are consumed by this -function. -

As many waveforms may be created as there is space available. The -wave id is passed to wave_send_* to specify the waveform to transmit. -

A usage would be the creation of two waves where one is filled while the -other is being transmitted. Each wave is assigned 50% of the resources. -This buffer structure allows the transmission of infinite wave sequences. -

Normal usage: -

Step 1. wave_clear to clear all waveforms and added data. -

Step 2. wave_add_* calls to supply the waveform data. -

Step 3. wave_create_and_pad to create a waveform of uniform size. -

Step 4. wave_send_* with the id of the waveform to transmit. -

Repeat steps 2-4 as needed. -

Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. -

Example

wid = pi.wave_create_and_pad(50)

wave_delete(wave_id)

-This function deletes the waveform with id wave_id. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Wave ids are allocated in order, 0, 1, 2, etc. -

The wave is flagged for deletion. The resources used by the wave -will only be reused when either of the following apply. -

- all waves with higher numbered wave ids have been deleted or have -been flagged for deletion. -

- a new wave is created which uses exactly the same resources as -the current wave (see the C source for gpioWaveCreate for details). -

Example

pi.wave_delete(6) # delete waveform with id 6

pi.wave_delete(0) # delete waveform with id 0

wave_get_cbs()

-Returns the length in DMA control blocks of the current -waveform. -

Example

cbs = pi.wave_get_cbs()

wave_get_max_cbs()

-Returns the maximum possible size of a waveform in DMA -control blocks. -

Example

cbs = pi.wave_get_max_cbs()

wave_get_max_micros()

-Returns the maximum possible size of a waveform in microseconds. -

Example

micros = pi.wave_get_max_micros()

wave_get_max_pulses()

-Returns the maximum possible size of a waveform in pulses. -

Example

pulses = pi.wave_get_max_pulses()

wave_get_micros()

-Returns the length in microseconds of the current waveform. -

Example

micros = pi.wave_get_micros()

wave_get_pulses()

-Returns the length in pulses of the current waveform. -

Example

pulses = pi.wave_get_pulses()

wave_send_once(wave_id)

-Transmits the waveform with id wave_id. The waveform is sent -once. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_once(wid)

wave_send_repeat(wave_id)

-Transmits the waveform with id wave_id. The waveform repeats -until wave_tx_stop is called or another call to wave_send_* -is made. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_repeat(wid)

wave_send_using_mode(wave_id, mode)

-Transmits the waveform with id wave_id using mode mode. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).
   mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT,
          WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC.


WAVE_MODE_ONE_SHOT: same as wave_send_once. -

WAVE_MODE_REPEAT same as wave_send_repeat. -

WAVE_MODE_ONE_SHOT_SYNC same as wave_send_once but tries -to sync with the previous waveform. -

WAVE_MODE_REPEAT_SYNC same as wave_send_repeat but tries -to sync with the previous waveform. -

WARNING: bad things may happen if you delete the previous -waveform before it has been synced to the new waveform. -

NOTE: Any hardware PWM started by hardware_PWM will -be cancelled. -

Parameters

wave_id:= >=0 (as returned by a prior call to wave_create).


Returns the number of DMA control blocks used in the waveform. -

Example

cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC)

wave_tx_at()

-Returns the id of the waveform currently being -transmitted. -

Returns the waveform id or one of the following special -values: -

WAVE_NOT_FOUND (9998) - transmitted wave not found. -NO_TX_WAVE (9999) - no wave being transmitted. -

Example

wid = pi.wave_tx_at()

wave_tx_busy()

-Returns 1 if a waveform is currently being transmitted, -otherwise 0. -

Example

pi.wave_send_once(0) # send first waveform

while pi.wave_tx_busy(): # wait for waveform to be sent
   time.sleep(0.1)

pi.wave_send_once(1) # send next waveform

wave_tx_repeat()

-This function is deprecated and has beeen removed. -

Use
wave_create/wave_send_* instead. -

wave_tx_start()

-This function is deprecated and has been removed. -

Use
wave_create/wave_send_* instead. -

wave_tx_stop()

-Stops the transmission of the current waveform. -

This function is intended to stop a waveform started with -wave_send_repeat. -

Example

pi.wave_send_repeat(3)

time.sleep(5)

pi.wave_tx_stop()

write(gpio, level)

-Sets the GPIO level. -

Parameters

 GPIO:= 0-53.
level:= 0, 1.


If PWM or servo pulses are active on the GPIO they are -switched off. -

Example

pi.set_mode(17, pigpio.OUTPUT)

pi.write(17,0)
print(pi.read(17))
0

pi.write(17,1)
print(pi.read(17))
1

class pulse -

pigpio.pulse(gpio_on, gpio_off, delay)

-Initialises a pulse. -

Parameters

 gpio_on:= the GPIO to switch on at the start of the pulse.
gpio_off:= the GPIO to switch off at the start of the pulse.
   delay:= the delay in microseconds before the next pulse.

FUNCTIONS

pigpio.error_text(errnum)

-Returns a text description of a pigpio error. -

Parameters

errnum:= <0, the error number


Example

print(pigpio.error_text(-5))
level not 0-1

pigpio.tickDiff(t1, t2)

-Returns the microsecond difference between two ticks. -

Parameters

t1:= the earlier tick
t2:= the later tick


Example

print(pigpio.tickDiff(4294967272, 12))
36

pigpio.u2i(uint32)

-Converts a 32 bit unsigned number to signed. -

Parameters

uint32:= an unsigned 32 bit number


Example

print(u2i(4294967272))
-24
print(u2i(37))
37

PARAMETERS

active: 0-1000000

The number of microseconds level changes are reported for once -a noise filter has been triggered (by steady microseconds of -a stable level). -

arg1:

An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

arg2:

An unsigned argument passed to a user customised function. Its -meaning is defined by the customiser. -

argx:

An array of bytes passed to a user customised function. -Its meaning and content is defined by the customiser. -

baud:

The speed of serial communication (I2C, SPI, serial link, waves) -in bits per second. -

bb_bits: 1-32

The number of data bits to be used when adding serial data to a -waveform. -

bb_stop: 2-8

The number of (half) stop bits to be used when adding serial data -to a waveform. -

bit: 0-1

A value of 0 or 1. -

bits: 32 bit number

A mask used to select GPIO to be operated on. If bit n is set -then GPIO n is selected. A convenient way of setting bit n is to -bit or in the value (1<<n). -

To select GPIO 1, 7, 23 -

bits = (1<<1) | (1<<7) | (1<<23) -

bsc_control:

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) -

Bits 0-13 are copied unchanged to the BSC CR register. See -pages 163-165 of the Broadcom peripherals document. -

byte_val: 0-255

A whole number. -

clkfreq: 4689-250M (13184-375M for the BCM2711)

The hardware clock frequency. -

connected:

True if a connection was established, False otherwise. -

count:

The number of bytes of data to be transferred. -

CS:

The GPIO used for the slave select signal when bit banging SPI. -

data:

Data to be transmitted, a series of bytes. -

delay: >=1

The length of a pulse in microseconds. -

dutycycle: 0-range_

A number between 0 and range_. -

The dutycycle sets the proportion of time on versus time off during each -PWM cycle. -

DutycycleOn time
0Off
range_ * 0.2525% On
range_ * 0.5050% On
range_ * 0.7575% On
range_Fully On

edge: 0-2

EITHER_EDGE = 2
FALLING_EDGE = 1
RISING_EDGE = 0

errnum: <0

PI_BAD_USER_GPIO = -2
PI_BAD_GPIO = -3
PI_BAD_MODE = -4
PI_BAD_LEVEL = -5
PI_BAD_PUD = -6
PI_BAD_PULSEWIDTH = -7
PI_BAD_DUTYCYCLE = -8
PI_BAD_WDOG_TIMEOUT = -15
PI_BAD_DUTYRANGE = -21
PI_NO_HANDLE = -24
PI_BAD_HANDLE = -25
PI_BAD_WAVE_BAUD = -35
PI_TOO_MANY_PULSES = -36
PI_TOO_MANY_CHARS = -37
PI_NOT_SERIAL_GPIO = -38
PI_NOT_PERMITTED = -41
PI_SOME_PERMITTED = -42
PI_BAD_WVSC_COMMND = -43
PI_BAD_WVSM_COMMND = -44
PI_BAD_WVSP_COMMND = -45
PI_BAD_PULSELEN = -46
PI_BAD_SCRIPT = -47
PI_BAD_SCRIPT_ID = -48
PI_BAD_SER_OFFSET = -49
PI_GPIO_IN_USE = -50
PI_BAD_SERIAL_COUNT = -51
PI_BAD_PARAM_NUM = -52
PI_DUP_TAG = -53
PI_TOO_MANY_TAGS = -54
PI_BAD_SCRIPT_CMD = -55
PI_BAD_VAR_NUM = -56
PI_NO_SCRIPT_ROOM = -57
PI_NO_MEMORY = -58
PI_SOCK_READ_FAILED = -59
PI_SOCK_WRIT_FAILED = -60
PI_TOO_MANY_PARAM = -61
PI_SCRIPT_NOT_READY = -62
PI_BAD_TAG = -63
PI_BAD_MICS_DELAY = -64
PI_BAD_MILS_DELAY = -65
PI_BAD_WAVE_ID = -66
PI_TOO_MANY_CBS = -67
PI_TOO_MANY_OOL = -68
PI_EMPTY_WAVEFORM = -69
PI_NO_WAVEFORM_ID = -70
PI_I2C_OPEN_FAILED = -71
PI_SER_OPEN_FAILED = -72
PI_SPI_OPEN_FAILED = -73
PI_BAD_I2C_BUS = -74
PI_BAD_I2C_ADDR = -75
PI_BAD_SPI_CHANNEL = -76
PI_BAD_FLAGS = -77
PI_BAD_SPI_SPEED = -78
PI_BAD_SER_DEVICE = -79
PI_BAD_SER_SPEED = -80
PI_BAD_PARAM = -81
PI_I2C_WRITE_FAILED = -82
PI_I2C_READ_FAILED = -83
PI_BAD_SPI_COUNT = -84
PI_SER_WRITE_FAILED = -85
PI_SER_READ_FAILED = -86
PI_SER_READ_NO_DATA = -87
PI_UNKNOWN_COMMAND = -88
PI_SPI_XFER_FAILED = -89
PI_NO_AUX_SPI = -91
PI_NOT_PWM_GPIO = -92
PI_NOT_SERVO_GPIO = -93
PI_NOT_HCLK_GPIO = -94
PI_NOT_HPWM_GPIO = -95
PI_BAD_HPWM_FREQ = -96
PI_BAD_HPWM_DUTY = -97
PI_BAD_HCLK_FREQ = -98
PI_BAD_HCLK_PASS = -99
PI_HPWM_ILLEGAL = -100
PI_BAD_DATABITS = -101
PI_BAD_STOPBITS = -102
PI_MSG_TOOBIG = -103
PI_BAD_MALLOC_MODE = -104
PI_BAD_SMBUS_CMD = -107
PI_NOT_I2C_GPIO = -108
PI_BAD_I2C_WLEN = -109
PI_BAD_I2C_RLEN = -110
PI_BAD_I2C_CMD = -111
PI_BAD_I2C_BAUD = -112
PI_CHAIN_LOOP_CNT = -113
PI_BAD_CHAIN_LOOP = -114
PI_CHAIN_COUNTER = -115
PI_BAD_CHAIN_CMD = -116
PI_BAD_CHAIN_DELAY = -117
PI_CHAIN_NESTING = -118
PI_CHAIN_TOO_BIG = -119
PI_DEPRECATED = -120
PI_BAD_SER_INVERT = -121
PI_BAD_FOREVER = -124
PI_BAD_FILTER = -125
PI_BAD_PAD = -126
PI_BAD_STRENGTH = -127
PI_FIL_OPEN_FAILED = -128
PI_BAD_FILE_MODE = -129
PI_BAD_FILE_FLAG = -130
PI_BAD_FILE_READ = -131
PI_BAD_FILE_WRITE = -132
PI_FILE_NOT_ROPEN = -133
PI_FILE_NOT_WOPEN = -134
PI_BAD_FILE_SEEK = -135
PI_NO_FILE_MATCH = -136
PI_NO_FILE_ACCESS = -137
PI_FILE_IS_A_DIR = -138
PI_BAD_SHELL_STATUS = -139
PI_BAD_SCRIPT_NAME = -140
PI_BAD_SPI_BAUD = -141
PI_NOT_SPI_GPIO = -142
PI_BAD_EVENT_ID = -143
PI_CMD_INTERRUPTED = -144
PI_NOT_ON_BCM2711   = -145
PI_ONLY_ON_BCM2711  = -146

event: 0-31

An event is a signal used to inform one or more consumers -to start an action. -

file_mode:

The mode may have the following values -

FILE_READ   1
FILE_WRITE  2
FILE_RW     3


The following values can be or'd into the file open mode -

FILE_APPEND 4
FILE_CREATE 8
FILE_TRUNC  16

file_name:

A full file path. To be accessible the path must match -an entry in /opt/pigpio/access. -

fpattern:

A file path which may contain wildcards. To be accessible the path -must match an entry in /opt/pigpio/access. -

frequency: 0-40000

Defines the frequency to be used for PWM on a GPIO. -The closest permitted frequency will be used. -

func:

A user supplied callback function. -

gpio: 0-53

A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. -

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 get_hardware_revision. -

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  -  -  -  -

gpio_off:

A mask used to select GPIO to be operated on. See bits. -

This mask selects the GPIO to be switched off at the start -of a pulse. -

gpio_on:

A mask used to select GPIO to be operated on. See bits. -

This mask selects the GPIO to be switched on at the start -of a pulse. -

handle: >=0

A number referencing an object opened by one of the following -

file_open -i2c_open -notify_open -serial_open -spi_open -

host:

The name or IP address of the Pi running the pigpio daemon. -

i2c_address: 0-0x7F

The address of a device on the I2C bus. -

i2c_bus: >=0

An I2C bus number. -

i2c_flags: 0

No I2C flags are currently defined. -

invert: 0-1

A flag used to set normal or inverted bit bang serial data -level logic. -

level: 0-1 (2)

CLEAR = 0
HIGH = 1
LOW = 0
OFF = 0
ON = 1
SET = 1
TIMEOUT = 2 # only returned for a watchdog timeout

MISO:

The GPIO used for the MISO signal when bit banging SPI. -

mode:

1.The operational mode of a GPIO, normally INPUT or OUTPUT. -

ALT0 = 4
ALT1 = 5
ALT2 = 6
ALT3 = 7
ALT4 = 3
ALT5 = 2
INPUT = 0
OUTPUT = 1


2. The mode of waveform transmission. -

WAVE_MODE_ONE_SHOT = 0
WAVE_MODE_REPEAT = 1
WAVE_MODE_ONE_SHOT_SYNC = 2
WAVE_MODE_REPEAT_SYNC = 3

MOSI:

The GPIO used for the MOSI signal when bit banging SPI. -

offset: >=0

The offset wave data starts from the beginning of the waveform -being currently defined. -

pad: 0-2

A set of GPIO which share common drivers. -

PadGPIO
00-27
128-45
246-53

pad_strength: 1-16

The mA which may be drawn from each GPIO whilst still guaranteeing the -high and low levels. -

params: 32 bit number

When scripts are started they can receive up to 10 parameters -to define their operation. -

percent: : 0-100

The size of waveform as percentage of maximum available. -

port:

The port used by the pigpio daemon, defaults to 8888. -

pstring:

The string to be passed to a shell script to be executed. -

pud: 0-2

PUD_DOWN = 1
PUD_OFF = 0
PUD_UP = 2

pulse_len: 1-100

The length of the trigger pulse in microseconds. -

pulses:

A list of class pulse objects defining the characteristics of a -waveform. -

pulsewidth:

The servo pulsewidth in microseconds. 0 switches pulses off. -

PWMduty: 0-1000000 (1M)

The hardware PWM dutycycle. -

PWMfreq: 1-125M (1-187.5M for the BCM2711)

The hardware PWM frequency. -

range_: 25-40000

Defines the limits for the dutycycle parameter. -

range_ defaults to 255. -

reg: 0-255

An I2C device register. The usable registers depend on the -actual device. -

retMax: >=0

The maximum number of bytes a user customised function -should return, default 8192. -

SCL:

The user GPIO to use for the clock when bit banging I2C. -

SCLK: :

The GPIO used for the SCLK signal when bit banging SPI. -

script:

The text of a script to store on the pigpio daemon. -

script_id: >=0

A number referencing a script created by store_script. -

SDA:

The user GPIO to use for data when bit banging I2C. -

seek_from: 0-2

Direction to seek for file_seek. -

FROM_START=0
FROM_CURRENT=1
FROM_END=2

seek_offset:

The number of bytes to move forward (positive) or backwards -(negative) from the seek position (start, current, or end of file). -

ser_flags: 32 bit

No serial flags are currently defined. -

serial_*:

One of the serial_ functions. -

shellscr:

The name of a shell script. The script must exist -in /opt/pigpio/cgi and must be executable. -

show_errors:

Controls the display of pigpio daemon connection failures. -The default of True prints the probable failure reasons to -standard output. -

spi_channel: 0-2

A SPI channel. -

spi_flags: 32 bit

See spi_open. -

steady: 0-300000

The number of microseconds level changes must be stable for -before reporting the level changed (set_glitch_filter) -or triggering the active part of a noise filter -(set_noise_filter). -

t1:

A tick (earlier). -

t2:

A tick (later). -

tty:

A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0 -

uint32:

An unsigned 32 bit number. -

user_gpio: 0-31

A Broadcom numbered GPIO. -

All the user GPIO are in the range 0-31. -

Not all the GPIO within this range are usable, some are reserved -for system use. -

See gpio. -

wait_timeout: 0.0 -

The number of seconds to wait in wait_for_edge before timing out. -

wave_add_*:

One of the following -

wave_add_new -wave_add_generic -wave_add_serial -

wave_id: >=0

A number referencing a wave created by wave_create. -

wave_send_*:

One of the following -

wave_send_once -wave_send_repeat -

wdog_timeout: 0-60000

Defines a GPIO watchdog timeout in milliseconds. If no level -change is detected on the GPIO for timeout millisecond a watchdog -timeout report is issued (with level TIMEOUT). -

word_val: 0-65535

A whole number. -

\ No newline at end of file diff --git a/DOC/tmp/body/sif.body b/DOC/tmp/body/sif.body deleted file mode 100644 index 1274ee9..0000000 --- a/DOC/tmp/body/sif.body +++ /dev/null @@ -1,1994 +0,0 @@ - -pigpio provides a socket interface to many of its functions.
-
-The socket interface is available whenever pigpio is running, -either because it has been started as a daemon, or it has been -linked in to a running user program.
-
-The socket interface can be disabled by the program which -initialises the library.  pigpiod offers the -k option to -disable the socket interface.  User programs should call -gpioCfgInterfaces if they -wish to disable the socket interface.
-
-pigpio listens for connections on port 8888 by default.  This -default may be overridden when pigpio starts by the gpioCfgSocketPort function -call.  The pigpio daemon uses this function to provide an -option to change the port number.
-
-The pigs utility is an example of using the socket interface from -C.
-

Request

-

pigpio expects messages of type cmdCmd_t immediately followed with an -extension for a few commands.
-
-The caller should fill in cmd, p1, p2, p3/res, and any extension as -needed.  p3 will always be zero unless the command requires an -extension in which case p3 will be the length in bytes of the -extension.
-
-The cmdCmd_t is echoed back with -the result, if any, in p3/res, and an extension immediately -afterwards for a few commands.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
COMMANDcmd
p1p2p3Extension
MODES0gpiomode0-
MODEG1gpio00-
PUD2gpiopud0-
READ3gpio00-
WRITE4gpiolevel0-
PWM5gpiodutycycle0-
PRS6gpiorange0-
PFS7gpiofrequency0-
SERVO8gpiopulsewidth0-
WDOG9gpiotimeout0-
BR110000-
BR211000-
BC112bits00-
BC213bits00-
BS114bits00-
BS215bits00-
TICK16000-
HWVER17000-
NO18000-
NB19handlebits0-
NP20handle00-
NC21handle00-
PRG22gpio00-
PFG23gpio00-
PRRG24gpio00-
HELP
25N/A
N/A
N/A
N/A
PIGPV26000-
WVCLR27000-
WVAG280012*XgpioPulse_t pulse[X]
WVAS29gpiobaud12+Xuint32_t databits
-uint32_t stophalfbits
-uint32_t offset
-uint8_t data[X]
N/A
30000-
N/A
31000-
WVBSY32000-
WVHLT33000-
WVSM34subcmd00-
WVSP35subcmd00-
WVSC36subcmd00-
TRIG37gpiopulselen4uint32_t level
PROC3800Xuint8_t text[X]
PROCD39script_id00-
PROCR40script_id04*X
uint32_t pars[X]
PROCS41script_id00-
SLRO42gpiobaud4uint32_t databits
SLR43gpiocount0-
SLRC44gpio00-
PROCP45script_id00-
MICS46micros00-
MILS47millis00-
PARSE48N/AN/A
N/A
N/A
WVCRE49000-
WVDEL50wave_id00-
WVTX51wave_id00-
WVTXR52wave_id00-
WVNEW53000-
I2CO54busdevice4uint32_t flags
I2CC55handle00-
I2CRD56handlecount0-
I2CWD57handle0Xuint8_t data[X]
I2CWQ58handlebit0-
I2CRS59handle00-
I2CWS60handlebyte0-
I2CRB61handleregister0-
I2CWB62handleregister4uint32_t byte
I2CRW63handleregister0-
I2CWW64handleregister4uint32_t word
I2CRK65handleregister
0-
I2CWK66handleregister
Xuint8_t bvs[X]
I2CRI67handleregister
4uint32_t num
I2CWI68handleregister
X
uint8_t bvs[X]
I2CPC69handleregister
4uint32_t word
I2CPK70handleregister
X
uint8_t data[X]
SPIO
71channelbaud4uint32_t flags
SPIC72handle00-
SPIR73handlecount0-
SPIW74handle0Xuint8_t data[X]
SPIX75handle0Xuint8_t data[X]
SERO76baudflagsXuint8_t device[X]
SERC77handle00-
SERRB78handle00-
SERWB79handlebyte0-
SERR80handlecount0-
SERW81handle0Xuint8_t data[X]
SERDA82handle00-
GDC
83
gpio
0
0
-
GPW
84
gpio
0
0
-
HC
85
gpio
frequency
0
-
HP
86
gpio
frequency
4
uint32_t dutycycle
CF1
87
arg1
arg2
X
uint8_t argx[X]
CF2
88
arg1
retMax
X
uint8_t argx[X]
BI2CC
89
sda
0
0
-
BI2CO
90
sda
scl
4
uint32_t baud
BI2CZ
91
sda
0
X
uint8_t data[X]
I2CZ
92
handle
0
X
uint8_t data[X]
WVCHA
93
0
0
X
uint8_t data[X]
SLRI
94
gpio
invert
0
-
CGI
95
0
0
0
-
CSI
96
config
0
0
-
FG
97
gpio
steady
0
-
FN
98
gpio
steady
4
uint32_t active
NOIB99000-
WVTXM
100
wave_id
mode
0
-
WVTAT
101
0
0
0
-
PADS
102
pad
strength
0
-
PADG
103
pad
0
0
-
FO
104
mode
0
X
uint8_t file[X]
FC
105
handle
0
0
-
FR
106
handle
count
0
-
FW
107
handle
0
X
uint8_t data[X]
FS
108
handle
offset
4
uint32_t from
FL
109
count
0
X
uint8_t pattern[X]
SHELL
110
len(name)
0
len(name)+
-1+
-len(string)
uint8_t name[len(name)]
-uint8_t null (0)
-uint8_t string[len(string)]
BSPIC
111
CS
0
0
-
BSPIO
112
CS
0
20
uint32_t MISO
-uint32_t MOSI
-uint32_t SCLK
-uint32_t baud
-uint32_t spi_flags
BSPIX
113
CS
0
X
uint8_t data[X]
BSCX
114
control
0
X
uint8_t data[X]
EVM
115
handle
bits
0
-
EVT
116
event
0
0
-
PROCU
117
script_id
0
4*X
uint32_t pars[X]
-

Response

-

The response has cmd/p1/p2 as in the request.  p3/res holds -the return value.  If the command returns additional values -they will be in the immediately following extension.

-Normally res should be treated as a 32 bit signed value and will be -greater than or equal to zero.  Upon failure res will be less -than 0 and contains an error code.
-

There are a few commands where the returned value should be -treated as a 32 bit unsigned value.  These commands can not -fail.  They are indicated with a * after the command -name.

-

Commands with an extension have the size of the extension in -bytes returned in res (or <0 on error as above).

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
COMMANDcmd
p1
p2
res
Extension
MODES0-
-
0-
MODEG1-
-
mode
-
PUD2-
-
0-
READ3-
-
level
-
WRITE4-
-
0-
PWM5-
-
0-
PRS6-
-
0-
PFS7-
-
0-
SERVO8-
-
0-
WDOG9-
-
0-
BR1 *10-
-
bits
-
BR2 *11-
-
bits
-
BC112-
-
0-
BC213-
-
0-
BS114-
-
0-
BS215-
-
0-
TICK *
16-
-
tick
-
HWVER *
17-
-
version
-
NO18-
-
handle
-
NB19-
-
0-
NP20-
-
0-
NC21-
-
0-
PRG22-
-
range
-
PFG23-
-
frequency
-
PRRG24-
-
real range
-
HELP25-
-
N/A
N/A
PIGPV *
26-
-
version
-
WVCLR27-
-
0-
WVAG28-
-
wave pulses
-
WVAS29-
-
wave pulses
-
N/A
30-
-
-
-
N/A
31-
-
-
-
WVBSY32-
-
busy (1) or not busy (0)
-
WVHLT33-
-
0-
WVSM34-
-
wave micros
-wave micros - high
-wave micros - max
-
WVSP35-
-
wave pulses
-wave pulses - high
-wave pulses - max
-
WVSC36-
-
wave DMA CBs
-wave DMA CBs - high
-wave DMA CBs - max
-
TRIG37-
-
0
-
PROC38-
-
script id
-
PROCD39-
-
0-
PROCR40-
-
script status
-
PROCS41-
-
0-
SLRO42-
-
0
-
SLR43-
-
X
uint8_t data[X]
SLRC44-
-
0-
PROCP45-
-
44uint32_t script_status
-uint32_t pars[10]
MICS46-
-
0-
MILS47-
-
0-
PARSE48-
-
N/A
-
WVCRE49-
-
wave id
-
WVDEL50-
-
0-
WVTX51-
-
wave DMA CBs
-
WVTXR52-
-
wave DMA CBs
-
WVNEW53-
-
0-
I2CO54-
-
handle-
I2CC55-
-
0-
I2CRD56-
-
X
uint8_t data[X]
I2CWD57-
-
0
-
I2CWQ58-
-
0-
I2CRS59-
-
byte value
-
I2CWS60-
-
0-
I2CRB61-
-
byte value
-
I2CWB62-
-
0
-
I2CRW63-
-
word value
-
I2CWW64-
-
0
-
I2CRK65-
-
0-
I2CWK66-
-
0
-
I2CRI67-
-
X
uint8_t data[X]
I2CWI68-
-
0
-
I2CPC69-
-
word value
-
I2CPK70-
-
X
uint8_t data[X]
SPIO
71-
-
handle
-
SPIC72-
-
0-
SPIR73-
-
X
uint8_t data[X]
SPIW74-
-
0
-
SPIX75-
-
Xuint8_t data[X]
SERO76-
-
handle
-
SERC77-
-
0-
SERRB78-
-
byte value
-
SERWB79-
-
0-
SERR80-
-
X
uint8_t data[X]
SERW81-
-
0
-
SERDA82-
-
data ready count
-
GDC
83
-
-
dutycycle
-
GPW
84
-
-
pulsewidth
-
HC
85
-
-
0
-
HP
86
-
-
0
-
CF1
87
-
-
value
-
CF2
88
-
-
X
uint8_t retBuf[X]
BI2CC
89
-
-
0
-
BI2CO
90
-
-
handle
-
BI2CZ
91
-
-
X
uint8_t data[X]
I2CZ
92
-
-
X
uint8_t data[X]
WVCHA
93
-
-
0
-
SLRI
94
-
-
0
-
CGI
95
-
-
config
-
CSI
96
-
-
0
-
FG
97
-
-
0
-
FN
98
-
-
0
-
NOIB99-
-
0-
WVTXM
100
-
-
wave DMA CBs
-
WVTAT
101
-
-
wave id
-
PADS
102
-
-
0
-
PADG
103
-
-
strength
-
FO
104
-
-
handle
-
FC
105
-
-
0
-
FR
106
-
-
X
uint8_t data[X]
FW
107
-
-
0
-
FS
108
-
-
position
-
FL
109
-
-
X
uint8_t filenames[X]
SHELL
110
-
-
exit status
-
BSPIC
111
-
-
0
-
BSPIO
112
-
-
0
-
BSPIX
113
-
-
X
uint8_t data[X]
BSCX
114
-
-
X+4
uint32_t status
-uint8_t data[X]
EVM
115
-
-
0
-
EVT
116
-
-
0
-
PROCU
117
-
-
0
-
-
-

cmdCmd_t

-typedef struct
-{
-   uint32_t cmd;
-   uint32_t p1;
-   uint32_t p2;
-   union
-   {
-      uint32_t p3;
-      uint32_t ext_len;
-      uint32_t res;
-   };
-} cmdCmd_t;

diff --git a/DOC/tmp/pydoc/pigpio.pydoc b/DOC/tmp/pydoc/pigpio.pydoc deleted file mode 100644 index c5dbdc2..0000000 --- a/DOC/tmp/pydoc/pigpio.pydoc +++ /dev/null @@ -1,4162 +0,0 @@ -Help on module pigpio: - -NAME - pigpio - -FILE - /mnt/d/Users/guy/Projects/pigpio/pigpio.py - -DESCRIPTION - pigpio is a Python module for the Raspberry which talks to - the pigpio daemon to allow control of the general purpose - input outputs (GPIO). - - [http://abyz.me.uk/rpi/pigpio/python.html] - - *Features* - - o the pigpio Python module can run on Windows, Macs, or Linux - - o controls one or more Pi's - - o hardware timed PWM on any of GPIO 0-31 - - o hardware timed servo pulses on any of GPIO 0-31 - - o callbacks when any of GPIO 0-31 change state - - o creating and transmitting precisely timed waveforms - - o reading/writing GPIO and setting their modes - - o wrappers for I2C, SPI, and serial links - - o creating and running scripts on the pigpio daemon - - *GPIO* - - ALL GPIO are identified by their Broadcom number. - - *Notes* - - Transmitted waveforms are accurate to a microsecond. - - Callback level changes are time-stamped and will be - accurate to within a few microseconds. - - *Settings* - - A number of settings are determined when the pigpio daemon is started. - - o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). - - o the set of GPIO which may be updated (generally written to). The - default set is those available on the Pi board revision. - - o the available PWM frequencies (see [*set_PWM_frequency*]). - - *Exceptions* - - By default a fatal exception is raised if you pass an invalid - argument to a pigpio function. - - If you wish to handle the returned status yourself you should set - pigpio.exceptions to False. - - You may prefer to check the returned status in only a few parts - of your code. In that case do the following: - - ... - pigpio.exceptions = False - - # Code where you want to test the error status. - - pigpio.exceptions = True - ... - - *Usage* - - This module uses the services of the C pigpio library. pigpio - must be running on the Pi(s) whose GPIO are to be manipulated. - - The normal way to start pigpio is as a daemon (during system - start). - - sudo pigpiod - - Your Python program must import pigpio and create one or more - instances of the pigpio.pi class. This class gives access to - a specified Pi's GPIO. - - ... - pi1 = pigpio.pi() # pi1 accesses the local Pi's GPIO - pi2 = pigpio.pi('tom') # pi2 accesses tom's GPIO - pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO - - pi1.write(4, 0) # set local Pi's GPIO 4 low - pi2.write(4, 1) # set tom's GPIO 4 to high - pi3.read(4) # get level of dick's GPIO 4 - ... - - The later example code snippets assume that pi is an instance of - the pigpio.pi class. - - OVERVIEW - - ESSENTIAL - - pigpio.pi Initialise Pi connection - stop Stop a Pi connection - - BASIC - - set_mode Set a GPIO mode - get_mode Get a GPIO mode - - set_pull_up_down Set/clear GPIO pull up/down resistor - - read Read a GPIO - write Write a GPIO - - PWM_(overrides_servo_commands_on_same_GPIO) - - set_PWM_dutycycle Start/stop PWM pulses on a GPIO - set_PWM_frequency Set PWM frequency of a GPIO - set_PWM_range Configure PWM range of a GPIO - - get_PWM_dutycycle Get PWM dutycycle set on a GPIO - get_PWM_frequency Get PWM frequency of a GPIO - get_PWM_range Get configured PWM range of a GPIO - - get_PWM_real_range Get underlying PWM range for a GPIO - - Servo_(overrides_PWM_commands_on_same_GPIO) - - set_servo_pulsewidth Start/Stop servo pulses on a GPIO - - get_servo_pulsewidth Get servo pulsewidth set on a GPIO - - INTERMEDIATE - - gpio_trigger Send a trigger pulse to a GPIO - - set_watchdog Set a watchdog on a GPIO - - read_bank_1 Read all bank 1 GPIO - read_bank_2 Read all bank 2 GPIO - - clear_bank_1 Clear selected GPIO in bank 1 - clear_bank_2 Clear selected GPIO in bank 2 - - set_bank_1 Set selected GPIO in bank 1 - set_bank_2 Set selected GPIO in bank 2 - - callback Create GPIO level change callback - - wait_for_edge Wait for GPIO level change - - ADVANCED - - notify_open Request a notification handle - notify_begin Start notifications for selected GPIO - notify_pause Pause notifications - notify_close Close a notification - - hardware_clock Start hardware clock on supported GPIO - - hardware_PWM Start hardware PWM on supported GPIO - - set_glitch_filter Set a glitch filter on a GPIO - set_noise_filter Set a noise filter on a GPIO - - set_pad_strength Sets a pads drive strength - get_pad_strength Gets a pads drive strength - - shell Executes a shell command - - Custom - - custom_1 User custom function 1 - custom_2 User custom function 2 - - Events - - event_callback Sets a callback for an event - - event_trigger Triggers an event - - wait_for_event Wait for an event - - Scripts - - store_script Store a script - run_script Run a stored script - update_script Set a scripts parameters - script_status Get script status and parameters - stop_script Stop a running script - delete_script Delete a stored script - - I2C - - i2c_open Opens an I2C device - i2c_close Closes an I2C device - - i2c_write_quick SMBus write quick - - i2c_read_byte SMBus read byte - i2c_write_byte SMBus write byte - - i2c_read_byte_data SMBus read byte data - i2c_write_byte_data SMBus write byte data - - i2c_read_word_data SMBus read word data - i2c_write_word_data SMBus write word data - - i2c_read_block_data SMBus read block data - i2c_write_block_data SMBus write block data - - i2c_read_i2c_block_data SMBus read I2C block data - i2c_write_i2c_block_data SMBus write I2C block data - - i2c_read_device Reads the raw I2C device - i2c_write_device Writes the raw I2C device - - i2c_process_call SMBus process call - i2c_block_process_call SMBus block process call - - i2c_zip Performs multiple I2C transactions - - I2C_BIT_BANG - - bb_i2c_open Opens GPIO for bit banging I2C - bb_i2c_close Closes GPIO for bit banging I2C - - bb_i2c_zip Performs multiple bit banged I2C transactions - - I2C/SPI_SLAVE - - bsc_xfer I2C/SPI as slave transfer - bsc_i2c I2C as slave transfer - - SERIAL - - serial_open Opens a serial device - serial_close Closes a serial device - - serial_read_byte Reads a byte from a serial device - serial_write_byte Writes a byte to a serial device - - serial_read Reads bytes from a serial device - serial_write Writes bytes to a serial device - - serial_data_available Returns number of bytes ready to be read - - SERIAL_BIT_BANG_(read_only) - - bb_serial_read_open Open a GPIO for bit bang serial reads - bb_serial_read_close Close a GPIO for bit bang serial reads - - bb_serial_invert Invert serial logic (1 invert, 0 normal) - - bb_serial_read Read bit bang serial data from a GPIO - - SPI - - spi_open Opens a SPI device - spi_close Closes a SPI device - - spi_read Reads bytes from a SPI device - spi_write Writes bytes to a SPI device - spi_xfer Transfers bytes with a SPI device - - SPI_BIT_BANG - - bb_spi_open Opens GPIO for bit banging SPI - bb_spi_close Closes GPIO for bit banging SPI - bb_spi_xfer Transfers bytes with bit banging SPI - - FILES - - file_open Opens a file - file_close Closes a file - - file_read Reads bytes from a file - file_write Writes bytes to a file - - file_seek Seeks to a position within a file - - file_list List files which match a pattern - - WAVES - - wave_clear Deletes all waveforms - - wave_add_new Starts a new waveform - wave_add_generic Adds a series of pulses to the waveform - wave_add_serial Adds serial data to the waveform - - wave_create Creates a waveform from added data - wave_create_and_pad Creates a waveform of fixed size from added data - wave_delete Deletes a waveform - - wave_send_once Transmits a waveform once - wave_send_repeat Transmits a waveform repeatedly - wave_send_using_mode Transmits a waveform in the chosen mode - - wave_chain Transmits a chain of waveforms - - wave_tx_at Returns the current transmitting waveform - - wave_tx_busy Checks to see if a waveform has ended - - wave_tx_stop Aborts the current waveform - - wave_get_cbs Length in cbs of the current waveform - wave_get_max_cbs Absolute maximum allowed cbs - - wave_get_micros Length in microseconds of the current waveform - wave_get_max_micros Absolute maximum allowed micros - - wave_get_pulses Length in pulses of the current waveform - wave_get_max_pulses Absolute maximum allowed pulses - - UTILITIES - - get_current_tick Get current tick (microseconds) - - get_hardware_revision Get hardware revision - get_pigpio_version Get the pigpio version - - pigpio.error_text Gets error text from error number - pigpio.tickDiff Returns difference between two ticks - -CLASSES - exceptions.Exception(exceptions.BaseException) - error - pi - pulse - - class error(exceptions.Exception) - | pigpio module exception - | - | Method resolution order: - | error - | exceptions.Exception - | exceptions.BaseException - | __builtin__.object - | - | Methods defined here: - | - | __init__(self, value) - | - | __str__(self) - | - | ---------------------------------------------------------------------- - | Data descriptors defined here: - | - | __weakref__ - | list of weak references to the object (if defined) - | - | ---------------------------------------------------------------------- - | Data and other attributes inherited from exceptions.Exception: - | - | __new__ = - | T.__new__(S, ...) -> a new object with type S, a subtype of T - | - | ---------------------------------------------------------------------- - | Methods inherited from exceptions.BaseException: - | - | __delattr__(...) - | x.__delattr__('name') <==> del x.name - | - | __getattribute__(...) - | x.__getattribute__('name') <==> x.name - | - | __getitem__(...) - | x.__getitem__(y) <==> x[y] - | - | __getslice__(...) - | x.__getslice__(i, j) <==> x[i:j] - | - | Use of negative indices is not supported. - | - | __reduce__(...) - | - | __repr__(...) - | x.__repr__() <==> repr(x) - | - | __setattr__(...) - | x.__setattr__('name', value) <==> x.name = value - | - | __setstate__(...) - | - | __unicode__(...) - | - | ---------------------------------------------------------------------- - | Data descriptors inherited from exceptions.BaseException: - | - | __dict__ - | - | args - | - | message - - class pi - | Methods defined here: - | - | __init__(self, host='localhost', port=8888, show_errors=True) - | Grants access to a Pi's GPIO. - | - | host:= the host name of the Pi on which the pigpio daemon is - | running. The default is localhost unless overridden by - | the PIGPIO_ADDR environment variable. - | - | port:= the port number on which the pigpio daemon is listening. - | The default is 8888 unless overridden by the PIGPIO_PORT - | environment variable. The pigpio daemon must have been - | started with the same port number. - | - | This connects to the pigpio daemon and reserves resources - | to be used for sending commands and receiving notifications. - | - | An instance attribute [*connected*] may be used to check the - | success of the connection. If the connection is established - | successfully [*connected*] will be True, otherwise False. - | - | ... - | pi = pigio.pi() # use defaults - | pi = pigpio.pi('mypi') # specify host, default port - | pi = pigpio.pi('mypi', 7777) # specify host and port - | - | pi = pigpio.pi() # exit script if no connection - | if not pi.connected: - | exit() - | ... - | - | __repr__(self) - | - | bb_i2c_close(self, SDA) - | This function stops bit banging I2C on a pair of GPIO - | previously opened with [*bb_i2c_open*]. - | - | SDA:= 0-31, the SDA GPIO used in a prior call to [*bb_i2c_open*] - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. - | - | ... - | pi.bb_i2c_close(SDA) - | ... - | - | bb_i2c_open(self, SDA, SCL, baud=100000) - | This function selects a pair of GPIO for bit banging I2C at a - | specified baud rate. - | - | Bit banging I2C allows for certain operations which are not possible - | with the standard I2C driver. - | - | o baud rates as low as 50 - | o repeated starts - | o clock stretching - | o I2C on any pair of spare GPIO - | - | SDA:= 0-31 - | SCL:= 0-31 - | baud:= 50-500000 - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or - | PI_GPIO_IN_USE. - | - | NOTE: - | - | The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. - | As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. - | - | ... - | h = pi.bb_i2c_open(4, 5, 50000) # bit bang on GPIO 4/5 at 50kbps - | ... - | - | bb_i2c_zip(self, SDA, data) - | This function executes a sequence of bit banged I2C operations. - | The operations to be performed are specified by the contents - | of data which contains the concatenated command codes and - | associated data. - | - | SDA:= 0-31 (as used in a prior call to [*bb_i2c_open*]) - | data:= the concatenated I2C commands, see below - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (count, data) = pi.bb_i2c_zip( - | SDA, [4, 0x53, 2, 7, 1, 0x32, 2, 6, 6, 3, 0]) - | ... - | - | The following command codes are supported: - | - | Name @ Cmd & Data @ Meaning - | End @ 0 @ No more commands - | Escape @ 1 @ Next P is two bytes - | Start @ 2 @ Start condition - | Stop @ 3 @ Stop condition - | Address @ 4 P @ Set I2C address to P - | Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) - | Read @ 6 P @ Read P bytes of data - | Write @ 7 P ... @ Write P bytes of data - | - | The address, read, and write commands take a parameter P. - | Normally P is one byte (0-255). If the command is preceded by - | the Escape command then P is two bytes (0-65535, least significant - | byte first). - | - | The address and flags default to 0. The address and flags maintain - | their previous value until updated. - | - | No flags are currently defined. - | - | Any read I2C data is concatenated in the returned bytearray. - | - | ... - | Set address 0x53 - | start, write 0x32, (re)start, read 6 bytes, stop - | Set address 0x1E - | start, write 0x03, (re)start, read 6 bytes, stop - | Set address 0x68 - | start, write 0x1B, (re)start, read 8 bytes, stop - | End - | - | 0x04 0x53 - | 0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03 - | - | 0x04 0x1E - | 0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03 - | - | 0x04 0x68 - | 0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03 - | - | 0x00 - | ... - | - | bb_serial_invert(self, user_gpio, invert) - | Invert serial logic. - | - | user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - | invert:= 0-1 (1 invert, 0 normal) - | - | ... - | status = pi.bb_serial_invert(17, 1) - | ... - | - | bb_serial_read(self, user_gpio) - | Returns data from the bit bang serial cyclic buffer. - | - | user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | The bytes returned for each character depend upon the number of - | data bits [*bb_bits*] specified in the [*bb_serial_read_open*] - | command. - | - | For [*bb_bits*] 1-8 there will be one byte per character. - | For [*bb_bits*] 9-16 there will be two bytes per character. - | For [*bb_bits*] 17-32 there will be four bytes per character. - | - | ... - | (count, data) = pi.bb_serial_read(4) - | ... - | - | bb_serial_read_close(self, user_gpio) - | Closes a GPIO for bit bang reading of serial data. - | - | user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - | - | ... - | status = pi.bb_serial_read_close(17) - | ... - | - | bb_serial_read_open(self, user_gpio, baud, bb_bits=8) - | Opens a GPIO for bit bang reading of serial data. - | - | user_gpio:= 0-31, the GPIO to use. - | baud:= 50-250000, the baud rate. - | bb_bits:= 1-32, the number of bits per word, default 8. - | - | The serial data is held in a cyclic buffer and is read using - | [*bb_serial_read*]. - | - | It is the caller's responsibility to read data from the cyclic - | buffer in a timely fashion. - | - | ... - | status = pi.bb_serial_read_open(4, 19200) - | status = pi.bb_serial_read_open(17, 9600) - | ... - | - | bb_spi_close(self, CS) - | This function stops bit banging SPI on a set of GPIO - | opened with [*bb_spi_open*]. - | - | CS:= 0-31, the CS GPIO used in a prior call to [*bb_spi_open*] - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. - | - | ... - | pi.bb_spi_close(CS) - | ... - | - | bb_spi_open(self, CS, MISO, MOSI, SCLK, baud=100000, spi_flags=0) - | This function selects a set of GPIO for bit banging SPI at a - | specified baud rate. - | - | CS := 0-31 - | MISO := 0-31 - | MOSI := 0-31 - | SCLK := 0-31 - | baud := 50-250000 - | spiFlags := see below - | - | spiFlags consists of the least significant 22 bits. - | - | . . - | 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - | 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m - | . . - | - | mm defines the SPI mode, defaults to 0 - | - | . . - | Mode CPOL CPHA - | 0 0 0 - | 1 0 1 - | 2 1 0 - | 3 1 1 - | . . - | - | The following constants may be used to set the mode: - | - | . . - | pigpio.SPI_MODE_0 - | pigpio.SPI_MODE_1 - | pigpio.SPI_MODE_2 - | pigpio.SPI_MODE_3 - | . . - | - | Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA - | may be used. - | - | p is 0 if CS is active low (default) and 1 for active high. - | pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag. - | - | T is 1 if the least significant bit is transmitted on MOSI first, - | the default (0) shifts the most significant bit out first. - | pigpio.SPI_TX_LSBFIRST may be used to set this flag. - | - | R is 1 if the least significant bit is received on MISO first, - | the default (0) receives the most significant bit first. - | pigpio.SPI_RX_LSBFIRST may be used to set this flag. - | - | The other bits in spiFlags should be set to zero. - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or - | PI_GPIO_IN_USE. - | - | If more than one device is connected to the SPI bus (defined by - | SCLK, MOSI, and MISO) each must have its own CS. - | - | ... - | bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1 - | bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2 - | ... - | - | bb_spi_xfer(self, CS, data) - | This function executes a bit banged SPI transfer. - | - | CS:= 0-31 (as used in a prior call to [*bb_spi_open*]) - | data:= data to be sent - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | #!/usr/bin/env python - | - | import pigpio - | - | CE0=5 - | CE1=6 - | MISO=13 - | MOSI=19 - | SCLK=12 - | - | pi = pigpio.pi() - | if not pi.connected: - | exit() - | - | pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC - | pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC - | - | for i in range(256): - | - | count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value - | - | if count == 2: - | - | count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC - | - | if count == 2: - | - | set_val = data[1] - | - | count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC - | - | if count == 3: - | - | read_val = ((data[1]&3)<<8) | data[2] - | - | print("{} {}".format(set_val, read_val)) - | - | pi.bb_spi_close(CE0) - | pi.bb_spi_close(CE1) - | - | pi.stop() - | ... - | - | bsc_i2c(self, i2c_address, data=[]) - | This function allows the Pi to act as a slave I2C device. - | - | This function is not available on the BCM2711 (e.g. as - | used in the Pi4B). - | - | The data bytes (if any) are written to the BSC transmit - | FIFO and the bytes in the BSC receive FIFO are returned. - | - | i2c_address:= the I2C slave address. - | data:= the data bytes to transmit. - | - | The returned value is a tuple of the status, the number - | of bytes read, and a bytearray containing the read bytes. - | - | See [*bsc_xfer*] for details of the status value. - | - | If there was an error the status will be less than zero - | (and will contain the error code). - | - | Note that an i2c_address of 0 may be used to close - | the BSC device and reassign the used GPIO as inputs. - | - | This example assumes GPIO 2/3 are connected to GPIO 18/19 - | (GPIO 10/11 on the BCM2711). - | - | ... - | #!/usr/bin/env python - | import time - | import pigpio - | - | I2C_ADDR=0x13 - | - | def i2c(id, tick): - | global pi - | - | s, b, d = pi.bsc_i2c(I2C_ADDR) - | if b: - | if d[0] == ord('t'): # 116 send 'HH:MM:SS*' - | - | print("sent={} FR={} received={} [{}]". - | format(s>>16, s&0xfff,b,d)) - | - | s, b, d = pi.bsc_i2c(I2C_ADDR, - | "{}*".format(time.asctime()[11:19])) - | - | elif d[0] == ord('d'): # 100 send 'Sun Oct 30*' - | - | print("sent={} FR={} received={} [{}]". - | format(s>>16, s&0xfff,b,d)) - | - | s, b, d = pi.bsc_i2c(I2C_ADDR, - | "{}*".format(time.asctime()[:10])) - | - | pi = pigpio.pi() - | - | if not pi.connected: - | exit() - | - | # Respond to BSC slave activity - | - | e = pi.event_callback(pigpio.EVENT_BSC, i2c) - | - | pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave - | - | time.sleep(600) - | - | e.cancel() - | - | pi.bsc_i2c(0) # Disable BSC peripheral - | - | pi.stop() - | ... - | - | While running the above. - | - | . . - | $ i2cdetect -y 1 - | 0 1 2 3 4 5 6 7 8 9 a b c d e f - | 00: -- -- -- -- -- -- -- -- -- -- -- -- -- - | 10: -- -- -- 13 -- -- -- -- -- -- -- -- -- -- -- -- - | 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | 70: -- -- -- -- -- -- -- -- - | - | $ pigs i2co 1 0x13 0 - | 0 - | - | $ pigs i2cwd 0 116 - | $ pigs i2crd 0 9 -a - | 9 10:13:58* - | - | $ pigs i2cwd 0 116 - | $ pigs i2crd 0 9 -a - | 9 10:14:29* - | - | $ pigs i2cwd 0 100 - | $ pigs i2crd 0 11 -a - | 11 Sun Oct 30* - | - | $ pigs i2cwd 0 100 - | $ pigs i2crd 0 11 -a - | 11 Sun Oct 30* - | - | $ pigs i2cwd 0 116 - | $ pigs i2crd 0 9 -a - | 9 10:23:16* - | - | $ pigs i2cwd 0 100 - | $ pigs i2crd 0 11 -a - | 11 Sun Oct 30* - | . . - | - | bsc_xfer(self, bsc_control, data) - | This function provides a low-level interface to the SPI/I2C Slave - | peripheral on the BCM chip. - | - | This peripheral allows the Pi to act as a hardware slave device - | on an I2C or SPI bus. - | - | This is not a bit bang version and as such is OS timing - | independent. The bus timing is handled directly by the chip. - | - | The output process is simple. You simply append data to the FIFO - | buffer on the chip. This works like a queue, you add data to the - | queue and the master removes it. - | - | I can't get SPI to work properly. I tried with a - | control word of 0x303 and swapped MISO and MOSI. - | - | The function sets the BSC mode, writes any data in - | the transmit buffer to the BSC transmit FIFO, and - | copies any data in the BSC receive FIFO to the - | receive buffer. - | - | bsc_control:= see below - | data:= the data bytes to place in the transmit FIFO. - | - | The returned value is a tuple of the status (see below), - | the number of bytes read, and a bytearray containing the - | read bytes. If there was an error the status will be less - | than zero (and will contain the error code). - | - | Note that the control word sets the BSC mode. The BSC will - | stay in that mode until a different control word is sent. - | - | 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 will be reset - | to INPUT mode. - | - | bsc_control consists of the following bits: - | - | . . - | 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - | a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN - | . . - | - | Bits 0-13 are copied unchanged to the BSC CR register. See - | pages 163-165 of the Broadcom peripherals document for full - | details. - | - | aaaaaaa @ defines the I2C slave address (only relevant in I2C mode) - | IT @ invert transmit status flags - | HC @ enable host control - | TF @ enable test FIFO - | IR @ invert receive status flags - | RE @ enable receive - | TE @ enable transmit - | BK @ abort operation and clear FIFOs - | EC @ send control register as first I2C byte - | ES @ send status register as first I2C byte - | PL @ set SPI polarity high - | PH @ set SPI phase high - | I2 @ enable I2C mode - | SP @ enable SPI mode - | EN @ enable BSC peripheral - | - | The status has the following format: - | - | . . - | 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - | S S S S S R R R R R T T T T T RB TE RF TF RE TB - | . . - | - | Bits 0-15 are copied unchanged from the BSC FR register. See - | pages 165-166 of the Broadcom peripherals document for full - | details. - | - | SSSSS @ number of bytes successfully copied to transmit FIFO - | RRRRR @ number of bytes in receieve FIFO - | TTTTT @ number of bytes in transmit FIFO - | RB @ receive busy - | TE @ transmit FIFO empty - | RF @ receive FIFO full - | TF @ transmit FIFO full - | RE @ receive FIFO empty - | TB @ transmit busy - | - | ... - | (status, count, data) = pi.bsc_xfer(0x330305, "Hello!") - | ... - | - | callback(self, user_gpio, edge=0, func=None) - | Calls a user supplied function (a callback) whenever the - | specified GPIO edge is detected. - | - | user_gpio:= 0-31. - | edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE. - | func:= user supplied callback function. - | - | The user supplied callback receives three parameters, the GPIO, - | the level, and the tick. - | - | . . - | Parameter Value Meaning - | - | GPIO 0-31 The GPIO which has changed state - | - | level 0-2 0 = change to low (a falling edge) - | 1 = change to high (a rising edge) - | 2 = no level change (a watchdog timeout) - | - | tick 32 bit The number of microseconds since boot - | WARNING: this wraps around from - | 4294967295 to 0 roughly every 72 minutes - | . . - | - | If a user callback is not specified a default tally callback is - | provided which simply counts edges. The count may be retrieved - | by calling the tally function. The count may be reset to zero - | by calling the reset_tally function. - | - | The callback may be cancelled by calling the cancel function. - | - | A GPIO may have multiple callbacks (although I can't think of - | a reason to do so). - | - | The GPIO are sampled at a rate set when the pigpio daemon - | is started (default 5 us). - | - | The number of samples per second is given in the following table. - | - | . . - | samples - | per sec - | - | 1 1,000,000 - | 2 500,000 - | sample 4 250,000 - | rate 5 200,000 - | (us) 8 125,000 - | 10 100,000 - | . . - | - | GPIO level changes shorter than the sample rate may be missed. - | - | The daemon software which generates the callbacks is triggered - | 1000 times per second. The callbacks will be called once per - | level change since the last time they were called. - | i.e. The callbacks will get all level changes but there will - | be a latency. - | - | If you want to track the level of more than one GPIO do so by - | maintaining the state in the callback. Do not use [*read*]. - | Remember the event that triggered the callback may have - | happened several milliseconds before and the GPIO may have - | changed level many times since then. - | - | ... - | def cbf(gpio, level, tick): - | print(gpio, level, tick) - | - | cb1 = pi.callback(22, pigpio.EITHER_EDGE, cbf) - | - | cb2 = pi.callback(4, pigpio.EITHER_EDGE) - | - | cb3 = pi.callback(17) - | - | print(cb3.tally()) - | - | cb3.reset_tally() - | - | cb1.cancel() # To cancel callback cb1. - | ... - | - | clear_bank_1(self, bits) - | Clears GPIO 0-31 if the corresponding bit in bits is set. - | - | bits:= a 32 bit mask with 1 set if the corresponding GPIO is - | to be cleared. - | - | A returned status of PI_SOME_PERMITTED indicates that the user - | is not allowed to write to one or more of the GPIO. - | - | ... - | pi.clear_bank_1(int("111110010000",2)) - | ... - | - | clear_bank_2(self, bits) - | Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. - | - | bits:= a 32 bit mask with 1 set if the corresponding GPIO is - | to be cleared. - | - | A returned status of PI_SOME_PERMITTED indicates that the user - | is not allowed to write to one or more of the GPIO. - | - | ... - | pi.clear_bank_2(0x1010) - | ... - | - | custom_1(self, arg1=0, arg2=0, argx=[]) - | Calls a pigpio function customised by the user. - | - | arg1:= >=0, default 0. - | arg2:= >=0, default 0. - | argx:= extra arguments (each 0-255), default empty. - | - | The returned value is an integer which by convention - | should be >=0 for OK and <0 for error. - | - | ... - | value = pi.custom_1() - | - | value = pi.custom_1(23) - | - | value = pi.custom_1(0, 55) - | - | value = pi.custom_1(23, 56, [1, 5, 7]) - | - | value = pi.custom_1(23, 56, b"hello") - | - | value = pi.custom_1(23, 56, "hello") - | ... - | - | custom_2(self, arg1=0, argx=[], retMax=8192) - | Calls a pigpio function customised by the user. - | - | arg1:= >=0, default 0. - | argx:= extra arguments (each 0-255), default empty. - | retMax:= >=0, maximum number of bytes to return, default 8192. - | - | The returned value is a tuple of the number of bytes - | returned and a bytearray containing the bytes. If - | there was an error the number of bytes read will be - | less than zero (and will contain the error code). - | - | ... - | (count, data) = pi.custom_2() - | - | (count, data) = pi.custom_2(23) - | - | (count, data) = pi.custom_2(23, [1, 5, 7]) - | - | (count, data) = pi.custom_2(23, b"hello") - | - | (count, data) = pi.custom_2(23, "hello", 128) - | ... - | - | delete_script(self, script_id) - | Deletes a stored script. - | - | script_id:= id of stored script. - | - | ... - | status = pi.delete_script(sid) - | ... - | - | event_callback(self, event, func=None) - | Calls a user supplied function (a callback) whenever the - | specified event is signalled. - | - | event:= 0-31. - | func:= user supplied callback function. - | - | The user supplied callback receives two parameters, the event id, - | and the tick. - | - | If a user callback is not specified a default tally callback is - | provided which simply counts events. The count may be retrieved - | by calling the tally function. The count may be reset to zero - | by calling the reset_tally function. - | - | The callback may be cancelled by calling the event_cancel function. - | - | An event may have multiple callbacks (although I can't think of - | a reason to do so). - | - | ... - | def cbf(event, tick): - | print(event, tick) - | - | cb1 = pi.event_callback(22, cbf) - | - | cb2 = pi.event_callback(4) - | - | print(cb2.tally()) - | - | cb2.reset_tally() - | - | cb1.event_cancel() # To cancel callback cb1. - | ... - | - | event_trigger(self, event) - | This function signals the occurrence of an event. - | - | event:= 0-31, the event - | - | Returns 0 if OK, otherwise PI_BAD_EVENT_ID. - | - | An event is a signal used to inform one or more consumers - | to start an action. Each consumer which has registered an - | interest in the event (e.g. by calling [*event_callback*]) will - | be informed by a callback. - | - | One event, EVENT_BSC (31) is predefined. This event is - | auto generated on BSC slave activity. - | - | The meaning of other events is arbitrary. - | - | Note that other than its id and its tick there is no data associated - | with an event. - | - | ... - | pi.event_trigger(23) - | ... - | - | file_close(self, handle) - | Closes the file associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*file_open*]). - | - | ... - | pi.file_close(handle) - | ... - | - | file_list(self, fpattern) - | Returns a list of files which match a pattern. - | - | fpattern:= file pattern to match. - | - | Returns the number of returned bytes if OK, otherwise - | PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. - | - | The pattern must match an entry in /opt/pigpio/access. The - | pattern may contain wildcards. See [*file_open*]. - | - | NOTE - | - | The returned value is not the number of files, it is the number - | of bytes in the buffer. The file names are separated by newline - | characters. - | - | ... - | #!/usr/bin/env python - | - | import pigpio - | - | pi = pigpio.pi() - | - | if not pi.connected: - | exit() - | - | # Assumes /opt/pigpio/access contains the following line: - | # /ram/*.c r - | - | c, d = pi.file_list("/ram/p*.c") - | if c > 0: - | print(d) - | - | pi.stop() - | ... - | - | file_open(self, file_name, file_mode) - | This function returns a handle to a file opened in a specified mode. - | - | file_name:= the file to open. - | file_mode:= the file open mode. - | - | Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, - | PI_NO_FILE_ACCESS, PI_BAD_FILE_MODE, - | PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. - | - | ... - | h = pi.file_open("/home/pi/shared/dir_3/file.txt", - | pigpio.FILE_WRITE | pigpio.FILE_CREATE) - | - | pi.file_write(h, "Hello world") - | - | pi.file_close(h) - | ... - | - | File - | - | A file may only be opened if permission is granted by an entry - | in /opt/pigpio/access. This is intended to allow remote access - | to files in a more or less controlled manner. - | - | Each entry in /opt/pigpio/access takes the form of a file path - | which may contain wildcards followed by a single letter permission. - | The permission may be R for read, W for write, U for read/write, - | and N for no access. - | - | Where more than one entry matches a file the most specific rule - | applies. If no entry matches a file then access is denied. - | - | Suppose /opt/pigpio/access contains the following entries: - | - | . . - | /home/* n - | /home/pi/shared/dir_1/* w - | /home/pi/shared/dir_2/* r - | /home/pi/shared/dir_3/* u - | /home/pi/shared/dir_1/file.txt n - | . . - | - | Files may be written in directory dir_1 with the exception - | of file.txt. - | - | Files may be read in directory dir_2. - | - | Files may be read and written in directory dir_3. - | - | If a directory allows read, write, or read/write access then files - | may be created in that directory. - | - | In an attempt to prevent risky permissions the following paths are - | ignored in /opt/pigpio/access: - | - | . . - | a path containing .. - | a path containing only wildcards (*?) - | a path containing less than two non-wildcard parts - | . . - | - | Mode - | - | The mode may have the following values: - | - | Constant @ Value @ Meaning - | FILE_READ @ 1 @ open file for reading - | FILE_WRITE @ 2 @ open file for writing - | FILE_RW @ 3 @ open file for reading and writing - | - | The following values may be or'd into the mode: - | - | Name @ Value @ Meaning - | FILE_APPEND @ 4 @ All writes append data to the end of the file - | FILE_CREATE @ 8 @ The file is created if it doesn't exist - | FILE_TRUNC @ 16 @ The file is truncated - | - | Newly created files are owned by root with permissions owner - | read and write. - | - | ... - | #!/usr/bin/env python - | - | import pigpio - | - | pi = pigpio.pi() - | - | if not pi.connected: - | exit() - | - | # Assumes /opt/pigpio/access contains the following line: - | # /ram/*.c r - | - | handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ) - | - | done = False - | - | while not done: - | c, d = pi.file_read(handle, 60000) - | if c > 0: - | print(d) - | else: - | done = True - | - | pi.file_close(handle) - | - | pi.stop() - | ... - | - | file_read(self, handle, count) - | Reads up to count bytes from the file associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*file_open*]). - | count:= >0, the number of bytes to read. - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.file_read(h2, 100) - | if b > 0: - | # process read data - | ... - | - | file_seek(self, handle, seek_offset, seek_from) - | Seeks to a position relative to the start, current position, - | or end of the file. Returns the new position. - | - | handle:= >=0 (as returned by a prior call to [*file_open*]). - | seek_offset:= byte offset. - | seek_from:= FROM_START, FROM_CURRENT, or FROM_END. - | - | ... - | new_pos = pi.file_seek(h, 100, pigpio.FROM_START) - | - | cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT) - | - | file_size = pi.file_seek(h, 0, pigpio.FROM_END) - | ... - | - | file_write(self, handle, data) - | Writes the data bytes to the file associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*file_open*]). - | data:= the bytes to write. - | - | ... - | pi.file_write(h1, b'\x02\x03\x04') - | - | pi.file_write(h2, b'help') - | - | pi.file_write(h2, "hello") - | - | pi.file_write(h1, [2, 3, 4]) - | ... - | - | get_PWM_dutycycle(self, user_gpio) - | Returns the PWM dutycycle being used on the GPIO. - | - | user_gpio:= 0-31. - | - | Returns the PWM dutycycle. - | - | - | For normal PWM the dutycycle will be out of the defined range - | for the GPIO (see [*get_PWM_range*]). - | - | If a hardware clock is active on the GPIO the reported - | dutycycle will be 500000 (500k) out of 1000000 (1M). - | - | If hardware PWM is active on the GPIO the reported dutycycle - | will be out of a 1000000 (1M). - | - | ... - | pi.set_PWM_dutycycle(4, 25) - | print(pi.get_PWM_dutycycle(4)) - | 25 - | - | pi.set_PWM_dutycycle(4, 203) - | print(pi.get_PWM_dutycycle(4)) - | 203 - | ... - | - | get_PWM_frequency(self, user_gpio) - | Returns the frequency of PWM being used on the GPIO. - | - | user_gpio:= 0-31. - | - | Returns the frequency (in Hz) used for the GPIO. - | - | For normal PWM the frequency will be that defined for the GPIO - | by [*set_PWM_frequency*]. - | - | If a hardware clock is active on the GPIO the reported frequency - | will be that set by [*hardware_clock*]. - | - | If hardware PWM is active on the GPIO the reported frequency - | will be that set by [*hardware_PWM*]. - | - | ... - | pi.set_PWM_frequency(4,0) - | print(pi.get_PWM_frequency(4)) - | 10 - | - | pi.set_PWM_frequency(4, 800) - | print(pi.get_PWM_frequency(4)) - | 800 - | ... - | - | get_PWM_range(self, user_gpio) - | Returns the range of PWM values being used on the GPIO. - | - | user_gpio:= 0-31. - | - | If a hardware clock or hardware PWM is active on the GPIO - | the reported range will be 1000000 (1M). - | - | ... - | pi.set_PWM_range(9, 500) - | print(pi.get_PWM_range(9)) - | 500 - | ... - | - | get_PWM_real_range(self, user_gpio) - | Returns the real (underlying) range of PWM values being - | used on the GPIO. - | - | user_gpio:= 0-31. - | - | If a hardware clock is active on the GPIO the reported - | real range will be 1000000 (1M). - | - | If hardware PWM is active on the GPIO the reported real range - | will be approximately 250M divided by the set PWM frequency. - | - | ... - | pi.set_PWM_frequency(4, 800) - | print(pi.get_PWM_real_range(4)) - | 250 - | ... - | - | get_current_tick(self) - | Returns the current system tick. - | - | Tick is the number of microseconds since system boot. As an - | unsigned 32 bit quantity tick wraps around approximately - | every 71.6 minutes. - | - | ... - | t1 = pi.get_current_tick() - | time.sleep(1) - | t2 = pi.get_current_tick() - | ... - | - | get_hardware_revision(self) - | Returns the Pi's hardware revision number. - | - | The hardware revision is the last few characters on the - | Revision line of /proc/cpuinfo. - | - | The revision number can be used to determine the assignment - | of GPIO to pins (see [*gpio*]). - | - | There are at least three types of board. - | - | Type 1 boards have hardware revision numbers of 2 and 3. - | - | Type 2 boards have hardware revision numbers of 4, 5, 6, and 15. - | - | Type 3 boards have hardware revision numbers of 16 or greater. - | - | If the hardware revision can not be found or is not a valid - | hexadecimal number the function returns 0. - | - | ... - | print(pi.get_hardware_revision()) - | 2 - | ... - | - | get_mode(self, gpio) - | Returns the GPIO mode. - | - | gpio:= 0-53. - | - | Returns a value as follows - | - | . . - | 0 = INPUT - | 1 = OUTPUT - | 2 = ALT5 - | 3 = ALT4 - | 4 = ALT0 - | 5 = ALT1 - | 6 = ALT2 - | 7 = ALT3 - | . . - | - | ... - | print(pi.get_mode(0)) - | 4 - | ... - | - | get_pad_strength(self, pad) - | This function returns the pad drive strength in mA. - | - | pad:= 0-2, the pad to get. - | - | Returns the pad drive strength if OK, otherwise PI_BAD_PAD. - | - | Pad @ GPIO - | 0 @ 0-27 - | 1 @ 28-45 - | 2 @ 46-53 - | - | ... - | strength = pi.get_pad_strength(0) # Get pad 0 strength. - | ... - | - | get_pigpio_version(self) - | Returns the pigpio software version. - | - | ... - | v = pi.get_pigpio_version() - | ... - | - | get_servo_pulsewidth(self, user_gpio) - | Returns the servo pulsewidth being used on the GPIO. - | - | user_gpio:= 0-31. - | - | Returns the servo pulsewidth. - | - | ... - | pi.set_servo_pulsewidth(4, 525) - | print(pi.get_servo_pulsewidth(4)) - | 525 - | - | pi.set_servo_pulsewidth(4, 2130) - | print(pi.get_servo_pulsewidth(4)) - | 2130 - | ... - | - | gpio_trigger(self, user_gpio, pulse_len=10, level=1) - | Send a trigger pulse to a GPIO. The GPIO is set to - | level for pulse_len microseconds and then reset to not level. - | - | user_gpio:= 0-31 - | pulse_len:= 1-100 - | level:= 0-1 - | - | ... - | pi.gpio_trigger(23, 10, 1) - | ... - | - | hardware_PWM(self, gpio, PWMfreq, PWMduty) - | Starts hardware PWM on a GPIO at the specified frequency - | and dutycycle. Frequencies above 30MHz are unlikely to work. - | - | NOTE: Any waveform started by [*wave_send_once*], - | [*wave_send_repeat*], or [*wave_chain*] will be cancelled. - | - | This function is only valid if the pigpio main clock is PCM. - | The main clock defaults to PCM but may be overridden when the - | pigpio daemon is started (option -t). - | - | gpio:= see descripton - | PWMfreq:= 0 (off) or 1-125M (1-187.5M for the BCM2711). - | PWMduty:= 0 (off) to 1000000 (1M)(fully on). - | - | Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, - | PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ. - | - | The same PWM channel is available on multiple GPIO. - | The latest frequency and dutycycle setting will be used - | by all GPIO which share a PWM channel. - | - | The GPIO must be one of the following: - | - | . . - | 12 PWM channel 0 All models but A and B - | 13 PWM channel 1 All models but A and B - | 18 PWM channel 0 All models - | 19 PWM channel 1 All models but A and B - | - | 40 PWM channel 0 Compute module only - | 41 PWM channel 1 Compute module only - | 45 PWM channel 1 Compute module only - | 52 PWM channel 0 Compute module only - | 53 PWM channel 1 Compute module only - | . . - | - | The actual number of steps beween off and fully on is the - | integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711). - | - | The actual frequency set is 250M/steps (375M/steps - | for the BCM2711). - | - | There will only be a million steps for a PWMfreq of 250 - | (375 for the BCM2711). Lower frequencies will have more - | steps and higher frequencies will have fewer steps. - | PWMduty is automatically scaled to take this into account. - | - | ... - | pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle - | - | pi.hardware_PWM(18, 2000, 750000) # 2000Hz 75% dutycycle - | ... - | - | hardware_clock(self, gpio, clkfreq) - | Starts a hardware clock on a GPIO at the specified frequency. - | Frequencies above 30MHz are unlikely to work. - | - | gpio:= see description - | clkfreq:= 0 (off) or 4689-250M (13184-375M for the BCM2711) - | - | - | Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO, - | PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. - | - | The same clock is available on multiple GPIO. The latest - | frequency setting will be used by all GPIO which share a clock. - | - | The GPIO must be one of the following: - | - | . . - | 4 clock 0 All models - | 5 clock 1 All models but A and B (reserved for system use) - | 6 clock 2 All models but A and B - | 20 clock 0 All models but A and B - | 21 clock 1 All models but A and Rev.2 B (reserved for system use) - | - | 32 clock 0 Compute module only - | 34 clock 0 Compute module only - | 42 clock 1 Compute module only (reserved for system use) - | 43 clock 2 Compute module only - | 44 clock 1 Compute module only (reserved for system use) - | . . - | - | Access to clock 1 is protected by a password as its use will - | likely crash the Pi. The password is given by or'ing 0x5A000000 - | with the GPIO number. - | - | ... - | pi.hardware_clock(4, 5000) # 5 KHz clock on GPIO 4 - | - | pi.hardware_clock(4, 40000000) # 40 MHz clock on GPIO 4 - | ... - | - | i2c_block_process_call(self, handle, reg, data) - | Writes data bytes to the specified register of the device - | associated with handle and reads a device specified number - | of bytes of data in return. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | data:= the bytes to write. - | - | The SMBus 2.0 documentation states that a minimum of 1 byte may - | be sent and a minimum of 1 byte may be received. The total - | number of bytes sent/received must be 32 or less. - | - | SMBus 2.0 5.5.8 - Block write-block read. - | . . - | S Addr Wr [A] reg [A] len(data) [A] data0 [A] ... datan [A] - | S Addr Rd [A] [Count] A [Data] ... A P - | . . - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.i2c_block_process_call(h, 10, b'\x02\x05\x00') - | - | (b, d) = pi.i2c_block_process_call(h, 10, b'abcdr') - | - | (b, d) = pi.i2c_block_process_call(h, 10, "abracad") - | - | (b, d) = pi.i2c_block_process_call(h, 10, [2, 5, 16]) - | ... - | - | i2c_close(self, handle) - | Closes the I2C device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | - | ... - | pi.i2c_close(h) - | ... - | - | i2c_open(self, i2c_bus, i2c_address, i2c_flags=0) - | Returns a handle (>=0) for the device at the I2C bus address. - | - | i2c_bus:= >=0. - | i2c_address:= 0-0x7F. - | i2c_flags:= 0, no flags are currently defined. - | - | Physically buses 0 and 1 are available on the Pi. Higher - | numbered buses will be available if a kernel supported bus - | multiplexor is being used. - | - | The GPIO used are given in the following table. - | - | @ SDA @ SCL - | I2C 0 @ 0 @ 1 - | I2C 1 @ 2 @ 3 - | - | For the SMBus commands the low level transactions are shown - | at the end of the function description. The following - | abbreviations are used: - | - | . . - | S (1 bit) : Start bit - | P (1 bit) : Stop bit - | Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. - | A, NA (1 bit) : Accept and not accept bit. - | Addr (7 bits): I2C 7 bit address. - | reg (8 bits): Command byte, which often selects a register. - | Data (8 bits): A data byte. - | Count (8 bits): A byte defining the length of a block operation. - | - | [..]: Data sent by the device. - | . . - | - | ... - | h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1 - | ... - | - | i2c_process_call(self, handle, reg, word_val) - | Writes 16 bits of data to the specified register of the device - | associated with handle and reads 16 bits of data in return. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | word_val:= 0-65535, the value to write. - | - | SMBus 2.0 5.5.6 - Process call. - | . . - | S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] - | S Addr Rd [A] [DataLow] A [DataHigh] NA P - | . . - | - | ... - | r = pi.i2c_process_call(h, 4, 0x1231) - | r = pi.i2c_process_call(h, 6, 0) - | ... - | - | i2c_read_block_data(self, handle, reg) - | Reads a block of up to 32 bytes from the specified register of - | the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | - | SMBus 2.0 5.5.7 - Block read. - | . . - | S Addr Wr [A] reg [A] - | S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P - | . . - | - | The amount of returned data is set by the device. - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.i2c_read_block_data(h, 10) - | if b >= 0: - | # process data - | else: - | # process read failure - | ... - | - | i2c_read_byte(self, handle) - | Reads a single byte from the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | - | SMBus 2.0 5.5.3 - Receive byte. - | . . - | S Addr Rd [A] [Data] NA P - | . . - | - | ... - | b = pi.i2c_read_byte(2) # read a byte from device 2 - | ... - | - | i2c_read_byte_data(self, handle, reg) - | Reads a single byte from the specified register of the device - | associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | - | SMBus 2.0 5.5.5 - Read byte. - | . . - | S Addr Wr [A] reg [A] S Addr Rd [A] [Data] NA P - | . . - | - | ... - | # read byte from reg 17 of device 2 - | b = pi.i2c_read_byte_data(2, 17) - | - | # read byte from reg 1 of device 0 - | b = pi.i2c_read_byte_data(0, 1) - | ... - | - | i2c_read_device(self, handle, count) - | Returns count bytes read from the raw device associated - | with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | count:= >0, the number of bytes to read. - | - | . . - | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P - | . . - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (count, data) = pi.i2c_read_device(h, 12) - | ... - | - | i2c_read_i2c_block_data(self, handle, reg, count) - | Reads count bytes from the specified register of the device - | associated with handle . The count may be 1-32. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | count:= >0, the number of bytes to read. - | - | . . - | S Addr Wr [A] reg [A] - | S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P - | . . - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.i2c_read_i2c_block_data(h, 4, 32) - | if b >= 0: - | # process data - | else: - | # process read failure - | ... - | - | i2c_read_word_data(self, handle, reg) - | Reads a single 16 bit word from the specified register of the - | device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | - | SMBus 2.0 5.5.5 - Read word. - | . . - | S Addr Wr [A] reg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P - | . . - | - | ... - | # read word from reg 2 of device 3 - | w = pi.i2c_read_word_data(3, 2) - | - | # read word from reg 7 of device 2 - | w = pi.i2c_read_word_data(2, 7) - | ... - | - | i2c_write_block_data(self, handle, reg, data) - | Writes up to 32 bytes to the specified register of the device - | associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | data:= the bytes to write. - | - | SMBus 2.0 5.5.7 - Block write. - | . . - | S Addr Wr [A] reg [A] len(data) [A] data0 [A] data1 [A] ... [A] - | datan [A] P - | . . - | - | ... - | pi.i2c_write_block_data(4, 5, b'hello') - | - | pi.i2c_write_block_data(4, 5, "data bytes") - | - | pi.i2c_write_block_data(5, 0, b'\x00\x01\x22') - | - | pi.i2c_write_block_data(6, 2, [0, 1, 0x22]) - | ... - | - | i2c_write_byte(self, handle, byte_val) - | Sends a single byte to the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | byte_val:= 0-255, the value to write. - | - | SMBus 2.0 5.5.2 - Send byte. - | . . - | S Addr Wr [A] byte_val [A] P - | . . - | - | ... - | pi.i2c_write_byte(1, 17) # send byte 17 to device 1 - | pi.i2c_write_byte(2, 0x23) # send byte 0x23 to device 2 - | ... - | - | i2c_write_byte_data(self, handle, reg, byte_val) - | Writes a single byte to the specified register of the device - | associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | byte_val:= 0-255, the value to write. - | - | SMBus 2.0 5.5.4 - Write byte. - | . . - | S Addr Wr [A] reg [A] byte_val [A] P - | . . - | - | ... - | # send byte 0xC5 to reg 2 of device 1 - | pi.i2c_write_byte_data(1, 2, 0xC5) - | - | # send byte 9 to reg 4 of device 2 - | pi.i2c_write_byte_data(2, 4, 9) - | ... - | - | i2c_write_device(self, handle, data) - | Writes the data bytes to the raw device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | data:= the bytes to write. - | - | . . - | S Addr Wr [A] data0 [A] data1 [A] ... [A] datan [A] P - | . . - | - | ... - | pi.i2c_write_device(h, b"\x12\x34\xA8") - | - | pi.i2c_write_device(h, b"help") - | - | pi.i2c_write_device(h, 'help') - | - | pi.i2c_write_device(h, [23, 56, 231]) - | ... - | - | i2c_write_i2c_block_data(self, handle, reg, data) - | Writes data bytes to the specified register of the device - | associated with handle . 1-32 bytes may be written. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | data:= the bytes to write. - | - | . . - | S Addr Wr [A] reg [A] data0 [A] data1 [A] ... [A] datan [NA] P - | . . - | - | ... - | pi.i2c_write_i2c_block_data(4, 5, 'hello') - | - | pi.i2c_write_i2c_block_data(4, 5, b'hello') - | - | pi.i2c_write_i2c_block_data(5, 0, b'\x00\x01\x22') - | - | pi.i2c_write_i2c_block_data(6, 2, [0, 1, 0x22]) - | ... - | - | i2c_write_quick(self, handle, bit) - | Sends a single bit to the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | bit:= 0 or 1, the value to write. - | - | SMBus 2.0 5.5.1 - Quick command. - | . . - | S Addr bit [A] P - | . . - | - | ... - | pi.i2c_write_quick(0, 1) # send 1 to device 0 - | pi.i2c_write_quick(3, 0) # send 0 to device 3 - | ... - | - | i2c_write_word_data(self, handle, reg, word_val) - | Writes a single 16 bit word to the specified register of the - | device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | reg:= >=0, the device register. - | word_val:= 0-65535, the value to write. - | - | SMBus 2.0 5.5.4 - Write word. - | . . - | S Addr Wr [A] reg [A] word_val_Low [A] word_val_High [A] P - | . . - | - | ... - | # send word 0xA0C5 to reg 5 of device 4 - | pi.i2c_write_word_data(4, 5, 0xA0C5) - | - | # send word 2 to reg 2 of device 5 - | pi.i2c_write_word_data(5, 2, 23) - | ... - | - | i2c_zip(self, handle, data) - | This function executes a sequence of I2C operations. The - | operations to be performed are specified by the contents of data - | which contains the concatenated command codes and associated data. - | - | handle:= >=0 (as returned by a prior call to [*i2c_open*]). - | data:= the concatenated I2C commands, see below - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (count, data) = pi.i2c_zip(h, [4, 0x53, 7, 1, 0x32, 6, 6, 0]) - | ... - | - | The following command codes are supported: - | - | Name @ Cmd & Data @ Meaning - | End @ 0 @ No more commands - | Escape @ 1 @ Next P is two bytes - | On @ 2 @ Switch combined flag on - | Off @ 3 @ Switch combined flag off - | Address @ 4 P @ Set I2C address to P - | Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8) - | Read @ 6 P @ Read P bytes of data - | Write @ 7 P ... @ Write P bytes of data - | - | The address, read, and write commands take a parameter P. - | Normally P is one byte (0-255). If the command is preceded by - | the Escape command then P is two bytes (0-65535, least significant - | byte first). - | - | The address defaults to that associated with the handle. - | The flags default to 0. The address and flags maintain their - | previous value until updated. - | - | Any read I2C data is concatenated in the returned bytearray. - | - | ... - | Set address 0x53, write 0x32, read 6 bytes - | Set address 0x1E, write 0x03, read 6 bytes - | Set address 0x68, write 0x1B, read 8 bytes - | End - | - | 0x04 0x53 0x07 0x01 0x32 0x06 0x06 - | 0x04 0x1E 0x07 0x01 0x03 0x06 0x06 - | 0x04 0x68 0x07 0x01 0x1B 0x06 0x08 - | 0x00 - | ... - | - | notify_begin(self, handle, bits) - | Starts notifications on a handle. - | - | handle:= >=0 (as returned by a prior call to [*notify_open*]) - | bits:= a 32 bit mask indicating the GPIO to be notified. - | - | The notification sends state changes for each GPIO whose - | corresponding bit in bits is set. - | - | The following code starts notifications for GPIO 1, 4, - | 6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). - | - | ... - | h = pi.notify_open() - | if h >= 0: - | pi.notify_begin(h, 1234) - | ... - | - | notify_close(self, handle) - | Stops notifications on a handle and releases the handle for reuse. - | - | handle:= >=0 (as returned by a prior call to [*notify_open*]) - | - | ... - | h = pi.notify_open() - | if h >= 0: - | pi.notify_begin(h, 1234) - | ... - | pi.notify_close(h) - | ... - | ... - | - | notify_open(self) - | Returns a notification handle (>=0). - | - | A notification is a method for being notified of GPIO state - | changes via a pipe. - | - | Pipes are only accessible from the local machine so this - | function serves no purpose if you are using Python from a - | remote machine. The in-built (socket) notifications - | provided by [*callback*] should be used instead. - | - | Notifications for handle x will be available at the pipe - | named /dev/pigpiox (where x is the handle number). - | - | E.g. if the function returns 15 then the notifications must be - | read from /dev/pigpio15. - | - | Notifications have the following structure: - | - | . . - | H seqno - | H flags - | I tick - | I level - | . . - | - | seqno: starts at 0 each time the handle is opened and then - | increments by one for each report. - | - | flags: three flags are defined, PI_NTFY_FLAGS_WDOG, - | PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT. - | - | If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the - | flags indicate a GPIO which has had a watchdog timeout. - | - | If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep - | alive signal on the pipe/socket and is sent once a minute - | in the absence of other notification activity. - | - | If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the - | flags indicate an event which has been triggered. - | - | - | tick: the number of microseconds since system boot. It wraps - | around after 1h12m. - | - | level: indicates the level of each GPIO. If bit 1<= 0: - | pi.notify_begin(h, 1234) - | ... - | - | notify_pause(self, handle) - | Pauses notifications on a handle. - | - | handle:= >=0 (as returned by a prior call to [*notify_open*]) - | - | Notifications for the handle are suspended until - | [*notify_begin*] is called again. - | - | ... - | h = pi.notify_open() - | if h >= 0: - | pi.notify_begin(h, 1234) - | ... - | pi.notify_pause(h) - | ... - | pi.notify_begin(h, 1234) - | ... - | ... - | - | read(self, gpio) - | Returns the GPIO level. - | - | gpio:= 0-53. - | - | ... - | pi.set_mode(23, pigpio.INPUT) - | - | pi.set_pull_up_down(23, pigpio.PUD_DOWN) - | print(pi.read(23)) - | 0 - | - | pi.set_pull_up_down(23, pigpio.PUD_UP) - | print(pi.read(23)) - | 1 - | ... - | - | read_bank_1(self) - | Returns the levels of the bank 1 GPIO (GPIO 0-31). - | - | The returned 32 bit integer has a bit set if the corresponding - | GPIO is high. GPIO n has bit value (1<=0 (as returned by a prior call to [*serial_open*]). - | - | ... - | pi.serial_close(h1) - | ... - | - | serial_data_available(self, handle) - | Returns the number of bytes available to be read from the - | device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | - | ... - | rdy = pi.serial_data_available(h1) - | - | if rdy > 0: - | (b, d) = pi.serial_read(h1, rdy) - | ... - | - | serial_open(self, tty, baud, ser_flags=0) - | Returns a handle for the serial tty device opened - | at baud bits per second. The device name must start - | with /dev/tty or /dev/serial. - | - | tty:= the serial device to open. - | baud:= baud rate in bits per second, see below. - | ser_flags:= 0, no flags are currently defined. - | - | Normally you would only use the [*serial_**] functions if - | you are or will be connecting to the Pi over a network. If - | you will always run on the local Pi use the standard serial - | module instead. - | - | The baud rate must be one of 50, 75, 110, 134, 150, - | 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, - | 38400, 57600, 115200, or 230400. - | - | ... - | h1 = pi.serial_open("/dev/ttyAMA0", 300) - | - | h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0) - | - | h3 = pi.serial_open("/dev/serial0", 9600) - | ... - | - | serial_read(self, handle, count=1000) - | Reads up to count bytes from the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | count:= >0, the number of bytes to read (defaults to 1000). - | - | The returned value is a tuple of the number of bytes read and - | a bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | If no data is ready a bytes read of zero is returned. - | ... - | (b, d) = pi.serial_read(h2, 100) - | if b > 0: - | # process read data - | ... - | - | serial_read_byte(self, handle) - | Returns a single byte from the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | - | If no data is ready a negative error code will be returned. - | - | ... - | b = pi.serial_read_byte(h1) - | ... - | - | serial_write(self, handle, data) - | Writes the data bytes to the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | data:= the bytes to write. - | - | ... - | pi.serial_write(h1, b'\x02\x03\x04') - | - | pi.serial_write(h2, b'help') - | - | pi.serial_write(h2, "hello") - | - | pi.serial_write(h1, [2, 3, 4]) - | ... - | - | serial_write_byte(self, handle, byte_val) - | Writes a single byte to the device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*serial_open*]). - | byte_val:= 0-255, the value to write. - | - | ... - | pi.serial_write_byte(h1, 23) - | - | pi.serial_write_byte(h1, ord('Z')) - | ... - | - | set_PWM_dutycycle(self, user_gpio, dutycycle) - | Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. - | - | user_gpio:= 0-31. - | dutycycle:= 0-range (range defaults to 255). - | - | The [*set_PWM_range*] function can change the default range of 255. - | - | ... - | pi.set_PWM_dutycycle(4, 0) # PWM off - | pi.set_PWM_dutycycle(4, 64) # PWM 1/4 on - | pi.set_PWM_dutycycle(4, 128) # PWM 1/2 on - | pi.set_PWM_dutycycle(4, 192) # PWM 3/4 on - | pi.set_PWM_dutycycle(4, 255) # PWM full on - | ... - | - | set_PWM_frequency(self, user_gpio, frequency) - | Sets the frequency (in Hz) of the PWM to be used on the GPIO. - | - | user_gpio:= 0-31. - | frequency:= >=0 Hz - | - | Returns the numerically closest frequency if OK, otherwise - | PI_BAD_USER_GPIO or PI_NOT_PERMITTED. - | - | If PWM is currently active on the GPIO it will be switched - | off and then back on at the new frequency. - | - | Each GPIO can be independently set to one of 18 different - | PWM frequencies. - | - | The selectable frequencies depend upon the sample rate which - | may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The - | sample rate is set when the pigpio daemon is started. - | - | The frequencies for each sample rate are: - | - | . . - | Hertz - | - | 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 - | 1250 1000 800 500 400 250 200 100 50 - | - | 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 - | 625 500 400 250 200 125 100 50 25 - | - | 4: 10000 5000 2500 2000 1250 1000 625 500 400 - | 313 250 200 125 100 63 50 25 13 - | sample - | rate - | (us) 5: 8000 4000 2000 1600 1000 800 500 400 320 - | 250 200 160 100 80 50 40 20 10 - | - | 8: 5000 2500 1250 1000 625 500 313 250 200 - | 156 125 100 63 50 31 25 13 6 - | - | 10: 4000 2000 1000 800 500 400 250 200 160 - | 125 100 80 50 40 25 20 10 5 - | . . - | - | ... - | pi.set_PWM_frequency(4,0) - | print(pi.get_PWM_frequency(4)) - | 10 - | - | pi.set_PWM_frequency(4,100000) - | print(pi.get_PWM_frequency(4)) - | 8000 - | ... - | - | set_PWM_range(self, user_gpio, range_) - | Sets the range of PWM values to be used on the GPIO. - | - | user_gpio:= 0-31. - | range_:= 25-40000. - | - | ... - | pi.set_PWM_range(9, 100) # now 25 1/4, 50 1/2, 75 3/4 on - | pi.set_PWM_range(9, 500) # now 125 1/4, 250 1/2, 375 3/4 on - | pi.set_PWM_range(9, 3000) # now 750 1/4, 1500 1/2, 2250 3/4 on - | ... - | - | set_bank_1(self, bits) - | Sets GPIO 0-31 if the corresponding bit in bits is set. - | - | bits:= a 32 bit mask with 1 set if the corresponding GPIO is - | to be set. - | - | A returned status of PI_SOME_PERMITTED indicates that the user - | is not allowed to write to one or more of the GPIO. - | - | ... - | pi.set_bank_1(int("111110010000",2)) - | ... - | - | set_bank_2(self, bits) - | Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. - | - | bits:= a 32 bit mask with 1 set if the corresponding GPIO is - | to be set. - | - | A returned status of PI_SOME_PERMITTED indicates that the user - | is not allowed to write to one or more of the GPIO. - | - | ... - | pi.set_bank_2(0x303) - | ... - | - | set_glitch_filter(self, user_gpio, steady) - | Sets a glitch filter on a GPIO. - | - | Level changes on the GPIO are not reported unless the level - | has been stable for at least [*steady*] microseconds. The - | level is then reported. Level changes of less than [*steady*] - | microseconds are ignored. - | - | user_gpio:= 0-31 - | steady:= 0-300000 - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - | - | This filter affects the GPIO samples returned to callbacks set up - | with [*callback*] and [*wait_for_edge*]. - | - | It does not affect levels read by [*read*], - | [*read_bank_1*], or [*read_bank_2*]. - | - | Each (stable) edge will be timestamped [*steady*] - | microseconds after it was first detected. - | - | ... - | pi.set_glitch_filter(23, 100) - | ... - | - | set_mode(self, gpio, mode) - | Sets the GPIO mode. - | - | gpio:= 0-53. - | mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5. - | - | ... - | pi.set_mode( 4, pigpio.INPUT) # GPIO 4 as input - | pi.set_mode(17, pigpio.OUTPUT) # GPIO 17 as output - | pi.set_mode(24, pigpio.ALT2) # GPIO 24 as ALT2 - | ... - | - | set_noise_filter(self, user_gpio, steady, active) - | Sets a noise filter on a GPIO. - | - | Level changes on the GPIO are ignored until a level which has - | been stable for [*steady*] microseconds is detected. Level - | changes on the GPIO are then reported for [*active*] - | microseconds after which the process repeats. - | - | user_gpio:= 0-31 - | steady:= 0-300000 - | active:= 0-1000000 - | - | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER. - | - | This filter affects the GPIO samples returned to callbacks set up - | with [*callback*] and [*wait_for_edge*]. - | - | It does not affect levels read by [*read*], - | [*read_bank_1*], or [*read_bank_2*]. - | - | Level changes before and after the active period may - | be reported. Your software must be designed to cope with - | such reports. - | - | ... - | pi.set_noise_filter(23, 1000, 5000) - | ... - | - | set_pad_strength(self, pad, pad_strength) - | This function sets the pad drive strength in mA. - | - | - | pad:= 0-2, the pad to set. - | pad_strength:= 1-16 mA. - | - | Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. - | - | Pad @ GPIO - | 0 @ 0-27 - | 1 @ 28-45 - | 2 @ 46-53 - | - | ... - | pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA. - | ... - | - | set_pull_up_down(self, gpio, pud) - | Sets or clears the internal GPIO pull-up/down resistor. - | - | gpio:= 0-53. - | pud:= PUD_UP, PUD_DOWN, PUD_OFF. - | - | ... - | pi.set_pull_up_down(17, pigpio.PUD_OFF) - | pi.set_pull_up_down(23, pigpio.PUD_UP) - | pi.set_pull_up_down(24, pigpio.PUD_DOWN) - | ... - | - | set_servo_pulsewidth(self, user_gpio, pulsewidth) - | Starts (500-2500) or stops (0) servo pulses on the GPIO. - | - | user_gpio:= 0-31. - | pulsewidth:= 0 (off), - | 500 (most anti-clockwise) - 2500 (most clockwise). - | - | The selected pulsewidth will continue to be transmitted until - | changed by a subsequent call to set_servo_pulsewidth. - | - | The pulsewidths supported by servos varies and should probably - | be determined by experiment. A value of 1500 should always be - | safe and represents the mid-point of rotation. - | - | You can DAMAGE a servo if you command it to move beyond its - | limits. - | - | ... - | pi.set_servo_pulsewidth(17, 0) # off - | pi.set_servo_pulsewidth(17, 1000) # safe anti-clockwise - | pi.set_servo_pulsewidth(17, 1500) # centre - | pi.set_servo_pulsewidth(17, 2000) # safe clockwise - | ... - | - | set_watchdog(self, user_gpio, wdog_timeout) - | Sets a watchdog timeout for a GPIO. - | - | user_gpio:= 0-31. - | wdog_timeout:= 0-60000. - | - | The watchdog is nominally in milliseconds. - | - | Only one watchdog may be registered per GPIO. - | - | The watchdog may be cancelled by setting timeout to 0. - | - | Once a watchdog has been started callbacks for the GPIO - | will be triggered every timeout interval after the last - | GPIO activity. - | - | The callback will receive the special level TIMEOUT. - | - | ... - | pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23 - | pi.set_watchdog(23, 0) # cancel watchdog on GPIO 23 - | ... - | - | shell(self, shellscr, pstring='') - | This function uses the system call to execute a shell script - | with the given string as its parameter. - | - | shellscr:= the name of the script, only alphanumerics, - | '-' and '_' are allowed in the name - | pstring := the parameter string to pass to the script - | - | The exit status of the system call is returned if OK, - | otherwise PI_BAD_SHELL_STATUS. - | - | [*shellscr*] must exist in /opt/pigpio/cgi and must be executable. - | - | The returned exit status is normally 256 times that set by - | the shell script exit function. If the script can't be - | found 32512 will be returned. - | - | The following table gives some example returned statuses: - | - | Script exit status @ Returned system call status - | 1 @ 256 - | 5 @ 1280 - | 10 @ 2560 - | 200 @ 51200 - | script not found @ 32512 - | - | ... - | // pass two parameters, hello and world - | status = pi.shell("scr1", "hello world"); - | - | // pass three parameters, hello, string with spaces, and world - | status = pi.shell("scr1", "hello 'string with spaces' world"); - | - | // pass one parameter, hello string with spaces world - | status = pi.shell("scr1", "\"hello string with spaces world\""); - | ... - | - | spi_close(self, handle) - | Closes the SPI device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*spi_open*]). - | - | ... - | pi.spi_close(h) - | ... - | - | spi_open(self, spi_channel, baud, spi_flags=0) - | Returns a handle for the SPI device on the channel. Data - | will be transferred at baud bits per second. The flags - | may be used to modify the default behaviour of 4-wire - | operation, mode 0, active low chip select. - | - | 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 - | - | spi_channel:= 0-1 (0-2 for the auxiliary SPI). - | baud:= 32K-125M (values above 30M are unlikely to work). - | spi_flags:= see below. - | - | spi_flags consists of the least significant 22 bits. - | - | . . - | 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - | b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m - | . . - | - | mm defines the SPI mode. - | - | WARNING: modes 1 and 3 do not appear to work on - | the auxiliary SPI. - | - | . . - | 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 [*spi_read*], [*spi_write*], and [*spi_xfer*] functions - | transfer data packed into 1, 2, or 4 bytes according to - | the word size in bits. - | - | For bits 1-8 there will be one byte per character. - | For bits 9-16 there will be two bytes per character. - | For bits 17-32 there will be four bytes per character. - | - | Multi-byte transfers are made in least significant byte - | first order. - | - | E.g. to transfer 32 11-bit words data should - | contain 64 bytes. - | - | E.g. to transfer the 14 bit value 0x1ABC send the - | bytes 0xBC followed by 0x1A. - | - | The other bits in flags should be set to zero. - | - | ... - | # open SPI device on channel 1 in mode 3 at 50000 bits per second - | - | h = pi.spi_open(1, 50000, 3) - | ... - | - | spi_read(self, handle, count) - | Reads count bytes from the SPI device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*spi_open*]). - | count:= >0, the number of bytes to read. - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (b, d) = pi.spi_read(h, 60) # read 60 bytes from device h - | if b == 60: - | # process read data - | else: - | # error path - | ... - | - | spi_write(self, handle, data) - | Writes the data bytes to the SPI device associated with handle. - | - | handle:= >=0 (as returned by a prior call to [*spi_open*]). - | data:= the bytes to write. - | - | ... - | pi.spi_write(0, b'\x02\xc0\x80') # write 3 bytes to device 0 - | - | pi.spi_write(0, b'defgh') # write 5 bytes to device 0 - | - | pi.spi_write(0, "def") # write 3 bytes to device 0 - | - | pi.spi_write(1, [2, 192, 128]) # write 3 bytes to device 1 - | ... - | - | spi_xfer(self, handle, data) - | Writes the data bytes to the SPI device associated with handle, - | returning the data bytes read from the device. - | - | handle:= >=0 (as returned by a prior call to [*spi_open*]). - | data:= the bytes to write. - | - | The returned value is a tuple of the number of bytes read and a - | bytearray containing the bytes. If there was an error the - | number of bytes read will be less than zero (and will contain - | the error code). - | - | ... - | (count, rx_data) = pi.spi_xfer(h, b'\x01\x80\x00') - | - | (count, rx_data) = pi.spi_xfer(h, [1, 128, 0]) - | - | (count, rx_data) = pi.spi_xfer(h, b"hello") - | - | (count, rx_data) = pi.spi_xfer(h, "hello") - | ... - | - | stop(self) - | Release pigpio resources. - | - | ... - | pi.stop() - | ... - | - | stop_script(self, script_id) - | Stops a running script. - | - | script_id:= id of stored script. - | - | ... - | status = pi.stop_script(sid) - | ... - | - | store_script(self, script) - | Store a script for later execution. - | - | See [[http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts]] for - | details. - | - | script:= the script text as a series of bytes. - | - | Returns a >=0 script id if OK. - | - | ... - | sid = pi.store_script( - | b'tag 0 w 22 1 mils 100 w 22 0 mils 100 dcr p0 jp 0') - | ... - | - | update_script(self, script_id, params=None) - | Sets the parameters of a script. The script may or - | may not be running. The first parameters of the script are - | overwritten with the new values. - | - | script_id:= id of stored script. - | params:= up to 10 parameters required by the script. - | - | ... - | s = pi.update_script(sid, [par1, par2]) - | - | s = pi.update_script(sid, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - | ... - | - | wait_for_edge(self, user_gpio, edge=0, wait_timeout=60.0) - | Wait for an edge event on a GPIO. - | - | user_gpio:= 0-31. - | edge:= EITHER_EDGE, RISING_EDGE (default), or - | FALLING_EDGE. - | wait_timeout:= >=0.0 (default 60.0). - | - | The function returns when the edge is detected or after - | the number of seconds specified by timeout has expired. - | - | Do not use this function for precise timing purposes, - | the edge is only checked 20 times a second. Whenever - | you need to know the accurate time of GPIO events use - | a [*callback*] function. - | - | The function returns True if the edge is detected, - | otherwise False. - | - | ... - | if pi.wait_for_edge(23): - | print("Rising edge detected") - | else: - | print("wait for edge timed out") - | - | if pi.wait_for_edge(23, pigpio.FALLING_EDGE, 5.0): - | print("Falling edge detected") - | else: - | print("wait for falling edge timed out") - | ... - | - | wait_for_event(self, event, wait_timeout=60.0) - | Wait for an event. - | - | event:= 0-31. - | wait_timeout:= >=0.0 (default 60.0). - | - | The function returns when the event is signalled or after - | the number of seconds specified by timeout has expired. - | - | The function returns True if the event is detected, - | otherwise False. - | - | ... - | if pi.wait_for_event(23): - | print("event detected") - | else: - | print("wait for event timed out") - | ... - | - | wave_add_generic(self, pulses) - | Adds a list of pulses to the current waveform. - | - | pulses:= list of pulses to add to the waveform. - | - | Returns the new total number of pulses in the current waveform. - | - | The pulses are interleaved in time order within the existing - | waveform (if any). - | - | Merging allows the waveform to be built in parts, that is the - | settings for GPIO#1 can be added, and then GPIO#2 etc. - | - | If the added waveform is intended to start after or within - | the existing waveform then the first pulse should consist - | solely of a delay. - | - | ... - | G1=4 - | G2=24 - | - | pi.set_mode(G1, pigpio.OUTPUT) - | pi.set_mode(G2, pigpio.OUTPUT) - | - | flash_500=[] # flash every 500 ms - | flash_100=[] # flash every 100 ms - | - | # ON OFF DELAY - | - | flash_500.append(pigpio.pulse(1<=0) if OK, otherwise PI_EMPTY_WAVEFORM, - | PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - | - | The data provided by the [*wave_add_**] functions is consumed by - | this function. - | - | As many waveforms may be created as there is space available. - | The wave id is passed to [*wave_send_**] to specify the waveform - | to transmit. - | - | Normal usage would be - | - | Step 1. [*wave_clear*] to clear all waveforms and added data. - | - | Step 2. [*wave_add_**] calls to supply the waveform data. - | - | Step 3. [*wave_create*] to create the waveform and get a unique id - | - | Repeat steps 2 and 3 as needed. - | - | Step 4. [*wave_send_**] with the id of the waveform to transmit. - | - | A waveform comprises one or more pulses. - | - | A pulse specifies - | - | 1) the GPIO to be switched on at the start of the pulse. - | 2) the GPIO to be switched off at the start of the pulse. - | 3) the delay in microseconds before the next pulse. - | - | Any or all the fields can be zero. It doesn't make any sense - | to set all the fields to zero (the pulse will be ignored). - | - | When a waveform is started each pulse is executed in order with - | the specified delay between the pulse and the next. - | - | ... - | wid = pi.wave_create() - | ... - | - | wave_create_and_pad(self, percent) - | This function creates a waveform like [*wave_create*] but pads the consumed - | resources. Where percent gives the percentage of the resources to use - | (in terms of the theoretical maximum, not the current amount free). - | This allows the reuse of deleted waves while a transmission is active. - | - | Upon success a wave id greater than or equal to 0 is returned, otherwise - | PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. - | - | . . - | percent: 0-100, size of waveform as percentage of maximum available. - | . . - | - | The data provided by the [*wave_add_**] functions are consumed by this - | function. - | - | As many waveforms may be created as there is space available. The - | wave id is passed to [*wave_send_**] to specify the waveform to transmit. - | - | A usage would be the creation of two waves where one is filled while the - | other is being transmitted. Each wave is assigned 50% of the resources. - | This buffer structure allows the transmission of infinite wave sequences. - | - | Normal usage: - | - | Step 1. [*wave_clear*] to clear all waveforms and added data. - | - | Step 2. [*wave_add_**] calls to supply the waveform data. - | - | Step 3. [*wave_create_and_pad*] to create a waveform of uniform size. - | - | Step 4. [*wave_send_**] with the id of the waveform to transmit. - | - | Repeat steps 2-4 as needed. - | - | Step 5. Any wave id can now be deleted and another wave of the same size - | can be created in its place. - | - | ... - | wid = pi.wave_create_and_pad(50) - | ... - | - | wave_delete(self, wave_id) - | This function deletes the waveform with id wave_id. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | - | Wave ids are allocated in order, 0, 1, 2, etc. - | - | The wave is flagged for deletion. The resources used by the wave - | will only be reused when either of the following apply. - | - | - all waves with higher numbered wave ids have been deleted or have - | been flagged for deletion. - | - | - a new wave is created which uses exactly the same resources as - | the current wave (see the C source for gpioWaveCreate for details). - | - | ... - | pi.wave_delete(6) # delete waveform with id 6 - | - | pi.wave_delete(0) # delete waveform with id 0 - | ... - | - | wave_get_cbs(self) - | Returns the length in DMA control blocks of the current - | waveform. - | - | ... - | cbs = pi.wave_get_cbs() - | ... - | - | wave_get_max_cbs(self) - | Returns the maximum possible size of a waveform in DMA - | control blocks. - | - | ... - | cbs = pi.wave_get_max_cbs() - | ... - | - | wave_get_max_micros(self) - | Returns the maximum possible size of a waveform in microseconds. - | - | ... - | micros = pi.wave_get_max_micros() - | ... - | - | wave_get_max_pulses(self) - | Returns the maximum possible size of a waveform in pulses. - | - | ... - | pulses = pi.wave_get_max_pulses() - | ... - | - | wave_get_micros(self) - | Returns the length in microseconds of the current waveform. - | - | ... - | micros = pi.wave_get_micros() - | ... - | - | wave_get_pulses(self) - | Returns the length in pulses of the current waveform. - | - | ... - | pulses = pi.wave_get_pulses() - | ... - | - | wave_send_once(self, wave_id) - | Transmits the waveform with id wave_id. The waveform is sent - | once. - | - | NOTE: Any hardware PWM started by [*hardware_PWM*] will - | be cancelled. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | - | Returns the number of DMA control blocks used in the waveform. - | - | ... - | cbs = pi.wave_send_once(wid) - | ... - | - | wave_send_repeat(self, wave_id) - | Transmits the waveform with id wave_id. The waveform repeats - | until wave_tx_stop is called or another call to [*wave_send_**] - | is made. - | - | NOTE: Any hardware PWM started by [*hardware_PWM*] will - | be cancelled. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | - | Returns the number of DMA control blocks used in the waveform. - | - | ... - | cbs = pi.wave_send_repeat(wid) - | ... - | - | wave_send_using_mode(self, wave_id, mode) - | Transmits the waveform with id wave_id using mode mode. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | mode:= WAVE_MODE_ONE_SHOT, WAVE_MODE_REPEAT, - | WAVE_MODE_ONE_SHOT_SYNC, or WAVE_MODE_REPEAT_SYNC. - | - | WAVE_MODE_ONE_SHOT: same as [*wave_send_once*]. - | - | WAVE_MODE_REPEAT same as [*wave_send_repeat*]. - | - | WAVE_MODE_ONE_SHOT_SYNC same as [*wave_send_once*] but tries - | to sync with the previous waveform. - | - | WAVE_MODE_REPEAT_SYNC same as [*wave_send_repeat*] but tries - | to sync with the previous waveform. - | - | WARNING: bad things may happen if you delete the previous - | waveform before it has been synced to the new waveform. - | - | NOTE: Any hardware PWM started by [*hardware_PWM*] will - | be cancelled. - | - | wave_id:= >=0 (as returned by a prior call to [*wave_create*]). - | - | Returns the number of DMA control blocks used in the waveform. - | - | ... - | cbs = pi.wave_send_using_mode(wid, WAVE_MODE_REPEAT_SYNC) - | ... - | - | wave_tx_at(self) - | Returns the id of the waveform currently being - | transmitted. - | - | Returns the waveform id or one of the following special - | values: - | - | WAVE_NOT_FOUND (9998) - transmitted wave not found. - | NO_TX_WAVE (9999) - no wave being transmitted. - | - | ... - | wid = pi.wave_tx_at() - | ... - | - | wave_tx_busy(self) - | Returns 1 if a waveform is currently being transmitted, - | otherwise 0. - | - | ... - | pi.wave_send_once(0) # send first waveform - | - | while pi.wave_tx_busy(): # wait for waveform to be sent - | time.sleep(0.1) - | - | pi.wave_send_once(1) # send next waveform - | ... - | - | wave_tx_repeat(self) - | This function is deprecated and has beeen removed. - | - | Use [*wave_create*]/[*wave_send_**] instead. - | - | wave_tx_start(self) - | This function is deprecated and has been removed. - | - | Use [*wave_create*]/[*wave_send_**] instead. - | - | wave_tx_stop(self) - | Stops the transmission of the current waveform. - | - | This function is intended to stop a waveform started with - | wave_send_repeat. - | - | ... - | pi.wave_send_repeat(3) - | - | time.sleep(5) - | - | pi.wave_tx_stop() - | ... - | - | write(self, gpio, level) - | Sets the GPIO level. - | - | GPIO:= 0-53. - | level:= 0, 1. - | - | If PWM or servo pulses are active on the GPIO they are - | switched off. - | - | ... - | pi.set_mode(17, pigpio.OUTPUT) - | - | pi.write(17,0) - | print(pi.read(17)) - | 0 - | - | pi.write(17,1) - | print(pi.read(17)) - | 1 - | ... - - class pulse - | A class to store pulse information. - | - | Methods defined here: - | - | __init__(self, gpio_on, gpio_off, delay) - | Initialises a pulse. - | - | gpio_on:= the GPIO to switch on at the start of the pulse. - | gpio_off:= the GPIO to switch off at the start of the pulse. - | delay:= the delay in microseconds before the next pulse. - -FUNCTIONS - error_text(errnum) - Returns a text description of a pigpio error. - - errnum:= <0, the error number - - ... - print(pigpio.error_text(-5)) - level not 0-1 - ... - - tickDiff(t1, t2) - Returns the microsecond difference between two ticks. - - t1:= the earlier tick - t2:= the later tick - - ... - print(pigpio.tickDiff(4294967272, 12)) - 36 - ... - - u2i(uint32) - Converts a 32 bit unsigned number to signed. - - uint32:= an unsigned 32 bit number - - ... - print(u2i(4294967272)) - -24 - print(u2i(37)) - 37 - ... - - xref() - active: 0-1000000 - The number of microseconds level changes are reported for once - a noise filter has been triggered (by [*steady*] microseconds of - a stable level). - - - arg1: - An unsigned argument passed to a user customised function. Its - meaning is defined by the customiser. - - arg2: - An unsigned argument passed to a user customised function. Its - meaning is defined by the customiser. - - argx: - An array of bytes passed to a user customised function. - Its meaning and content is defined by the customiser. - - baud: - The speed of serial communication (I2C, SPI, serial link, waves) - in bits per second. - - bb_bits: 1-32 - The number of data bits to be used when adding serial data to a - waveform. - - bb_stop: 2-8 - The number of (half) stop bits to be used when adding serial data - to a waveform. - - bit: 0-1 - A value of 0 or 1. - - bits: 32 bit number - A mask used to select GPIO to be operated on. If bit n is set - then GPIO n is selected. A convenient way of setting bit n is to - bit or in the value (1<=1 - The length of a pulse in microseconds. - - dutycycle: 0-range_ - A number between 0 and range_. - - The dutycycle sets the proportion of time on versus time off during each - PWM cycle. - - Dutycycle @ On time - 0 @ Off - range_ * 0.25 @ 25% On - range_ * 0.50 @ 50% On - range_ * 0.75 @ 75% On - range_ @ Fully On - - edge: 0-2 - - . . - EITHER_EDGE = 2 - FALLING_EDGE = 1 - RISING_EDGE = 0 - . . - - errnum: <0 - - . . - PI_BAD_USER_GPIO = -2 - PI_BAD_GPIO = -3 - PI_BAD_MODE = -4 - PI_BAD_LEVEL = -5 - PI_BAD_PUD = -6 - PI_BAD_PULSEWIDTH = -7 - PI_BAD_DUTYCYCLE = -8 - PI_BAD_WDOG_TIMEOUT = -15 - PI_BAD_DUTYRANGE = -21 - PI_NO_HANDLE = -24 - PI_BAD_HANDLE = -25 - PI_BAD_WAVE_BAUD = -35 - PI_TOO_MANY_PULSES = -36 - PI_TOO_MANY_CHARS = -37 - PI_NOT_SERIAL_GPIO = -38 - PI_NOT_PERMITTED = -41 - PI_SOME_PERMITTED = -42 - PI_BAD_WVSC_COMMND = -43 - PI_BAD_WVSM_COMMND = -44 - PI_BAD_WVSP_COMMND = -45 - PI_BAD_PULSELEN = -46 - PI_BAD_SCRIPT = -47 - PI_BAD_SCRIPT_ID = -48 - PI_BAD_SER_OFFSET = -49 - PI_GPIO_IN_USE = -50 - PI_BAD_SERIAL_COUNT = -51 - PI_BAD_PARAM_NUM = -52 - PI_DUP_TAG = -53 - PI_TOO_MANY_TAGS = -54 - PI_BAD_SCRIPT_CMD = -55 - PI_BAD_VAR_NUM = -56 - PI_NO_SCRIPT_ROOM = -57 - PI_NO_MEMORY = -58 - PI_SOCK_READ_FAILED = -59 - PI_SOCK_WRIT_FAILED = -60 - PI_TOO_MANY_PARAM = -61 - PI_SCRIPT_NOT_READY = -62 - PI_BAD_TAG = -63 - PI_BAD_MICS_DELAY = -64 - PI_BAD_MILS_DELAY = -65 - PI_BAD_WAVE_ID = -66 - PI_TOO_MANY_CBS = -67 - PI_TOO_MANY_OOL = -68 - PI_EMPTY_WAVEFORM = -69 - PI_NO_WAVEFORM_ID = -70 - PI_I2C_OPEN_FAILED = -71 - PI_SER_OPEN_FAILED = -72 - PI_SPI_OPEN_FAILED = -73 - PI_BAD_I2C_BUS = -74 - PI_BAD_I2C_ADDR = -75 - PI_BAD_SPI_CHANNEL = -76 - PI_BAD_FLAGS = -77 - PI_BAD_SPI_SPEED = -78 - PI_BAD_SER_DEVICE = -79 - PI_BAD_SER_SPEED = -80 - PI_BAD_PARAM = -81 - PI_I2C_WRITE_FAILED = -82 - PI_I2C_READ_FAILED = -83 - PI_BAD_SPI_COUNT = -84 - PI_SER_WRITE_FAILED = -85 - PI_SER_READ_FAILED = -86 - PI_SER_READ_NO_DATA = -87 - PI_UNKNOWN_COMMAND = -88 - PI_SPI_XFER_FAILED = -89 - PI_NO_AUX_SPI = -91 - PI_NOT_PWM_GPIO = -92 - PI_NOT_SERVO_GPIO = -93 - PI_NOT_HCLK_GPIO = -94 - PI_NOT_HPWM_GPIO = -95 - PI_BAD_HPWM_FREQ = -96 - PI_BAD_HPWM_DUTY = -97 - PI_BAD_HCLK_FREQ = -98 - PI_BAD_HCLK_PASS = -99 - PI_HPWM_ILLEGAL = -100 - PI_BAD_DATABITS = -101 - PI_BAD_STOPBITS = -102 - PI_MSG_TOOBIG = -103 - PI_BAD_MALLOC_MODE = -104 - PI_BAD_SMBUS_CMD = -107 - PI_NOT_I2C_GPIO = -108 - PI_BAD_I2C_WLEN = -109 - PI_BAD_I2C_RLEN = -110 - PI_BAD_I2C_CMD = -111 - PI_BAD_I2C_BAUD = -112 - PI_CHAIN_LOOP_CNT = -113 - PI_BAD_CHAIN_LOOP = -114 - PI_CHAIN_COUNTER = -115 - PI_BAD_CHAIN_CMD = -116 - PI_BAD_CHAIN_DELAY = -117 - PI_CHAIN_NESTING = -118 - PI_CHAIN_TOO_BIG = -119 - PI_DEPRECATED = -120 - PI_BAD_SER_INVERT = -121 - PI_BAD_FOREVER = -124 - PI_BAD_FILTER = -125 - PI_BAD_PAD = -126 - PI_BAD_STRENGTH = -127 - PI_FIL_OPEN_FAILED = -128 - PI_BAD_FILE_MODE = -129 - PI_BAD_FILE_FLAG = -130 - PI_BAD_FILE_READ = -131 - PI_BAD_FILE_WRITE = -132 - PI_FILE_NOT_ROPEN = -133 - PI_FILE_NOT_WOPEN = -134 - PI_BAD_FILE_SEEK = -135 - PI_NO_FILE_MATCH = -136 - PI_NO_FILE_ACCESS = -137 - PI_FILE_IS_A_DIR = -138 - PI_BAD_SHELL_STATUS = -139 - PI_BAD_SCRIPT_NAME = -140 - PI_BAD_SPI_BAUD = -141 - PI_NOT_SPI_GPIO = -142 - PI_BAD_EVENT_ID = -143 - PI_CMD_INTERRUPTED = -144 - PI_NOT_ON_BCM2711 = -145 - PI_ONLY_ON_BCM2711 = -146 - . . - - event:0-31 - An event is a signal used to inform one or more consumers - to start an action. - - file_mode: - The mode may have the following values - - . . - FILE_READ 1 - FILE_WRITE 2 - FILE_RW 3 - . . - - The following values can be or'd into the file open mode - - . . - FILE_APPEND 4 - FILE_CREATE 8 - FILE_TRUNC 16 - . . - - file_name: - A full file path. To be accessible the path must match - an entry in /opt/pigpio/access. - - fpattern: - A file path which may contain wildcards. To be accessible the path - must match an entry in /opt/pigpio/access. - - frequency: 0-40000 - Defines the frequency to be used for PWM on a GPIO. - The closest permitted frequency will be used. - - func: - A user supplied callback function. - - gpio: 0-53 - A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. - - 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 [*get_hardware_revision*]. - - 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 - - - - - . . - - gpio_off: - A mask used to select GPIO to be operated on. See [*bits*]. - - This mask selects the GPIO to be switched off at the start - of a pulse. - - gpio_on: - A mask used to select GPIO to be operated on. See [*bits*]. - - This mask selects the GPIO to be switched on at the start - of a pulse. - - handle: >=0 - A number referencing an object opened by one of the following - - [*file_open*] - [*i2c_open*] - [*notify_open*] - [*serial_open*] - [*spi_open*] - - host: - The name or IP address of the Pi running the pigpio daemon. - - i2c_address: 0-0x7F - The address of a device on the I2C bus. - - i2c_bus: >=0 - An I2C bus number. - - i2c_flags: 0 - No I2C flags are currently defined. - - invert: 0-1 - A flag used to set normal or inverted bit bang serial data - level logic. - - level: 0-1 (2) - - . . - CLEAR = 0 - HIGH = 1 - LOW = 0 - OFF = 0 - ON = 1 - SET = 1 - TIMEOUT = 2 # only returned for a watchdog timeout - . . - - MISO: - The GPIO used for the MISO signal when bit banging SPI. - - mode: - - 1.The operational mode of a GPIO, normally INPUT or OUTPUT. - - . . - ALT0 = 4 - ALT1 = 5 - ALT2 = 6 - ALT3 = 7 - ALT4 = 3 - ALT5 = 2 - INPUT = 0 - OUTPUT = 1 - . . - - 2. The mode of waveform transmission. - - . . - WAVE_MODE_ONE_SHOT = 0 - WAVE_MODE_REPEAT = 1 - WAVE_MODE_ONE_SHOT_SYNC = 2 - WAVE_MODE_REPEAT_SYNC = 3 - . . - - MOSI: - The GPIO used for the MOSI signal when bit banging SPI. - - offset: >=0 - The offset wave data starts from the beginning of the waveform - being currently defined. - - pad: 0-2 - A set of GPIO which share common drivers. - - Pad @ GPIO - 0 @ 0-27 - 1 @ 28-45 - 2 @ 46-53 - - pad_strength: 1-16 - The mA which may be drawn from each GPIO whilst still guaranteeing the - high and low levels. - - params: 32 bit number - When scripts are started they can receive up to 10 parameters - to define their operation. - - percent:: 0-100 - The size of waveform as percentage of maximum available. - - port: - The port used by the pigpio daemon, defaults to 8888. - - pstring: - The string to be passed to a [*shell*] script to be executed. - - pud: 0-2 - . . - PUD_DOWN = 1 - PUD_OFF = 0 - PUD_UP = 2 - . . - - pulse_len: 1-100 - The length of the trigger pulse in microseconds. - - pulses: - A list of class pulse objects defining the characteristics of a - waveform. - - pulsewidth: - The servo pulsewidth in microseconds. 0 switches pulses off. - - PWMduty: 0-1000000 (1M) - The hardware PWM dutycycle. - - PWMfreq: 1-125M (1-187.5M for the BCM2711) - The hardware PWM frequency. - - range_: 25-40000 - Defines the limits for the [*dutycycle*] parameter. - - range_ defaults to 255. - - reg: 0-255 - An I2C device register. The usable registers depend on the - actual device. - - retMax: >=0 - The maximum number of bytes a user customised function - should return, default 8192. - - SCL: - The user GPIO to use for the clock when bit banging I2C. - - SCLK:: - The GPIO used for the SCLK signal when bit banging SPI. - - script: - The text of a script to store on the pigpio daemon. - - script_id: >=0 - A number referencing a script created by [*store_script*]. - - SDA: - The user GPIO to use for data when bit banging I2C. - - seek_from: 0-2 - Direction to seek for [*file_seek*]. - - . . - FROM_START=0 - FROM_CURRENT=1 - FROM_END=2 - . . - - seek_offset: - The number of bytes to move forward (positive) or backwards - (negative) from the seek position (start, current, or end of file). - - ser_flags: 32 bit - No serial flags are currently defined. - - serial_*: - One of the serial_ functions. - - shellscr: - The name of a shell script. The script must exist - in /opt/pigpio/cgi and must be executable. - - show_errors: - Controls the display of pigpio daemon connection failures. - The default of True prints the probable failure reasons to - standard output. - - spi_channel: 0-2 - A SPI channel. - - spi_flags: 32 bit - See [*spi_open*]. - - steady: 0-300000 - - The number of microseconds level changes must be stable for - before reporting the level changed ([*set_glitch_filter*]) - or triggering the active part of a noise filter - ([*set_noise_filter*]). - - t1: - A tick (earlier). - - t2: - A tick (later). - - tty: - A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0 - - uint32: - An unsigned 32 bit number. - - user_gpio: 0-31 - A Broadcom numbered GPIO. - - All the user GPIO are in the range 0-31. - - Not all the GPIO within this range are usable, some are reserved - for system use. - - See [*gpio*]. - - wait_timeout: 0.0 - - The number of seconds to wait in [*wait_for_edge*] before timing out. - - wave_add_*: - One of the following - - [*wave_add_new*] - [*wave_add_generic*] - [*wave_add_serial*] - - wave_id: >=0 - A number referencing a wave created by [*wave_create*]. - - wave_send_*: - One of the following - - [*wave_send_once*] - [*wave_send_repeat*] - - wdog_timeout: 0-60000 - Defines a GPIO watchdog timeout in milliseconds. If no level - change is detected on the GPIO for timeout millisecond a watchdog - timeout report is issued (with level TIMEOUT). - - word_val: 0-65535 - A whole number. - -DATA - ALT0 = 4 - ALT1 = 5 - ALT2 = 6 - ALT3 = 7 - ALT4 = 3 - ALT5 = 2 - CLEAR = 0 - EITHER_EDGE = 2 - EVENT_BSC = 31 - FALLING_EDGE = 1 - FILE_APPEND = 4 - FILE_CREATE = 8 - FILE_READ = 1 - FILE_RW = 3 - FILE_TRUNC = 16 - FILE_WRITE = 2 - FROM_CURRENT = 1 - FROM_END = 2 - FROM_START = 0 - HIGH = 1 - INPUT = 0 - LOW = 0 - NO_TX_WAVE = 9999 - NTFY_FLAGS_ALIVE = 64 - NTFY_FLAGS_EVENT = 128 - NTFY_FLAGS_GPIO = 31 - NTFY_FLAGS_WDOG = 32 - OFF = 0 - ON = 1 - OUTPUT = 1 - PI_BAD_CHAIN_CMD = -116 - PI_BAD_CHAIN_DELAY = -117 - PI_BAD_CHAIN_LOOP = -114 - PI_BAD_DATABITS = -101 - PI_BAD_DUTYCYCLE = -8 - PI_BAD_DUTYRANGE = -21 - PI_BAD_EVENT_ID = -143 - PI_BAD_FILE_FLAG = -130 - PI_BAD_FILE_MODE = -129 - PI_BAD_FILE_READ = -131 - PI_BAD_FILE_SEEK = -135 - PI_BAD_FILE_WRITE = -132 - PI_BAD_FILTER = -125 - PI_BAD_FLAGS = -77 - PI_BAD_FOREVER = -124 - PI_BAD_GPIO = -3 - PI_BAD_HANDLE = -25 - PI_BAD_HCLK_FREQ = -98 - PI_BAD_HCLK_PASS = -99 - PI_BAD_HPWM_DUTY = -97 - PI_BAD_HPWM_FREQ = -96 - PI_BAD_I2C_ADDR = -75 - PI_BAD_I2C_BAUD = -112 - PI_BAD_I2C_BUS = -74 - PI_BAD_I2C_CMD = -111 - PI_BAD_I2C_RLEN = -110 - PI_BAD_I2C_WLEN = -109 - PI_BAD_LEVEL = -5 - PI_BAD_MALLOC_MODE = -104 - PI_BAD_MICS_DELAY = -64 - PI_BAD_MILS_DELAY = -65 - PI_BAD_MODE = -4 - PI_BAD_PAD = -126 - PI_BAD_PARAM = -81 - PI_BAD_PARAM_NUM = -52 - PI_BAD_PUD = -6 - PI_BAD_PULSELEN = -46 - PI_BAD_PULSEWIDTH = -7 - PI_BAD_SCRIPT = -47 - PI_BAD_SCRIPT_CMD = -55 - PI_BAD_SCRIPT_ID = -48 - PI_BAD_SCRIPT_NAME = -140 - PI_BAD_SERIAL_COUNT = -51 - PI_BAD_SER_DEVICE = -79 - PI_BAD_SER_INVERT = -121 - PI_BAD_SER_OFFSET = -49 - PI_BAD_SER_SPEED = -80 - PI_BAD_SHELL_STATUS = -139 - PI_BAD_SMBUS_CMD = -107 - PI_BAD_SPI_BAUD = -141 - PI_BAD_SPI_CHANNEL = -76 - PI_BAD_SPI_COUNT = -84 - PI_BAD_SPI_SPEED = -78 - PI_BAD_STOPBITS = -102 - PI_BAD_STRENGTH = -127 - PI_BAD_TAG = -63 - PI_BAD_USER_GPIO = -2 - PI_BAD_VAR_NUM = -56 - PI_BAD_WAVE_BAUD = -35 - PI_BAD_WAVE_ID = -66 - PI_BAD_WDOG_TIMEOUT = -15 - PI_BAD_WVSC_COMMND = -43 - PI_BAD_WVSM_COMMND = -44 - PI_BAD_WVSP_COMMND = -45 - PI_CHAIN_COUNTER = -115 - PI_CHAIN_LOOP_CNT = -113 - PI_CHAIN_NESTING = -118 - PI_CHAIN_TOO_BIG = -119 - PI_CMD_INTERRUPTED = -144 - PI_DEPRECATED = -120 - PI_DUP_TAG = -53 - PI_EMPTY_WAVEFORM = -69 - PI_FILE_IS_A_DIR = -138 - PI_FILE_NOT_ROPEN = -133 - PI_FILE_NOT_WOPEN = -134 - PI_FIL_OPEN_FAILED = -128 - PI_GPIO_IN_USE = -50 - PI_HPWM_ILLEGAL = -100 - PI_I2C_OPEN_FAILED = -71 - PI_I2C_READ_FAILED = -83 - PI_I2C_WRITE_FAILED = -82 - PI_MSG_TOOBIG = -103 - PI_NOT_HCLK_GPIO = -94 - PI_NOT_HPWM_GPIO = -95 - PI_NOT_I2C_GPIO = -108 - PI_NOT_ON_BCM2711 = -145 - PI_NOT_PERMITTED = -41 - PI_NOT_PWM_GPIO = -92 - PI_NOT_SERIAL_GPIO = -38 - PI_NOT_SERVO_GPIO = -93 - PI_NOT_SPI_GPIO = -142 - PI_NO_AUX_SPI = -91 - PI_NO_FILE_ACCESS = -137 - PI_NO_FILE_MATCH = -136 - PI_NO_HANDLE = -24 - PI_NO_MEMORY = -58 - PI_NO_SCRIPT_ROOM = -57 - PI_NO_WAVEFORM_ID = -70 - PI_ONLY_ON_BCM2711 = -146 - PI_SCRIPT_FAILED = 4 - PI_SCRIPT_HALTED = 1 - PI_SCRIPT_INITING = 0 - PI_SCRIPT_NOT_READY = -62 - PI_SCRIPT_RUNNING = 2 - PI_SCRIPT_WAITING = 3 - PI_SER_OPEN_FAILED = -72 - PI_SER_READ_FAILED = -86 - PI_SER_READ_NO_DATA = -87 - PI_SER_WRITE_FAILED = -85 - PI_SOCK_READ_FAILED = -59 - PI_SOCK_WRIT_FAILED = -60 - PI_SOME_PERMITTED = -42 - PI_SPI_OPEN_FAILED = -73 - PI_SPI_XFER_FAILED = -89 - PI_TOO_MANY_CBS = -67 - PI_TOO_MANY_CHARS = -37 - PI_TOO_MANY_OOL = -68 - PI_TOO_MANY_PARAM = -61 - PI_TOO_MANY_PULSES = -36 - PI_TOO_MANY_TAGS = -54 - PI_UNKNOWN_COMMAND = -88 - PUD_DOWN = 1 - PUD_OFF = 0 - PUD_UP = 2 - RISING_EDGE = 0 - SET = 1 - SPI_CPHA = 1 - SPI_CPOL = 2 - SPI_CS_HIGH_ACTIVE = 4 - SPI_MODE_0 = 0 - SPI_MODE_1 = 1 - SPI_MODE_2 = 2 - SPI_MODE_3 = 3 - SPI_RX_LSBFIRST = 32768 - SPI_TX_LSBFIRST = 16384 - TIMEOUT = 2 - VERSION = '1.46' - WAVE_MODE_ONE_SHOT = 0 - WAVE_MODE_ONE_SHOT_SYNC = 2 - WAVE_MODE_REPEAT = 1 - WAVE_MODE_REPEAT_SYNC = 3 - WAVE_NOT_FOUND = 9998 - exceptions = True - - diff --git a/util/pigpiod b/util/pigpiod deleted file mode 100755 index 59ba142..0000000 --- a/util/pigpiod +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: pigpiod -# Required-Start: -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: pigpio daemon -# Description: pigpio daemon required to control GPIO pins via pigpio $ -### END INIT INFO - -# Actions -case "$1" in - start) - pigpiod - ;; - stop) - pkill pigpiod - ;; - restart) - pkill pigpiod - pigpiod - ;; - *) - echo "Usage: $0 start" >&2 - exit 3 - ;; -esac - -exit 0 - -- cgit v1.2.3 From fc37a8c8677884492ddfb8c4c090e6d1525472a4 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 31 May 2020 13:44:14 -0500 Subject: Revert "Issue #220 Calling exit from a signal handler is not safe." --- pigpio.c | 6 +++--- pigpio.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pigpio.c b/pigpio.c index 5e04e0a..5b11476 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 7602 */ +/* pigpio version 76 */ /* include ------------------------------------------------------- */ @@ -5621,7 +5621,7 @@ static void sigHandler(int signum) default: DBG(DBG_ALWAYS, "Unhandled signal %d, terminating\n", signum); gpioTerminate(); - _exit(); + exit(-1); } } } @@ -5631,7 +5631,7 @@ static void sigHandler(int signum) DBG(DBG_ALWAYS, "Unhandled signal %d, terminating\n", signum); gpioTerminate(); - _exit(); + exit(-1); } } diff --git a/pigpio.h b/pigpio.h index 56a5f11..7aa6f78 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7602 +#define PIGPIO_VERSION 7601 /*TEXT -- cgit v1.2.3 From bea536389f38dfd57ea565c4af1197a2800b077d Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 31 May 2020 14:26:37 -0500 Subject: Fix waveCBsOOLs tallys for 2d dma stride. --- pigpio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 5b11476..2c52870 100644 --- a/pigpio.c +++ b/pigpio.c @@ -3000,7 +3000,9 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) for (i=0; i Date: Mon, 25 May 2020 16:00:22 -0400 Subject: Fix issue #353, initialising glitch filter --- pigpio.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/pigpio.c b/pigpio.c index 2c52870..6ef6ce9 100644 --- a/pigpio.c +++ b/pigpio.c @@ -950,6 +950,7 @@ typedef struct uint32_t nfRBitV; uint32_t gfSteadyUs; + uint8_t gfInitialised; uint32_t gfTick; uint32_t gfLBitV; uint32_t gfRBitV; @@ -5685,7 +5686,7 @@ unsigned alert_delays[]= static void alertGlitchFilter(gpioSample_t *sample, int numSamples) { int i, j, diff; - uint32_t steadyUs, changedTick, RBitV, LBitV; + uint32_t steadyUs, changedTick, RBitV, LBitV, initialised; uint32_t bit, bitV; for (i=0; i<=PI_MAX_USER_GPIO; i++) @@ -5694,6 +5695,17 @@ static void alertGlitchFilter(gpioSample_t *sample, int numSamples) if (monitorBits & bit & gFilterBits) { + initialised = gpioAlert[i].gfInitialised; + if (!initialised && numSamples > 0) + { + /* Initialise filter with first sample */ + bitV = sample[0].level & bit; + gpioAlert[i].gfRBitV = bitV; + gpioAlert[i].gfLBitV = bitV; + gpioAlert[i].gfTick = sample[0].tick; + gpioAlert[i].gfInitialised = 1; + } + steadyUs = gpioAlert[i].gfSteadyUs; RBitV = gpioAlert[i].gfRBitV; LBitV = gpioAlert[i].gfLBitV; @@ -12335,18 +12347,8 @@ int gpioGlitchFilter(unsigned gpio, unsigned steady) if (steady) { - gpioAlert[gpio].gfTick = systReg[SYST_CLO]; - - if (gpioRead_Bits_0_31() & (1< Date: Thu, 25 Jun 2020 12:34:45 -0500 Subject: Fix issue #355, python module event_callback documentation. --- pigpio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pigpio.py b/pigpio.py index 978aff2..2d418b1 100644 --- a/pigpio.py +++ b/pigpio.py @@ -5055,7 +5055,7 @@ class pi(): by calling the tally function. The count may be reset to zero by calling the reset_tally function. - The callback may be cancelled by calling the event_cancel function. + The callback may be canceled by calling the cancel function. An event may have multiple callbacks (although I can't think of a reason to do so). @@ -5072,7 +5072,7 @@ class pi(): cb2.reset_tally() - cb1.event_cancel() # To cancel callback cb1. + cb1.cancel() # To cancel callback cb1. ... """ -- cgit v1.2.3 From 11c75ee5eaf0b7a32ca5abbb7dfec0bdb25c2e86 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 25 Jun 2020 22:26:41 -0500 Subject: Fix issue #356, document wave_tx_at API is not supported on chained waves. --- pigpio.h | 2 +- pigpio.py | 2 +- pigpiod_if2.h | 2 +- pigs.1 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pigpio.h b/pigpio.h index 7aa6f78..c318515 100644 --- a/pigpio.h +++ b/pigpio.h @@ -2181,7 +2181,7 @@ D*/ int gpioWaveTxAt(void); /*D This function returns the id of the waveform currently being -transmitted. +transmitted using [*gpioWaveTxSend*]. Chained waves are not supported. Returns the waveform id or one of the following special values: diff --git a/pigpio.py b/pigpio.py index 2d418b1..7fc80a5 100644 --- a/pigpio.py +++ b/pigpio.py @@ -2466,7 +2466,7 @@ class pi(): def wave_tx_at(self): """ Returns the id of the waveform currently being - transmitted. + transmitted using [*wave_send**]. Chained waves are not supported. Returns the waveform id or one of the following special values: diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 79d0223..9700cc0 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -1609,7 +1609,7 @@ D*/ int wave_tx_at(int pi); /*D This function returns the id of the waveform currently being -transmitted. +transmitted by [*wave_send**]. Chained waves are not supported. . . pi: >=0 (as returned by [*pigpio_start*]). diff --git a/pigs.1 b/pigs.1 index b315910..8fa4337 100644 --- a/pigs.1 +++ b/pigs.1 @@ -4823,7 +4823,7 @@ $ pigs wvas 7 38400 8 2 0 0x41 0x42 .br This command returns the id of the waveform currently -being transmitted. +being transmitted. Note: chained waves are not supported. .br Returns the waveform id or one of the following special -- cgit v1.2.3 From 5e0688951554359f9c6ce423f2738509f714df41 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 25 Jun 2020 23:02:41 -0500 Subject: Remove deprecated gpioCfgInternals API. Fix issue #341. --- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/defs/pigs.def | 2 +- pigpio.c | 38 -------------------------------------- pigpio.h | 23 ++++++++++------------- 4 files changed, 11 insertions(+), 52 deletions(-) diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index 6ac1161..a26ab8e 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/defs/pigs.def b/DOC/src/defs/pigs.def index 7c3ef07..f678126 100644 --- a/DOC/src/defs/pigs.def +++ b/DOC/src/defs/pigs.def @@ -2610,7 +2610,7 @@ $ pigs wvas 7 38400 8 2 0 0x41 0x42 WVTAT :: This command returns the id of the waveform currently -being transmitted. +being transmitted. Chained waves are not supported. Returns the waveform id or one of the following special values: diff --git a/pigpio.c b/pigpio.c index 6ef6ce9..4bee29a 100644 --- a/pigpio.c +++ b/pigpio.c @@ -14002,44 +14002,6 @@ int gpioCfgSetInternals(uint32_t cfgVal) return 0; } -int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal) -{ - int retVal = PI_BAD_CFG_INTERNAL; - - DBG(DBG_USER, "cfgWhat=%u, cfgVal=%d", cfgWhat, cfgVal); - - switch(cfgWhat) - { - case 562484977: - - if (cfgVal) gpioCfg.internals |= PI_CFG_STATS; - else gpioCfg.internals &= (~PI_CFG_STATS); - - DBG(DBG_ALWAYS, "show stats is %u", cfgVal); - - retVal = 0; - - break; - - case 984762879: - - if ((cfgVal >= DBG_ALWAYS) && (cfgVal <= DBG_MAX_LEVEL)) - { - - gpioCfg.dbgLevel = cfgVal; - gpioCfg.internals = (gpioCfg.internals & (~0xF)) | cfgVal; - - DBG(DBG_ALWAYS, "Debug level is %u", cfgVal); - - retVal = 0; - } - - break; - } - - return retVal; -} - /* include any user customisations */ diff --git a/pigpio.h b/pigpio.h index c318515..a24e074 100644 --- a/pigpio.h +++ b/pigpio.h @@ -106,6 +106,15 @@ return error PI_NOT_INITIALISED. If the library is initialised the [*gpioCfg**] functions will return error PI_INITIALISED. +If you intend to rely on signals sent to your application, you should +turn off the internal signal handling as show in this example: +. . +int cfg = gpioCfgGetInternals(); +cfg |= PI_CFG_NOSIGHANDLER; // (1<<10) +gpioCfgSetInternals(cfg); +int status = gpioInitialise(); +. . + TEXT*/ /*OVERVIEW @@ -377,7 +386,6 @@ gpioCfgSocketPort Configure socket port gpioCfgMemAlloc Configure DMA memory allocation mode gpioCfgNetAddr Configure allowed network addresses -gpioCfgInternals Configure misc. internals (DEPRECATED) gpioCfgGetInternals Get internal configuration settings gpioCfgSetInternals Set internal configuration settings @@ -4975,18 +4983,6 @@ numSockAddr: 0-256 (0 means all addresses allowed) D*/ -/*F*/ -int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal); -/*D -Used to tune internal settings. - -. . -cfgWhat: see source code - cfgVal: see source code -. . -D*/ - - /*F*/ uint32_t gpioCfgGetInternals(void); /*D @@ -5003,6 +4999,7 @@ settings. . . cfgVal: see source code . . + D*/ -- cgit v1.2.3 From 342feb43f247f7a57c8bc0e39461f050d2a773ce Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Fri, 26 Jun 2020 16:20:36 -0500 Subject: Bump version and generate docs. --- .gitignore | 4 +++- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes pigpio.3 | 42 +++++++++++++++++++++++------------------- pigpio.c | 2 +- pigpio.h | 2 +- pigpiod_if2.3 | 2 +- pigs.1 | 2 +- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 39331b5..dad25ca 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,9 @@ __pycache__ build dist *.egg-info -wavepad_jitter.py + +tmp/ + # DOC files DOC/dbase/pigpio.sqlite.* DOC/tmp diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index a26ab8e..ba61140 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/pigpio.3 b/pigpio.3 index c878cbd..0871b71 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -189,6 +189,24 @@ error PI_INITIALISED. .br +.br +If you intend to rely on signals sent to your application, you should +turn off the internal signal handling as show in this example: + +.EX +int cfg = gpioCfgGetInternals(); +.br +cfg |= PI_CFG_NOSIGHANDLER; // (1<<10) +.br +gpioCfgSetInternals(cfg); +.br +int status = gpioInitialise(); +.br + +.EE + +.br + .br .SH OVERVIEW @@ -689,8 +707,6 @@ gpioCfgMemAlloc Configure DMA memory allocation mode gpioCfgNetAddr Configure allowed network addresses .br -.br -gpioCfgInternals Configure misc. internals (DEPRECATED) .br gpioCfgGetInternals Get internal configuration settings .br @@ -3026,7 +3042,7 @@ int main(int argc, char *argv[]) .IP "\fBint gpioWaveTxAt(void)\fP" .IP "" 4 This function returns the id of the waveform currently being -transmitted. +transmitted using \fBgpioWaveTxSend\fP. Chained waves are not supported. .br @@ -7896,22 +7912,6 @@ numSockAddr: 0-256 (0 means all addresses allowed) .EE -.IP "\fBint gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)\fP" -.IP "" 4 -Used to tune internal settings. - -.br - -.br - -.EX -cfgWhat: see source code -.br - cfgVal: see source code -.br - -.EE - .IP "\fBuint32_t gpioCfgGetInternals(void)\fP" .IP "" 4 This function returns the current library internal configuration @@ -7932,6 +7932,10 @@ cfgVal: see source code .EE +.br + +.br + .IP "\fBint gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)\fP" .IP "" 4 This function is available for user customisation. diff --git a/pigpio.c b/pigpio.c index 4bee29a..0ad740d 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 76 */ +/* pigpio version 77 */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index a24e074..7364b71 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7601 +#define PIGPIO_VERSION 7700 /*TEXT diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index f07de8d..e5c79e8 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -2829,7 +2829,7 @@ int main(int argc, char *argv[]) .IP "\fBint wave_tx_at(int pi)\fP" .IP "" 4 This function returns the id of the waveform currently being -transmitted. +transmitted by \fBwave_send*\fP. Chained waves are not supported. .br diff --git a/pigs.1 b/pigs.1 index 8fa4337..9b53e0e 100644 --- a/pigs.1 +++ b/pigs.1 @@ -4823,7 +4823,7 @@ $ pigs wvas 7 38400 8 2 0 0x41 0x42 .br This command returns the id of the waveform currently -being transmitted. Note: chained waves are not supported. +being transmitted. Chained waves are not supported. .br Returns the waveform id or one of the following special -- cgit v1.2.3 From 6016f39ad099785a289639c9f48ed19cb123afc6 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sat, 27 Jun 2020 07:08:01 -0500 Subject: Revert "Remove excessive PROT_EXEC" This reverts commit e9a0dd8ead58eb5e15c62e64d36a788c27835a9c. --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 0ad740d..491c40d 100644 --- a/pigpio.c +++ b/pigpio.c @@ -7332,7 +7332,7 @@ static int initGrabLockFile(void) static uint32_t * initMapMem(int fd, uint32_t addr, uint32_t len) { return (uint32_t *) mmap(0, len, - PROT_READ|PROT_WRITE, + PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_LOCKED, fd, addr); } -- cgit v1.2.3 From ad52dcdc834c2f813c32002c26f82e00a9f0ac5f Mon Sep 17 00:00:00 2001 From: hazuki Date: Sun, 26 Apr 2020 17:42:35 +0900 Subject: Remove excessive PROT_EXEC --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 1bdae12..5b11476 100644 --- a/pigpio.c +++ b/pigpio.c @@ -7318,7 +7318,7 @@ static int initGrabLockFile(void) static uint32_t * initMapMem(int fd, uint32_t addr, uint32_t len) { return (uint32_t *) mmap(0, len, - PROT_READ|PROT_WRITE|PROT_EXEC, + PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fd, addr); } -- cgit v1.2.3 From 41b3cdfc65330d43a1f9fc56bf5cceb07065fb94 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sat, 2 May 2020 11:17:25 -0500 Subject: Issue #220 Calling exit from a signal handler is not safe. --- pigpio.c | 6 +++--- pigpio.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pigpio.c b/pigpio.c index 5b11476..5e04e0a 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 76 */ +/* pigpio version 7602 */ /* include ------------------------------------------------------- */ @@ -5621,7 +5621,7 @@ static void sigHandler(int signum) default: DBG(DBG_ALWAYS, "Unhandled signal %d, terminating\n", signum); gpioTerminate(); - exit(-1); + _exit(); } } } @@ -5631,7 +5631,7 @@ static void sigHandler(int signum) DBG(DBG_ALWAYS, "Unhandled signal %d, terminating\n", signum); gpioTerminate(); - exit(-1); + _exit(); } } diff --git a/pigpio.h b/pigpio.h index 059d751..56a5f11 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 76 +#define PIGPIO_VERSION 7602 /*TEXT -- cgit v1.2.3 From 90d206e941f0e2543e94bc59a2f575345ed1a227 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Mon, 4 May 2020 20:46:45 +0100 Subject: updated pigs.def for WVCAP and download.html for download version --- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/defs/pigs.def | 27 +++++++++++++-------------- DOC/src/html/download.html | 14 ++++++++------ pigs.1 | 34 ++++++++++++++++++---------------- 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index 531ccfd..22ceb98 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/defs/pigs.def b/DOC/src/defs/pigs.def index 2f6d23c..7c3ef07 100644 --- a/DOC/src/defs/pigs.def +++ b/DOC/src/defs/pigs.def @@ -320,7 +320,7 @@ 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 +WVCAP percent :: Create a waveform of fixed size :: gpioWaveCreatePad WVDEL wid :: Delete selected waveform :: gpioWaveDelete WVTX wid :: Transmits waveform once :: gpioWaveTxSend @@ -2786,20 +2786,13 @@ ERROR: attempt to create an empty waveform WVCAP :: -Similar to [*WVCRE*], this command creates a waveform but pads the consumed -resources to a fixed size, specified as a percent of total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. +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 allowing newly created waves to re-use the resources of deleted waves of the same dimension. -Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. +Upon success a wave id (>=0) is returned. On error a negative status code will be returned. -The data provided by the [*WVAG*] and [*WVAS*] commands are -consumed by this command. +The data provided by the [*WVAG*] and [*WVAS*] commands are consumed by this command. -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. +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 @@ -2813,8 +2806,9 @@ Step 4. [*WVTX*] or [*WVTXR*] with the id of the waveform to transmit. Repeat steps 2 - 4 as needed. -Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. +Step 5. Any wave id can now be deleted and another wave of the same size can be created in its place. + +Example ... # Create a wave that consumes 50% of the total resource: @@ -3200,6 +3194,11 @@ 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. diff --git a/DOC/src/html/download.html b/DOC/src/html/download.html index 8c2c7be..740a3c8 100644 --- a/DOC/src/html/download.html +++ b/DOC/src/html/download.html @@ -1,7 +1,7 @@ - + download @@ -14,12 +14,14 @@ pigpiod).
compilation of pigpio.c, takes 100 seconds on early model Pis.  Be patient.  The overall install takes just over 3 minutes.
-

Download and install (V75)

-wget https://github.com/joan2937/pigpio/archive/v75.zip
-unzip v75.zip
-cd pigpio-75
+

Download and install latest version

+ +wget https://github.com/joan2937/pigpio/archive/master.zip
+unzip master.zip
+cd pigpio-master
make
-sudo make install

+sudo make install
+

If the Python part of the install fails it may be because you need the setup tools.
diff --git a/pigs.1 b/pigs.1 index 9b6192c..b315910 100644 --- a/pigs.1 +++ b/pigs.1 @@ -548,8 +548,8 @@ Add serial data to waveform .B WVCRE Create a waveform .P -.B WVCAP -Create a waveform of fixed size +.B WVCAP percent +Create a waveform of fixed size .P .B WVDEL wid Delete selected waveform @@ -5142,27 +5142,20 @@ ERROR: attempt to create an empty waveform .br -.IP "\fBWVCAP \fP - Create a waveform of fixed size" +.IP "\fBWVCAP percent\fP - Create a waveform of fixed size" .IP "" 4 .br -Similar to \fBWVCRE\fP, this command creates a waveform but pads the consumed -resources to a fixed size, specified as a percent of total resource. -Padded waves of equal size can be re-cycled efficiently allowing newly -created waves to re-use the resources of deleted waves of the same dimension. +Create a waveform of fixed size. Similar to \fBWVCRE\fP, this command creates a waveform but pads the consumed resources to a fixed size, specified as a \fBpercent\fP of the total resources. Padded waves of equal size can be re-cycled efficiently allowing newly created waves to re-use the resources of deleted waves of the same dimension. .br -Upon success a wave id (>=0) is returned. On error a negative status -code will be returned. +Upon success a wave id (>=0) is returned. On error a negative status code will be returned. .br -The data provided by the \fBWVAG\fP and \fBWVAS\fP commands are -consumed by this command. +The data provided by the \fBWVAG\fP and \fBWVAS\fP commands are consumed by this command. .br -As many waveforms may be created as there is space available. -The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the -waveform to transmit. +As many waveforms may be created as there is space available. The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the waveform to transmit. .br Normal usage would be @@ -5183,8 +5176,10 @@ Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit. Repeat steps 2 - 4 as needed. .br -Step 5. Any wave id can now be deleted and another wave of the same size - can be created in its place. +Step 5. Any wave id can now be deleted and another wave of the same size can be created in its place. + +.br +Example .br @@ -5881,6 +5876,13 @@ The command expects a dutycycle. .br +.IP "\fBpercent\fP - percent (1-100)" 0 +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). + +.br + .IP "\fBpf\fP - hardware PWM frequency (1-125M, 1-187.5M for the BCM2711)" 0 The command expects a frequency. -- cgit v1.2.3 From eb7600ecd9d14ef2ec6d98105ed0a3003135da0d Mon Sep 17 00:00:00 2001 From: joan2937 Date: Thu, 7 May 2020 11:53:04 +0100 Subject: fixed untracked files --- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/defs/examples.def | 7 +++++++ util/pigpiod | 31 ------------------------------- 3 files changed, 7 insertions(+), 31 deletions(-) delete mode 100755 util/pigpiod diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index 22ceb98..6ac1161 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/defs/examples.def b/DOC/src/defs/examples.def index cd793a4..5a54f92 100644 --- a/DOC/src/defs/examples.def +++ b/DOC/src/defs/examples.def @@ -501,6 +501,13 @@ gpioHardwareRevision Related code. +?4|https://pypi.org/project/nrf24/|2020-04-20|NRF24 +Python Package Index (Pypi) NRF24 module. +pip install nrf24 + +?4|https://github.com/bjarne-hansen/py-nrf24|2020-04-20|NRF24 +Code and example usage of the Pypi NRF24 module. Cleaned up and added support for reading from multiple pipes using open_reading_pipe(pipe, address) and open_writing_pipe(address) in order to be more "compatible" with the way NRF24 is used on Arduinos. + ?4|https://github.com/stripcode/pigpio-stepper-motor|2016-08-12|Stepper Motor Stepper motor code. diff --git a/util/pigpiod b/util/pigpiod deleted file mode 100755 index 59ba142..0000000 --- a/util/pigpiod +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: pigpiod -# Required-Start: -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: pigpio daemon -# Description: pigpio daemon required to control GPIO pins via pigpio $ -### END INIT INFO - -# Actions -case "$1" in - start) - pigpiod - ;; - stop) - pkill pigpiod - ;; - restart) - pkill pigpiod - pigpiod - ;; - *) - echo "Usage: $0 start" >&2 - exit 3 - ;; -esac - -exit 0 - -- cgit v1.2.3 From a77351a941e6716a588c48b99ef0fd3462be9cae Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 31 May 2020 13:44:14 -0500 Subject: Revert "Issue #220 Calling exit from a signal handler is not safe." --- pigpio.c | 6 +++--- pigpio.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pigpio.c b/pigpio.c index 5e04e0a..5b11476 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 7602 */ +/* pigpio version 76 */ /* include ------------------------------------------------------- */ @@ -5621,7 +5621,7 @@ static void sigHandler(int signum) default: DBG(DBG_ALWAYS, "Unhandled signal %d, terminating\n", signum); gpioTerminate(); - _exit(); + exit(-1); } } } @@ -5631,7 +5631,7 @@ static void sigHandler(int signum) DBG(DBG_ALWAYS, "Unhandled signal %d, terminating\n", signum); gpioTerminate(); - _exit(); + exit(-1); } } diff --git a/pigpio.h b/pigpio.h index 56a5f11..7aa6f78 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7602 +#define PIGPIO_VERSION 7601 /*TEXT -- cgit v1.2.3 From 5395bbed13e175a16c8fc27d006e3c2b6ccd6782 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 31 May 2020 14:26:37 -0500 Subject: Fix waveCBsOOLs tallys for 2d dma stride. --- pigpio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 5b11476..2c52870 100644 --- a/pigpio.c +++ b/pigpio.c @@ -3000,7 +3000,9 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) for (i=0; i Date: Mon, 25 May 2020 16:00:22 -0400 Subject: Fix issue #353, initialising glitch filter --- pigpio.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/pigpio.c b/pigpio.c index 2c52870..6ef6ce9 100644 --- a/pigpio.c +++ b/pigpio.c @@ -950,6 +950,7 @@ typedef struct uint32_t nfRBitV; uint32_t gfSteadyUs; + uint8_t gfInitialised; uint32_t gfTick; uint32_t gfLBitV; uint32_t gfRBitV; @@ -5685,7 +5686,7 @@ unsigned alert_delays[]= static void alertGlitchFilter(gpioSample_t *sample, int numSamples) { int i, j, diff; - uint32_t steadyUs, changedTick, RBitV, LBitV; + uint32_t steadyUs, changedTick, RBitV, LBitV, initialised; uint32_t bit, bitV; for (i=0; i<=PI_MAX_USER_GPIO; i++) @@ -5694,6 +5695,17 @@ static void alertGlitchFilter(gpioSample_t *sample, int numSamples) if (monitorBits & bit & gFilterBits) { + initialised = gpioAlert[i].gfInitialised; + if (!initialised && numSamples > 0) + { + /* Initialise filter with first sample */ + bitV = sample[0].level & bit; + gpioAlert[i].gfRBitV = bitV; + gpioAlert[i].gfLBitV = bitV; + gpioAlert[i].gfTick = sample[0].tick; + gpioAlert[i].gfInitialised = 1; + } + steadyUs = gpioAlert[i].gfSteadyUs; RBitV = gpioAlert[i].gfRBitV; LBitV = gpioAlert[i].gfLBitV; @@ -12335,18 +12347,8 @@ int gpioGlitchFilter(unsigned gpio, unsigned steady) if (steady) { - gpioAlert[gpio].gfTick = systReg[SYST_CLO]; - - if (gpioRead_Bits_0_31() & (1< Date: Thu, 25 Jun 2020 12:34:45 -0500 Subject: Fix issue #355, python module event_callback documentation. --- pigpio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pigpio.py b/pigpio.py index 978aff2..2d418b1 100644 --- a/pigpio.py +++ b/pigpio.py @@ -5055,7 +5055,7 @@ class pi(): by calling the tally function. The count may be reset to zero by calling the reset_tally function. - The callback may be cancelled by calling the event_cancel function. + The callback may be canceled by calling the cancel function. An event may have multiple callbacks (although I can't think of a reason to do so). @@ -5072,7 +5072,7 @@ class pi(): cb2.reset_tally() - cb1.event_cancel() # To cancel callback cb1. + cb1.cancel() # To cancel callback cb1. ... """ -- cgit v1.2.3 From 1c5b27f41d4796204008138f580adf1d288bf335 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 25 Jun 2020 22:26:41 -0500 Subject: Fix issue #356, document wave_tx_at API is not supported on chained waves. --- pigpio.h | 2 +- pigpio.py | 2 +- pigpiod_if2.h | 2 +- pigs.1 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pigpio.h b/pigpio.h index 7aa6f78..c318515 100644 --- a/pigpio.h +++ b/pigpio.h @@ -2181,7 +2181,7 @@ D*/ int gpioWaveTxAt(void); /*D This function returns the id of the waveform currently being -transmitted. +transmitted using [*gpioWaveTxSend*]. Chained waves are not supported. Returns the waveform id or one of the following special values: diff --git a/pigpio.py b/pigpio.py index 2d418b1..7fc80a5 100644 --- a/pigpio.py +++ b/pigpio.py @@ -2466,7 +2466,7 @@ class pi(): def wave_tx_at(self): """ Returns the id of the waveform currently being - transmitted. + transmitted using [*wave_send**]. Chained waves are not supported. Returns the waveform id or one of the following special values: diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 79d0223..9700cc0 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -1609,7 +1609,7 @@ D*/ int wave_tx_at(int pi); /*D This function returns the id of the waveform currently being -transmitted. +transmitted by [*wave_send**]. Chained waves are not supported. . . pi: >=0 (as returned by [*pigpio_start*]). diff --git a/pigs.1 b/pigs.1 index b315910..8fa4337 100644 --- a/pigs.1 +++ b/pigs.1 @@ -4823,7 +4823,7 @@ $ pigs wvas 7 38400 8 2 0 0x41 0x42 .br This command returns the id of the waveform currently -being transmitted. +being transmitted. Note: chained waves are not supported. .br Returns the waveform id or one of the following special -- cgit v1.2.3 From d7379baf9b40ed0f629954408f3d65588a07843e Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Thu, 25 Jun 2020 23:02:41 -0500 Subject: Remove deprecated gpioCfgInternals API. Fix issue #341. --- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/defs/pigs.def | 2 +- pigpio.c | 38 -------------------------------------- pigpio.h | 23 ++++++++++------------- 4 files changed, 11 insertions(+), 52 deletions(-) diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index 6ac1161..a26ab8e 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/defs/pigs.def b/DOC/src/defs/pigs.def index 7c3ef07..f678126 100644 --- a/DOC/src/defs/pigs.def +++ b/DOC/src/defs/pigs.def @@ -2610,7 +2610,7 @@ $ pigs wvas 7 38400 8 2 0 0x41 0x42 WVTAT :: This command returns the id of the waveform currently -being transmitted. +being transmitted. Chained waves are not supported. Returns the waveform id or one of the following special values: diff --git a/pigpio.c b/pigpio.c index 6ef6ce9..4bee29a 100644 --- a/pigpio.c +++ b/pigpio.c @@ -14002,44 +14002,6 @@ int gpioCfgSetInternals(uint32_t cfgVal) return 0; } -int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal) -{ - int retVal = PI_BAD_CFG_INTERNAL; - - DBG(DBG_USER, "cfgWhat=%u, cfgVal=%d", cfgWhat, cfgVal); - - switch(cfgWhat) - { - case 562484977: - - if (cfgVal) gpioCfg.internals |= PI_CFG_STATS; - else gpioCfg.internals &= (~PI_CFG_STATS); - - DBG(DBG_ALWAYS, "show stats is %u", cfgVal); - - retVal = 0; - - break; - - case 984762879: - - if ((cfgVal >= DBG_ALWAYS) && (cfgVal <= DBG_MAX_LEVEL)) - { - - gpioCfg.dbgLevel = cfgVal; - gpioCfg.internals = (gpioCfg.internals & (~0xF)) | cfgVal; - - DBG(DBG_ALWAYS, "Debug level is %u", cfgVal); - - retVal = 0; - } - - break; - } - - return retVal; -} - /* include any user customisations */ diff --git a/pigpio.h b/pigpio.h index c318515..a24e074 100644 --- a/pigpio.h +++ b/pigpio.h @@ -106,6 +106,15 @@ return error PI_NOT_INITIALISED. If the library is initialised the [*gpioCfg**] functions will return error PI_INITIALISED. +If you intend to rely on signals sent to your application, you should +turn off the internal signal handling as show in this example: +. . +int cfg = gpioCfgGetInternals(); +cfg |= PI_CFG_NOSIGHANDLER; // (1<<10) +gpioCfgSetInternals(cfg); +int status = gpioInitialise(); +. . + TEXT*/ /*OVERVIEW @@ -377,7 +386,6 @@ gpioCfgSocketPort Configure socket port gpioCfgMemAlloc Configure DMA memory allocation mode gpioCfgNetAddr Configure allowed network addresses -gpioCfgInternals Configure misc. internals (DEPRECATED) gpioCfgGetInternals Get internal configuration settings gpioCfgSetInternals Set internal configuration settings @@ -4975,18 +4983,6 @@ numSockAddr: 0-256 (0 means all addresses allowed) D*/ -/*F*/ -int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal); -/*D -Used to tune internal settings. - -. . -cfgWhat: see source code - cfgVal: see source code -. . -D*/ - - /*F*/ uint32_t gpioCfgGetInternals(void); /*D @@ -5003,6 +4999,7 @@ settings. . . cfgVal: see source code . . + D*/ -- cgit v1.2.3 From d4e20ead60f50b0b6a5e864b7d993ccfdd3b7e35 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Fri, 26 Jun 2020 16:20:36 -0500 Subject: Bump version and generate docs. --- .gitignore | 2 ++ DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes pigpio.3 | 42 +++++++++++++++++++++++------------------- pigpio.c | 2 +- pigpio.h | 2 +- pigpiod_if2.3 | 2 +- pigs.1 | 2 +- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 4449b61..fcdcc13 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ build dist *.egg-info +tmp/ + # DOC files DOC/dbase/pigpio.sqlite.* DOC/tmp diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index a26ab8e..ba61140 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/pigpio.3 b/pigpio.3 index c878cbd..0871b71 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -189,6 +189,24 @@ error PI_INITIALISED. .br +.br +If you intend to rely on signals sent to your application, you should +turn off the internal signal handling as show in this example: + +.EX +int cfg = gpioCfgGetInternals(); +.br +cfg |= PI_CFG_NOSIGHANDLER; // (1<<10) +.br +gpioCfgSetInternals(cfg); +.br +int status = gpioInitialise(); +.br + +.EE + +.br + .br .SH OVERVIEW @@ -689,8 +707,6 @@ gpioCfgMemAlloc Configure DMA memory allocation mode gpioCfgNetAddr Configure allowed network addresses .br -.br -gpioCfgInternals Configure misc. internals (DEPRECATED) .br gpioCfgGetInternals Get internal configuration settings .br @@ -3026,7 +3042,7 @@ int main(int argc, char *argv[]) .IP "\fBint gpioWaveTxAt(void)\fP" .IP "" 4 This function returns the id of the waveform currently being -transmitted. +transmitted using \fBgpioWaveTxSend\fP. Chained waves are not supported. .br @@ -7896,22 +7912,6 @@ numSockAddr: 0-256 (0 means all addresses allowed) .EE -.IP "\fBint gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)\fP" -.IP "" 4 -Used to tune internal settings. - -.br - -.br - -.EX -cfgWhat: see source code -.br - cfgVal: see source code -.br - -.EE - .IP "\fBuint32_t gpioCfgGetInternals(void)\fP" .IP "" 4 This function returns the current library internal configuration @@ -7932,6 +7932,10 @@ cfgVal: see source code .EE +.br + +.br + .IP "\fBint gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)\fP" .IP "" 4 This function is available for user customisation. diff --git a/pigpio.c b/pigpio.c index 4bee29a..0ad740d 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 76 */ +/* pigpio version 77 */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index a24e074..7364b71 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7601 +#define PIGPIO_VERSION 7700 /*TEXT diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index f07de8d..e5c79e8 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -2829,7 +2829,7 @@ int main(int argc, char *argv[]) .IP "\fBint wave_tx_at(int pi)\fP" .IP "" 4 This function returns the id of the waveform currently being -transmitted. +transmitted by \fBwave_send*\fP. Chained waves are not supported. .br diff --git a/pigs.1 b/pigs.1 index 8fa4337..9b53e0e 100644 --- a/pigs.1 +++ b/pigs.1 @@ -4823,7 +4823,7 @@ $ pigs wvas 7 38400 8 2 0 0x41 0x42 .br This command returns the id of the waveform currently -being transmitted. Note: chained waves are not supported. +being transmitted. Chained waves are not supported. .br Returns the waveform id or one of the following special -- cgit v1.2.3 From f51642ad1374b5bc6bfcf076c7459f7a7bf0db54 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sat, 27 Jun 2020 07:08:01 -0500 Subject: Revert "Remove excessive PROT_EXEC" --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 0ad740d..491c40d 100644 --- a/pigpio.c +++ b/pigpio.c @@ -7332,7 +7332,7 @@ static int initGrabLockFile(void) static uint32_t * initMapMem(int fd, uint32_t addr, uint32_t len) { return (uint32_t *) mmap(0, len, - PROT_READ|PROT_WRITE, + PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_LOCKED, fd, addr); } -- cgit v1.2.3 From b96c77c281d8179188b200b01bda3bc4a6bf1eae Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sat, 27 Jun 2020 07:51:44 -0500 Subject: Change version to 77. --- pigpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.h b/pigpio.h index 7364b71..f90b81b 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7700 +#define PIGPIO_VERSION 77 /*TEXT -- cgit v1.2.3 From c3759529b2cd54df4b27bbfda47c6f031dd35e64 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 28 Jun 2020 09:40:59 +0100 Subject: Update index.html Add link to Xojo implementation by Eugene Dakin --- DOC/src/html/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DOC/src/html/index.html b/DOC/src/html/index.html index b34ea79..d9093c6 100644 --- a/DOC/src/html/index.html +++ b/DOC/src/html/index.html @@ -652,6 +652,8 @@ Calin Horea) "https://github.com/vasmalltalk/pigpio-vast">Smalltalk(Instantiations)
  • Xojo(UBogun)
  • +
  • Xojo(Eugene Dakin)

  • The PWM and servo pulses are timed using the DMA -- cgit v1.2.3 From a686d1de717de7aa5ba13f8db6fded3dad9e64d0 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 28 Jun 2020 09:51:27 +0100 Subject: Update index.html Removed experimental on Pi4 paragraph. --- DOC/src/html/index.html | 7 ------- 1 file changed, 7 deletions(-) diff --git a/DOC/src/html/index.html b/DOC/src/html/index.html index d9093c6..229073f 100644 --- a/DOC/src/html/index.html +++ b/DOC/src/html/index.html @@ -10,13 +10,6 @@ pigpio is a library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO).  pigpio works on all versions of the Pi. -

    At the moment pigpio on the Pi4B is experimental. I am not -sure if the DMA channels being used are safe. The Pi4B defaults are -primary channel 7, secondary channel 6. If these channels do not -work you will have to experiment. You can set the channels used by -the pigpio daemon by invoking it with the -d and -e options, e.g. -sudo pigpiod -d 5 -e 8 to specify primary 5, -secondary 8.

    Download

    Features

      -- cgit v1.2.3 From 0c1fb8b6603040ee41c4cdde0e60f16f6f264240 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 28 Jun 2020 10:20:05 -0500 Subject: Update docs --- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/html/index.html | 6 ++++-- pigpio.3 | 6 +++++- pigpio.h | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index ba61140..c20cbe0 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/html/index.html b/DOC/src/html/index.html index 229073f..0b8e33c 100644 --- a/DOC/src/html/index.html +++ b/DOC/src/html/index.html @@ -620,7 +620,7 @@ links.

      Languages

      There are several third party projects which provide wrappers for pigpio.

      -

      Some I am aware of are:

      +

      Some are listed here:


      The PWM and servo pulses are timed using the DMA -- cgit v1.2.3 From c07bbb299a3c8edf2bd6d56d7db2567cff469436 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 28 Jun 2020 09:51:27 +0100 Subject: Update index.html Removed experimental on Pi4 paragraph. --- DOC/src/html/index.html | 7 ------- 1 file changed, 7 deletions(-) diff --git a/DOC/src/html/index.html b/DOC/src/html/index.html index d9093c6..229073f 100644 --- a/DOC/src/html/index.html +++ b/DOC/src/html/index.html @@ -10,13 +10,6 @@ pigpio is a library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO).  pigpio works on all versions of the Pi. -

      At the moment pigpio on the Pi4B is experimental. I am not -sure if the DMA channels being used are safe. The Pi4B defaults are -primary channel 7, secondary channel 6. If these channels do not -work you will have to experiment. You can set the channels used by -the pigpio daemon by invoking it with the -d and -e options, e.g. -sudo pigpiod -d 5 -e 8 to specify primary 5, -secondary 8.

      Download

      Features

        -- cgit v1.2.3 From e6bfc40a5110cb5edb7d419f1dcba1692ba8b224 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 28 Jun 2020 10:20:05 -0500 Subject: Update docs --- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/html/index.html | 6 ++++-- pigpio.3 | 6 +++++- pigpio.h | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index ba61140..c20cbe0 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/html/index.html b/DOC/src/html/index.html index 229073f..0b8e33c 100644 --- a/DOC/src/html/index.html +++ b/DOC/src/html/index.html @@ -620,7 +620,7 @@ links.

        Languages

        There are several third party projects which provide wrappers for pigpio.

        -

        Some I am aware of are:

        +

        Some are listed here:

        • Erlang (skvamme)
        • @@ -635,7 +635,9 @@ diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc "https://github.com/unosquare/pigpio-dotnet">.NET/mono (unosquare)
        • Node.js -(fivdi)
        • +A wrapper for the pigpio C library (fivdi) +
        • Node.js +A client for pigpio socket interface (guymcswain)
        • Perl (Gligan Calin Horea)
        • Date: Sun, 28 Jun 2020 22:01:40 -0500 Subject: Fixing possible fclose on null pointer --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 491c40d..ff1fb5d 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13733,8 +13733,8 @@ unsigned gpioHardwareRevision(void) rev = ntohl(tmp); rev &= 0xFFFFFF; /* mask out warranty bit */ } + fclose(filp); } - fclose(filp); } piCores = 0; -- cgit v1.2.3 From 9a22f2d64b5a2f84aef829bd642dd81de627873f Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 16 Aug 2020 21:27:04 +0100 Subject: New pulse per second example synced to wall time. --- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/defs/examples.def | 5 ++++- pigpio.c | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index c20cbe0..f24fd30 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/defs/examples.def b/DOC/src/defs/examples.def index 5a54f92..637a82b 100644 --- a/DOC/src/defs/examples.def +++ b/DOC/src/defs/examples.def @@ -52,7 +52,7 @@ Examples of C pigpio programs. If your program is called foobar.c then build with -gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt +gcc -Wall -o foobar foobar.c -lpigpio ?3|freq_count_1|2014-08-20|Frequency Counter 1 A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). @@ -75,6 +75,9 @@ A program to display readings from the (I2C) PCF8591. ?3|pot_cap_charge_c|2014-03-14|Pot + Capacitor Recharge Timing Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance. +?3|pps_c|2020-07-28|Pulse Per Second generator +A program to generate a pulse on a GPIO every x seconds (1<=x<=60). The pulse is synced with the wall time second boundary. + ?3|rotary_encoder_c|2015-10-03|Rotary Encoder Function to decode a mechanical rotary encoder. diff --git a/pigpio.c b/pigpio.c index 491c40d..8fd91cf 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13221,6 +13221,8 @@ int fileApprove(char *filename) buffer[0] = 0; match[0] = 0; + if (myPathBad(filename)) return PI_FILE_NONE; + f = fopen("/opt/pigpio/access", "r"); if (!f) return PI_FILE_NONE; -- cgit v1.2.3 From 93965f8e3bc991a7c90155fae9dffe93e945c981 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Mon, 17 Aug 2020 08:31:26 +0100 Subject: Misc plus fix for #373 --- pigpio.c | 3 +++ pigpiod_if.c | 2 +- pigpiod_if2.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index 8fd91cf..da492d0 100644 --- a/pigpio.c +++ b/pigpio.c @@ -1572,6 +1572,9 @@ int myPathBad(char *name) in_part = 0; last_char_dot = 0; + if (strstr(name, "..")) return 1; + if (strstr(name, "\\.")) return 1; + len = strlen(name); for (i=0; i Date: Mon, 17 Aug 2020 13:09:44 +0100 Subject: Tidy file handling. --- pigpio.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pigpio.c b/pigpio.c index da492d0..3c5b05d 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13282,7 +13282,7 @@ int fileOpen(char *file, unsigned mode) { static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int fd=-1; - int i, slot, oflag, omode; + int i, slot, oflag, omode, pmode, rmode; struct stat statbuf; DBG(DBG_USER, "file=%s mode=%d", file, mode); @@ -13294,9 +13294,15 @@ int fileOpen(char *file, unsigned mode) ((mode & PI_FILE_RW) == 0) ) SOFT_ERROR(PI_BAD_FILE_MODE, "bad mode (%d)", mode); - if ((fileApprove(file) & mode) == PI_FILE_NONE) + pmode = fileApprove(file); // 0=NONE, 1=READ, 2=WRITE, 3=RW + rmode = mode & PI_FILE_RW; // 0=NONE, 1=READ, 2=WRITE, 3=RW + + if (((pmode & rmode) != rmode) || (rmode == PI_FILE_NONE)) SOFT_ERROR(PI_NO_FILE_ACCESS, "no permission to access file (%s)", file); + if ((mode > 3) && ((mode & PI_FILE_WRITE) == 0)) + SOFT_ERROR(PI_NO_FILE_ACCESS, "no permission to write file (%s)", file); + slot = -1; pthread_mutex_lock(&mutex); @@ -13320,7 +13326,6 @@ int fileOpen(char *file, unsigned mode) if (mode & PI_FILE_APPEND) { - mode |= PI_FILE_WRITE; oflag |= O_APPEND; } @@ -13332,7 +13337,6 @@ int fileOpen(char *file, unsigned mode) if (mode & PI_FILE_TRUNC) { - mode |= PI_FILE_WRITE; oflag |= O_TRUNC; } @@ -13517,7 +13521,7 @@ int fileList(char *fpat, char *buf, unsigned count) CHECK_INITED; - if (fileApprove(fpat) == PI_FILE_NONE) + if ((fileApprove(fpat) & PI_FILE_READ) != PI_FILE_READ) SOFT_ERROR(PI_NO_FILE_ACCESS, "no permission to access file (%s)", fpat); bufpos = 0; -- cgit v1.2.3 From 7154e302e3749b54615a70548ba3be2cc04b0c2d Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 16 Aug 2020 21:27:04 +0100 Subject: New pulse per second example synced to wall time. --- DOC/dbase/pigpio.sqlite | Bin 1433600 -> 1433600 bytes DOC/src/defs/examples.def | 5 ++++- pigpio.c | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/DOC/dbase/pigpio.sqlite b/DOC/dbase/pigpio.sqlite index c20cbe0..f24fd30 100644 Binary files a/DOC/dbase/pigpio.sqlite and b/DOC/dbase/pigpio.sqlite differ diff --git a/DOC/src/defs/examples.def b/DOC/src/defs/examples.def index 5a54f92..637a82b 100644 --- a/DOC/src/defs/examples.def +++ b/DOC/src/defs/examples.def @@ -52,7 +52,7 @@ Examples of C pigpio programs. If your program is called foobar.c then build with -gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt +gcc -Wall -o foobar foobar.c -lpigpio ?3|freq_count_1|2014-08-20|Frequency Counter 1 A program showing how to use the gpioSetAlertFunc function to set a callback for GPIO state changes. A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1μs). @@ -75,6 +75,9 @@ A program to display readings from the (I2C) PCF8591. ?3|pot_cap_charge_c|2014-03-14|Pot + Capacitor Recharge Timing Function to time capacitor charging (through a resistance). The time can be used to estimate the resistance. +?3|pps_c|2020-07-28|Pulse Per Second generator +A program to generate a pulse on a GPIO every x seconds (1<=x<=60). The pulse is synced with the wall time second boundary. + ?3|rotary_encoder_c|2015-10-03|Rotary Encoder Function to decode a mechanical rotary encoder. diff --git a/pigpio.c b/pigpio.c index ff1fb5d..eb04fcd 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13221,6 +13221,8 @@ int fileApprove(char *filename) buffer[0] = 0; match[0] = 0; + if (myPathBad(filename)) return PI_FILE_NONE; + f = fopen("/opt/pigpio/access", "r"); if (!f) return PI_FILE_NONE; -- cgit v1.2.3 From ad83b33426d33f8cee8d2afac94f2f1aa4ef84c4 Mon Sep 17 00:00:00 2001 From: joan2937 Date: Mon, 17 Aug 2020 08:31:26 +0100 Subject: Misc plus fix for #373 --- pigpio.c | 3 +++ pigpiod_if.c | 2 +- pigpiod_if2.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index eb04fcd..42ac4d5 100644 --- a/pigpio.c +++ b/pigpio.c @@ -1572,6 +1572,9 @@ int myPathBad(char *name) in_part = 0; last_char_dot = 0; + if (strstr(name, "..")) return 1; + if (strstr(name, "\\.")) return 1; + len = strlen(name); for (i=0; i Date: Mon, 17 Aug 2020 13:09:44 +0100 Subject: Tidy file handling. --- pigpio.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pigpio.c b/pigpio.c index 42ac4d5..b061a15 100644 --- a/pigpio.c +++ b/pigpio.c @@ -13282,7 +13282,7 @@ int fileOpen(char *file, unsigned mode) { static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int fd=-1; - int i, slot, oflag, omode; + int i, slot, oflag, omode, pmode, rmode; struct stat statbuf; DBG(DBG_USER, "file=%s mode=%d", file, mode); @@ -13294,9 +13294,15 @@ int fileOpen(char *file, unsigned mode) ((mode & PI_FILE_RW) == 0) ) SOFT_ERROR(PI_BAD_FILE_MODE, "bad mode (%d)", mode); - if ((fileApprove(file) & mode) == PI_FILE_NONE) + pmode = fileApprove(file); // 0=NONE, 1=READ, 2=WRITE, 3=RW + rmode = mode & PI_FILE_RW; // 0=NONE, 1=READ, 2=WRITE, 3=RW + + if (((pmode & rmode) != rmode) || (rmode == PI_FILE_NONE)) SOFT_ERROR(PI_NO_FILE_ACCESS, "no permission to access file (%s)", file); + if ((mode > 3) && ((mode & PI_FILE_WRITE) == 0)) + SOFT_ERROR(PI_NO_FILE_ACCESS, "no permission to write file (%s)", file); + slot = -1; pthread_mutex_lock(&mutex); @@ -13320,7 +13326,6 @@ int fileOpen(char *file, unsigned mode) if (mode & PI_FILE_APPEND) { - mode |= PI_FILE_WRITE; oflag |= O_APPEND; } @@ -13332,7 +13337,6 @@ int fileOpen(char *file, unsigned mode) if (mode & PI_FILE_TRUNC) { - mode |= PI_FILE_WRITE; oflag |= O_TRUNC; } @@ -13517,7 +13521,7 @@ int fileList(char *fpat, char *buf, unsigned count) CHECK_INITED; - if (fileApprove(fpat) == PI_FILE_NONE) + if ((fileApprove(fpat) & PI_FILE_READ) != PI_FILE_READ) SOFT_ERROR(PI_NO_FILE_ACCESS, "no permission to access file (%s)", fpat); bufpos = 0; -- cgit v1.2.3 From b332474c9d7742f7a8b0d518f330674603747a12 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 30 Aug 2020 10:23:16 -0500 Subject: Fix issue #274 - Delay on reboot/shutdown. --- util/pigpiod.service | 1 + 1 file changed, 1 insertion(+) diff --git a/util/pigpiod.service b/util/pigpiod.service index a0bb916..f040d38 100644 --- a/util/pigpiod.service +++ b/util/pigpiod.service @@ -3,6 +3,7 @@ Description=Pigpio daemon [Service] Type=forking +PIDFile=pigpio.pid ExecStart=/usr/bin/pigpiod [Install] -- cgit v1.2.3 From d5961b9de252b1d90fd74bea21bfc0c01b854501 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 30 Aug 2020 10:55:59 -0500 Subject: v7702 fixes 'Operation not permitted' and 'Delay on reboot/shutdown'. --- pigpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.h b/pigpio.h index 2d98e75..7697514 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7700 +#define PIGPIO_VERSION 7702 /*TEXT -- cgit v1.2.3 From c7c561177d530cb3b3e5827669e24950626ef45c Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Tue, 29 Sep 2020 08:33:55 -0500 Subject: Sync versions for next release (78). --- pigpio.c | 2 +- pigpio.h | 2 +- pigpio.py | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pigpio.c b/pigpio.c index 1ea82cd..92b9bf7 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 77 */ +/* pigpio version 78 */ /* include ------------------------------------------------------- */ diff --git a/pigpio.h b/pigpio.h index 7697514..2f9fc64 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7702 +#define PIGPIO_VERSION 7800 /*TEXT diff --git a/pigpio.py b/pigpio.py index 7fc80a5..edb6734 100644 --- a/pigpio.py +++ b/pigpio.py @@ -331,7 +331,7 @@ import threading import os import atexit -VERSION = "1.46" +VERSION = "1.78" # sync minor number to pigpio library version exceptions = True diff --git a/setup.py b/setup.py index 023a2c4..4dbb8a9 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.46', + version='1.78', author='joan', author_email='joan@abyz.me.uk', maintainer='joan', -- cgit v1.2.3