Nextion LCD communicate with Arduino UNO

Nextion LCD communicate with Arduino UNO © GPL3+

You can communicate your Nextion LCD with your Arduino UNO by Software serial ... a liitle tricky but not much :)

  • 33,616 views
  • 9 comments
  • 18 respects

Components and supplies

Apps and online services

About this project

Ok, my Nextion LCD can communicate with Arduino MEGA by Serial 2 ports. Nextion library and its examples allowed this. When I upload one of nextion example (like Compslider etc..) and connect it to my Mega by serial 2 ports it works.. but MEGA is so "MEGA", what about using my nextion LCD with UNO, Pro mini or Nano... when I tried same example with UNO Arduino IDE always gives error to me about serial connection.. sometihng wrong... something "deep inside" must be wrong.. :)

But firstly you can check this project to use Nextion LCD without SD card..

https://www.hackster.io/tsavascii/programming-nextion-lcd-without-sd-card-6b18d7

Thanks to @Spirko with this explanation..

  • Firstly, open your Nextion library folder and find "Nexconfig.h" file.

and right click it and open with Notepad..

Find this line;

 #define nexSerial Serial2

and change it with this lines,

#include <SoftwareSerial.h>
extern SoftwareSerial HMISerial;
#define nexSerial HMISerial

save it and close. Sure, you can keep old file with different name to use it with Mega in future.

Then open your Arduino nextion example..choose one of them..

and add this line to your code..

SoftwareSerial HMISerial(10, 11);  

and its ready to compile and upload to arduino uno..

Use this connections:

Nextion - Arduino UNO

TX - 11

RX - 10

Now your Arduino UNO will communicate with Nextion LCD...

You can find my example nextion firmware and arduino code in this project..

Code

Arduino partArduino
Arduino part of the code
#include "Nextion.h"
SoftwareSerial HMISerial(10, 11);

NexText t0 = NexText(0, 2, "t0");
NexSlider h0 = NexSlider(0, 1, "h0");
NexGauge z0  = NexGauge(0, 3, "z0");
NexDSButton bt0 = NexDSButton(0, 5, "bt0");


NexTouch *nex_listen_list[] = {&h0, &bt0, NULL};

void bt0PopCallback(void *ptr)
{
  uint32_t dual_state;
  NexDSButton *btn = (NexDSButton *)ptr;
  dbSerialPrintln("b0PopCallback");
  dbSerialPrint("ptr=");
  dbSerialPrintln((uint32_t)ptr);
  bt0.getValue(&dual_state);
  
  if (dual_state)               
  {
    digitalWrite(13, HIGH);           // if my dual state buton is pressed
  }
  else
  {
    digitalWrite(13, LOW);            // if not
  }

}
void h0PopCallback(void *ptr)
{
  int numberx = 0;
  int gosterge = 0;
  uint32_t number = 0;
  char temp[10] = {0};
  dbSerialPrintln("h0PopCallback");
  h0.getValue(&number);
  utoa(number, temp, 10);
  t0.setText(temp);
  numberx = number;
  gosterge = map(numberx, 0, 100, 0, 180);
  z0.setValue(gosterge);
}

void setup(void)
{
  pinMode(13, OUTPUT);
  nexInit();
  h0.attachPop(h0PopCallback);
  bt0.attachPop(bt0PopCallback, &bt0);
  dbSerialPrintln("setup done");
}

void loop(void)
{
  nexLoop(nex_listen_list);
}

Schematics

nextion
nextion part
slider_lDwLWfEBlP.HMI

Comments

Similar projects you might like

Simple LCD Timer With Arduino UNO

Project showcase by Hugo Blanc

  • 7,705 views
  • 7 comments
  • 24 respects

Displaying Sensor Values on LCD

by Wimpie van den Berg

  • 42,769 views
  • 4 comments
  • 36 respects

LCD (Liquid Crystal Display)

by MicroBob

  • 30,778 views
  • 40 comments
  • 101 respects
Add projectSign up / Login