[Solved] Moving from Win10 to Ubuntu: upload failing

I am in the process of moving from a Windows10 based PC to a Ubuntu 22.04 LTS one. Installing MS VSC and PlatformIO was successful, now I wanted to build and upload a simple blink sketch to a NodeMCU Amica (ESP8266). This is failing with

Configuring upload protocol...
AVAILABLE: espota, esptool
CURRENT: upload_protocol = esptool
Looking for upload port...
Using manually specified: /dev/ttyUSB0
Uploading .pio/build/nodemcuv2/firmware.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
*** [upload] Error 2

The platformio.ini is simplest:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
upload_port = /dev/ttyUSB0

The upload_port was added by me as attempt to get it working.
lsusb is showing the NodeMCU:

$ lsusb
Bus 001 Device 005: ID 10c4:ea60 Silicon Labs CP210x UART Bridge

What am I missing?

On Ubuntu, and Mint etc, you need to be sure that your user is in the appropriate groups.

What do you get when you login as the affected user, and in a terminal session, type:

groups

You need to be sure that this user is a member of the group which owns the /dev/ttyUSB0 special file. On my Linux Mint (based on Ubuntu) system, I see this:

ls -l /dev/ttyUSB0
crw-rw-rw- 1 root dialout 188, 0 Jan  8 15:45 /dev/ttyUSB0

The “dialout” group owns the device, so I need to be a member of this group:

groups
norman adm dialout cdrom sudo dip plugdev lpadmin sambashare docker

And I see that I am, so I can upload with no problems.

To add your user to the group:

sudo usermod --append --groups dialout $USER

You need to logout of the terminal session and then log back in, or you can simpky:

su - $USER

To start a new shell which will pick up the new group. Saves logging out and back in. Exit twice to fully logout when you are done.

If you started VSCode before adding yourself to dialout then you will need to exit and restart VSCode to pick up the new dialout group privileges.

HTH

Cheers,
Norm.

Thanks, Norm! In fact my user is member of the dialout group for other reasons already, thus I am getting

$ groups
micha adm tty dialout cdrom sudo dip plugdev lpadmin lxd sambashare

I am afraid my problem seems to be caused by something different.

Ok, that’s a shame.

I remember when I upgraded Linux Mint, there was a problem uploading. This was due to a screen reader utility , brltty, which took over the port and prevented uploads. Try this in the terminal:

dmesg --follow | grep -i brltty

Then connect your board and attempt an upload.

If you see “brltty” mentioned in the output from dmesg then you need to:

sudo apt remove brltty

The application is useful for visually impaired folks, but grabs the ttyUSB0 port and prevents Arduino/PlatformIO uploads to that port.

If this isn’t the case, I’m afraid I’m currently out of ideas!

Cheers,
Norm.

1 Like

Attempted to follow your advice - but there is no more /dev/ttyUSB0 now, so PlatformIO is not able to determine a port. WTF? I had another device plugged in (a DMM) before, so maybe that tricked me into believing I saw the ESP.
So I tried a different USB cable…
What can I say? It now is working. :blush:

Thanks for your help!

Ah! The old “power only, no data” USB cables. They should be destroyed immediately! :wink:

Cheers,
Norm.