K30 sensor interface with MATLAB by using arduino board

HI, I am trying to read a data from K30 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 K30 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 4 uint8 value(s) from the device." The code used is :
clear all
clc
a=arduino('com1', 'nano3', 'Libraries', 'I2C');
scanI2CBus(a);
dev = i2cdev(a,'0x68');
write(dev, hex2dec('D0'));
write(dev, hex2dec('22'));
write(dev, hex2dec('00'));
write(dev, hex2dec('08'));
write(dev, hex2dec('2A'));
pause(0.1);
write(dev, hex2dec('D1'));
out = read(dev,4,'uint8')
Please help to resolve this issue. I am using MATLAB 2015a
Thanks Mahadev

1 comentario

Mahadevanna S
Mahadevanna S el 24 de Ag. de 2015
Editada: Walter Roberson el 24 de Ag. de 2015
hi all,
finally i made it work:
code is :
Below is the code which will work:
a=arduino('com1', 'nano3', 'Libraries', 'I2C');
scanI2CBus(a);
dev = i2cdev(a,'0x68');
mod_read=[34,0,8,42];%hex values converted to decimal
write(dev, mod_read);
pause(20e-3);
out = read(dev, 4,'uint8');
hope it is helpful to you all

Iniciar sesión para comentar.

 Respuesta aceptada

Mahadevanna S
Mahadevanna S el 24 de Ag. de 2015
Editada: Walter Roberson el 24 de Ag. de 2015
hi all, finally i made it work: code is :
Below is the code which will work:
a=arduino('com1', 'nano3', 'Libraries', 'I2C');
scanI2CBus(a);
dev = i2cdev(a,'0x68');
mod_read=[34,0,8,42];%hex values converted to decimal
write(dev, mod_read);
pause(20e-3);
out = read(dev, 4,'uint8');
hope it is helpful to you all

1 comentario

Eyal Wurgaft
Eyal Wurgaft el 9 de Abr. de 2019
Editada: Eyal Wurgaft el 10 de Abr. de 2019
Hi,
Thank you for posting the code. I tried running the code:
a=arduino('com13', 'uno', 'Libraries', 'I2C');
scanI2CBus(a);
dev = i2cdev(a,'0x68');
mod_read=[34,0,8,42];%hex values converted to decimal
write(dev, mod_read);
pause(20e-3);
out = read(dev, 4,'uint8');
but I got the following error:
Failed to read 4 uint8 value(s) from the device.
All the connections work well, I read CO2 values easily using Arduino IDE.
Will appreciate your help.
Eyal

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 17 de Ag. de 2015

Editada:

el 10 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by