4

I've been trying to flash esp-wroom-32 for a long time, but I can't seem to get it. idf.py throws this error:

Serial port /dev/ttyUSB0
A fatal error occurred: Could not open /dev/ttyUSB0, the port doesn't exist
CMake Error at run_serial_tool.cmake:55 (message):
  /home/matvey/.espressif/python_env/idf5.1_py3.9_env/bin/python;;/home/matvey/esp/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32
  failed
FAILED: CMakeFiles/flash /home/matvey/esp/esp-idf/examples/get-started/hello_world/build/CMakeFiles/flash
cd /home/matvey/esp/esp-idf/components/esptool_py && /usr/bin/cmake -D IDF_PATH=/home/matvey/esp/esp-idf -D "SERIAL_TOOL=/home/matvey/.espressif/python_env /idf5.1_py3.9_env/bin/python;;/home/matvey/esp/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32" -D "SERIAL_TOOL_ARGS=--before=default_reset; --after=hard_reset;write_flash;@flash_args" -D WORKING_DIRECTORY=/home/matvey/esp/esp-idf/examples/get-started/hello_world/build -P /home/matvey/esp/esp-idf/components/ esptool_py/run_serial_tool.cmake
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the /home/matvey/esp/esp-idf/examples/get-started/hello_world/build/log/idf_py_stderr_output_27303 and /home/matvey/esp/esp-idf/ examples/get-started/hello_world/build/log/idf_py_stdout_output_27303`

I have no idea what could be the problem, I changed the udev settings, but maybe it did not work for me.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
  • The error message seems very clear. Your device is not located at `/dev/ttyUSB0`. What command line are you entering? Are you forcing a specific port? Usually the tool will search to find it. You might `ls /dev/ttyUSB*` to see what devices there are. – Tim Roberts Oct 02 '22 at 04:13
  • @TimRoberts The command I entered: "idf.py -p /dev/ttyUSB0 flash". "ls /dev/ttyUSB*" output "/dev/ttyUSB0". Also entering the command "idf_monitor.py" showed an error: "OSError: [Errno 16] Device or resource busy: '/dev/ttyUSB0'". – Матвей павлов Oct 02 '22 at 04:51
  • arduino ide sees the port and shows it as /dev/ttyUSB0 – Матвей павлов Oct 02 '22 at 05:14
  • 1
    Serial ports are one-user-at-a-time. If the IDE has the port open, you can't open it from your script. – Tim Roberts Oct 02 '22 at 18:15
  • Are you able to download a simple Arduino based program to your ESP32 over /dev/ttyUSB0 using your Arduino IDE? – lurker Oct 03 '22 at 23:19

2 Answers2

20

add yourself to dialout and change permissions on it

$ sudo adduser <username> dialout
$ sudo chmod a+rw /dev/ttyUSB0

It worked for me

Cosme Urdaibay
  • 301
  • 2
  • 5
  • 1
    If the user is added to the correct group, why would we need to add global read/write? – Tim Feb 08 '23 at 03:12
  • I believe it has to do with the file that represents the device. Although it worked for me, I found out each time the device is plugged I've to change the file mod. Probably there's a better way to do it. In no way I'm an expert I'm sharing what I found out worked for me. Good luck and happy coding. – Cosme Urdaibay Mar 22 '23 at 03:51
  • 3
    for arch-based distros it would be: usermod -a -G uucp – Julian Zatloukal May 15 '23 at 15:34
1

Another thing can happen that the modem file name will be changed from /dev/ttyUSB0 to /dev/ttyUSB1 instead. So check the /dev directory for alternatives.

There is a very nice script in this answer: https://raspberrypi.stackexchange.com/a/132175/152061

zubko
  • 1,718
  • 25
  • 28