Page 1 of 1

esp8266 UART error

Posted: Thu Nov 26, 2020 3:14 pm
by rave
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?

Re: esp8266 UART error

Posted: Fri Nov 27, 2020 1:19 am
by jimmo
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?

Re: esp8266 UART error

Posted: Fri Nov 27, 2020 7:16 am
by Roberthh
@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.

Re: esp8266 UART error

Posted: Fri Nov 27, 2020 8:13 am
by rave
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                                                                                                                             

Re: esp8266 UART error

Posted: Fri Nov 27, 2020 8:14 am
by rave
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?

Re: esp8266 UART error

Posted: Fri Nov 27, 2020 8:59 am
by Roberthh
UART0 is fix assigned to the pins denoted as TX and RX. So do not have and cannot assign pins to it.

Re: esp8266 UART error

Posted: Fri Nov 27, 2020 9:31 am
by rave
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 🤷🏻‍♂️

Re: esp8266 UART error

Posted: Fri Nov 27, 2020 10:10 am
by Roberthh
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

Re: esp8266 UART error

Posted: Sun Nov 29, 2020 7:14 am
by rave
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                                                                                                                                          
 

Re: esp8266 UART error

Posted: Sun Nov 29, 2020 7:42 am
by Roberthh
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.