-
Notifications
You must be signed in to change notification settings - Fork 411
/
pigs.1
6380 lines (4754 loc) · 101 KB
/
pigs.1
1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
." 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 percent
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
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 - - 20 19 18 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 - - 9 11 10 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