Pressure Sensor
The Adafruit LPS25 is a barometric pressure and temperature sensor. It supports two chipset variants (LPS22 and LPS25) with configurable output data rates. See the Adafruit learn guide for wiring and hardware details.
Connection
Call startPressureSensor() inside preload(). The device is ready to use by the time setup() runs.
let sensor;
function preload() {
sensor = startPressureSensor(name?, addressOrIndex?, chipset?);
}name string | false | null "pressure"
Controls automatic event callback registration. With the default name:
function pressureChanged(event) { /* new reading */ }Pass false or null to disable and use addEventListener instead.
addressOrIndex number 0x5D
The I2C address of the device, or an index (0–1) into the address list. Set by the SDO pin:
| Address | Index | SDO pin |
|---|---|---|
| 0x5D | 0 | high |
| 0x5C | 1 | low |
chipset PressureSensorChipset PRESSURE_SENSOR_CHIPSET_LPS25
The chipset variant on the board. All constants are available as global variables in p5.js sketches:
| Constant | Chip |
|---|---|
| PRESSURE_SENSOR_CHIPSET_LPS25 | LPS25HB (default) |
| PRESSURE_SENSOR_CHIPSET_LPS22 | LPS22HB |
Methods
getDataRate() PressureSensorDataRate
Returns the current output data rate enum value.
getPressure() number
Returns the last measured pressure in hPa.
getTemperature() number
Returns the last measured temperature in °C.
setDataRate(value) Promise<boolean>
Sets the output data rate. Unsupported rates on a given chipset are mapped to the nearest available rate. Available constants (all global in p5.js sketches):
| Constant | LPS25 | LPS22 |
|---|---|---|
| PRESSURE_SENSOR_DATA_RATE_ONE_SHOT | one-shot | one-shot |
| PRESSURE_SENSOR_DATA_RATE_1_HZ | 1 Hz | 1 Hz |
| PRESSURE_SENSOR_DATA_RATE_7_HZ | 7 Hz | ~10 Hz |
| PRESSURE_SENSOR_DATA_RATE_10_HZ | ~12.5 Hz | 10 Hz |
| PRESSURE_SENSOR_DATA_RATE_12_5_HZ | 12.5 Hz | ~10 Hz |
| PRESSURE_SENSOR_DATA_RATE_25_HZ | 25 Hz (default) | 25 Hz (default) |
| PRESSURE_SENSOR_DATA_RATE_50_HZ | ~25 Hz | 50 Hz |
| PRESSURE_SENSOR_DATA_RATE_75_HZ | ~25 Hz | 75 Hz |
Methods (BaseDevice)
connect() Promise<Response>
Opens the USB connection and sends the start command to the firmware. Calling it multiple times is safe — subsequent calls return the same promise. In p5.js you do not need to call this manually; startXxx() calls it for you inside preload().
Properties
Properties (BaseDevice)
id { type, address }
Identifies the device. type is the DeviceType enum value, address is the I2C address the device was started with.
isConnected boolean
true once the USB connection has been established and the firmware has acknowledged the device. In p5.js this is always true by the time setup() runs, because startXxx() waits for the connection inside preload().
Events
changed(event) changed
Fires on every sensor poll with updated pressure and temperature readings.
Event Argument
All event callbacks receive a single event argument. The event detail is available at event.detail and contains:
event.detail.pressure number — Barometric pressure in hPa.
event.detail.temperature number — Temperature in °C.