Načítá teploty ze 2 čidel, posílá na thinkspeak a zobrazuje na OLED displeji
#include <Wire.h> #include <DHT.h> #include <ESP8266WiFi.h> #include <ACROBOTIC_SSD1306.h> // replace with your channel's thingspeak API key, String apiKey = "DTQ**********"; String apiKey2 = "HE5**********"; 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 oled.init(); // Initialze SSD1306 OLED display oled.clearDisplay(); // Clear screen 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); oled.setTextXY(1,0); // Set cursor position, start of line 1 oled.putString("Wi-Fi:"); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); oled.putString("."); } Serial.println(""); Serial.println("WiFi connected"); oled.setTextXY(4,0); // Set cursor position, start of line 4 oled.putString("PRIPOJENO"); } void loop() { oled.clearDisplay(); // Clear screen 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; } 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; } 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 }
Dobrý den,
při kompilaci mi to vypisuje chybu error: cannot access /dev/cu.wchusbserialfd130
Dobrý den,
jde o OSX? Dle popisu co jsem dohledal, tak může jít o cybu ovladače, nebo že není zvolený správní PORT v Tools > Port menu v Arduino IDE.
Tedy ani jiné kódy by vám tam neměli jít aktuálně uploadovat.
Je to tak, před tím než jsem nahrával tenhle projekt tak jsem na desce zkoušel OTA a ono to v ní zůstalo a ja jsem si to neuvědomil.
Už jsem to rozchodil, děkuji za hezký příklad. Nevíš náhodou jak otočit zobrazování na oled? (vzhuru nohama) děkuji
oled.rotate(); nebo něco takového to tuším bylo – ale používal jsem více knihoven a nejsem si teď úplně jistý. JEstli dohledáš, tak prosím napiš 😉
OK, podívam se na to.
Něco sem vygooglil – můžeš zkusit oled.setRotation(2); ?
Zkoušel jsem ale IDE vypisuje hlášku:
exit status 1
‚class ACROBOTIC_SSD1306‘ has no member named ‚setRotation‘
Zkoušel jsem i toto:
oled.setHorizontalMode();
ale oled se mi otočit zatím nepovedlo.
knihovnu jsem našel tady: https://github.com/acrobotic/Ai_Ardulib_SSD1306/blob/master/ACROBOTIC_SSD1306.cpp