Skip to content

Latest commit

 

History

History
436 lines (296 loc) · 7.48 KB

File metadata and controls

436 lines (296 loc) · 7.48 KB

ArduinoLSM6DSOX library

Methods

begin()

Initialize the IMU.

Syntax

IMU.begin()

Parameters

None.

Returns

1 on success, 0 on failure.

Example

if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
}

See also

end()

De-initialize the IMU.

Syntax

IMU.end()

Parameters

None.

Returns

None.

Example

if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
}

// Read IMU data...

// Done with the IMU readings
IMU.end();

See also

readAcceleration()

Query the IMU's accelerometer and return the acceleration in g's. The accelerometer is configured with a scale of [-4, +4] g.

Syntax

IMU.readAcceleration(x,y,z)

Parameters

  • x: float variable where the acceleration value in the IMU's x-axis will be stored.
  • y: float variable where the acceleration value in the IMU's y-axis will be stored.
  • z: float variable where the acceleration value in the IMU's z-axis will be stored.

Returns

1 on success, 0 on failure.

Example

float x, y, z;

if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);

    Serial.print(x);
    Serial.print('\t');
    Serial.print(y);
    Serial.print('\t');
    Serial.println(z);
}

See also

readGyroscope()

Query the IMU's gyroscope and return the angular speed in dps (degrees per second). The gyroscope is configured with a scale of [-2000, +2000] dps.

Syntax

IMU.readGyroscope(x,y,z)

Parameters

  • x: float variable where the gyroscope value in the IMU's x-axis will be stored.
  • y: float variable where the gyroscope value in the IMU's y-axis will be stored.
  • z: float variable where the gyroscope value in the IMU's z-axis will be stored.

Returns

1 on success, 0 on failure.

Example

float x, y, z;

if (IMU.gyroscopeAvailable()) {
    IMU.readGyroscope(x, y, z);

    Serial.print(x);
    Serial.print('\t');
    Serial.print(y);
    Serial.print('\t');
    Serial.println(z);
}

See also

accelerationAvailable()

Query if new acceleration data from the IMU is available.

Syntax

IMU.accelerationAvailable()

Parameters

None.

Returns

0 if no new acceleration data is available, 1 if new acceleration data is available.

Example

float x, y, z;

if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);

    Serial.print(x);
    Serial.print('\t');
    Serial.print(y);
    Serial.print('\t');
    Serial.println(z);
}

See also

gyroscopeAvailable()

Query if new gyroscope data from the IMU is available.

Syntax

IMU.gyroscopeAvailable()

Parameters

None.

Returns

0 if no new gyroscope data is available, 1 if new gyroscope data is available.

Example

float x, y, z;

if (IMU.gyroscopeAvailable()) {
    IMU.readGyroscope(x, y, z);

    Serial.print(x);
    Serial.print('\t');
    Serial.print(y);
    Serial.print('\t');
    Serial.println(z);
}

See also

accelerationSampleRate()

Return the IMU's accelerometer sample rate.

Syntax

IMU.accelerationSampleRate()

Parameters

None.

Returns

The IMU's accelerometer sample rate in Hz.

Example

Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println(" Hz");
Serial.println();
Serial.println("Acceleration in g's");
Serial.println("X\tY\tZ");

See also

gyroscopeSampleRate()

Return the IMU's gyroscope sample rate.

Syntax

IMU.gyroscopeSampleRate()

Parameters

None.

Returns

The IMU's gyroscope sample rate in Hz.

Example

Serial.print("Gyroscope sample rate = ");
Serial.print(IMU.gyroscopeSampleRate());
Serial.println(" Hz");
Serial.println();
Serial.println("Angular speed in degrees/second");
Serial.println("X\tY\tZ");

See also

readTemperature()

Reads the temperature from the sensor (Celsius).

Syntax

IMU.readTemperature(temperature_deg)

Parameters

  • temperature_deg: int variable where the temperature value will be stored.

Returns

None.

Example

if (IMU.temperatureAvailable())
  {
    int temperature_deg = 0;
    IMU.readTemperature(temperature_deg);

    Serial.print("LSM6DSOX Temperature = ");
    Serial.print(temperature_deg);
    Serial.println(" °C");
  }

readTemperatureFloat()

Reads the temperature from the sensor (Celsius).

Syntax

IMU.readTemperatureFloat(temperature_deg)

Parameters

  • temperature_deg: float variable where the temperature value will be stored.

Returns

None.

Example

if (IMU.temperatureAvailable())
  {
    float temperature_deg = 0.0f;
    IMU.readTemperatureFloat(temperature_deg);

    Serial.print("LSM6DSOX Temperature = ");
    Serial.print(temperature_deg);
    Serial.println(" °C");
  }

temperatureAvailable()

Checks if temperature data is available.

Syntax

IMU.temperatureAvailable()

Parameters

None.

Returns

1 on success, 0 on failure.

Example

if (IMU.temperatureAvailable())
  {
    int temperature_deg = 0;
    IMU.readTemperature(temperature_deg);

    Serial.print("LSM6DSOX Temperature = ");
    Serial.print(temperature_deg);
    Serial.println(" °C");
  }