Main Content

lsm6ds3

Connect to LSM6DS3 sensor onArduinohardware I2C bus

    Description

    Thelsm6ds3object reads acceleration, angular velocity, and temperature using the LSM6DS3 sensor connected to the I2C bus of the hardware. The LSM6DS3 is an inertial measurement unit (IMU) used to read acceleration and angular velocity in all three dimensions. The LSM6DS3 also has an embedded temperature sensor. Attach an LSM6DS3 sensor to the I2C pins on the hardware. You can read the data from your sensor in MATLAB®using theObject Functions.

    Creation

    Description

    imu= lsm6ds3(a)创建一个传感器对象与默认的财产价值es.

    Example:imu = lsm6ds3(a);.

    imu= lsm6ds3(a,Name,Value)creates a sensor object with properties using one or moreName,Valuepair arguments.

    Example:imu = lsm6ds3(a,'I2CAddress',0x6A);.

    Input Arguments

    expand all

    Connection to the hardware specified as an object.

    Example:imu = lsm6ds3(a)creates a connection to the LSM6DS3 sensor on the hardware represented as an object,a.

    Name-Value Arguments

    Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

    Specify the I2C address of the sensors when multiple I2C devices with the expected address for LSM6DS3 are connected to the same hardware board. LSM6DS3 can have two I2C addresses depending on the logic level on pin SDO/SA0 of the sensor.

    Pin Name Pin State I2C Address
    SDO/SA0 Low 0x6A
    High 0x6B

    You can specify the I2C address in:

    • Hexadecimal, decimal, or binary format

    • String of hexadecimal value of I2C Address

    • Character vector of hexadecimal value of I2C Address

    Example:imu = lsm6ds3(a,'I2CAddress',0x6A)

    0x6A is the I2C address of the accelerometer and gyroscope of LSM6DS3 connected to Arduino board.

    If not specified, the object will be created with one of the available I2C device address in the table. Availability of I2C device with the expected address will be determined by usingscanI2CBus.

    I2C bus number, specified as 0 or 1. The default value is 0.

    Example:imu = lsm6ds3(a, 'Bus', 1)creates the sensor object on Bus 1 of the hardware.

    Data Types:double

    Properties

    expand all

    Note

    The properties can also be used as name-value pair arguments while creating anlsm6ds3object.

    Specify the I2C address of the sensors when multiple I2C devices with the expected address for LSM6DS3 are connected to the same hardware board. LSM6DS3 can have two I2C addresses depending on the logic level on pin SDO/SA0 of the sensor.

    Pin Name Pin State I2C Address
    SDO/SA0 Low 0x6A
    High 0x6B

    You can specify the I2C address in:

    • Hexadecimal, decimal, or binary format

    • String of hexadecimal value of I2C Address

    • Character vector of hexadecimal value of I2C Address

    0x6A is the I2C address of the accelerometer and gyroscope of LSM6DS3 connected to Arduino board.

    If not specified, the object will be created with one of the available I2C device address in the table. Availability of I2C device with the expected address will be determined by usingscanI2CBus.

    I2C bus number, specified as 0 or 1. The default value is 0.

    Data Types:double

    Note

    Except forTimeFormat, all the other properties are non-tunable, which means you cannot change their values once the object is locked. Objects are locked when you call thereadfunction, and thereleasefunction unlocks them. If a property is tunable, you can change its value at any time.

    The rate in samples/s at which data is read from the sensor.

    Data Types:double

    Number of samples read from the sensor in a single execution of thereadfunction.

    Data Types:double

    Specify whether to return the latest or the oldest data samples. The number of samples depends on theSamplesPerReadvalue. The data read from the sensor is stored in the MATLAB buffer.

    • latest- - - - - -

      Provides the latest data samples available in the buffer. All previous data samples in the buffer are discarded. For example, ifSamplesPerRead= 3, the latest three data samples read by the sensor are returned.

      The following figure illustrates how latest data samples are returned assuming S1 is the first sensor data stored in the buffer, S2 is the second data and so on and Sn is the last data stored in the buffer andSamplesPerReadproperty is set to 3 during sensor object creation.

    • oldest- - - - - -

      Provides the oldest data samples available in the buffer. In this case, no data samples are discarded. For example, ifSamplesPerRead= 3, the first three data samples read are returned for the first read, the next three data samples are returned for the second read, and so on.

      The following figure illustrates how oldest data samples are returned assuming S1 is the first sensor data stored in the buffer, S2 is the second data and so on and Sn is the last data stored in the buffer andSamplesPerReadproperty is set to 3 during sensor object creation.

    Data Types:character vector|string

    This property is read-only.

    Samplesreadproperty outputs the values of samples read so far by executingreadfunction.Samplesreadis set to0, when the object is created or when youreleasethe object.

    Data Types:double

    This property is read-only.

    Samples available in the host buffer. The data read from the sensor is stored in the MATLAB buffer.SamplesAvailableproperty shows the number ofSamplesAvailablein this host buffer. When you release the object,SamplesAvailableis set to 0. When theReadModeof sensor is set aslatest,SamplesAvailablewill always be 0.

    Data Types:double

    Set the output format of the data returned by executing thereadfunction.

    When theOutputFormatis set totimetable, the data returned has the following fields:

    • Time — Time stamps indatetimeordurationformat

    • Acceleration — N-by-3 array in units of m/s2

    • AngularVelocity — N-by-3 array in units of rad/s

    • Temperature — N-by-1 array in units of degree Celsius

    When theOutputFormatis set tomatrix, the data is returned as matrices of acceleration, angular velocity, temperature, and time stamps. The units and size for the sensor readings are the same as thetimetableformat.

    N is the number of samples per read specified bySamplesPerRead. The three columns of each field represent the measurements in x, y, and z axes.

    Data Types:character vector|string

    Set the format of the time displayed when the sensor data is read.

    • datetime- - - - - -Displays the date and time at which the data is read.

    • duration- - - - - -Displays the time elapsed in seconds after the sensor object is locked. The sensor object gets locked at the first call of thereadfunction either after the object creation or after the execution of thereleasefunction.

    Data Types:character vector|string

    Object Functions

    readAcceleration Read one sample of acceleration from sensor
    readAngularVelocity Read one sample of angular velocity from sensor
    readTemperature Read one sample of temperature from sensor
    read Read real-time sensor data at a specified rate
    release Release the sensor object
    flush Flush the host buffer
    info Read information related to sensor

    Examples

    Create Connection to LSM6DS3 Sensor

    Create anarduinoobject with the I2C library.

    a = arduino('COM4','Uno','Libraries','I2C');

    Create the sensor object.

    imu = lsm6ds3(a)
    imu = lsm6ds3 with properties: I2CAddress: 106 ("0x6B") SCLPin: "A5" SDAPin: "A4" SampleRate: 100 (Samples/s) SamplesPerRead: 10 ReadMode: 'latest' SamplesRead: 0 SamplesAvailable: 0 Show all properties, functions

    Create LSM6DS3 Sensor Connection with Additional Name-Value Pair Arguments

    Create a sensor object with additional properties specified as name-value pair arguments .

    clearimu; imu = lsm6ds3(a,'SampleRate',110,'SamplesPerRead',3,'ReadMode','oldest')
    imu = lsm6ds3 with properties: I2CAddress: 107 ("0x6B") Bus: 0 SCLPin: "A5" SDAPin: "A4" SampleRate: 110 (samples/s) SamplesPerRead: 3 ReadMode: "oldest" SamplesRead: 0 SamplesAvailable: 0 Show all properties all functions

    More About

    expand all

    版本历史

    Introduced in R2021a