I don't get it. according to docs, gpio takes WiringPi numbers, unless the -g option is used.
This means I need to export "gpio2" to use BCM pin 27.
However, the value of this pin 2 doesn't match the value of the BCM pin 27. (This is on a 2+)
Code: Select all
pi@raspberrypi:~/robot_software/controller $ gpio unexportall
pi@raspberrypi:~/robot_software/controller $ gpio export 2 in
pi@raspberrypi:~/robot_software/controller $ gpio -g mode 27 in
pi@raspberrypi:~/robot_software/controller $ gpio -g mode 27 up
pi@raspberrypi:~/robot_software/controller $ gpio -g read 27
1
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio2/value
1
pi@raspberrypi:~/robot_software/controller $ gpio -g mode 27 down
pi@raspberrypi:~/robot_software/controller $ gpio -g read 27
0
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio2/value
1
pi@raspberrypi:~/robot_software/controller $ gpio readall
+-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | ALT2 | 0 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 0 | ALT2 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | ALT2 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | ALT2 | 1 | 11 || 12 | 1 | ALT2 | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | ALT2 | 0 | 15 || 16 | 0 | OUT | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | ALT2 | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | ALT2 | 1 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | ALT2 | 1 | 21 || 22 | 0 | ALT2 | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | ALT2 | 0 | 23 || 24 | 1 | ALT2 | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | ALT2 | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | ALT2 | 1 | 27 || 28 | 0 | ALT2 | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | ALT2 | 1 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 0 | 31 || 32 | 1 | ALT2 | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | ALT2 | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | ALT2 | 1 | 35 || 36 | 1 | ALT2 | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | ALT2 | 0 | 37 || 38 | 1 | ALT2 | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | ALT2 | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
This is another problem:
Code: Select all
pi@raspberrypi:~/robot_software/controller $ gpio -g export 27 in
gpio: Unknown command: export.
But it seems like the "export" part of the GPIO tool always uses the BCM numbering?
Code: Select all
pi@raspberrypi:~/robot_software/controller $ gpio export 27 in
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio27/value
0
pi@raspberrypi:~/robot_software/controller $ gpio -g mode 27 up
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio27/value
1
pi@raspberrypi:~/robot_software/controller $ gpio -g mode 27 down
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio27/value
0
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio2/value
1
pi@raspberrypi:~/robot_software/controller $
However, "mode" does not; it requires -g:
Code: Select all
pi@raspberrypi:~/robot_software/controller $ gpio mode 27 up
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio27/value
0
pi@raspberrypi:~/robot_software/controller $ gpio -g mode 27 up
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio27/value
1
This matches the expectation that "non-G" GPIO pin numbers:
Code: Select all
pi@raspberrypi:~/robot_software/controller $ gpio mode 2 down
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio27/value
0
pi@raspberrypi:~/robot_software/controller $ gpio mode 2 up
pi@raspberrypi:~/robot_software/controller $ cat /sys/class/gpio/gpio27/value
1
But, wait -- /sys/class/gpio/gpio2/value uses the wiringPi number, but /sys/class/gpio/gpio27/value uses the BCM number for the same pin!
WHAAAAT!??!?!?
I may need to just give my program root and use the "standard" wiringPi interface instead. I can't make sense of this behavior.