|
| 1 | +--- |
| 2 | +title: 'Opta™ Analog Expansion Usage with the PLC IDE' |
| 3 | +difficulty: beginner |
| 4 | +description: "Learn how to use the Opta™ Analog Expansion to extend your solution capabilities with the Arduino® PLC IDE." |
| 5 | +tags: |
| 6 | + - Expansions |
| 7 | + - IEC-61131-3 |
| 8 | + - PLC-IDE |
| 9 | + - Opta™ |
| 10 | +author: 'Christopher Mendez' |
| 11 | + |
| 12 | +hardware: |
| 13 | + - hardware/07.opta/opta-family/opta |
| 14 | + - hardware/07.opta/opta-family/opta-analog-ext |
| 15 | +software: |
| 16 | + - plc-ide |
| 17 | +--- |
| 18 | + |
| 19 | +## Overview |
| 20 | +In this tutorial, you will learn how to use Opta™ Analog Expansion AFX00007 alongside an Opta™ controller. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +We will create a demo application from scratch, in which we will read the voltage from an analog sensor and control the expansion relay outputs based on the voltage level measured. |
| 25 | + |
| 26 | +## Goals |
| 27 | + |
| 28 | +- Learn how to use Opta™ Analog Expansion with the PLC IDE |
| 29 | +- Learn how to enhance your Opta™ controller's capabilities using Opta™ expansions |
| 30 | +- Leverage Arduino Pro products for real industrial applications |
| 31 | + |
| 32 | +## Hardware and Software Requirements |
| 33 | + |
| 34 | +### Hardware |
| 35 | +- [Opta™](https://store-usa.arduino.cc/collections/opta-family) (x1) |
| 36 | +- [AFX00007 - Opta Ext A0602](https://store.arduino.cc/products/Opta-Ext-A0602) (x1) |
| 37 | +- 12-24 VDC/0.5 A power supply (x1) |
| 38 | +- [USB-C® cable](https://store-usa.arduino.cc/products/usb-cable2in1-type-c) (x1) |
| 39 | + |
| 40 | +### Software |
| 41 | +- The [Arduino PLC IDE](https://www.arduino.cc/pro/software-plc-ide) |
| 42 | + |
| 43 | +## Initial Configuration |
| 44 | + |
| 45 | +### Snapping the Expansion |
| 46 | + |
| 47 | +You can connect up to five expansions to your Opta™ controller module to multiply and diversify your I/O set with seamless detection. |
| 48 | + |
| 49 | +Remove the breakable plastic cover marked as AUX from the expansion port on the Opta™ controller and the expansion module to expose the ports. |
| 50 | + |
| 51 | +Attach the expansions to the right side of your Opta™ controller. Ensure that the **Aux connector** and the connection clips are correctly aligned, as shown in the image below: |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +The expansions must be powered externally in order to be detected and properly work. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +### Opta™ Micro PLC Setup |
| 60 | + |
| 61 | +After downloading the [PLC IDE](https://www.arduino.cc/en/software#arduino-plc-ide), follow the installation process from the following [guide](https://docs.arduino.cc/software/plc-ide/tutorials/plc-ide-setup-license/). |
| 62 | + |
| 63 | +Open the PLC IDE and create a new project for the Opta™. |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +Connect the Opta controller to your PC using a USB-C® cable. Then, upload the runtime for Opta™ by selecting its Serial Port and clicking on the **Download** button. |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +Once the runtime is flashed, navigate to **On-line > Set up communication**. With the **Modbus** protocol selected, open its properties and select the new virtual serial port (different from the one used in the previous step). Click "OK" to confirm. |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +***Modbus is the default serial protocol used to communicate the Opta™ with the PC.*** |
| 77 | + |
| 78 | +Next, click the **Connect** button in the upper left corner and wait for the base program to upload. A green **Connected** flag will appear in the lower right corner if the connection is successful. |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +***The Opta™ is pre-licensed, meaning no additional license purchase is required for use with the PLC IDE.*** |
| 83 | + |
| 84 | +If the Opta™ status displays **No License**, click the **Activate PLC runtime** button to activate it. For more details, refer to this [guide](https://docs.arduino.cc/tutorials/portenta-machine-control/plc-ide-setup-license/#7-license-activation-with-pre-licensed-products-opta). |
| 85 | + |
| 86 | +### Analog Expansion Setup |
| 87 | + |
| 88 | +To enable the Opta™ Analog Expansion features in the PLC IDE, navigate to the **Resources** tab and select **I/O Expansions** in the configuration tree. Then click **Scan** to allow the IDE to search for connected expansions. |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +Once the available expansion appears in the **Detected config** column, enable it by clicking on **Apply detect config**. Verify that the **Project config** column is updated. |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +## Programmable Inputs |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +To set up the sensor input for the potentiometer, navigate to **Programmable Inputs** under your desired expansion in the left resources menu. Define a **variable** name, **sensor** in this case, and set the **IOType** to **Analog**. |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +To set up the Opta™ expansion outputs, proceed to **Relay Outputs** under your desired expansion in the left resources menu. In this instance, define **variable** names for each output, **out_1** to **out_8**. |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +For the main code of our solution, navigate to the **Project** tab in the left panel, select **Main** in the project tree, and right-click on the **Local variables** window to insert some variables. |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +Insert the following three variables with their respective _type_ and _attribute_: |
| 113 | + |
| 114 | +| Name | Type | Init value | Attribute | |
| 115 | +|-------|------|------------|-----------| |
| 116 | +| VSTEP | REAL | - | - | |
| 117 | +| VCC | REAL | 12 | CONSTANT | |
| 118 | +| VIN | REAL | - | - | |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +- **VSTEP** will store the voltage step threshold to activate the relay outputs sequentially. |
| 123 | +- **VCC** is a constant representing the 12 VDC used to power the Opta™ Digital Expansion. |
| 124 | +- **VIN** will store the voltage read at the sensor input. |
| 125 | + |
| 126 | +Copy and paste the following sketch to the **Main code** text editor: |
| 127 | + |
| 128 | +``` |
| 129 | +VSTEP := VCC/8; |
| 130 | +
|
| 131 | +VIN := sensor*1.733E-3; |
| 132 | +
|
| 133 | +IF VIN >= VSTEP*1 THEN |
| 134 | + out_1 := TRUE; |
| 135 | +ELSE |
| 136 | + out_1 := FALSE; |
| 137 | +END_IF; |
| 138 | +
|
| 139 | +IF VIN >= VSTEP*2 THEN |
| 140 | + out_2 := TRUE; |
| 141 | +ELSE |
| 142 | + out_2 := FALSE; |
| 143 | +END_IF; |
| 144 | +
|
| 145 | +IF VIN >= VSTEP*3 THEN |
| 146 | + out_3 := TRUE; |
| 147 | +ELSE |
| 148 | + out_3 := FALSE; |
| 149 | +END_IF; |
| 150 | +
|
| 151 | +IF VIN >= VSTEP*4 THEN |
| 152 | + out_4 := TRUE; |
| 153 | +ELSE |
| 154 | + out_4 := FALSE; |
| 155 | +END_IF; |
| 156 | +
|
| 157 | +IF VIN >= VSTEP*5 THEN |
| 158 | + out_5 := TRUE; |
| 159 | +ELSE |
| 160 | + out_5 := FALSE; |
| 161 | +END_IF; |
| 162 | +
|
| 163 | +IF VIN >= VSTEP*6 THEN |
| 164 | + out_6 := TRUE; |
| 165 | +ELSE |
| 166 | + out_6 := FALSE; |
| 167 | +END_IF; |
| 168 | +
|
| 169 | +IF VIN >= VSTEP*7 THEN |
| 170 | + out_7 := TRUE; |
| 171 | +ELSE |
| 172 | + out_7 := FALSE; |
| 173 | +END_IF; |
| 174 | +
|
| 175 | +IF VIN >= VSTEP*8 THEN |
| 176 | + out_8 := TRUE; |
| 177 | +ELSE |
| 178 | + out_8 := FALSE; |
| 179 | +END_IF; |
| 180 | +``` |
| 181 | + |
| 182 | +Compile the project by clicking on the compilation button found in the upper left corner of the IDE. If no errors are shown, upload the program to the Opta™ controller by clicking the upload button highlighted next to it. |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | +You can monitor the project variables in real-time while the project is running by dragging and dropping the desired variables from the left project panel to the **Watch** window: |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | +Finally, your solution is ready. The Opta™ expansion relay outputs will activate sequentially as the sensor output increases. |
| 191 | + |
| 192 | +Turn the potentiometer and observe how the **VIN** variable displays the voltage being read. The outputs activate as their respective thresholds are reached: |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | +### Conclusion |
| 197 | + |
| 198 | +In this tutorial, you have learned how to use an Opta™ Digital Expansion by demonstrating a simple application that reads an analog input and controls the expansion relay outputs. |
| 199 | + |
| 200 | +As you can see, the configuration process is straightforward, and the results are as expected. This serves as an excellent starting point for adapting the techniques covered here to develop your professional solutions. |
| 201 | + |
| 202 | +#### Next Steps |
| 203 | + |
| 204 | +Extend your knowledge about the Opta™ controller and the PLC IDE by following these tutorials: |
| 205 | + |
| 206 | +- [Arduino PLC IDE Setup & Device License Activation](https://docs.arduino.cc/tutorials/portenta-machine-control/plc-ide-setup-license/) |
| 207 | +- [Programming Introduction with Arduino PLC IDE](https://docs.arduino.cc/tutorials/portenta-machine-control/plc-programming-introduction/) |
| 208 | +- [Tank Level Monitoring with the Opta™](https://docs.arduino.cc/tutorials/opta/tank-level-app-note/) |
| 209 | +- [Modbus TCP with Portenta Machine Control & Opta™](https://docs.arduino.cc/tutorials/portenta-machine-control/pmc-opta-modbus-tcp/) |
0 commit comments