Persistent Data Storage and Retrieval on Arduino with Nextion Display

I am currently developing a project involving a Nextion screen and an Arduino. The objective is to write a value to the Nextion display, save it to the Arduino's memory, and ensure that the value can be recalled and displayed on the Nextion screen even after a power loss. Although the code successfully stores the value in Arduino's memory, there is an issue with displaying it back on the Nextion screen after a reboot. Can anyone tell me what I am doing wrong?

  #include <Nextion.h>  //HMI Library
  #include <Wire.h>
  #include <Arduino.h>
  #include <EEPROM.h>

const int Light = 13;  // Define the pin number you want to set as an output
unsigned long HMI_activateHour;
unsigned long HMI_deactivateHour;
//HMI Paramters
  NexButton bParamSave = NexButton(1, 26, "b1");  // Button to save the parameters
  //Active Time Hours
  NexText ActiveTimeHourSetpoint = NexText(1, 21, "t17"); // Text input New high setpoint
  //Deactive Time Hours
  NexText DeactiveTimeHourSetpoint = NexText(1, 24, "t19"); // Text input New high setpoint
  NexTouch *nex_listen_list_Page[] = { &bParamSave, NULL };

void setup() 
{ 
// put your setup code here, to run once:
  Serial.begin(9600);
  nexInit(); //HMI Enable
//HMI Button Setup
  bParamSave.attachPop(bParamSavePopCallback);  //HMI Button Cycle Start
  pinMode(Light, OUTPUT);              // Set the specified pin as an output
// // Recall Data
  EEPROM.get(0, HMI_activateHour);
  EEPROM.get(8, HMI_deactivateHour); 
  // Set Data
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);  
  ActiveTimeHourSetpoint.setText(String(HMI_activateHour).c_str());
  DeactiveTimeHourSetpoint.setText(String(HMI_deactivateHour).c_str());
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}

void loop() 
{
  nexLoop(nex_listen_list_Page);
  Print();
}

void Print(){
  Serial.print("HMI_activateHour: ");
  Serial.println(HMI_activateHour);
  Serial.print("HMI_deactivateHour: ");
  Serial.println(HMI_deactivateHour);
}

void bParamSavePopCallback(void *ptr) 
{
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
//Get Active Time
  char ActiveTimeBuffer[10];
  ActiveTimeHourSetpoint.getText(ActiveTimeBuffer, sizeof(ActiveTimeBuffer)); // Read weeks from the text input
  HMI_activateHour = atoi(ActiveTimeBuffer);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
// //Get Deactive Time
  char DeactiveTimeBuffer[10];
  DeactiveTimeHourSetpoint.getText(DeactiveTimeBuffer, sizeof(DeactiveTimeBuffer)); // Read weeks from the text input
  HMI_deactivateHour = atoi(DeactiveTimeBuffer);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
//Store Data
  EEPROM.put(0, HMI_activateHour);
  EEPROM.put(8, HMI_deactivateHour);
}  

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