Using the REPL interpreter to debug a MicroPython Script

When you write a script in main.py, you often want to use the print() function or maybe want to see python errors that you would normally seen in the interpreter. How can we do this? It’s actually quite easy!

1. Add some code

1. Add this to the top of your script:


import time

time.sleep(10)

Save your code and wait for the red light to go off.

2. Reset your board

Press the RST button to reset your MicroPython board.

3. Restart REPL

Quickly relaunch the REPL window.

Hint: I often find I have to reset the MicroPython board twice in order to get this working.

Your REPL should now be a blank screen (see below) and your program will execute as normal, printing out whatever you ask to the REPL window and printing out errors.

 

prinitng