Nextion Enhanced display - data in SD card and Waveforms

Hello,
I'm new to this forum, and new to arduino.

I have home central heating project that is controlling 3-way to set correct supply heat to radiators using temperature sensors in heating system and in living room.

To achieve this I decided to use 2 arduinos (Uno - in boiler room and Mega in living room currently) that is communicating using HC-12 RF modules.

Uno has 3 DS18B20s temperature sensors and controls the valve motor using relays.
Mega has BME280 temperature and humidity sensor and Nextion Enhanced 3.5" display (NX4832K035_011R). (Initially started with 2.4 inch TFT LCD screen ILI9341 shield - that is why I needed the Mega - to have spare pins, because the screen takes all pins of the Uno, but Nextion gives better looks and easier design, so decided to switch).

Initially I have used the original Nextion libraries from ITEAD, but had random communication issues so redone it using tutorial made by PerryBebbington - was a very big help, and was able to do all forward and back communications with it easily. Big thanks to him.. :slight_smile:

So now the problems that I have...
I decided to use the Waveforms to display charts of the temperature change (Set temperature, Actual temperature on one form, and Set supply temp, Actual supply temp, Return temp, Accumulated temp on other page). And the issue is that I could'n find a way to add value to Nextion Waveform while other page is active...
What I want is while I'm looking to the main page (showing actual temperature and humidity), the waveforms would still get the data so I could go those pages and see the history of the change (I should get 80 minutes of history there by writing every 10 seconds in to 450 pixels...)
Function "add ID,Channel,Value" does not have possibility to define page anywhere (or I missed something?). So in this case I should use the "addt" function and load all the data at start of the page, but then question is where should I store the data for 6 channels (450 pixels wide so 6x450 of uint8_t ?).

Fastest load would be if I would be able to store it in the Nextion display itself - It has lots of memory, but how should it be done? There is a variable element that can store number or string, so I do not think that i could use that? So maybe there is a way so save the data in the SD card? Display has this slot for loading the Layout project, so maybe it could be used to save and read data from it? Have any one tried to do so?

If data could not be stored in the Display itself (or It's SD card) so then I should use another SD Card module connected to Mega? (If so, then I'll need to look for those tutorials :slight_smile: ) Or maybe this amount of data would be perfectly OK to be stored inside of the memory of Mega? I do not think that I really need to permanently store the data, so that it could be retrieved after power loss.. But having it would be a bonus (would be able to have longer history with buttons that loads older data...).

Will not post any code, because I have no problems currently with mine (thanks again to PerryBebbington for that... :slight_smile: )

Initially I have used the original Nextion libraries from ITEAD, but had random communication issues so redone it using tutorial made by PerryBebbington - was a very big help, and was able to do all forward and back communications with it easily. Big thanks to him.. :)

You're welcome :slight_smile:

As far as I know you can't do what you are trying to do; you can't send data to a waveform on a page that is not active. Objects on Nextion pages can be local or global scope; local ones lose their data when you change pages, global ones don't so the solution would be to have the waveform with global scope, then it might work. Unfortunately global scope is not an option for a waveform so you can't do it. I have a NX8048K070_011 CTP for my heating controller and I use a waverform to show the outside temperature over the past 7 days. I have to send the data when the page is selected. The data is accumulated in the controller in a big array.

I'm surprised you are using both a Uno and a Mega, are you finding communication between them easy or a nightmare? I would think one or the other would be enough. You could use one of the more powerful boards with a lot more SRAM to hold the data. I don't want to recommend one as I don't know what all your requirements are or what your preferences are but for example an MKR WiFi 1010 has 32K of SRAM, which I would imagine would be more than enough. Please take that as a starting point for looking for a more powerful board, not a final recommendation.

As you suggested 450 pixels wide so 6x450 of uint8_t is 2700 bytes, a Mega has 8k, so unless you are using lots of SRAM elsewhere that should fit. Try it. Create an array of uint8_t and see what happens.

If you can use the Nextion SD card I have yet to find out how. If you do find a way I'd like to know.

