Hello!
I want to use my NodeMCU esp8266 board to drive some relays in my PC, and i want it to recieve signals frought uart interface.
I started to learn how i can do this, and find machine.uart method. But i have faced a problem:
esp8266 is starting to recieve UART messages already after 'uart = machine.UART(0, 9600)' command, and it paste it to input line of REPL. How can i force it to recieve the UART signals to variable?
I tried all other commands, uart.init, uart.read, uart.readline - nothing changes.
And i'm sorry, i'm newbie, and maybe i'm understand somthing wrong?
How can i use machine.UART?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How can i use machine.UART?
Using the ESP8266 UART is difficult because the chip has only one fully functional UART which is used for the USB interface.
My preferred solutions are either to use another means of communication or to use a chip with multiple UARTs (ESP32 or Pyboard D). Others have had success with UART 0; perhaps they will advise.
My preferred solutions are either to use another means of communication or to use a chip with multiple UARTs (ESP32 or Pyboard D). Others have had success with UART 0; perhaps they will advise.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: How can i use machine.UART?
If you have the UART assigned to REPL/console, you can use sys.stdout.write() to send and sys.stdin.read(), sys.stdin.readline(), ... to read data from the port, without using machine.UART. If you want to use machine.UART, you have to detach the UARt from the console first, with;
But then you have to use webrepl for the console. Instructions to do so are in the documentation: http://docs.micropython.org/en/latest/e ... ht=webrepl
Code: Select all
import uos
uos.dupterm(None, 1) # disable REPL on UART(0)
Re: How can i use machine.UART?
I'm dont understand that problem. If uart can recieve and sent messages, why cant i use it?pythoncoder wrote: ↑Fri Nov 29, 2019 9:07 amUsing the ESP8266 UART is difficult because the chip has only one fully functional UART which is used for the USB interface.
thanks! Now it works as it supossed to!Roberthh wrote: ↑Fri Nov 29, 2019 9:09 amCode: Select all
import uos uos.dupterm(None, 1) # disable REPL on UART(0)
I'm already use webrepl, as you can see on the screenshot! Thanks again!
Re: How can i use machine.UART?
Thanks for this! I suspected this might be the case, but I couldn't find any confirmation in the MicroPython documentation (including how to disable UART<->USB).Roberthh wrote: ↑Fri Nov 29, 2019 9:09 amIf you have the UART assigned to REPL/console, you can use sys.stdout.write() to send and sys.stdin.read(), sys.stdin.readline(), ... to read data from the port, without using machine.UART. If you want to use machine.UART, you have to detach the UARt from the console first, with;But then you have to use webrepl for the console. Instructions to do so are in the documentation: http://docs.micropython.org/en/latest/e ... ht=webreplCode: Select all
import uos uos.dupterm(None, 1) # disable REPL on UART(0)
I would suggest adding this information to the relevant sections in Quick Reference and UART sections (happy to do this myself if they're editable).
I might also suggest altering boot.py to disable the USB<>UART interface if there's nothing in the receive buffer after n seconds.
Edit: I see the line is already present and commented out in boot.py, which is handy! I hadn't looked at it when I posted because I didn't have any boot settings that I wanted to persist yet.