Showing posts with label Data Logger. Show all posts
Showing posts with label Data Logger. Show all posts

Monday, February 6, 2023

Raspberry Pico Project Data Logger

Raspberry Pi Pico demo project data logger.

Battery power for Raspberry Pico , battery 18650 shield BME280 temperature and pressure sensor and start button You need BME280 library in MicroPython Thonny IDE.

Code:

from machine import Pin, I2C 
import time
import BME280 

# PICO - Pins
sda=machine.Pin(16)
scl=machine.Pin(17)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

led1 = Pin(25, Pin.OUT)
button_start = Pin(2, Pin.IN, Pin.PULL_DOWN) # Start button

# Data logging time in seconds
LOGt = 600 
 
# Data logging interval in seconds 
LOGi = 10

i=0

while button_start.value() == 0:
    led1.value(0) # Board led off 
else:
    tpfile=open("TempPres.txt","w")  # w Opens a file for writing only and will create a new file       

    while i < (LOGt/LOGi):
         led1.value(1) # Board led on          
         bme = BME280.BME280(i2c=i2c)
         temp = bme.temperature
  ##     hum = bme.humidity  No humidity in BMP280
         pres = bme.pressure
  ##   tempf temperature in Fahrenheit
  ##     tempf = (bme.read_temperature()/100) * (9/5) + 32
  ##     tempf = str(round(tempf, 2)) + 'F'
  ##     print('Temperature:', temp ,tempf, '  Pressure: ',pres)  
  ##     print('Humidity: ', hum)
     
         tpfile.write(str(temp + ' , ' + pres) + "\n")
         tpfile.flush()
  
         time.sleep(LOGi)
         i += 1
              
         led1.value(0) # Board led off
  




Thonny shell use for open the file file=open("TempPres.txt") print (file.read())

Pinouts for the project: