I tried to follow your example and it worked great for interfaces that are in Arduino.h such as digital and analog IO. I ran into problems when trying to include other Arduino Libraries.
I noticed that you had included "AFMotor.cpp" and "AFMotor.h" in your examples, which I guess is similar what I am attempting with "DS1307RTC.h" and "DS1307RTC.cpp" which are libraries for keeping time.
I can build the sfunction with the sfunction builder when it is structured like you have it in your examples. When I go to build the applicaiton, however, I run into an issue that seems to be related to cpp code when the compiler is expecting c code. I am using the Arduino integration package found here http://www.mathworks.com/matlabcentral/fileexchange/30277-embedded-coder-support-package-for-arduino
The compiler message I get when it attempts to build the header file with a class definition is this:
C:/ARDUIN~1.3/hardware/tools/avr/bin//avr-gcc -c -mmcu=atmega2560 -I. -DF_CPU=16000000 -Os -Wall -Wstrict-prototypes -std=gnu99 -I. -I.. -IC:/PROGRA~1/MATLAB/R2011a/rtw/c/ert -IC:/PROGRA~1/MATLAB/R2011a/extern/include -IC:/PROGRA~1/MATLAB/R2011a/simulink/include -IC:/PROGRA~1/MATLAB/R2011a/rtw/c/src -IC:/PROGRA~1/MATLAB/R2011a/rtw/c/src/ext_mode/common -Ic:/OU_SYSTEMS_ENG/GH/gh-dev/Simulink_Models/Drivers/GH_TopLevel_Test_arduino -Ic:/OU_SYSTEMS_ENG/GH/gh-dev/Simulink_Models/Drivers -Ic:/OU_SYSTEMS_ENG/GH/gh-dev/Simulink_Models -Ic:/OU_SYSTEMS_ENG/GH/gh-dev/Simulink_Models/Custom_Includes -Ic:/OU_SYSTEMS_ENG/GH/gh-dev/Simulink_Models/ArduinoML/blocks -IC:/arduino-1.0.3/hardware/arduino/variants/mega2560 -IC:/arduino-1.0.3/hardware/arduino/cores/arduino -IC:/arduino-1.0.3/libraries/Time -IC:/arduino-1.0.3/libraries/DS1307RTC -Ireferenced_model_includes -I../slprj/arduino/_sharedutils -IC:/ARDUIN~1.3/hardware/arduino/cores/arduino ../sfun_systime_get_wrapper.c -o sfun_systime_get_wrapper.o
In file included from ../sfun_systime_get_wrapper.c:39:
C:/arduino-1.0.3/libraries/DS1307RTC/DS1307RTC.h:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'DS1307RTC'
../sfun_systime_get_wrapper.c:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sysTime'
Please let me know if you have any thoughts. I am wondering if this is still an issue with the newer Arduino support in later versions of ML/Simulink.
I've gone ahead and created a tutorial for integrating the new Arduino 1.0.3 libraries in with this support package. There are some directions in this post that I have borrowed from to compose it, but I thought it would be useful to keep everything in once place.
When you have message like "... does not exist", it looks that directory "blocks" is not on the MATLAB path. It should be, because it is done in function "setup_customtarget_arduino.m" on first functional line and next this path is saved:
result = savepath;
Try to run "setup_customtarget_arduino.m" again.
I have some trouble when I try to run simulate/build/flash any model from example (Error in S-function 'myarduino_blink/Digital Output': S-Function 'sfunar_digitalOutput' does not exist). But installation was successful (all path saved in matlab (2014/64). What do I do wrong?
This is strictly AVR-based Arduino with IDE version 1.0.5. This cannot be working with Due because of different MCU, different compiler and mainly, different internal structure of IDE 1.5.x.
If there will be more interest, we can consider port for Arduino Due.
I am trying to use the package with my arduino Due.
In the comments I read, the Arduino 1.5.x is not supported. So I installed 1.0.5 and set the path in the setup file correctly. When I try to build the demo "myarduino_blink.slx" I get the following error:
unknown MCU 'cortex-m3' specified
Known MCU names:
C:/Users/thomas/Desktop/arduino_ec_target/blocks/io_wrappers.cpp:1: error: MCU 'cortex-m3' supported for assembler only
In file included from c:/arduino/hardware/tools/avr/lib/gcc/../../avr/include/avr/pgmspace.h:82,
c:/arduino/hardware/tools/avr/lib/gcc/../../avr/include/avr/io.h:330:6: warning: #warning "device type not defined"
In file included from C:/Users/thomas/Desktop/arduino_ec_target/blocks/io_wrappers.cpp:10:
C:/Arduino/hardware/arduino/cores/arduino/Arduino.h:213:26: error: pins_arduino.h: No such file or directory
Did anybody use this package with the Arduino Due? Please help me on that.