{"id":1026,"date":"2015-11-11T11:51:24","date_gmt":"2015-11-11T10:51:24","guid":{"rendered":"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/?p=1026"},"modified":"2019-01-11T12:53:53","modified_gmt":"2019-01-11T11:53:53","slug":"raspberry-als-datenlogger-teil1-das-betiebssystem-einrichten","status":"publish","type":"post","link":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/2015\/11\/11\/raspberry-als-datenlogger-teil1-das-betiebssystem-einrichten\/","title":{"rendered":"Raspberry als Datenlogger Teil1&#8230;Das Betriebssystem einrichten"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1026\" class=\"pvc_stats all  \" data-element-id=\"1026\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p style=\"text-align: justify\">Der Raspberry Pi ist ja mittlerweile ein bekannter und beliebter Scheckkartenplatinen-Computer mit dem sich allerlei anstellen l\u00e4sst. Vom TV-Frontend mit <a href=\"http:\/\/kodi.tv\/download\/\" target=\"_blank\" rel=\"noopener\">Kodi<\/a>, \u00fcber Spielekonsolenemulatoren mit <a href=\"http:\/\/blog.petrockblock.com\/retropie\/\" target=\"_blank\" rel=\"noopener\">Retropi<\/a> bis hin zum B\u00fcrorechner, ist damit fast alles m\u00f6glich. In diesem Projekt m\u00f6chte ich vorstellen, wie mit Hilfe des Raspberry Pi Model2 physikalische Gr\u00f6\u00dfen wie Temperatur und Luftfeuchtigkeit gemessen und auf einem Speichermedium geloggt werden. Und zwar mit einem Feuchtesensor der Type HYT939 der am I\u00b2C Bus angeschlossen wird, genauer gesagt: mehrere I\u00b2C Feuchtesensoren am Bus&#8230;<\/p>\n<p style=\"text-align: justify\"><a href=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2015\/11\/DSC_4789.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignleft wp-image-1028 size-medium\" src=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2015\/11\/DSC_4789-300x169.jpg\" alt=\"DSC_4789\" width=\"300\" height=\"169\" srcset=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2015\/11\/DSC_4789-300x169.jpg 300w, https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2015\/11\/DSC_4789-1024x576.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>Wir beginnen zuallererst mit der Versorgung des Raspberry PI. Im Bild ist ein Pi2 in ein einfaches Kunststoffgeh\u00e4use eingebaut und an eine 2Ah USB-Powerbank von RS-Components angeschlossen. Der Ladeanschluss der Powerbank ist vom Geh\u00e4use nach aussen gef\u00fchrt. So kann der Pi wahlweise \u00fcber die Powerbank (mit einer nicht rechenintensiven Anwendung bis zu 3h) oder \u00fcber eine externe USB-Versorgung (z.Bsp. einem Handyladeadapter) betrieben werden. Der I\u00b2C Bus des PI (Pin 3 SDA und Pin 5 SCL sowie Pin 2,4 +5V und GND an Pin 6,14&#8230;) ist auf einen RJ Stecker im Geh\u00e4use ausgef\u00fchrt. Um sp\u00e4ter irgendwelche Statusmeldungen ausgeben zu k\u00f6nnen, sind zwei LEDs an die GPIOs 24 und 18 (an Pin18 und Pin12) angeschlossen. Ein weiterer GPIO wird \u00fcber einen 22k Pulldown-Widerstand an einen Taster an 5V geschaltet. (GPIO23 an Pin16).<\/p>\n<p style=\"text-align: justify\">F\u00fcr die USB Anschl\u00fcsse, Ethernet und HDMI wurden im Geh\u00e4use passende Ausschnitte gemacht, an eine USB Schnittstelle ein Keyboard und an den HDMI Port ein Monitor angeschlossen. Die LAN Verbinung mit Internetzugang sollte auch hergestellt sein, um nach der Ersteinrichtung die ben\u00f6tigten Module und Updates laden zu k\u00f6nnen.<\/p>\n<p style=\"text-align: justify\">Jetzt fehlt nur noch das Speichermedium mit Betriebssystem. Der PI2 ist mit einem Micro-SD Slot ausgestattet. Ich habe hier eine 4GB Micro SD mit einem <a href=\"https:\/\/www.raspberrypi.org\/downloads\/\" target=\"_blank\" rel=\"noopener\">raspian-wheezy<\/a> image bespielt. Um das Imagefile auf einfache Weise auf die SD-Karte zu bekommen, empfiehlt es sich, das Tool <a href=\"http:\/\/sourceforge.net\/projects\/win32diskimager\/\" target=\"_blank\" rel=\"noopener\">win32diskimager<\/a> zu verwenden. Ist die Speicherkarte dann fertiggestellt, kann man beginnen.<\/p>\n<p style=\"text-align: justify\">Der Raspberry zeigt nach dem Einschalten kurz seinen Farbverlauf und dann beginnt auch schon der Bootprozess. Ist der dann beendet, so startet das OS am PI erstmal eine Setup-Routine.<\/p>\n<p>Hier sind nun folgende Schritte durchzuf\u00fchren:<\/p>\n<ul>\n<li>im Menu <strong>internationalisation options<\/strong> unter I1 die entsprechenden locals einstellen -&gt; DE_UTF_8<\/li>\n<li>in <strong>advanced options<\/strong> unter A2&#8230; einen Hostname vergeben z.Bsp.:&#8220;raspisensor&#8220;, in A4&#8230; SSH enablen, in A7 &#8230;I\u00b2C enablen und &#8222;load per default&#8220; und in A8 &#8230; &#8222;serial enable&#8220; und &#8222;login shell&#8220; aktivieren<\/li>\n<li>dann noch <strong>expand&nbsp; filesystem<\/strong> w\u00e4hlen damit der Speicherplatz der gesamten SD-Karte genutzt wird<\/li>\n<li>jetzt noch mit <strong>finish -&gt; reboot<\/strong> neu starten<\/li>\n<\/ul>\n<p style=\"text-align: justify\">Jetzt f\u00e4hrt der PI wieder hoch und bleibt beim Login-Prompt stehen. Mit login: <strong>pi<\/strong> und dem passwort:<strong> raspberry<\/strong> loggt man sich nun ein. Mit den folgenden Kommandos werden Updates und ben\u00f6tigte Module installiert:<\/p>\n<blockquote><p><em>sudo apt-get update<br \/>\nsudo apt-get install python-smbus&nbsp;&nbsp;&nbsp;&nbsp; <\/em>(installiert den system management bus)<br \/>\n<em>sudo modprobe i2c_bcm2708<\/em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (kernelmodule f\u00fcr I\u00b2C von Hand laden)<br \/>\n<em>sudo modprobe i2c_dev<\/em><br \/>\n<em>lsmod<\/em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (geladene Module listen)<br \/>\n<em>sudo i2cdetect -y 1<\/em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; (I\u00b2C ports scannen)<\/p><\/blockquote>\n<p>Es empfiehlt sich, die Kernelmodule per Autostart zu laden. Das geht wie folgt:<\/p>\n<blockquote><p><em>sudo nano \/etc\/modules<\/em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (mit dem Nano-Editor die Datei modules \u00f6ffnen &#8230;)<\/p><\/blockquote>\n<p>dann folgende Zeilen hinzuf\u00fcgen:<\/p>\n<p><em>i2c_bcm2708<\/em><br \/>\n<em>i2c_dev<\/em><\/p>\n<p>dann mit <strong>STRG+X<\/strong> den Editor beenden und bei Speichern <strong>JA<\/strong> w\u00e4hlen.<br \/>\ndanach mit:<\/p>\n<blockquote><p><em>sudo nano \/etc\/modprobe.d\/raspi-blacklist.conf<\/em><\/p><\/blockquote>\n<p style=\"text-align: justify\">\u00fcberpr\u00fcfen, ob hier bereits ein Eintrag &#8222;<strong>blacklist i2c-bcm 2708<\/strong>&#8220; existiert.<br \/>\nFalls ja, ist der auszukommentieren oder zu l\u00f6schen.<\/p>\n<p>jetzt wieder neustarten mit:<\/p>\n<blockquote><p><em>sudo shutdown -r now<\/em><\/p>\n<p>danach wieder einloggen und mit<\/p>\n<p><em>lsmod<\/em><\/p>\n<p>\u00fcberpr\u00fcfen ob die gw\u00fcnschten Module korrekt geladen sind.<em><br \/>\n<\/em><\/p><\/blockquote>\n<p style=\"text-align: justify\">Da wir sp\u00e4ter die Daten von den Sensoren in eine Datei loggen wollen und diese Datei auf einem USB-Stick gespeichert werden soll, sind folgende Schritte notwendig:<\/p>\n<ul>\n<li>einen USB-Sick mit FAT32 Filesystem auf einem Windowsrechner formatieren<\/li>\n<li>auf dem PI das Filesystem FAT32 installieren<\/li>\n<li>den Stick in den PI stecken und die Mountlist um den Stick erweitern<\/li>\n<\/ul>\n<p>Zuerst laden und installieren wir das Filesystem:<\/p>\n<blockquote><p><em>sudo apt-get -y install ntfs-3g hfsutils hfsprogs exfat-fuse<\/em><\/p><\/blockquote>\n<p>dann legen wir folgendes Verzeichnis an:<\/p>\n<blockquote><p><em>sudo mkdir \/media\/usbstick <\/em>(<em>usbstick<\/em> dient hier als beispielname&#8230;)<em><br \/>\n<\/em><\/p>\n<p><em>sudo blkid -o list -w \/dev\/null<\/em><\/p>\n<p>(listet die IDs der Datentr\u00e4ger auf -&gt; unser Stick sollte in der Liste als vfat mit einer ID in dem Format XXXX-XXXX erscheinen)<\/p>\n<p><em>sudo mount -t vfat -o utf8,uid=pi,gid=pi,noatime \/dev\/sda \/media\/usbstick<\/em><\/p><\/blockquote>\n<p>nun \u00f6ffnen wir folgende Datei mit dem Editor:<\/p>\n<blockquote><p><em>sudo nano -w \/etc\/fstab<\/em><\/p><\/blockquote>\n<p>die ID des USB-Sticks von vorher tragen wir nun samt folgender Zeile ein und speichern dann wieder ab:<\/p>\n<p><em>UUID=XXXX-XXXX \/media\/usbstick\/ vfat utf8,uid=pi,gid=pi,noatime 0<\/em><\/p>\n<p>weiter geht&#8217;s mit der Einrichtung der GPIOs und den Python libraries:<\/p>\n<blockquote><p>sudo apt-get install python-dev<br \/>\nsudo apt-get install python-rpi.gpio<\/p><\/blockquote>\n<p>Noch ein paar allgemeine Einstellungen:<\/p>\n<blockquote><p>sudo nano \/etc\/networks\/interfaces&nbsp; (Wir wollen eine fixe IP Adresse vergeben, um sp\u00e4ter einfach per SSH auf den PI zugreifen zu k\u00f6nnen)<\/p><\/blockquote>\n<p>folgende Zeile ersetzen:<\/p>\n<blockquote><p>iface eth0 inet dhcp<\/p><\/blockquote>\n<p>durch:<\/p>\n<blockquote><p>iface eth0 inet static<br \/>\naddress xxx.xxx.xxx.xxx<br \/>\nnetmask yyy.yyy.yyy.yyy<br \/>\ngateway zzz.zzz.zzz.zzz<\/p><\/blockquote>\n<p>und wieder speichern:<\/p>\n<p style=\"text-align: justify\">Das zu Anfang gestartete Setup Script l\u00e4sst sich immer \u00fcber folgenden Befehl aufrufen:<\/p>\n<blockquote><p>sudo raspi-config<\/p><\/blockquote>\n<p style=\"text-align: justify\">Die Systemzeit des Raspi (f\u00fcr meine Anwendung ben\u00f6tige ich auch einen Zeitstempel) l\u00e4sst sich mit folgendem Befehl stellen:<\/p>\n<blockquote><p>sudo date &#8222;MMTThhmmJJ&#8220;<\/p><\/blockquote>\n<p style=\"text-align: justify\">Das war\u00b4s f\u00fcr den Anfang. Im zweiten Teil beschreibe ich dann die Sensorhardware und die Python-Scripts, die die Sensoren dann auslesen&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1026\" class=\"pvc_stats all  \" data-element-id=\"1026\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Der Raspberry Pi ist ja mittlerweile ein bekannter und beliebter Scheckkartenplatinen-Computer mit dem sich allerlei anstellen l\u00e4sst. Vom TV-Frontend mit Kodi, \u00fcber Spielekonsolenemulatoren mit Retropi bis hin zum B\u00fcrorechner, ist damit fast alles m\u00f6glich. In diesem Projekt m\u00f6chte ich vorstellen, wie mit Hilfe des Raspberry Pi Model2 physikalische Gr\u00f6\u00dfen wie Temperatur und Luftfeuchtigkeit gemessen und&hellip; <br \/> <a class=\"read-more\" href=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/2015\/11\/11\/raspberry-als-datenlogger-teil1-das-betiebssystem-einrichten\/\">Weiterlesen<\/a><\/p>\n","protected":false},"author":86,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[57,1186],"tags":[337,338,342,346,336,339,343,344,340,341,345],"class_list":["post-1026","post","type-post","status-publish","format-standard","hentry","category-elektronikbastler","category-raspberrypi","tag-feuchtesensor-hyt","tag-feuchtesensor-i2c","tag-feuchtesensoren-mit-pi","tag-hyt-sensoren-mit-python-auslesen","tag-hyt939","tag-i2c-bus-raspberry","tag-pi2","tag-python","tag-raspberry-datenlogger","tag-raspberry-pi","tag-raspberry-python"],"a3_pvc":{"activated":true,"total_views":245,"today_views":0},"_links":{"self":[{"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/posts\/1026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/users\/86"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/comments?post=1026"}],"version-history":[{"count":0,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/posts\/1026\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/media?parent=1026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/categories?post=1026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/tags?post=1026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}