Code covered by the MathWorks Limited License

Highlights from
Embedded Coder Support Package for Arduino

4.625

4.6 | 8 ratings Rate this file 163 Downloads (last 30 days) File Size: 305.64 KB File ID: #30277
image thumbnail

Embedded Coder Support Package for Arduino

by Classroom Resources Team

 

03 Feb 2011 (Updated 14 Mar 2012)

Simulink block library for creating standalone Arduino applications (requires Embedded Coder)

| Watch this File

File Information
Description

Arduino (www.arduino.cc) is a low-cost open-source electronics prototyping platform based on flexible, easy-to-use hardware and software.

Embedded Coder Support Package for Arduino allows you to create Simulink applications that will run autonomously on your Arduino board. Using Simulink Coder and Embedded Coder, the Simulink model is automatically converted to readable C code, compiled, and downloaded to the Arduino. You can:
* View the generated code
* Modify and reuse the generated code if needed
* Use Processor-in-the-loop (PIL) mode
* Use Embedded Coder features such as traceability and reporting.

Note: This support package does not support External mode

The support package comes with the following driver blocks:
* Digital Input
* Digital Output
* Analog Input
* Analog Output
* Serial Read
* Serial Write

It also comes with sample models demonstrating:
* Processor-in-the-loop (PIL) mode
* Serial communication with a host, and
* Use of Stateflow

For interfacing to the Arduino from MATLAB, see:
http://www.mathworks.com/academia/arduino-software/arduino-matlab.html

This package has been tested with R2010b, R2011a, and R2011b (Windows only). See README.txt for product requirements.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Arduino Target
This submission has inspired the following:
Embedded Coder Arduino Servo Write Block

Required Products Real-Time Workshop
Embedded Coder
Simulink
MATLAB release MATLAB 7.11 (2010b)
Other requirements * Windows platform only (either 32-bit or 64-bit) * Tested on R2010b, R2011a, or R2011b * PIL mode requires R2011b or later
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (35)
03 Nov 2011 Suleman Shafqat  
11 Nov 2011 Guillaume MARTIN

The baud rate is configured at 57600, but my baud rate is 115200. (So, the upload don't works)

Do you know how to configure the baud rate in :
c:/AARDUI~1/hardware/tools/avr/bin/avrdude -V -F -C c:/AARDUI~1/hardware/tools/avr/etc/avrdude.conf -p atmega328p -P //./COM4 -c stk500v1 -b 57600 -U flash:w:demo_arduino_blink.hex ?

Bests regads,
Guillaume

18 Nov 2011 Stefan Disch

I needed two changes to get it working in my environment (Win 7, Matlab 2011b, Arduino-0023 Software, Arduino Uno):

- In Prefs.m I changed in the function searchForComPort the string of the device name to '\\Device\\USBSER000'
(Have a look in your registry at HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM to identify the correct string)

- In runAvrDude.m I removed the baudrate option from the avrdude call. (Before it was set to 57600 and it doesn't work)

Best regards
Stefan

20 Nov 2011 Guillaume MARTIN

Thank you Stefan.

I did as you said (but I corrected the baudrate at 155200 in Prefs.m), and it ran.

Thank you very much,
Guillaume

28 Nov 2011 Frazer

Hey guys,

Has anyone had an issue with "multiple main errors, i.e.

main.o: In function `main':
main.cpp:(.text+0x0): multiple definition of `main'

I've followed all the instructions and I've not had any problems using eclipse to compile for my Arduino UNO.

Thanks Frazer

29 Nov 2011 Classroom Resources Team

Note: the latest version of the support package (released Nov 29, 2011) should address the above issues with Uno.

29 Nov 2011 Frazer

Is there a direct link for the Nov 29, 2011 update? I can only find the Nov 22, 2011 update.

30 Nov 2011 Classroom Resources Team

The Nov 22, 2011 update is the same as the Nov 29 update (the earlier date is when the file was submitted to FileExchange, the later date is when it got approved and published).

30 Nov 2011 Frazer

Great, thank you for that.

08 Dec 2011 Marcell  
09 Dec 2011 Stefan Disch

Has anyone used it with Arduino version 1.0 so far?

19 Dec 2011 Stephen Williams

Please add PWM block

19 Dec 2011 Stephen Williams

Just found the PWM block - it is labeled "Analog Output"

22 Dec 2011 Sean

I'm getting an error when trying to execute arduino.Prefs.setBoard:

??? Reference to non-existent element of a cell array.

Error in ==> Prefs>Prefs.parseBoardsFile at 227
                lhs = parsedLines{i}{1}{1}; % can be of the form xx.yy.zz

Error in ==> Prefs>Prefs.setBoard at 66
            boards = arduino.Prefs.parseBoardsFile(boardsFile);

Anyone know why this is?

22 Dec 2011 Classroom Resources Team

There is a problem parsing hardware/arduino/boards.txt for the latest Arduino IDE (Arduino 1.0). For the time being, try one of the following workarounds:

1) Use an older IDE (0023 or 0022), or

2) Edit boards.txt and delete lines 145 through 181 (inclusive).

