ESP 12E devkit with Nextion Screen 3.5

So i was try:


#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();
}

[1760] Connected to WiFi
[1760] IP: 192.168.1.31
[1760] 

5001] Connecting to blynk-cloud.com:8442
[5038] Ready (ping: 1ms).

Exception (28):
epc1=0x402044f4 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont 
sp: 3ffefd00 end: 3ffeff20 offset: 01a0

>>>stack>>>
3ffefea0:  00000000 3ffe8df0 3ffeec94 402050dc  
3ffefeb0:  00000000 3ffe8df0 3ffeec94 402045d5  
3ffefec0:  00000000 00000000 00000000 00000000  
3ffefed0:  00000000 00000000 3fff1004 0000000f  
3ffefee0:  00000006 feefeffe 3ffeece4 3ffeeeec  
3ffefef0:  00000000 00000724 3ffeece4 40203272  
3ffeff00:  3fffdad0 00000000 3ffeeee4 402049a0  
3ffeff10:  feefeffe feefeffe 3ffeef00 40100718  
<<<stack<<<

But temp and hum are no show on the Nextion screen… In app blynk yes…
can i try D1 to RX and D2 to TX?
THansk.

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);
}
1 Like

So i add: Nextion myNextion(HMISerial, 9600); but still no show temp and hum on NExtion…

5001] Connecting to blynk-cloud.com:8442
[5022] <[02|00|01|00] c7e6d0b5b68a476a9711ca56b76372ab
[5042] >[00|00|01|00]Č
[5042] Ready (ping: 4ms).
[5042] <[11|00|01|00]Hver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Feb  8 2017 14:03:59[00]
[5325] >[00|00|01|00]Č
[5660] >[14]F•[00|04]
[5660] >vr[00]3
[6595] >[14|19]G[00|05]
[6596] >vr[00]12
[7664] >[14]GĂŽ[00|04]
[7664] >vr[00]3
[8591] >[14].Ś[00|05]
[8592] >vr[00]12
[8663] >[14];É[00|04]
[8663] >vr[00]3
[10607] >[14];Ś[00|05]
[10607] >vr[00]12
[10658] >[14|12]\[00|04]
[10658] >vr[00]3
[12593] >[14]6ď[00|05]
[12593] >vr[00]12
[12662] >[14]Wá[00|04]
[12662] >vr[00]3
[14596] >[14]zE[00|05]
[14596] >vr[00]12
[14656] >[14]UŁ[00|04]
[14656] >vr[00]3
[15174] <[06|00|02|00|00]
[15192] >[00|00|02|00]Č
[15600] <[14|00|03|00|0D]vw[00]12[00]18.0000
[15660] <[14|00|04|00|0C]vw[00]13[00]59.800
[16750] >[14|13]ďż˝[00|04]
[16750] >vr[00]3
[16750] >[14|15]`[00|05]
[16750] >vr[00]12
[16754] >[14|0A]Ş[00|04]
[16754] >vr[00]3
[17629] >[14]m'[00|05]
[17629] >vr[00]12
[18593] >[14|03|0E|00|05]
[18594] >vr[00]12
[18659] >[14|00]Ü[00|04]
[18660] >vr[00]3
[19622] >[14]@Í[00|05]
[19622] >vr[00]12
[19694] >[14]0Đ[00|04]
[19694] >vr[00]3
[21604] >[14]\Ĺž[00|05]
[21604] >vr[00]12
[21668] >[14|1D]e[00|04]
[21668] >vr[00]3
[23595] >[14]s­[00|05]
[23596] >vr[00]12
[23661] >[14]p„[00|04]
[23661] >vr[00]3
[24682] >[14]1_[00|04]
[24682] >vr[00]3
[25599] <[14|00|05|00|0D]vw[00]12[00]18.0000
[25617] <[14|00|06|00|0C]vw[00]13[00]59.700
[26708] >[14]W˛[00|05]
[26708] >vr[00]12
[26708] >[14],Ý[00|05]
[26708] >vr[00]12
[26708] >[14]eç[00|04]
[26708] >vr[00]3
[27591] >[14]SÄ[00|05]
[27591] >vr[00]12
[28659] >[14]`[1C|00|04]
[28659] >vr[00]3
[29587] >[14]8Ş[00|05]
[29587] >vr[00]12
[30590] >[14]#Ŕ[00|05]
[30590] >vr[00]12
[30660] >[14];[05|00|04]
[30660] >vr[00]3
[31660] >[14]PŢ[00|04]

But did it crash? If not, you probably can switch the Tx/Rx pins on the Nextion and try again, I’m not 100% sure what the right order is.

1 Like

SO yes. Now is it working:-D THanks.

And knwo you how i can change backlit(light) on the Nextion ?

Congratz :slight_smile:

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).

Yes i mean brightness. :slight_smile:

There’s an example :slight_smile:

1 Like

So thanks now i know. I use : String dim = "dim=10"; myNextion.sendCommand(dim.c_str());

dim=0-100

Used he A0 and potentiometer for intensity brightness?

int brightness = analogRead(A0);
  int bright = map(brightness, 0, 1024, 0, 100);
  String dim = "dim=" + String(bright);
  myNextion.sendCommand(dim.c_str());

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 :slight_smile:

1 Like

Yes. I now only find how work in Nextion Editor Corp :


And what code i can use for corp in my sketch… Thanks.:slight_smile:

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? :frowning:

//#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();
}

THanks

[1839] Free RAM: 44576
[5001] Connecting to blynk-cloud.com:8442
[5904] <[02|00|01|00] c7e6d0b5b68a476a9711ca56b76372ab
[5936] >[00|00|01|00]Č
[5936] Ready (ping: 2ms).
[5936] <[11|00|01|00]Hver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Feb  9 2017 14:43:56[00]
[6188] >[00|00|01|00]Č
[16036] <[06|00|02|00|00]
[16059] >[00|00|02|00]Č
[16462] <[14|00|03|00|0C]vw[00]12[00]20.200
[16641] <[14|00|04|00|0C]vw[00]13[00]55.200

Or
#include <SimpleTimer.h>
and
#include <Wire.h>
cant be together in sketch?

They can.

Ok thanks. but why if a add I2C to sketch so Nextion no show temp…

Probably not

Look at the datasheet for your model for more info.

Yes Nextion no working on I2C. https://itead.freshdesk.com/support/discussions/topics/11000007519

But if i have on I2C a sensors and Nextion on other pins… It is possible?and how…
THanks.

I do not understand your question.

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?

Sorry no. I will find on google how i can use I2C protocol with sensors and nextion together on devkit ESP…