Gyroscope
The Adafruit LSM6DSOX is a 6-DoF IMU combining a 3-axis accelerometer and a 3-axis gyroscope in one package. It reports acceleration, rotation rate, and die temperature at configurable data rates and measurement ranges. See the Adafruit learn guide for wiring and hardware details.
Connection
Call startGyroscope() inside preload(). The device is ready to use by the time setup() runs.
let imu;
function preload() {
imu = startGyroscope(name?, addressOrIndex?, chipset?);
}name string | false | null "gyroscope"
Controls automatic event callback registration. Any function on the sketch named name + EventName (event name capitalised) is called whenever that event fires. With the default name:
function gyroscopeChanged(event) { /* new sensor reading */ }Pass false or null to disable automatic registration and use addEventListener instead.
addressOrIndex number 0x6A
The I2C address of the device, or an index (0–1) into the address list. Two addresses are available, set by the SDO pin on the board:
| Address | Index | ADDR pin |
|---|---|---|
| 0x6A | 0 | open |
| 0x6B | 1 | closed |
chipset GyroscopeChipset GYROSCOPE_CHIPSET_LSM6DSOX
The chipset variant of the connected sensor. Use this when the board uses a different LSM6DS-family chip than the default LSM6DSOX. All constants are available as global variables in p5.js sketches:
| Constant | Chip |
|---|---|
| GYROSCOPE_CHIPSET_LSM6DSOX | LSM6DSOX (default) |
| GYROSCOPE_CHIPSET_ISM330DHCX | ISM330DHCX |
| GYROSCOPE_CHIPSET_LSM6DSO32 | LSM6DSO32 |
Methods
getAcceleration() { x, y, z }
Returns the last measured linear acceleration as a { x, y, z } object in m/s².
getRotation() { x, y, z }
Returns the last measured angular velocity as a { x, y, z } object in degrees per second.
getTemperature() number
Returns the die temperature in °C at the time of the last reading.
Configuration methods — ranges & data rates
getAccelerationDataRate() DataRate
Returns the current accelerometer output data rate as a DataRate enum value. Default is DataRate.DATA_RATE_HZ_104.
getAccelerationRange() AccelerationRange
Returns the current acceleration full-scale range as an AccelerationRange enum value. Default is AccelerationRange.ACCELERATION_RANGE_4_G.
getRotationDataRate() DataRate
Returns the current gyroscope output data rate as a DataRate enum value. Default is DataRate.DATA_RATE_HZ_104.
getRotationRange() RotationRange
Returns the current gyroscope full-scale range as a RotationRange enum value. Default is RotationRange.ROTATION_RANGE_DPS_250.
setAccelerationDataRate(value) Promise<boolean>
Sets the accelerometer output data rate. Resolves to true when acknowledged by the firmware. Available values:
| Constant | Rate |
|---|---|
| GYROSCOPE_DATA_RATE_SHUTDOWN | off |
| GYROSCOPE_DATA_RATE_HZ_12_5 | 12.5 Hz |
| GYROSCOPE_DATA_RATE_HZ_26 | 26 Hz |
| GYROSCOPE_DATA_RATE_HZ_52 | 52 Hz |
| GYROSCOPE_DATA_RATE_HZ_104 | 104 Hz (default) |
| GYROSCOPE_DATA_RATE_HZ_208 | 208 Hz |
| GYROSCOPE_DATA_RATE_HZ_416 | 416 Hz |
| GYROSCOPE_DATA_RATE_HZ_833 | 833 Hz |
| GYROSCOPE_DATA_RATE_HZ_1_66K | 1.66 kHz |
| GYROSCOPE_DATA_RATE_HZ_3_33K | 3.33 kHz |
| GYROSCOPE_DATA_RATE_HZ_6_66K | 6.66 kHz |
setAccelerationRange(value) Promise<boolean>
Sets the acceleration full-scale range. Resolves to true when acknowledged by the firmware. Available values:
| Constant | Range |
|---|---|
| GYROSCOPE_ACCELERATION_RANGE_4_G | ±4 g (default) |
| GYROSCOPE_ACCELERATION_RANGE_8_G | ±8 g |
| GYROSCOPE_ACCELERATION_RANGE_16_G | ±16 g |
| GYROSCOPE_ACCELERATION_RANGE_32_G | ±32 g |
setRotationDataRate(value) Promise<boolean>
Sets the gyroscope output data rate. Accepts the same DataRate constants as setAccelerationDataRate. Default is DataRate.DATA_RATE_HZ_104.
setRotationRange(value) Promise<boolean>
Sets the gyroscope full-scale range. Resolves to true when acknowledged by the firmware. Available values:
| Constant | Range |
|---|---|
| GYROSCOPE_ROTATION_RANGE_DPS_125 | ±125 dps |
| GYROSCOPE_ROTATION_RANGE_DPS_250 | ±250 dps (default) |
| GYROSCOPE_ROTATION_RANGE_DPS_500 | ±500 dps |
| GYROSCOPE_ROTATION_RANGE_DPS_1000 | ±1000 dps |
| GYROSCOPE_ROTATION_RANGE_DPS_2000 | ±2000 dps |
| GYROSCOPE_ROTATION_RANGE_DPS_4000 | ±4000 dps |
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 acceleration, rotation, 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.acceleration { x, y, z } — Linear acceleration in m/s² along each axis.
event.detail.rotation { x, y, z } — Angular velocity in degrees per second around each axis.
event.detail.temperature number — Die temperature in °C at the time of the reading.