espressif/arduino-esp32

No "Serial" Module

samjulien opened this issue ยท 46 comments

Hi there. Windows 8.1 here. Followed the instructions on getting set up and receiving the following when trying to upload a blinking light sketch:

Traceback (most recent call last):

  File "C:\Program Files (x86)\Arduino\hardware\espressif\esp32/tools/esptool.py", line 25, in <module>

    import serial

ImportError: No module named serial

exit status 1
Error compiling for board ESP32 Dev Module.

Any ideas?

P.S. Thanks for working on this port!

Hi I had the same issue, you're missing pyserial. You can install pyserial via pip. Open CMD as Administrator and type: pip install pyserial

I believe that pip is installed by default when installing python, Pip should go and get pyserial and install it in the correct location. Restart Arduino IDE and Build, worked for me.

Ah, excellent, thanks. Now it compiles and gives me:

esptool.py v2.0-dev
Connecting...

A fatal error occurred: Failed to connect to ESP32: Invalid head of packet ('f')

So that's something.

That error seems related to uploading, double check that you are holding down boot button then pressing the reset button and then releasing both, then click upload (arrow button).

Does it compile by clicking the tick (verify) button?

Yes, it compiles with the verify button, and yes, I'm doing the boot-and-reset press and upload. No dice. If I open the serial monitor at 115200 I do see some boot text and info about the wifi starting, so the device is alive. I've got flash frequency at 40MHz and flash speed at 115200, are those right? And does the programmer setting matter? I've got AVRISP mkII selected.

These are the setting that work for me:

esp32

Sorry for the delayed response - thanks for the screenshot. Still getting the same error for some reason. I'll keep tinkering.

Hi @samjulien, did you have any luck getting this to work?

Hi @samjulien, Did you by chance install the Silabs driver? I was able to get my Dev board working, once I go the driver install on Mac. I just finished testing PubSubClient on the ESP32, and it works good.

@MrAPierce - not yet, still not sure what the problem is. I'm just uploading super simple LED blink code with an LED in pin 12 and a resistor to ground.

@sorscode - are these same drivers by Silabs used for the ESP8266? Googling "silabs esp32" took me to the same page of "CP210x USB to UART Bridge VCP Drivers," which I do have installed from working with the 8266.

Once I get this working I'm happy to submit a PR to the readme with anything pertinent. Definitely not just trying to be a pain, hoping to help out the larger community by being a guinea pig. :)

@samjulien That would be the one. Which port do you have selected when uploading? I'm going to build a quick Windows 8.1 VM and test.

Okay, cool, thanks. A buddy of mine pointed out that it's been several months since I installed those drivers for the ESP8266 and perhaps an update to them is in order, so I'll also give that a go and report back.

Hmm, updated the drivers, took away the LED, did the boot mode dance, changed sketch to just empty setup and void loops - still no dice. Same invalid head of packet error. Settings are as you have it above. Weird.

+1 for AnalogLamb, see https://github.com/pyserial/pyserial, or just type pip install pyserial
then restart the Arduino IDE. Fixed it for me.

Yeah, above I had already installed pyserial and was able to compile but got a different error. That was on Windows 8.1. I just got a new laptop with Windows 10 on it and will give this another shot soon.

I too am seeing the serial error "ImportError: No module named serial" in spite of having both python and pyserial. When I opened up a python console on my Terminal and imported serial, that worked fine. Any suggestions?
My guess, is that the Arduino compiler isn't running the right version of Python, it may be using the default version that comes inbuilt with the Mac, but I'm not sure how I could test this theory.

Arduino compile runs the version of python that you have in the path :) so basically starting a shell without running .bash_profile and executing python. Where is your python installed? Why not use the default one (I use it daily and it's totally fine)?

No that was just a theory. Turns out, I am running the inbuilt version of python, but the Arduino compiler still returns an error importing "serial". Importing serial in the terminal works fine. In fact, I printed the command that had failed in the compiler (using the verbose output functionality), and ran it in the terminal, and that executed fine.
So I'm not sure what's going on there.

your PATH variable is different if you run in terminal than what programs trying to execute command see. Usually that is limited to /usr/bin:/usr/sbin:usb/local/bin:/usr/local/sbin
run which python in terminal and see where python is. It might be different than python that might be in one of the locations by default

So which python returns /usr/local/bin, and that's why I think its running the inbuilt version of python.

ok here is an idea :)
prepend which "{compiler.python.cmd}" && to this command and run build. it should print the path it sees right before building the bin

recipe.objcopy.hex.pattern=which "{compiler.python.cmd}" && "{compiler.python.cmd}" "{runtime.platform.path}/tools/esptool.py" --chip esp32 elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"

So that worked! Thanks a lot! Adding the text to platform.txt revealed that the path it was trying to use was at /usr/bin/. However, changing that path in platform.txt seems to throw a genericexit status 1 Error compiling for board ESP32 Dev Module. error. Any suggestions?

do not change the path :)
open terminal and do

sudo mv /usr/bin/python /usr/bin/python_other
sudo ln -s /usr/local/bin/python /usr/bin/python

that will link the correct python to /usr/bin and save the day :)

So both those commands are forbidden. But I get the general idea. I'll try some other things out (like creating an alias, etc.), and see if that works.
Thanks a lot!

I had this same issue on windows with the sparkfun board... I installed pyserial, then got the next issue. Then I went back to holding the reset button while it programmed, and it worked. Thanks guys!

Hi all;

I'm working on a mac with homebrew installed python.

Arduino seems to be ignoring my path - as I choose to use the homebrew python over the system python.

Nevertheless, if I brew unlink python - leaving only the system python, I can:

  • run the system python
  • see that pyserial is not installed
  • install pip (using sudo)
  • install pyserial (using sudo)
  • run the python get.py command
  • compile the sketch.

I don't have my esp32 hooked up right now, but will test it later.

FYI - the above solution works (for homebrewed python macs) I was able to upload sketches and get them working on my esp32 (ESP32 Thing from Sparkfun)

Ideally, the IDE would have recognize my path settings so one can avoid the work around.

Now I want to find/use a CLI-based toolchain to just avoid the Arduino IDE.

@dgdosen if you want to use it without the IDE:

  • Download and install esp-idf
  • Create blank idf project (from one of the examples)
  • in the project folder, create a folder called components
  • git clone this repository inside components as name arduino (git clone https://github.com/espressif/arduino-esp32.git arduino)
  • make menuconfig has some Arduino options (maybe enable arduino autostart)
  • in your main.cpp, include Arduino.h and format it as any other sketch (if autostart is enabled)
  • make flash monitor will build, upload and open serial monitor

I can recommend using platform.io to do ESP32 builds on the command line without an IDE. See http://platformio.org/get-started/cli

@blackketter and how is ESP32 working on platformio?

Well, I haven't dug in deeply but a blink example compiled, downloaded and ran perfectly on my SparkFun ESP32 Thing.

So I figured out a workaround for this problem and got the code to work on a Mac.

  1. Install PySerial using "sudo -H pip install pyserial" in you terminal.

  2. Then get the path of python that you are working on in the terminal using "which python" command. This will give you a path name like below:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

Copy this path.

  1. Open up the platform.txt in the hardware/espressif/esp32 folder.
    Change the value of compiler.python.cmd=python to compiler.python.cmd=/Library/Frameworks/Python.framework/Versions/2.7/bin/python.
    Also change the value of tools.esptool.cmd=python to tools.esptool.cmd=/Library/Frameworks/Python.framework/Versions/2.7/bin/python. This worked just fine for me and code is compiling and uploaded to the esp32 successfully.

this is now all resolved because python is no longer required on Windows

here am working with esp32 and arduino but when i connect my esp32 its not showing me the port can anyone solve this ????

@harshithuchil, did you already solve the issue?
I face similiar Problem with ESP32DevC under win10. I have installed the CP2102 VCP-Driver. But after connecting the board it is not appearing in device Manager as virtual COM-port.

T-vK commented

On Fedora you follow these instructions: https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/fedora.md

And in addition to that, you run pip install pyserial --user. (Not as root!)

For anyone who comes here from a search engine. On Ubuntu 19.04, my version of pip is for Python 3.7, you need to install pip2.

sudo apt install python-pip

Then install pyserial

pip2 install pyserial

Thank you @psiphi75. That was exactly the solution on Ubuntu 19.10 as well.

lviss commented

Thank you @psiphi75. That was exactly the solution on Debian 10 as well.

cyzen commented

Thank you @psiphi75. That was right step to the solution on Ubuntu 20.04 as well.
After i installed pip2 for python2,7
(https://linuxize.com/post/how-to-install-pip-on-ubuntu-20.04/)
i could finally do "pip2 install pyserial"
and ESP32 compiling works at Arduino-IDE 1.8.13 without an error

python2 is past end of life. Move forward to python3 instead of backwards.
espressif/esptool#528 (comment)

to solve this issue just follow these steps

  1. install and update python
    sudo apt-get install python3 python3-pip python3-setuptools

  2. set default python version
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

regards

Issue: import serial module not found :
sudo apt install python-is-python3

for library clash :
sudo pip3 uninstall serial
sudo pip3 install pyserial

worked for me because in my case this error was due to python supported by IDE

on Linux systems just try this sudo apt install python-is -python3

sudo apt install python-serial python3-serial

solved it! :D