Software saveboot using P14 on Pytrack/Pysense



  • Quite often (depending on my code ) I had problems uploading code, accessing the REPL or connecting to the board. I found myself a solution using the Button on Pytrack/Pysense when starting up the divice after a reset. Instead of the main.py an altenative main.py ( main_save.py in my case) will be loaded. Here is my boot.py code. Mybe someone find it useful:

    from machine import Timer
    from machine import Pin
    from machine import main
    import pycom
    
    pycom.heartbeat(False)
    
    chrono = Timer.Chrono()
    chrono.start()
    
    i=True
    saveboot=False
    
    ##Timeout for pressing the button
    waitForSavebootTimeout=3
    
    ###Waiting for the buttonn to be pressed:  Green LED 
    pycom.rgbled(0x005500)  
    
    while i==True:
        if (Pin('P14').value()==0):
            saveboot=True
        lap = chrono.read()
        if lap>waitForSavebootTimeout  or    saveboot:
            i=False
    
    if   saveboot:
        ###entering save boot main_save.py will be loaded: Blue LED 
        pycom.rgbled(0x000055)  
        main("main_save.py")
    
    if   not saveboot:
        ###entering normal boot main.py will be loaded: Red LED 
        pycom.rgbled(0x550000)  
    
    


Pycom on Twitter