Circuitpython "interactive" option

733 Views Asked by At

I'm trying to debug a circuitpython program (that's running on a microcontroller) and I would like to know if there's a simple way to get the program to drop into the REPL upon a crash/termination while preserving the variables and functions defined in the script.

If this was a regular python program I would simply run it with the "interactive" option of the interpreter set : python -i my_code.py and then have access the variables and function defined in my code for easy debugging.

Instead what I get right now is: after a crash I get prompted to press a key to enter the REPL but the memory is cleared from any trace of my previously running code.

1

There are 1 best solutions below

2
On

A somewhat cumbersome way to achive an equivalent behaviour, that only works if the code terminates and doesn't crash, is to proceed as follows :

  1. Upload the code

  2. Code will start running automatically

  3. Interupt the code with a keyboard interupt

  4. Press a key to get to the REPL

  5. Import all from the code from the REPL by typing in:

    from code import *
    
  6. Wait for the code to terminate

  7. Finally debug

  8. Rince and repeat for each bug you find...