Able to upload sketch to one UNO but no other boards

I have created two sketches - one transmitting program and one receiving program. The sketch I've uploaded to the transmitting Arduino have no issues, however, when uploading the receiving sketch it just uploads forever. I've tried with 4 different UNO boards and one MEGA board. It works sometimes right after I boot my PC, but not always. I have tried changing the COMx number in device manager several times, doesn't work. I have tested a bunch of USB cables in addition. I would be grateful for some help - I'm going mad.

This is my latest error message when trying to upload:

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\olesn\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : COM11
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
avrdude: ser_open(): can't open device "\\.\COM11": Access is denied.


avrdude: ser_drain(): read error: The handle is invalid.


avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.


avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.


avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.


avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.


avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.


avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.


avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

avrdude done.  Thank you.

Failed uploading: uploading error: exit status 1

Do you select the correct board with IDE >> TOOLS >> BOARD >> AVR BOARDS >> (board)

1 Like

Yes I did. And checked the port.
I think it might be a serial flood (?) and the board won't stop to receive a new sketch. Anyone knows how to fix? Perhaps factory reset or something? Here's the code:


// Arduino B (Receiver)

// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 790;
const float stepsPerAngle = float(stepsPerRevolution) / float(360);

int currentAngle = 0;
float radangle = 0;
int angleDifference = 0;

int lastTime = 0;

void setup() {
  Serial.begin(115200); // Initialize serial communication at 115200 baud

  

  // Declare stepper pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  Serial.print("\nSetup finished");
  delay(5000);

}

void loop() {
  if (millis() - lastTime >= 5) { // Attempt to read position every 5 milliseconds
    lastTime = millis();
  
    if (Serial.available() > 0) { // Check if data is available to read
      float angle = Serial.parseFloat(); // Read the angle data

      Serial.print("\nangle: ");
      Serial.print(angle);
      // Control stepper motor based on received angle
      //controlStepperMotor(angle); // Your stepper motor control function
      int steps = 0;

      float deltaAngle = abs(currentAngle - angle);
      
      if(angle > 0 && angle <= 360){
        if(deltaAngle < 10){
          // Adjust angle according to button choice
          if(currentAngle != angle){      
              if(currentAngle < angle){
                  // Set motor direction clockwise
                digitalWrite(dirPin, LOW);
                  angleDifference = angle-currentAngle;
                  steps = angleDifference*stepsPerAngle;
                for(int x=0; x<steps; x++){
                  digitalWrite(stepPin, HIGH);
                  delayMicroseconds(1500);
                  digitalWrite(stepPin, LOW);
                  delayMicroseconds(100);
                  }
              }

              else if(currentAngle > angle){
                  // Set motor direction counterclockwise
                digitalWrite(dirPin, HIGH);
                  angleDifference = currentAngle-angle;
                  steps = angleDifference*stepsPerAngle;
                  for(int x=0; x<steps; x++){
                    digitalWrite(stepPin, HIGH);
                    delayMicroseconds(1500);
                    digitalWrite(stepPin, LOW);
                    delayMicroseconds(100);
                  }
              }
              currentAngle = angle;
          }
        }
      }
    }
  }
}

Take these steps:

Power off the board completely
Remove the USB cable
Hold down the Reset button
keep it held down (or, run a jumper wire from the RESET pin to the GND pin).
Still holding down Reset reconnect the USB cable.
Start uploading a sketch that does not have this problem (I use the Blink sketch).
When you see the Receive light blink, release the Reset button
Change your code and add a delay(3000), or more in setup(). This allows easy recovery from a serial flood.
Note: I have seen this happen several times when I flood the serial output. An indication is the TX light is stuck on.

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