User manual
29
Numbering of the GPIO ports
The library RPi.GPIO supports two modes to identify the ports. In mode BCM the known GPIO port
numbers are used, as they are also used on command line level or in shell scripts. In alternative mode
BOARD the notation equal the pin numbers from 1 to 26 on a Raspberry Pi board.
GPIO.setup(25, GPIO.OUT) The function GPIO.setup initializes a GPIO port as output or as input. The
initial parameter identifies a port depending on the preset mode
BCM or BOARD by a GPIO number or a pin
number. The second parameter can either be
GPIO.OUT for an output or GPIO.IN for the input.
GPIO.output(25, 1) On the port that is just initialized, 1 is called out. The LED connected there lights up.
Instead of
1 also the predefined values True or GPIO.HIGH may be called out.
time.sleep(5) This function is derived from the previously imported time library and triggers a waiting
time of 5 seconds until the program continues to run.
GPIO.output(25, 0) To turn off the LED you call out the value 0 or False or GPIO.LOW on the GPIO port.
GPIO.cleanup() At the end of a programme the GPIO ports must be reset. This line is doing it for all of the
GPIO ports that were initialized by the programme and at once. Ports that have been initialized by another
programme remain unaffected. That way the process of any other, possibly parallel running programmes is
not disrupted.
Intercepting GPIO warnings
If you configure a GPIO port that was not properly reset and which may be still open due to being used
by another program or by an aborted program, you will receive a warning alert that, however, does not
interrupt the program flow. These alerts can be very useful to detect errors during the process of
developing a program. Yet in a ready-made programme an inexperienced user may get confused.
Therefore there is an option in the GPIO library to suppress these warnings using
GPIO.setwarnings(False).
2.5 Starting Python with GPIO support without terminal
If you work a lot with Python and GPIO, you don’t want to call up LXTerminal every time to start IDLE. There
is an easier way. Add an icon to your desktop that calls the Python IDE using superuser privileges: