Barometer
The Barometer
class in MMFS provides an abstract base for all barometric pressure sensors, extending the functionality of the core Sensor
interface. It not only standardizes access to pressure data, but also computes altitude from that data, enabling derived classes to easily support telemetry and flight logic.
Overview
Barometers convert pressure readings into meaningful altitude data using standard atmospheric models. The Barometer
base class handles this transformation internally, so implementing a new sensor requires only providing raw pressure and temperature values via read()
.
Inheritance Structure
Barometer
inherits from Sensor
and implements many of the required pieces:
begin()
→ Callsinit()
and handles sensor startup, including zeroing pressure to define "ground level"update()
→ Callsread()
and populates altitude, pressure, and temperature values
The only two methods you must implement in a derived class is:
read()
is intended to read the physical hardware data using the library you've found or written to talk to the sensor and update Barometer's internal variables.
init()
is designed to use said library to initialize the sensor and write and config options that you need to set to it.
Neither of these methods are intended to any kind of complex math or variable transformation, with the potential exception of unit conversions. Anything more complex should already be handeld by Baromter's update()
or begin()
. Just double check that this abstract class doesn't already do the calculations that you're looking for before you write redundnat code.
Exposed Data Columns
Barometer
automatically registers the following telemetry columns:
- Altitude (
alt
) – computed from pressure - Pressure (
press
) – hPa - Temperature (
temp
) – °C
These values are exposed via the inherited DataReporter
API and will appear in logs and live telemetry.
How Altitude is Calculated
The barometer uses the hypsometric formula to convert pressure to altitude, assuming standard atmosphere:
Where basePressure_hPa
is the pressure reading at ground level. This is automatically captured during begin()
.
Usage Flow
To implement a new barometer driver, follow these steps:
-
Choose a sensor library
-
Prefer stable and maintained libraries (e.g., Adafruit, SparkFun)
-
Wrap it in a new class derived from
Barometer
- If you're using MMFSSystem, then that's it. Pass an instance of your new barometer to State, and the software will take care of the rest. If you're not using MMFSSystem, you should call
myBaro.begin()
insetup()
andmyBaro.update()
inloop()
, at whatever frequency you find works best.
Available Built-in Drivers
The following sensors are currently supported in MMFS:
- BMP280 - Datasheet (NRND)
- BMP390 - Datasheet
- DPS310/DPS368 - Datasheet (DPS310 is NRND) and Datasheet
- MS5611 - Datasheet
Each of these classes derives from Barometer
and implements the required read()
and init()
methods.
Advanced Options
Using Bias Correction Mode
Bias correction mode helps compensate for slow pressure drift and sensor noise by continuously recalibrating the zero-altitude baseline — essentially adjusting what the barometer considers "ground level." This is especially useful when the vehicle stays on the pad for a long time before launch, or when ambient pressure changes slightly.
However, it’s off by default because blindly recalibrating can be dangerous — especially if the rocket has already left the ground. See the MMFSSystem docs for more on the risks and defaults.
When enabled, the barometer periodically computes a new baseline using the second-to-last second of recent pressure data — not the most recent second. Why? Because launch detection systems typically rely on altitude changes to identify liftoff. Including very recent data (which may already show movement) would confuse this logic and result in a bad zero point. Using the "2nd-to-last" second instead gives you a quieter, more accurate reference without interfering with launch detection.
You can enable or disable this feature at any time using:
And you should lock in the baseline permanently at liftoff by calling:
This disables further corrections and locks the AGL altitude reference point in place.
Accessing Raw Data
The following methods are available for reading the latest values:
Above Ground Level is either denoted as alt difference since boot up, or, if you are using bias Correction, difference since bias correction was disabled.
Summary
Barometer
simplifies pressure → altitude conversion using standard math- Hardware implementations must only define a
read()
method begin()
auto-calibrates base pressure andupdate()
calls your driver- Output is integrated with the MMFS logging/telemetry stack via
DataReporter
- Easy to extend using any existing Arduino/C++ pressure sensor library
Note
The Barometer
class is meant for atmospheric sensors. Do not use it for water pressure sensors or sealed altimeters without modifying the pressure-to-altitude logic.
Written by ChatGPT. May not be fully accurate; verify against source.