How do i use S-function twice with the same object? - Arduino in Simulink
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello!
I'm an Arduino programmer and i have just started program my Arduino with Simulink. I have learn how to add in libraries such as LCD, Keypad and diffrent I2C sensors.
Right now i have a problem with the S-functions. I want to use the S-function twice. You probably got confused now. I don't know how to spell it or what to call it. So i giving you an example.
Let's say you want to display "Hello World" on a LCD. The first thing you need to do in Arduino/microcontrollers is to setup the LCD. In Arduino you just write LCD.begin(); then your LCD is ready to use.
But lets jump over to Simulink....
Inside the first S-Function block(we call that s_LCD_1) you want to make sure that LCD has a setup. You add the libraries and some functions decelerations before the output. In the text in output inside the S-function s_LCD_1 should be the following:
#infndef MATLAB_MEX_FILE LCD.begin(); #endif
Easy!
But the next S-Function will write out "Hello". Then we need to create a new S-Function with the name s_LCD_2 and do exaktly the same thing, but a diffrent output.
#ifndef MATLAB_MEX_FILE LCD.print("Hello "); #endif
And the third S-Function s_LCD_3 will have the same libraries and functions deceleration but this output:
#ifndef MATLAB_MEX_FILE LCD.print("World"); LCD.display(); // This sends up the text loaded text "Hello World" to the LCD. #endif
But when i do this...i got an error when i upload the Simulink model to my Arduino. I cannot double declare the libraries #include this_is_my_LCD_lib.h or something like that in the S-Function. The first S-function s_LCD_1 works great! No error. But the rest of the S-Functions will give errors.
My question is: 1. How do i solve this problem? 2. Can Simulink only have ONE S-Function per external object? One S-Function for my LCD and ONE S-Function for my keypad and ONE S-function for my I2C sensor?
If you don't understand what i mean. Just look at this video: https://www.youtube.com/watch?v=L86n9wZZz-g
Here is the error log if i use one LCD with two LCD S-function builder. One LCD-Function builder names LCD1. The other one names LCD2. Both print out text, but different texts. They have the same #include library.
2 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Block and Blockset Authoring en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!