BMP390 Integration Guide¶
The BMP390 barometric pressure sensor is architected for but not required.
The packet reserves bytes 202–209 (two float32 fields: pressure hPa, altitude m).
The host parser reads them, the recorder stores them, and the feature extractor
ignores them (not part of the 328-dim vector). The firmware writes 0.0 until
the sensor is fitted.
What to do when the BMP390 arrives¶
1. Write a driver module¶
Create firmware/stm32f405/src/bmp390_driver.c and .h:
// bmp390_driver.h
#pragma once
#include <stdbool.h>
bool bmp390_init(void); // I2C init + calibration load
void bmp390_read(float *pressure, float *altitude); // read both in one call
Implement using the Bosch BMP3xx sensor API or register-level reads over I2C. Connect the BMP390 to one of the STM32 I²C buses (I2C1 or I2C2, any free Qwiic port) or add it to the KB2040's I2C bus. Address is typically 0x76 or 0x77 (selectable by the SDO pin).
2. Wire one pair of put_f32 calls¶
In packet_builder.c, replace the two zero writes:
// packet_builder.c — current (placeholder)
put_f32(pkt, PKT_OFF_BMP_PRESSURE, 0.0f);
put_f32(pkt, PKT_OFF_BMP_ALTITUDE, 0.0f);
// packet_builder.c — after BMP390 integration
float pressure, altitude;
bmp390_read(&pressure, &altitude);
put_f32(pkt, PKT_OFF_BMP_PRESSURE, pressure);
put_f32(pkt, PKT_OFF_BMP_ALTITUDE, altitude);
3. Call bmp390_init() from main.c¶
// main.c — setup()
bmp390_init(); // after analog_task_init()
4. No protocol change needed¶
The packet layout, CRC, and all offsets remain identical. The host code already parses bytes 202–209. The HDF5 recorder already stores them.
5. Optional: add BMP390 to the feature vector¶
The current 328-dim feature vector does NOT use BMP390 data. To add it,
modify:
- host/protocol.py: append BMP390 feature names to EXTRACTED_FEATURE_NAMES
- host/feature_extraction.py: add BMP390-derived features (mean pressure, std pressure, etc.) to the extractor output
- Update EXPECTED_FEATURE_DIM accordingly
- Retrain the model
This is optional — altitude change may not be discriminative for the 11 construction-worker activities.