NExtion and I2C
-
He i have Nextion screen. I need show on Nextion data from I2C sensors.. I have ESP8266 devkit. Here is my sketch but this sketch no showing temp and hum on the Nextion. I need alternative wire.h. ? Thanks.
#include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <SimpleTimer.h> #include <DHT.h> #include <Wire.h> #include <SI7021.h> float temp, hum; bool SI7021_present = true; #define I2C_SCL 12 // Barometric Pressure Sensor (BMP085) #define I2C_SDA 13 SI7021 sensor; #include <Nextion.h> #include <SoftwareSerial.h> #define DHTPIN 2 //D4 #define DHTTYPE DHT22 // DHT 22 Change this if you have a DHT11 DHT dht(DHTPIN, DHTTYPE); // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = ""; // Put your Auth Token here. (see Step 3 above) SoftwareSerial HMISerial(4,5,false,256);//RX-D1 , TX-D2 Nextion myNextion(HMISerial, 9600); SimpleTimer timer; void setup() { Wire.begin(); sensor.begin(SDA,SCL); Wire.begin(I2C_SDA, I2C_SCL); Serial.begin(9600); // See the connection status in Serial Monitor Blynk.begin(auth, "", ""); //insert here your SSID and password myNextion.init(); // Setup a function to be called every second timer.setInterval(10000L, sendUptime); } void sendUptime() { // You can send any value at any time. // Please don't send more that 10 values per second. //Read the Temp and Humidity from DHT float h = dht.readHumidity(); float t = dht.readTemperature(); Blynk.virtualWrite(12, t); // virtual pin Blynk.virtualWrite(13, h); // virtual pin float temperature = sensor.getCelsiusHundredths()/100; float humidity = sensor.getHumidityPercent(); Blynk.virtualWrite(5, temperature); Blynk.virtualWrite(6, humidity); // virtual pin myNextion.setComponentText("t1", String(temperature)); myNextion.setComponentText("t2", String(humidity)); myNextion.setComponentText("t3", String(t)); myNextion.setComponentText("t4", String(h)); delay(1000); String dim = "dim=50"; //pro podsvíceni myNextion.sendCommand(dim.c_str()); //pro podsvícení } void loop() { Blynk.run(); timer.run(); }