sending readings to Nextion display - Stuck

Hi All

Firstly thank you for clicking on this thread and I hope some one can point me in the right direction.

I am building an Aquarium monitor with the following:

UNO
one wire sensor
waterflow sensor
RTC clock module.

I can get the read outs on my 24x4 lcd however getting the reading on the nextion is getting tricky. I have a custom background with the text boxes labelled temperature, flow rate and time.

I have looked through many videos and resources and cant get the information over to the uno.

If you need any further information please ask.

Thanks

code below:

//LIBRARIES

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>  // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
#include <DS3231.h> // CLOCK MODULE


// PINS USED - Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 7

//Raspberry Pi is connected to Serial 0
#define serialPi Serial

DS3231  rtc(SDA, SCL);

float humidity = 0.0f;

// USED VARIABLES

volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 2;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal


}

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
void setup(void)
{
  //   start serial port
  Serial.begin(9600);
  //  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  lcd.begin(20, 4);
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0, 0);
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  Serial.begin(9600); //This is the setup function where the serial port is initialised,


  attachInterrupt(0, rpm, RISING); //and the interrupt is attached

  rtc.begin();
}
// the loop() method runs over and over again,
// as long as the Arduino has power



void loop(void)
{
  Serial.print ("Aquarium monitor created by Robert Ball:"); //Prints "Aquarium monitor created by Robert Ball "
  Serial.print('\n'); //returns a  new line*/
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.print("Temperature for the device 1 (index 0) is: ");
  float x = sensors.getTempCByIndex(0);
  Serial.print(x);
  Serial.print('\n'); //returns a  new line*/
  Serial.print ("L/hour: "); //Prints "L/hour"
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print('\n'); //returns a  new line*/
  Serial.print ("PH: THIS WILL BE PHASE 3"); //Prints "PH" - code required below for getting the ph reading to the serial print screen
  Serial.print('\n'); //returns a  new line*/
  Serial.print ("Date: "); //Prints "Date"
  Serial.print (rtc.getDateStr()); //Requests the date from the clocl module
  Serial.print('\n'); //returns a  new line
  Serial.print ("Time: "); //Prints "Time"
  Serial.print (rtc.getTimeStr()); // Requests the time from the clock module
  Serial.print('\n'); //returns a  new line

  //Send temperature and humidity data to Raspberry Pi
  serialPi.print("<");
  serialPi.print(x);
  serialPi.print(",");
  //serialPi.print(humidity);
  //serialPi.println(">");

  // print First line to LCD - Temp sensor
  lcd.setCursor(0, 0);
  lcd.print("Temp:       C ");
  lcd.setCursor(7, 0);
  lcd.print("          ");
  lcd.setCursor(7, 0);
  lcd.print(x);

  // print Second line to LCD - waterflow sensor
  lcd.setCursor(0, 1);
  lcd.print("L/hour: ");
  lcd.setCursor(7, 1);
  lcd.print("          ");
  lcd.setCursor(7, 1);
  lcd.print(Calc, DEC);;

  // print Third line to LCD - PH probe
  lcd.setCursor(0, 2);
  lcd.print("PH: ");
  lcd.setCursor(7, 2);
  lcd.print("PHASE 3");
  lcd.setCursor(7, 2);

  // print Forth line to LCD - Date - part 1
  lcd.setCursor(0, 3);
  lcd.print("DATE:");
  lcd.setCursor(0, 3);
  lcd.print(rtc.getDateStr());

  // print Forth line to LCD - Time - part 2
  lcd.setCursor(10, 3);
  //lcd.print("TIME:");
 // lcd.setCursor(12, 3);
  lcd.print(rtc.getTimeStr());

  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  delay (1000);      //Wait 1 second
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour

}
/*
  ****************************************************************************************************
                                                NOTES - CODE
  ****************************************************************************************************

  CODE
   // reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
  // Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
  // http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com

  volatile int NbTopsFan; //measuring the rising edges of the signal
  int Calc;
  int hallsensor = 2;    //The pin location of the sensor

  void rpm ()     //This is the function that the interupt calls
  {
  NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal


  }
  // The setup() method runs once, when the sketch starts
  void setup() //
  {
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  Serial.begin(9600); //This is the setup function where the serial port is initialised,


  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
  }
  // the loop() method runs over and over again,
  // as long as the Arduino has power
  void loop ()
  {
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  delay (1000);      //Wait 1 second
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour


  Serial.print (Calc, DEC); //Prints th


*/
1 Like

