forked from joan2937/pigpio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pigs.1
5829 lines (4254 loc) · 90.9 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-2018 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 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
pigs is a program and internally uses the socket interface to pigpio
whereas /dev/pigpio uses the pipe interface.
.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 and the socket 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 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
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
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.
.br
When a zero control word is received GPIO 18-21 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.
.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