Page 1 of 1

strange datalogging

Posted: Thu May 07, 2020 4:29 pm
by IHOXOHI
Hi,

I have tried to save data from the original tile sensor... And discover in same time the behaviour of pyboard d (I have used pyboard classic yet)...

Maybe I don't understand something, but the exemple of upython site doesn't works for me. I don't know why, but it appears that there is a confusion between "while" boucle(s). The part at the end which normaly isn't read, is reading when I push just one time on button...? and always, finally, the saving file contain nothing.

So, I have write something, very quickly... It works. But it's not perfect. I have to disconnect the pyboard before a sleep time for that data wasen't rewritted. I have used led for help me...

The script writting with upyton's site example (just the part with the boucle):

Code: Select all

while True:
    pyb.wfi()
    if sw.value():
        pyb.delay(200)
        bleu.on()    
        log = open("/sd/liste_lux_temp_hum", "w")  
        while not sw.value():
            hdc.measure()
            while not hdc.is_ready():
                machine.idle()
            temp = round(hdc.temperature(), 2)
            hum = round(hdc.humidity(), 2)
            print(temp, hum)
            rouge.on()
            sleep(1)
            rouge.off()
            opt.measure()
            while not opt.is_ready():
                machine.idle()
            luxi = round(opt.lux(), 2)
            print(luxi)
            vert.on()
            sleep(1)
            vert.off()

            log.write('{},{},{}\n'.format(temp,hum,luxi))
            #sleep(10)
        log.close()
        bleu.off() 
        pyb.delay(200)
My simple code :

Code: Select all

bleu.on()    
log = open("/sd/liste_lux_temp_hum", "w")
bleu.off()
while sw.value() == False:
    hdc.measure()
    while not hdc.is_ready():
        machine.idle()
    temp = round(hdc.temperature(), 2)
    hum = round(hdc.humidity(), 2)
    rouge.on()
    sleep(1)
    rouge.off()
    opt.measure()
    while not opt.is_ready():
        machine.idle()
    luxi = round(opt.lux(), 2)
    print(luxi)
    vert.on()
    sleep(1)
    
    log.write('{},{},{}\n'.format(temp,hum,luxi))
    sleep(10)
    vert.off()

if sw.value() == True:
   bleu.on()
   log.close()
   bleu.off()

sleep(10) 

Have I make a mistake in my use of the example? Is there anybody who uses datalogging exemple correctly?
Is there anybody who has a script which permit to disconnect the pyboard without stress after datalogging session?
Thanks.