0

StatusDisplay ESP8266 ePaper ioBroker

Allgemein

So nach dem ich in einer Geschäftsauflösung einige elektronische Preisschilder bekomme habe diese aber wegen einer verschlüsselung nur für das ausschlachten geeignet sind, hatte ich einige 2,13 und 4,9 inch e-Paper Displays.

Als Controller habe ich mir bei exp-Tech diese hier bestellt

nach diesen angaben einfach anschliesen

  • BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V

Einige Bibliotheken benötigt man noch

  1. GxEPD
  2. ESP8266WiFi
  3. PubSubClient

Meine Script habe ich mir aus diesen zwei zusammen bebastelt,

https://github.com/ZinggJM/GxEPD

www.smarthome-tricks.de  übrigens eine mega geniale Seite zum Thema ioBroker und Homeautomatisierung

[codesyntax lang=“php“]

#include <GxEPD.h>
#include <GxGDEW042T2/GxGDEW042T2.cpp>      // 4.2" b/w
#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>
#include <SPI.h>
#include <Wire.h>
#include <PubSubClient.h>
#include <ESP8266WiFi.h>



// Update these with values suitable for your network.
const char* ssid = "SSID";
const char* password = "PASSWORD";
const char* mqtt_server = "IP-des ioBroker";
 
String _DisplayLine1 = "";
String _DisplayLine2 = "";
String _DisplayLine3 = "";
String _DisplayLine4 = "";
String _DisplayLine5 = "";
String _DisplayLine6 = "";
String _DisplayLine7 = "";
String _DisplayLine8 = "";
String _DisplayLine9 = "";


 

 
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;


GxIO_Class io(SPI, /*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2); // arbitrary selection of D3(=0), D4(=2), selected for default of GxEPD_Class
GxEPD_Class display(io /*RST=D4*/ /*BUSY=D2*/); // default selection of D4(=2), D2(=4)


//Schriftarten includieren, https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fonts
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeMono12pt7b.h>
#include <Fonts/FreeSerif9pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeSerifBold9pt7b.h>

void setup_wifi() {
 
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  Serial.print(".");
  }
 
randomSeed(micros());
 
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}



 
void callback
    (char* topic, byte* payload, unsigned int length) {
    Serial.print("Message arrived [");
    Serial.print(topic);
    Serial.print("] ");
 
if ( strcmp( topic, "display_line1" ) == 0 )
  {
  _DisplayLine1 = "";
  for (int i = 0; i < length; i++) { _DisplayLine1 += (char)payload[i]; }
  }
  
if ( strcmp( topic, "display_line2" ) == 0 )
  {
  _DisplayLine2 = "";
  for (int i = 0; i < length; i++) { _DisplayLine2 += (char)payload[i]; }
  }
 
if ( strcmp( topic, "display_line3" ) == 0 )
  {
  _DisplayLine3 = "";
  for (int i = 0; i < length; i++) { _DisplayLine3 += (char)payload[i]; }
  }
 
if ( strcmp( topic, "display_line4" ) == 0 )
  {
  _DisplayLine4 = "";
  for (int i = 0; i < length; i++) { _DisplayLine4 += (char)payload[i]; }
  }

if ( strcmp( topic, "display_line5" ) == 0 )
  {
  _DisplayLine5 = "";
  for (int i = 0; i < length; i++) { _DisplayLine5 += (char)payload[i]; }
  }

if ( strcmp( topic, "display_line6" ) == 0 )
  {
  _DisplayLine6 = "";
  for (int i = 0; i < length; i++) { _DisplayLine6 += (char)payload[i]; }
  }

if ( strcmp( topic, "display_line7" ) == 0 )
  {
  _DisplayLine7 = "";
  for (int i = 0; i < length; i++) { _DisplayLine7 += (char)payload[i]; }
  }

if ( strcmp( topic, "display_line8" ) == 0 )
  {
  _DisplayLine8 = "";
  for (int i = 0; i < length; i++) { _DisplayLine8 += (char)payload[i]; }
  }

if ( strcmp( topic, "display_line9" ) == 0 )
  {
  _DisplayLine9 = "";
  for (int i = 0; i < length; i++) { _DisplayLine9 += (char)payload[i]; }
  }
}

 
void reconnect() { // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
  String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
  if (client.connect(clientId.c_str())) {
  Serial.println("connected");
 
  client.subscribe("display_line1");
  client.subscribe("display_line2");
  client.subscribe("display_line3");
  client.subscribe("display_line4");
  client.subscribe("display_line5");
  client.subscribe("display_line6");
  client.subscribe("display_line7");
  client.subscribe("display_line8");
  client.subscribe("display_line9");


  
  } else {
  Serial.print("failed, rc=");
  Serial.print(client.state());
  Serial.println(" try again in 5 seconds");
  // Wait 5 seconds before retrying
  delay(5000);
}
}
}


