Does Compiling and Uploading Code Hurt My Nano

Hi! Not exactly sure which subforum is most appropriate for this question, but here I am..

I'm on a Nano 33 iot device, and when following a couple of examples, I noticed that when I use the "upload" button on the IDE, it will print:

Write 30124 bytes to flash (471 pages)
[==============================] 100% (471/471 pages)
done in 0.188 seconds

I've read that each device can only write to Flash for a particular amount of times (something like 10,000 or 100,000) - My question is simply: Does this Upload operation count as one of those times? If so, is there anything I can do (change in my code) so that it doesn't do this every time I do an upload? Current Code pasted below, thanks in advance!

//#include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
#include <Wire.h>
#include <HX711_ADC.h>
#include <WiFiNINA.h>

// Initiate LoadCell
HX711_ADC LoadCell(2, 3); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>


//Initiate WifiClient
#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;    

int status = WL_IDLE_STATUS;


//ip address with http
WiFiClient client;
IPAddress server(192, 168, 0, 119);
int portNum = 8000;

// frequency? We can set other criteria
unsigned long lastConnectionTime = 0;            // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds

long t;
float calibration_factor = 2.61; // device dependent

void setup() {
  LoadCell.begin(); // start connection to HX711
  LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
  LoadCell.setCalFactor(999.0); // calibration factor for load cell => strongly dependent on your individual setup
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Getting started!");

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();

  
}
void loop() {

  const int serialPrintInterval = 10000; //increase value to slow down serial print activity
  static boolean newDataReady = 0;

  // check for new data/start next conversion:
  if (LoadCell.update()) newDataReady = true;

  // get smoothed value from the dataset:
  if (newDataReady) {
    if (millis() > t + serialPrintInterval) {
      float i = LoadCell.getData();
      Serial.print("Load_cell output val: ");
      Serial.println(calibration_factor * i);
      newDataReady = 0;
      t = millis();
      uploadScaleData(2);
    }
  }

  // receive command from serial terminal, send 't' to initiate tare operation:
  if (Serial.available() > 0) {
    float i;
    char inByte = Serial.read();
    if (inByte == 't') LoadCell.tareNoDelay();
  }

  // check if last tare operation is complete:
  if (LoadCell.getTareStatus() == true) {
    Serial.println("Tare complete");
  } 
}



// this method makes a HTTP connection to the server:
void uploadScaleData(float scaleValue) {
  // close any connection before send a new request.
  // This will free the socket on the Nina module
  client.stop();

  //  Construct POST data
  String PostData="udid=xxxxxxxxxxx&record_value=25.32";
//  PostData = PostData+"\"record_value\": 25.32}"; 
  Serial.println(PostData);

  // if there's a successful connection:
  if (client.connect(server, portNum)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.println("POST /devices/upload-scale-reading/ HTTP/1.1");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
    client.println(PostData.length());
    client.println();
    client.println(PostData);    
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made:
    lastConnectionTime = millis();
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

10,000 cycles, is a lot for the program FLASH. Do some maths as to how many times a day you reprogram and work out how long it will last you...

Plus most chips will probably do a lot more than 10,000 cycles. That figure is just a worst case minimum such that the manufacturer can guarantee their devices will meet the published specification.

But there’s nothing you can do to change it.

The only write cycle limit you really need to worry about is the data EEPROM, not the program FLASH. With an incorrectly written program, for example constantly writing to EEPROM in loop(), you’ll hit that limit in no time.

I've read that each device can only write to Flash for a particular amount of times (something like 10,000 or 100,000) - My question is simply: Does this Upload operation count as one of those times?

Yes.

If so, is there anything I can do (change in my code) so that it doesn't do this every time I do an upload?

Not really. The actual "upload" is seldom one of the flash writes that people worry about; the concern is when you're using part of the flash to save data (multiple times per minute is easy to exceed.)

You can write your code more carefully so that you don't need to keep changing it... :slight_smile:

Theoretically, if your code is small, you could reconfigure the compiler to upload and run the code from RAM instead of flash. But not from the Arduino IDE, as far as I know.

westfw:
Theoretically, if your code is small, you could reconfigure the compiler to upload and run the code from RAM instead of flash. But not from the Arduino IDE, as far as I know.

No, you can't, because the AVR processors are Harvard architecture, and they are incapable of running code from RAM.

Regards,
Ray L.

OP has a Nano 33 - not an AVR...
(But Ray is right - you can’t run from RAM at all on an AVR.)

Thanks everyone! I thought I would get notifications when there are replies but probably didn't configure the settings correctly..

I just have this bad habit of trying things out after every small changes - guess I'll have to be just a tiny bit more careful with uploading codes. The actual program, when it runs, might require some writes. I'm thinking having configurable wifi credentials saved to the device, which after some research, I think is doable but haven't looked into that too much yet. Even with that, I imagine I should still be fairly safe from the limit.