[Solved] Pysense - Light sensor shows zero after cycling through deep sleep



  • I am running 1.7.6.b1 on LoPy on a Pysense board and I have confirmed that almost all the sensors work normally and continue to work after the Pysense has been through a Deep Sleep cycle.
    However, the light sensor only works when first powered up.
    If the Pysense is put to sleep, when it wakes the board resets, runs the code but the light sensor always shows 0 for all sleep cycles after the first.

    Here is some test code that shows the effect:

    # Test script running on LoPy release 1.7.6.b1 attached to Pysense board
    from machine import Pin
    from pysense import Pysense     #Basic Pysense board settings
    from LTR329ALS01 import LTR329ALS01 #light meter
    import utime
    # escape button
    button=Pin('P14')
    
    # Set up the sensors
    BD   = Pysense()
    lightsensor= LTR329ALS01(pysense=BD)
    
    # Record some light measurements
    if button():  #Pysense button normally high - this is not pressed during the test
    	with open('/flash/mylog.log',mode='a') as f:
    		while 1:
    			# Main loop
    			(Light,dummy)= lightsensor.lux()
    			utime.sleep(1)
    			f.write(' LIGHT SENSOR '+str(Light)+'\r\n')    
    			utime.sleep(1)
    			
    			f.close()
    			BD.setup_sleep(5)# sleep in seconds 
    			BD.go_to_sleep()
    			#utime.sleep(5)
    pass
    

    The resulting Log file shows a line for each cycle:
    LIGHT SENSOR 32
    LIGHT SENSOR 0
    LIGHT SENSOR 0
    LIGHT SENSOR 0
    LIGHT SENSOR 0
    LIGHT SENSOR 0
    LIGHT SENSOR 0

    Any ideas how to reset/remove/recover the light sensor ?



  • @markN I have now solved this. The light sensor seems to have an internal buffer that is keeping an old value. Placing a dummy read of the light sensor at the beginning of the code flushes out the old value (which is 0 if the Pysense has gone through a deep sleep cycle).



Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.