Uno Wifi Rev.2 Cant upload a new program, with program already running

Hi everyone,

Today my Arduino Uno Wifi rev2 came in, as i was having trouble with the SRAM capacity of my Uno. What I'm trying to do, is connect to the arduino a motion sensor, of which the output is saved to an SD card. The idea was that the system could measure without being connected to the computer. I used the following code (ignore the custom libraries):

#include <XSens.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

//Initializing XSens at ADDRESS 0X1D
XSens xsens(0x6b);
File myFile;
const int chipSelect = 4;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  //Wake up process
  xsens.begin();

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
}
void loop() {
  //Read mesurements (Reads all data given by the AHRS)
  
  myFile = SD.open("kloek.txt", FILE_WRITE);
  
  if (myFile) {
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  delay(1000);
}

This worked fine. I could also edit to code to write data from the sensor to the SD card, no issues. However, the serial monitor had to be opened before the writing to the SD card began. I figured I could just remove the lines containing "Serial" and I added 3 lines to make the led blink whenever there was an error with opening the file. The code is as follows (again ignore the custom libraries):

#include <XSens.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

//Initializing XSens at ADDRESS 0X1D
XSens xsens(0x6b);
File myFile;
const int chipSelect = 4;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  //Wake up process
  xsens.begin();
  pinMode(LED_BUILTIN, OUTPUT);

}
void loop() {
  //Read mesurements (Reads all data given by the AHRS)
  xsens.updateMeasures();
  myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile) {
//    myFile.println("testing 1, 2, 3.");
    for(int i = 0 ; i < 3; ++i){
      myFile.print(xsens.getEulerd()[i]);
      myFile.print(" ");
    }

    for(int i = 0 ; i < 3; ++i){
    myFile.print(xsens.getFAccel()[i]);
    myFile.print(" ");
    }
    myFile.print(xsens.getStime()/10);
    myFile.println(" ");
  
    
    
    // close the file:
    myFile.close();

  } else {
    // if the file didn't open, print an error:
    digitalWrite(LED_BUILTIN, HIGH);
    delay(20);
    digitalWrite(LED_BUILTIN, LOW);
  }
  delay(1000);
}

After I uploaded this, the L started blinking with one second intervals, suggesting that the program was not writing anything, and this was the case after I checked the SD card. Now, when I try to upload a new sketch, It gets stuck uploading. This is also the case for the BareMinumum sketch. The program on the Arduino is still running as I see the light blinking. There seems to be no exchange between the Arduino and the computer. I also found that somewhere along the way, the port switched from COM8 to COM9. I tried to find similar problems on the forums but the solutions didnt work out for me.

Things that I tried:

-Reboot computer
-Reinstall drivers
-Disabling Bluetooth ports
-Holding the reset button while uploading
-Checked the board and port in the "Tools" menu
-Connecting my Arduino Uno and uploading different sketches, which worked fine

Sorry for the whole "story", but as im quite inexperienced with Arduino, I'm trying to provide you with the information that I understand. I hope I made my issue clear.

Thank you in advance and kind regards,

L

Please do this:

  • (In the Arduino IDE) File > Preferences
  • Uncheck the checkbox next to "Show verbose output during: compilation"
  • Check the checkbox next to "Show verbose output during: upload
  • Click "OK"
  • Sketch > Upload
  • After the upload fails, you'll see a button on the right side of the orange bar "Copy error messages" (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button.
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
  • Press "Ctrl + V". This will paste the upload output between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the upload just hangs and never fails, then you won't get the "two pieces of paper" icon, and instead you'll need to click on the black console pane of the Arduino IDE, then Ctrl + A to select all, and Ctrl + C to copy the selected text to the clipboard.

You can use one simple trick. Press and hold the reset button of the Arduino, keep that button holded. Then click upload. Release the reset button just when the Arduino IDE shows "Sketch used ..... bytes of program memory" or something like that. You should try it multiple times and adjust the proper timing of releasing the reset button. This could help.

..Arnav

ArnavPawarAA:
You can use one simple trick. Press and hold the reset button of the Arduino, keep that button holded. Then click upload. Release the reset button just when the Arduino IDE shows "Sketch used ..... bytes of program memory" or something like that. You should try it multiple times and adjust the proper timing of releasing the reset button. This could help.

..Arnav

Uno WiFi doesn't work like that. so this another wrong advice from you.
it has a programmer on-board