void setup()
{
  
  Serial.begin(115200);
  Serial.println();
  Serial.println("GxEPD_WiFi_Example");

  setup_wifi();
  client.setServer(mqtt_server, 1883);  //MQTT Port
  client.setCallback(callback);
 


  display.init(115200);
  display.init();                   // e-Ink Display initialisieren
  display.fillScreen(GxEPD_WHITE);  // Display Weiss füllen
  display.setRotation(0);           // Display um 90° drehen
  
  }


void loop()

  {
    display.fillScreen(GxEPD_WHITE);
    delay(500);
    display.fillScreen(GxEPD_WHITE);
    display.setTextColor(GxEPD_BLACK);     // Schriftfarbe Schwarz
    

    // Rechteck mit weissem Hintergrund erstellen
    //X-Position, Y-Position, Breite, Höhe, Farbe
    //display.fillRect(0, 0, 200, 128, GxEPD_WHITE); //Xpos,Ypos,box-w,box-h

    // Überschrift
    display.setFont(&FreeMonoBold18pt7b);  // Schrift definieren
    display.setCursor(35, 25);
    display.print("ioBroker Display");
    // URL
    display.setFont(&FreeMonoBold12pt7b);  // Schrift definieren
    display.setCursor(80, 50);
    //display.print("www.ossilampe.de");
    // Zeile 1
    display.setFont(&FreeSerif9pt7b);  // Schrift definieren
    display.setCursor(15, 90);
    display.print("-");
    display.setCursor(30, 90);
    display.print(_DisplayLine1.c_str());
    // Zeile 2
    display.setCursor(15, 110);
    display.print("-");    
    display.setCursor(30, 110);
    display.print(_DisplayLine2.c_str());
    // Zeile 3
    display.setCursor(15, 130);
    display.print("-");    
    display.setCursor(30, 130);
    display.print(_DisplayLine3.c_str());
    // Zeile 4
    display.setCursor(15, 150);
    display.print("-");    
    display.setCursor(30, 150);
    display.print(_DisplayLine4.c_str());    
    // Zeile 5
    display.setCursor(15, 170);
    display.print("-");    
    display.setCursor(30, 170);
    display.print(_DisplayLine5.c_str());    
    // Zeile 6
    display.setCursor(15, 190);
    display.print("-");    
    display.setCursor(30, 190);
    display.print(_DisplayLine6.c_str());    
    // Zeile 7
    display.setCursor(15, 210);
    display.print("-");    
    display.setCursor(30, 210);
    display.print(_DisplayLine7.c_str());    
    // Zeile 8
    display.setCursor(15, 230);
    display.print("-");    
    display.setCursor(30, 230);
    display.print(_DisplayLine8.c_str());


    // Fusszeile
    display.setFont(&FreeSerifBold9pt7b);  // Schrift definieren
    display.setCursor(5, 290);
    display.print(_DisplayLine9.c_str());

    // Teil refresh vom  Display
    display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false);
    if (!client.connected()) {
    reconnect();
    }
    
    client.loop();
    ;
    //delay(600000);
     }

[/codesyntax]

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.