COM port works only with new sketches

I've just bought brand new arduino nano board. I wrote some code and uploaded it to the board. Everything worked fine until I made some changes to the code and tried to upload it again. It doesn't seem to be the code issue because it happens even with empty sketch. If i edit an existing sketech and try to upload it, I get an error saying that acces to COM port is denied... Tried to fix that with device maneger and changing the port number but that didn't work.

#define joyX A0
#define joyY A1

int xValue, yValue;

void update_joystick() {
  xValue = analogRead(joyX);
  yValue = analogRead(joyY);
  Serial.print("X: ");
  Serial.print(xValue);
  Serial.print(" Y: ");
  Serial.println(yValue);
}


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

void loop() {
  // put your main code here, to run repeatedly:
  update_joystick();
}

that's the code i was working with, the changes I made were to map the xValue and yValue.
If I open new sketch and paste the code, it uploads. But I have to do it every time I change something in the code.

It appears you have a serial flood, you are sending more then the uart can process. Take these steps and upload the blink sketch:

  1. Power off the board completely
  2. Remove the USB cable
  3. Hold down the Reset button
  4. keep it held down (or, run a jumper wire from the RESET pin to the GND pin).
  5. Still holding down Reset reconnect the USB cable.
  6. Start uploading a sketch that does not have this problem (I use the Blink sketch).
  7. When you see the Receive light blink, release the Reset button
    Note: I have seen this happen several times when I flood the serial output. An indication is the tx light is stuck on.
1 Like

This is a known bug with the IDE 2.2.x that is being worked on in the background.

Use this workaround whenever you start a new sketch:

  1. Close the Serial Monitor by pressing the "X" on the tab

  2. In the board/port pull-down select a board and COM port OTHER than the port you want to use

  3. Then re-select the board & COM port you want to use.

You should now be good to go ...

It's a bit annoying, but it is an effective solution

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.