Show last authors
1 = Program Arduino with SCCharts =
2
3
4
5 {{toc minLevel="2"/}}
6
7 ----
8
9 == Overview ==
10
11 Arduino is a project and community wich creates open-source software and open-source hardware. The Arduino boards and software are well suited for novices and expierenced programmers alike to create digital devices. In the following we will see how to develop applications for the Arduino boards using SCCharts together with the [[Arduino Eclipse Plugin>>url:http://eclipse.baeyens.it/||shape="rect"]]. Therefore we will first download and setup the development environment and afterwards create and upload a small example project.
12
13 ----
14
15 == Download and Configure KIELER
16 ==
17
18 Download and unpack the nightly build of KIELER for your OS. It is available at the [[doc:Downloads]] page.\\
19
20 **Note:** Java 1.8 is needed on all operating systems. With Java 1.7 not all plugins of KIELER will be loaded. **Furthermore on Windows**, you will need to download the **32 Bit version of KIELER** – even if you have a 64 bit operating system! Otherwise flashing the brick and uploading to the brick will fail.
21
22 === The Arduino Eclipse Plugin ===
23
24 There is an Eclipse plugin for Arduino, which makes it easy to create and deploy projects and to use the IDE features of the C/C++ Development Tools (CDT) when programming Arduino.
25
26 You have to install the plugin manually via **Help > Install new Software... **. Use the following update site: [[http:~~/~~/eclipse.baeyens.it/nightly>>url:http://eclipse.baeyens.it/nightly||shape="rect"]]
27
28 The installation might take a few minutes because it will install the Arduino Tools as well as required software such as the CDT. Furthermore it will download the newest version of the Arduino software and libraries.
29
30 ----
31
32 == Creating an Example Project ==
33
34 The following shows how to create a project, which will turn an LED on and off repeatedly.
35
36 === Create a new project: ===
37
38 1. Choose //File > New > Project > KIELER SCCharts > SCCharts Project//
39 1. In the project creation wizard that opens, select //Arduino// as environment and hit //finish//
40 1. The project wizard from the Arduino Eclipse Plugin opens. Set the project name to //Blinky// and click //next//.
41 1. Set the configuration for your Arduino board. In the field //Upload Protocol// select //Default//.
42 These settings can be changed later in the project preferences (Right click on project > Preferences > Arduino)
43 1. Click //finish//.
44 1. The project is created and the model file is opened in an editor (This might take a few seconds).
45
46 === Edit the model: ===
47
48 Change the contents of the model file to the following code and save it.
49
50 {{code language="sct" theme="Eclipse" title="Floodlight.sct"}}
51 scchart BlinkyModel {
52
53 @Wrapper Clock, "500"
54 input bool clock;
55
56 @Wrapper DigitalWrite, "13"
57 output bool light;
58
59 initial state lightOff
60 --> lightOn with clock / light = true;
61
62 state lightOn
63 --> lightOff with clock / light = false;
64 }
65 {{/code}}
66
67 This model will start in the state lightOff. If the variable //clock// is true, it will switch its state, going from off to on and from on to off. Thereby it sets the light variable so that the led will blink.
68
69 The annotations on the input and output variable are used to define which wrapper code is used to set / read them. **@Wrapper Clock, "500"** will set the input variable to true for one tick every 500ms. **@Wrapper DigitalWrite, "13"** will set pin 13 to HIGH if the variable is true and to LOW if it is false. We assume that an **LED is connected** to the Arduino board on **pin 13**.
70
71 The available wrapper code snippets are defined in the //snippets// directory of the project in ftl files (FreeMarker template files). The table below gives an overview of the available wrapper code snippets.
72
73 **Note: **To view ftl files with highlighting, you may want to install the //FreeMarker IDE// feature from the JBoss Tools. However, this is not necessary to work with KIELER. JBoss Tools is available in the Eclipse Market Place and via update site. The update site for Eclipse Luna is [[http:~~/~~/download.jboss.org/jbosstools/updates/stable/luna/>>url:http://download.jboss.org/jbosstools/updates/stable/luna/||shape="rect"]] . Note that only the //FreeMarker IDE// feature is required (Abridged JBoss Tools > FreeMarker IDE).**
74 **
75
76 === Launch the project: ===
77
78 With the mouse over the SCT file in the project explorer, perform //Right Click > Run As > KiCo Compilation.//
79
80 A launch config is created, which compiles the model to C code and creates wrapper code from the annotations in the model file. Afterwards this output is compiled and deployed to the Arduino board, by using the launch shortcut from the Arduino Plugin. If any errors occur, you can see them in the Console View.
81
82 For a deeper understanding of the project launch and initialization, take a look at the [[wiki page for Prom>>url:http://rtsys.informatik.uni-kiel.de/confluence/pages/viewpage.action?pageId=13762626||shape="rect"]].
83
84 === Available Wrapper Code Snippets ===
85
86 There are several wrapper code snippets that can be used as annotations on input and output variables in the model file. These snippets are inserted in the main file template as part of the project launch. The available snippets are listed below.
87
88 |=(((
89 Snippet Name and Parameters
90 )))|=(((
91 Description
92 )))|=(((
93 Use on
94 )))|=(% colspan="1" %)(% colspan="1" %)
95 (((
96 Variable type
97 )))|=(((
98 Remark
99 )))|=(% colspan="1" %)(% colspan="1" %)
100 (((
101 Defined in File
102 )))
103 |(% colspan="1" %)(% colspan="1" %)
104 (((
105 **Clock,** milliseconds
106 )))|(% colspan="1" %)(% colspan="1" %)
107 (((
108 Sets a variable to true if the time in milliseconds passed.
109 )))|(% colspan="1" %)(% colspan="1" %)
110 (((
111 input
112 )))|(% colspan="1" %)(% colspan="1" %)
113 (((
114 bool
115 )))|(% colspan="1" %)(% colspan="1" %)
116 (((
117 See also ResetClock.
118 )))|(% colspan="1" %)(% colspan="1" %)
119 (((
120 timing.ftl
121 )))
122 |(% colspan="1" %)(% colspan="1" %)
123 (((
124 **ResetClock,** clockVariableName, autoFalse
125 )))|(% colspan="1" %)(% colspan="1" %)
126 (((
127 Resets a clock, such that the full time intervall of the clock has to elapse, before the clock will be set to true again.
128
129 If autoFalse is true, the reset variable will be set to false automatically.
130 )))|(% colspan="1" %)(% colspan="1" %)
131 (((
132 output
133 )))|(% colspan="1" %)(% colspan="1" %)
134 (((
135 bool
136 )))|(% colspan="1" %)(% colspan="1" %)
137 (((
138 autoFalse is true per default.
139 )))|(% colspan="1" %)(% colspan="1" %)
140 (((
141 timing.ftl
142 )))
143 |(% colspan="1" %)(% colspan="1" %)
144 (((
145 **Time**
146 )))|(% colspan="1" %)(% colspan="1" %)
147 (((
148 Reads the elapsed time since program start in milliseconds.
149 )))|(% colspan="1" %)(% colspan="1" %)
150 (((
151 input
152 )))|(% colspan="1" %)(% colspan="1" %)
153 (((
154 unsigned
155 )))|(% colspan="1" %)(% colspan="1" %)
156 (((
157
158 )))|(% colspan="1" %)(% colspan="1" %)
159 (((
160 timing.ftl
161 )))
162 |(% colspan="1" %)(% colspan="1" %)
163 (((
164 **TickDuration,** targetInMilliseconds
165 )))|(% colspan="1" %)(% colspan="1" %)
166 (((
167 Delays the execution until the tick loop takes at least as long as the given target duration.
168
169 The input variable is set to the actual tick loop duration.
170 )))|(% colspan="1" %)(% colspan="1" %)
171 (((
172 input
173 )))|(% colspan="1" %)(% colspan="1" %)
174 (((
175 unsigned
176 )))|(% colspan="1" %)(% colspan="1" %)
177 (((
178 Should be used on the very first input variable in the model, so that waiting is the last action in the tick loop.
179 )))|(% colspan="1" %)(% colspan="1" %)
180 (((
181 timing.ftl
182 )))
183 |(% colspan="1" %)(% colspan="1" %)
184 (((
185 **Delay
186 **
187 )))|(% colspan="1" %)(% colspan="1" %)
188 (((
189 Lets the program delay the time in milliseconds of the variable value.
190 )))|(% colspan="1" %)(% colspan="1" %)
191 (((
192 output
193 )))|(% colspan="1" %)(% colspan="1" %)
194 (((
195 unsigned
196 )))|(% colspan="1" %)(% colspan="1" %)
197 (((
198
199 )))|(% colspan="1" %)(% colspan="1" %)
200 (((
201 timing.ftl
202 )))
203 |(% colspan="1" %)(% colspan="1" %)
204 (((
205 **SerialRate,** baud**
206 **
207 )))|(% colspan="1" %)(% colspan="1" %)
208 (((
209 Sets the baud rate for communication. This is done only in the initilization, not in the loop.
210 )))|(% colspan="1" %)(% colspan="1" %)
211 (((
212 output
213 )))|(% colspan="1" %)(% colspan="1" %)
214 (((
215 unsigned
216 )))|(% colspan="1" %)(% colspan="1" %)
217 (((
218
219 )))|(% colspan="1" %)(% colspan="1" %)
220 (((
221 print.ftl
222 )))
223 |(% colspan="1" %)(% colspan="1" %)
224 (((
225 **Print**
226 )))|(% colspan="1" %)(% colspan="1" %)
227 (((
228 Prints a string variable if the string is not 0.
229 )))|(% colspan="1" %)(% colspan="1" %)
230 (((
231 output
232 )))|(% colspan="1" %)(% colspan="1" %)
233 (((
234 string
235 )))|(% colspan="1" %)(% colspan="1" %)
236 (((
237
238 )))|(% colspan="1" %)(% colspan="1" %)
239 (((
240 print.ftl
241 )))
242 |(((
243 **DigitalWrite,** pin
244 )))|(((
245 Sets the pin value to HIGH if the variable is true and to LOW otherwise.
246 )))|(((
247 output
248 )))|(((
249 bool
250 )))|(((
251
252 )))|(((
253 read_and_write.ftl
254 )))
255 |(((
256 **DigitalRead,** pin
257 )))|(((
258 Sets the variable value to the pin state (HIGH or LOW).
259 )))|(((
260 input
261 )))|(((
262 bool
263 )))|(((
264
265 )))|(((
266 read_and_write.ftl
267 )))
268 |(((
269 **Analog**Write, pin
270 )))|(((
271 Sets the voltage of the given analog IO pin via pulse-width modulation (PWM). Integers from 0 to 1023 are linearly mapped to an pseudo voltage from 0V to 5V.
272 )))|(((
273 output
274 )))|(((
275 int
276 )))|(((
277
278 )))|(((
279 read_and_write.ftl
280 )))
281 |(% colspan="1" %)(% colspan="1" %)
282 (((
283 **AnalogRead,** pin
284 )))|(% colspan="1" %)(% colspan="1" %)
285 (((
286 Reads the value of the given analog IO pin. Voltage from 0V to 5V is linearly mapped to an integer value from 0 to 1023.
287 )))|(% colspan="1" %)(% colspan="1" %)
288 (((
289 input
290 )))|(% colspan="1" %)(% colspan="1" %)
291 (((
292 int
293 )))|(% colspan="1" %)(% colspan="1" %)
294 (((
295
296 )))|(% colspan="1" %)(% colspan="1" %)
297 (((
298 read_and_write.ftl
299 )))
300
301 ----
302
303 == Using the Serial Monitor ==
304
305 The Arduino Eclipse Plugin has a Serial Monitor (Window > Show View > Other > Arduino > Serial monitor view). Here you can open connections to serial ports and read and write to them.
306
307 To open a connection, click the plus button and select the serial port you want to conenct to as well as the serial rate that is used to transmit data. Click //OK.//
308
309 The output of all open connections will be combined in the text editor.
310
311 [[image:attach:Screenshot_20160509_125654.png]]
312
313 ----
314
315 == Problem Solving ==
316
317 The following presents typical issues and how to solve them.
318
319 |=(((
320 Issue
321 )))|=(((
322 Typical Error Messages
323 )))|=(((
324 Description
325 )))|=(((
326 Solution
327 )))
328 |(((
329 The upload protocol is not set
330 )))|(((
331 avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)
332 )))|(((
333 You launch a project and there is no different behaviour although there are changes in code.
334
335 You try to launch the project and compilation finishes successful. However The upload fails because the upload protocol is not correctly configured.
336 )))|(((
337 Go to the project properties and select //Default// in the field //Upload Protocol// (Right click on project > Properties > Arduino > Arduino Board Selection)
338 )))