<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zisterne &#8211; SmartHomeNG | smarthome knx homematic mqtt hue 1wire home automation</title>
	<atom:link href="https://www.smarthomeng.de/tag/zisterne/feed" rel="self" type="application/rss+xml" />
	<link>https://www.smarthomeng.de</link>
	<description>Die Device Integrations-Plattform für Dein Smart Home</description>
	<lastBuildDate>Sat, 19 May 2018 18:08:56 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.5</generator>

<image>
	<url>https://www.smarthomeng.de/wp-content/uploads/global/logo_small_152x152-150x150.png</url>
	<title>Zisterne &#8211; SmartHomeNG | smarthome knx homematic mqtt hue 1wire home automation</title>
	<link>https://www.smarthomeng.de</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Entfernungsmessung mit ESP32 und SmartHomeNG &#8211; Teil 2: Anbindung eines SSD1306 OLED Displays</title>
		<link>https://www.smarthomeng.de/entfernungsmessung-mit-esp32-und-smarthomeng-teil-2-anbindung-eines-ssd1306-oled-displays</link>
					<comments>https://www.smarthomeng.de/entfernungsmessung-mit-esp32-und-smarthomeng-teil-2-anbindung-eines-ssd1306-oled-displays#respond</comments>
		
		<dc:creator><![CDATA[Marc René Frieß]]></dc:creator>
		<pubDate>Sat, 19 May 2018 17:46:32 +0000</pubDate>
				<category><![CDATA[Beispiel-Implementierungen]]></category>
		<category><![CDATA[Tipps & Tricks]]></category>
		<category><![CDATA[ESP32]]></category>
		<category><![CDATA[OLED Display]]></category>
		<category><![CDATA[SSD1306]]></category>
		<category><![CDATA[Wasserstand]]></category>
		<category><![CDATA[Webservices]]></category>
		<category><![CDATA[Zisterne]]></category>
		<guid isPermaLink="false">https://www.smarthomeng.de/?p=1671</guid>

					<description><![CDATA[Als nächsten Schritt meines Projekts zur Überwachung des Wasserstands meiner Zisterne, habe ich ein SSD1306 OLED Display ergänzt, das in meiner Garage in der Nähe der Pumpe installiert werden soll. Hier möchte ich die Wasserhöhe und &#8211; eines Tages &#8211; den Wasserstand anzeigen. Als Vorarbeiten wird im Wesentlichen der Artikel<a class="moretag" href="https://www.smarthomeng.de/entfernungsmessung-mit-esp32-und-smarthomeng-teil-2-anbindung-eines-ssd1306-oled-displays"> Weiterlesen&#8230;</a>]]></description>
										<content:encoded><![CDATA[<p>Als nächsten Schritt meines Projekts zur Überwachung des Wasserstands meiner Zisterne, habe ich ein SSD1306 OLED Display ergänzt, das in meiner Garage in der Nähe der Pumpe installiert werden soll. Hier möchte ich die Wasserhöhe und &#8211; eines Tages &#8211; den Wasserstand anzeigen.</p>
<p>Als Vorarbeiten wird im Wesentlichen der Artikel &#8222;<a href="https://www.smarthomeng.de/entfernungsmessung-auf-basis-eines-esp32-und-smarthomeng" target="_blank" rel="noopener">Entfernungsmessung auf Basis eines ESP32 und SmartHomeNG</a>&#8220; vorausgesetzt.<a href="https://www.smarthomeng.de/entfernungsmessung-auf-basis-eines-esp32-und-smarthomeng"></a></p>
<p>Mittlerweile bin ich bei der Messung des Ultraschallsignales des HR-SR04 allerdings auf die Arduino Bibliothek <a href="https://playground.arduino.cc/Code/NewPing" target="_blank" rel="noopener">NewPing</a> umgestiegen, die die Messung übernimmt:<img fetchpriority="high" decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/05/newping_lib.jpg" alt="" width="726" height="96" class="alignnone size-full wp-image-1710" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/05/newping_lib.jpg 726w, https://www.smarthomeng.de/wp-content/uploads/2018/05/newping_lib-300x40.jpg 300w" sizes="(max-width: 726px) 100vw, 726px" />Als Display kommt ein kleines OLED Display mit SSD 1306 Controller zum Einsatz (<a href="https://www.az-delivery.de/products/0-96zolldisplay" target="_blank" rel="noopener">https://www.az-delivery.de/products/0-96zolldisplay</a>, ca. 7 Euro).</p>
<p>Das Display wird wie folgt zusätzlich zum HC-SR04 angeschlossen:</p>
<p><img decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/05/Untitled-Sketch-2_Steckplatine.png" alt="" width="529" height="460" class="alignnone wp-image-1673" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/05/Untitled-Sketch-2_Steckplatine.png 1098w, https://www.smarthomeng.de/wp-content/uploads/2018/05/Untitled-Sketch-2_Steckplatine-300x261.png 300w, https://www.smarthomeng.de/wp-content/uploads/2018/05/Untitled-Sketch-2_Steckplatine-768x667.png 768w, https://www.smarthomeng.de/wp-content/uploads/2018/05/Untitled-Sketch-2_Steckplatine-1024x890.png 1024w" sizes="(max-width: 529px) 100vw, 529px" /></p>
<p>Als Bibliothek kommt die &#8222;<a href="https://github.com/ThingPulse/esp8266-oled-ssd1306" target="_blank" rel="noopener">ESP8266 and ESP32 Oled Driver for SSD1306 display</a>&#8220; von Daniel Eichhorn und Fabrice Weinberg in Version 4.0.0 zum Einsatz:</p>
<p><img decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/05/display_lib.jpg" alt="" width="734" height="90" class="alignnone size-full wp-image-1685" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/05/display_lib.jpg 734w, https://www.smarthomeng.de/wp-content/uploads/2018/05/display_lib-300x37.jpg 300w" sizes="(max-width: 734px) 100vw, 734px" /></p>
<p>Der angepasst Sourcecode sieht nun wie folgt aus. Es ist dabei zu beachten, dass das Webservices- Plugin inzwischen über die REST Schnittstelle angesteuert wird. Weiterhin sind alle Log-Outputs für den Seriellen Monitor entfernt worden. Sämtliche relevanten Outputs werden jetzt auf dem Display ausgegeben.</p>
<pre><code class="language-c">
#include &lt;HTTPClient.h&gt;
#include &lt;NewPing.h&gt;
#include &lt;WiFi.h&gt;
#include &lt;WiFiClient.h&gt;
#include &lt;WiFiServer.h&gt;
#include &lt;WiFiUdp.h&gt;
#include &lt;Wire.h&gt;
#include "SSD1306.h"

const int triggerPin = 15;   // HC-SR04: Trigger Pin
const int echoPin = 4;       // HC-SR04: Echo Pin
const int sdaPin = 21;       // Display: SDA Pin
const int sclPin = 22;       // Display: SCL Pin
const int sensorRange = 280; // Reichweite (&lt; maximale Reichweite)

// HC-SR04
NewPing sonar(triggerPin, echoPin, sensorRange); // create NewPing instance

// Wifi
char ssid[] = "&lt;wlan_ssid&gt;";     // your network SSID (name)
char pass[] = "&lt;wlan_password&gt;"; // your network password
char host[] = "192.168.178.100"; // ip of service interface in SmartHomeNG
int port = 4321;                 // port of service interface in SmartHomeNG
char cm_item[] = "test.numeric";
int status = WL_IDLE_STATUS;
WiFiClient client;

// Display
SSD1306Wire display(0x3c, sdaPin, sclPin);

void setup() {
  Serial.begin(19200);
  // Init Display
  display.init();
  display.flipScreenVertically();
  // Init Wifi
  initialise_wifi();
}

void loop() {
  delay(50);
  unsigned int result = sonar.ping();
  float cm = sonar.convert_cm(result); //(result/2)/29.1; //

  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  if (cm &gt; 0) {
    if (client.connect(host, port)) {
      HTTPClient http;
      char portStr[12];
      sprintf(portStr, "%d", port);
      char url[128];
      sprintf(url, "http://%s:%s/rest/items/%s", host, portStr, cm_item);
      http.begin(url);
      http.addHeader("Content-Type", "application/json");
      char cmStr[12];
      char cmStrFull[24];
      sprintf(cmStr, "%f", cm);
      sprintf(cmStrFull, "%i cm", (int)cm);
      int httpCode = http.PUT(cmStr);
      String payload = http.getString();
      http.end();

      display.clear();
      display.setFont(ArialMT_Plain_16);
      display.drawString(0, 0, "Wasserstand:");
      display.setFont(ArialMT_Plain_24);
      display.drawString(0, 17, cmStrFull);
      display.display();
    }
  }
  // Wait 5 seconds and do next measurement
  delay(5000);
}

static void initialise_wifi(void) {
  display.setFont(ArialMT_Plain_10);
  display.drawString(0, 0, "Setting up wifi...");
  display.display();

  while (status != WL_CONNECTED) {
    display.drawString(0, 11, "Attempting to connect...");
    display.display();
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }
  display.drawString(0, 22, "Connected to wifi!");
  display.display();
  printWifiStatus();
}

void printWifiStatus() {
  IPAddress ip = WiFi.localIP();
  String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
  display.drawString(0, 33, "IP: "+ipStr);
  display.display();
  long rssi = WiFi.RSSI();
  char rssiStr[255];
  sprintf(rssiStr, "RSSI: %d dBm", rssi);
  display.drawString(0, 44, rssiStr);
  display.display();
}</code></pre>
<p>Nach der Initialisierung des Displays in der Methode <code>setup</code>, kann mittels <code>display.drawString(...)</code> Text auf das Display gesendet werden. Der erste Parameter ist dabei die X-, der zweite die Y-Koordinate. Im dritten Parameter wird der String gesetzt. Mit <code>display.display();</code> werden alle zuvor eingesteuerten Operationen dann wirklich auf dem Display ausgegeben. Ein <code>display.clear();</code> leert die auf dem Display ausgegebenen Werte, damit neuer Text dargestellt werden kann. Wird kein <code>display.display();</code> aufgerufen, so wird immer mehr auf das Display geschrieben. Dies kann soweit führen, dass Text über bestehenden Text geschrieben wird.</p>
<p>Dies kann am Beispiel der WLAN-Initialisierung gut gesehen werden. Das Gehäuse ist dabei wieder von Thingiverse bezogen und via 3D Drucker gedruckt worden (<a href="https://www.thingiverse.com/thing:2176764" target="_blank" rel="noopener">https://www.thingiverse.com/thing:2176764</a>):</p>
<p><img loading="lazy" decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/05/IMAG0778-1.jpg" alt="" width="546" height="418" class="alignnone wp-image-1699" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/05/IMAG0778-1.jpg 730w, https://www.smarthomeng.de/wp-content/uploads/2018/05/IMAG0778-1-300x230.jpg 300w" sizes="(max-width: 546px) 100vw, 546px" /><br />
Nach der Initialisierung wird nun auf dem Display der Abstand angezeigt:</p>
<p><img loading="lazy" decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/05/IMAG0776.jpg" alt="" width="516" height="556" class="alignnone wp-image-1690" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/05/IMAG0776.jpg 3024w, https://www.smarthomeng.de/wp-content/uploads/2018/05/IMAG0776-278x300.jpg 278w, https://www.smarthomeng.de/wp-content/uploads/2018/05/IMAG0776-768x827.jpg 768w, https://www.smarthomeng.de/wp-content/uploads/2018/05/IMAG0776-950x1024.jpg 950w" sizes="(max-width: 516px) 100vw, 516px" /></p>
<p>In Teil 3 folgt nun in Kürze noch ein Update zu meiner tatsächlichen Installation in der Zisterne und der Garage. Die Arbeiten sind bereits vollendet und die Werte werden via Kabel in die Garage auf den ESP32 übertragen. Mehr dazu aber in der nächsten Zeit&#8230;</p>
<p><em>(Die in diesem Artikel verwendeten Screenshots und Fotos wurden selber erstellt. Für den Schaltplan wurde das Tool<span> </span><a href="http://fritzing.org/home/" target="_blank" rel="noopener">Fritzing</a><span> </span>verwendet.)</em></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.smarthomeng.de/entfernungsmessung-mit-esp32-und-smarthomeng-teil-2-anbindung-eines-ssd1306-oled-displays/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
