Effacer les filtres
Effacer les filtres

How to create custom blocks in Simulink for Arduino

11 vues (au cours des 30 derniers jours)
Durga Samannth
Durga Samannth le 27 Avr 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.

Réponses (2)

Ryan G
Ryan G le 2 Mai 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 le 21 Mai 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


Community Treasure Hunt

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

Start Hunting!

Translated by