Nextion outputting value using Arduino uno

Arduino is printing the correct values of the analog on the serial monitor however we can not get the Nextion to print those values in the n# text box

#include <doxygen.h>
#include <NexButton.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexGauge.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexSlider.h>
#include <NexText.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexWaveform.h>
#include <NexNumber.h>


#include <EasyNextionLibrary.h>
#include <trigger.h>


#include "Nextion.h"
/*#include "SoftSerial.h" */
#define nexSerial Serial


int SensorValue1 = 0;
int SensorValue2 = 0;
int SensorPin1= A1;
int SensorPin2= A5;

int variable1 = 0;  // This is a simple variable to keep increasing a number to have something dynamic to show on the display.


// Declare your Nextion objects - Example (page id = 0, component id = 1, component name = "b0") 
NexText Title1 = NexText(0, 1, "t0"); 
NexButton Photodiode = NexButton(0, 2, "b0");
NexButton ThermalCam = NexButton(0, 3, "b1");
NexButton Wifi = NexButton(0, 4, "b2");
NexButton Laser = NexButton(0, 5, "b3");

NexText Title2 = NexText(2, 4, "t0"); 
NexText Title3 = NexText(2, 8, "t1"); 
NexText Title4 = NexText(2, 9, "t2"); 
NexNumber n0 = NexNumber(2, 6, "n0");
NexNumber n1 = NexNumber(2, 7, "n1");
NexNumber n2 = NexNumber(2, 3, "n2");
NexButton b0 = NexButton(2, 2, "b0");
NexButton b1 = NexButton(2, 5, "b1");


NexButton back2 = NexButton(1, 1, "b0");
NexNumber n3 = NexNumber(1, 2, "n3");
NexText Title5 = NexText(1, 4, "t0"); 

//NexButton back3 = NexButton(3, 1, "b0");
//NexButton OnOff = NexButton(3, 2, "b1");
//
//NexButton back4 = NexButton(4, 1, "b0");

NexPage page0 = NexPage(0, 0, "page0");
NexPage page1 = NexPage(1, 0, "page1");
NexPage page2 = NexPage(2, 0, "page2");
//NexPage page3 = NexPage(3, 0, "page3");
//NexPage page4 = NexPage(4, 0, "page4");
//

// Register a button object to the touch event list.  
NexTouch *nex_listen_list[] = {
  &Photodiode,
  &ThermalCam,
  &Wifi,
  &Laser,
  //&back1,
  &back2,
 // &back3,
 // &back4,
  &b1,
  &b0,
  NULL
};
  
  // End of setup


void setup() {  // Put your setup code here, to run once:
  
  Serial.begin(115200);  // Start serial comunication at baud=9600. For Arduino mega you would have to add a
                       // number (example: "Serial1.begin(9600);").
                       // If you use an Arduino mega, you have to also edit everything on this sketch that
                       // says "Serial" and replace it with "Serial1" (or whatever number you are using).
  
  pinMode(SensorPin1, INPUT); 
  pinMode(SensorPin2, INPUT);

}

void loop() {  // Put your main code here, to run repeatedly:
  
  SensorValue1 = analogRead(SensorPin1);
  Serial.println(SensorValue1);
  SensorValue2 = analogRead(SensorPin2);
  Serial.println(SensorValue2);
//
//  // We are going to update the progress bar to show the value of the variable.
//  // The progress bar range goes from 0 to 100, so when the variable is greater than 100, the progress bar will keep showing full (100%).
//  Serial.print("n1.val=");  // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
//  Serial.print(SensorValue2);  // This is the value you want to send to that object and atribute mention before.
//  Serial.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.
//  Serial.write(0xff);
//  Serial.write(0xff);
  // We are going to send the variable value to the object called n0:
  // After the name of the object you need to put the dot val because val is the atribute we want to change on that object.
  Serial.print("n0.val=");  // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
  Serial.print(SensorValue1);  // This is the value you want to send to that object and atribute mention before.
  Serial.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.
  Serial.write(0xff);
  Serial.write(0xff);
 delay(500); 

 Serial.print("n1.val=");  // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
  Serial.print(SensorValue1);  // This is the value you want to send to that object and atribute mention before.
  Serial.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.
  Serial.write(0xff);
  Serial.write(0xff);




  delay(500); 

}   // End of loop






/*

// Page change event:
void page0PushCallback(void *ptr)  // If page 0 is loaded on the display, the following is going to execute:
{
  CurrentPage = 0;  // Set variable as 0 so from now on arduino knows page 0 is loaded on the display
}  // End of press event


// Page change event:
void page1PushCallback(void *ptr)  // If page 1 is loaded on the display, the following is going to execute:
{
  CurrentPage = 1;  // Set variable as 1 so from now on arduino knows page 1 is loaded on the display
}  // End of press event


// Page change event:
void page2PushCallback(void *ptr)  // If page 2 is loaded on the display, the following is going to execute:
{
  CurrentPage = 2;  // Set variable as 2 so from now on arduino knows page 2 is loaded on the display
}  // End of press event



*/

I think the solution is hiding behind the distracrion of copy/paste left behind. The sketch shows "// end of setup" immediately above "void setup()" which says a lot about the organization of the full program. Reorganize, and the solution will be easy to find.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.