How do you program the Arduino in Simulink so you can read the sensors via I2C and SPI?
조회 수: 4 (최근 30일)
이전 댓글 표시
Hey.
I'm trying to build a control system in Simulink and then transfer it to an Arduino MEGA. The problem is that the accelerometer I've only communicate via I2C or SPI protocol and I do not know how it builds up in Simulink. I am relatively new to creating my own C \ C + + code in Simulink. Does anyone know how I can solve this problem? I thought on creating a separate block from the library that I have for the sensor that I use when I do programming in Arduinos own software.
Matlab version: 2012a Operating System: Windows 7 Arduino: MEGA Sensor: ADXL345
댓글 수: 0
답변 (4개)
Kaustubha Govind
2012년 4월 17일
If you know how to do this in C using Arduino libraries, you can generate a custom S-function block, using the Legacy Code Tool.
댓글 수: 0
Tim Rothmann
2012년 5월 9일
how does it work to include some arduino libraries like wire.h for example? i always get some compile errors. can you give me some small example?
댓글 수: 9
Tim Rothmann
2012년 5월 28일
after spending hours and hours now i'm trying to do the other way and generating C-code from simulink and import it to eclipse.
are there some papers about code generation for atmega?especially to acces inputs and outputs?
Kaustubha Govind
2012년 5월 29일
Tim: Not sure what you mean by "to access inputs and outputs" - do you mean accessing sensor/actuator signals? Typically there needs to be a blockset containing blocks corresponding to the various board peripherals that represent the sensors and actuators.
Zhuo Li
2013년 5월 2일
편집: Zhuo Li
2013년 5월 2일
These two links may be helpful to your case
ADLX345 i2c Driver for Arduino Mega
I2C block for ArduinoIO simulink package
댓글 수: 1
joshua hadi
2013년 5월 6일
Hello Zhuo Li, I want to ask about using adxl 345 in simulink, could we divide the x,y,z output reading into the 3 blocks (x,y,z blocks) because i saw your i2c read block only can give 1 output arrow. thanks.
Mohit Khandelwal
2018년 9월 10일
% create an arduino object
a = arduino('com3', 'uno');
% start the loop to blink led for 10 seconds
for i = 1:10
writeDigitalPin(a, 'D11', 1);
pause(0.5);
writeDigitalPin(a, 'D11', 0);
pause(0.5);
end
% end communication with arduino
clear a
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Modeling에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!