Score:7

Ubuntu 20.04 - can't upload Arduino's sketch

cn flag

After a fresh install of Ubuntu, I tried to upload sketch using Arduino IDE v1.8.16 (installed using a .deb file downloaded from web).

An error occurred while uploading the sketch avrdude: ser_open(): can't open device "/dev/ttyACM0": Device or resource busy

After a first install of Arduino IDE on a new Linux machine need to be a member of : sudo usermod -a -G dialout $USER and logoff, logon ,which didn't change as expected.

So I tried to chmod of connected port /dev/ttyUSB0, which didn't change the error message ( by the way, also on USB1, and ACM0 I got the same output- when trying to upload to Nano).

Now I get this error:

esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
Traceback (most recent call last):
  File "/home/guy/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/upload.py", line 66, in <module>
    esptool.main(cmdline)
  File "/home/guy/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 3552, in main
    esp.connect(args.before, args.connect_attempts)
  File "/home/guy/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 529, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

To verify it is not an IDE error, I tried using esptool.py to erase flash, and I got the same behaviour Connecting........_____....._____....._____....._____....._____....._____....._____

David avatar
cn flag
An error regarding Serial port is known Do you mean there is a known error or are you referring to the error you received?
guyd avatar
cn flag
@David perhaps a not optimal explanation, try this: After a new installation of ubuntu ( or first time using Arduino IDE on a PC, there is a need to add user to the `dialout` group
David avatar
cn flag
Very different from what the question says. Maybe edit the question.
guyd avatar
cn flag
question edited as mentioned
N0rbert avatar
zw flag
Nano seems to be Arduino. While esptool is used for Espressif ESP8266 and/or ESP32. Please clarify the used hardware MCU model.
Eric Duminil avatar
us flag
The bug now seems to be fixed (e.g. in "5.4.0-91-generic")
Score:7
ru flag

this happens to the latest ubuntu with the latest kernel and several versions of arduino-ide ( from snap, from apt install, even with the latest version installed from arduino's website ) tried several board version's tried modded esptool tried not-modded esptool tried several (not charge only) cables tries several esp32 boards and esp32 vendors ( wemos, nodemcu, etc. )

I believe that there might be a problem with the serial driver? All boards are working great on windows with all versions of arduino-ide tested on Ubuntu 20.04, and same cables. I ruled out any possible problem in regards to : software (ide), cables, boards.

will dig more into this.

LE: Found the issue! Looks like there is a bug in the kernel driver for ch340/ch341 I had one old kernel installed ( 5.9.x ) and with this one works. That took me to some search over the internet :) so here it is

      Bug ID: 214131
     Summary: ch341 communication problem
     Product: Drivers
     Version: 2.5

Kernel Version: 5.14-rc5 Hardware: All OS: Linux Tree: Mainline Status: NEW Severity: normal Priority: P1 Component: USB

It looks to me that starting kernel 5.10.x till 5.14-rc5 the bug is present.

Happy coding guys

er flag
So from what I understand, there's no end user solution here but to wait for an update? This is troublesome but strangely enough, my Arduino Nano running on CH340 runs just fine. Only the ESP boards experience the problem.
fr flag
Seems to have fixed itself after recent kernel patch for me, before that booting into 5.3.0-64 worked as a temporary fix.
ISparkes avatar
ru flag
I have held back the kernel which works until an update comes https://askubuntu.com/questions/938494/how-to-i-prevent-ubuntu-from-kernel-version-upgrade-and-notification
Score:4
in flag

Workaround for ESP boards:

Settings prior to uploading the sketch:

  • Boardtype: Generic ESP8266
  • Flash size: 4MB
  • Reset method: "dtr (aka nodemcu)" (default)

Then:

  1. Change reset method to: "no dtr (aka ck)" (Tools -> Reset Method)
  2. Then press Flash button
  3. Press Reset shortly
  4. Then release Flash
  5. Upload sketch in the Arduino IDE

Arduino

Source: https://forum.manjaro.org/t/manjaro-21-1-0-und-esp8266-sketch-upload-doesnt-work-anymore/79712/2

Note: Tested on ESP8266 (NodeMCU)

Update:

This issue has been fixed in the latest kernel version. Please update the kernel and test again.

guyd avatar
cn flag
I tried it already as it seemed like ESP32 or pro micro waiting for that reset ( not successfully though)
DevTomek avatar
in flag
@Guy.D I successfully tested on ESP8266 (NodeMCU)
Eric Duminil avatar
us flag
I cannot find "Tools -> Reset Method". Is it in Arduino IDE, next to Board/Upload Speed/Debug Port/...?
DevTomek avatar
in flag
@EricDuminil You have to select correct board e.g. 'Generic ESP8266 Module'
Eric Duminil avatar
us flag
@DevTomek: Thanks. I downgraded my kernel, but it's good to know that other temporary fixes are available.
guyd avatar
cn flag
how do i update kernel only ?
Score:3
mn flag

with kernel linux-image-5.4.0-87-generic @ ubuntu 18.04 I have exactly the same problem (running latest arduino, board definitions and libz), when I reboot to 5.4.0-86-generic it works again, dunno why, but spent like hour today finding out what changed (bcs I use arduino for a long time on this computer and always everything worked smoothly...)

So try to boot older kernel, maybe it helps

Eric Duminil avatar
us flag
I can confirm this works fine with "5.4.0-86-generic", on Ubuntu 18.04 and Linux Mint 19.3. This issue was really hard to track down, amid all the "RTFM, Noobie" answers telling people to press buttons, change permissions, add users to groups or use DIP switches. "5.4.0-87", "5.4.0-88" and "5.4.0-89" all have this bug. Let's hope the next version won't.
Eric Duminil avatar
us flag
"5.4.0-91-generic" is now working fine, and I can upload again to ESP8266 with the current kernel.
Score:0
us flag

Thank you, the workaround works for me!!

5.4.0-89-generic #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

VID: 1A86 PID: 7523

Someone avatar
my flag
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.