"measure temperature from i2c device using arduino hardware".

1 visualización (últimos 30 días)
HI, I am trying to read a data from tmp102 sensor with MATLAB by using arduino board. Here I am using I2C communication Before this I was able to read many sensor data with MATLAB by using arduino board with I2C communication. but for tmp102 sensor I am able to read the address and follow the data and write the required bytes, but when I read I am getting error "Failed to read 2 uint8 value(s) from the device." The code used is :
clear all clc a = arduino();
addrs = scanI2CBus(a)
tmp102 = i2cdev(a, '0x48')
write(tmp102, 0, 'uint8');
data = read(tmp102, 2, 'uint8');
temperature = (double(bitshift(int16(data(1)), 4)) + double(bitshift(int16(data(2)), -4))) * 0.0625
writeRegister(tmp102, 1, hex2dec('60B0'), 'uint16');
pause(0.25);
data = readRegister(tmp102, 0, 'int16');
temperature = double(bitshift(bitand(data, hex2dec('FFF8')), -3)) * 0.0625
writeRegister(tmp102, 1, hex2dec('60A0'), 'int16');
clear tmp102 a
Please help to resolve this issue. I am using MATLAB 2018b
Thanks saketh
  2 comentarios
Walter Roberson
Walter Roberson el 23 de Mzo. de 2019
You are not assigning to a.
Your line
clear all clc a = arduino();
is interpreted as a request to clear all, and clc, and a, and =, and arduino() . Some of that is not really valid syntax, but clear does not seem to care.
TAMALAMPUDI VENKATA SAI SAKETH REDDY
TAMALAMPUDI VENKATA SAI SAKETH REDDY el 26 de Mzo. de 2019
Editada: TAMALAMPUDI VENKATA SAI SAKETH REDDY el 26 de Mzo. de 2019
Iam using the code and connections which was given in the link provided by the mathworks https://www.mathworks.com/help/supportpkg/arduinoio/examples/measure-temperature-from-i2c-device-on-arduino-hardware.html?prodcode=ML .But Iam getting an error"Failed to read 2 uint8 value(s) from the device" when i running the code in the matlab version 2018b with arduino uno board.And while running the code Iam getting 0x0 empty cell array in the address place.Can you resolve the code and give the correct code.
thank you

Iniciar sesión para comentar.

Respuestas (3)

Madhu Govindarajan
Madhu Govindarajan el 20 de Mzo. de 2019
What is the Arduino board using and does your hardware setup look similar to the one shown here - https://www.mathworks.com/help/supportpkg/arduinoio/examples/measure-temperature-from-i2c-device-on-arduino-hardware.html?prodcode=ML
  2 comentarios
TAMALAMPUDI VENKATA SAI SAKETH REDDY
TAMALAMPUDI VENKATA SAI SAKETH REDDY el 21 de Mzo. de 2019
almost same.we are using arduino uno board,tmp102 and connections are connected as mentioned above and the code is also same.But we are getting error "Failed to read 2 uint8 value(s) from the device.sir can u please give the solution for that.
Thanks for the previous response
Madhu Govindarajan
Madhu Govindarajan el 21 de Mzo. de 2019
What happens if you remove the following three lines of code and run the rest of the code? -
write(tmp102, 0, 'uint8');
data = read(tmp102, 2, 'uint8');
temperature = (double(bitshift(int16(data(1)), 4)) + double(bitshift(int16(data(2)), -4))) * 0.0625

Iniciar sesión para comentar.


TAMALAMPUDI VENKATA SAI SAKETH REDDY
TAMALAMPUDI VENKATA SAI SAKETH REDDY el 22 de Mzo. de 2019
it was giving an error "failed to read int16 values from register 0".sir our project final review date was ahead. Can u please give the correct code to get output. Thank you for the response

Madhu Govindarajan
Madhu Govindarajan el 22 de Mzo. de 2019
Can you try with other arduino boards or other sensors? That code works for me on the Arduino and TMP102 sensor.
  4 comentarios
TAMALAMPUDI VENKATA SAI SAKETH REDDY
TAMALAMPUDI VENKATA SAI SAKETH REDDY el 27 de Mzo. de 2019
I connected as per the given connections.Sir how can we know that whether the sensor is working or not. Thank you
Madhu Govindarajan
Madhu Govindarajan el 27 de Mzo. de 2019
Try testing it from Arduino IDE itself and if that also does not work then you know the sensor is not working. If that works, reach out to MathWorks Technical Support.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by