Introduction
This guide will help you read barometric pressure from your PiicoDev® Pressure Sensor and a Raspberry Pi Pico
To follow along, it's best to have:
- A Raspberry Pi Pico with pins soldered (pointing down)
- A PiicoDev Pressure Sensor MS5637
- A PiicoDev Expansion Board for Raspberry Pi Pico
- A PiicoDev Cable
- (Optional) A PiicoDev platform helps secure everything together.
If you prefer not to use the Expansion Board for Raspberry Pi Pico, there are other connection options in our PiicoDev Connection Guide.
Contents
Connect the PiicoDev sensor to your Pico
Plug your Pico into the Expansion Board, connect your pressure sensor to the Expansion Board via the PiicoDev cable, and finally connect your Pico to your computer with a USB lead.
If you're unfamiliar with connecting PiicoDev modules, read the PiicoDev Connection Guide before proceeding.
Download MicroPython modules
We will need three files to easily read data from the Distance Sensor:
- Download the PiicoDev Unified Library: PiicoDev_Unified.py (right-click, "save link as").
- Download the device module: PiicoDev_MS5637.py (right-click, "save link as")
- Download the example script: main.py (right-click, "save link as")
It will be best to keep these files wherever you like to keep your coding projects eg. Documents > PiicoDev
Example Code
We'll be working in Thonny - if you're unfamiliar working with Thonny see our guide for Thonny and Raspberry Pi Pico.
Open Thonny, connect to your Pico and upload the three files (that we just downloaded) to your Pico. (Hint: View the files menu with View > Files)
Restart your Pico (Keyboard shortcut, Ctrl+D) and you should be seeing your Pico printing barometric pressure measurements in hectopascal, which is equivalent to millibar - a commonly used unit for describing barometric pressure: 1hPa = 100Pa = 1mbar.
Above: Pressure data streams up the Shell, while the Plot shows historic data.
Remix
Did you know you can also infer altitude from air pressure? Comment out the pressure print statement and uncomment the altitude print statement. Run the script again and now the Pico will infer altitude-above-sea-level from air pressure. There can be a bit of error here since your local weather conditions will affect the reading. You can optionally pass in the local air pressure at sea level to the read_altitude() function to correct for weather effects. You can find the current air pressure at sea level for your area with an internet search.
Conclusion
We can now measure air pressure from our PiicoDev Pressure Sensor, and use it to infer altitude.
If you make something cool with this starter project we'd love for you to share it on our forums! And if you'd like some help with this guide, start the conversation below - We're full-time makers and here to help!