Page 1 of 1

Two way serial communication

Posted: Fri Aug 21, 2020 8:24 am
by joshuachu3
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

Re: Two way serial communication

Posted: Thu Sep 03, 2020 5:45 am
by jimmo
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.

Re: Two way serial communication

Posted: Thu Sep 03, 2020 4:37 pm
by dhylands
I put together some examples where json is used to send data back and forth.

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.