Hello ballerball,
Welcome to the forum
For posting your code correctly on your first post ++Karma;

What you are asking and the code you have posted don't match. You ask about sending text to a Nextion but your code is about sending stuff to an Rpi and an LCD, there is nothing in there that would communicate with a Nextion.

I have looked through many videos and resources and cant get the information over to the uno.

This does not make sense. You initially asked about getting stuff on a Nextion now you are saying you can't get information to a Uno, what are you really asking about. As for 'looking through videos and other resources', I can only think you didn't look at 'using Nextion displays with Arduino' on this site, as the top of the displays forum.

Finally, using a Nextion with a Uno, while possible, is a bit of a problem as the one serial port on a Uno is used for the serial monitor already, making is not really useable with a Nextion (although I have had it working I don't recommend trying).

PerryBebbington:
What you are asking and the code you have posted don’t match. You ask about sending text to a Nextion but your code is about sending stuff to an Rpi and an LCD, there is nothing in there that would communicate with a Nextion.

This does not make sense. You initially asked about getting stuff on a Nextion now you are saying you can’t get information to a Uno, what are you really asking about. As for ‘looking through videos and other resources’, I can only think you didn’t look at ‘using Nextion displays with Arduino’ on this site, as the top of the displays forum.

Finally, using a Nextion with a Uno, while possible, is a bit of a problem as the one serial port on a Uno is used for the serial monitor already, making is not really useable with a Nextion (although I have had it working I don’t recommend trying).

Thank you for your reply

Sorry I wasn’t clear in last post. Updates below:

  1. I have changed the Ardunio UNO to the MEGA 2560 as you mentioned in your last post and in the thread you created in the Display section which had lots of information in.

  2. I am only trying to get the readings from the Ardunio 2560 to the Nextion display ONLY at this time.

  3. My mistake the code includes rasberry pi because I was putting the read outs from the serial port to a website. (This has been taken out of code)

  4. I have made some changes to the code However I can not get the Nextion to pick it up.

Update code below

I have also upload a copy of the HMI file.

Lastly, I am getting the following via serial port on the computer:

18:37:33.200 → n0.val=23.06⸮⸮⸮
18:37:34.321 → n0.val=23.06⸮⸮⸮
18:37:35.433 → n0.val=23.06⸮⸮⸮
18:37:36.547 → n0.val=23.06⸮⸮⸮
18:37:37.667 → n0.val=23.06⸮⸮⸮
18:37:38.804 → n0.val=23.06⸮⸮⸮
18:37:39.932 → n0.val=23.06⸮⸮⸮
18:37:41.048 → n0.val=23.06⸮⸮⸮
18:37:42.163 → n0.val=23.06⸮⸮⸮
18:37:43.313 → n0.val=23.06⸮⸮⸮
18:37:44.436 → n0.val=23.06⸮⸮⸮
18:37:45.540 → n0.val=23.06⸮⸮⸮
18:37:46.660 → n0.val=23.06⸮⸮⸮
18:37:47.786 → n0.val=23.06⸮⸮⸮

Any idea what is causing the ⸮⸮⸮ ?

 //LIBRARIES

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>  // Comes with Arduino IDE
#include <DS3231.h> // CLOCK MODULE
//#define nexSerial Serial2
//#include "Nextion.h"

//NexGpio gpio;
#define NexNumber n0 = NexNumber(0,5,"n0");
//#define NexNumber n1 = NexNumber(0,3,"n1");

// PINS USED - Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 7

DS3231  rtc(SDA, SCL);

float humidity = 0.0f;

// USED VARIABLES

volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 2;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal


}

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
{
  //   start serial port
  Serial.begin(9600);
  //  Serial.println("Dallas Temperature IC Control Library Demo");

  //   start serial port1
  Serial1.begin(9600);


  attachInterrupt(0, rpm, RISING); //and the interrupt is attached

  rtc.begin();
}
// the loop() method runs over and over again,
// as long as the Arduino has power

