Issue with Uploading Code to Arduino Board

Hello,

I am experiencing an issue with uploading code to my Arduino board. I am using a non-original Arduino-compatible board (Keyestudio). When I try to upload the code, I get the following error message:
SnĂ­mek obrazovky 2024-12-24 171450

I have tried various solutions, including changing the port and selecting the correct board type in the Arduino IDE, but the issue persists.

Here is the detailed setup:

*Board model: Keyestudio/Arduino UNO
*Port: COM3
*Arduino IDE version: 2.3.4

I also verified that the board is powered and that the connections are correct. The onboard LED blinks when I upload simple code like blinking an LED, so the board seems to be functioning properly in other scenarios.

Has anyone encountered a similar issue? Any suggestions or solutions would be greatly appreciated!

Thank you in advance!

Best regards,
Daniel

If the "Arduino" is good, this error is usually from (1) the "Arduino" needs the CH340 driver installed, (2) if CH340 is installed, IDE >> TOOLS >> PROCESSOR >> OLD BOOTLOADER (3) the USB cable is not a data cable (only a power cable)

1 Like

AFIK, the Keystudio Uno R3 board uses a 16u2 as the usb interface chip
https://www.jameco.com/Jameco/Products/ProdDS/2283863.pdf

The onboard LED blinks when I upload simple code like blinking an LED, so the board seems to be functioning properly in other scenarios.

@daniel464895 are you saying that you can load code to the board and change the blink rate of the led, or that the board is currently running the blink code?

If you can indeed load simple code, you will need to post the code which does not load.

Are you using the same usb cable which can load the simple code as when you try code which does not load and gives and error?

2 Likes

Hi @cattledog
Yes, I am able to load simple code (like the blink example) to the board and change the blink rate of the LED, which works perfectly. However, when I try to load a more complex code, it fails to upload and gives the error message.

I am using the same USB cable for both the simple code upload and the complex one. The simple code uploads fine, but when I try the other one, the error appears.

There is the complex code:

#include <Servo.h>
#define Trigger_Pin 5
#define Echo_Pin 4
#define LeftMotorPin1 D1
#define LeftMotorPin2 D2
#define RightMotorPin1 D3
#define RightMotorPin2 D4
#define IR_Pin A0
#define LeftPhotoCell A1
#define RightPhotoCell A2
#define BluetoothPin 6

Servo myservo;
int servoPosition = 0;
long duration;
long distance;

void setup() {
  pinMode(LeftMotorPin1, OUTPUT);
  pinMode(LeftMotorPin2, OUTPUT);
  pinMode(RightMotorPin1, OUTPUT);
  pinMode(RightMotorPin2, OUTPUT);

  pinMode(Trigger_Pin, OUTPUT);
  pinMode(Echo_Pin, INPUT);

  pinMode(IR_Pin, INPUT);
  pinMode(LeftPhotoCell, INPUT);
  pinMode(RightPhotoCell, INPUT);

  myservo.attach(9);

  Serial.begin(9600);
}

void loop() {
  digitalWrite(Trigger_Pin, LOW);
  delayMicroseconds(2);
  digitalWrite(Trigger_Pin, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trigger_Pin, LOW);

  duration = pulseIn(Echo_Pin, HIGH);
  distance = duration * 0.034 / 2;

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.print(" cm");

  if (distance < 10) {
    myservo.write(90);
  } else {
    myservo.write(0);
  }

  int leftPhotoValue = analogRead(LeftPhotoCell);
  int rightPhotoValue = analogRead(RightPhotoCell);

  if (leftPhotoValue > 512) {
    digitalWrite(LeftMotorPin1, HIGH);
    digitalWrite(LeftMotorPin2, LOW);
  } else {
    digitalWrite (LeftMotorPin1, LOW);
    digitalWrite (LeftMotorPin2, HIGH);
  }

  if (rightPhotoValue > 512) {
    digitalWrite (RightMotorPin1, HIGH);
    digitalWrite (RightMotorPin2, LOW);
  } else {
    digitalWrite (RightMotorPin1, LOW);
    digitalWrite (RightMotorPin2, HIGH);
  }

  int irValue = analogRead(IR_Pin);
  if (irValue == HIGH) {
    digitalWrite(LeftMotorPin1, LOW);
    digitalWrite(LeftMotorPin2, LOW);
    digitalWrite(RightMotorPin1, LOW);
    digitalWrite(RightMotorPin2, LOW);
  }

  if (Serial.available()) {
    char command = Serial.read();
    if (command == 'F') {
  

  digitalWrite(LeftMotorPin1, HIGH);
  digitalWrite(LeftMotorPin2, LOW);
  digitalWrite(RightMotorPin1, HIGH);
  digitalWrite(RightMotorPin2, LOW);
  }
  else if (command == 'B') {

    digitalWrite(LeftMotorPin1, LOW);
    digitalWrite(LeftMotorPin2, HIGH);
    digitalWrite(RightMotorPin1, LOW);
    digitalWrite(RightMotorPin2, HIGH);
      }
  }

  delay(100);
}

Let me know if you need any more information or the exact error message.

Thanks!

Hi @xfpd
Thank you for your suggestion! I followed your advice and tried the following:

  1. *CH340 driver: I checked if the CH340 driver was installed, and I installed it if it wasn’t already present. It didn't seem to resolve the issue.

  2. *Old Bootloader: I went to the Arduino IDE and tried to select "Old Bootloader" in Tools > Processor, but I noticed that the "Processor" option is missing, so I couldn't select it. Despite that, I still encountered the same error when trying to upload the code.

  3. *USB Cable: I also checked the USB cable. It is a data cable (not just a power cable), and I have used it with other devices successfully.

However, the error persists. Could there be another solution or something I might have missed? Thank you again for your help!

I could not get your code to compile with

#define LeftMotorPin1 D1
#define LeftMotorPin2 D2
#define RightMotorPin1 D3
#define RightMotorPin2 D4

When the D was removed from the pin numbers, I could compile and load your sketch.

Pin 1 is a Serial tx pin, and since you are using Serial in your sketch, you should not use it as the motor pin.

Since I don't understand your ability to compile and then fail upload, I would like you to go into File>Preferences in the IDE and enable the verbose output during compile and upload. Then copy and post the complete message you get.

Sorry. @cattledog pointed to my error. The 16U2 does the data communications.

Hi @cattledog

I’ve finally figured out what was causing the issue. It turns out the problem was with the Bluetooth module. When I had it connected, the code wouldn’t upload properly. After disconnecting the Bluetooth module, everything worked fine and I was able to upload the code without any issues.

Thank you for your help!

Merry Christmas🎄

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