{"id":497,"date":"2021-04-09T18:41:21","date_gmt":"2021-04-09T18:41:21","guid":{"rendered":"http:\/\/www.peakproductions.at\/sides\/peakproductions\/?p=497"},"modified":"2021-04-10T05:42:36","modified_gmt":"2021-04-10T05:42:36","slug":"raspberry-pi-led-zum-blinken-bringen-mit-gpio-befehlen-und-python","status":"publish","type":"post","link":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/2021\/04\/09\/raspberry-pi-led-zum-blinken-bringen-mit-gpio-befehlen-und-python\/","title":{"rendered":"Raspberry Pi &#8211; LED zum blinken bringen mit GPIO Befehlen und Python"},"content":{"rendered":"\n<p>In diesem Beitrag geht es darum, dass wir eine LED beim Raspberry Pi zum blinken bringen. Klingt einfach, ist es auch. Ich werde in dieser Anleitung Schritt f\u00fcr Schritt erkl\u00e4ren wie die LED angeschlossen werden muss, was f\u00fcr Bibliotheken installiert werden m\u00fcssen und noch ein paar allgemeine Informationen dazu erz\u00e4hlen. <\/p>\n\n\n\n<p>Im ersten Schritt wird eine Verbindung via ssh hergestellt. Falls du noch keinen Raspberry Pi konfiguriert hast, geht&#8217;s <strong><a href=\"http:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/2021\/03\/16\/raspberry-pi-betriebsystem-installieren-mit-dem-wlan-verbinden-und-ssh-aktivieren-ohne-tastatur-und-maus\/\" data-type=\"post\" data-id=\"352\">hier<\/a><\/strong> zur Einsteiger-Anleitung. Um die IP-Adresse des Raspberry zu finden, kann entweder ein Tool wie beispielsweise der <strong><a href=\"https:\/\/angryip.org\/download\/#mac\">Angry IP Scanner <\/a><\/strong>verwendet werden oder die Weboberfl\u00e4che des Routers. Hier in meinem Beispiel ist diese unter http:\/\/192.168.0.1 erreichbar. auf der Weboberfl\u00e4che gibt es je nach Router eine Option die IP-Adressen von Ger\u00e4ten anzuzeigen.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"982\" style=\"aspect-ratio: 1792 \/ 982;\" width=\"1792\" controls src=\"http:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/Netzwerk.mov\"><\/video><figcaption><em><span class=\"has-inline-color has-background-color-color\">Hier wird die IP-Adresse auf der Weboberfl\u00e4che des Routers angezeigt<\/span><\/em><\/figcaption><\/figure>\n\n\n\n<p>Sobald die IP-Adresse gefunden wurde, kann mittels ssh eine Verbindung hergestellt werden. Unter Windows geht das mit der cmd (Start -&gt; cmd) und bei MacOS mit dem Terminal (CMD + Leertaste und Terminal eingeben). Um eine ssh Verbindung herzustellen wird folgender Befehl ben\u00f6tigt: &#8222;ssh pi@&lt;IP-Adresse&gt;.&#8220; <\/p>\n\n\n\n<p>Jetzt werden ein paar Bibliotheken f\u00fcr Python ben\u00f6tigt. Um die GPIOs anzusteuern, verwende ich die <strong><a href=\"https:\/\/gpiozero.readthedocs.io\/en\/stable\/installing.html\">GPIO-Zero-Bibliothek<\/a><\/strong>, welche mit folgenden Befehlen installiert wird (bei einem aktuellen Raspberry Pi Image werden \u00fcbrigens bereits alle Bibliotheken mitgeliefert):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install python3-gpiozero\nsudo apt install python-gpiozero\nsudo pip3 install gpiozero\nsudo pip install gpiozero<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1364\" style=\"aspect-ratio: 2056 \/ 1364;\" width=\"2056\" controls src=\"http:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/Bibliotheken-1.mov\"><\/video><figcaption><span class=\"has-inline-color has-background-color-color\"><em>Die Bibliotheken sind bei einem aktuellen Image bereits installiert<\/em><\/span><\/figcaption><\/figure>\n\n\n\n<p>Jetzt kann bereits die LED angeschlossen werden. Damit die GPIO-PINS nicht so un\u00fcbersichtlich sind, habe ich eine Excel-Datei erstellt, welches die beiden Reihen aufgeteilt in Spalten hat. Am besten anschauen, es klingt komplizierter als es ist. Gr\u00fcn markiert sind die verwendeten PINs und es steht auch in der Mitte ein Text wof\u00fcr diese verwendet wurden. Das Sheet gibt&#8217;s <strong><a href=\"http:\/\/www.peakproductions.at\/Data\/Pin_Belegung_LED-Tutorial.xlsx\">hier<\/a><\/strong> zum Herunterladen.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"844\" src=\"http:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-09-at-18.01.33-1024x844.png\" alt=\"\" class=\"wp-image-502\" srcset=\"https:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-09-at-18.01.33-1024x844.png 1024w, https:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-09-at-18.01.33-300x247.png 300w, https:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-09-at-18.01.33-768x633.png 768w, https:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-09-at-18.01.33.png 1032w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption><em><span class=\"has-inline-color has-background-color-color\">F\u00fcr diese Tutorial verwende ich nur 2 PINS <\/span><\/em><\/figcaption><\/figure>\n\n\n\n<p>Ebenfalls wird ein 500 Ohm-Widerstand ben\u00f6tigt, den es um ein paar Cent im Web zum kaufen gibt. Ich verwende gerne ein Breadboard f\u00fcr solch einfache Testschaltungen. Um die LED richtig anzuschlie\u00dfen &#8211; es gibt nat\u00fcrlich mehr M\u00f6glichkeiten &#8211; muss ein Kabel vom PIN 8, das ist der Vierte von rechts oben (Auf der Unterseite markiert eine viereckige L\u00f6tstelle den 1er PIN) mit dem Breadboard verbunden werden. Jetzt kommt der Widerstand, dieser kann entweder am Anfang oder am Schluss des Stromkreises angebracht werden. Bei der LED gibt es zwei Beinchen, eines ist immer ein wenig l\u00e4nger, diese ist das Plus-Beinchen. Da eine LED immer eine Diode ist, kann der Strom nur in eine Richtung flie\u00dfen. Wenn also gar nichts geht, dann am besten gleich \u00fcberpr\u00fcfen, ob das lange Beinchen am Pluspol anliegt. Das zweite Ende kommt wieder an den Raspberry Pi und zwar an den PIN 6, welcher GND (-) ist.<\/p>\n\n\n\n<p>Damit w\u00e4ren die Vorbereitungen f\u00fcr die Schaltung abgeschlossen.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"540\" style=\"aspect-ratio: 960 \/ 540;\" width=\"960\" controls src=\"http:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/LED_low_Quality.mp4\"><\/video><figcaption><em><span class=\"has-inline-color has-background-color-color\">Hier wird kurz beschrieben wie die PINs angeschlossen werden k\u00f6nnen<\/span><\/em><\/figcaption><\/figure>\n\n\n\n<p>Jetzt noch zum Programm. Die Bibliothek ist recht einsteigerfreundlich und kann daher einfach bedient werden. Mittels dem Befehl &#8222;sudo nano led.py&#8220; wird eine neue Datei erstellt. In den ersten Zeilen werden die ben\u00f6tigten Bibliotheken importiert. &#8222;red&#8220; ist eine Variable, welche die Funktion LED(14) \u00fcbergeben bekommt. Wobei die 14 f\u00fcr GPIO 14 steht. Mit &#8222;while True:&#8220; wird eine Endlosschleife erzeugt, in der die LED angeschaltet wird, dann eine Sekunde gewartet wird und drauf wieder abgeschaltet wird.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from gpiozero import LED\nfrom time import sleep\n\nred = LED(14)\n\nwhile True:\n    red.on()\n    sleep(1)\n    red.off()\n    sleep(1)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1364\" style=\"aspect-ratio: 2056 \/ 1364;\" width=\"2056\" controls src=\"http:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/Skript.mov\"><\/video><figcaption><em><span class=\"has-inline-color has-background-color-color\">Am Ende muss noch &#8222;sudo python led.py&#8220; mittels Enter best\u00e4tigt werden<\/span><\/em><\/figcaption><\/figure>\n\n\n\n<p>Mit &#8222;strg+x&#8220; kann die Datei gespeichert werden. Dann noch &#8222;sudo python led.py&#8220; ausf\u00fchren und die LED blinkt.<\/p>\n\n\n\n<p>Mit &#8222;strg + c&#8220; kann das Skript abgebrochen werden.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"540\" style=\"aspect-ratio: 960 \/ 540;\" width=\"960\" controls src=\"http:\/\/www.peakproductions.at\/sides\/peakproductions\/wp-content\/uploads\/2021\/04\/LED-blink.mp4\"><\/video><\/figure>\n\n\n\n<p>Viel Spa\u00df beim Nachbauen und sollte es ein Problem geben, dann nicht z\u00f6gern und ein Kommentar hinterlassen :-).<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/2021\/03\/16\/raspberry-pi-betriebsystem-installieren-mit-dem-wlan-verbinden-und-ssh-aktivieren-ohne-tastatur-und-maus\/\" data-type=\"post\" data-id=\"352\">Zum vorherigen Beitrag<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In diesem Beitrag geht es darum, dass wir eine LED beim Raspberry Pi zum blinken bringen. Klingt einfach, ist es auch. Ich werde in dieser Anleitung Schritt f\u00fcr Schritt erkl\u00e4ren wie die LED angeschlossen werden muss, was f\u00fcr Bibliotheken installiert werden m\u00fcssen und noch ein paar allgemeine Informationen dazu erz\u00e4hlen. Im ersten Schritt wird eine &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/2021\/04\/09\/raspberry-pi-led-zum-blinken-bringen-mit-gpio-befehlen-und-python\/\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eRaspberry Pi &#8211; LED zum blinken bringen mit GPIO Befehlen und Python\u201c<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":512,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-497","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/posts\/497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/comments?post=497"}],"version-history":[{"count":9,"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/posts\/497\/revisions"}],"predecessor-version":[{"id":520,"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/posts\/497\/revisions\/520"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/media\/512"}],"wp:attachment":[{"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/media?parent=497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/categories?post=497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.peakproductions.at\/sides\/peakproductions\/index.php\/wp-json\/wp\/v2\/tags?post=497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}