Read one sample of temperature from sensor
readTemperature function is available for the
Read temperature Data from 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('COM4', 'Uno', 'Libraries', 'I2C');
Create the sensor object for the sensor in use.
The sample code and output in this example is for
object. If you are using another sensor that supports
readTemperature function, use the corresponding
sensorobj = hts221(a);
Return one sample of temperature data.
temperatureReadings = readTemperature(sensorobj)
temperatureReadings = 28.12
sensorobj — sensor object
The sensor object with the default or specified properties.
tempReadings — Value read from the sensor
The temperature from the sensor.
timestamp — Timestamp
The time at which MATLAB® receives temperature data from the sensor, specified as a datetime.
Code Generation Using MATLAB Function Block
readTemperaturein 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.