Start a new topic

send Data from Arduino to Nextion


I know that there are a lot of similar Posts but i have a Special question.

I want to set a Progress bar to 100 and another to 0 if the analog Input from a Joystick is bigger than 330. If the Input is less than 300 i want to set the Progress Switch the Progress barsm ( the frist to 0 and the second to 100). If the value is between 300 and 330 both Progress bars schould be set to 0.

I know that the Arduino is sending data, because of the TX LED but i dont know why the Nextion Display isnt recieving the data.

Here is the Code

 #include "Nextion.h"

NexProgressBar j0  = NexProgressBar(1, 7, "j0");

NexProgressBar j1  = NexProgressBar(1, 8, "j1");

int JoystickPin = A0;

int JoystickValue = 315;

void setup() {   




void loop() {   



delay(200); }

void readSensor() {   

JoystickValue = analogRead(JoystickPin); }

void sendJoystickToNextion() {   

if(JoystickValue < 300) {     



endNextionCommand();   }  

 if(JoystickValue > 330) {    



endNextionCommand();   }   

else {     



endNextionCommand();   }   


void endNextionCommand() {   





(784 Bytes)

There are a lot of similar posts - over 150 as a matter of course.

Examine the code in the Library

- endNextionCommand() 

  is already handled by the .setValue() function

Now your logic is only doing as you told it to do.

- when less than 300  0 and 100

- when above 330  100 and 0 otherwise override 0 and 0

So effectively when Joystick is above 330 j0 is 100 

at all other times j0 is 0 and j1 is never not 0

My bet is that this isn't what you meant

 - but it is exactly what you told it to do.

yes but the Progress bars do not Change if i move the Joystick and i dont know what i did wrong, they stay in their starting Position like the Background of my Display. 

Now i tried to use it with Pictures, with the Signal: vis p2,0

But nothing happens and i used example codes but nothing happens. 

Basics in Debugging

(if you get a 404 it is because you are not logged in)

(Register, email is sent to set password, Login to view)

One step at a time.

 - action on Joystick

 - prove MCU catches the value

 - prove MCU triggers your event code

Until you have proven the basics

  you are just running around in circles.


@Tom M

Be sure you fully understand what the analogRead() function does.

I.E it produces a 10bit precision integer, range 0-1023 on a voltage swing of 0-5V

Then once that is sorted, do you really only want to poll for changes 5 times per second, as the delay(200) in loop() specifies?

I would remove the delay and come up with some better logic to send to Nextion just once as the boundaries are crossed. 

Login or Signup to post a comment