#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <Nextion.h>
#include <SoftwareSerial.h>
#define DHTPIN 12 //D6
#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); // Nextion TX to pin D1 and RX to pin D2 of Arduino
Nextion myNextion;
SimpleTimer timer;
void setup()
{
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
myNextion.setComponentText("t1", String(h));
myNextion.setComponentText("t2", String(t));
delay(1000);
}
void loop()
{
Blynk.run();
timer.run();
}
You didnât initialize the screen properly nor the serial port.
You have to set the proper serial port in the Nextion declaration:
SoftwareSerial HMISerial(4,5); // Nextion TX to pin D1 and RX to pin D2 of Arduino
Nextion myNextion(HMISerial, 9600);
SimpleTimer timer;
void setup()
{
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);
}
The backlight, do you mean the brightness or the picture? I think you have to upload the picture to the firmware of the thing. I vaguely seem to remember it was possible to adjust brightness, but itâs too long ago since I played with it (I got too much nifty things to play with, LOL).
Yeah. The trick is to adapt code to your needs. If you try and figure it out on your own (with a little help from your friends) it will only teach you more
And how i can add to my sketch I2C? Can i connect Nextion to I2C? Or only change pinsâŚ
Thisk sketch no show data on Nextion?
//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#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
#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();
}
After a quick Google search on âi2c softserialâ I can already see that there are conflicts between the two. Run your own search and read up on their discussions, you might find your answers already explained.
Remember, this is a Blynk forum, do you have any additional Blynk related questions?