Read data from Arduino Nano 33 IoT IMU sensor

32 次查看(过去 30 天)
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,
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
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 =
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 个评论
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
Connecting to LSM6DS3 sensor on Arduino hardware I2C bus can be done by following
The feature is available from MATLAB R2021a.


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