De relatie tussen GPIO-nummers en pinnen is als volgt.
GPIO pin pin GPIO
3V3 1 2 5V
0/2 (SDA) 3 4 5V
1/3 (SCL) 5 6 0V
4 7 8 14 (TXD)
0V 9 10 15 (RXD)
17 (ce1) 11 12 18 (ce0)
21/27 13 14 0V
22 15 16 23
3V3 17 18 24
10 (MOSI) 19 20 0V
9 (MISO) 21 22 25
11 (SCLK) 23 24 8 (CE0)
0V 25 26 7 (CE1)
.......
0 (ID_SD) 27 28 1 (ID_SC)
5 29 30 0V
6 31 32 12
13 33 34 0V
19 (miso) 35 36 16 (ce2)
26 37 38 20 (mosi)
0V 39 40 21 (sclk)
Als de GPIO-kolom een V heeft, geeft dit aan dat de pin is verbonden met de vermogensrail en geen GPIO.
Waar 2 figuren worden weergegeven gescheiden door een/de eerste figuur is het GPIO-nummer dat wordt gebruikt op de eerste revisie Pi B-kaarten.
Hier is een eenvoudige RPM-teller.
#!/usr/bin/env python
import time
import pigpio # http://abyz.co.uk/rpi/pigpio/python.html
REV_GPIO=2 # GPIO getting pulses.
SAMPLE_TIME=3 # Recalculate every SAMPLE_TIME seconds.
pi = pigpio.pi() # Connect to Pi.
cb = pi.callback(REV_GPIO) # Default tally callback.
old_count = cb.tally() # Pulse count.
try:
while True:
time.sleep(SAMPLE_TIME)
new_count = cb.tally() # Pulse count.
print("{} RPM".format(60.0*(new_count-old_count)/SAMPLE_TIME))
old_count = new_count
except KeyboardInterrupt:
cb.cancel() # Cancel callback.
pi.stop() # Disconnect from Pi.