Looking inside the mind of a running MicroPython program

The text in red is just the REPL code in ThONNY getting upset…

I love typing in interactive commands to the MicroPython REPL console. It makes development much easier as I can test out program constructions and even view the contents of variables after I have interrupted the code. But the problem is that I lose the REPL console when the program starts running. MindReader fixes that. It lets you type in Python statements which will be executed as your program is running.

To use it you add the MindReader class to your program. Then make an instance of the class (I called it m) and call m.update() in your program at regular intervals. The update method scans the serial port and builds up a command. When you press return it executes the command. This means that you can still type in REPL commands when your code is running, which is neat. You can enter print statements to view variables or even modify them for testing. I’ve found it very useful. You can find the code on GitHub here.