adxl345
Connect to ADXL345, ADXL343, ADXL344, or ADXL346 sensor on Arduino hardware I2C bus
Since R2022a
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Description
The adxl345
object reads linear acceleration using the ADXL345,
ADXL343, ADXL344, or ADXL346 sensor connected to the I2C bus of the hardware. The ADXL34x
family of accelerometers are used to read acceleration in all three dimensions. Attach an
ADXL34x 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.accelSensor
= adxl345(a
)
Example:
accelSensor = adxl345(a);
.
creates a sensor object with properties using one or more accelSensor
= adxl345(a
,Name,Value
)Name,Value
pair arguments.
Example:
accelSensor = adxl345(a, Bus=1);
.
Input Arguments
Properties
Object Functions
readAcceleration | Read one sample of acceleration 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 ADXL345 Sensor
Create an arduino
object with the I2C library.
a = arduino('COM4', 'Uno', Libraries='I2C');
Create the sensor object.
accelSensor = adxl345(a)
accelSensor = adxl345 with properties: I2CAddress: 83 ("0x53") Bus: 0 SCLPin: "A5" SDAPin: "A4" SampleRate: 100 (Samples/s) SamplesPerRead: 10 ReadMode: 'latest' SamplesRead: 0 SamplesAvailable: 0 Show all properties, functions
Create ADXL345 Sensor Connection with Additional Name-Value Pair Arguments
Create a sensor object with additional properties specified as name-value pair arguments.
clear accelSensor; accelSensor = adxl345(a,SampleRate=110,SamplesPerRead=3,ReadMode='latest')
imu = accelSensor with properties: I2CAddress: 83 ("0x53") Bus: 0 SCLPin: "A5" SDAPin: "A4" SampleRate: 110 (samples/s) SamplesPerRead: 3 ReadMode: "latest" SamplesRead: 0 SamplesAvailable: 0 Show all properties, functions
More About
Version History
Introduced in R2022a