With the Arduino Modelica library you can simulate your circuits and sketches on a virtual Arduino Uno and connect your Modelica models to real-world circuits using the Firmata protocol.
- Dymola 2017 FD01 or later
- Visual Studio 2015
- download the latest release and extract the archive
- in Dymola select
File > Open...and openArduino/package.mofrom the extracted files - in the package browser double-click
Arduino.Examples.Blink - right-click on the toolbar and check
SimulationandAnimationto view the simulation and animation toolbars - open the
Simulation Setup
and on the Compilertab selectVisual Studio 2015/Visual Studio C++ Express Edition (14.0) - click
to run the Simulation - after the simulation has finished click
in the animation toolbar and watch the LED Lblink
- try the other examples in
Arduino.Examples
To simulate your sketch MySketch you have to perform the following steps.
- save your sketch as
Arduino/Resources/Sketches/MySketch.ino - add the block
Arduino.Components.ArduinoUnoto your model - double-click the block and set the parameter
sketchto"MySketch.ino" - click
to re-translate the model when the sketch has changed
-
currently you can use only one instance of ArduinoUno in your Modelica model
-
the whole Arduino API is supported except for the following functions
- analogReadResolution()
- analogWriteResolution()
- tone()
- noTone()
- shiftOut()
- shiftIn()
- isWhitespace()
- Serial
print(), println() and write() are supported - Stream
- Keyboard
- Mouse
The following libraries are included and can be used directly.
| Name | Description |
|---|---|
| Servo.h | Servo library to control RC (hobby) servo motors |
| PID_v1.h | PID controller library for Arduino |
To use an external library in your sketch copy its header files (*.h) and source files (*.cpp) to the Libraries folder. If the library contains .cpp files you have to add them to the Arduino project by dragging them from the Libraries folder in the file browser onto the Source Files folder in the solution explorer.
The ArduinoUno model is driven by an ExternalObject that contains the compiled sketch and an implementation of the Arduino API. The external object is synchronized at every sample step with the Modelica model.
When a model that contains the ArduinoUno block is translated the external object is automatically re-built through the preInstantiate=Arduino.Internal.buildSketch(...) directive in its annotation.
This function writes a new Sketch.cpp to Arduino/Resources/Source/Arduino that includes the sketch currently selected in the ArduinoUno component and calls the build script build_sketch.bat.
This script re-builds the shared libraries Arduino/Resources/Library/win32/ModelicaArduino.dll and win64/ModelicaArduino.dll that contain the implementation of the external object.
- translate and simulate the model you want to debug
- open
VisualStudio/Arduino.slnin VisualStudio - select
Debugas configuration and the platform that matches your Dymola model (x64ifAdvanced.CompileWith64 = 2otherwiseWin32) - open the project settings and under
DebugsetCommandtodymosim.exeandWorking Directoryto your current Dymola working directory - open the sketch in VisualStudio and set a breakpoint
- start debugging
Copyright © 2018 Dassault Systèmes. The code is licensed GPLv3, the documentation CC BY-SA 4.0.
