Simulink, Arduino, and I2C accelerometer

11 次查看(过去 30 天)
Hi!
I am trying to develop a control system using Simulink's model-based design approach, and I need to use the data from an accelerometer. Ultimately this control system will be downloaded onto/implemented on an Arduino Mega microcontroller.
My question: How can I, in Simulink, recieve the accelerometer data? I have found out that the accelerometer uses I2C communication. I notice that there's a "Serial recieve" block in the Simulink Arduino support package, but I cannot figure out how to make it work.
This video shows exactly what I want to be able to do:
https://www.youtube.com/watch?v=04QI08JNSnw
Any help would be GREATLY appreciated!

回答(3 个)

Omer Ikram
Omer Ikram 2014-4-7
编辑:Omer Ikram 2014-4-7
Hi there, I am also stuck, same place as you are. Serial Receive will not work for you. You need a block which can read I2C. However no I2C read/write block comes with Arduino Support package. I am trying to write an sFunction for it but stuck with the compatibility of the library files. "Wire.h" which is used for I2C communication in Arduino SDK uses "inttypes.h" and this header file is now obsolete and new compilers such as Windows SDK 7.1 can not recognize them. I dont know how to solve this problem and a bit of help will be appreciated.
However, if you want to use only accelerometer data out. you can use the Matlab code to read the receiving data.
In the Arduino code export the data to the serial port 0
by write example lines in your code
Serial.println(Xdata);
Serial.println(Ydata);
Serial.Println(Zdata);
you should be able to receive it by listening the COM and embed the matlab code in the Simulink.
  5 个评论
Omer Ikram
Omer Ikram 2014-4-10
:D I think our interests perfectly align. I am also looking for a ways to use the generated code by Simulink to embed in our own code for arduino. But that is a later part, if I am not able to read I2C device with-in Simulink.
Currently the problem is that I can not find any I2C library which do not use inttypes.h header file.
inttypes.h file is not compatible with current version of c compilers which are used by Matlab 2013
An-other approach is to use any digital pin as SDA and SCL and use it for reading and writing the data but i feel it as a waste of resources.
Alex
Alex 2014-4-11
I've actually resorted to using a separate arduino and sending the data received from the gyro over serial to the one running from simulink in the end. But if you find a better way of doing this, please let me know!

请先登录,再进行评论。


Mohamed
Mohamed 2014-5-19
What is wrong with that one , can it be used ? I2C block for ArduinoIO simulink package

John
John 2014-5-29
I have the same problem - I want to use a mpu 9150 in my project
  2 个评论
Cristian Acosta
Cristian Acosta 2016-1-25
Hi Guys, I am trying to reed the MPU 6050. I wondered if they had found a solution to your communication. Any help will be appreciated.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by