forked from joan2937/pigpio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pigs.1
4345 lines (3136 loc) · 68.3 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-2015 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
.br
The socket and pipe interfaces allow control of the gpios 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 PWM on any of gpios 0-31
.br
o servo pulses on any of gpios 0-31
.br
o reading/writing all of the gpios in a bank as one operation
.br
o individually setting gpio modes, reading and writing
.br
o notifications when any of gpios 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 gpios
.br
ALL gpios 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 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
.SH COMMANDS
.br
.IP "\fBBC1 bits\fP - Clear specified gpios in bank 1"
.IP "" 4
This command clears (sets low) the gpios specified by \fBbits\fP in bank 1.
Bank 1 consists of gpios 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 gpios 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 gpios
.br
.EE
.br
.IP "\fBBC2 bits\fP - Clear specified gpios in bank 2"
.IP "" 4
This command clears (sets low) the gpios specified by \fBbits\fP in bank 2.
Bank 2 consists of gpios 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)
.br
.br
$ pigs bc2 1 # clear gpio 32 (first in bank 2)
.br
-42
.br
ERROR: no permission to update one or more gpios
.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 gpios \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 gpios
.br
The baud rate may be between 50 and 500000 bits per second.
.br
The gpios 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 gpios"
.IP "" 4
This command read gpios 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 gpios"
.IP "" 4
This command read gpios 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 gpios in bank 1"
.IP "" 4
This command sets (sets high) the gpios specified by \fBbits\fP in bank 1.
Bank 1 consists of gpios 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 gpios
.br
.EE
.br
.IP "\fBBS2 bits\fP - Set specified gpios in bank 2"
.IP "" 4
This command sets (sets high) the gpios specified by \fBbits\fP in bank 2.
Bank 2 consists of gpios 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)
.br
.br
$ pigs bs2 1 # set gpio 32 (first in bank 2)
.br
-42
.br
ERROR: no permission to update one or more gpios
.br
.EE
.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 "\fBFG u stdy\fP - Set a glitch filter on a gpio"
.IP "" 4
.br
Level changes on the gpio 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
Note, each (stable) edge will be timestamped \fBstdy\fP microseconds
after it was first detected.
.br
.IP "\fBFN u stdy actv\fP - Set a noise filter on a gpio"
.IP "" 4
.br
Level changes on the gpio 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
Note, level changes before and after the active period may
be reported. Your software must be designed to cope with
such reports.
.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 gpios. The latest
frequency setting will be used by all gpios which share a clock.
.br
The gpio must be one of the following.
.br
.EX
4 clock 0 All models
5 clock 1 A+/B+/Pi2 and compute module only (reserved for system use)
6 clock 2 A+/B+/Pi2 and compute module only
20 clock 0 A+/B+/Pi2 and compute module only
21 clock 1 All models but Type 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 125000001 100000
.br
-96
.br
ERROR: hardware PWM frequency not 1-125M
.br
.EE
.br
The same PWM channel is available on multiple gpios. The latest
frequency and dutycycle setting will be used by all gpios which
share a PWM channel.
.br
The gpio must be one of the following.
.br
.EX
12 PWM channel 0 A+/B+/Pi2 and compute module only
13 PWM channel 1 A+/B+/Pi2 and compute module only
18 PWM channel 0 All models
19 PWM channel 1 A+/B+/Pi2 and compute module only
.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
.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 gpios
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
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 bytes"
.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