Start a new topic

Nextion, 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...But why? I need a another hardware? Or i must use other Nextion library?  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

// 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(I2C_SDA, I2C_SCL);
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth, "", ""); //insert here your SSID and password

  // 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));

  String dim = "dim=50";         //pro podsvíceni 
  myNextion.sendCommand(dim.c_str()); //pro podsvícení


void loop()


Which Nextion Lib?



???? I don't know any Nextion Library named "YES" ... ????

O sorry. Library name is : nextion.master.   #include <Nextion.h>

I need use I2C protocol  but wihout #include <Wire.h>

Sorry unable to help you as I am not familiar with this library

Perhaps you can get assistance from the authors of the lib or another user.

What is the Nextion specific question?

What is the Nextion specific question?  My question is how i can use NExtion screen with sensors on I2C pins.... THanks

I2C is not a Nextion issue - Nextion is TTL serial RX/TX

Please start at the Nextion HMI Solutions page.

 - accessible when you select Help under the Help Menu

 - clicking the Instructions Tab in the Nextion Editor

 - the link is:

Please review the Datasheet for your model, this will show how to connect the RX/TX

Please review the Nextion Editor Quick Start Guide.

Please review the Nextion Instruction Set.

Perhaps evaluate the IteadLib Arduino Nextion Library

Perhaps try some of the Arduino Nextion Examples

The Nextion is a simple serial device that accepts text commands

- all commands are data terminated with three bytes. 

  Hex 0xFF 0xFF 0xFF char ÿÿÿ  Dec 255 255 255.

- sending page0.t0="Hello World"ÿÿÿ   will set page0 component t0 to Hello World.

How you accomplish this in code is users domain

 - choice of programming language

 - choice of code compiler

 - choice of MCU

 - choice of any libraries or no libraries

The Nextion will evaluate commands upon receiving the data termination

Help with Nextion - Nextion users forum

 - how to enable sleep on Nextion

 - how to format commands

 - how to set slider component

Help with MCU - see your MCU documentation

Help with Code Compiler - see the compiler site

Help with Programming Language - Internet, books, courses.

Help with Electronics - that is users domain to know

ESP has forum for ESP related questions

So the Nextion related aspect of what you have presented is perhaps

 - how to set text component

I2C is not Nexiton, Blinky is not Nextion, ESP is not Nextion,

  Timer is not ours, if this is Arduino again not ours.

  Sensor for Temp Humidity is not part of the Nextion

Nextion is the serial display, so when I say Nextion related question

 - help in HMI design, or how to use Nextion Instructon Set.

Thanks  but i dont want connect Nextion to I2C... I need connect to I2C sensors.

But if i add to void setup : wire.begin  so Nextion no show data from sensors...

But on Arduino UNO is I2C with sensors and NExtion together good working...


This sounds like an issue in how MCU handles

 - check MCU if conflict between UART and I2C exists.

On many MCUs if a pin group is used in such and such manner,

pins may not be available for an alt function.

You will also have to examine your library source

    SoftwareSerial HMISerial(4,5,false,256);//RX-D1 , TX-D2

    Nextion myNextion(HMISerial, 9600);

This is not the Iteadlib format, beyond our scope to know other libs

Please check the OneWire page

Such as many issues that need considerations to be made

@Bos Video

Did you try to print the temperature and humidity values on the Serial Monitor?

I use Blynk and there is temp and hum normaly.. Now i useing pin : #define I2C_SCL 4 //d2

#define I2C_SDA 5 //d1
SoftwareSerial HMISerial(12,14,false,256);//RX-D1 5 , TX-D2 6
Nextion myNextion(HMISerial, 9600);

And now show data on NExtion but BH1750 sensor show bad valoue.....

And now show data on NExtion but BH1750 sensor show bad valoue.....

Does it show bad value only on Nextion, or also on Blynk?

Login or Signup to post a comment