Skip to content

Commit 0a69f8a

Browse files
committed
Initial commit - Getting started Din Simul8 content update
1 parent c8de4b3 commit 0a69f8a

File tree

8 files changed

+56
-49
lines changed

8 files changed

+56
-49
lines changed

content/hardware/08.edu/solution-and-kits/din-simul8/tutorials/getting-started/content.md

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: 'Getting Started with DIN Simul8'
2+
title: 'Getting Started with Arduino® DIN Simul8'
33
difficulty: beginner
4-
description: 'This short guide helps you connecting the board to a PLC of the Opta® family and test some basic functionality.'
4+
description: 'This tutorial will help you connect the board to a PLC from the Opta® family and test some basic functionality.'
55
tags:
66
- Simul8
77
- DIN
@@ -13,20 +13,20 @@ software:
1313
- ide-v2
1414
---
1515

16-
![The board.](assets/title.png)
16+
![ ](assets/title.png)
1717

18-
In this tutorial you'll be guided in connecting the **Arduino® DIN Simul8** to the **Arduino Opta® WiFi**, and trigger some basic functions.
18+
In this tutorial, you will learn how to connect the **Arduino® DIN Simul8** to the **Arduino Opta® WiFi** and implement basic functions.
1919

2020
## Hardware & Software Requirements
2121

2222
### Hardware
2323

