Start a new topic

Simple Arduino x Nextion Interface example (first atempt)

 Hi folks, i just received my 3.5" display, and i'm trying to understand how it works and how to communicate with arduino... I think i'm going in the right direction..

I made a simple graphic interface using 5 pages, 2 using only nextion editor to make things, and 3 to use with arduino, those are:
1. Timers: Has a button to enable/disable the timer, a plus and minus to set the timing, and a visual indicator of the timer, does nothing. just to learn about the timers.

2. Dim: Just to test the dims command, plus and minus button and a save button.

3. Analog: Read 4 analogs inputs of Arduino and displays in the Nextion.

4. Has 4 DSButtons for manipulating 4 outputs and 4 indicators for another 4 inputs.

5. Has 2 PWM enable DSbutton and plus and minus button for duty cycle.

Yes, very simple and unecessary, but maybe it can help other noobies like me to work with those things.

i would apreciate if you can point me bugs or things that can be optimized, cause i'm not that good with that. Neither with english.

Thanks !

(10.8 KB)
(615 KB)

Code debugging is not standard offering

 - can be through purchasing Enhanced Support

Perhaps start with a specific question.

- most questions possible to ask have been answered in forum

Sorry Mr. Patrick, i thought the 'free chat' works like a open community to share projects and improve skills, i didn't mean to break any rule of this forum. Just want to share my personal experiences with other noobs like me so they can have some more examples to learn from. Thanks anyway!


Sharing is indeed welcome

 - code dumping for debug is not

So, if you are to form it into

 - a Nextion Question you would like answered

 - a specific aspect of Nextion you wish to discuss

Then this can be expanded on by the community.

point me bugs or things that can be optimized

 - this is indeed dumping code looking for others to debug

 - such debugging belongs to Enhanced Support

1 person likes this
Ok, got it!

I will also point out

Nextion is a TTL Serial HMI device

  - it can be used with over 65000 different MCU types

Nextion has a text based command set

  - it can be used with 130+ programming languages

Arduino represents one programming language C++

 - and in this, just 1 variant of C++, Arduino C++

Arduino also represents many MCU types now

 - once Arduino was basically just AVR type MCUs

 - now Arduino offers ARM and other MCUs

and the Arduino IDE can be used for other non Arduino MCUs

 - such as STM and ESP type MCUs.

Then there are various Nextion Libraries

 - Itead created the Iteadlib Arduino Nextion Library

   - it supports the Arduino Mega2560 and UNO

 - Itead also created Segnix for Raspberry PI to handle Arduino files

   - so the Segnix Arduino Nextion Library

     supports Raspberry PI v2

These libraries can be used as example code and ported

   to many other MCU types in many other languages

So when posting about an Arduino MCU side

 - it is best to mention which MCU is used with this code

 - it is best to mention which library is used for the code

For Arduino C++

The loop() function is designed to be repeated over and over.

On an 8 MHz MCU, this can occur around 150,000+ times per second.

Each function called takes time

 - time that can be measured with millis() and micros()

It is not just possible for the user to know how long a function takes

 - but in purposeful programming, the user should know how long.

I am almost certain that in purposeful programming there is no function

that needs be called every 5us to 10us as fast as loop() can call them

Therefore inside a loop() function

 - calls to other functions should be made when needed and

   not called in every single iteration of loop()

 - conditionally execution versus unbridled execution

 - unbridled will indeed lead to issues, it isn't purposefully programmed

 - millis() and micros() will help

When you ponder the "sendme" command sent every loop() iteration

 - was this meant to be sent 150,000 per second?

Putting the "sendme" command in page preinitialization Nextion side

   will send out Nextion Return Data 0x66 when the page changes

Learn to catch this in NexHardware.cpp nexLoop() function.

On the new Forum at

  Basic Framework Sketch for Arduino

  Debugging-Basics in Debugging

  Basic Understandings for Designing a Nextion HMI

Ensure to register (receive email to set password), and login

 - if you are getting a 404 error, you missed a step


  delay(10) means 

  - Halt all execution on MCU for 10ms and do absolutely nothing.

  - absolutely nothing also means no serial incoming

  - no interrupts, no code execution, nothing. zip zero zilch.

  at 115200 baud, in 10ms 115.2 bytes of data can be lost

Login or Signup to post a comment