Arduino Leonardo is disconnecting from pc in a few seconds
I moved your topic to an appropriate forum category @runols.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
Hi @runols. Please post the full sketch that is running on the Leonardo.
I'll provide instructions you can follow to do that if using Arduino IDE 2.x:
- Select Tools > Auto Format from the Arduino IDE menus.
ⓘ This is done to make the code easier for us to read. - Select Edit > Copy for Forum (Markdown) from the Arduino IDE menus.
- In a forum reply here, click on the post composer field.
- Press the Ctrl+V keyboard shortcut.
This will paste the sketch to the post composer. - Move the cursor outside of the code block markup before you add any additional text to your reply.
- Repeat the above process if your sketch has multiple tabs.
- Click the "Reply" button to post your reply.
When your code requires a library that's not included with the Arduino IDE please post a link to where you downloaded that library from, or if you installed it using Library Manager (Sketch > Include Library > Manage Libraries... in Arduino IDE) then say so and state the full name of the library.
Please complete Your post according to How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum
No offence but Your post is way out of line lacking all nceessary information.
I actually have practised crystal ball reading and tell: It's really difficult and for Your question, no way I'm trying.
Since my Arduino has not been connected to the computer for a week, I continued my projects using another Arduino, so unfortunately I do not know what the code in it is.
Are you able to upload your new project code to the Leonardo?
If yes, does the problem of the Leonardo disconnecting still occur after uploading the new project code?
The problem is that, after a few seconds of connecting the Arduino to the computer, the connection is interrupted and a USB disconnection sound is heard. However, until the connection is interrupted (for example, 5-6 seconds), the Arduino ide sees the Arduino, but this period does not allow me to upload new code. After that, what I said is The connection is cut off like.
The tricky thing about the boards with native USB capability like your Leonardo is the USB code that creates the CDC serial port is running on the same microcontroller as your sketch. This means your sketch code can break the USB code, or stop it from running. When that happens, the board no longer produces a serial port.
This can be unexpected to those who previously mainly worked with the boards like Uno and Mega with a dedicated USB chip that can never be affected by the sketch code.
As you noticed, the missing port makes it so you can't upload normally any more. However, the situation is really not so bad because there is an independent program called the bootloader in a separate section of memory from your sketch, and that program has its own USB CDC code. So even if the sketch is completely broken, you only need to activate the bootloader to get a port back and be able to upload.
You need to get the timing right. If you press the reset button too early, the bootloader will have already timed out by the time the upload starts. The tricky thing is that when you press the "Upload" button in Arduino IDE, it first compiles your sketch before starting the actual upload. So you need to wait until after the compilation finishes before pressing the reset button.
Try this:
- Select Sketch > Upload from the Arduino IDE menus.
- Watch the black "Output" panel at the bottom of the Arduino IDE window until you see something like this:
Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes. Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
- Immediately press and release the reset button on the Arduino board.
The upload should now finish successfully.
If you find that the disconnection still occurs even after you have uploaded your latest project code to the board, then we can guess that there is a problem in the code. You can verify this by uploading a simple sketch like the one from File > Examples > 01.Basics > BareMinimum in the Arduino IDE menus. If the board no longer has the disconnect problemafter uploading that sketch, but not after uploading your full project sketch, then you will know the issue is caused by something in the project sketch code. If so, we can take a look at your code and see if we can spot the cause of the disconection.
appreciate for support , problem is solved , my arduino is working now
I have one more question
how can I fix that
It doesn't cause me any problems, but I wanted to ask because it appeared as a warning.
The red color of the upload output text might give the impression that it indicates an error, but it is not so in this case. The output you posted is what we would expect from a successful upload. As long as you see a "Done uploading." notification in Arduino IDE at the end of the upload operation, all is well and you can disregard the color of the upload output text:
Arduino IDE uses a tool named AVRDUDE to upload sketches to your Arduino board.
The AVRDUDE developers made the decision to print even output that is not related to an error condition to the "standard error" (AKA "stderr") stream instead of the more common practice of printing it on the "standard output" (AKA "stdout") stream.
Each boards platform may use any arbitrary external tool to perform an upload, so Arduino IDE doesn't have any understanding of the contents of the output from the upload tool. The IDE only knows which of the streams the upload tool printed the output to. Because the stderr stream is usually used for errors or warnings, Arduino IDE colors all output received on that stream red. Likewise, the output received on the stdout stream is colored white since that stream is usually used for purely informational output.
When you have the Show verbose output during: ☐ upload enabled in your Arduino IDE preferences, this particularly cryptic output is in the context of a bunch of other more easily interpretable output, which makes it a bit easier to understand why it is printed. But for some reason the AVRDUDE developers decided that these specific messages were so important that they should be printed by the tool even when it was not configured in the verbose mode. Maybe the information is meaningful in other use cases, but for Arduino users it is not very interesting.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.