How to create custom blocks in Simulink for Arduino

5 views (last 30 days)
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.

Answers (2)

Ryan G
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.

Mohith Prabhu
Mohith Prabhu on 21 May 2021
Refer the below documentation links for creating a custom Simulink Device Driver block using Arduino library.
• Create Custom Device Driver Block for Arduino Library
• Create a device driver block to access specific features of your hardware board

Products

Community Treasure Hunt

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

Start Hunting!