Read data from Arduino Nano 33 IoT IMU sensor

20 ビュー (過去 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 Center および File ExchangeModeling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by