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:

AddressIndexSDO pin
0x5D0high
0x5C1low

chipset PressureSensorChipset PRESSURE_SENSOR_CHIPSET_LPS25

The chipset variant on the board. All constants are available as global variables in p5.js sketches:

ConstantChip
PRESSURE_SENSOR_CHIPSET_LPS25LPS25HB (default)
PRESSURE_SENSOR_CHIPSET_LPS22LPS22HB

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):

ConstantLPS25LPS22
PRESSURE_SENSOR_DATA_RATE_ONE_SHOTone-shotone-shot
PRESSURE_SENSOR_DATA_RATE_1_HZ1 Hz1 Hz
PRESSURE_SENSOR_DATA_RATE_7_HZ7 Hz~10 Hz
PRESSURE_SENSOR_DATA_RATE_10_HZ~12.5 Hz10 Hz
PRESSURE_SENSOR_DATA_RATE_12_5_HZ12.5 Hz~10 Hz
PRESSURE_SENSOR_DATA_RATE_25_HZ25 Hz (default)25 Hz (default)
PRESSURE_SENSOR_DATA_RATE_50_HZ~25 Hz50 Hz
PRESSURE_SENSOR_DATA_RATE_75_HZ~25 Hz75 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.