Making Arduino run for only one loop

I need to run my Nano for about 24 hours collecting temperature readings and then to stop.

My understanding of void setup and void loop has been that setup runs only once while loop runs infinitely.
So I placed my code in void setup and left void loop blank. But during testing, I noticed that the code is running repeatedly and not just once as I had thought.

Is my understanding above incorrect or have I done something different in my program?

Please share suggestions on the recommended way to run my code only once. One method would be to put a ‘while 1’ condition inside void loop. That sounds inefficient. Is there any better method?

code below:

#include <EEPROM.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);


void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);

  // Start up the Dallas temp sensor library
  sensors.begin();

 
// number of readings in total (one evry 10 mins, for a total of 24 h = 60/10 x 24 = 144)
 const int ARRAY_SIZE = 144;
 const int STARTING_EEPROM_ADDRESS = 0;
 
 int newNumbers[ARRAY_SIZE];
 // readIntArrayFromEEPROM(STARTING_EEPROM_ADDRESS, newNumbers, ARRAY_SIZE);
 

  for (int j=0; j< ARRAY_SIZE*2; j+=2) {

   // section to disp all EEPROM readings   
  const int STARTING_EEPROM_ADDRESS = 0;
  readIntArrayFromEEPROM(STARTING_EEPROM_ADDRESS, newNumbers, ARRAY_SIZE);
  Serial.print("###Iteration:");
  Serial.print(j/2 + 1 );
  Serial.print(" of ");
  Serial.println(ARRAY_SIZE);
  for (int i = 0; i < ARRAY_SIZE; i++)
  {
    Serial.println(newNumbers[i]);
  }
    delay (60000);
  sensors.requestTemperatures();  
  int reading = (int) sensors.getTempCByIndex(0) ;
   //int reading = (int) 49.3;
   writeIntIntoEEPROM(j, reading);
  

  

  }

}

  void loop () {
}

void writeIntIntoEEPROM(int address, int number)
{ 
  byte byte1 = number >> 8;
  byte byte2 = number & 0xFF;
  EEPROM.write(address, byte1);
  EEPROM.write(address + 1, byte2);
}



void readIntArrayFromEEPROM(int address, int numbers[], int arraySize)
{
  int addressIndex = address;
  for (int i = 0; i < arraySize; i++)
  {
    numbers[i] = (EEPROM.read(addressIndex) << 8) + EEPROM.read(addressIndex + 1);
    addressIndex += 2;
  }
}

yes the loop runs all the time and setup only once

But during testing, I noticed that the code is running repeatedly and not just once as I had thought.

you have multiple for loops (including needlessly reading the EEPROM array every 10 minutes). What do you see being repeated ??

I have a specific need for which I'm reading the EEPROM every 10 minutes. So not, it is not needless.

Focusing back on my question, it looks like my nano is executing the code that is in the void setup() section repeatedly. I was expecting it to run just once, and then go into void loop and stay there forever.

However, as I type, I think I understand something new - if there is nothing in void loop(), the code simply restarts from void setup()?
So to modify that to my desired behavior (I want it to go to void loop and stay there indefinitely), I guess I have to stick a while (1) inside the void loop. I will test this now and share findings for the benefit of others.

In the mean while, if anyone is already aware of this behavior, please share details.

If code in setup is running repeatedly, then you’re having resets, or doing something to corrupt the program state.

samuraijack256:
I have a specific need for which I'm reading the EEPROM every 10 minutes. So not, it is not needless.

I'd be very curious to know what this is.

There is nothing changing your array's content nor the rest of the EEPROM besides the data point you read.
So you could read the EEPROM once and just update 2 bytes in EEPROM at every step, the array in SRAM would be still matching the EEPROM.

how do you know it's executing setup() multiple times ?