Nextion Not receiving data

Hello,

First time using this forum.... I cannot send data from ardunio to nextion. Serial monitor prints values such as "n2.val=73???" but the value of n2 on my nextion display dose not change. very confused and feel as i have tried everything i could think of in a day...




#define coolantsensorDivider 2670   //defines the resistor value that is in series in the voltage divider
#define coolantsensorPin A0         //defines the analog pin of the input voltage from the voltage divider
#define NUMSAMPLES 5                //defines the number of samples to be taken for a smooth average


const float steinconstA = 0.00147884119800319;        //steinhart equation constant A, determined from wikipedia equations
const float steinconstB = 0.000229807049500269;       //steinhart equation constant B, determined from wikipedia equations
const float steinconstC = 0.000000103363303076981;    //steinhart equation constant C, determined from wikipedia equations

int samples[NUMSAMPLES];                              //variable to store number of samples to be taken
void setup() {
  Serial.begin(9600);                                 //start serial monitor
    delay(500);//Delay to let system boot
}


void loop() {
  uint8_t i;                                          //integer for loop
  float average;                                      //decimal for average
  
  for (i=0; i<NUMSAMPLES; i++) {                      
    samples[i] = analogRead(coolantsensorPin);        //takes samples at number defined with a short delay between samples
    delay(10);
  }

  average = 0;
  for (i=0; i< NUMSAMPLES; i++) {
    average += samples[i];                            //adds all number of samples together
  }
  average /= NUMSAMPLES;                              //divides by number of samples to output the average

  Serial.print("Average Analog Coolant Reading = ");
  Serial.println(average);                                        //analog value at analog pin into arduino
  average = (coolantsensorDivider*average)/(1023-average);        //conversion equation to read resistance from voltage divider
  Serial.print("Coolant Sensor Resistance = ");
  Serial.println(average);

  float steinhart;                              //steinhart equation to estimate temperature value at any resistance from curve of thermistor sensor
  steinhart = log(average);                     //lnR
  steinhart = pow(steinhart,3);                 //(lnR)^3
  steinhart *= steinconstC;                     //C*((lnR)^3)
  steinhart += (steinconstB*(log(average)));    //B*(lnR) + C*((lnR)^3)
  steinhart += steinconstA;                     //Complete equation, 1/T=A+BlnR+C(lnR)^3
  steinhart = 1.0/steinhart;                    //Inverse to isolate for T
  steinhart -= 273.15;                          //Conversion from kelvin to celcius
  steinhart *= 1.8;
  steinhart += 32;
  steinhart =(int)steinhart;


  Serial.print("n2.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(steinhart);  // This is the value you want to send to that object and atribute mentioned 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(5000); //delay between readings
}

Where is the screen connected? you can’t have both the screen and the serial monitor connected on Serial
What arduino are you using?

I am using Mega 2560 and the screen is connected to the tx and rx pins of the ardunio @J-M-L
thank you for the help i did not know they could not both be open, i also plugged everything into same pins on a spare uno i had and there was no change

Use your MEGA

Connect the screen on Serial1 and send the commands to Serial1

Open that serial port at the right baud rate for your screen in the setup

What you send to serial will go to the serial monitor

What you send to Serial1 will go to the screen

There are libraries (some not too good I read) for this screen to simplify your life. I don’t use those screens though so can’t help much with choice there

Thank you very much you sent me in the correct direction so i was able to corret the ports and send values!Thank you! @J-M-L Here is what i did if anyone else runs into same issue



/* This example code shows how to display temperature
 *  from a standard 1 or 2 wire automotive coolant temperature
 *  sensor. These types of sensors are a simple thermistor in
 *  an industrial casing. Thermistor's change resistance based
 *  on temperature. A voltage divider circuit must be used to
 *  read the voltage to a microcontroller. Contact tylerovens@me.com
 *  if you have any questions.
 */



#define coolantsensorDivider 2670   //defines the resistor value that is in series in the voltage divider
#define coolantsensorPin A0         //defines the analog pin of the input voltage from the voltage divider
#define NUMSAMPLES 5                //defines the number of samples to be taken for a smooth average
void plssendvalue(int steinhart);


const float steinconstA = 0.00147884119800319;        //steinhart equation constant A, determined from wikipedia equations
const float steinconstB = 0.000229807049500269;       //steinhart equation constant B, determined from wikipedia equations
const float steinconstC = 0.000000103363303076981;    //steinhart equation constant C, determined from wikipedia equations

int samples[NUMSAMPLES];                              //variable to store number of samples to be taken
void setup() {
  Serial1.begin(9600);                                 //start serial monitor
    delay(500);//Delay to let system boot

}


void loop() {
  uint8_t i;                                          //integer for loop
  float average;                                      //decimal for average
  
  for (i=0; i<NUMSAMPLES; i++) {                      
    samples[i] = analogRead(coolantsensorPin);        //takes samples at number defined with a short delay between samples
    delay(10);
  }

  average = 0;
  for (i=0; i< NUMSAMPLES; i++) {
    average += samples[i];                            //adds all number of samples together
  }
  average /= NUMSAMPLES;                              //divides by number of samples to output the average

  //Serial.print("Average Analog Coolant Reading = ");
  //Serial.println(average);                                        //analog value at analog pin into arduino
  average = (coolantsensorDivider*average)/(1023-average);        //conversion equation to read resistance from voltage divider
  //Serial.print("Coolant Sensor Resistance = ");
  //Serial.println(average);

  float steinhart;                              //steinhart equation to estimate temperature value at any resistance from curve of thermistor sensor
  steinhart = log(average);                     //lnR
  steinhart = pow(steinhart,3);                 //(lnR)^3
  steinhart *= steinconstC;                     //C*((lnR)^3)
  steinhart += (steinconstB*(log(average)));    //B*(lnR) + C*((lnR)^3)
  steinhart += steinconstA;                     //Complete equation, 1/T=A+BlnR+C(lnR)^3
  steinhart = 1.0/steinhart;                    //Inverse to isolate for T
  steinhart -= 273.15;                          //Conversion from kelvin to celcius
  steinhart *= 1.8;
  steinhart += 32;
  steinhart =(int)steinhart;
  plssendvalue(steinhart);
  delay(5000); //delay between readings
}
void plssendvalue(int steinhart){
  Serial1.print("tair.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.
  Serial1.print(steinhart);  // This is the value you want to send to that object and atribute mentioned before.
  Serial1.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.
  Serial1.write(0xff);
  Serial1.write(0xff);
}

great !

(it's probably overkill to use a nextion for just 1 value)

Haha yes this is just a start I have plans to make a full digital dash for my 88 car that doesn't have a obd2 port or a after market ecu I can plug into so it will soon have 6 sensors or so to start! Thanks again for the patience and help I am pretty new to coding and Arduino.

OK makes more sense ! have fun