esp8266 UART error

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
rave
Posts: 5
Joined: Thu Nov 26, 2020 3:10 pm

esp8266 UART error

Post by rave » Thu Nov 26, 2020 3:14 pm

Hi,

I'm trying to test https://github.com/chrisb2/micropython-fingerprint on my esp8266 and following the instructions, I fail to init the software UART:

Code: Select all

from pyfingerprint import PyFingerprint
from machine import UART
sensorSerial = UART(1)
sensorSerial.init(57600, bits=8, parity=None, stop=1, rx=13, tx=12)
The result of the last line:

Code: Select all

>>> sensorSerial.init(57600, bits=8, parity=None, stop=1, rx=13, tx=12)                                                                                    
Traceback (most recent call last):                                                                                                                    
  File "<stdin>", line 1, in <module>                                                                                                                 
ValueError: expecting a pin      
I tried Pin(14) and '14' and can't seem to get the init to work. Any clue?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: esp8266 UART error

Post by jimmo » Fri Nov 27, 2020 1:19 am

rave wrote:
Thu Nov 26, 2020 3:14 pm
I fail to init the software UART:
FWIW, this is not a "software" UART (there's no soft UARTs in MicroPython), and there's only one full hardware UART on the ESP8266 (which is also used for the REPL).
rave wrote:
Thu Nov 26, 2020 3:14 pm
ValueError: expecting a pin
The tx and rx kwargs need to be machine.Pin instances, not integers. But you said you tried that -- did you get a different error?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: esp8266 UART error

Post by Roberthh » Fri Nov 27, 2020 7:16 am

@rave The lib you are trying to use is made for ESP32. Lacking a second UART, it will not work this way on a ESP8266. Using webrepl for the micropython prompt, you couls use UART0 for that purpose.

rave
Posts: 5
Joined: Thu Nov 26, 2020 3:10 pm

Re: esp8266 UART error

Post by rave » Fri Nov 27, 2020 8:13 am

FWIW, this is not a "software" UART (there's no soft UARTs in MicroPython), and there's only one full hardware UART on the ESP8266 (which is also used for the REPL).
That's disappointing :)
If this is the case, why do I need to declare the pins? Isn't it board depandant?
The tx and rx kwargs need to be machine.Pin instances, not integers. But you said you tried that -- did you get a different error?
This is the error I get:

Code: Select all

>>> sensorSerial.init(57600, bits=8, parity=None, stop=1, rx=machine.Pin(15))
Traceback (most recent call last):                                                                                                                    
  File "<stdin>", line 1, in <module>                                                                                                                 
ValueError: invalid tx/rx                                                                                                                             

rave
Posts: 5
Joined: Thu Nov 26, 2020 3:10 pm

Re: esp8266 UART error

Post by rave » Fri Nov 27, 2020 8:14 am

Roberthh wrote:
Fri Nov 27, 2020 7:16 am
@rave The lib you are trying to use is made for ESP32. Lacking a second UART, it will not work this way on a ESP8266. Using webrepl for the micropython prompt, you couls use UART0 for that purpose.
And how do I do use UART0? Just emit the pins?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: esp8266 UART error

Post by Roberthh » Fri Nov 27, 2020 8:59 am

UART0 is fix assigned to the pins denoted as TX and RX. So do not have and cannot assign pins to it.

rave
Posts: 5
Joined: Thu Nov 26, 2020 3:10 pm

Re: esp8266 UART error

Post by rave » Fri Nov 27, 2020 9:31 am

Roberthh wrote:
Fri Nov 27, 2020 8:59 am
UART0 is fix assigned to the pins denoted as TX and RX. So do not have and cannot assign pins to it.
It’s seems to mess up with webrepl and hangs after the call to the sensor.
Sadly, reverting back to non-python, with software serial :(
I really wish a serial port emulation is implemented soon. I see a lot of people asking for that 🤷🏻‍♂️

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: esp8266 UART error

Post by Roberthh » Fri Nov 27, 2020 10:10 am

You have to detach REPL on UARFT first, with

import uos
uos.dupterm(None, 1)

See: http://docs.micropython.org/en/latest/e ... ckref.html

rave
Posts: 5
Joined: Thu Nov 26, 2020 3:10 pm

Re: esp8266 UART error

Post by rave » Sun Nov 29, 2020 7:14 am

Roberthh wrote:
Fri Nov 27, 2020 10:10 am
You have to detach REPL on UARFT first, with

import uos
uos.dupterm(None, 1)

See: http://docs.micropython.org/en/latest/e ... ckref.html
Thanks. Tried that as well.
Still seem to hang on the sensor handshake. Moved back to my C code :(

Code: Select all

WebREPL connected                                                                                                                                     
>>> from pyfingerprint import PyFingerprint                                                                                                           
>>>                                                                                                                                                   
>>> from machine import UART                                                                                                                          
>>>                                                                                                                                                   
>>> import uos                                                                                                                                        
>>>                                                                                                                                                   
>>> uos.dupterm(None, 1)                                                                                                                              
UART(0, baudrate=115200, bits=8, parity=None, stop=1, rxbuf=15, timeout=0, timeout_char=1)                                                            
>>>                                                                                                                                                   
>>>                                                                                                                                                   
>>>                                                                                                                                                   
>>> sensorSerial = UART(0)                                                                                                                            
>>>                                                                                                                                                   
>>> sensorSerial.init(57600, bits=8, parity=None, stop=1)                                                                                             
>>>                                                                                                                                                   
>>> f = PyFingerprint(sensorSerial)                                                                                                                   
>>>                                                                                                                                                   
>>> f.verifyPassword()                                                                                                                                
Disconnected                                                                                                                                          
 

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: esp8266 UART error

Post by Roberthh » Sun Nov 29, 2020 7:42 am

You can compine the set-up of the serial port to:

sensorSerial = UART(0, 57600)

All init parameters can be added to the object instantiation. It is ususally hard to tell what happens on a serial link without any kind of monitoring. Simple logic analyzers for about 10 USD do a perfect job there.

Post Reply