diff options
author | Pragya28 | 2018-06-11 22:24:11 +0530 |
---|---|---|
committer | Pragya28 | 2018-06-11 22:24:11 +0530 |
commit | 0d1a8efeba2fd927aa99f24ff5dc3714d67b1e29 (patch) | |
tree | 8a4c7d89151e7c3e4df1055ea109a2092c963ef2 | |
parent | 06883740a342341cd17622e8572e3e04423cdc96 (diff) | |
download | OpenModelicaEmbedded-1-0d1a8efeba2fd927aa99f24ff5dc3714d67b1e29.tar.gz OpenModelicaEmbedded-1-0d1a8efeba2fd927aa99f24ff5dc3714d67b1e29.tar.bz2 OpenModelicaEmbedded-1-0d1a8efeba2fd927aa99f24ff5dc3714d67b1e29.zip |
ArduinoExamples package, dc motor eg., custom board added
-rw-r--r-- | OpenModelicaArduino/ArduinoExamples.mo | 479 | ||||
-rw-r--r-- | OpenModelicaArduino/package.mo | 57 | ||||
-rw-r--r-- | OpenModelicaArduino/package.order | 1 |
3 files changed, 537 insertions, 0 deletions
diff --git a/OpenModelicaArduino/ArduinoExamples.mo b/OpenModelicaArduino/ArduinoExamples.mo new file mode 100644 index 0000000..2e61882 --- /dev/null +++ b/OpenModelicaArduino/ArduinoExamples.mo @@ -0,0 +1,479 @@ +within OpenModelicaArduino; + +package ArduinoExamples + extends Modelica.Icons.ExamplesPackage; + + package Led + extends Modelica.Icons.ExamplesPackage; + + model ex1_led_blue + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanConstant booleanConstant1(k = true) annotation( + Placement(visible = true, transformation(origin = {-60, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Boards.customBoard customBoard1 annotation( + Placement(visible = true, transformation(origin = {61, -21}, extent = {{-21, -21}, {21, 21}}, rotation = 0))); + equation + connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{20, -20}, {60, -20}, {60, -20}, {62, -20}})); + connect(booleanConstant1.y, digitalOutput1.u) annotation( + Line(points = {{-38, -20}, {-20, -20}, {-20, -20}, {-20, -20}}, color = {255, 0, 255})); + end ex1_led_blue; + + model ex2_led_blue_delay + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {60, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1(enableRealTimeScaling = false) annotation( + Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanPulse booleanPulse1(period = 20, startTime = 5, width = 10) annotation( + Placement(visible = true, transformation(origin = {-60, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(booleanPulse1.y, digitalOutput1.u) annotation( + Line(points = {{-38, -20}, {-20, -20}, {-20, -20}, {-20, -20}}, color = {255, 0, 255})); + connect(digitalOutput1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{20, -20}, {60, -20}, {60, -20}, {60, -20}})); + end ex2_led_blue_delay; + + model ex3_led_blue_red + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput2(Pin = 11) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanPulse booleanPulse1(period = 20, startTime = 5, width = 25) annotation( + Placement(visible = true, transformation(origin = {-60, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanPulse booleanPulse2(period = 20, startTime = 5, width = 40) annotation( + Placement(visible = true, transformation(origin = {-60, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {60, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{20, 0}, {60, 0}, {60, -20}, {60, -20}})); + connect(digitalOutput2.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{20, -60}, {60, -60}, {60, -20}, {60, -20}})); + connect(booleanPulse2.y, digitalOutput2.u) annotation( + Line(points = {{-38, -60}, {-20, -60}, {-20, -60}, {-20, -60}}, color = {255, 0, 255})); + connect(booleanPulse1.y, digitalOutput1.u) annotation( + Line(points = {{-38, 0}, {-20, 0}, {-20, 0}, {-20, 0}}, color = {255, 0, 255})); + end ex3_led_blue_red; + + model ex4_led_blink + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {42, -6}, extent = {{-14, -14}, {14, 14}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 10) annotation( + Placement(visible = true, transformation(origin = {-9, -7}, extent = {{-13, -13}, {13, 13}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanPulse booleanPulse1(period = 2, startTime = 4, width = 50) annotation( + Placement(visible = true, transformation(origin = {-68, -12}, extent = {{-14, -14}, {14, 14}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-19, 51}, extent = {{-13, -13}, {13, 13}}, rotation = 0))); + equation + connect(booleanPulse1.y, digitalOutput1.u) annotation( + Line(points = {{-53, -12}, {-24, -12}, {-24, -7}, {-22, -7}}, color = {255, 0, 255})); + connect(digitalOutput1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{4, -7}, {22, -7}, {22, -6}, {42, -6}})); + annotation( + uses(OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2"), Modelica_DeviceDrivers(version = "1.5.0"))); + end ex4_led_blink; + end Led; + + package Push_button + extends Modelica.Icons.ExamplesPackage; + + model ex1_push_button_status + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {-60, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalInput digitalInput1(Pin = 12) annotation( + Placement(visible = true, transformation(origin = {0, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.BooleanValue booleanValue1 annotation( + Placement(visible = true, transformation(origin = {80, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(digitalInput1.y, booleanValue1.activePort) annotation( + Line(points = {{20, 0}, {54, 0}, {54, 0}, {58, 0}}, color = {255, 0, 255})); + connect(arduino1.boardConnector, digitalInput1.pinConnector) annotation( + Line(points = {{-60, 0}, {-20, 0}})); + Modelica.Utilities.Streams.print(String(booleanValue1.activePort)); + end ex1_push_button_status; + + model ex2_led_push_button + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-60, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalInput digitalInput1(Pin = 12) annotation( + Placement(visible = true, transformation(origin = {62, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(customBoard1.boardConnector, digitalInput1.pinConnector) annotation( + Line(points = {{0, 0}, {44, 0}, {44, 0}, {42, 0}})); + connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{-40, 0}, {0, 0}, {0, 0}, {0, 0}})); + connect(digitalInput1.y, digitalOutput1.u) annotation( + Line(points = {{82, 0}, {94, 0}, {94, -40}, {-92, -40}, {-92, 0}, {-80, 0}, {-80, 0}}, color = {255, 0, 255})); + end ex2_led_push_button; + end Push_button; + + package Ldr + extends Modelica.Icons.ExamplesPackage; + + model ex1_ldr_read + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {-60, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 19) annotation( + Placement(visible = true, transformation(origin = {-4.44089e-16, 4.44089e-16}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation( + Placement(visible = true, transformation(origin = {60, -8.88178e-16}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(analogInput1.y, realValue1.numberPort) annotation( + Line(points = {{20, 0}, {37, 0}}, color = {0, 0, 127})); + connect(arduino1.boardConnector, analogInput1.pinConnector) annotation( + Line(points = {{-60, 0}, {-20, 0}, {-20, 0}, {-20, 0}})); + Modelica.Utilities.Streams.print(String(realValue1.numberPort)); + annotation( + uses(Modelica(version = "3.2.2"))); + end ex1_ldr_read; + + + model ex2_ldr_led + extends Modelica.Icons.Example; + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 19) annotation( + Placement(visible = true, transformation(origin = {60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-70, 68}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.Constant const(k = 300) annotation( + Placement(visible = true, transformation(origin = {60, -70}, extent = {{20, -20}, {-20, 20}}, rotation = 0))); + Modelica.Blocks.Logical.Less less1 annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{20, -20}, {-20, 20}}, rotation = 0))); + OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(customBoard1.boardConnector, analogInput1.pinConnector) annotation( + Line(points = {{0, 20}, {40, 20}, {40, 20}, {40, 20}})); + connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{-40, 20}, {0, 20}, {0, 20}, {0, 20}})); + connect(const.y, less1.u2) annotation( + Line(points = {{38, -70}, {32, -70}, {32, -56}, {24, -56}}, color = {0, 0, 127})); + connect(less1.y, digitalOutput1.u) annotation( + Line(points = {{-22, -40}, {-92, -40}, {-92, 20}, {-80, 20}}, color = {255, 0, 255})); + connect(analogInput1.y, less1.u1) annotation( + Line(points = {{80, 20}, {90, 20}, {90, -40}, {24, -40}}, color = {0, 0, 127})); + end ex2_ldr_led; + + end Ldr; + + package DC_motor + extends Modelica.Icons.ExamplesPackage; + + model ex1_dcmotor_clock + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {60, 4.21885e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogOutput analogOutput1(MaxValue = 255, MinValue = 0, Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogOutput analogOutput2(MaxValue = 255, MinValue = 0, Pin = 10) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Constant const(k = 0) annotation( + Placement(visible = true, transformation(origin = {-60, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Pulse pulse1(amplitude = 255, period = 20, startTime = 5, width = 15) annotation( + Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(analogOutput2.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{20, -40}, {60, -40}, {60, 0}, {60, 0}})); + connect(analogOutput1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{20, 20}, {60, 20}, {60, 0}, {60, 0}, {60, 0}})); + connect(const.y, analogOutput2.u) annotation( + Line(points = {{-38, -40}, {-22, -40}, {-22, -40}, {-20, -40}}, color = {0, 0, 127})); + connect(pulse1.y, analogOutput1.u) annotation( + Line(points = {{-38, 20}, {-22, 20}, {-22, 20}, {-20, 20}}, color = {0, 0, 127})); + end ex1_dcmotor_clock; + + model ex2_dcmotor_both + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {60, 4.21885e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogOutput analogOutput1(MaxValue = 255, MinValue = 0, Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogOutput analogOutput2(MaxValue = 255, MinValue = 0, Pin = 10) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Pulse pulse1(amplitude = 255, period = 20, startTime = 5, width = 15) annotation( + Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Pulse pulse2(amplitude = 255, period = 20, startTime = 8, width = 10) annotation( + Placement(visible = true, transformation(origin = {-60, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(pulse2.y, analogOutput2.u) annotation( + Line(points = {{-38, -40}, {-20, -40}, {-20, -40}, {-20, -40}}, color = {0, 0, 127})); + connect(analogOutput2.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{20, -40}, {60, -40}, {60, 0}, {60, 0}})); + connect(analogOutput1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{20, 20}, {60, 20}, {60, 0}, {60, 0}, {60, 0}})); + connect(pulse1.y, analogOutput1.u) annotation( + Line(points = {{-38, 20}, {-22, 20}, {-22, 20}, {-20, 20}}, color = {0, 0, 127})); + end ex2_dcmotor_both; + + model ex3_dcmotor_loop + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {60, 4.21885e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogOutput analogOutput1(MaxValue = 255, MinValue = 0, Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, 18}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogOutput analogOutput2(MaxValue = 255, MinValue = 0, Pin = 10) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Pulse pulse1(amplitude = 255, period = 10, startTime = 5, width = 30) annotation( + Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Pulse pulse2(amplitude = 255, period = 10, startTime = 10, width = 20) annotation( + Placement(visible = true, transformation(origin = {-60, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(pulse1.y, analogOutput1.u) annotation( + Line(points = {{-38, 20}, {-20, 20}, {-20, 18}}, color = {0, 0, 127})); + connect(analogOutput1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{20, 18}, {20, 39}, {60, 39}, {60, 0}})); + connect(pulse2.y, analogOutput2.u) annotation( + Line(points = {{-38, -40}, {-20, -40}, {-20, -40}, {-20, -40}}, color = {0, 0, 127})); + connect(analogOutput2.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{20, -40}, {60, -40}, {60, 0}, {60, 0}})); + end ex3_dcmotor_loop; + end DC_motor; + + package Potentiometer + extends Modelica.Icons.ExamplesPackage; + + model ex1_pot_threshold + extends Modelica.Icons.Example; + OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 16) annotation( + Placement(visible = true, transformation(origin = {28, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-50, 90}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput2(Pin = 10) annotation( + Placement(visible = true, transformation(origin = {-50, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold = 0) annotation( + Placement(visible = true, transformation(origin = {70, 10}, extent = {{10, -10}, {-10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold2(threshold = 320) annotation( + Placement(visible = true, transformation(origin = {70, -30}, extent = {{10, -10}, {-10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold3(threshold = 900) annotation( + Placement(visible = true, transformation(origin = {70, -70}, extent = {{10, -10}, {-10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Xor xor1 annotation( + Placement(visible = true, transformation(origin = {30, -10}, extent = {{10, -10}, {-10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Xor xor2 annotation( + Placement(visible = true, transformation(origin = {30, -50}, extent = {{10, -10}, {-10, 10}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput3(Pin = 11) annotation( + Placement(visible = true, transformation(origin = {-50, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {-10, 50}, extent = {{-14, -14}, {14, 14}}, rotation = 0))); + equation + connect(analogInput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{18, 50}, {-10, 50}})); + connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{-40, 90}, {-10, 90}, {-10, 50}})); + connect(digitalOutput2.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{-40, 50}, {-10, 50}})); + connect(digitalOutput3.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{-40, 10}, {-10, 10}, {-10, 50}})); + connect(xor1.y, digitalOutput3.u) annotation( + Line(points = {{20, -10}, {-72, -10}, {-72, 10}, {-60, 10}, {-60, 10}}, color = {255, 0, 255})); + connect(xor2.y, digitalOutput2.u) annotation( + Line(points = {{20, -50}, {-80, -50}, {-80, 50}, {-60, 50}, {-60, 50}}, color = {255, 0, 255})); + connect(greaterEqualThreshold3.y, digitalOutput1.u) annotation( + Line(points = {{60, -70}, {-90, -70}, {-90, 90}, {-60, 90}, {-60, 90}}, color = {255, 0, 255})); + connect(greaterEqualThreshold3.y, xor2.u2) annotation( + Line(points = {{60, -70}, {52, -70}, {52, -58}, {42, -58}, {42, -58}, {42, -58}}, color = {255, 0, 255})); + connect(greaterEqualThreshold2.y, xor2.u1) annotation( + Line(points = {{60, -30}, {52, -30}, {52, -50}, {42, -50}, {42, -50}}, color = {255, 0, 255})); + connect(greaterEqualThreshold2.y, xor1.u2) annotation( + Line(points = {{60, -30}, {52, -30}, {52, -18}, {42, -18}, {42, -18}}, color = {255, 0, 255})); + connect(greaterEqualThreshold1.y, xor1.u1) annotation( + Line(points = {{60, 10}, {50, 10}, {50, -10}, {42, -10}, {42, -10}}, color = {255, 0, 255})); + connect(analogInput1.y, greaterEqualThreshold1.u) annotation( + Line(points = {{38, 50}, {94, 50}, {94, 10}, {82, 10}, {82, 10}}, color = {0, 0, 127})); + connect(analogInput1.y, greaterEqualThreshold2.u) annotation( + Line(points = {{38, 50}, {94, 50}, {94, -30}, {82, -30}, {82, -30}, {82, -30}}, color = {0, 0, 127})); + connect(analogInput1.y, greaterEqualThreshold3.u) annotation( + Line(points = {{38, 50}, {94, 50}, {94, -70}, {82, -70}, {82, -70}}, color = {0, 0, 127})); + annotation( + uses(OpenModelicaArduino(version = "1.2"))); + end ex1_pot_threshold; + end Potentiometer; + + package Thermistor + extends Modelica.Icons.ExamplesPackage; + + model ex1_therm_read + extends Modelica.Icons.Example; + OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 18) annotation( + Placement(visible = true, transformation(origin = {-4.44089e-16, 4.44089e-16}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {-59, -1}, extent = {{-21, -21}, {21, 21}}, rotation = 0))); + equation + connect(customBoard1.boardConnector, analogInput1.pinConnector) annotation( + Line(points = {{-58, 0}, {-20, 0}, {-20, 0}, {-20, 0}})); + Modelica.Utilities.Streams.print(String(analogInput1.y)); + end ex1_therm_read; + + model ex2_therm_buzzer + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 3) annotation( + Placement(visible = true, transformation(origin = {-60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1023, MinValue = 0, Pin = 18) annotation( + Placement(visible = true, transformation(origin = {60, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-70, 68}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.Constant const(k = 500) annotation( + Placement(visible = true, transformation(origin = {60, -70}, extent = {{20, -20}, {-20, 20}}, rotation = 0))); + Modelica.Blocks.Logical.Greater greater1 annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, -40}, extent = {{20, -20}, {-20, 20}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1 annotation( + Placement(visible = true, transformation(origin = {40, 60}, extent = {{20, -20}, {-20, 20}}, rotation = 0))); + equation + connect(analogInput1.y, realValue1.numberPort) annotation( + Line(points = {{80, 20}, {90, 20}, {90, 60}, {64, 60}, {64, 60}}, color = {0, 0, 127})); + connect(greater1.y, digitalOutput1.u) annotation( + Line(points = {{-22, -40}, {-94, -40}, {-94, 20}, {-80, 20}, {-80, 20}}, color = {255, 0, 255})); + connect(analogInput1.y, greater1.u1) annotation( + Line(points = {{80, 20}, {92, 20}, {92, -40}, {24, -40}, {24, -40}}, color = {0, 0, 127})); + connect(greater1.u2, const.y) annotation( + Line(points = {{24, -56}, {32, -56}, {32, -70}, {38, -70}, {38, -70}}, color = {0, 0, 127})); + connect(arduino1.boardConnector, analogInput1.pinConnector) annotation( + Line(points = {{0, 20}, {40, 20}})); + connect(digitalOutput1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{-40, 20}, {0, 20}})); + Modelica.Utilities.Streams.print(String(realValue1.numberPort)); + annotation( + uses(Modelica(version = "3.2.2"))); + end ex2_therm_buzzer; + end Thermistor; + + package Servo_motor + extends Modelica.Icons.ExamplesPackage; + + model ex1_servo_init + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {78, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.Servo servo1(InputUnit = OpenModelicaArduino.Internal.Types.ServoUnit.None, MaxPulse = 1000000, MinPulse = 500000, Pin = 9) annotation( + Placement(visible = true, transformation(origin = {20, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Constant const(k = 0.1667) annotation( + Placement(visible = true, transformation(origin = {-40, 20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(const.y, servo1.u) annotation( + Line(points = {{-18, 20}, {-4, 20}, {-4, 20}, {0, 20}}, color = {0, 0, 127})); + connect(servo1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{40, 20}, {76, 20}, {76, 18}, {78, 18}, {78, 20}})); + annotation( + uses(Modelica_DeviceDrivers(version = "1.5.0"), OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2"))); + end ex1_servo_init; + + model ex2_servo_reverse + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {78, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.Servo servo1(InputUnit = OpenModelicaArduino.Internal.Types.ServoUnit.None, MaxPulse = 1000000, MinPulse = 500000, Pin = 9) annotation( + Placement(visible = true, transformation(origin = {20, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Pulse pulse2(amplitude = 0.5, offset = 0.5, period = 2, startTime = 6, width = 50) annotation( + Placement(visible = true, transformation(origin = {-80, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Math.Product product1 annotation( + Placement(visible = true, transformation(origin = {-40, 1.77636e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Constant const(k = 0.5) annotation( + Placement(visible = true, transformation(origin = {-80, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(const.y, product1.u1) annotation( + Line(points = {{-58, 60}, {-36, 60}, {-36, 24}, {-80, 24}, {-80, 10}, {-64, 10}, {-64, 12}}, color = {0, 0, 127})); + connect(pulse2.y, product1.u2) annotation( + Line(points = {{-58, -60}, {-48, -60}, {-48, -24}, {-80, -24}, {-80, -12}, {-64, -12}, {-64, -12}}, color = {0, 0, 127})); + connect(product1.y, servo1.u) annotation( + Line(points = {{-18, 0}, {0, 0}, {0, 0}, {0, 0}}, color = {0, 0, 127})); + connect(servo1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{40, 0}, {78, 0}})); + annotation( + uses(Modelica_DeviceDrivers(version = "1.5.0"), OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2"))); + end ex2_servo_reverse; + + model ex3_servo_loop + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {78, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.Servo servo1(InputUnit = OpenModelicaArduino.Internal.Types.ServoUnit.None, MaxPulse = 1000000, MinPulse = 500000, Pin = 9) annotation( + Placement(visible = true, transformation(origin = {20, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.Ramp ramp1(duration = 10, height = 10, startTime = 5) annotation( + Placement(visible = true, transformation(origin = {-90, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Math.RealToInteger realToInteger1 annotation( + Placement(visible = true, transformation(origin = {-50, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.Constant const(k = 0.11) annotation( + Placement(visible = true, transformation(origin = {-70, 68}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Math.Product product1 annotation( + Placement(visible = true, transformation(origin = {-28, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Math.IntegerToReal integerToReal1 annotation( + Placement(visible = true, transformation(origin = {-10, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(integerToReal1.y, product1.u2) annotation( + Line(points = {{2, -70}, {14, -70}, {14, -36}, {-56, -36}, {-56, -6}, {-40, -6}, {-40, -6}}, color = {0, 0, 127})); + connect(realToInteger1.y, integerToReal1.u) annotation( + Line(points = {{-38, -70}, {-22, -70}, {-22, -70}, {-22, -70}}, color = {255, 127, 0})); + connect(ramp1.y, realToInteger1.u) annotation( + Line(points = {{-78, -70}, {-62, -70}}, color = {0, 0, 127})); + connect(const.y, product1.u1) annotation( + Line(points = {{-58, 68}, {-52, 68}, {-52, 6}, {-40, 6}, {-40, 6}}, color = {0, 0, 127})); + connect(product1.y, servo1.u) annotation( + Line(points = {{-16, 0}, {0, 0}, {0, 0}, {0, 0}}, color = {0, 0, 127})); + connect(servo1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{40, 0}, {78, 0}})); + annotation( + uses(Modelica_DeviceDrivers(version = "1.5.0"), OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2"))); + end ex3_servo_loop; + + model ex4_servo_pot + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {60, 3.10862e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.Servo servo1(InputUnit = OpenModelicaArduino.Internal.Types.ServoUnit.None, MaxPulse = 1000000, MinPulse = 500000, Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-3.55271e-15, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogInput analogInput1(MaxValue = 1, MinValue = 0, Pin = 16) annotation( + Placement(visible = true, transformation(origin = {-60, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(analogInput1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{-80, 0}, {-92, 0}, {-92, -52}, {60, -52}, {60, 0}, {60, 0}})); + connect(servo1.pinConnector, arduino1.boardConnector) annotation( + Line(points = {{20, 0}, {62, 0}, {62, 0}, {60, 0}, {60, 0}})); + connect(analogInput1.y, servo1.u) annotation( + Line(points = {{-40, 0}, {-16, 0}, {-16, 0}, {-20, 0}}, color = {0, 0, 127})); + annotation( + uses(OpenModelicaArduino(version = "1.2"), Modelica_DeviceDrivers(version = "1.5.0"))); + end ex4_servo_pot; + end Servo_motor; +end ArduinoExamples;
\ No newline at end of file diff --git a/OpenModelicaArduino/package.mo b/OpenModelicaArduino/package.mo index 5d43efc..de10e5b 100644 --- a/OpenModelicaArduino/package.mo +++ b/OpenModelicaArduino/package.mo @@ -266,6 +266,27 @@ end AnalogOutput; <p>When running the simulation, you will get a list of the capabilities of every pin. If you want to stop showing the capabilities every time you simulate, you need to set the property "ShowCapabilities" to false.</p></html>", revisions = ""), Icon(coordinateSystem( initialScale = 0.1, grid = {10, 10}), graphics = {Polygon(origin = {10.562, 9.352}, fillColor = {42, 85, 94}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-85.751, 70.648}, {-102.737, 66.761}, {-105.751, 50.648}, {-105.751, -69.352}, {-99.475, -85.465}, {-85.751, -89.352}, {74.249, -89.352}, {81.746, -83.29}, {84.249, -76.041}, {84.249, 34.141}, {79.249, 43.202}, {54.249, 43.202}, {52.314, 67.486}, {31.729, 70.648}, {-85.751, 70.648}}, smooth = Smooth.Bezier), Rectangle(origin = {-71.211, 40}, fillColor = {106, 108, 116}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-32.24, -20}, {32.24, 20}}, radius = 10), Rectangle(origin = {-79.366, -45.041}, fillPattern = FillPattern.Solid, extent = {{-25.915, -15.041}, {25.915, 15.041}}, radius = 10), Text(origin = {0, -130}, extent = {{-100, -20}, {100, 20}}, textString = "%Port"), Text(origin = {5, -30}, lineColor = {255, 255, 255}, extent = {{-75, 30}, {75, -30}}, textString = "Leonardo")}), Diagram(coordinateSystem( initialScale = 0.1, grid = {10, 10}), graphics = {Polygon(origin = {10.562, 9.352}, fillColor = {42, 85, 94}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-85.751, 70.648}, {-102.737, 66.761}, {-105.751, 50.648}, {-105.751, -69.352}, {-99.475, -85.465}, {-85.751, -89.352}, {74.249, -89.352}, {81.746, -83.29}, {84.249, -76.041}, {84.249, 34.141}, {79.249, 43.202}, {54.249, 43.202}, {52.314, 67.486}, {31.729, 70.648}, {-85.751, 70.648}}, smooth = Smooth.Bezier), Rectangle(origin = {-71.211, 40}, fillColor = {106, 108, 116}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-32.24, -20}, {32.24, 20}}, radius = 10), Rectangle(origin = {-79.366, -45.041}, fillPattern = FillPattern.Solid, extent = {{-25.915, -15.041}, {25.915, 15.041}}, radius = 10), Ellipse(origin = {-8.451, 32.225}, lineColor = {255, 255, 255}, fillColor = {42, 85, 94}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-15, -12.225}, {15, 12.225}}, endAngle = 360), Ellipse(origin = {21.55, 32.22}, lineColor = {255, 255, 255}, fillColor = {42, 85, 94}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-15, -12.23}, {15, 12.23}}, endAngle = 360), Text(origin = {-5, -15}, lineColor = {255, 255, 255}, extent = {{-75, 25}, {95, -35}}, textString = "Leonardo", textStyle = {TextStyle.Bold})}), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Polygon(visible = true, origin = {10.751, 9.352}, fillColor = {42, 85, 94}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-85.751, 70.648}, {-102.737, 66.761}, {-105.751, 50.648}, {-105.751, -69.352}, {-99.475, -85.465}, {-85.751, -89.352}, {74.249, -89.352}, {81.746, -83.29}, {84.249, -76.041}, {84.249, 34.141}, {79.249, 43.202}, {54.249, 43.202}, {52.314, 67.486}, {31.729, 70.648}}, smooth = Smooth.Bezier), Rectangle(visible = true, origin = {-71.211, 40}, fillColor = {106, 108, 116}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-32.24, -20}, {32.24, 20}}, radius = 10), Rectangle(visible = true, origin = {-79.366, -45.041}, fillPattern = FillPattern.Solid, extent = {{-25.915, -15.041}, {25.915, 15.041}}, radius = 10), Rectangle(visible = true, origin = {0.725, 70}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-54.177, -6.186}, {54.177, 6.186}}, radius = 10), Rectangle(visible = true, origin = {22.372, -63.814}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-64.177, -6.186}, {64.177, 6.186}}, radius = 10), Rectangle(visible = true, origin = {25.52, -30}, fillPattern = FillPattern.Solid, extent = {{-51.029, -13.424}, {51.029, 13.424}}, radius = 10), Rectangle(visible = true, origin = {76.549, -63.624}, fillColor = {250, 105, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {66.549, -63.624}, fillColor = {243, 134, 48}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {56.549, -63.624}, fillColor = {250, 105, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {46.549, -63.624}, fillColor = {243, 134, 48}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {36.549, -63.624}, fillColor = {250, 105, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {26.549, -63.624}, fillColor = {243, 134, 48}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {46.549, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {36.549, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {26.549, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {16.549, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {6.549, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-3.451, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-13.451, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-23.451, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-33.451, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-43.451, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-33.451, -63.624}, fillColor = {204, 208, 224}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-23.451, -63.624}, fillColor = {204, 208, 224}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-13.451, -63.624}, fillColor = {204, 208, 224}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-3.451, -63.624}, fillColor = {204, 208, 224}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Ellipse(visible = true, origin = {-8.451, 43.801}, lineColor = {255, 255, 255}, fillColor = {42, 85, 94}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-15, -12.225}, {15, 12.225}}), Ellipse(visible = true, origin = {21.549, 43.801}, lineColor = {255, 255, 255}, fillColor = {42, 85, 94}, fillPattern = FillPattern.Solid, lineThickness = 5, extent = {{-15, -12.225}, {15, 12.225}}), Text(visible = true, origin = {10, 23.151}, extent = {{-40, -10}, {40, 10}}, textString = "Leonardo")})); end ArduinoLeonardo; +model customBoard + parameter Internal.Types.SerialPort Port = "COM1" "Name of the serial port"; + parameter Boolean ShowPinCapabilities = true "Set to true if you want to see the capabilities of the pins in your board"; + parameter Boolean UseDTR = false "Some boards like Arduino Leonardo require UseDTR=true"; + parameter String BoardName = "[Board Name]" "Name of the development board/Microcontroller you are using"; + OpenModelicaArduino.Internal.ExternalFunctions.FirmataBoardObject board = Internal.ExternalFunctions.FirmataBoardObject.constructor(Port, ShowPinCapabilities, integer(UpdatePeriod * 1000), BaudRate, UseDTR); + OpenModelicaArduino.Internal.Interfaces.BoardConnector boardConnector annotation(Placement(visible = true, transformation(origin = {-90, -12.256}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {0, 0}, extent = {{-100, -100}, {100, 100}}, rotation = 0))); + protected + discrete Integer BoardId(start = -1) "Board Identifier. Initialized automatically keep as -1."; + constant Modelica.SIunits.Time UpdatePeriod = 0.01 "Sampling interval. The standard Firmata has a maximum sampling period of 10 ms (0.01 s)"; + constant Integer BaudRate = 57600 "Baud rate used to communicate with the board"; +equation + when initial() then + BoardId = Internal.ExternalFunctions.getBoardId(board); + end when; + when sample(0, UpdatePeriod) then + OpenModelicaArduino.Internal.ExternalFunctions.updateBoard(BoardId); + end when; + boardConnector = BoardId; + annotation(Icon(coordinateSystem( initialScale = 0.1, grid = {10, 10}), graphics = {Rectangle(fillColor = {0, 85, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-95, 90}, {95, -70}}, radius = 10), Text(origin = {0, 20}, lineColor = {255, 255, 255}, extent = {{-85, 40}, {85, -40}}, textString = "%BoardName"), Text(origin = {0, -80}, extent = {{-50, 20}, {50, -20}}, textString = "Port: %Port")}), Diagram(coordinateSystem( initialScale = 0.1, grid = {10, 10}), graphics = {Rectangle(fillColor = {0, 85, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-95, 80}, {95, -80}}, radius = 10), Text( lineColor = {255, 255, 255}, extent = {{-85, 35}, {85, -35}}, textString = "%BoardName")})); +end customBoard; annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Polygon(visible = true, origin = {12.096, 9.352}, fillColor = {0, 128, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-85.75100000000001, 70.648}, {-102.737, 66.761}, {-105.751, 50.648}, {-105.751, -69.352}, {-99.47499999999999, -85.465}, {-85.75100000000001, -89.352}, {74.249, -89.352}, {81.746, -83.29000000000001}, {86.32899999999999, -74.352}, {84.249, 34.141}, {82.185, 50.648}, {74.732, 67.486}, {52.373, 70.648}, {31.729, 70.648}}, smooth = Smooth.Bezier), Rectangle(visible = true, origin = {-69.67700000000001, 40}, fillColor = {106, 108, 116}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-32.24, -20}, {32.24, 20}}, radius = 10), Rectangle(visible = true, origin = {-77.83199999999999, -45.041}, fillPattern = FillPattern.Solid, extent = {{-25.915, -15.041}, {25.915, 15.041}}, radius = 10), Rectangle(visible = true, origin = {24.177, 70}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-54.177, -6.186}, {54.177, 6.186}}, radius = 10), Rectangle(visible = true, origin = {23.906, -63.814}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-64.17700000000001, -6.186}, {64.17700000000001, 6.186}}, radius = 10), Rectangle(visible = true, origin = {21.91, 0}, fillPattern = FillPattern.Solid, extent = {{-28.09, -25}, {28.09, 25}}, radius = 10), Rectangle(visible = true, origin = {78.083, -63.624}, fillColor = {250, 105, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {68.083, -63.624}, fillColor = {243, 134, 48}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {58.083, -63.624}, fillColor = {250, 105, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {48.083, -63.624}, fillColor = {243, 134, 48}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {38.083, -63.624}, fillColor = {250, 105, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {28.083, -63.624}, fillColor = {243, 134, 48}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {70.00100000000001, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {60.001, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {50.001, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {40.001, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {30.001, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {20.001, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {10.001, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {0.001, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-9.999000000000001, 70}, fillColor = {167, 219, 216}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-19.999, 70}, fillColor = {105, 210, 231}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-31.917, -63.624}, fillColor = {204, 208, 224}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-21.917, -63.624}, fillColor = {204, 208, 224}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-11.917, -63.624}, fillColor = {204, 208, 224}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50), Rectangle(visible = true, origin = {-1.917, -63.624}, fillColor = {204, 208, 224}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, borderPattern = BorderPattern.Engraved, extent = {{-4.118, -3.624}, {4.118, 3.624}}, radius = 50)}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); @@ -498,6 +519,42 @@ end BlinkLed; <p><img src=\"modelica://OpenModelicaArduino/Resources/Images/StandardFirmata.png\" alt=\"\" /></p></html>", revisions = ""), Diagram(coordinateSystem(extent = {{-50, -50}, {50, 50}}, initialScale = 0.1, grid = {5, 5}))); end UsingStandardFirmata; + model DCMotorWithPWM + extends Modelica.Icons.Example; + OpenModelicaArduino.Boards.customBoard customBoard1(BoardName = "Arduino UNO", Port = "/dev/ttyACM0") annotation( + Placement(visible = true, transformation(origin = {13, 29}, extent = {{-25, -25}, {25, 25}}, rotation = 0))); + Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( + Placement(visible = true, transformation(origin = {54, 78}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogOutput analogOutput1(MaxValue = 255, Pin = 9) annotation( + Placement(visible = true, transformation(origin = {-57, 29}, extent = {{-15, -15}, {15, 15}}, rotation = 0))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput1(Pin = 6) annotation( + Placement(visible = true, transformation(origin = {-45, -23}, extent = {{-13, -13}, {13, 13}}, rotation = 90))); + OpenModelicaArduino.Pins.DigitalOutput digitalOutput2(Pin = 7) annotation( + Placement(visible = true, transformation(origin = {50, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 90))); + Modelica.Blocks.Sources.BooleanConstant booleanConstant1(k = true) annotation( + Placement(visible = true, transformation(origin = {-70, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanConstant booleanConstant2(k = false) annotation( + Placement(visible = true, transformation(origin = {14, -74}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + OpenModelicaArduino.Pins.AnalogInput analogInput1(Pin = 16) annotation( + Placement(visible = true, transformation(origin = {-56, 74}, extent = {{-14, -14}, {14, 14}}, rotation = 0))); + equation + connect(analogInput1.y, analogOutput1.u) annotation( + Line(points = {{-42, 74}, {-20, 74}, {-20, 52}, {-90, 52}, {-90, 28}, {-72, 28}, {-72, 30}}, color = {0, 0, 127})); + connect(analogInput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{-70, 74}, {-88, 74}, {-88, 92}, {12, 92}, {12, 30}, {14, 30}})); + connect(digitalOutput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{-45, -10}, {-44.75, -10}, {-44.75, -2}, {14, -2}, {14, 30}})); + connect(booleanConstant1.y, digitalOutput1.u) annotation( + Line(points = {{-58, -70}, {-46, -70}, {-46, -36}, {-45, -36}}, color = {255, 0, 255})); + connect(booleanConstant2.y, digitalOutput2.u) annotation( + Line(points = {{26, -74}, {50, -74}, {50, -40}, {49, -40}, {49, -38}, {50, -38}}, color = {255, 0, 255})); + connect(digitalOutput2.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{50, -18}, {50, 30}, {14, 30}})); + connect(analogOutput1.pinConnector, customBoard1.boardConnector) annotation( + Line(points = {{-42, 30}, {13, 30}, {13, 29}})); + annotation( + uses(OpenModelicaArduino(version = "1.2"), Modelica(version = "3.2.2"), Modelica_DeviceDrivers(version = "1.5.0"))); + end DCMotorWithPWM; annotation(Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); end Examples; diff --git a/OpenModelicaArduino/package.order b/OpenModelicaArduino/package.order index 5da4d2b..5c5caaf 100644 --- a/OpenModelicaArduino/package.order +++ b/OpenModelicaArduino/package.order @@ -3,3 +3,4 @@ Pins Boards Examples Internal +ArduinoExamples |