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(); }
1 out of 1
Suggested Topics
-
Over the air updates
General Discussion • 23 Mar 2014, 21:38 • ToSa 1 Mar 2015, 11:21 -
Newbie questions
Hardware • 14 Feb 2025, 20:03 • magwas 14 Feb 2025, 20:03 -
"Remote Irrigation with LoRaWAN: LM27313 Challenges and PCB Design"
Hardware • 24 Jan 2024, 23:06 • wrendral 3 Feb 2024, 07:13 -
Does MySensors require Arduino Timer 2?
Hardware • 6 Jan 2024, 19:39 • OldSurferDude 11 Jan 2024, 04:39 -
Best time of year to buy higher quality small project solar panels?
Hardware • 10 Jun 2021, 19:19 • NeverDie 30 Aug 2024, 14:01 -
Sleep mode for bmp280
Hardware • 20 Feb 2018, 13:24 • fishermans 5 Feb 2024, 18:30