Compile Simulink generated code in Arduino IDE?
99 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Apr 2017
Answered: MathWorks Support Team
on 9 May 2017
I'm trying to figure out how to get code created by Embedded Coder to build in the Arduino IDE. I have created a model in Simulink that I can build directly to the arduino board and it runs. However, I'd like to be able to make some modifications so it can run on some Arduino 3rd party boards.
I tried using Embedded Coder to generate the code, but it doesn't package it as an arduino .ino file. I tried adding all the generated files to the sketch, but arduino requires you to use the setup and loop functions and it was not obvious how to connect the generated code into the sketch.
Accepted Answer
MathWorks Support Team
on 27 Apr 2017
The inability to compile Simulink's generated code within the Arduino IDE is expected. The Arduino IDE uses its own language (the files are INO-files) which are then converted to C-code. This can often go unnoticed as Arduino's language is so similar to C (it is actually a subset of C).
The Simulink Support Package is generating C-code directly (bypassing the INO-file). However, there is a way to modify the generated C-code before deploying an application to the target.
1) Select the option to "Generate code only" in the Simulink Code Generation Configuaration Parameters and generate code for the Arduino embedded target.
2) Open and modify that generated C-code using any C-code IDE.
3) Use the MK-file generated by Simulink to compile and build the application for the Arduino.
4) Use the 'avrdude' tool to deploy the application to the Arduino.
The following website provides a good explanation of the Arduino IDE programming/compilation process (and how to bypass using the INO-file).
0 Comments
More Answers (0)
See Also
Categories
Find more on Run on Target Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!