-->
Page 1 of 1

Reading serial data with MicroPython

PostPosted: Wed Mar 15, 2017 12:09 pm
by DR4
I'm a complete beginner with firmware programming, and electronics in general, so I apologize if the information I provide is lacking.

I have an ESP8266 running MicroPython.

I'm trying to read serial data from another source. I have confirmed that this source is sending data, by
connecting it to my computer and opening its serial port. It sends a bit of data every minute.

I want to be able to read this data, and send it somewhere else. I've found out how to do the sending part. It's the reading part I struggle with.

I don't know if this is neccessary information, but when connecting the data source to my computer, I used a little USB thingy, and plugged the source into RXD and GND on that. The cable that went into GND now goes into GND on the ESP, and the cable that went into RXD goes to GPIO13.

By defining a callback function and running the following code...

Code: Select allpin = machine.Pin(13, machine.Pin.IN)
pin.irq(trigger=pin.IRQ_FALLING, handler=callback)


... I can see that there is indeed something happening every minute. The callback function is called (many times) - every minute. So I guess my ESP receives the data.

But how do I read it? I'm told to use the UART class (https://docs.micropython.org/en/latest/esp8266/libr
ary/machine.UART.html) for that.

I tried to initialize an instance like this:

Code: Select alluart = machine.UART(1, 9600) # (Trying with 0 instead of 1 freezes the REPL.)
uart.init(9600, bits=8, parity=None, stop=1)


And then I've randomly called the various read-functions on that object. They all give me "OSError: UART(1) can't read". Could this be related to the actual data I'm receiving?

Any input appreciated!

Re: Reading serial data with MicroPython

PostPosted: Sun Mar 19, 2017 10:24 pm
by SlowBro
I'm a n00b as well, but try to initialize UART 0 instead of 1.

Edit: Nevermind, you already did that. Well I'm stumped.

Re: Reading serial data with MicroPython

PostPosted: Tue May 23, 2017 12:42 pm
by craftyguy
uart1 is write-only, you cannot read from it.

Also, repl operates over uart0, so you cannot both interact with a device over uart0 and use repl at the same time.