------
mancas
------

LED Wanduhr

Hängt fertig an der Wand!

Marco hatte diese Uhr nach einer Idee von bastelgarage.ch Donnerstags zu unserem Linux Vereinstreffen mitgebracht.
https://www.youtube.com/watch?v=BMY3TZdeMGw

Das machte Lust dieses Projekt nachzubauen, da es ein schönes Beispiel ist für:

  • Code schreiben für den ESP8266
  • Ansteuerung einer 8x8-LED Anzeige
  • Text rollt über die Anzeige
  • Einwählen ins WLAN
  • Uhrzeit wird vom Zeitserver abgeholt
  • Wetter kommt von openweathermap.org
  • Variablen für den Programmcode werden aus einem Json-File aufbereitet

Gut zum Lernen und ausbaufähig zum kreativen Umsetzen mit eigenen Ergänzungen im Code.

LED-Uhr-Orig




Macht sich gut in einem schönen Gehäuse!

LED-Uhr-Zeit

LED-Uhr-Innen




So wird angepasst

Die Wetteranzeige hatte bei mir leider nicht funktionniert. Daher wurde das Script auf die Library ESP8266HTTP umgestellt.

// Modifiziertes Script von https://techtutorialsx.com/2016/07/17/esp8266-http-get-requests/
// replaces getWeatherData()

// added by mancas
// #include <ESP8266WiFi.h>
// #include <ESP8266HTTPClient.h>
 

void getMetarData ()  {
String line;
 
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
 
HTTPClient http;  //Declare an object of class HTTPClient
 
http.begin("http://api.openweathermap.org/data/2.5/weather?id=xxxx&units=metric&appid=xxxxxx&lang=de");  //Specify request destination

int httpCode = http.GET();                                                                  //Send the request
Serial.print(" - httpCode is ");
Serial.println(httpCode);
 
if (httpCode > 0) { //Check the returning code
 
String payload = http.getString();   //Get the request response payload

Serial.print(" - Response from Server ");
Serial.println(payload);                     //Print the response payload


line += payload; // to let the rest of the script untouched
Serial.println(line);
 

http.end();   //Close connection
}

// Allocate JsonBuffer  // Leh
  // Use arduinojson.org/assistant to compute the capacity.
  const size_t capacity = JSON_ARRAY_SIZE(2) + JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + JSON_OBJECT_SIZE(12) + 420;
  DynamicJsonBuffer jsonBuf(capacity);
  
//  DynamicJsonBuffer jsonBuf;
  JsonObject &root = jsonBuf.parseObject(line);
  if (!root.success())
  {
    Serial.println("parseObject() failed");
    return;
  }
  //weatherMain = root["weather"]["main"].as<String>();
  weatherDescription = root["weather"]["description"].as<String>();
  weatherDescription.toLowerCase();
  //  weatherLocation = root["name"].as<String>();
  //  country = root["sys"]["country"].as<String>();
  temp = root["main"]["temp"];
  humidity = root["main"]["humidity"];
  pressure = root["main"]["pressure"];
  tempMin = root["main"]["temp_min"];
  tempMax = root["main"]["temp_max"];
  windSpeed = root["wind"]["speed"];
  windDeg = root["wind"]["deg"];
  clouds = root["clouds"]["all"];
  
 getTimeLocal();

  String windDirection = "N NOO SOS SWW NW";  // Windrichtungen N NO O SO S SW W NW immer 2 char lang
  int wr = (windDeg+22)%360/45;
//  Serial.println(wr);

  String dayName[] = {"Err", "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"};

// For test purposes
// String(d) = "25";
// String(m) = "5";
// w = 2; // was monday in year 2020
  
  String deg = String(char('~' + 25));
  String arrowUp = String(char('~' + 23));
  
  if (String(d) == "25" and String(mo) == "5") {
    weatherString = "       " + dayName[w]  + "  " + String(d) + "." + String(mo) + ".  Towel Day!      ";
  } else {
    weatherString = "       " + dayName[w]  + "  " + String(d) + "." + String(mo) + "." + String(ye) + "     ";
  }
  weatherString +=   String(temp, 1) + deg + "C ";
  weatherString += "  Luftf.: " + String(humidity) + "%  ";  // Luftfeuchtigkeit
  weatherString += "  Luftd: " + String(pressure) + "hPa  "; // Luftdruck
  weatherString += "  Regenrisiko: " + String(clouds) + "%  "; // Regenrisiko
//  weatherString += "  Wind: " + String(windSpeed, 1) + "m/s                "; // Windgeschwindigkeit
  weatherString += "  Wind: " + String(windSpeed, 1) + "m/s  "; // Windgeschwindigkeit
  weatherString += String(windDeg) + deg + "  ";
  weatherString +=  arrowUp + "  " + windDirection.substring(2*wr,2*wr+2) + "    "; // Windgeschwindigkeit und Richtung
  Serial.println(weatherString);  //Leh
}

} 

