Thursday, June 25, 2020

Install ESP32/ESP8266 to Arduino IDE on Ubuntu 20.04, with setup Pythton & serial

After install JDK (OpenJDK) and Arduino IDE on Ubuntu 20.04, you can add support of ESP32 (or ESP8266).

May be you will be with Python 2 related error of:
exec: "python": executable file not found in $PATH
ModuleNotFoundError: No module named 'serial'

In 20.04 LTS, the python included in the base system is Python 3.8. Python 2.7 has been moved to universe and is not included by default in any new installs. (referene: Ubuntu 20.04 LTS (Focal Fossa) release notes)

Here show how to fix it:


First, install board to Boards Manager:

Menu > File> Preferences
Enter the url in the "Additional Board Manager URLs":
https://dl.espressif.com/dl/package_esp32_index.json (for ESP32)
http://arduino.esp8266.com/stable/package_esp8266com_index.json (for ESP8266)

To enter more than one URL, separate it with a comma.

Menu > Tools > Board > Boards Manager…
Search and install ESP32 (or ESP8266)

When you build your code for ESP32/ESP8266, if you report with error of :
exec: "python": executable file not found in $PATH

It's because Python 2 is not installed on Ubuntu 20.04. You can create a symlinks /usr/bin/python to python3 by installing python-is-python3.

$ sudo apt install python-is-python3

Optionally, you can prevent Python 2 from being installed as a dependency of something in the future:

$ sudo apt-mark hold python2 python2-minimal python2.7 python2.7-minimal libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib

Then you may be report with error:
ModuleNotFoundError: No module named 'serial'

Because pyserial is not installed in Python 3 by default. Install with pip:

$ sudo apt install python3-pip
$ pip3 install pyserial

Additionally, if you cannot download your code to board caused by:
avrdude: ser_open(): can't open device "/dev/xxx": Permission denied

Add permission to your user:

$ sudo usermod -a -G dialout <username>
$ sudo chmod a+rw /dev/xxx


Next:
ESP32-DevKitC + 2.8inch 240x320 SPI TFT (ILI9341) using TFT_eSPI library
ESP32 + 1.3 inch 240x240 IPS LCD (ST7789 SPI interface), using TFT_eSPI library
NodeMCU (ESP8266) + 1.44" 128x128 TFT with ST7735 SPI driver (KMR1441_SPI V2), using ssd1306 library

5 comments:

  1. I was having trouble compiling esp32 on ubuntu with an error.
    I searched for various nets and arrived here.
    Thanks to that, I was able to eliminate the error.

    from Japan

    ReplyDelete
  2. Hi Eric,
    I get the same import error even after installing the pyserial module. I cant run the sudo apt install python-is-python3 command since that will also uninstall oracle virtual Box. It will we very kind of you resolve this issue and please let me know is there any way.

    ReplyDelete
  3. in my case it works if execute pip3 install pyserial as super user:
    sudo su

    ReplyDelete
  4. in my case works if enter in mode super user:
    sudo su
    # pip3 install pySerial

    ReplyDelete
  5. Unfortunately, python-is-python3 caused Python 2.7 to be uninstalled, along with packages that I need which depend on Python 2.7.

    I instead installed python3-serial and made a symbolic link in the ~/.arduino15 folder so that esptool.py finds it:

    ln -s /usr/lib/python3/dist-packages/serial $HOME/.arduino15/packages/esp32/tools/esptool_py/3.1.0/

    ReplyDelete