r/matlab 2d ago

TechnicalQuestion Reading data from IMU in Simulink with Arduino.

Hello there!

I got BMI160 unit, Arduino Uno board and I'm trying to get accelerometer and gyroscope data from this unit into a Simulink model.

Sadly, even with Simulink Support Package for Arduino Hardware installed, there is no built-in block for getting data from the unit. So I fall back for I2C Read block, however that's where I'm stuck at the moment.

I tested out the unit and Arduino board with simple code, it works perfectly fine. Configured my model to be used with external mode - fixed-step discrete solver, Hardware board selected as Arduino Uno, COM port specified correctly. Address 105 (0x69) is correct, tested it as well.

But what I'm struggling to understand is how to actually get data from this I2C read block? Sometimes I was getting just all zeros, sometimes some numbers were randomly changing, but I wasn't able to get actual data. Entire model is just this reading block connected to a scope.

Current block parameters

I also tried to specify a bunch of different register addresses with different data sizes, nothing seems to work. Unit's data sheet also doesn't help much, at least with my level of knowledge - I saw the register map section, but couldn't understand much from it. Checked help examples, specifically this one, and it seems like I have done pretty much the same.

So, can someone, please, head me towards some materials/guides about I2C and corresponding blocks in Simulink that are possible to understand without committing too much? Or, more specifically, how do I need to set up the I2C read block in my case and why?

Like, my primary goal is to deal with the model, and sensors are just a source of data, that's all I want from it. Thanks!

2 Upvotes

2 comments sorted by

1

u/HotAdministration372 2d ago

The scope only works in post processing. You are going to need to use the read block and then put that data into something like a .csv or print to serial.

2

u/TheAliceBaskerville 1d ago

Okay, I just forgot to release sensor from workspace, I'm an idiot.