rgs(1)
welcome to rgs(1) from the lg archive section bestie π β this is the manual for rgs, and yes it's a whole vibe, and yes we're getting through all of it together, no skimming, no skipping. πΈ
π NAME π
rgs β a shell command to manipulate a remote SBC's GPIO. That's it, that's the whole thing, she's a shell command and she's coming for your GPIO from across the network. π¦
β¨ SYNOPSIS β¨
okay so first you gotta have the daemon running, then you talk to it:
rgpiod &
then
rgs {command}+
π DESCRIPTION π
rgs is a program that lets you remote-control the GPIO and other functions of Linux SBCs that are running the rgpiod daemon. So like, the daemon is the main character on the SBC, and rgs is you, texting it from your laptop. π
The rgpiod daemon must be running on the SBCs you wish to control. No daemon, no vibes. Periodt.
π Features π
she does a lot, actually:
- reading and writing GPIO singly and in groups
- software timed PWM and waves
- GPIO callbacks
- pipe notification of GPIO events
- I2C wrapper
- SPI wrapper
- serial link wrapper
- simple file handling
- creating and running scripts on the
rgpioddaemon
π Usage π
rgs {command}+
rgs will show the result of the command on screen, right there, for you. π
The rgs process returns an exit status (which you can display with the command echo $? β you know this one, bestie).
RGS_OKβ0RGS_CONNECT_ERRβ255RGS_OPTION_ERRβ254RGS_SCRIPT_ERRβ253
If an error was detected a message will have been written to stderr. That message is likely to be more informative than the message returned by rgs, so like... actually read your stderr, she's trying to help you. π
Several commands may be entered on a line. If present, PROC and PARSE must be the last command on a line. (that's a rule, don't fight it)
π¦ Notes π¦
rgs does not show the status of successful commands unless the command itself returns data. The status (0) will be returned to rgs but will be discarded. she's quiet when she's winning, iconic behaviour tbh.
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 rgs -a option can be used to force the display as ASCII and the rgs -x option can be used to force the display as hex.
E.g. assuming the transmitted serial data is the letters ABCDEONM
$ rgs serr 4 100 # assumes serial data available from handle 4
8 65 66 67 68 69 79 78 77
$ rgs -a serr 4 100
8 ABCDEONM
$ rgs -x serr 4 100
8 41 42 43 44 45 4f 4e 4d
look at her switching up formats on demand, she's so versatile π
π Permissions π
Generally, objects created on the rgpiod daemon exist for the duration of the socket connection.
- For a Python script this will be for the duration of the script.
- For a program linked with
rgpiothis will be for the duration of the program. - For
rgsit is the command line.
Which means the following command will achieve little:
rgs go 0 # get handle to gpiochip 0
The daemon will delete the handle as soon as the rgs command has finished. like, gone. poof. π
To preserve the handle it must be shared.
A lot of the examples will show the command c 1 (use share id 1). This means the handle is preserved and may be used in subsequent commands.
rgs c 1 go 0 # get and preserve handle to gpiochip 0
If the LG_SHARE environment variable exists that share will be automatically used in rgs commands.
E.g. export LG_SHARE=12 will automatically use share id 12.
If a command is privileged it is indicated in the notes for the command. The examples given here assume the daemon access control system is not active (so any user can use privileged commands).
If the LG_USER environment variable exists that user will be automatically used in rgs commands. This only has an effect if the rgpiod daemon is running with access control enabled.
E.g. export LG_USER=joan will automatically use user joan.
β OVERVIEW β
π FILES π
FO file modeβ File openFC hβ File closeFR h numβ File readFW h bvsβ File writeFS h num fromβ File seekFL pat numβ File list
π GPIO π
GO gcβ gpiochip open deviceGC hβ gpiochip close deviceGIC hβ gpiochip informationGIL h gβ gpiochip line informationGMODE h gβ GPIO get modeGSI h gβ GPIO claim for input (simple)GSIX h lf gβ GPIO claim for inputGSO h gβ GPIO claim for output (simple)GSOX h lf g vβ GPIO claim for outputGSA h g nfyhβ GPIO claim for alerts (simple)GSAX h lf ef g nfyhβ GPIO claim for alertsGSF h gβ GPIO freeGSGI h g*β GPIO group claim for inputs (simple)GSGIX h lf g*β GPIO group claim for inputsGSGO h g*β GPIO group claim for outputs (simple)GSGOX h lf g* v*β GPIO group claim for outputsGSGF h gβ GPIO group freeGR h gβ GPIO readGW h g vβ GPIO writeGGR h gβ GPIO group readGGW h g gbitsβ GPIO group write (simple)GGWX h g gbits gmaskβ GPIO group writeGP h g mon moffβ GPIO tx pulse (simple)GPX h g mon moff off cycβ GPIO tx pulseP h g pf pdcβ GPIO tx PWM (simple)PX h g pf pdc off cycβ GPIO tx PWMS h g spwβ GPIO tx servo pulses (simple)SX h g spw sf off cycβ GPIO tx servo pulsesGWAVE h g p*β GPIO group tx waveGBUSY h g kβ GPIO or group tx busyGROOM h g kβ GPIO or group tx entriesGDEB h g usβ GPIO debounce timeGWDOG h g usβ GPIO watchdog time
π I2C π
I2CO ib id ifβ I2C open deviceI2CC hβ I2C close deviceI2CWQ h bitβ SMB Write Quick: write bitI2CRS hβ SMB Read Byte: read byteI2CWS h bvβ SMB Write Byte: write byteI2CRB h rβ SMB Read Byte Data: read byte from registerI2CWB h r bvβ SMB Write Byte Data: write byte to registerI2CRW h rβ SMB Read Word Data: read word from registerI2CWW h r wvβ SMB Write Word Data: write word to registerI2CRK h rβ SMB Read Block Data: read data from registerI2CWK h r bvsβ SMB Write Block Data: write data to registerI2CWI h r bvsβ SMB Write I2C Block DataI2CRI h r numβ SMB Read I2C Block Data: read bytes from registerI2CRD h numβ I2C read deviceI2CWD h bvsβ I2C write deviceI2CPC h r wvβ SMB Process Call: exchange register with wordI2CPK h r bvsβ SMB Block Process Call: exchange data bytes with registerI2CZ h bvsβ I2C zip
π NOTIFICATIONS π
NOβ Notification openNC hβ Notification closeNP hβ Notification pauseNR hβ Notification resume
π SCRIPTS π
PROC tβ Script storePROCR h parsβ Script runPROCU h parsβ Script update parametersPROCP hβ Script get status and parametersPROCS hβ Script stopPROCD hβ Script deletePARSE tβ Script validate
π SERIAL π
SERO dev b sefβ Serial open deviceSERC hβ Serial close deviceSERRBβ Serial read byteSERWB h bvβ Serial write byteSERR h numβ Serial read bytesSERW h bvsβ Serial write bytesSERDA hβ Serial data available
π SHELL π
SHELL name strβ Execute a shell command
π SPI π
SPIO spd spc b spfβ SPI open deviceSPIC hβ SPI close deviceSPIR h numβ SPI read bytesSPIW h bvsβ SPI write bytesSPIX h bvsβ SPI transfer bytes
π UTILITIES π
LGVβ Get lg library versionSBCβ Get SBC's host nameCGI cidβ Get internal configuration settingCSI cid vβ Set internal configuration settingT/TICKβ Get nanoseconds since the epochMICS vβ Microseconds delayMILS vβ Milliseconds delayU/USERβ Set userC/SHAREβ Set shareLCFGβ Reload permits configuration filePCDβ Print daemon configuration directoryPWDβ Print daemon working directory
π«Ά COMMANDS π«Ά
okay bestie, this is the big one. deep breaths. we're doing all of them.
πΈ FILES πΈ
FO file mode β File open πΈ
This is a privileged command. See permits.
This function returns a handle to a file opened in a specified mode.
Upon success a handle (>=0) is returned. On error a negative status code will be returned.
The mode may have the following values.
READ=1β open file for readingWRITE=2β open file for writingRW=3β open file for reading and writing
The following values may be or'd into the mode.
APPEND=4β All writes append data to the end of the fileCREATE=8β The file is created if it doesn't existTRUNC=16β The file is truncated
Newly created files are owned by the user that launched the daemon with permissions owner read and write.
Example
ls /ram/*.c
/ram/q.c /ram/qdhtxx.c /ram/q-errcod.c /ram/q_t1.c
/ram/q-c1.c /ram/Q-err.c /ram/q-group.c /ram/q_t2.c
$ rgs c 1 fo /ram/q.c 1 # read access
1
$ rgs c 1 fo /ram/new.c 1 # file does not exist
-58
ERROR: file open failed
$rgs c 1 fo /ram/new.c 9 # can not create file
-67
ERROR: no permission to access file
FC h β File close πΈ
This command closes a file previously opened by FO.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 fc 1 # First close okay.
$ rgs c 1 fc 1 # Second fails.
-5
ERROR: unknown handle
FR h num β File read πΈ
This command returns up to num bytes of data read from the file.
Upon success the count of returned bytes followed by the bytes themselves is returned. On error a negative status code will be returned.
Example
$ rgs c 1 fr 0 10
5 48 49 128 144 255
$ rgs c 1 fr 0 10
0
FW h bvs β File write πΈ
This command writes bvs bytes to the file.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 fw 0 23 45 67 89
FS h num from β File seek πΈ
This command seeks to a position within the file.
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.
0β start1β current position2β end
Upon success the new byte position within the file (>=0) is returned. On error a negative status code will be returned.
Example
$ rgs c 1 fs 0 200 0 # Seek to start of file plus 200
200
$ rgs c 1 fs 0 0 1 # Return current position
200
$ rgs c 1 fs 0 0 2 # Seek to end of file, return size
296235
FL pat num β File list πΈ
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.
This is a privileged command. See permits.
Example
$ rgs -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
$ rgs -a fl "/sys/bus/*" 5000
ERROR: no permission to access file
-67
πΈ GPIO πΈ
GO gc β gpiochip open device πΈ
This is a privileged command. See permits.
This command opens a gpiochip.
Example
(...and that's exactly where this part of the page stops, bestie β the GO example is mid-sentence and there's so much more coming: GC, GIC, the whole GS family, I2C, SPI, scripts, all of it. don't go anywhere π)
$ rgs c 1 go 0 # open /dev/gpiochip0
1
$ rgs c 1 go 23 # try to open /dev/gpiochip23
-78
ERROR: can not open gpiochip
π GC h β gpiochip close device π
This one closes a gpiochip that you already opened with GO. bye bestie π
Example
$ rgs c 1 gc 1 # first close ok
$ rgs c 1 gc 1 # already closed
-5
ERROR: unknown handle
β¨ GIC h β gpiochip information β¨
Gets the deets on an opened gpiochip. Specifically it gets the number of GPIO on the gpiochip, its name, and its usage. the way it just tells you things π
Example
$ rgs c 1 gic 1
54 "gpiochip0" "pinctrl-bcm2835"
πΈ GIL h g β gpiochip line information πΈ
Gets the info for GPIO g of an opened gpiochip. In particular it gets the GPIO number, line flags, its user, and its purpose. full profile, no filter π«Ά
The meaning of the line flags bits is the same as the ones given for the mode by GMODE (scroll down, it's right there).
The user and purpose fields are filled in by the software which has claimed the GPIO and may be blank. so likeβ¦ don't panic if they're empty, it's giving "nobody claimed me yet" energy π
Example
$ for ((i=2; i<10; i++)); do rgs c 1 gil 1 $i; done
2 65536 "SDA1" ""
3 65536 "SCL1" ""
4 65536 "GPIO_GCLK" ""
5 65536 "GPIO5" ""
6 65536 "GPIO6" ""
7 7 "SPI_CE1_N" "spi0 CS1"
8 7 "SPI_CE0_N" "spi0 CS0"
9 65536 "SPI_MISO" ""
π₯ GMODE h g β GPIO get mode π₯
Gets the mode for GPIO g of an opened gpiochip. and it comes with a whole bit menu, so let's get into it:
- Bit
0β Value1β Kernel: In use by the kernel - Bit
1β Value2β Kernel: Output - Bit
2β Value4β Kernel: Active low - Bit
3β Value8β Kernel: Open drain - Bit
4β Value16β Kernel: Open source - Bit
5β Value32β Kernel: Pull up set - Bit
6β Value64β Kernel: Pull down set - Bit
7β Value128β Kernel: Pulls off set - Bit
8β Value256β LG: Input - Bit
9β Value512β LG: Output - Bit
10β Value1024β LG: Alert - Bit
11β Value2048β LG: Group - Bit
12β Value4096β LG: --- - Bit
13β Value8192β LG: --- - Bit
14β Value16384β LG: --- - Bit
15β Value32768β LG: --- - Bit
16β Value65536β Kernel: Input - Bit
17β Value1<<17β Kernel: Rising edge alert - Bit
18β Value1<<18β Kernel: Falling edge alert - Bit
19β Value1<<19β Kernel: Realtime clock alert
The LG bits are only set if the query was made by the process that owns the GPIO. so it's giving β¨exclusive accessβ¨ iykyk
π GSI h g β GPIO claim for input (simple) π
Claims GPIO g for input. mine now π
Example
$ rgs c 1 gsi 1 23 # claim GPIO 23 for input.
π¦ GSIX h lf g β GPIO claim for input π¦
Claims GPIO g for input. same vibe, but with β¨optionsβ¨
The line flags lf may be used to set the GPIO as active low, open drain, open source, pull up, pull down, pull off.
Example
$ rgs c 1 gsi 1 0 23 # claim GPIO 23 for input.
β GSO h g β GPIO claim for output (simple) β
Claims GPIO g for output.
The GPIO will be initialised low. lowkey starting low and humble fr
Example
$ rgs c 1 gso 1 25 # claim GPIO 25 for low output.
π GSOX h lf g v β GPIO claim for output π
Claims GPIO g for output.
The line flags lf may be used to set the GPIO as active low, open drain, open source, pull up, pull down, pull off.
If v is zero the GPIO will be initialised low. If any other value is used the GPIO will be initialised high. zero = low, anything else = high, that's the whole rule, periodt π
Example
$ rgs c 1 gso 1 0 25 # claim GPIO 25 for high output.
π GSA h g nfyh β GPIO claim for alerts (simple) π
Claims GPIO g for alerts.
Alerts will be generated for both edges. equal opportunity alerting honestly.
The alerts will be sent to a previously opened notification pipe nfyh.
π GSAX h lf ef g nfyh β GPIO claim for alerts π
Claims GPIO g for alerts.
The line flags lf may be used to set the GPIO as active low, open drain, open source, pull up, pull down, pull off.
The event flags ef specify whether alerts should be generated on a rising edge, a falling edge, or both edges.
The alerts will be sent to a previously opened notification pipe nfyh.
π GSF h g β GPIO free π
Releases GPIO g. The GPIO may now be claimed by another user or for a different purpose. we're letting it go, it's not you it's the pin assignment π
π§ GSGI h *g** β GPIO group claim for inputs (simple) π§
Claims a group of GPIO for inputs. squad goals.
*g** is a list of one or more GPIO. The first GPIO in the list is called the group leader and is used to reference the group as a whole. main character energy of the group ngl π
Example
$ rgs c 1 gsgi 1 16 17 18 19 20 21
π«Ά GSGIX h lf *g** β GPIO group claim for inputs π«Ά
Claims a group of GPIO for inputs. All the GPIO share the same line flag setting. matching fits, love that for them π
The line flags lf may be used to set the GPIO as active low, open drain, open source, pull up, pull down, pull off.
*g** is a list of one or more GPIO. The first GPIO in the list is called the group leader and is used to reference the group as a whole.
Example
$ rgs c 1 gsgix 1 0 16 17 18 19 20 21
π GSGO h *g** β GPIO group claim for outputs (simple) π
Claims a group of GPIO for outputs.
*g** is a list of one or more GPIO. The first GPIO in the list is called the group leader and is used to reference the group as a whole.
The GPIO will be initialised low.
Example
$ rgs c 1 gsgo 1 22 23 24 25
π GSGOX h lf *g** *v** β GPIO group claim for outputs π
Claims a group of GPIO for outputs. All the GPIO and share the same line flag setting. besties who configure together stay together π
The line flags lf may be used to set the GPIO as active low, open drain, open source, pull up, pull down, pull off.
*g** is a list of one or more GPIO. The first GPIO in the list is called the group leader and is used to reference the group as a whole.
*v** is a list of initialisation values for the GPIO. If a value is zero the corresponding GPIO will be initialised low. If any other value is used the corresponding GPIO will be initialised high.
Example
$ rgs c 1 gsgox 1 0 22 23 24 25 1 1 1 1
π GSGF h g β GPIO group free π
Releases the group of GPIO identified by the group leader g. The GPIO may now be claimed by another user or for a different purpose. the whole groupchat is disbanding π
Example
rgs c 1 gsgf 1 22
β‘ GR h g β GPIO read β‘
Returns the current value (0 or 1) of GPIO g.
This command will work for any claimed GPIO (even if a member of a group). For an output GPIO the value returned will be that last written to the GPIO.
Example
$ rgs c 1 gr 1 22
1
π₯ GW h g v β GPIO write π₯
Sets the value (0 or 1) of GPIO g.
This command will work for any GPIO claimed as an output (even if a member of a group).
If v is zero the GPIO will be set low. If any other value is used the GPIO will be set high.
π GGR h g β GPIO group read π
Reads a group of GPIO identified by group leader g.
This command will work for an output group as well as an input group. For an output group the value returned will be that last written to the group GPIO. Note that this command will also work on an individual GPIO claimed as an input or output as that is treated as a group with one member. solo group, still a group, no gatekeeping here π«Ά
Two values are returned. The first is the group size (the number of GPIO in the group). The second is the group bits as a decimal value.
Bit 0 is the level of the group leader. Bit 1 is the level of the second GPIO in the group. Bit g is the level of GPIO g+1 in the group.
Example
$ rgs c 1 gsgi 1 0 16 17 18 19 20 21
$ rgs c 1 ggr 1 16
6 49 # six GPIO, group leader (16) high, 17-19 low, 20-21 high
β¨ GGW h g gbits β GPIO group write (simple) β¨
Writes a group of GPIO identified by group leader g.
The values of each GPIO of the group are set according to the bits of gbits.
Bit 0 sets the level of the group leader. Bit 1 sets the level of the second GPIO in the group. Bit g sets the level of GPIO g+1 in the group.
Example
$ rgs c 1 ggr 1 22
4 15
$ rgs c 1 ggw 1 22 5
$ rgs c 1 ggr 1 22
4 5
$ rgs c 1 ggw 1 22 10
$ rgs c 1 ggr 1 22
4 10
π GGWX h g gbits gmask β GPIO group write π
Writes a group of GPIO identified by group leader g.
The values of each GPIO of the group are set according to the bits of gbits.
Bit 0 sets the level of the group leader. Bit 1 sets the level of the second GPIO in the group. Bit g sets the level of GPIO g+1 in the group.
However this may be modified by the gmask. A GPIO is only updated if the corresponding bit in the mask is 1. selective updating, we love a little permission slip π
Example
$ rgs c 1 ggr 1 22
4 15
$ rgs c 1 ggw 1 22 5 15
$ rgs c 1 ggr 1 22
4 5
$ rgs c 1 ggw 1 22 10 0
$ rgs c 1 ggr 1 22
4 5
$ rgs c 1 ggw 1 22 10 15
$ rgs c 1 ggr 1 22
4 10
πΈ GP h g mon moff β GPIO tx pulse (simple) πΈ
Starts software timed pulses on GPIO g.
Each cycle consists of mon microseconds of GPIO high followed by moff microseconds of GPIO low.
PWM is characterised by two values, its frequency (number of cycles per second) and its duty cycle (percentage of high time per cycle).
The set frequency will be 1000000 / (mon + moff) Hz.
The set duty cycle will be mon / (mon + moff) * 100 %.
E.g. if mon is 50 and moff is 100 the frequency will be 6666.67 Hz and the duty cycle will be 33.33 %.
π GPX h g mon moff off cyc β GPIO tx pulse π
Starts software timed pulses on GPIO g.
cyc cycles are transmitted (0 means infinite). Each cycle consists of mon microseconds of GPIO high followed by moff microseconds of GPIO low.
PWM is characterised by two values, its frequency (number of cycles per second) and its duty cycle (percentage of high time per cycle).
The set frequency will be 1000000 / (mon + moff) Hz.
The set duty cycle will be mon / (mon + moff) * 100 %.
E.g. if mon is 50 and moff is 100 the frequency will be 6666.67 Hz and the duty cycle will be 33.33 %.
off is a microsecond offset from the natural start of the PWM cycle.
For instance if the PWM frequency is 10 Hz the natural start of each cycle is at seconds 0, then 0.1, 0.2, 0.3 etc. In this case if the offset is 20000 microseconds the cycle will start at seconds 0.02, 0.12, 0.22, 0.32 etc. shifting the whole thing over, iconic behaviour tbh β¨
Another command may be issued to the GPIO before the last has finished. yes really, it's giving overlap, it's giving multitasking, it's giving chaos π
If the last command had infinite cycles (cyc of 0) then it will be replaced by the new settings at the end of the current cycle. Otherwise it will be replaced by the new settings at the end of cyc cycles.
Multiple pulse settings may be queued in this way. β¨
πΈ P h g pf pdc β GPIO tx PWM (simple)
This command starts software timed PWM on GPIO g. π
PWM is characterised by two values, its frequency (number of cycles per second) and its duty cycle (percentage of high time per cycle).
π¦ PX h g pf pdc off cyc β GPIO tx PWM
This command starts software timed PWM on GPIO g. π
PWM is characterised by two values, its frequency (number of cycles per second) and its duty cycle (percentage of high time per cycle).
off is a microsecond offset from the natural start of the PWM cycle.
For instance if the PWM frequency is 10 Hz the natural start of each cycle is at seconds 0, then 0.1, 0.2, 0.3 etc. In this case if the offset is 20000 microseconds the cycle will start at seconds 0.02, 0.12, 0.22, 0.32 etc. π
Another PWM command may be issued to the GPIO before the last has finished.
If the last PWM had infinite cycles (cyc of 0) then it will be replaced by the new settings at the end of the current cycle. Otherwise it will be replaced by the new settings at the end of cyc cycles.
Multiple PWM settings may be queued in this way. π
β S h g spw β GPIO tx servo pulses (simple)
This command starts software timed servo pulses on GPIO g. πΈ
I would only use software timed servo pulses for testing purposes. The timing jitter will cause the servo to fidget. This may cause it to overheat and wear out prematurely. π
π SX h g spw sf off cyc β GPIO tx servo pulses
This command starts software timed servo pulses on GPIO g. π
I would only use software timed servo pulses for testing purposes. The timing jitter will cause the servo to fidget. This may cause it to overheat and wear out prematurely. π
Another servo command may be issued to the GPIO before the last has finished.
If the last command had infinite cycles (cyc of 0) then it will be replaced by the new settings at the end of the current cycle. Otherwise it will be replaced by the new settings at the end of cyc cycles.
Multiple servo settings may be queued in this way. β¨
π GWAVE h g p* β GPIO group tx wave
This command starts a wave on GPIO group g. π
p is a series of pulses to be transmitted on the GPIO group.
Each pulse is defined by the following triplet:
gbitsβ the levels to set for the selected GPIOgmaskβ the GPIO to selectusβ the delay in microseconds before the next pulse
Another wave command may be issued to the GPIO group before the last has finished transmission.
Multiple waves may be queued in this way. π«
π§ GBUSY h g k β GPIO or group tx busy
This command checks to see if a specified kind k of transmission is ongoing on a GPIO or GPIO group g.
The command returns 1 if transmission is ongoing, otherwise 0. π
π GROOM h g k β GPIO or group tx entries
This returns the number of slots there are to queue further transmissions of a specified kind k in the tx queue for GPIO or GPIO group g.
The command returns the number of free slots (0 for no free slots). π―
π GDEB h g us β GPIO debounce time
This command sets the debounce time for GPIO g to us microseconds.
This command is only effective when the GPIO is being used as a source of alerts. β οΈ
Any level changes shorter than the debounce setting will be discarded, i.e. they will not generate an alert.
Reported level changes will be timestamped us microseconds after the level change. β±οΈ
π₯ GWDOG h g us β GPIO watchdog time
This command sets the watchdog time for GPIO g to us microseconds.
This only affects alerts.
A watchdog alert will be sent if no edge alert has been issued for that GPIO in the previous watchdog microseconds.
Note that only one watchdog alert will be sent per stream of edge alerts. The watchdog is reset by the sending of a new edge alert.
The level is set to 2 for a watchdog alert. π
π I2C π
π I2CO ib id if β I2C open device
This is a privileged command. See permits. π
This command returns a handle to access device id on I2C bus ib. The device is opened with flags if.
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
$ rgs c 1 i2co 1 0x70 0 # Bus 1, device 0x70, flags 0.
0
$ rgs c 1 i2co 1 0x53 0 # Bus 1, device 0x53, flags 0.
1
π¦ I2CC h β I2C close device
This command closes an I2C device previously opened by I2CO.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2cc 0 # First close okay.
$ rgs c 1 i2cc 0 # Second fails.
-25
ERROR: unknown handle
πΈ I2CWQ h bit β SMB Write Quick: write bit
This command writes a single bit to the I2C device.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2cwq 0 1
β I2CRS h β SMB Read Byte: read byte
This command returns a single byte read from the I2C device.
Upon success a value between 0 and 255 will be returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2crs 0
0
π
I2CWS h bv β SMB Write Byte: write byte
This command writes a single byte bv to the I2C device.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2cws 0 0x12
$ rgs c 1 i2cws 0 0xff
-82
ERROR: I2C write failed
π 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.
Upon success a value between 0 and 255 will be returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2crb 0 0
6
π¦ 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.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2cwb 0 10 0x54
π 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.
Upon success a value between 0 and 65535 will be returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2crw 0 0
6150
π₯ 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.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2cww 0 0 0xffff
π 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.
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
$ rgs c 1 i2crk 0 0
6 0 0 0 0 0 0
$ rgs c 1 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
π 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.
Upon success nothing is returned. On error a negative status code will be returned.
Example
rgs c 1 i2cwk 0 4 0x01 0x04 0xc0
π§ 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.
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
$ rgs c 1 i2cri 0 0 16
16 237 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155
πΈ 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.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 i2cwi 0 4 0x01 0x04 0xc0
β I2CRD h num β I2C read device
This command returns num bytes read from the I2C device.
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. rgs imposes a limit of about 8000 bytes.
Example
$ rgs c 1 i2crd 0 16
16 6 24 0 0 0 0 0 0 0 0 0 0 0 0 32 78
π I2CWD h bvs β I2C write device
This command writes a block of bytes bvs to the I2C device.
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. rgs imposes a limit of about 500 bytes.
This command operates on the raw I2C device.
Example
$ rgs c 1 i2cwd 0 0x01 0x02 0x03 0x04
π I2CPC h r wv β SMB Process Call: exchange register with word
This command writes wv to register r of the I2C device 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
$ rgs c 1 i2cpc 0 37 43210
39933
$ rgs c 1 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 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
$ rgs c 1 i2cpk 0 0 0x11 0x12
6 0 0 0 0 0 0
I2CZ h bvs - I2C zip π¦
Okay so this one is literally a whole queue of I2C operations bundled into one command, and it's giving efficiency β¨. The operations to be performed are specified by the contents of bvs, which holds the concatenated command codes plus their associated data.
Here are the command codes you get to play with:
- End β
0β no more commands, we're done, periodt π - Escape β
1β the nextPis two bytes - Address β
2 Pβ set the I2C address toP - Flags β
3 lsb msbβ set the I2C flags tolsb + (msb << 8) - Read β
4 Pβ readPbytes of data - Write β
5 P ...β writePbytes of data
The address, read, and write commands all take a parameter P. Normally P is one byte (0-255). But if the command is preceded by the Escape command, then P is two bytes (0-65535, least significant byte first) β glow up π.
The address defaults to the one associated with the handle h. The flags default to 0. And heads up bestie: the address and flags keep their previous value until updated, so they just stay sticky like that π«Ά.
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:
2 0x53 5 1 0x32 4 6
2 0x1E 5 1 0x03 4 6
2 0x68 5 1 0x1B 4 8
0
π NOTIFICATIONS π
NO - Notification open π
This is a privileged command. See permits.
This command requests a free notification handle.
A notification is a method for being notified of GPIO state changes via a pipe. So like, the GPIO changes and it tells you through a pipe. Very main character of it π.
Upon success the command returns a handle greater than or equal to zero. On error a negative status code will be returned.
The pipes are created in the daemon's working directory (the command pwd will show the working directory).
Notifications for handle x will be available at the pipe named .lgd-nfyx (where x is the handle number).
E.g. if the command returns 15 then the notifications must be read from .lgd-nfy15.
Example
$ rgs c 1 no
0
NC h - Notification close π
This command closes a notification previously opened by NO.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 nc 0 # First call succeeds.
$ rgs c 1 nc 1 # Second call fails.
-5
ERROR: unknown handle
NP h - Notification pause βΈοΈ
This command pauses notifications.
Upon success nothing is returned. On error a negative status code will be returned.
Notifications for the handle are paused until a NR command.
Example
$ rgs c 1 np 0
NR h - Notification resume βΆοΈ
This command resumes notifications.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs c 1 nr 0
$ rgs c 1 nr 1
-5
ERROR: unknown handle
π SCRIPTS π
PROC t - Script store πΎ
This is a privileged command. See permits.
This command stores a script t for later execution.
If the script is valid a handle (>=0) is returned which is passed to the other script commands. On error a negative status code will be returned.
Example
$ rgs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123
0
$ rgs proc tag 123 w 4 0 mils 5 w 4 1 mils 5 jmp 12
ERROR: script has unresolved tag
-63
PROCR h pars - Script run πββοΈ
This command runs stored script h passing it up to 10 optional parameters.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123
0
$ rgs procr 0 50 # Run script 0 with parameter 0 of 50.
$ rgs procp 0
2 44 0 0 0 0 0 0 0 0 0
$ rgs procp 0
2 37 0 0 0 0 0 0 0 0 0
$ rgs procp 0
2 10 0 0 0 0 0 0 0 0 0
$ rgs procp 0
2 5 0 0 0 0 0 0 0 0 0
$ rgs procp 0
2 2 0 0 0 0 0 0 0 0 0
$ rgs procp 0
1 -1 0 0 0 0 0 0 0 0 0
PROCU h pars - Script update parameters π
This command sets the parameters of a stored script h passing it up to 10 parameters.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs proc tag 0 hp 18 p0 p1 mils 1000 jmp 0
0
$ rgs procu 0 50 500000
$ rgs procr 0
$ rgs procu 0 100
$ rgs procu 0 200
$ rgs procu 0 200 100000
PROCP h - Script get status and parameters π
This command returns the status of script h 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 initialised1β ready2β running3β waiting4β ended5β halted6β failed π
Example
$ rgs procp 0
1 0 0 0 0 0 0 0 0 0 0
PROCS h - Script stop π
This command stops a running script h.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs procs 0
$ rgs procs 1
-5
ERROR: unknown handle
PROCD h - Script delete ποΈ
This command deletes script h.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs procd 1
$ rgs procd 1
ERROR: unknown handle
-5
PARSE t - Script validate π§
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.
This command may be used to find script syntax faults β lowkey the linting bestie of this whole page β¨.
Example
$ rgs parse tag 100 w 22 1 mils 200 w 22 0 mils 800 jmp 100
$ rgs 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
π SERIAL π
SERO dev b sef - Serial open device π
This is a privileged command. See permits.
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 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
$ rgs sero /dev/ttyAMA0 9600 0
0
$ rgs sero /dev/tty1 38400 0
1
SERC h - Serial close device πͺ
This command closes a serial device previously opened by SERO.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs serc 0 # First close okay.
$ rgs serc 0 # Second close gives error.
-25
ERROR: unknown handle
SERRB - Serial read byte π
This command returns a byte of data read from the serial device.
Upon success a number between 0 and 255 is returned. On error a negative status code will be returned.
Example
$ rgs serrb 0
23
$ rgs serrb 0
45
SERWB h bv - Serial write byte βοΈ
This command writes a single byte bv to the serial device.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs serwb 0 23
$ rgs serwb 0 0xf0
SERR h num - Serial read bytes π
This command returns up to num bytes of data read from the serial 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
$ rgs serr 0 10
5 48 49 128 144 255
$ rgs serr 0 10
0
SERW h bvs - Serial write bytes π¦
This command writes bytes bvs to the serial device.
Upon success nothing is returned. On error a negative status code will be returned.
Example
$ rgs serw 0 23 45 67 89
SERDA h - Serial data available πΆ
This command returns the number of bytes of data available to be read from the serial device.
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
$ rgs serda 0
0
π SHELL π
SHELL name str - Execute a shell command π
This is a privileged command. See permits.
This command uses the system call to execute a shell script name with the given string str as its parameter.
Upon success the exit status of the system call is returned. On error a negative status code will be returned.
name must exist in a directory named cgi in the daemon's configuration directory 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.
Here are some example returned statuses, because the numbers are genuinely wild π:
- Script exit status
1β returned system call status256 - Script exit status
5β returned system call status1280 - Script exit status
10β returned system call status2560 - Script exit status
200β returned system call status51200 - script not found β returned system call status
32512
Example
# pass two parameters, hello and world
$ rgs shell scr1 hello world
256
# pass three parameters, hello, string with spaces, and world
$ rgs shell scr1 "hello 'string with spaces' world"
256
# pass one parameter, hello string with spaces world
$ rgs shell scr1 "
256
# non-existent script
$ rgs shell scr78 par1
32512
π SPI π
SPIO spd spc b spf - SPI open device π
This is a privileged command. See permits.
Upon success a handle is returned. On error a negative status code will be returned.
Data will be transferred at b bits per second. The flags spf may be used to modify the default behaviour.
The flags consists of the least significant 2 bits.
1 0
m m
mm defines the SPI mode.
Mode POL PHA
0 0 0
1 0 1
2 1 0
3 1 1
SPIC h - SPI close device π
This command closes a SPI device previously opened by SPIO.
Upon success nothing is returned. On error a negative status code will be returned. π
Example:
$ rgs spic 1
$ rgs spic 1
-25
ERROR: unknown handle
SPIR h num β SPI read bytes π¦
Bestie, this one returns num bytes read from the SPI 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:
$ rgs 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 β¨
This command writes bytes bvs to the SPI device.
Upon success nothing is returned. On error a negative status code will be returned.
Example:
$ rgs spiw 0 0x22 0x33 0xcc 0xff
SPIX h bvs β SPI transfer bytes π₯
This command writes bytes bvs to the SPI device.
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:
$ rgs spix 0 0x22 0x33 0xcc 0xff
4 0 0 0 0
π οΈ UTILITIES π
LGV β get lg library version πΈ
This command returns the lg library version.
$ rgs lgv
lg_0.1.0.0
SBC β get SBC's host name π
This command returns the rgpiod daemon server name.
$ rgs sbc
venus
CGI cid β get internal configuration setting π
This is a privileged command. See permits.
This command returns the value of an internal library configuration setting cid.
$ rgs cgi 0
1
CSI cid v β set internal configuration setting π
This is a privileged command. See permits.
This command sets the value of the internal library configuration setting cid to v.
$ rgs csi 0 3
$ rgs cgi 0
3
T/TICK β get nanoseconds since the epoch β±οΈ
T and TICK are synonyms.
This command returns the number of nanoseconds since the epoch (start of 1970).
$ rgs t
1601838936723095901
$ rgs tick
1601838940792322758
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.
$ rgs mics 20 # Delay 20 microseconds.
$ rgs mics 1000000 # Delay 1 second.
$ rgs mics 5100000 # Delay 5.1 seconds.
-24
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.
$ rgs mils 2000 # Delay 2 seconds.
$ rgs mils 301000 # Delay 301 seconds.
-25
ERROR: bad MILS delay (too large)
U/USER β set user π«Ά
U and USER are synonyms.
This command sets the current user and associated permissions.
$ rgs u test1 # set user test1
$ rgs user test1 # set user test1
$ rgs u testx # unknown user
-95
ERROR: bad secret for user
C/SHARE β set share π
C and SHARE are synonyms.
This command sets the share for handles.
The command has two uses. Firstly it sets the share id for any subsequently created handles on the current command line. Secondly it sets the share id to use to access any previously created handles on this or earlier command lines.
rgs c 1 # use share id 1
rgs share 1 # use share id 1
rgs c 0 # switch off sharing
rgs share 867 # use share id 867
LCFG β reload permits configuration file π
This is a privileged command. See permits.
This command reloads the permits configuration file.
$ rgs lcfg
$ rgs lcfg
-93
ERROR: no permission to perform action
$ rgs lcfg
-93
ERROR: no permission to perform action
PCD β print daemon configuration directory π
This command prints the daemon configuration directory.
rgs pcd
/home/joan/LG/TEST
PWD β print daemon working directory π
This command prints the daemon working directory.
rgs pwd
/home/joan/LG
π PARAMETERS π
b: baud β the command expects the baud rate in bits per second for the transmission of serial data (I2C/SPI/serial link, waves).bit: bit value (0-1) β the command expects0or1.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.cidβ a number identifying an internal configuration item.0β debug level1β minimum transmission period for PWM and waves
cyc: >= 0 β the number of PWM pulses to generate. A value of0means infinite.dev: a tty serial device β the command expects the name of a serial device, e.g./dev/ttyAMA0/dev/ttyUSB0/dev/tty0/dev/serial0
ef: GPIO event flags β the following values may be or'd to form the event flags.1β Rising edge2β Falling edge3β Both edges
file: a file name β the file name must match an entry in the[files]section of the permits file.from: 0-2 β position to seek from FS.0β start1β current position2β end
g: GPIO β the command expects a GPIO.g*β a list of one or more GPIO.gbitsβ this value is used to set the levels of a GPIO group.- Bit 0 represents the level of the group leader.
- Bit 1 represents the level of the second GPIO in the group.
- Bit
grepresents the level of GPIOg+1in the group.
gc: gpiochip (>=0) β the command expects a gpiochip number.gmaskβ this value is used to select GPIO from a GPIO group.- Bit 0 of the mask indicates item 1
- Bit 1 of the mask indicates item 2
- Bit
gof the mask indicates itemg+1 - For example suppose the items are GPIO 5, 10, 23, 25, 11.
- Bit 0 of the mask indicates GPIO 5
- Bit 1 of the mask indicates GPIO 10
- Bit 2 of the mask indicates GPIO 23
- Bit 3 of the mask indicates GPIO 25
- Bit 4 of the mask indicates GPIO 11
- If a bit of the mask is high the corresponding GPIO will be selected.
- E.g. in the above example if the mask has the value 17 GPIO 5 and GPIO 11 will be selected.
h: handle (>=0) β the command expects a handle.- A handle is a number referencing an object opened by one of
FO,I2CO,NO,PROC,SERO,SPIO,GO.
- A handle is a number referencing an object opened by one of
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.kβ a kind of transmission.0= PWM1= WAVE
lf: GPIO line flags β the following values may be or'd to form the line flags.4β Active low8β Open drain16β Open source32β Pull up64β Pull down128β Pull none
mode: lgFile open mode β one of the following values.READ=1β open file for readingWRITE=2β open file for writingRW=3β open file for reading and writing- The following values can be or'd into the mode.
APPEND=4β All writes append data to the end of the fileCREATE=8β The file is created if it doesn't existTRUNC=16β The file is truncated
moff: >= 0 β the off period for a PWM pulse in microseconds.mon: >= 0 β the on period for a PWM pulse in microseconds.name: the name of a script β only alphanumeric characters,-and_are allowed in the name.nfyh: >= 0 β this associates a notification with a GPIO event.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
numbytes will be returned.
off: >= 0 β the offset in microseconds from the nominal PWM pulse start.p*β one or more triplets ofgbits,gmask, andusmicrosecond delay.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 the[files]section of the permits file.pdc: % β PWM duty cycle between 0.0 % and 100 % inclusive.pf: Hz β PWM frequency between 0.1 Hz and 10000 Hz inclusive. Use0for off.r: register (0-255) β the command expects an I2C register number.sef: serial flags (32 bits) β the command expects a flag value. No serial flags are currently defined.sf: Hz (40-500) β servo frequency.spc: SPI channel (>= 0) β the command expects a SPI channel.spd: SPI device (>= 0) β the command expects aSPOdevice.spf: SPI flags β see SPIO.spw: 0=off, 500-2500 microseconds β servo pulse width.str: a string β the command expects a string.t: a string β the command expects a string.usβ the command expects a time interval measured in microseconds.v: value β the command expects a number.v*β a list of one or more values.wv: word value (0-65535) β the command expects a word value.
π SEE ALSO π
okay bestie that's the whole entire page, you officially know rgs(1) now, no cap π This one shipped for Linux, dated 2020-2021, and the page is rgs(1) β go forth and poke at your GPIOs, you absolute icon πβ¨π¦
π¦ where this page comes from
- ubuntu noble: rgpio-tools 0.2.0.0-0ubuntu3 Β· LicenseRef-public-domain
- ubuntu questing: rgpio-tools 0.2.0.0-0ubuntu4
- ubuntu resolute: rgpio-tools 0.2.0.0-0ubuntu6 Β· LicenseRef-public-domain
- ubuntu stonking: rgpio-tools 0.2.0.0-0ubuntu6 Β· LicenseRef-public-domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms