Read data from Arduino Nano 33 IoT IMU sensor

조회 수: 27 (최근 30일)
Matthias Wölfleder
Matthias Wölfleder 2020년 4월 6일
댓글: Tomás 2023년 8월 2일
Hey everyone!
I would like to read the data from the integrated LSM6DS3 IMU sensor in the Arduino Nano 33 IoT.
When using "port1", I only get an array filled with zeros with the read function or a single zero with the readRegister function.
When using "port2", I get [4 17 51 67 255 255 255 ... ] with the read function an 4356 with the readRegister function, independent from movement or tilt.
I've already read the documentation, but it seems I don't really understand what is going on here.
And what does the error message "I2C address '96 (0x60)' already in use." mean when I try to run the script again without clearing the arduino object first?
I would be glad if someone could help me!
Kind regards,
Matthias
clear;
a = arduino('COM8','Nano33IoT','Libraries','I2C');
%% Scan for device adress
ports = scanI2CBus(a,0);
% Avaliable ports
port1 = '0x60';
port2 = '0x6A';
%%
IMU = device(a,'I2CAddress',port2);
out = read(IMU,10);
value = readRegister(IMU,port2,'uint16')

채택된 답변

MathWorks MATLAB Hardware Team
MathWorks MATLAB Hardware Team 2020년 4월 22일
Hi Matthias,
I see that you are using a correct subset of I2C APIs documented to read out the sensor register. However, the data must be read from registers specified in the datasheet. For intsance, if you wish to read linear acceleration values along all the X,Y, and Z directions, values at 0x28 must be accessed. The sensor can also be configured with some non-zero default settings beforehand.
Use the slave address 0x6A to construct the I2C device object.
>> IMU = device(a, 'I2CAddress', 0x6A);
Before reading any data, you can verify that the sensor is readable by reading the WHO_AM_I register with address 0x0F.
>> readRegister(IMU, 0x0F, 1)
ans =
105
Here is an example of reading acceleration with default 2g setting:
% Read three 'int16' type data values starting from address 0x28.
% Normalize and scale it to 2g (chosen by default)
>> dataRead = (2/32768)*readRegister(IMU, 0x28, 3, 'int16')
ans =
0.4904 0.0054 0.2997
NOTE : The values will differ as per the IMU position
Similarly, you can try other settings present in the datasheet. Moreover, you may use the writeRegister API to configure the registers.
Our support doesn’t allow multiple connections to same device for ease of use.
If you want to use the existing connection in workspace without clearing it; you can bypass the device creation and proceed with read
Hope this helps. Please contact MathWorks Technical Support for further queries.
  댓글 수: 7
Nicholas Motta
Nicholas Motta 2020년 11월 25일
Thank you. Works great now.
Tomás
Tomás 2023년 8월 2일
Hello! One question, were you able to make this connection via bluetooth? or only with the serial cable?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Gayatri Menon
Gayatri Menon 2022년 1월 4일
편집: Gayatri Menon 2022년 1월 4일
Hi,
Connecting to LSM6DS3 sensor on Arduino hardware I2C bus can be done by following
The feature is available from MATLAB R2021a.
Thanks
Gayatri

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by