Read voltage from ADC pins on sensor
Create an Arduino object and include the I2C library.
a = arduino();
Or, you can explicitly specify it in the
pair while creating the Arduino object.
clear a; a = arduino('COM8', 'Uno', 'Libraries', 'I2C');
Create the sensor object for the sensor in use.
sensorObj = lis3dh(a);
Return one sample of voltage data.
sensorObj = lis3dh with properties: I2CAddress: 24 ("0x18") Bus: 0 SCLPin: "D21" SDAPin: "D20" SampleRate: 100 (samples/s) SamplesPerRead: 10 ReadMode: "latest" SamplesRead: 0 SamplesAvailable: 0 AvailableADCPins: ["ADC1","ADC2","ADC3"]
sensorObj — sensor object
The sensor object.
pin — ADC pin
ADC pin on the sensor, specified as a character vector.
voltage — Voltage read from ADC pin
Voltage read from a ADC pin on the sensor specified as a numeric double.
timestamp — Timestamp
The time at which MATLAB® receives voltage data from the sensor, specified as a datetime.
Code Generation Using MATLAB Function Block
readVoltagein a MATLAB Function block with the Simulink® Support Package for Arduino® Hardware to generate code that can be deployed on Arduino Hardware.
Timestamp returned is always in seconds.
Introduced in R2023a