How to use Arduino due with matlab I2C and sensor(Adafruit LSM6DSOX)

4 views (last 30 days)
Hello,
I'm pro to matlab, but new to be using an Arduino. So my question might be easy to answer for advanced Arduino and Matlab users.
I have bought the sensor (LSM6DSOX), connected it to arduino Due using the SCL and SDA pin number 20 and 21, and then I want to replicate the data which I can see using the Arduino software taken from https://learn.adafruit.com/lsm6dsox-and-ism330dhc-6-dof-imu/arduino. I have downloaded all the nesersarry expansion for matlab.
I have tryed in simulink using the "I2C Read" block setting parameters:
I2C module: 0
Slave address: 106
Slave byte order: BigEndian
I have not enabled register access
Data type: uint8
Data size (N): 4
Sample time: 0.1
With this set and the code running from the Arduino software, I expected to see som data in a simple scope in simulink, but nothing happens. I can get the scope running, but it will forever show zero for all data.
Then in Matlab I have tryed whit this code:
clear all
if ~isemty(instrfind);
fclose(instrfind);
delete(instrfind);
end
a = arduino("COM10","Due","Libraries","I2C")
address = scanI2CBus(a,0)
disp = (['i2c address:',address])
dev = device(a,'I2CAddress','0x6A')
data = read(dev,8,'unit32')
%% which can give 8 of the same numbers, but I don't know how to get further with these
% els I use this to generate data
a = serial("COM10")
fopen(a)
data = fread(a)
plot(hello)
% this code generates a lot of random numbers for me, and I cannot see which is acceleration(x,y,z), Gyro or Temperature.
% Whit this I get this figure
Now my questions is:
1: how to seperate the data?
2: how to show live data running infinity?
3: Can I get it both in Matlab and Simulink? (One of them is also just fine)

Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!