UART and REPL Issue

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
pmulvey
Posts: 45
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

UART and REPL Issue

Post by pmulvey » Sat Oct 26, 2019 8:13 pm

I have a Grove MP3 V2 module that connects to the ESP8266 via a serial connection on the TX and RX pins. After a late night and pulling out the last few strands of my hair, the following morning I got to grips with why the ESP8266 was apparently being bricked and not responding to the REPL. The programme was grabbing UART0 that services REPL and not giving it back. I modified the program to take over UART0 at 9600 and when finished sending a command to the MP3 module it hands it back to the REPL at 115200. Happy days.
This is the code:

Code: Select all

def play_folder_track(folder_id, track_id, level):
    uos.dupterm(None, 1)
    uart = UART(0, 9600)
    uart.write(cmd.set_volume(level))
    sleep(.02)  #delay 20 mS to allow 9600 data to be transmitted   
    uart.write(cmd.play_folder_track(folder_id, track_id))
    sleep(.02)  #delay 20 mS to allow 9600 data to be transmitted
    uos.dupterm(UART(0, 115200), 1)
However...
As long as the TX line from the MP3 module is connected to the RX line of the ESP8266 (as it must be) the REPL does not work. It would appear that UART0 does not ignore the RX line even when it is servicing REPL. I am using an analogue switch chip (4016) to isolate the TX and RX lines of the MP3 module. The TX part works fine but I have to do some programming to respond to the data on the RX line. So my query is before I embark on this route is there a simpler solution? I can see that a couple of 4016 chips could provide a ESP board with a switchable serial interface that could prove useful for some projects.
Paul Mulvey

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

Re: UART and REPL Issue

Post by jimmo » Sun Oct 27, 2019 1:43 am

Yeah it will not work having multiple TX lines connected to a single RX on the ESP, as the TX is driven high at idle.

A switch controlled by another GPIO sounds like a good idea.

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

Re: UART and REPL Issue

Post by Roberthh » Sun Oct 27, 2019 8:27 am

You could also make a wired OR with two (schottky) diodes and a pull-up resistor at the ESP8266 RX, as long as you can be sure that both TX are active alternatively. Using analog switches avoids the interference, but requires another GPIO + inverter for controlling.

pmulvey
Posts: 45
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: UART and REPL Issue

Post by pmulvey » Mon Oct 28, 2019 9:37 am

Thanks for that. Given this serial port limitation on the ESP8266 and also the difficulty (I think) in getting IR Tx and RX working under Micropython I was thinking of building another board with Arduino acting as an I2C slave and carrying out these "difficult" functions.
Paul Mulvey

pmulvey
Posts: 45
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: UART and REPL Issue

Post by pmulvey » Mon Oct 28, 2019 10:15 am

Just looking at the D1 Mini, it seems doable to cut the track from the CH340 to the 470 R resistor and insert a schottky diode.
Paul Mulvey

safsound
Posts: 1
Joined: Mon Nov 04, 2019 12:03 pm

Re: UART and REPL Issue

Post by safsound » Mon Nov 04, 2019 12:08 pm

Hello,

I've the same problem to use a YX5300 catalex. when i configure the serial i can dialog with the catalex very well but repl dont work anymore and i cant upload file with ampy. I need to reflash the cart (with D0 and GND wire)

It's possible to use softserial on PIN13 and PIN15 ? i see the pinout schema and this 2 pin seems to be RX2 and TX2

My idea is keep RX0/TX0 to debug, transfert file etc .. and RX2/DX2 to pilot the yx5300

Thanks

pmulvey
Posts: 45
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: UART and REPL Issue

Post by pmulvey » Mon Nov 04, 2019 5:15 pm

I have an arduino connected to the esp8266 via I2C. I have a simple command processor running on the arduino. I am sending commands to it and getting responses. The mp3 module is connected to the arduino and I am sending requests from the esp8266 to play clips specifying the track and folder number. I also send requests to query when the track is finished so that the next one can be played. I have some wrinkle in the code that causes the arduino to ignore requests after about 4 successful ones, but I'm hopeful of finding the problem.
Paul Mulvey

Post Reply