my arduino Leonardo was working perfectly the last days, but today when i tried to upload a sketch it disconnected right after I hit the upload button. I tried with different sketches, but still no luck. I have red about the reset and upload sketch trick but that doesnt fix the problem for me.
I am getting this error:
Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.
Programmer supports the following devices:
Device code: 0x44
It disconnects when the actual upload starts. The thing is that for simple projects, such as the blink , even though it disconnected , it has uploaded the code cause the led blinks.
But when i try to upload a more complex sketch, I am trying to make leornado a joystick, it doesnt actually upload the code. It disconnects completely and I have to reset it to get it to work again and it is very weird because yesterday it was working perfectaly.
Check what happens in Windows device manager; is the port still there? Note that it might have moved.
Part of the code that is uploaded is responsible for board detection and for the detection of the software reset (not the hardware reset by the reset button).
A buggy sketch can overwrite variables used by that part if the code. If that happens, your board is either not detected (your case) or it does not react on the software reset.
When I plug my leonardo in my pc, my device manager shows the port. But as soon as I upload the sketch, it disconnects and when i hear the sound of it reconnecting it appears as an uknown usb device in device manager and thus not uploading the sketch successfully and it gives me the error.
I coppied the code from a tutorial I show online, so I dont think that this is the source of the malfunction.
// Testing USB joystick function using Arduino Leonardo
// using MPU6050 as analog x, y and z axis input
// Code written by Pin Chung
// Sep 22, 2020
#include <Joystick.h>
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
Joystick_ Joystick;
#define ResetPin 13
#define Joystick1Pin 9
int lastButtonState=0;
int currentButtonState;
float zeroX=0;
float zeroY=0;
float zeroZ=0;
//upper and lower limit on the angle of the MPU6050 board range.
int upperLimit = 45;
int lowerLimit = -45;
void setup() {
pinMode(Joystick1Pin, INPUT_PULLUP);
pinMode(ResetPin, INPUT_PULLUP);
Serial.begin(9600);
Joystick.begin();
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(false); //This is is not a necessary call. works fine without it.
}
void ResetMPU6050(float x, float y, float z){
//Center the Joystick at current position
zeroX=x;
zeroY=y;
zeroZ=z;
}
void loop()
{
mpu6050.update();
float x=mpu6050.getAngleX();
float y=mpu6050.getAngleY();
float z=mpu6050.getAngleZ();
if (!digitalRead(ResetPin)) {
ResetMPU6050(x,y,z);
}
currentButtonState=!digitalRead(Joystick1Pin);
if (currentButtonState != lastButtonState){
Joystick.setButton(0, currentButtonState);
// 0 is joystick button #1 in Windows 10
lastButtonState=currentButtonState;
}
x-=zeroX;
y-=zeroY;
z-=zeroZ;
if (x>upperLimit) x=upperLimit;
else if (x<lowerLimit) x=lowerLimit;
if (y>upperLimit) y=upperLimit;
else if (y<lowerLimit) y=lowerLimit;
if (z>upperLimit) z=upperLimit;
else if (z<lowerLimit) z=lowerLimit;
// Map the angles of x, y and z to joystick position 0 to 1024
// to reverse the axis, switch the last 2 numbers in the map() function
Joystick.setXAxis(map(x, lowerLimit,upperLimit, 0,1024));
Joystick.setYAxis(map(y, lowerLimit,upperLimit, 1024, 0));
Joystick.setZAxis(map(z, lowerLimit,upperLimit, 1024,0));
}
The standard Leonardo's COM port on my system was 20. After uploading your sketch in IDE 2.0 it changed to COM32 (Windows device manager) which was not picked up by the IDE.
I closed the IDE and tried IDE 1.8.5 and it it showed COM32; upload of your sketch succeeded.
After that I closed IDE 1.8.5 and opened IDE 2.0; now COM32 was available and upload of your sketch succeeded.
After that, I toggled between uploading your sketch and another one and the only thing that changed was the COM port (COM20 to COM32 to COM20 etc); the IDE 2.0 followed Windows device manager.
After that I loaded an innocent sketch, rebooted my PC, started the proces again but this time the IDE did pick up COM32 immediately after uploading your sketch; it's happily following what Windows device manager sees. So I can no longer reproduce the issue
I have a vague recall of a bug report; maybe @ptillisch's memory is better.
Hi @zankostas. I'm going to ask you to post some additional information that might help us to identify the problem.
NOTE: These instructions will not solve the problem. They are only intended to gather more information which might provide a clue that eventually leads to a solution.
Please do this:
Select File > Preferences from the Arduino IDE menus.
Check the box next to "Show verbose output during: ☐ compilation".
Click the OK button.
Select Sketch > Verify/Compile from the Arduino IDE menus.
Wait for the compilation to finish.
Right click on the black "Output" panel at the bottom of the Arduino IDE window.
From the context menu, click Copy All.
Open a forum reply here by clicking the Reply button.
Click the </> icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Press Ctrl+V.
This will paste the compilation output into the code block.
Move the cursor outside of the code tags before you add any additional text to your reply.
Click the Reply button to post the output.
In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:
Open a forum reply here by clicking the Reply button.
Click the "Upload" icon () on the post composer toolbar:
Select the .txt file you saved.
Click the Open button.
Click the Reply button to publish the post.
Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.
As soon as you asked what version of IDE I was using, I downloaded IDE 1.8.5 and it worked like a charm. I didnt bother switching again to IDE 2, cause my job was done.
Thank you guys for your help and your quick response!