30 Dec 2011 Curtis

I tried this fix (2) Edit boards.txt and delete lines 145 through 181 (inclusive).)

And got this error after.

demo_arduino_blink.h:23:22: error: WProgram.h: No such file or directory
gmake: *** [demo_arduino_blink_data.o] Error 1

30 Dec 2011 Curtis

I tried this fix: 1) Use an older IDE (0023)

And everything worked.

03 Jan 2012 Stefan Disch

I also tried fix 2) (using Arduino 1.0).

With Arduino 1.0 there came some changes in naming and layout of the includes (see http://arduino.cc/en/Main/ReleaseNotes for details).

I made the following changes to the current version of the arduino target:

1. Edit boards.txt and delete lines 145 through 181 (as told in a previous post)
2. Substitute every occurence of "WProgram.h" with "Arduino.h".
3. Add an additonal include path in rtwmkcfg.m in order to find the "pins_arduino.h" header file (moved to the new variants dir).
4. Commented out line 33 in arduino_smain.tlc because __cxa_pure_virtual is now defined in the Arduino 1.0 libs (see new.h).

These changes allowed me to compile the blink demo without errors.

09 Jan 2012 Nuri Temurlenk

Do you plan to support Chipkit Max32 kit?

http://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-MAX32

19 Jan 2012 Mark

Can this be used to configure pins as interrupts?

26 Jan 2012 Raja Rout

very very thanks, keep up the good work. It works with 2011a successfully installed. Can we access the extra serial ports of Arduino using this toolbox??.....

28 Jan 2012 Raja Rout

I did'nt find any option for accessing the others serial port.

13 Feb 2012 Gary

Excellent package, works great on my Uno

In the block directory there is an LCDOutput 'S' function can this be made functional & if so how?

24 Feb 2012 Mikhail

It would be great to have motor shield support, just like in MATLAB support package for Arduino.

27 Feb 2012 Nitin

Is it possible to access the I2C pins (SDA/SCL) via the blockset? If not, would appreciate a workaround!!

29 Feb 2012 Mikhail

Here i added the Servo Write block, which works with motor shield:
http://www.mathworks.com/matlabcentral/fileexchange/35356-simulink-arduino-servo-write-block

You are welcome to incorporate this patch into official package.

Thanks!

14 Mar 2012 Gary

Would like to change the AnalogOut PWM frequency, need to know if changing timer1 & timer2 is safe for integrity of simulink time base (assuming timer0 is used by simulink)?

16 Mar 2012 Nils  
16 Mar 2012 Mikhail

Thumbs up MathWorks for providing a more free license on this package (as of 14th March 2012 release), allowing to distribute and share the code!
It's a pity though that the contents itself had not been updated for a long time.

28 Mar 2012 Andrey Zagvazdin

Hello! I MatLAB 7.12 (R2011a) 64-bit. OS Windows 7
Fee clone Arduino, Russian assembly Freeduino (http://freeduino.ru/arduino/index.html), a complete analog Ardruino Uno / Duemilanove w/ATmega328.
My actions:
1 - Connection "Arduino" to MatLAB
* Set ArduinoIO (http://www.mathworks.com/matlabcentral/fileexchange/32374);
* Unpack the package into C: \ arduinoIO;
* >> Cd c: \ arduinoIO
* >> Install_arduino
* >> Savepath
* Flashed "Arduino" core srv.pde (https://github.com/adafruit/Adafruit-Motor-Shield-library/zipball/master);
* >> A = arduino ('COM4');
At this point, everything is OK! From the window MatLAB, board responds and takes command.

2 - Connection "Arduino" to SIMULINK
* Downloading the package Simulink Support Package for Arduino (http://www.mathworks.com/matlabcentral/fileexchange/30277);
* "Simulink Support Package for Arduino" unpacked to C: \ arduino_simulink
* Downloading Wednesday Arduino IDE (arduino-1.0) and extract it to c: \ ArduinoTarget
* >> Cd c: \ arduino_simulink
* >> Addpath (fullfile (pwd, 'arduino'), fullfile (pwd, 'blocks'), fullfile (pwd, 'demos'))
* >> Savepath
* >> Sl_refresh_customizations
* Plug-in board "Arduino" to your computer.
* Indicates the path to the environment Arduino IDE >> arduino.Prefs.setArduinoPath ('c: \ ArduinoTarget')

That's all up to this point NORMALLY PUT.

* Determine the current platform team
>> Arduino.Prefs.setBoard ('atmega328') or >> arduino.Prefs.setMcu ('atmega328')
Throws an error
>> Arduino.Prefs.setBoard ('atmega328')
?? Reference to non-existent element of a cell
array.
Error in ==> Prefs> Prefs.parseBoardsFile at 227
                lhs = parsedLines {i} {1} {1}%
                can be of the form xx.yy.zz
Error in ==> Prefs> Prefs.setBoard at 66
            boards =
            arduino.Prefs.parseBoardsFile (boardsFile);
>> Arduino.Prefs.setMcu ('atmega328')
?? Error using ==> Prefs> Prefs.setMcu at 129
This function is deprecated. Use
arduino.Prefs.setBoard instead, e.g.
  arduino.Prefs.setBoard ('uno')

TRIED TO IGNORE THIS OPTION AND KEEP SETTING, BUT IN MODELING, DEMANDS categorically specify the model.

28 Mar 2012 Gerald

Hey,
I just need to know if this support package also works with Matlab R2009a?

I want to do small models in Simulink and flash it to the Arduino Mega 2560 Board. I can just use R2009a!

30 Mar 2012 Gautam Vallabha

Gerald, it has been tested with R2010b. There are no guarantees whether it will or will not work with R2009a.

If you are working with Mega, take a look at the support in R2012a (it only requires Simulink): http://www.mathworks.com/academia/arduino-software/arduino-simulink.html

30 Mar 2012 Classroom Resources Team

General guidelines:
* Please use this FileExchange page to post general comments and ratings on the support package

* If you have questions about using this support package, post your question at http://www.mathworks.com/matlabcentral/answers (with tag "arduino", and product "Embedded Coder")

15 Apr 2012 cerverus33

What's the diference with the file "Simulink Support Package for Arduino Uno Hardware"? I'm a little confuse about it

19 Apr 2012 Gautam Vallabha

@ceverus33 question answered at http://www.mathworks.com/matlabcentral/answers/35538

Please login to add a comment or rating.
Updates
22 Nov 2011

Version 1.2.
* Simplified workflow to specify Arduino boards (no need to set MCU and upload rate)
* Support for Arduino Uno & newer boards
* Miscellaneous bug and usability fixes

14 Mar 2012

Updated title and description

Tag Activity for this File
Tag Applied By Date/Time
arduino Classroom Resources Team 24 May 2011 14:39:03
support package Classroom Resources Team 24 May 2011 14:39:03
arduino Konstantin Volodin 02 Oct 2011 07:47:31
support package Konstantin Volodin 02 Oct 2011 07:47:34
pil Konstantin Volodin 02 Oct 2011 12:43:54
embedded coder Konstantin Volodin 02 Oct 2011 12:44:05
modeling Suleman Shafqat 03 Nov 2011 05:10:22
pil Classroom Resources Team 29 Nov 2011 10:01:40
support package chiranjeevi 30 Nov 2011 22:54:50
arduino julian 04 Feb 2012 19:56:39
simulink Classroom Resources Team 14 Mar 2012 17:17:52
support package Michael McNaughton 28 Mar 2012 17:15:11

Contact us at files@mathworks.com