Verbindung Scratch <-> Raspberry PI GPIO

Eine der Besonderheiten des Raspberry Pi’s sind die programmierbaren Input-Output Pins. Diese sog. GPIOs können einfach über ein Programm geschaltet werden, was wir in diesem Tutorial durchgehen. Dafür schreiben wir ein Python Programm, womit wir einerseits Eingaben erfassen und andererseits die Raspberry Pi GPIO Pins schalten, um so andere Module und Sensoren schalten zu können. Darüber hinaus erkläre ich in diesem Tutorial die Funktionsweise eines Breadboards / Steckbrett.

Raspberry Pi GPIO Pins schalten – Ausgabe

Zunächst möchten wir ein paar einfache LEDs mittels der GPIOs schalten. Dazu bauen wir die LEDs entsprechend der nachfolgenden Grafik auf. Als Verbindung zwischen Raspberry Pi und dem Breadboard kannst du die Jumper Kabel nehmen und für alle anderen Verbindung einfachen Draht. Die Farben spielen keine Rolle und sind nur zur besseren Unterscheidung gedacht.

Schaltplan

Die LED hat zwei unterschiedlich lange Enden. Das längere Ende kommt an die positive 3.3 Volt Spannung des GPIO 23 (Pin 16). Der gewählte Widerstand ist 330Ω (Ohm).

Scratch

Open the More Blocks panel, click Add an Extension, and select Pi GPIO. You should then see two new blocks appear:

You can use these two purple blocks to control output pins or read input pins by entering the pin number into the field, or using a variable containing the pin number:

LED

To control an LED connected to GPIO10, you can use these blocks:

BUTTON

To read the state of a button connected to GPIO10, you can use these blocks:

Note that the button is pulled up so the GPIO pin will read high when it is not pressed, and low when it is pressed.

LED and BUTTON

To connect the LED and button together, you can use these blocks: