MATLAB Answers


How to create custom blocks in Simulink for Arduino

Asked by Durga Samannth on 27 Apr 2013
Hi, My name is Samanth, I want to create my own custom blocks like the servo motor write and read in simulink. I want to use these custom blocks in Arduino microcontroller boards.
I have already tried this stuff and I am getting linkage errors so, I just want to check whether I am doing the things properly. So, I am requesting you guys to help me find some references which would explain the procedure step-by-step.
I am thinking that I am doing some mistake in the parameters pane part (Which appears by double clicking the S-Function builder).
I was doing like this
I have placed the following part under Libraries pane #ifndef MATLAB_MEX_FILE #include "Arduino.h" #include "Servo.h" #endif
I have seen some reference material and placed #if condition if I have removed it I am getting errors as
C:\Users\Nani\Desktop\samanth\simulonk models\avr/pgmspace.h(211) : error C2061: syntax error : identifier '__attribute__'
I have not modified anything in the header file which was in Arduino package.
Under the outputs pane I have kept the code as follows
if(xD[0]==1) { /*don't do anything for MEX-file generation*/ #ifdef MATLAB_MEX_FILE
//Custom code #endif }
I have followed a site to place the #if condition at the top.
Under the Discreete update pane I have kept the code as follows
if(xD[0]!=1) { #ifdef MATLAB_MEX_FILE // Custom code
#endif }
Can anyone correct me if I am doing wrong please.
Any step by step reference would be a lot helpful.
Thank you for the help in advance.

1 Answer

Answer by Ryan G
on 2 May 2013

This was just posted on the simulink blog. That may help you figure this out.
When creating a custom block for the first time I would recommend something simple like making the LED blink so you know you're doing it right.


Sign in to comment.