Electronic Barometer using Raspberry Pi Pico

This PCB has two I2C bus connections for PiicoDev etc. One bus is currently used. It also connects to an SD card reader, along with a PiicoDev device that reads pressure, temperature and humidity, and it has an RTC clock (coin cell free). Download modified utilities. SD card driver. Go to PiicoDev site.

Data file charset extractor fonts:

datafile charset extractor font7x12sx
datafile charset extractor font8x12sx
datafile charset extractor font10x18sx
datafile charset extractor font12x16sx

The electronic barometer can run from a phone charger, 5V supply or 4 NiMH rechargeable batteries. The PCB has a place for a power socket, along with a Schottky diode; there is also a place for a jumper shunt to bypass the diode, if higher efficiency is needed. The Schottky diode protects against accidental reversal of power supply voltage.

Building this device can be used for teaching at high school or undergraduate university. If the code provided is used and modified, the bigger part of the project could be containing the hardware. Students could design 3D print jobs to house the Pico and the PiicoDev components, presenting the OLED screen to the user on the outside. Typically Fusion 360 or Solid Works etc. could be used for these design tasks. Companies like JLCPCB can do 3D print jobs using higher melting point plastics, such as nylon, if you do not have a printer.

However, there could be a programming component to set up communication via Wifi with the user. The unit could present a web page that draws a graph of the captured data or a web socket program could be designed were the Pico unit uploads its data to a server at regular times. The software could also present interactive graphs of the environmental data.

Though this board is designed for the barometer project, it is a very adaptable board and it could be connected to whatever I2C or serial devices are preferred. A modified board will be available soon where all of the spare pins are connected to a double header array of pins. This will allow a greater variety of project applications.

The PCB sells for $10 plus postage and including commission.

==================================================
# main.py
# barometer_main.py
==================================================
from machine import Pin, I2C, ADC
import time
from micropython import const
from PiicoDev_RV3028 import PiicoDev_RV3028
from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_SSD1306 import *
import sdcard
import uos
import gfx

p0 = Pin(0)
p1 = Pin(1)
p25 = machine.Pin(25, machine.Pin.OUT)
p25.value(0)
rtc = PiicoDev_RV3028(0, None, p0, p1)
sensor = PiicoDev_BME280(0, None, p0, p1)
display = create_PiicoDev_SSD1306(0x3C, 0, None, p0, p1, None)
oledg = gfx.GFX(128, 64, display.pixel)
adcpin = machine.Pin(29, machine.Pin.IN)
adc = machine.ADC(4)
vpin = machine.ADC(3)

MISO = const(12)
MOSI = const(11)
SCK = const(10)
CS = const(19)

# 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(SCK),
                  mosi=machine.Pin(MOSI),
                  miso=machine.Pin(MISO))

# Initialize SD card
sd = sdcard.SDCard(spi, Pin(CS))

# Mount filesystem
vfs = uos.VfsFat(sd)
uos.mount(vfs, "/sd")

settime = False
if settime:
    rtc.day = 27
    rtc.month = 3
    rtc.year = 2025
    rtc.hour = 23
    rtc.minute = 22
    rtc.second = 00
    rtc.ampm = '24' # 'AM','PM' or '24'. Defaults to 24-hr time
    rtc.weekday = 4 # Rolls over at midnight, works independently of the calendar date
    rtc.setDateTime() # Sets the time with the above values

rtc.getDateTime()
secs = rtc.second
minutes = rtc.minute
hours = rtc.hour
day = rtc.day
month = rtc.month
year = rtc.year
print("Start ", hours, minutes, secs, day, month, year)

display.fill(0) # empty the frame buffer
for xx in range(6):
    oledg.ellipse(20+17*xx, 15, 15, 7, 1)
oledg.printstring16(13,30,"Microtron", 1)
display.show()
time.sleep_ms(2000)

count = 0
printedcount = 0
conversion_factor = 3.3 / (1 << 12)

