Not able to upload program to esp01?

I am currently trying to upload a sketch/program to my esp01, from my mac, but are having issue with its port being busy?

Not sure why?

raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 16] could not open port /dev/cu.usbserial-1420: [Errno 16] Resource busy: '/dev/cu.usbserial-1420'

I tried to locate the application that makes it busy, but i seem to be unable to locate it it.

I have tried

$ fuser /dev/cu.usbserial-1420

/dev/cu.usbserial-1420:

$ lsof /dev/cu.usbserial-1420

nothing seem to pop up? why though?

I’ve seen cases where two drivers are installed for the USB-to-serial chip (probably a CH340 in your case). The device then appears under two names: one is working, the other one isn’t.

What other serial devices can you see?

To display them, run:

ls -l /dev/cu.*
1 Like

It returns this

crw-rw-rw- 1 root wheel 18, 5 21 Jun 08:45 /dev/cu.Bluetooth-Incoming-Port
crw-rw-rw- 1 root wheel 18, 1 21 Jun 08:45 /dev/cu.TestiPhone-Wirel
crw-rw-rw- 1 root wheel 18, 9 21 Jun 08:45 /dev/cu.NXT-DevB
crw-rw-rw- 1 root wheel 18, 3 21 Jun 08:45 /dev/cu.nuvi3906452112-COM5
crw-rw-rw- 1 root wheel 18, 7 21 Jun 08:45 /dev/cu.nuvi3906452112-COM6
crw-rw-rw- 1 root wheel 18, 41 7 Sep 18:55 /dev/cu.usbserial-1420
crw-rw-rw- 1 root wheel 18, 39 7 Sep 18:55 /dev/cu.wchusbserial1420

Have you tried setting upload_port = /dev/cu.wchusbserial* in the platformio.ini?

That worked…

I am just getting timeouts?

Processing esp01_1m (platform: espressif8266; board: esp01_1m; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/esp01_1m.html
PLATFORM: Espressif 8266 (2.6.2) > Espressif Generic ESP8266 ESP-01 1M
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 3.20704.0 (2.7.4) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - tool-mklittlefs 1.203.200522 (2.3) 
 - tool-mkspiffs 1.200.0 (2.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 29 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio/build/esp01_1m/firmware.elf
Checking size .pio/build/esp01_1m/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [===       ]  32.7% (used 26816 bytes from 81920 bytes)
Flash: [===       ]  33.8% (used 257328 bytes from 761840 bytes)
Configuring upload protocol...
AVAILABLE: espota, esptool
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: /dev/cu.wchusbserial1420
Uploading .pio/build/esp01_1m/firmware.bin
esptool.py v2.8
Serial port /dev/cu.wchusbserial1420
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
*** [upload] Error 2
===================================================== [FAILED] Took 14.34 seconds =====================================================
The terminal process "platformio 'run', '--target', 'upload'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Either the serial is also non-functioning and the other should be used (with some additional fix?) or there is a problem with the physical connection to the ESP01.

Have you made sure it’s in bootloader mode (GPIO0 to GND and reset)? How did you connect everything with respect to power, UART and reset?

You can sanity check the UART connection by using a terminal program to open the serial at 74880 baud and reset the ESP01 in bootloader mode. Then, some text shoud appear.

its basically this which consist of the connection https://ardustore.dk/wp-content/uploads/2018/05/esp8266-programmer.jpg

i would assume the adapter ensured this?

So you have two drivers installed for the WCH CH340 chip. I recommend uninstalling the one from WCH (old kernel mode driver) in favour of the one from Apple (new user mode driver):

  • Unplug your devices with a CH340 chip
  • Execute sudo kextunload /System/Extensions/usbserial.kext/
  • Execute sudo rm -rf /System/Extensions/usbserial.kext/

If you are running macOS Catalina, your Mac has probably already complained about this driver on each restart. As far as I know, they no longer work in the upcoming macOS Big Sur.

As for the timeout: It usually helps to reduce the upload speed:

upload_speed = 460800

Or:

upload_speed = 230400

If it doesn’t help, check the wires. Do you use a dedicated USB-to-Serial adapter? If so, TX and RX could be swapped (or rather not). The correct setup is to connect adapter RX to ESP TX, and adapter TX to ESP RX.

your first command returned an error and did not delete the other usbserial, and setting the sped does not change