Then I should use another SD Card module connected to Mega? (If so, then I'll need to look for those tutorials :) )

Maybe! I can't help with that, not done it. However, a Mega does have 4k of EEPROM, so maybe use that. I've not done that either, you'll have to do your homework, I cannot advise you. You can probably also use the Mega's flash memory for data storage, but again I have not done it, I assume it's possible but I don't know how.

Hopefully there is something in the above to help you.

PerryBebbington:
I have a NX8048K070_011 CTP for my heating controller and I use a waverform to show the outside temperature over the past 7 days. I have to send the data when the page is selected. The data is accumulated in the controller in a big array.

Could you please share the code of this accumulation and data sending when page is selected? I'm currently having the waveform filled with data when particular page is open (2 different pages has waveforms showing different data), but only the newly loaded, so the example would really help. And what controller are you using?

PerryBebbington:
I'm surprised you are using both a Uno and a Mega, are you finding communication between them easy or a nightmare? I would think one or the other would be enough. You could use one of the more powerful boards with a lot more SRAM to hold the data.

I did not know that there could be problems :slight_smile: so was a challenge because of I'm still inexperienced in this area... Had issues when could not send message in setup, but figured, that HC12 needed time to boot or something so only after delay, in the loop I could send first message (using variable and logic that allows to send the initial data request only once 5 sec after boot)
But everything else was OK, the HC12 example worked the first time despite the Uno <-> Mega or Uno <-> Uno... Had more issues with multiplication of big numbers - had inaccuracies... (for example multiply integers 4 and 10000 had result 39999 - if i'm remembering it correctly, so had to do it in doubles and then round it... then result came correctly)

Will try the Mega for the big array storage, but I have ESP32 on the way so it might be good replacement for it (do no know any specifics/differences in library supports, etc, so have no idea if the current code would work, or will need to redo much things...)

PerryBebbington:
If you can use the Nextion SD card I have yet to find out how. If you do find a way I'd like to know.

In Nextion instruction-set I have found command:

rdfile
. Read File contents and outputs contents over serial
usage: rdfile ,,,
is source path and filename as quote encapsulated text
is the starting offset of the file
is number of bytes to return (see note if 0)
is an option (0: no crc, 1: Modbus crc16, 10: crc32)
Note: current support is file in root. Subdirectories are not supported.
If count is 0, then 4 byte file size is returned in little endian order.
rdfile “ram/0.jpg”,0,10,0// send first 10 bytes of file, no CRC, 10 bytes.
rdfile “sd0/0.jpg”,0,10,1// send first 10 bytes of file, MODBUS CRC, 12 bytes.
rdfile “sd0/0.jpg”,0,10,10// send first 10 bytes of file, CRC32, 14 bytes.

So it is only some kind of reading, but there are nothing about writing to file, so might be not possible with Nextion. So store it all in controller's RAM, or if i'll decide that I need history after the power loss, then additional SD card module would be needed...
About EEPROM I have no knowledge (maybe you have some good examples?), only that is not cleared after the reboot, and it is had limited write count, so I do not know if i should mess with that and write 6 values every 10 seconds 24/7 for ~half a year...

Could you please share the code of this accumulation and data sending when page is selected? I'm currently having the waveform filled with data when particular page is open (2 different pages has waveforms showing different data), but only the newly loaded, so the example would really help. And what controller are you using?

My heating controller was designed before I discovered Arduino, it runs on a PIC 18F26K22, which has just under 4k of SRAM, so about half what a Mega has. Even with this I manage to store the temperature log as an array of floats and not use all the memory. 1 measurement every 15 minutes, 96 per day, 672 for 7 days.

float temperature_log[672];

Every second:

        if (clock[0].second == 3 && (clock[0].minute == 0 || clock[0].minute == 15 || clock[0].minute == 30 || clock[0].minute == 45)) {
            if (clock[0].minute == 0 && clock[0].hour == 0) {
                log_temperature_delete();
            }
            log_temperature();
            HMI_P3_update_dow = 1;
            HMI_P3_update_graph = 1;
            HMI_P3_update_min_max = 1;
        }

log_temperature_delete(); deletes (sets to 0.0) the log from the new day from the previous week, for example as Monday starts at midnight it deletes last Monday's data from the log ready for the new Monday's data.

log_temperature(); saves the current temperature in the log with an index calculated for the current day of the week and time. It also saves the current temperature in a separate log of he maximum and minimum for the current day.

I'm reluctant to share the code that sends the data to the display because of the amount of explanation it needs, because it is deeply integrated into other code which then requires explanation and because there is no equivalent to the Arduino Serial.print(); so the way the data is sent is significantly different and also required explanation. I would end up writing a tutorial about a PIC based project on an Arduino site and it wouldn't even be the answer you are looking for, sorry.

I did not know that there could be problems

It's not a case of problems as such, you can get any micro-controller talking to any other if you put the effort in. If you write all your code on one controller then all your data is there in one place where any part of the program can access it. If you have 2 controllers you have to decide which data goes on which controller and what data you want to communicate between them, you have to work out how one controller instructs the other to do something and you have to write code to do all of that. None of that is needed if you put everything on one controller.

rdfile

Applies to the Advanced model, you have the Enhanced model. AFAIK you can't use the SD card for saving and reading data like you want to.

About EEPROM I have no knowledge (maybe you have some good examples?)

No, not done it. This is for your homework. Somewhere on this site there will be instructions. Yes, EEPROM saves data when the power is off, data is not lost. If that's what you want then using the internal EEPROM would best as it's already there. As for write cycles (read are unlimited) check the data sheet. I think (I have not looked) it is of the order of 100000 write cycles, that's per location, not for the whole EEPROM. You have to be careful NOT to write code the accidentally goes mad repeatedly writing the same data to the same location repeatedly. One careless for() loop could kill a location in a few seconds. Yes, the amount of writes you want to make could be a problem. Flash also has a limited number of writes (Flash is basically an improved version of EEPROM). Save the data into SRAM and only write it to EEPROM every hour or on power down (you use a capacitor across the supply to keep the Arduino running for a few seconds after the power fails, you use those few seconds to write the data to EEPROM). You could also try to use more of the EEPROM rather than just a few bytes to spread the writes over more of the available locations.

Will try the Mega for the big array storage, but I have ESP32 on the way so it might be good replacement for it

Loads of everything in an ESP32, I challenge you to use all 520kB of SRAM...

Just found these, which might do what you want:
FRAM
With thanks to
gilshultz
Who pointed them out on a different discussion.