How to send a RTC Updating value from my Nextion to an Arduino without lib.

Helloooo ;D

I have been spending way too long trying to get a rtc value from NX8048K070_011 over to my Arduino Mega. I’m using the PerryBebbington method of ‘Using Nextion displays with Arduino’ the Arduino side works a treat data is coming in loud and clear.

The issue I have is on the Nextion side.
I have a timer event set to run every 5 seconds with the below code. Also a number n0 on screen.
The Screen number updates as expected but the HEX value of the Printh is static, I have checked the received code and the simulated output.

Question of the day is how best to get the rtc value updating and over to the Arduino pref in Binary.

Ta in Advance

Kev

n0.val=rtc5
printh a5     //Start
printh a5     //Start
printh a5     //Start
printh 00     //Page
printh 01      //Type
printh 00      //Index
printh n0.val

RTC_A.HMI.txt (1.02 MB)

Hello Kev,
Please post your complete code.

Please put your Nextion HMI file into a zip file and upload it. I will take a look but not until tomorrow, intending to have food and beer soon so not really going to want to look at this for you :slight_smile:

Perfect Thanks

Enjoy your food and beers :wink:

The attachment thing got the better of me on the original post, I blame the Gin. So I ended up sticking a .txt on the end of the file so it would go up. But Zip defo a better way :wink:

Kev

RTC_A.zip (9.83 KB)

Hello Untipr,

In your tm0 try:

n0.val=rtc5
printh a5     //Start
printh a5     //Start
printh a5     //Start
printh 00     //Page
printh 01      //Type
printh 00      //Index
prints n0.val,2  //Value

Note I have used prints n0.val,2 not printh n0.val. Note the 2 at the end, that's how many bytes it sends.
The value of n0 will be sent as 2 bytes of hex but as you only really need 1 byte for 0 to 59 you might like to try prints n0.val, however note I have not tested that.

I used the following code on a Nano Every to test:

/* Created for https://forum.arduino.cc/index.php?action=profile;u=1051327 */
/* Tested on Nano Every, should work on any Arduino with a spare serial port (NOT a Uno) */

void setup() {
  Serial.begin(9600); //This is for the serial monitor, if you need it.
  Serial1.begin(9600);  //This is for serial port 1, which is the one used for the Nextion in this demonstration. You might need to change this depending on which serial port you are using for your display.
}

void loop() {
  receiveData();
}

void receiveData() {
  char RxTemp;
  static uint8_t charCount;
  while (Serial1.available() > 0) {
    RxTemp = Serial1.read();
    Serial.print(charCount);
    Serial.print(" byte ");
    Serial.print((byte)RxTemp, HEX);
    Serial.print(" char ");
    Serial.println((char)RxTemp);
    ++charCount;
  }
}

Wow, cheers Perry :slight_smile:

prints n0.val,2  //Value

Works a treat, and saved me from going crazy.

Are supplemental questions allowed? :wink:

if so can you get a timer to run all the time rather than just when a page is active? I'm happy atm just my curiosity getting the better of me. :grinning:

Thanks Again

Kev

Try setting vscope to global and see if that does what you want.

If not then create exactly the same timer on every page, with the same code, same everything.

I've not tried it but you might be able to use something like:

printh a5     //Start
printh a5     //Start
printh a5     //Start
printh 00     //Page
printh 01      //Type
printh 00      //Index
prints rtc5,2  //Value

So as not to need n0 on every page. Try it, play around with it, see what works.

This topic was automatically closed after 120 days. New replies are no longer allowed.