Two way serial communication

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
joshuachu3
Posts: 4
Joined: Fri Jul 17, 2020 6:10 am

Two way serial communication

Post by joshuachu3 » Fri Aug 21, 2020 8:24 am

Hi, I am trying to input data from my laptop onto the microbit using pyserial, performing some analysis on the data on the microbit, then printing a result into REPL. Is this possible or will there be a clash between the two? Also would it be fast enough, as I need it done in real-time. Thanks

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

Re: Two way serial communication

Post by jimmo » Thu Sep 03, 2020 5:45 am

Yes this is definitely possible. It just means that you can't be simultaneously using the REPL and talking via pyserial at the same time. pyserial will effectively be pretending to operate the REPL.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Two way serial communication

Post by dhylands » Thu Sep 03, 2020 4:37 pm

I put together some examples where json is used to send data back and forth.
https://github.com/dhylands/json-ipc

Note that "realtime" doesn't really mean anything in this context. If you have a device that reports something once per second, and you can display it once per second then you're doing it in realtime. So realtime depends on your particular application (i.e. if the host can consume the data faster than the device can generate it then its running in realtime, otherwise its not).

Just be aware that only one program can have the serial port open at a time, so if your program running pyserial has the serial port open you need to close any terminal programs that are running.

Post Reply