Skip to main content
1 of 2
MattG
  • 117
  • 1
  • 6

Sparkfun Pro-Micro stuck on uploading

I have read multiple posts on how to reset the pro-micro when it gets stuck during upload, and this seems to work to get it back to a state where I can upload new code again - However, I am here to ask if it is possible that it is something in my code that is causing this issue? The reason I suspect it is my code is because I have tried:

  • Different pro micro
  • Different USB cable
  • Downloaded latest IDE
  • Downloaded latest AVR boards package
  • Tried reverting back to an older AVR boards package as suggested in a different post

Not sure if this is a coincidence, but when I upload a simple blink sketch I don't have any trouble, but as soon as I upload my code (below), it gets stuck on uploading... I can get it to eventually upload after many attempts using the reset during upload trick, but it seems to be unstable. I say unstable because sometimes it will print out the values requested, and other times it will print nothing...

int clampVal = 0;

void setup() {
  Serial.begin(115200);
}


void ClampReading()
{
    const int numRead = 400; //amount of calibration values we will average
    double vals[numRead];      // the readings from the analog input
    int readIndex2 = 0;                 // the index of the current reading
    double total2 = 0;                  // the running total
    int calibration2 = 0;               // calibration incrementer

    for (int thisReading2 = 0; thisReading2 < numRead; thisReading2++) {
    vals[thisReading2] = 0;
    }
    while(calibration2<numRead)
    {
      int rawClamp = analogRead(A0);
      total2 = total2 - vals[readIndex2];
      vals[readIndex2] = rawClamp;
      total2 = total2 + vals[readIndex2];
      readIndex2 = readIndex2 + 1;
      if (readIndex2 >= numRead) {
        readIndex2 = 0;
     }
      clampVal = total2 / numRead;
      calibration2++;
    }
      
}  


void loop() {
 ClampReading();
 Serial.println(clampVal);
}
MattG
  • 117
  • 1
  • 6