So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By DR4
#63735 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!