strange datalogging

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

strange datalogging

Post by IHOXOHI » Thu May 07, 2020 4:29 pm

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.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: strange datalogging

Post by IHOXOHI » Wed Sep 09, 2020 9:55 pm

Yop,

I have found, alone.
It was too easy, I think.

So, at each loop open the file with 'a' option, write, and close it.

It doesn't preserve sd card but datas are continiously saved.

Finally, I prefer a little bit of stress and preserve my sd card.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: strange datalogging

Post by davef » Thu Oct 15, 2020 5:44 am

Make a 'ramdisk' then every day save the file to SD.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: strange datalogging

Post by IHOXOHI » Tue Oct 20, 2020 3:22 pm

YES.
Certainly the best way for datalogging.
It' need just a count...
Thanks.

Post Reply