LED-Uhr-Wetter-mp4




Towel Day

Die Uhr kann natürlich auch an Geburtstage und andere wichtige Termine erinnern. Eine einfache Abfrage im Script machts möglich. Das Beispiel für den Nerd: Towel Day am 25.05. ist in obigem Script eingebaut.




Live Anzeige vom Textserver

Andere Variante für Live-Anzeige: In meinem Laptop habe ich einen Webserver aufgesetzt. Dieser wird abgefragt und der dort gepostete Satz angezeigt.

void getLocalWebData ()  {

String Line;

if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
 
HTTPClient http;  //Declare an object of class HTTPClient
 
http.begin("http://192.168.63.6");  //Specify request destination

int httpCode = http.GET();                                                                  //Send the request
Serial.print(" - httpCode is ");
Serial.println(httpCode);
 
if (httpCode > 0) { //Check the returning code
 
Line = http.getString();   //Get the request response payload

Serial.print(" - Response from localWebServer ");
Serial.println(Line);                     //Print the response payload

WebLine = "  " + Line + "   ";

http.end();   //Close connection

}
}
   
getTimeLocal();
  
Serial.println(WebLine);  //Leh
}



Zum Abschluß eine Wortuhr

Schließlich wurde die Uhr auf reine Textanzeige umgestellt. Die Anzeige ist für Slowdown-Nerds: “Es ist so viertel nach Zehn” ist ein Beispiel dazu.

//Sprachausgabe der Uhrzeit

int Stunde;
String MinutenText;
String StundenText;

void WordClock () {

  getTimeLocal();
  Serial.println("Wordclock ");
 if (h > 12) {Stunde = h-12;} else {Stunde = h;} 
  
//  Serial.print(Stunde); Serial.print(" : "); Serial.println(m);

 if (m == 0) {MinutenText = "genau ";}
 if (m > 0)  {MinutenText = "kurz nach ";}
 if (m > 2)  {MinutenText = "funf nach ";}
 if (m > 7)  {MinutenText = "zehn nach ";}
 if (m > 12) {MinutenText = "viertel nach  ";}
 if (m > 17) {MinutenText = "zwanzig nach ";}
 if (m > 22) {MinutenText = "funf vor halb "; Stunde = Stunde + 1;}
 if (m > 27) {MinutenText = "halb ";}
 if (m > 32) {MinutenText = "funf nach halb ";}
 if (m > 37) {MinutenText = "zwanzig vor ";}
 if (m > 42) {MinutenText = "viertel vor ";}
 if (m > 47) {MinutenText = "zehn vor ";}
 if (m > 52) {MinutenText = "funf vor ";}
 if (m > 57) {MinutenText = "gleich ";}

 if (Stunde == 1) {StundenText = "eins";}
 if (Stunde == 2) {StundenText = "zwei";}
 if (Stunde == 3) {StundenText = "drei";}
 if (Stunde == 4) {StundenText = "vier";}
 if (Stunde == 5) {StundenText = "funf";}
 if (Stunde == 6) {StundenText = "sechs";}
 if (Stunde == 7) {StundenText = "sieben";}
 if (Stunde == 8) {StundenText = "acht";}
 if (Stunde == 9) {StundenText = "neun";}
 if (Stunde == 10) {StundenText = "zehn";}
 if (Stunde == 11) {StundenText = "elf";}
 if (Stunde == 12) {StundenText = "zwolf";}

 
// Serial.print(MinutenText);
// Serial.println(StundenText);

TimeString = "                    Es ist so " + MinutenText + StundenText + "                                      ";
Serial.println(TimeString); 

}



Viel Spaß beim Mitmachen wünscht mancas!