Knihovna:
https://github.com/ThingPulse/esp8266-oled-ssd1306/tree/e2286ba37b4454fd2e0e22697a522ac222ffadbc
Užití:
https://techtutorialsx.com/2019/03/09/esp32-arduino-ssd1306-changing-font-size/
Nutno jestě upravit – aktuálně zobrazuje pouze venkovní teplotu.
#include <Wire.h> #include <DHT.h> #include <ESP8266WiFi.h> //#include <ACROBOTIC_SSD1306.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define OLED_RESET LED_BUILTIN Adafruit_SSD1306 display(OLED_RESET); // replace with your channel's thingspeak API key, String apiKey = "yyyyyyy"; String apiKey2 = "xxxxxx"; const char* ssid = "Brno4"; const char* password = "*******"; const char* server = "api.thingspeak.com"; #define DHTPIN D3 // D1 pin on Nodemcu #define DHTPIN2 D4 // D2 pin on Nodemcu DHT dht(DHTPIN, DHT22); DHT dht2(DHTPIN2, DHT22); WiFiClient client; void setup() { Wire.begin(); // OLED wiring // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) // init done // Show image buffer on the display hardware. // Since the buffer is intialized with an Adafruit splashscreen // internally, this will display the splashscreen. display.display(); delay(200); // Clear the buffer. display.clearDisplay(); Serial.begin(115200); delay(10); dht.begin(); delay(10); dht2.begin(); WiFi.begin(ssid, password); Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); // text display tests display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.println("Wi-Fi:"); display.display(); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); //oled.putString("."); display.print("."); display.display(); } Serial.println(""); Serial.println("WiFi connected"); //oled.setTextXY(4,0); // Set cursor position, start of line 4 display.clearDisplay(); display.setCursor(0,0); //oled.putString("PRIPOJENO"); display.println("PRIPOJENO"); display.display(); } void loop() { //oled.clearDisplay(); // Clear screen display.clearDisplay(); float h = dht.readHumidity(); // read-1- humidity float t = dht.readTemperature(); // read-1- temperature in celsius if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); //return; } display.clearDisplay(); display.setTextSize(2); display.setCursor(0,0); display.print("IN: "); display.print(String(t)); //display.print(" C"); display.display(); //oled.setTextXY(1,0); // Set cursor position, start of line 1 //oled.putString("Venku: "); //oled.putString(String(t)); //oled.putString(" C"); //oled.setTextXY(2,0); // Set cursor position, start of line 1 //oled.putString(" "); //oled.putString(String(h)); //oled.putString(" %"); if (client.connect(server,80)) { // "184.106.153.149" or api.thingspeak.com String postStr = apiKey; postStr +="&field1="; postStr += String(t); // prevadi na int-zruseno postStr +="&field2="; postStr += String((int)h); // převadi na int-ponechano client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr); Serial.print("Temperature: "); Serial.print(t); Serial.print(" degrees Celcius Humidity: "); Serial.print(h); Serial.println("% send to Thingspeak"); } client.stop(); float h2 = dht2.readHumidity(); // read-2- humidity float t2 = dht2.readTemperature(); // read-2- temperature in celsius if (isnan(h2) || isnan(t2)) { Serial.println("Failed to read from DHT2 sensor!"); //return; } //display.clearDisplay(); display.setTextSize(2); display.setCursor(0,20); display.print("OUT: "); display.print(String(t)); //display.print(" C"); display.display(); //oled.setTextXY(4,0); // Set cursor position, start of line 1 //oled.putString("Doma: "); //oled.putString(String(t2)); //oled.putString(" C"); //oled.setTextXY(5,0); // Set cursor position, start of line 1 //oled.putString(" "); //oled.putString(String(h2)); //oled.putString(" %"); if (client.connect(server,80)) { // "184.106.153.149" or api.thingspeak.com String postStr2 = apiKey2; postStr2 +="&field1="; postStr2 += String(t2); // prevadi na int-zruseno postStr2 +="&field2="; postStr2 += String((int)h2); // převadi na int-ponechano client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+apiKey2+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr2.length()); client.print("\n\n"); client.print(postStr2); Serial.print("Temperature: "); Serial.print(t2); Serial.print(" degrees Celcius Humidity: "); Serial.print(h2); Serial.println("% send to Thingspeak"); } client.stop(); Serial.println("Waiting..."); // time between updates delay(120000); // 2 mins }
https://github.com/ThingPulse/esp8266-oled-ssd1306/tree/e2286ba37b4454fd2e0e22697a522ac222ffadbc
https://techtutorialsx.com/2019/03/09/esp32-arduino-ssd1306-changing-font-size/