24-
- Arduino® DIN Simul8
2524
- [Arduino Opta® WiFi](https://store.arduino.cc/products/opta-wifi)
25+
- Arduino® DIN Simul8
2626
- USB-C® cable
27-
- 24 V power supply with barrel plug adapter
28-
- 8x wire for signal
29-
- 2x wire for power distribution
27+
- 24 V AC/DC power supply with barrel plug adapter
28+
- Wiring cable for signal (x8)
29+
- Wiring cable for power distribution (x2)
3030

3131
### Software
3232

@@ -36,31 +36,30 @@ In this tutorial you'll be guided in connecting the **Arduino® DIN Simul8** to
3636

3737
![Render front](assets/Simul-8-Top-with-Adaptor.png)
3838

39-
DIN Simul8 is a digital-input-simulator and power distribution board for the PLC of the Opta family. It provides eight toggle switches (0 - 10 V output) and four screw terminal for bringing the 24 V and the GROUND easily to the PLC or other boards.
39+
The **DIN Simul8** is a digital input simulator and power distribution board designed for the Opta PLC family. It features eight toggle switches (0 - 10 V output) and four screw terminals, making it easy to supply 24 VDC and GND to the PLC or other boards.
4040

41-
If you have any problems using the Opta WiFi you can read its [manual](https://docs.arduino.cc/tutorials/opta/user-manual/) before proceeding.
41+
***If you encounter any issues with the Opta WiFi, refer to its [user manual](https://docs.arduino.cc/tutorials/opta/user-manual/) before continuing.***
4242

4343
### Connections
4444

45-
To connect the DIN Simul8 to the PLC you'll need 8 wires for the signal and two for the power.
46-
47-
![connections scheme](assets/connections_scheme.png)
45+
To connect the DIN Simul8 to the PLC, you will need eight wiring cables for the signal connections and two for power.
4846

49-
Connections are super important in an industrial project, first of all **disconnect the power plug** and then connect all the pins using cable with lugs, or be careful that no copper part of the cable touch other pins.
47+
![Connection diagram](assets/wiring.png)
5048

51-
![Overall connections](assets/connections_all.png)
49+
1. Connect the power pins: +24V and GND.
50+
2. Connect all the signal pins.
5251

53-
1. Connect the power pins: +24V and GND
54-
2. Connect all the signal pins
52+
***It is recommended to use __AWG 17__ cables for all connections to ensure optimal performance and safety.***
5553

56-
![Detail connections](assets/connections.png)
54+
Proper connections are crucial in an industrial project. **Always disconnect the power source before making any connections.** Use cables with lugs, or ensure that no exposed copper parts of the cables come into contact with other pins.
5755

56+
![Wiring precaution](assets/wiring_caution.png)
5857

5958
## Upload Test Code
6059

61-
Firstly we have to test if the components and the connections works as excepted. Let's print on the [Serial Monitor](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-serial-monitor/) what arrives to the inputs.
60+
Before proceeding, it is necessary to test if the components and connections are working as expected. We can do this by printing the input values to the [Serial Monitor](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-serial-monitor/).
6261

63-
The Opta WiFi has eight inputs ports, at the top, named from `I1` to `I8`. They are mapped to pin `A0` to `A7`. Let's assign to each of them a variable with the name of the port on the Opta WiFi, easier to remember, we can use the [#define](https://www.arduino.cc/reference/en/language/structure/further-syntax/define/) function, like this:
62+
The Opta WiFi has eight input ports, labeled `I1` to `I8` at the top. These are mapped to pins `A0` through `A7`. To make it easier to reference each input, we can assign a variable to each port using the [`#define`](https://www.arduino.cc/reference/en/language/structure/further-syntax/define/) directive, as shown below:
6463

6564
```arduino
6665
#define pin_I1 A0
@@ -77,17 +76,15 @@ The Opta WiFi has eight inputs ports, at the top, named from `I1` to `I8`. They
7776
| `I7` | `A6`/`PIN_A6` | `pin_I7` |
7877
| `I8` | `A7`/`PIN_A7` | `pin_I8` |
7978

80-
From now on we can refer to the port `I1` of the Opta WiFi using the `pin_I1` variable.
79+
Now, you can refer to the `I1` port on the Opta WiFi using the `pin_I1` variable.
8180

82-
83-
To read what's arriving on each input port, we can use the [digitalRead](https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/) function, inside the `Serial.print` command:
81+
To read the received values at each input port, you can use the [`digitalRead`](https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/) function within the `Serial.print` command:
8482

8583
```arduino
8684
Serial.print(digitalRead(pin_I1));
8785
```
8886

89-
Now let's do this for each input port, dividing each value with a comma `,`.
90-
Here the full code:
87+
Next, lets do this for each input port, separating each value with a comma (`,`). Here is the complete code:
9188

9289
```arduino
9390
#define pin_I1 A0
@@ -130,25 +127,28 @@ void loop() {
130127
131128
```
132129

133-
>**Don't forget to** initialize the Serial communication with the Serial.begin command in the setup.
130+
***Remember to initialize the Serial communication with the `Serial.begin` command in the `setup` function.***
131+
132+
***Use `Serial.println` for the last `Serial.print` to ensure the output wraps to a new line, making it easier to read.***
134133

135-
>**Don't forget to** call the the last `Serial.print` as `Serial.println`, in order to print a new line and wrap the text to make readable.
134+
***Add a delay, such as __100ms__, to ensure stable communication over Serial.***
136135

137-
>**Don't forget to** put some delay, like 100ms in order to have a stable communication over serial.
136+
Each switch on the DIN Simul8 outputs 0 V when OFF and 10 V when ON. The `digitalRead()` function will read `0` for 0 V and `1` for 10 V.
138137

139-
Each switch in the DIN Simul8 outputs 0 V when OFF and 10 V when ON. The `digitalRead()` function will read 0 for 0 V and 1 for 10 V.
140-
If you switch on the toggle switches 1-3-5-7 and leave off the 2-4-6-8, like in the following image:
138+
For example, if you turn on toggle switches 1, 3, 5, and 7 while leaving 2, 4, 6, and 8 off, as shown in the image below:
141139

142-
![Toggle switches 1-3-5-7](assets/step1_switches.png)
140+
![Toggle switches 1-3-5-7](assets/led_toggles.png)
143141

144-
The output should be like this:
142+
The output should look like this:
145143

146144
![Serial Monitor output](assets/step1_serial-monitor.png)
147145

148146

149147
## Upload Function Trigger Code
150148

151-
If everything works we can move on and try to trigger a function when switch change state: a function that print `"Switch 1 ON"` when turned on and the inverse for the OFF state.
149+
If everything works correctly, we can trigger a function when the switch changes state.
150+
151+
For example, we can create a function that prints `"Switch 1 ON"` when the switch is turned on and `"Switch 1 OFF"` when it is turned off.
152152

153153
```arduino
154154
void ON_function() {
@@ -160,13 +160,13 @@ void OFF_function() {
160160
}
161161
```
162162

163-
In order to make every function runs once, only when the state changed, and not continuously, we can save the status of the switch in a variable:
163+
To ensure that the function only runs once when the state changes (and not continuously), we can store the current state of the switch in a variable:
164164

165165
```arduino
166166
bool stateSwitch = false;
167167
```
168168

169-
and call the function when it reads the opposite state: if the state is OFF (0) and it reads ON (1) it means that is just changed to ON, so call the `ON_function()` and update the `stateSwitch` variable.
169+
The function is called when the switch state changes. For instance, if the switch is currently OFF (`0`) and the state changes to ON (`1`), the `ON_function()` is triggered, and the `stateSwitch` variable is updated accordingly:
170170

171171
```arduino
172172
if (stateSwitch == 0) {
@@ -177,7 +177,7 @@ and call the function when it reads the opposite state: if the state is OFF (0)
177177
}
178178
```
179179

180-
The final code should like like this and it will works only for the toggle switch 1.
180+
Here is the complete code, which works for toggle switch 1:
181181

182182
```arduino
183183
#define pin_I1 A0
@@ -222,27 +222,31 @@ void ON_function() {
222222
void OFF_function() {
223223
Serial.println("Switch 1 OFF");
224224
}
225-
226225
```
227226

227+
This code will monitor the state of toggle switch 1 and trigger the appropriate function when the switch is turned *on* or *off*.
228+
228229
## Upload Final Code
229230

230-
In order to make it works for all the eight switches, you can repeat the `stateSwitch` variable and the `if-else` conditions eight times... but that would be boring. What about using [arrays](https://www.arduino.cc/reference/en/language/variables/data-types/array/) and a [for-loop](https://www.arduino.cc/reference/en/language/structure/control-structure/for/)?
231+
To make this work for all eight switches, you could repeat the `stateSwitch` variable and the `if-else` conditions eight times, but that would be a nonoptimal approach.
232+
233+
Instead, let's use [`arrays`](https://www.arduino.cc/reference/en/language/variables/data-types/array/) and a [`for-loop`](https://www.arduino.cc/reference/en/language/structure/control-structure/for/).
231234

232-
The idea is to replace all the variables used in the loop with arrays that stores eight values, one for each switch, and put it inside a `for loop` that will cycle through all the eight inputs. Let's see how to do it:
235+
The idea is to replace the variables in the loop with arrays that store values for each switch and then use a `for-loop` to cycle through all eight inputs.
233236

234-
First of all we need an array for all the pins definition of the inputs:
237+
First, define an array for all the input pin definitions:
235238

236239
```arduino
237240
int pins[] = { pin_I1, pin_I2, pin_I3, pin_I4, pin_I5, pin_I6, pin_I7, pin_I8 };
238241
```
239-
Then we need one for the `stateSwitch` variable:
242+
243+
Next, create an array for the `stateSwitch` variable:
240244

241245
```arduino
242246
bool stateSwitch[] = { false, false, false, false, false, false, false, false };
243247
```
244248

245-
And then we can substitute them:
249+
Then, you can substitute these arrays into your code:
246250

247251
```arduino
248252
if (stateSwitch[ ] == 0) {
@@ -258,8 +262,9 @@ if (stateSwitch[ ] == 0) {
258262
}
259263
```
260264

261-
Now we need to tell to each array-variable which values to use, you can do it by putting a number from 0 to 7 inside the `[]`, i.e. `pins[0] = pin_I1 // pins[1] = pin_I2 // etc..`.
262-
One way of doing it is with the [`for-loop`](https://www.arduino.cc/reference/en/language/structure/control-structure/for/). We can assign a variable, like `int i`, to change from 0 to 7, and then assign it to each array-variable:
265+
To specify which array values to use, you can use a number from 0 to 7 inside the brackets `[]`. For example, `pins[0] = pin_I1`, `pins[1] = pin_I2`, and so on.
266+
267+
One way to implement this is with a [`for-loop`](https://www.arduino.cc/reference/en/language/structure/control-structure/for/). Assign a variable, like `int i`, to iterate from 0 to 7, and then use it to access each array value:
263268

264269
```arduino
265270
for (int i = 0; i <= 7; i++) {
@@ -277,9 +282,9 @@ for (int i = 0; i <= 7; i++) {
277282
}
278283
```
279284

280-
Ok, that would work, but the `ON_function()` and the `OFF_function()` will print only the state of the Switch 1, unless we make the `i` variable as an [argument](https://docs.arduino.cc/learn/programming/functions/), and so we can print the number related to the switch we are switching.
285+
This approach will work, but the `ON_function()` and `OFF_function()` will only print the state of Switch 1 unless we pass the `i` variable as an [argument](https://docs.arduino.cc/learn/programming/functions/). This way, we can print the switch number that is being toggled.
281286

282-
Here the full code:
287+
Here is the full code:
283288

284289
```arduino
285290
#define pin_I1 A0
@@ -332,14 +337,16 @@ void OFF_function(int n) {
332337
}
333338
```
334339

335-
And here you can see what's goes on the serial monitor when you turn on all the switch from 1 to 8 and then off from 8 to 1:
340+
And here is what you should see on the Serial Monitor when you turn on all the switches from 1 to 8 and then off from 8 to 1:
336341

337342
![Serial Monitor with switches](assets/step3_serial-monitor.png)
338343

344+
This code will monitor the state of all eight switches and print the corresponding message whenever a switch is toggled *on* or *off*.
345+
339346
## Considerations
340347

341-
If something strange happens when you turn a switch on or off, like if the switch was triggered on and off super rapidly, don't panic! That's normal, and it is related to something called "debounce". You can have a look [here](https://docs.arduino.cc/built-in-examples/digital/Debounce/) to understand what's going on.
348+
If you notice any unexpected behavior when turning a switch on or off, such as the switch appearing to toggle on and off rapidly, don't worry! This is normal and is related to a phenomenon called "debounce." To understand further, you can learn more about it [here](https://docs.arduino.cc/built-in-examples/digital/Debounce/).
342349

343350
## Conclusions
344351

345-
The Arduino DIN Simul8 is the perfect playground to start experiment your coding skill in the PLC world. Try creating more functions that could be triggered by some combination of switch position, or whatever you like, have fun!
352+
The Arduino DIN Simul8 provides an excellent platform to start experimenting with your coding skills in the PLC world. Try creating more functions that different combinations of switch positions can trigger, or explore any other ideas you have. Have fun!

0 commit comments

Comments
 (0)