how to identify a board is connected to a deepsleep shield



  • I have several LoPy and LoPy4 boards.
    Usually I connect LoPy to a deepsleep shield, but not always.
    If I use the following code, I will always invoke the deepsleep library's go_to_sleep method to a LoPy, even if it is not connected to a deepsleep shield. The board will not wake from deepsleep in this case.
    Some deepsleep methods raise exceptions when called if there is no deepsleep shield attached (e.g. get_wake_status) however go_to_sleep does not.

    does anyone know how to check if a board is connected to a deepsleep shield before choosing how to put it into deepsleep?

    def sleep_to_next_time(sleep_time=interval):
        t=uos.uname()
        if t[0] == 'LoPy':
            ds = deepsleep.DeepSleep()
            ds.go_to_sleep(sleep_time/1000)
        else:
            machine.deepsleep(sleep_time)
    

    Some deepsleep methods raise exceptions when called e.g. get_wake_status however go_to_sleep does not.



  • thanks for the response @jcaron. Unfortunately all the methods you suggest only work on the expansion board types, not the deepsleep shield.
    The only way I can see to do this is to use an exception handler. Not very pythonic, but it does work.

    import deepsleep
    ds = deepsleep.DeepSleep()
    
    try:
        ds.get_wake_status()
        shield = True
    except:
        shield = False
    print(shield)
    


  • @philwilkinson read_hw_version, read_fw_version and read_product_id would probably be good starting points.



Pycom on Twitter