Read byte and time into EEPROM, then display with a comma between the time and the value?

I have bytes of natural numbers 1-60 coming in at random times.

I want to log the time (any time format) and what value was received into EEPROM:

#include <EEPROM.h>

const int timeRefreshDisplay = 30000;
const int EEPROM_SIZE = 100; // Define size of EEPROM available
int addr = 0; // EEPROM address pointer

unsigned long programStartTime;

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600); // Initialize Serial1 for data input
  programStartTime = millis(); // Record program start time
}

void loop()
{
  if (Serial1.available())
  {
    int receivedData = Serial1.read();

    if (receivedData != 0 && receivedData <= 60)
    {
      byte receivedValue = receivedData; // Convert?

      // Calculate the timestamp based on program start time
      unsigned long currentTime = programStartTime + millis();

      // Store the received timestamp and value in EEPROM
      EEPROM.put(addr, currentTime);
      addr += sizeof(unsigned long);
      EEPROM.put(addr, receivedValue);
      addr += sizeof(int);
    }
  }

  if (millis() - programStartTime >= timeRefreshDisplay)
  {
    programStartTime = millis();
    displayEEPROMData();
  }
}

void displayEEPROMData() {
  // Display all positions stored in EEPROM
  Serial.println("EEPROM:");

  for (int i = 0; i < EEPROM_SIZE; i += sizeof(unsigned long) + sizeof(int)) {
    if (i >= EEPROM_SIZE) {
      i = 0; // Start reading from the beginning when reaching the end of EEPROM
    }

    unsigned long timestamp;
    int value;
    EEPROM.get(i, timestamp);
    EEPROM.get(i + sizeof(unsigned long), value);

    // Display position data with timestamp in HH:MM:SS format
    Serial.print(String(i / (sizeof(unsigned long) + sizeof(int)) + 1) + ": ");
    Serial.println(String(timestamp) + ", " + String(value));
  }
}

Serial monitor

EEPROM:

1: 17330, 22272
2: 101, 27943
3: 4143972352, 116
4: 0, 0
5: 0, 0
6: 0, 0
7: 0, 0
8: 0, 0
9: 0, 0
10: 0, 0
11: 0, 0
12: 0, 0
13: 0, 0
14: 0, 0
15: 0, 0
16: 0, 0
17: 0, 0

I'm not quite sure how it is reading data into EEPROM. That has to be where the issue is. I just don't know how to fix it.

Example of send data

// Uno send

void setup() {
  Serial.begin(9600);
  
  int integersToSend[] = {1, 22, 30, 4, 50};
  for (int i = 0; i < 5; i++) 
  {
    Serial.print(integersToSend[i]);  // send as characters
    delay(1000);
  }
}

void loop() {}

Which board are you using ?

This sends ASCII character strings representing the stored decimal numbers. Is that your intention?

Leonardo receiving (any to send).

Yes. The data is sent. That's all I care that is done.

Highly recommend you ask @adamaero for some assistance. He's just been through this.

Or(evil thought), are you on the same project? Eerily similar specs.

@adamelli You and @adamaero appear to have the same IP address and similar usernames.

Please explain how this could be

why

Why what ?

Are you working together or is it a case of one person with two accounts ?

I don't see why it would matter either way, two different questions.

It would matter because one person having two accounts is against the policy of the forum

Perhaps @adamelli copied and slightly modified this code from the @adamaero thread, and amazing, ran into the same problems with EEPROM.

// Uno program, five random integers

void setup() 
{
  Serial.begin(38400);

  int integersToSend[] = {12345, 65432, 333, 4, 5050};
  for (int i = 0; i < 5; i++) 
  {
    Serial.print(integersToSend[i]);
    delay(1000);
  }  
}

void loop() {}

And another thread pops up. Paid consultancy, no less! Rich. Still, we'll go help him there, for a bit.

As a request for help has now been posted elsewhere this topic will be closed