//nexSerial.begin(9600);

void loop(void)
{
  //Serial1.print ("Aquarium monitor created by Robert Ball:"); //Prints "Aquarium monitor created by Robert Ball "
  //Serial.print('\n'); //returns a  new line*/
  //sensors.requestTemperatures(); // Send the command to get temperatures
  //Serial.print("Temperature for the device 1 (index 0) is: ");
  //float x = sensors.getTempCByIndex(0);
  //Serial.print(x);
  //Serial.print('\n'); //returns a  new line*/
  //Serial.print ("L/hour: "); //Prints "L/hour"
  //Serial.print (Calc, DEC); //Prints the number calculated above
  //Serial.print('\n'); //returns a  new line*/
  //Serial.print ("PH: THIS WILL BE PHASE 3"); //Prints "PH" - code required below for getting the ph reading to the serial print screen
  //Serial.print('\n'); //returns a  new line*/
  //Serial.print ("Date: "); //Prints "Date"
  //Serial.print (rtc.getDateStr()); //Requests the date from the clocl module
  //Serial.print('\n'); //returns a  new line
  //Serial.print ("Time: "); //Prints "Time"
  //Serial.print (rtc.getTimeStr()); // Requests the time from the clock module
  //Serial.print('\n'); //returns a  new line

  /* THIS IS NEW CODE FOR NEXTION DISPLAY TESTING*/
  //Serial1.print ("Aquarium monitor created by Robert Ball:"); //Prints "Aquarium monitor created by Robert Ball "
  //Serial.print('\n'); //returns a  new line*/
  sensors.requestTemperatures(); // Send the command to get temperatures
  //Serial.print("Temperature for the device 1 (index 0) is: ");
  float x = sensors.getTempCByIndex(0);
  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(x);  // 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);
Serial.print('\n'); //returns a  new line*/



  //Serial.print('\n'); //returns a  new line*/
  //Serial.print ("L/hour: "); //Prints "L/hour"
  //Serial.print (Calc, DEC); //Prints the number calculated above
  //Serial.print('\n'); //returns a  new line*/
  //Serial.print ("PH: THIS WILL BE PHASE 3"); //Prints "PH" - code required below for getting the ph reading to the serial print screen
  //Serial.print('\n'); //returns a  new line*/
  //Serial.print ("Date: "); //Prints "Date"
  //Serial.print (rtc.getDateStr()); //Requests the date from the clocl module
  //Serial.print('\n'); //returns a  new line
  //Serial.print ("Time: "); //Prints "Time"
  //Serial.print (rtc.getTimeStr()); // Requests the time from the clock module
  //Serial.print('\n'); //returns a  new line
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  delay (1000);      //Wait 1 second
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour


}
1 Like

Any idea what is causing the ⸮⸮⸮ ?

Yes.

  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);

The serial monitor can't display 0xff so it displays those weird characters instead to tell you there is something there but it doesn't know what to do with it. The Nextion, however, needs the three 0xff at the end to tell it that is the end of the data you are sending.

You are using an integer number box, n, on the Nextion and trying to send a float to it. You can only send integers to to them.

If you follow the methods I set out in my tutorial you won't need number boxes. Use a text box (t0 in the example below) instead and try something like (not tested):

    Serial1.print(F("t0.txt=\""));
    Serial1.print(x);
    Serial1.print(F("\""));
    Serial1.write(0xff);
    Serial1.write(0xff);
    Serial1.write(0xff);

This assumes the Nextion is on serial port 1 (don't use serial port 0 for the Nextion, that's for the serial monitor)

Don't use:

Serial.print('\n'); //returns a  new line*/

In the code sending to the Nextion.

1 Like