Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4869

MicroPython • Re: Logging temp to SD card, missing data

$
0
0
Missing data...Again. Ran the dryer for 40 minutes with a full load and only wound up with 3 minutes of useless data. The Pico might be resetting. It's running from a reliable phone charger. The same code logged 33 minutes of data last time (the graph), so I dunno. This is the code I'll run next time. It uses a new filename on each restart.

Code:

import machineimport onewireimport sdcardimport ds18x20import timeimport uosled = machine.Pin(25, machine.Pin.OUT)# Assign chip select (CS) pin (and start it high)cs = machine.Pin(9, machine.Pin.OUT)# Intialize SPI peripheral (start with 1 MHz)spi = machine.SPI(1,                  baudrate=1000000,                  polarity=0,                  phase=0,                  bits=8,                  firstbit=machine.SPI.MSB,                  sck=machine.Pin(10),                  mosi=machine.Pin(11),                  miso=machine.Pin(8))# Initialize SD cardsd = sdcard.SDCard(spi, cs)# Mount filesystemvfs = uos.VfsFat(sd)uos.mount(vfs, "/sd")i = 1x = ""while i < 100:    x = "test"    if i < 10:        x = x + "0"    x = x + str(i)    x = x + ".txt"    if not x in uos.listdir("/sd"):        break    i = i + 1    if i == 100:    x = "over99.txt"f = open("/sd/" + x, "w")    ds_pin = machine.Pin(22)ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))roms = ds_sensor.scan()t = 0while True:    i = 0    while i < 10:        i = i + 1        ds_sensor.convert_temp()        led.off()        time.sleep_ms(750)        led.on()        f.write("%02d:%02d:%02d" % time.localtime()[3:6])        for rom in roms:            tempC = ds_sensor.read_temp(rom)            tempF = tempC * (9/5) +32            f.write("\t%0.1f" % tempF)            time.sleep_ms(200)        f.write("\n")        t = t + 1    f.flush()

Statistics: Posted by Mike**K — Thu Dec 05, 2024 2:26 pm



Viewing all articles
Browse latest Browse all 4869

Trending Articles