Herunterladen Inhalt Inhalt Diese Seite drucken

Ansteuerung Der Gpio Pins Mittels Python Und Shellscript - Raspberry Pi Foundation Raspberry Pi Handbuch

Inhaltsverzeichnis

6.2.1 Ansteuerung der GPIO Pins mittels Python und Shellscript

Python script:
import RPi.GPIO as GPIO
# GPIO Pins konfigurierren - ein input and ein output
GPIO.setup(11, GPIO.IN)
GPIO.setup(12, GPIO.OUT)
# input von pin 11 einlesen
input_value = GPIO.input(11)
# output auf Pin 12 ausgegeben
GPIO.output(12, True)
Die Nummerierung der Pins 11 und 12 in diesem Beispiel bezieht sich auf
den physikalischen Pin der Stiftleiste die mit GPIO 17 und GPIO 18 in der Abbildung
beschriftet sind.
Shell script:
#!/bin/sh
# GPIO numbers should be from this list
# 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25
# Note that the GPIO numbers that you program here refer to the pins
# of the BCM2835 and *not* the numbers on the pin header.
# So, if you want to activate GPIO7 on the header you should be
# using GPIO4 in this script. Likewise if you want to activate GPIO0
# on the header you should be using GPIO17 here.
# set up GPIO 4 and set to output
echo "4" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio4/direction
# set up GPIO 7 and set to input
echo "7" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio7/direction
# write output
echo "1" > /sys/class/gpio/gpio4/value
# read from input
cat /sys/class/gpio/gpio7/value
# clean up
echo "4" > /sys/class/gpio/unexport
echo "7" > /sys/class/gpio/unexport
Seite 27 / 30
Kontakt: peba@inode.at
Edition 1
Inhaltsverzeichnis
loading

Inhaltsverzeichnis