while(1):
    # Get the current time
    rtc.getDateTime()
    printedcount += 1
    if count == 0 or (rtc.second == 0 and rtc.minute % 30 == 0 and printedcount > 5):
        printedcount = 0
        print(count, rtc.timestamp())        
        secs = rtc.second
        minutes = rtc.minute
        hours = rtc.hour
        day = rtc.day
        month = rtc.month
        year = rtc.year
        print(hours, minutes, secs, day, month, year)
        count += 1
        
        ADC_voltage = adc.read_u16() * (3.3 / (65536))
        temperature_celcius = 27 - (ADC_voltage - 0.706)/0.001721
        temp_fahrenheit=32+(1.8*temperature_celcius)
        
        p25.value(1) # needed for Pico W - potentially interrupts Wifi.
        adc_reading = vpin.read_u16()
        p25.value(0)
        adc_voltage  = (adc_reading * 3.3) / 65535
        vsys_voltage = adc_voltage * 3
        
        tempC, pres_Pa, humRH = sensor.values() # read all data from the sensor
        print("T:{0:.1f}C, P:{1:.1f}mbar, Hum:{2:.1f}%RH".format(tempC, pres_Pa/100, humRH))
        print("Temperature chip: {0:.1f}°C, VSYS voltage:{1:.1f}".
              format(temperature_celcius, vsys_voltage))
        
        display.fill(0)
        display.text("T:{0:.1f}C".format(tempC),10,10, 1)
        display.text("P:{0:.1f}mbar".format(pres_Pa/100),10,30, 1)
        display.text("Hum:{0:.1f}%RH".format(humRH),10,50, 1)
        display.show()
        
        with open("/sd/barom01.csv",'a') as f:
            f.write(rtc.timestamp() + ", ")
            f.write("T:,{0:.1f},°C, P:,{1:.1f},mbar, Hum:,{2:.1f},%RH, ".
                    format(tempC, pres_Pa/100, humRH))
            f.write("Temperature chip:,{0:.1f},°C, ".format(temperature_celcius))
            f.write("VSYS voltage:,{0:.1f}\n".format(vsys_voltage))        
    time.sleep_ms(500)
=======================================================

Barometer Data

Download barometer csv data file and excel file

Assembly of barometer

  • Drill a hole in the lid for the I2C cable to the screen and drill holes to fix the screen board (CE: SSD1306) to the lid. M2.5 white nylon threaded spacers can be used, if preferred (CE: ADA3658).
  • Plug clock (CE: RV-3028) into Bus0, plug barometer chip (CE: BME280) into clock and using the long connector, plug the screen (CE: SSD1306) into the clock.
  • Use a chisel and block of wood, to cut a rectangular hole for the SD card reader (Jaycar: XC4386).
  • Drill breather holes in the side walls to prevent heat the device from warming the barometer sensor.
  • Use threaded spacers to mount the main PCB (3mm holes), the clock and the barometer sensor inside the box.
  • Collect the python files above on your computer and open them with Thonny. Save them to the RPi Pico, after installing Micropython, except for “main.py”.
  • Open main.py from the computer and run it from there. You may see error messages, such as for missing python classes/files etc. Fix the problems. Set the date in main.py and change “settime” to True. Run the program and then change “settime” to False again. If the device is powered down for more than two weeks, you will need to repeat this step. Check the contents of the SD card and if good, then copy main.py to the Pico.
  • The program named “main.py” should run, even if the Pico is powered by a phone charger. The barometer readings should appear on the screen and one set should appear on the SD card every time the device is started, and every half hour after that.
  • Provision of barometer kit-sets is underway. There is interest from parents with children that have an interest in gadgets. It is recommended that parents participate in this project.
  • The Jiffy-box provided can be superseded by a detailed box made using Fusion 360 or Solid Works and 3D printing. I like to use black nylon provided by JLCPCB. This is more advanced, but there may be a way to design the detailed box using AI (maybe Grok).