Debian Arduino - AttributeError: 'Serial' object has no attribute 'dtr'

psilospiral
Posts: 2
Joined: Fri Feb 12, 2021 2:22 am

Debian Arduino - AttributeError: 'Serial' object has no attribute 'dtr'

Postby psilospiral » Fri Feb 12, 2021 2:39 am

Greetings Forum:

I have compiled and uploaded a simple led blink sketch with Arduino on Win10 without issue. I am now attempting to do the same on Debian 10.

I am running Arduino 1.8.13. On my 1st attempt in Debian to upload the same sketch to the same ESP32-WROOM-32D, I received:

Code: Select all

Traceback (most recent call last):
  File "/home/martin/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py", line 37, in <module>
    import serial
ImportError: No module named serial
exit status 1
Error compiling for board DOIT ESP32 DEVKIT V1.
My python version is 2.7.16, so I downloaded pyserial for python 2.7, ran

Code: Select all

python setup.py build
sudo python setup.py install
And no longer received the import serial error.

But now I am receiving a new error:

Code: Select all

Arduino: 1.8.13 (Linux), Board: "DOIT ESP32 DEVKIT V1, 80MHz, 921600, None"

Sketch uses 207705 bytes (15%) of program storage space. Maximum is 1310720 bytes.
Global variables use 15228 bytes (4%) of dynamic memory, leaving 312452 bytes for local variables. Maximum is 327680 bytes.
esptool.py v2.6
Traceback (most recent call last):
Serial port /dev/ttyUSB0
Connecting...
  File "/home/me/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py", line 2959, in <module>
    _main()
  File "/home/me/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py", line 2952, in _main
    main()
  File "/home/me/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py", line 2653, in main
    esp.connect(args.before)
  File "/home/me/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py", line 460, in connect
    last_error = self._connect_attempt(mode=mode, esp32r0_delay=False)
  File "/home/me/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py", line 419, in _connect_attempt
    self._setRTS(True)   # EN=LOW, chip in reset
  File "/home/me/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py", line 391, in _setRTS
    self._port.setDTR(self._port.dtr)
AttributeError: 'Serial' object has no attribute 'dtr'
AttributeError: 'Serial' object has no attribute 'dtr'
Does anybody have any idea on my issue?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Debian Arduino - AttributeError: 'Serial' object has no attribute 'dtr'

Postby ESP_Angus » Fri Feb 12, 2021 3:11 am

Hi psilospiral,

Very old version of pyserial (before 3.0 I think) don't have the 'dtr' property and are missing some other API features.

Note that the pyserial version and the python version are different, it's just a coincidence that the numbers are similar. Pyserial up to the current version 3.5 can run on Python 2 - so would recommend installing that version if you can.

Angus

EDIT: I realised even pyserial v3.5 hasn't dropped Python 2 support yet!

psilospiral
Posts: 2
Joined: Fri Feb 12, 2021 2:22 am

Re: Debian Arduino - AttributeError: 'Serial' object has no attribute 'dtr'

Postby psilospiral » Fri Feb 12, 2021 4:27 pm

Angus:

Thank you for your reply. I found a similar issue post over on esp8266.com forum where a user simply commented out the line

Code: Select all

self._port.setDTR(self._port.dtr)
within esptool.py, which solved his compile time error. I made a .bak copy and tried the same. It also worked for me, but I really wanted to know why the original code would not work as intended. Your reply explains why.

Being new to python, I was unaware pyserial 3.5 would run on a python 2.7 system. I followed your advice, installed pyserial 3.5, removed the comment in esptool.py, and my code compiled without error!

Thank you for your help in identifying the root cause. I'm sure others will benefit from this post in the future.

Who is online

Users browsing this forum: No registered users and 58 guests