lsm303c
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Description
The lsm303c
object reads linear acceleration, magnetic field
strength, and temperature using the LSM303C sensor connected to the I2C bus of the hardware.
The LSM303C is an inertial measurement unit (IMU) used to read acceleration and magnetic field
in all three dimensions. The LSM303C also has an embedded temperature sensor. Attach an
LSM303C sensor to the I2C pins on the hardware. You can read the data from your sensor in
MATLAB® using the Object Functions.
Creation
Description
creates a sensor object with default property values.imu
= lsm303c(a
)
Example:
imu = lsm303c(a);
.
creates a sensor object with properties using one or more imu
= lsm303c(a
,Name,Value
)Name,Value
pair arguments.
Example:
imu = lsm303c(a, 'Bus', 1);
.
Input Arguments
Properties
Object Functions
readAcceleration | Read one sample of acceleration from sensor |
readMagneticField | Read one sample of magnetic field 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 LSM303C Sensor
Create an arduino
object with the I2C library.
a = arduino('COM4', 'Uno', 'Libraries', 'I2C');
Create the sensor object.
imu = lsm303c(a)
imu = lsm303c with properties: I2CAddress: 29 ("0x1D") : 30 ("0x1E") Bus: 0 SCLPin: "D21" SDAPin: "D20" SampleRate: 100 (Samples/s) SamplesPerRead: 10 ReadMode: 'latest' SamplesRead: 0 SamplesAvailable: 0 Show all properties, functions Show all properties all functions
Create LSM303C Sensor Connection with Additional Name-Value Pair Arguments
Create a sensor object with additional properties specified as name-value pair arguments.
clear imu; imu = lsm303c(a,'SampleRate',110,'SamplesPerRead',3,'ReadMode','oldest')
imu = lsm303c 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
Version History
Introduced in R2021a