<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MAXI &#8211; CONTROLLINO</title>
	<atom:link href="https://www.controllino.com/category/tutorials/maxi/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.controllino.com</link>
	<description>Industrial PLCs &#124; 100% Arduino-compatible</description>
	<lastBuildDate>Fri, 06 Dec 2024 12:13:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.controllino.com/wp-content/uploads/2023/05/cropped-C_Logo_Filled_RGB-1-32x32.png</url>
	<title>MAXI &#8211; CONTROLLINO</title>
	<link>https://www.controllino.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>OpenPLC Water Reserve Control</title>
		<link>https://www.controllino.com/water-reserve-control-system/</link>
		
		<dc:creator><![CDATA[CONTROLLINO]]></dc:creator>
		<pubDate>Sat, 30 Nov 2024 22:50:39 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[MINI]]></category>
		<category><![CDATA[OpenPLC]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.controllino.com/?p=17463</guid>

					<description><![CDATA[Introduction This tutorial explains how to implement an automatic water reserve control system using a CONTROLLINO PLC and OpenPLC. The system monitors the water levels of a cistern (minimum level) and an elevated tank (minimum and maximum levels) to control a pump that transfers water from the cistern to the elevated tank. Additionally, manual pump [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>This tutorial explains how to implement an automatic water reserve control system using a CONTROLLINO PLC and OpenPLC. The system monitors the water levels of a cistern (minimum level) and an elevated tank (minimum and maximum levels) to control a pump that transfers water from the cistern to the elevated tank. Additionally, manual pump control is possible using start and stop buttons.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>Before starting, ensure you have the following:</p>



<ul class="wp-block-list">
<li>OpenPLC software installed.</li>



<li>A CONTROLLINO PLC (any model) or a compatible PLC.</li>



<li>Sensors for water level detection:</li>



<li>Minimum level sensor for the cistern.</li>



<li>Minimum and maximum level sensors for the elevated tank.</li>



<li>Two buttons for manual control (Start and Stop).</li>



<li>Basic knowledge of ladder logic programming.</li>
</ul>



<h2 class="wp-block-heading">Step-by-Step Guide</h2>



<h3 class="wp-block-heading">Step 1: Install and Set Up OpenPLC</h3>



<ol class="wp-block-list">
<li><strong>Download OpenPLC</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Visit the <a href="https://www.openplcproject.com/">OpenPLC official website</a> and download the software.</li>



<li>Follow the installation instructions for your operating system.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Set Up the OpenPLC Environment</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Open the OpenPLC editor.</li>



<li>Configure the device by selecting your CONTROLLINO model in <strong>Settings &gt; Device</strong>.</li>



<li>Assign the correct COM port for communication with the PLC.</li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/OpenPLC_examples/tree/master" target="_blank" rel="noreferrer noopener">Controllino&#8217;s OpenPLC repository</a></div>
</div>



<h3 class="wp-block-heading">Step 2: Configure System Inputs and Outputs</h3>



<p>Define the following inputs and outputs in your ladder logic program:</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th><strong>Name</strong></th><th><strong>Type</strong></th><th><strong>Description</strong></th><th><strong>Pin</strong></th></tr></thead><tbody><tr><td><code>Pool_Low_Level_Sensor</code></td><td>BOOL</td><td>Indicates the minimum water level in the cistern.</td><td><code>%IX0.0</code></td></tr><tr><td><code>Tank_High_Level_Sensor</code></td><td>BOOL</td><td>Indicates the maximum water level in the tank.</td><td><code>%IX0.1</code></td></tr><tr><td><code>Tank_Low_Level_Sensor</code></td><td>BOOL</td><td>Indicates the minimum water level in the tank.</td><td><code>%IX0.2</code></td></tr><tr><td><code>Automatic_Manual_Switch</code></td><td>BOOL</td><td>Switch for selecting automatic or manual mode.</td><td><code>%IX0.3</code></td></tr><tr><td><code>Stop_Button</code></td><td>BOOL</td><td>Push button to stop the pump manually.</td><td><code>%IX0.4</code></td></tr><tr><td><code>Start_Button</code></td><td>BOOL</td><td>Push button to start the pump manually.</td><td><code>%IX0.5</code></td></tr><tr><td><code>Water_Pump</code></td><td>BOOL</td><td>Output controlling the water pump.</td><td><code>%QX0.0</code></td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Step 3: Program the Ladder Logic</h3>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/OpenPLC_examples/tree/master/water_control">Download OpenPLC project here</a></div>
</div>



<ol class="wp-block-list">
<li><strong>Automatic Mode</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>The pump (<code>Water_Pump</code>) is activated automatically when:
<ul class="wp-block-list">
<li>The cistern is above its minimum level (<code>Pool_Low_Level_Sensor</code> is active).</li>



<li>The tank is below its minimum level (<code>Tank_Low_Level_Sensor</code> is active).</li>
</ul>
</li>



<li>The pump is deactivated when:
<ul class="wp-block-list">
<li>The tank reaches its maximum level (<code>Tank_High_Level_Sensor</code> is active).</li>



<li>The cistern falls below its minimum level (<code>Pool_Low_Level_Sensor</code> is inactive).</li>
</ul>
</li>
</ul>



<ol class="wp-block-list">
<li><strong>Manual Mode</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>The pump can be directly controlled using the buttons:
<ul class="wp-block-list">
<li>The Start Button (<code>Start_Button</code>) activates the pump.</li>



<li>The Stop Button (<code>Stop_Button</code>) deactivates the pump.</li>
</ul>
</li>



<li>The switch (<code>Automatic_Manual_Switch</code>) must be in manual mode to enable this functionality.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Switching Between Modes</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>The <code>Automatic_Manual_Switch</code> toggles between automatic and manual modes.</li>



<li>In manual mode, sensor readings do not affect the pump operation.</li>
</ul>



<h3 class="wp-block-heading">Step 4: Connect the Hardware</h3>



<ol class="wp-block-list">
<li><strong>Wiring</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Connect the level sensors to the respective input pins.</li>



<li>Connect the Start and Stop buttons to other input pins.</li>



<li>Connect the water pump to the assigned output pin.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Pin Mapping</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Ensure that the variable names in OpenPLC match the physical connections.</li>
</ul>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="766" src="https://www.controllino.com/wp-content/uploads/2024/11/Esquema-de-conexion-1024x766.png" alt="" class="wp-image-17482" srcset="https://www.controllino.com/wp-content/uploads/2024/11/Esquema-de-conexion-1024x766.png 1024w, https://www.controllino.com/wp-content/uploads/2024/11/Esquema-de-conexion-300x225.png 300w, https://www.controllino.com/wp-content/uploads/2024/11/Esquema-de-conexion-768x575.png 768w, https://www.controllino.com/wp-content/uploads/2024/11/Esquema-de-conexion-1200x898.png 1200w, https://www.controllino.com/wp-content/uploads/2024/11/Esquema-de-conexion.png 1526w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">Step 5: Test the System</h3>



<ol class="wp-block-list">
<li><strong>Load the Program</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Save your project in the OpenPLC editor.</li>



<li>Connect your CONTROLLINO PLC to the computer and upload the program.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Test Automatic Mode</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Ensure the cistern is above its minimum level.</li>



<li>Lower the water level in the tank below its minimum.</li>



<li>Observe how the pump automatically activates and fills the tank until it reaches the maximum level.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Test Manual Mode</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Switch to manual mode using the <code>Automatic_Manual_Switch</code>.</li>



<li>Press the Start Button to activate the pump and the Stop Button to deactivate it.</li>
</ul>



<h2 class="wp-block-heading">Ladder Logic Explanation</h2>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="602" src="https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1024x602.jpg" alt="" class="wp-image-17484" srcset="https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1024x602.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-300x176.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-768x451.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1536x902.jpg 1536w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1200x705.jpg 1200w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program.jpg 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">Automatic Mode</h3>



<ol class="wp-block-list">
<li><strong>Automatic Activation</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>When both <code>Pool_Low_Level_Sensor</code> and <code>Tank_Low_Level_Sensor</code> are active, the pump (<code>Water_Pump</code>) turns on.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Automatic Deactivation</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>The pump turns off when either:
<ul class="wp-block-list">
<li><code>Tank_High_Level_Sensor</code> is active (tank full).</li>



<li><code>Pool_Low_Level_Sensor</code> is inactive (cistern empty).</li>
</ul>
</li>
</ul>



<h3 class="wp-block-heading">Manual Mode</h3>



<ol class="wp-block-list">
<li><strong>Manual Control</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Pressing <code>Start_Button</code> turns on the pump manually.</li>



<li>Pressing <code>Stop_Button</code> turns off the pump manually.</li>
</ul>



<h2 class="wp-block-heading">Troubleshooting</h2>



<ol class="wp-block-list">
<li><strong>Check Wiring</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Ensure sensors and buttons are connected to the correct input pins.</li>



<li>Verify the pump is connected to the correct output pin.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Verify Variables</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Check that the variable names in OpenPLC match the physical connections.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Debugging</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Use the OpenPLC debugging tools to monitor the state of inputs, outputs, and signals.</li>
</ul>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Congratulations! You have successfully implemented a water reserve control system with both automatic and manual modes. This system is ideal for efficiently managing water levels in elevated tanks and cisterns. You can further customize the system by adding additional sensors or modifying the logic to suit specific requirements.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>OpenPLC Staircase Light Control</title>
		<link>https://www.controllino.com/openplc-staircase-light-control-tutorial/</link>
		
		<dc:creator><![CDATA[CONTROLLINO]]></dc:creator>
		<pubDate>Sat, 30 Nov 2024 22:46:34 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[MINI]]></category>
		<category><![CDATA[OpenPLC]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.controllino.com/?p=17461</guid>

					<description><![CDATA[Introduction This tutorial demonstrates how to create an automatic staircase lighting system using OpenPLC and a CONTROLLINO PLC. The system uses two push buttons for manual control and a PIR sensor for automatic activation. The light toggles manually with button presses or turns on automatically when motion is detected, staying on for 20 seconds before [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">Introduction</h1>



<p>This tutorial demonstrates how to create an automatic staircase lighting system using OpenPLC and a CONTROLLINO PLC. The system uses two push buttons for manual control and a PIR sensor for automatic activation. The light toggles manually with button presses or turns on automatically when motion is detected, staying on for 20 seconds before turning off if no further motion occurs.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>Before you begin, ensure you have the following:</p>



<ul class="wp-block-list">
<li>OpenPLC software installed.</li>



<li>A CONTROLLINO PLC (any model) or compatible PLC.</li>



<li>A Passive Infrared (PIR) motion sensor.</li>



<li>Two push buttons (for manual control).</li>



<li>Basic knowledge of ladder logic programming.</li>
</ul>



<h2 class="wp-block-heading">Step-by-Step Guide</h2>



<h3 class="wp-block-heading">Step 1: Install and Configure OpenPLC</h3>



<ol class="wp-block-list">
<li><strong>Download OpenPLC</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Visit the <a href="https://www.openplcproject.com/">OpenPLC website</a> and download the software.</li>



<li>Follow the installation instructions for your operating system.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Set Up the OpenPLC Environment</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Open the OpenPLC Editor.</li>



<li>Configure the environment for your CONTROLLINO PLC by selecting the correct model in <strong>Settings &gt; Device</strong>.</li>



<li>Assign the appropriate COM port for communication.</li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/OpenPLC_examples/tree/master">Controllino&#8217;s OpenPLC repository</a></div>
</div>



<h3 class="wp-block-heading">Step 2: Define System Inputs and Outputs</h3>



<p>Configure the following inputs and outputs in your ladder logic program:</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Pin</th></tr></thead><tbody><tr><td><code>stairs_pir_sensor</code></td><td>BOOL</td><td>Input from the PIR motion sensor.</td><td><code>%IX0.0</code></td></tr><tr><td><code>control_button_down</code></td><td>BOOL</td><td>Input from the downstairs push button.</td><td><code>%IX0.1</code></td></tr><tr><td><code>control_button_up</code></td><td>BOOL</td><td>Input from the upstairs push button.</td><td><code>%IX0.2</code></td></tr><tr><td><code>stairs_light</code></td><td>BOOL</td><td>Output to control the staircase light.</td><td><code>%QX0.0</code></td></tr></tbody></table></figure>



<p><strong>Timers</strong>:</p>



<ul class="wp-block-list">
<li><code>TOF0</code> (Off Delay Timer): Controls the light timeout after motion detection.</li>



<li>Duration: <code>T#20s</code>.</li>
</ul>



<h3 class="wp-block-heading">Step 3: Create the Ladder Logic Program</h3>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/OpenPLC_examples/tree/master/stairs_light_control">Download OpenPLC project here</a></div>
</div>



<ol class="wp-block-list">
<li><strong>Manual Light Control</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>When either <code>control_button_down</code> or <code>control_button_up</code> is pressed, the <code>lights_buttons_state</code> toggles the <code>stairs_light</code>.</li>



<li>This allows manual on/off control of the staircase light.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Automatic Light Control</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>When the <code>stairs_pir_sensor</code> detects motion, it activates the timer <code>TOF0</code>.</li>



<li>The light (<code>stairs_light</code>) remains on while the timer is active or as long as motion is detected.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Light Timeout</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>When no motion is detected for 20 seconds, the <code>TOF0</code> timer deactivates.</li>



<li>The light turns off automatically unless toggled manually.</li>
</ul>



<h3 class="wp-block-heading">Step 4: Connect the Hardware</h3>



<ol class="wp-block-list">
<li><strong>Wiring</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Connect the PIR sensor output to a digital input pin (e.g., <code>DI0</code>).</li>



<li>Connect the downstairs push button to another input pin (e.g., <code>DI1</code>).</li>



<li>Connect the upstairs push button to a separate input pin (e.g., <code>DI2</code>).</li>



<li>Connect the staircase light to a digital output pin (e.g., <code>DO0</code>).</li>
</ul>



<ol class="wp-block-list">
<li><strong>Pin Mapping</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Assign the corresponding input and output variables in OpenPLC:
<ul class="wp-block-list">
<li><code>stairs_pir_sensor</code> → <code>%IX0.0</code></li>



<li><code>control_button_down</code> → <code>%IX0.1</code></li>



<li><code>control_button_up</code> → <code>%IX0.2</code></li>



<li><code>stairs_light</code> → <code>%QX0.0</code></li>
</ul>
</li>
</ul>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="765" src="https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1024x765.png" alt="" class="wp-image-17488" srcset="https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1024x765.png 1024w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-300x224.png 300w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-768x573.png 768w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1200x896.png 1200w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram.png 1334w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">Step 5: Load and Test the Program</h3>



<ol class="wp-block-list">
<li><strong>Upload the Program</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Save your ladder logic project in the OpenPLC Editor.</li>



<li>Connect your CONTROLLINO PLC to your computer and upload the program.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Test Manual Light Control</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Press the upstairs (<code>control_button_up</code>) or downstairs (<code>control_button_down</code>) push button.</li>



<li>Confirm that the light toggles on and off with each press.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Test Automatic Light Control</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Walk near the PIR sensor to simulate motion detection.</li>



<li>Observe the light turning on and staying active for 20 seconds after the motion stops.</li>



<li>Ensure the light turns off automatically after the timer expires.</li>
</ul>



<h3 class="wp-block-heading">Ladder Logic Explanation (Detailed)</h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="676" src="https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1-1024x676.jpg" alt="" class="wp-image-17490" srcset="https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1-1024x676.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1-300x198.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1-768x507.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1-1536x1014.jpg 1536w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1-1200x792.jpg 1200w, https://www.controllino.com/wp-content/uploads/2024/11/OpenPLC-program-1.jpg 1920w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h4 class="wp-block-heading">Manual Light Control</h4>



<ol class="wp-block-list">
<li><strong>Toggling the Light</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Each button press (<code>control_button_up</code> or <code>control_button_down</code>) changes the state of <code>lights_buttons_state</code>.</li>



<li>The state of <code>lights_buttons_state</code> determines whether <code>stairs_light</code> is turned on or off.</li>
</ul>



<h4 class="wp-block-heading">Automatic Light Control</h4>



<ol class="wp-block-list">
<li><strong>PIR Sensor Activation</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>When the <code>stairs_pir_sensor</code> detects motion, the timer <code>TOF0</code> starts.</li>



<li>The <code>stairs_light</code> remains on while motion is detected or while the timer is active.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Light Timeout</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>The <code>TOF0</code> timer turns off the light 20 seconds after the PIR sensor stops detecting motion.</li>
</ul>



<h4 class="wp-block-heading">Combining Manual and Automatic Control</h4>



<ul class="wp-block-list">
<li>The light can be manually toggled on or off at any time using the push buttons.</li>



<li>Automatic activation by the PIR sensor operates independently, ensuring flexibility.</li>
</ul>



<h3 class="wp-block-heading">Troubleshooting</h3>



<ol class="wp-block-list">
<li><strong>Verify Wiring</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Ensure all sensors and buttons are correctly connected to the appropriate input pins.</li>



<li>Confirm the light is connected to the correct output pin.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Check Variable Assignments</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Double-check that the input and output variables in OpenPLC match your physical connections.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Debugging</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Use the OpenPLC debugging tools to monitor the state of variables and timers.</li>
</ul>



<h3 class="wp-block-heading">Conclusion</h3>



<p>Congratulations! You have successfully implemented an automatic staircase lighting system using OpenPLC and a CONTROLLINO PLC. This system combines manual and automatic control for optimal flexibility and convenience. Experiment with different timer durations or additional sensors to customize the system further.</p>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>OpenPLC Light Intensity Control</title>
		<link>https://www.controllino.com/pwm-light-intensity-control-system-tutorial/</link>
		
		<dc:creator><![CDATA[CONTROLLINO]]></dc:creator>
		<pubDate>Sat, 30 Nov 2024 22:40:52 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[MICRO]]></category>
		<category><![CDATA[MINI]]></category>
		<category><![CDATA[OpenPLC]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.controllino.com/?p=17457</guid>

					<description><![CDATA[Introduction This tutorial explains how to create a PWM-based light intensity control system using OpenPLC software and a CONTROLLINO Micro PLC. The system adjusts the brightness of a light through a single push button, using a digital output. Each button press decreases the brightness until it cycles back to full intensity. This project showcases ladder [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">Introduction</h1>



<p>This tutorial explains how to create a PWM-based light intensity control system using OpenPLC software and a CONTROLLINO Micro PLC. The system adjusts the brightness of a light through a single push button, using a digital output. Each button press decreases the brightness until it cycles back to full intensity. This project showcases ladder logic programming to control light intensity using PWM.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>Before you begin, ensure you have the following:</p>



<ul class="wp-block-list">
<li>OpenPLC software installed.</li>



<li>A CONTROLLINO Micro PLC.</li>



<li>Basic knowledge of ladder logic and PWM.</li>



<li>Hardware setup ready, including a connected push button and light output.</li>
</ul>



<h2 class="wp-block-heading">Step-by-Step Guide</h2>



<h3 class="wp-block-heading">Step 1: Install and Configure OpenPLC</h3>



<ol class="wp-block-list">
<li>Download OpenPLC from the official <a href="https://www.openplcproject.com/">OpenPLC website</a>.</li>



<li>Install the software on your computer.</li>



<li>Open the OpenPLC Editor and configure the environment for your CONTROLLINO Micro PLC:</li>
</ol>



<ul class="wp-block-list">
<li>Navigate to <strong>Settings &gt; Device</strong> and select &#8220;CONTROLLINO Micro&#8221; from the list.</li>



<li>Ensure the correct COM port is selected.</li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/OpenPLC_examples/tree/master">Controllino&#8217;s OpenPLC repository</a></div>
</div>



<h3 class="wp-block-heading">Step 2: Create the Ladder Logic Program</h3>



<ol class="wp-block-list">
<li><strong>Define Variables</strong>:<br>Open the OpenPLC editor and define the variables listed below: Name Type Description <code>Control_button</code> BOOL Push button input to control brightness cycling. <code>Light_output</code> BOOL PWM output controlling the light intensity. <code>Light_bright</code> INT Tracks the current brightness level. <code>Pulse_regulator</code> TIME Timing variable for PWM modulation. <code>Light_on_state</code> BOOL Indicates whether the light is currently on. <code>Reset_state</code> BOOL Resets the brightness level to maximum. <code>Flag_cicle</code> BOOL Controls PWM signal cycling. <code>Full_bright</code> BOOL Indicates the full brightness state.</li>
</ol>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="370" src="https://www.controllino.com/wp-content/uploads/2024/11/OpemPLC-Variables-1024x370.jpg" alt="" class="wp-image-17498" srcset="https://www.controllino.com/wp-content/uploads/2024/11/OpemPLC-Variables-1024x370.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/11/OpemPLC-Variables-300x108.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/11/OpemPLC-Variables-768x277.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/11/OpemPLC-Variables-1536x554.jpg 1536w, https://www.controllino.com/wp-content/uploads/2024/11/OpemPLC-Variables-1200x433.jpg 1200w, https://www.controllino.com/wp-content/uploads/2024/11/OpemPLC-Variables.jpg 1920w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ol class="wp-block-list">
<li><strong>Draw the Ladder Diagram</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Implement the logic as described in the <strong>Ladder Logic Explanation</strong> section below.</li>



<li>Use counters (CTU), timers (TP and TOF), and comparators (EQ, GT) to create the control logic.</li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/OpenPLC_examples/tree/master/Dimmer_light_control">Download OpenPLC project here</a></div>
</div>



<h3 class="wp-block-heading">Step 3: Understanding the Ladder Logic</h3>



<h4 class="wp-block-heading">Button Press and Brightness Cycling</h4>



<ol class="wp-block-list">
<li><strong>Counter (CTU0)</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Each button press increments the counter.</li>



<li>The counter cycles through brightness levels (0, 1, 2, 3) and resets to 0 after reaching the maximum level.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Brightness Level Comparison</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Use comparators to determine the brightness level (<code>Light_bright</code>) and adjust the PWM pulse width accordingly.</li>
</ul>



<ol class="wp-block-list">
<li><strong>PWM Signal Generation</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Use timers to control the on/off duration of the PWM signal based on the current brightness level.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Light Output Control</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>The variable <code>Pulse_regulator</code> adjusts the <code>Light_output</code> signal to modulate light intensity.</li>
</ul>



<h3 class="wp-block-heading">Step 4: Connect the Hardware</h3>



<ol class="wp-block-list">
<li><strong>Wiring</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Connect the push button to a digital input pin (e.g., <code>CONTROLLINO_D0</code>).</li>



<li>Connect the light output to a PWM-capable pin (e.g., <code>CONTROLLINO_Q0</code>).</li>
</ul>



<ol class="wp-block-list">
<li><strong>Pin Mapping</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Assign the <code>Control_button</code> variable to the input pin connected to the push button.</li>



<li>Assign the <code>Light_output</code> variable to the output pin connected to the light.</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="768" src="https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1-1024x768.png" alt="" class="wp-image-17495" srcset="https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1-1024x768.png 1024w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1-300x225.png 300w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1-768x576.png 768w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1-1536x1152.png 1536w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1-1200x900.png 1200w, https://www.controllino.com/wp-content/uploads/2024/11/Electric-diagram-1.png 1630w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">Step 5: Load and Run the Program</h3>



<ol class="wp-block-list">
<li><strong>Upload the Program</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Save your ladder logic project.</li>



<li>Use the OpenPLC Editor to upload the program to your CONTROLLINO Micro.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Test the System</strong>:</li>
</ol>



<ul class="wp-block-list">
<li>Power on the CONTROLLINO Micro.</li>



<li>Press the push button and observe the light cycling through brightness levels.</li>
</ul>



<h3 class="wp-block-heading">Ladder Logic Explanation (Detailed)</h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="819" src="https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-1-1024x819.jpg" alt="" class="wp-image-17496" srcset="https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-1-1024x819.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-1-300x240.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-1-768x614.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-1-1200x960.jpg 1200w, https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-1.jpg 1358w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p><strong>Counter (CTU0)</strong>:</p>



<ol class="wp-block-list">
<li></li>
</ol>



<ul class="wp-block-list">
<li>Tracks the number of button presses and increments the <code>Light_bright</code> variable.</li>



<li>Resets to 0 after reaching the maximum brightness level.</li>
</ul>



<p><strong>Reset and Cycling</strong>:</p>



<ul class="wp-block-list">
<li>When the brightness reaches the lowest level, the <code>Reset_state</code> variable resets the system to the maximum brightness level.</li>
</ul>



<p><strong>Brightness Control</strong>:</p>



<ol class="wp-block-list">
<li></li>
</ol>



<ul class="wp-block-list">
<li>Use comparators (<code>EQ</code>, <code>GT</code>) to map the brightness level to a PWM duty cycle.</li>



<li>Timers (<code>TP0</code>, <code>TOF0</code>) generate the PWM signal by controlling the on/off duration of <code>Light_output</code>.</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="474" src="https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-2-1024x474.png" alt="" class="wp-image-17497" srcset="https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-2-1024x474.png 1024w, https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-2-300x139.png 300w, https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-2-768x355.png 768w, https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-2-1200x555.png 1200w, https://www.controllino.com/wp-content/uploads/2024/11/OplenPLC-Program-2.png 1344w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">Troubleshooting</h3>



<ol class="wp-block-list">
<li>Verify the wiring between the push button, light, and CONTROLLINO.</li>



<li>Ensure that the correct input and output pins are assigned to the variables.</li>



<li>Check for errors in the ladder logic program using the OpenPLC debugger.</li>
</ol>



<h3 class="wp-block-heading">Conclusion</h3>



<p>You have successfully implemented a PWM-based light intensity control system using a CONTROLLINO Micro and OpenPLC. By integrating ladder logic and PWM, this project demonstrates an efficient way to control light brightness with a single push button. Experiment with the timing variables and additional functionality to customize the system further.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Modbus TCP Server Client I/O</title>
		<link>https://www.controllino.com/modbus-tcp-master-client-i-o/</link>
		
		<dc:creator><![CDATA[CONTROLLINO]]></dc:creator>
		<pubDate>Fri, 27 Sep 2024 16:57:09 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.controllino.com/?p=17155</guid>

					<description><![CDATA[Introduction This is an example guide to setting up Modbus TCP communication between a client and server using CONTROLLINO and an Ethernet shield. This tutorial will help you configure the client to read and write inputs and outputs and the server to synchronize its state with the client. Prerequisites Modbus TCP connection example Point to [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>This is an example guide to setting up Modbus TCP communication between a client and server using CONTROLLINO and an Ethernet shield. This tutorial will help you configure the client to read and write inputs and outputs and the server to synchronize its state with the client.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<ul class="wp-block-list">
<li>Installed Arduino IDE.</li>



<li>CONTROLLINO PLC board (e.g., MAXI(also Automation), or MEGA).</li>



<li>Basic understanding of Modbus TCP and Ethernet setup.</li>
</ul>



<h4 class="wp-block-heading">Modbus TCP connection example</h4>



<p>Point to point connection</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="429" src="https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-connection-1024x429.jpg" alt="" class="wp-image-17346" srcset="https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-connection-1024x429.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-connection-300x126.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-connection-768x321.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-connection.jpg 1056w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Connection using switch </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="639" src="https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-switch-connection-1024x639.jpg" alt="" class="wp-image-17347" srcset="https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-switch-connection-1024x639.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-switch-connection-300x187.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-switch-connection-768x479.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/09/Controllino-TCP-switch-connection.jpg 1084w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading"> Example Code</h2>



<p>You can download the example Modbus TCP&nbsp;<strong>Client</strong>&nbsp;and&nbsp;<strong>Server</strong>&nbsp;code from the following GitHub repository:</p>



<ul class="wp-block-list">
<li><strong>Modbus TCP Client code</strong></li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/tree/master/examples/Expand_Modbus/TCP/ControllinoClient" target="_blank" rel="noreferrer noopener">Client code link</a></div>
</div>



<ul class="wp-block-list">
<li><strong>Modbus TCP Server code</strong></li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/tree/master/examples/Expand_Modbus/TCP/ControllinoServer" target="_blank" rel="noreferrer noopener">Server code link</a></div>
</div>



<ul class="wp-block-list">
<li><strong>Detailed example explanation</strong></li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/blob/master/examples/Expand_Modbus/TCP/README.md" target="_blank" rel="noreferrer noopener">README</a></div>
</div>



<h2 class="wp-block-heading">Step-by-Step Guide</h2>



<h3 class="wp-block-heading">Modbus TCP Client</h3>



<p>The Modbus TCP client communicates with the server to toggle coils and read and write registers.</p>



<h4 class="wp-block-heading">Step 1: Setup the Arduino Environment</h4>



<ul class="wp-block-list">
<li>Connect your CONTROLLINO board to your computer.</li>



<li>Open the Arduino IDE.</li>



<li>Ensure that the CONTROLLINO is selected in the&nbsp;<code>Tools</code>&nbsp;menu.</li>



<li>Include the necessary libraries for communication:
<ul class="wp-block-list">
<li><code>ArduinoRS485</code></li>



<li><code>ArduinoModbus</code></li>



<li><code>Controllino</code></li>



<li><code>SPI</code></li>



<li><code>Ethernet</code></li>
</ul>
</li>
</ul>



<h4 class="wp-block-heading">Step 2: Initialize the Ethernet and Modbus TCP Client</h4>



<p>In the&nbsp;<code>setup()</code>&nbsp;function:</p>



<ol class="wp-block-list">
<li>Start the Ethernet connection by calling&nbsp;<code>Ethernet.begin(mac, ip)</code>&nbsp;using the MAC address of your Ethernet shield.</li>



<li>Check the Ethernet hardware and cable connection.</li>



<li>If the connection is successful, initialize the Modbus TCP client by using&nbsp;<code>modbusTCPClient.begin(server, 502)</code>.</li>
</ol>



<h4 class="wp-block-heading">Step 3: Configure Digital and Analog Pins</h4>



<p>In the&nbsp;<code>loop()</code>&nbsp;function:</p>



<ol class="wp-block-list">
<li><strong>Digital Inputs and Coils</strong>:
<ul class="wp-block-list">
<li>Declare an array&nbsp;<code>slaveInputs[]</code>&nbsp;to store the state of the slave&#8217;s digital inputs.</li>



<li>Read these inputs using&nbsp;<code>modbusTCPClient.discreteInputRead()</code>.</li>



<li>Synchronize the state of the slave inputs to the master outputs using&nbsp;<code>digitalWrite()</code>.</li>



<li>Write the current state of the master digital input to the slave using&nbsp;<code>modbusTCPClient.coilWrite()</code>.</li>
</ul>
</li>



<li><strong>Analog Inputs and Holding Registers</strong>:
<ul class="wp-block-list">
<li>Declare an array&nbsp;<code>slaveInRegisters[]</code>&nbsp;to store the state of the slave&#8217;s holding registers.</li>



<li>Read the analog inputs using&nbsp;<code>modbusTCPClient.inputRegisterRead()</code>.</li>



<li>Synchronize the master’s analog outputs using&nbsp;<code>analogWrite()</code>&nbsp;and update the slave’s holding registers using&nbsp;<code>modbusTCPClient.holdingRegisterWrite()</code>.</li>
</ul>
</li>
</ol>



<h3 class="wp-block-heading">Modbus TCP Server</h3>



<p>The Modbus TCP server simulates a coil and synchronizes the state of its inputs and outputs with the client.</p>



<h4 class="wp-block-heading">Step 1: Setup the Arduino Environment</h4>



<ul class="wp-block-list">
<li>Connect your CONTROLLINO board to your computer.</li>



<li>Open the Arduino IDE.</li>



<li>Ensure that the CONTROLLINO is selected in the&nbsp;<code>Tools</code>&nbsp;menu.</li>



<li>Include the same libraries as in the client setup:
<ul class="wp-block-list">
<li><code>ArduinoRS485</code></li>



<li><code>ArduinoModbus</code></li>



<li><code>Controllino</code></li>



<li><code>SPI</code></li>



<li><code>Ethernet</code></li>
</ul>
</li>
</ul>



<h4 class="wp-block-heading">Step 2: Initialize the Ethernet and Modbus TCP Server</h4>



<p>In the&nbsp;<code>setup()</code>&nbsp;function:</p>



<ol class="wp-block-list">
<li>Start the Ethernet connection using&nbsp;<code>Ethernet.begin(mac, ip)</code>.</li>



<li>Start the Modbus TCP server by calling&nbsp;<code>modbusTCPServer.begin()</code>.</li>



<li>Configure the Modbus coils, discrete inputs, holding registers, and input registers using:
<ul class="wp-block-list">
<li><code>modbusTCPServer.configureCoils()</code></li>



<li><code>modbusTCPServer.configureDiscreteInputs()</code></li>



<li><code>modbusTCPServer.configureHoldingRegisters()</code></li>



<li><code>modbusTCPServer.configureInputRegisters()</code></li>
</ul>
</li>
</ol>



<h4 class="wp-block-heading">Step 3: Configure Digital and Analog Pins</h4>



<ol class="wp-block-list">
<li>Set up digital input and output pins.
<ul class="wp-block-list">
<li>Use&nbsp;<code>pinMode()</code>&nbsp;to define the pins as either INPUT or OUTPUT.</li>



<li>Initialize output pins to a LOW state.</li>
</ul>
</li>



<li>Set up analog output pins for holding registers using&nbsp;<code>analogWrite()</code>.</li>
</ol>



<h4 class="wp-block-heading">Step 4: Synchronizing Coils and Registers</h4>



<p>In the&nbsp;<code>loop()</code>&nbsp;function:</p>



<ol class="wp-block-list">
<li><strong>Client Connection</strong>:
<ul class="wp-block-list">
<li>Wait for incoming client connections using&nbsp;<code>ethernetServer.available()</code>.</li>



<li>Accept the client connection with&nbsp;<code>modbusTCPServer.accept(client)</code>.</li>
</ul>
</li>



<li><strong>Synchronize Coils and Registers</strong>:
<ul class="wp-block-list">
<li>In the&nbsp;<code>executeSynchronization()</code>&nbsp;function:
<ul class="wp-block-list">
<li>Read the state of the server’s coils using&nbsp;<code>modbusTCPServer.coilRead()</code>, and update the corresponding output pins using&nbsp;<code>digitalWrite()</code>.</li>



<li>Read the state of the input pins using&nbsp;<code>digitalRead()</code>&nbsp;and update the corresponding coil register with&nbsp;<code>modbusTCPServer.coilWrite()</code>.</li>



<li>For analog outputs, write the value from the holding register to the PWM outputs using&nbsp;<code>analogWrite()</code>.</li>



<li>Read the analog input pins and update the corresponding input registers using&nbsp;<code>modbusTCPServer.inputRegisterWrite()</code>.</li>
</ul>
</li>
</ul>
</li>
</ol>



<h3 class="wp-block-heading">Conclusion</h3>



<p>You have now successfully configured Modbus TCP communication between a CONTROLLINO client and server using an Ethernet shield. The client reads and writes digital and analog inputs/outputs, while the server synchronizes its state accordingly. Experiment with different pin configurations and data handling to expand your project!</p>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Modbus RTU Master Slave I/O</title>
		<link>https://www.controllino.com/modbus-rtu-master-slave-synchronization/</link>
		
		<dc:creator><![CDATA[CONTROLLINO]]></dc:creator>
		<pubDate>Wed, 25 Sep 2024 23:36:09 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.controllino.com/?p=17117</guid>

					<description><![CDATA[Introduction This tutorial will guide you through setting up&#160;Modbus RTU communication&#160;between a&#160;master&#160;and a&#160;slave&#160;device using two&#160;CONTROLLINO devices. The master device reads&#160;digital&#160;and&#160;analog inputs&#160;from the slave and sends data to control its outputs, while the slave responds with data controlling its own outputs based on commands received from the master. Note The Controllino BSP, for MAXI and MEGA, [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>This tutorial will guide you through setting up&nbsp;<strong>Modbus RTU communication</strong>&nbsp;between a&nbsp;<strong>master</strong>&nbsp;and a&nbsp;<strong>slave</strong>&nbsp;device using two&nbsp;<strong>CONTROLLINO </strong>devices. The master device reads&nbsp;<strong>digital</strong>&nbsp;and&nbsp;<strong>analog inputs</strong>&nbsp;from the slave and sends data to control its outputs, while the slave responds with data controlling its own outputs based on commands received from the master.</p>



<h3 class="wp-block-heading">Note<a href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Tutorials/tree/master/Modbus/RTU#note"></a></h3>



<p>The Controllino BSP, for MAXI and MEGA, inside&nbsp;<strong>pins_arduino.h</strong>&nbsp;contains the following definitions:</p>



<pre class="wp-block-preformatted"><code>// ArduinoRS485 library support<br>#define RS485_SERIAL_PORT           Serial3<br>#define RS485_DEFAULT_TX_PIN        14<br>#define CUSTOM_RS485_DEFAULT_DE_PIN 75<br>#define CUSTOM_RS485_DEFAULT_RE_PIN 76</code></pre>



<p>These allows the use of the default instance of RS485 library:</p>



<pre class="wp-block-preformatted"><code>RS485Class RS485(RS485_SERIAL_PORT, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);</code></pre>



<p>Which is also the default RS485 interface for&nbsp;<strong>ModbusRTUServer</strong>&nbsp;and&nbsp;<strong>ModbusRTUClient</strong>&nbsp;the default instances for RTU in ArduinoModbus library.</p>



<p>This allows an easy integration of the libraries and the Controllino BSP so there is not need to create an instance of RS485 and later an instance of ModbusRTUServer or ModbusRTUClient, but just use the default instances like in the library examples.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<ul class="wp-block-list">
<li>Installed&nbsp;<strong>Arduino IDE</strong>.</li>



<li><strong>CONTROLLINO Mega</strong> or <strong>Maxi</strong>&nbsp;PLC board for both master and slave devices.</li>



<li>Basic understanding of&nbsp;<strong>Modbus RTU</strong>&nbsp;communication and&nbsp;<strong>pin setup</strong>.</li>



<li>Connect two Controllino boards using de RS485 pins as show the pictures above.</li>
</ul>



<h5 class="wp-block-heading">RS485 connection for Controllino Maxi</h5>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="604" src="https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Max1-RS485-1024x604.jpg" alt="" class="wp-image-17253" srcset="https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Max1-RS485-1024x604.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Max1-RS485-300x177.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Max1-RS485-768x453.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Max1-RS485-1536x906.jpg 1536w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Max1-RS485-1200x708.jpg 1200w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Max1-RS485.jpg 1920w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h5 class="wp-block-heading">RS485 connection for Controllino Mega</h5>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="546" src="https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Mega-RS485-1024x546.jpg" alt="" class="wp-image-17254" srcset="https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Mega-RS485-1024x546.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Mega-RS485-300x160.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Mega-RS485-768x409.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Mega-RS485-1200x640.jpg 1200w, https://www.controllino.com/wp-content/uploads/2024/09/Controll1no-Mega-RS485.jpg 1332w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">Example Code</h2>



<p>You can download the example Modbus RTU&nbsp;<strong>master</strong>&nbsp;and&nbsp;<strong>slave</strong>&nbsp;code from the following GitHub repository:</p>



<ul class="wp-block-list">
<li><strong>Modbus RTU Master code</strong></li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/tree/master/examples/Expand_Modbus/RTU/ControllinoMaster" target="_blank" rel="noreferrer noopener">Master code link</a></div>
</div>



<ul class="wp-block-list">
<li><strong>Modbus RTU Slave code</strong></li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/tree/master/examples/Expand_Modbus/RTU/ControllinoSlave" target="_blank" rel="noreferrer noopener">Slave code link</a></div>
</div>



<ul class="wp-block-list">
<li><strong>Detailed example explanation</strong></li>
</ul>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/blob/master/examples/Expand_Modbus/RTU/README.md" target="_blank" rel="noreferrer noopener">README</a></div>
</div>



<h2 class="wp-block-heading">Step-by-Step Guide</h2>



<h3 class="wp-block-heading">Step 1: Setup the Arduino Environment</h3>



<ol class="wp-block-list">
<li><strong>Connect your CONTROLLINO</strong>&nbsp;boards (both master and slave) to your computer.</li>



<li><strong>Open the Arduino IDE</strong>.</li>



<li>Ensure the appropriate&nbsp;<strong>CONTROLLINO Mega board</strong>&nbsp;and&nbsp;<strong>port</strong>&nbsp;are selected in the&nbsp;<strong>Tools</strong>&nbsp;menu.</li>



<li><strong>Include the necessary libraries</strong>:
<ul class="wp-block-list">
<li><strong>ArduinoRS485</strong>&nbsp;library for Modbus RTU communication.</li>



<li><strong>ArduinoModbus</strong>&nbsp;library for handling Modbus RTU protocol.</li>



<li><strong>Controllino library</strong>&nbsp;to handle CONTROLLINO-specific pins.</li>
</ul>
</li>
</ol>



<h3 class="wp-block-heading">Step 2: Initialize Modbus RTU Communication and Serial Debugging</h3>



<ol class="wp-block-list">
<li>In the&nbsp;<strong>setup() function</strong>&nbsp;of both master and slave:
<ul class="wp-block-list">
<li>Initialize&nbsp;<strong>Modbus RTU</strong>&nbsp;communication by calling&nbsp;<code>ModbusRTUClient.begin(9600)</code>&nbsp;for the master and&nbsp;<code>ModbusRTUServer.begin(1, 9600)</code>&nbsp;for the slave. This sets up the master to communicate at a&nbsp;<strong>9600 baud rate</strong>, and the slave is assigned&nbsp;<strong>ID 1</strong>.</li>



<li>Initialize&nbsp;<strong>serial communication</strong>&nbsp;for debugging purposes using&nbsp;<code>Serial.begin(9600)</code>.</li>
</ul>
</li>



<li>On the&nbsp;<strong>master</strong>&nbsp;side, you will configure the Modbus client, while the&nbsp;<strong>slave</strong>&nbsp;initializes the Modbus server.</li>
</ol>



<h3 class="wp-block-heading">Step 3: Configure Digital and Analog Pins</h3>



<ol class="wp-block-list">
<li><strong>Master Configuration</strong>:
<ul class="wp-block-list">
<li><strong>Digital Inputs and Outputs</strong>:
<ul class="wp-block-list">
<li>Configure&nbsp;<strong>digital pins</strong>&nbsp;<code>CONTROLLINO_A0</code>&nbsp;to&nbsp;<code>CONTROLLINO_A10</code>&nbsp;as inputs.</li>



<li>Configure&nbsp;<strong>relay pins</strong>&nbsp;<code>CONTROLLINO_R0</code>&nbsp;to&nbsp;<code>CONTROLLINO_R10</code>&nbsp;as outputs.</li>
</ul>
</li>



<li><strong>Analog Inputs and Outputs</strong>:
<ul class="wp-block-list">
<li>Configure&nbsp;<strong>analog input pins</strong>&nbsp;<code>CONTROLLINO_A11</code>&nbsp;to&nbsp;<code>CONTROLLINO_A15</code>&nbsp;as inputs.</li>



<li>Configure&nbsp;<strong>PWM output pins</strong>&nbsp;<code>CONTROLLINO_D0</code>&nbsp;to&nbsp;<code>CONTROLLINO_D4</code>&nbsp;as outputs.</li>
</ul>
</li>
</ul>
</li>



<li><strong>Slave Configuration</strong>:
<ul class="wp-block-list">
<li><strong>Digital Inputs and Outputs</strong>:
<ul class="wp-block-list">
<li>The same digital input-output configuration will be applied to the&nbsp;<strong>slave</strong>.</li>
</ul>
</li>



<li><strong>Analog Inputs and Outputs</strong>:
<ul class="wp-block-list">
<li>Similarly, configure&nbsp;<strong>analog input pins</strong>&nbsp;and&nbsp;<strong>PWM output pins</strong>&nbsp;as on the master.</li>
</ul>
</li>
</ul>
</li>
</ol>



<h3 class="wp-block-heading">Step 4: Sending and Receiving Data Between Master and Slave</h3>



<h4 class="wp-block-heading">Master Code</h4>



<p>In the&nbsp;<strong>loop() function</strong>:</p>



<ol class="wp-block-list">
<li>Start by&nbsp;<strong>reading the digital inputs</strong>&nbsp;(<code>CONTROLLINO_A0</code>&nbsp;to&nbsp;<code>CONTROLLINO_A10</code>) on the master.</li>



<li><strong>Write the input states to the slave&#8217;s coils</strong>&nbsp;using&nbsp;<code>ModbusRTUClient.coilWrite()</code>. This will send the master’s inputs to the corresponding&nbsp;<strong>digital outputs</strong>&nbsp;(<code>CONTROLLINO_R0</code>&nbsp;to&nbsp;<code>CONTROLLINO_R10</code>) on the slave.</li>



<li>Read the&nbsp;<strong>analog input values</strong>&nbsp;on the master, and split the 10-bit values into&nbsp;<strong>Modbus registers</strong>. Write these to the slave&#8217;s&nbsp;<strong>holding registers</strong>.</li>



<li>After sending data to the slave,&nbsp;<strong>read the slave&#8217;s discrete inputs</strong>&nbsp;and&nbsp;<strong>input registers</strong>&nbsp;to update the master&#8217;s digital and analog outputs.</li>
</ol>



<h4 class="wp-block-heading">Slave Code</h4>



<p>In the&nbsp;<strong>loop() function</strong>&nbsp;of the slave:</p>



<ol class="wp-block-list">
<li>Use&nbsp;<code>ModbusRTUServer.poll()</code>&nbsp;to check for incoming Modbus requests from the master.</li>



<li>For&nbsp;<strong>digital outputs</strong>, read the&nbsp;<strong>coil values</strong>&nbsp;sent by the master and update the&nbsp;<strong>digital output pins</strong>&nbsp;accordingly.</li>



<li>For&nbsp;<strong>analog outputs</strong>, read the values from the&nbsp;<strong>holding registers</strong>&nbsp;and use them to set the&nbsp;<strong>PWM outputs</strong>.</li>
</ol>



<h3 class="wp-block-heading">Step 5: Synchronizing Digital and Analog Outputs</h3>



<ol class="wp-block-list">
<li>The master’s&nbsp;<strong>digital outputs</strong>&nbsp;(<code>CONTROLLINO_R0</code>&nbsp;to&nbsp;<code>CONTROLLINO_R10</code>) are updated based on the data received from the slave’s&nbsp;<strong>discrete inputs</strong>.</li>



<li>The master’s&nbsp;<strong>analog outputs</strong>&nbsp;(<code>CONTROLLINO_D0</code>&nbsp;to&nbsp;<code>CONTROLLINO_D4</code>) are updated based on the slave’s&nbsp;<strong>input registers</strong>.</li>



<li>On the slave, the&nbsp;<strong>digital outputs</strong>&nbsp;and&nbsp;<strong>PWM outputs</strong>&nbsp;are controlled by the master’s Modbus write commands, allowing for synchronized control across the devices.</li>
</ol>



<h3 class="wp-block-heading">Step 6: Debugging and Monitoring Communication</h3>



<ol class="wp-block-list">
<li>Add&nbsp;<strong>serial print statements</strong>&nbsp;to monitor Modbus communication between the master and slave.</li>



<li>Ensure the&nbsp;<strong>Modbus client</strong>&nbsp;is correctly reading and writing data from and to the&nbsp;<strong>slave device</strong>.</li>



<li>Use&nbsp;<strong>LEDs or external devices</strong>&nbsp;connected to the outputs to visualize changes in state as you control the system through Modbus communication.</li>
</ol>



<h2 class="wp-block-heading">Troubleshooting</h2>



<ul class="wp-block-list">
<li><strong>Modbus Communication Issues</strong>: Verify the&nbsp;<strong>slave ID</strong>&nbsp;and&nbsp;<strong>Modbus address</strong>&nbsp;in both the master and slave codes.</li>



<li><strong>Serial Debugging</strong>: Ensure the&nbsp;<strong>Serial Monitor</strong>&nbsp;is open at the correct baud rate (<strong>9600 baud</strong>).</li>



<li><strong>Wiring</strong>: Double-check the&nbsp;<strong>RS485</strong>&nbsp;connections between the master and slave devices. Ensure that the&nbsp;<strong>A+</strong>&nbsp;and&nbsp;<strong>B-</strong>terminals are properly connected.</li>



<li><strong>Pin Setup</strong>: Verify that the correct pins are configured as inputs and outputs on both the master and slave.</li>
</ul>



<h2 class="wp-block-heading">Conclusion</h2>



<p>You have now successfully established&nbsp;<strong>Modbus RTU communication</strong>&nbsp;between a&nbsp;<strong>CONTROLLINO master and slave</strong>. The master reads digital and analog inputs, sends this data to the slave, and controls the slave’s outputs accordingly. Experiment with this setup to synchronize&nbsp;<strong>multiple devices</strong>&nbsp;or expand your project with additional sensors and actuators!</p>



<p>Also this tutorial can be a base example on how to extend the I/Os of a <strong>CONTROLLINO</strong> with another <strong>CONTROLLINO</strong>, using Modbus RTU and RS485.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>I2C Master Slave I/O</title>
		<link>https://www.controllino.com/i2c-master-slave-i-o/</link>
		
		<dc:creator><![CDATA[CONTROLLINO]]></dc:creator>
		<pubDate>Tue, 17 Sep 2024 20:45:54 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[MINI]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://www.controllino.com/?p=17065</guid>

					<description><![CDATA[Introduction This tutorial will guide you through setting up I2C communication between a master and a slave device using a CONTROLLINO PLC. The master device reads analog and digital inputs and sends this data to the slave, while the slave responds with data that controls the outputs on the master. Prerequisites I2C Connection example This [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>This tutorial will guide you through setting up I2C communication between a master and a slave device using a CONTROLLINO PLC. The master device reads analog and digital inputs and sends this data to the slave, while the slave responds with data that controls the outputs on the master.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<ul class="wp-block-list">
<li>Installed Arduino IDE.</li>



<li>CONTROLLINO PLC board (e.g., MINI, MAXI, or MEGA).</li>



<li>Basic understanding of I2C communication and pin setup.</li>
</ul>



<h5 class="wp-block-heading">I2C Connection example</h5>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="584" src="https://www.controllino.com/wp-content/uploads/2024/09/I2C-Controllino-Mega-1024x584.jpg" alt="" class="wp-image-17342" srcset="https://www.controllino.com/wp-content/uploads/2024/09/I2C-Controllino-Mega-1024x584.jpg 1024w, https://www.controllino.com/wp-content/uploads/2024/09/I2C-Controllino-Mega-300x171.jpg 300w, https://www.controllino.com/wp-content/uploads/2024/09/I2C-Controllino-Mega-768x438.jpg 768w, https://www.controllino.com/wp-content/uploads/2024/09/I2C-Controllino-Mega.jpg 1112w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>This example of connection is based on the Controllino Mega but I2C connections for Maxi and Mini uses the same pins of the same X1 connector. </p>



<h2 class="wp-block-heading">Example Code</h2>



<p>Please grab the following example .ino file from Github:</p>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/tree/master/examples/Expand_I2C/Master" target="_blank" rel="noreferrer noopener">I2C Master Code Example</a></div>
</div>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/tree/master/examples/Expand_I2C/Slave" target="_blank" rel="noreferrer noopener">I2C Slave Code Example</a></div>
</div>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/blob/master/examples/Expand_I2C/README.md" target="_blank" rel="noreferrer noopener">Readme file Link</a></div>
</div>



<h2 class="wp-block-heading">Step-by-Step Guide</h2>



<h3 class="wp-block-heading">Step 1: Setup the Arduino Environment</h3>



<ol class="wp-block-list">
<li>Connect your CONTROLLINO board to your computer.</li>



<li>Open the Arduino IDE.</li>



<li>Ensure that the appropriate CONTROLLINO board and port are selected in the&nbsp;<strong>Tools</strong>&nbsp;menu.</li>



<li>Include the&nbsp;<strong>Wire</strong>&nbsp;and&nbsp;<strong>Controllino</strong>&nbsp;libraries in your project.</li>
</ol>



<h3 class="wp-block-heading">Step 2: Initialize I2C Communication and Serial Debugging</h3>



<ol class="wp-block-list">
<li>In the&nbsp;<code>setup()</code>&nbsp;function, initialize the I2C communication by calling&nbsp;<code>Wire.begin()</code>. This sets up the CONTROLLINO device as a master.</li>



<li>Initialize serial communication for debugging purposes using&nbsp;<code>Serial.begin(9600)</code>.</li>
</ol>



<h3 class="wp-block-heading">Step 3: Configure Digital and Analog Pins</h3>



<ol class="wp-block-list">
<li>Set up the digital pins:
<ul class="wp-block-list">
<li>The first 5 digital pins (<code>CONTROLLINO_D0</code>&nbsp;to&nbsp;<code>CONTROLLINO_D4</code>) are configured as inputs.</li>



<li>The corresponding relay pins (<code>CONTROLLINO_R0</code>&nbsp;to&nbsp;<code>CONTROLLINO_R4</code>) are set as outputs.</li>
</ul>
</li>



<li>Set up the analog pins:
<ul class="wp-block-list">
<li>The next 2 analog input pins (<code>CONTROLLINO_A0</code>&nbsp;and&nbsp;<code>CONTROLLINO_A1</code>) are configured as inputs.</li>



<li>The same pins will also serve as PWM outputs, configured as outputs.</li>
</ul>
</li>
</ol>



<h3 class="wp-block-heading">Step 4: Sending Analog and Digital Inputs to the Slave</h3>



<ol class="wp-block-list">
<li>In the&nbsp;<code>loop()</code>&nbsp;function, start communication with the slave by calling&nbsp;<code>Wire.beginTransmission(slaveAddress)</code>.</li>



<li>Read the values from the analog input pins and split each 10-bit value into two bytes. Send these bytes to the slave using&nbsp;<code>Wire.write()</code>.</li>



<li>Read the states of the digital input pins, and store them in a single byte using bitwise operations. Send this byte to the slave.</li>
</ol>



<h3 class="wp-block-heading">Step 5: Receiving Data from the Slave</h3>



<ol class="wp-block-list">
<li>After ending the transmission with&nbsp;<code>Wire.endTransmission()</code>, request data from the slave by calling&nbsp;<code>Wire.requestFrom(slaveAddress, 5)</code>.</li>



<li>Once data is available, read the byte that contains the digital output states and update the output pins accordingly.</li>



<li>For analog data, combine the two bytes received into a single integer, and use this value to set the PWM outputs on the master.</li>
</ol>



<h3 class="wp-block-heading">Step 6: Control Digital Outputs Based on Slave Data</h3>



<ol class="wp-block-list">
<li>Use the byte received from the slave to set the states of the digital output pins (<code>CONTROLLINO_R0</code>&nbsp;to&nbsp;<code>CONTROLLINO_R4</code>).</li>



<li>Each bit in the byte represents the state of one output pin, and the&nbsp;<code>digitalWrite()</code>&nbsp;function is used to control these pins.</li>
</ol>



<p>Certainly! Here’s an expanded explanation with more details on how the slave code works and its interaction with the master:</p>



<h3 class="wp-block-heading">Step 7: Set Up the Slave Address and Digital/Analog Pins</h3>



<p>In the slave code, the device is initialized with a specific I2C address using <code>Wire.begin(8)</code>. This address must match the address used in the master code for communication to work.</p>



<p>The digital and analog pins on the slave are then configured:</p>



<ul class="wp-block-list">
<li>The first 5 digital pins are set as inputs and outputs, similar to the master.</li>



<li>The next 2 pins are designated as PWM outputs (for receiving analog data from the master) and as analog inputs (for sending data back to the master).</li>
</ul>



<p>This ensures that both the master and slave are working with the same configuration, which is essential for seamless data exchange.</p>



<h3 class="wp-block-heading">Step 8: Handling Data Received from the Master</h3>



<p>The <code>receiveEvent()</code> function in the slave code is triggered whenever the master sends data to the slave. This function:</p>



<ol class="wp-block-list">
<li>Reads the analog values sent by the master, reconstructing each value from two bytes.</li>



<li>Writes the reconstructed analog values to the designated PWM output pins on the slave, enabling the master to control the analog output on the slave remotely.</li>



<li>Reads the byte representing the digital output states, where each bit corresponds to the state of one digital output pin.</li>
</ol>



<p>The slave then uses <code>digitalWrite()</code> to set its digital output pins based on the master’s instructions, allowing the master to control these outputs directly.</p>



<h3 class="wp-block-heading">Step 9: Responding to the Master’s Data Request</h3>



<p>When the master requests data from the slave, the <code>requestEvent()</code> function on the slave is executed:</p>



<ol class="wp-block-list">
<li>The analog inputs are read, its value is splited into two bytes for transmission.</li>



<li>The combined digital input states are read and stored in a single byte, with each bit representing one digital input.</li>
</ol>



<p>The slave then sends these values back to the master via <code>Wire.write()</code>, allowing the master to read the current state of the slave’s inputs and use this data in its control logic.</p>



<h3 class="wp-block-heading">Step 10: Synchronizing Data Between Master and Slave</h3>



<p>The master and slave continuously communicate over I2C to maintain synchronization:</p>



<ol class="wp-block-list">
<li>The master sends analog values to control the PWM outputs on the slave.</li>



<li>The master also sends digital states to control specific digital outputs on the slave.</li>



<li>The slave responds with its own digital and analog input states, enabling the master to monitor and react to the slave’s environment.</li>
</ol>



<p>This bidirectional data flow ensures the master can dynamically control and respond to the conditions on the slave, creating a cohesive system where both devices operate in harmony.</p>



<h3 class="wp-block-heading">Troubleshooting</h3>



<ul class="wp-block-list">
<li>Ensure the I2C address of the slave matches the value set in&nbsp;<code>slaveAddress</code>.</li>



<li>Check the wiring between the master and slave, ensuring the I2C SDA and SCL lines are connected properly.</li>



<li>Verify the CONTROLLINO board and port are correctly selected in the Arduino IDE.</li>
</ul>



<h2 class="wp-block-heading">Conclusion</h2>



<p>You have now successfully established I2C communication between a CONTROLLINO master and slave. By reading analog and digital inputs on the master and controlling its outputs based on data received from the slave, this setup enables synchronized control between two devices. Experiment with different pin configurations and data handling to expand your project!</p>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Board &#038; Library Setup with Platform.io</title>
		<link>https://www.controllino.com/board-library-setup-with-platform-io/</link>
		
		<dc:creator><![CDATA[marcoriedi]]></dc:creator>
		<pubDate>Tue, 30 May 2023 09:21:28 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[MICRO]]></category>
		<category><![CDATA[MINI]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://page2023.controllino.com/?p=5080</guid>

					<description><![CDATA[Intro Platform.io together with VS Code is the current de-facto standard for advanced programmers to develop on Arduino boards. CONTROLLINO is natively compatible with Platform.io How to use CONTROLLINO with Platform.io Please refer to the official tutorials from Platform.io on how to connect your board:]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Intro</h2>



<p>Platform.io together with VS Code is the current de-facto standard for advanced programmers to develop on Arduino boards. CONTROLLINO is natively compatible with Platform.io</p>



<h2 class="wp-block-heading">How to use CONTROLLINO with Platform.io</h2>



<p>Please refer to the official tutorials from Platform.io on how to connect your board:</p>



<ul class="wp-block-list">
<li><a href="https://docs.platformio.org/en/latest/boards/atmelavr/controllino_mini.html">Controllino MINI</a></li>



<li><a href="https://docs.platformio.org/en/latest/boards/atmelavr/controllino_maxi.html">Controllino MAXI</a></li>



<li><a href="https://docs.platformio.org/en/latest/boards/atmelavr/controllino_maxi_automation.html">Controllino MAXI Automation</a></li>



<li><a href="https://docs.platformio.org/en/latest/boards/atmelavr/controllino_mega.html">Controllino MEGA</a></li>
</ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Controllino HMI with Modbus</title>
		<link>https://www.controllino.com/controllino-hmi-with-modbus/</link>
		
		<dc:creator><![CDATA[marcoriedi]]></dc:creator>
		<pubDate>Tue, 30 May 2023 07:22:00 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[MICRO]]></category>
		<category><![CDATA[MINI]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://page2023.controllino.com/controllino-hmi-with-modbus/</guid>

					<description><![CDATA[Intro Information: In this tutorial we are using the HMI from Beijer. Controllino&#160;HMIs are industrial HMI panels with high-resolution touch-screens and modern design. The panels combine IP65 corrosion resistant plastic housing with the full version of the iX software, providing an advanced HMI solution for every kind of&#160;applications.Combine&#160;HMI with Controllino and you can create simple as [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Intro</h2>



<p><em>Information: In this tutorial we are using the <a href="https://www.beijerelectronics.com/">HMI from Beijer</a>.</em></p>



<p>Controllino&nbsp;HMIs are industrial HMI panels with high-resolution touch-screens and modern design. The panels combine IP65 corrosion resistant plastic housing with the full version of the iX software, providing an advanced HMI solution for every kind of&nbsp;applications.<br>Combine&nbsp;HMI with Controllino and you can create simple as well as the sophisticated applications in very short time.</p>



<p><strong>IMPORTANT</strong>: Please, select proper target board in&nbsp;<strong>Tools-&gt;Board-&gt;Controllino MINI/MAXI/MEGA</strong>&nbsp;before Upload to your CONTROLLINO.<br>(Please, refer to https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library if you do not see the CONTROLLINOs in the Arduino IDE menu&nbsp;<strong>Tools-&gt;Board</strong>.)</p>



<h2 class="wp-block-heading">MODBUS TCP/IP</h2>



<h3 class="wp-block-heading">Hardware Required</h3>



<ul class="wp-block-list">
<li>Controllino MAXI/MEGA</li>



<li>24V DC Power supply</li>



<li>Controllino HMI</li>



<li>2x Ethernet cable</li>



<li>Router</li>
</ul>



<h3 class="wp-block-heading">Circuit</h3>



<h1 class="wp-block-heading"><a href="https://www.controllino.com/wp-content/uploads/2017/09/Controllino-HMI-TCP-connection.jpg" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" class="alignnone wp-image-2194 size-medium" src="https://www.controllino.com/wp-content/uploads/2017/09/Controllino-HMI-TCP-connection-300x177.jpg" width="300" height="177"></a></h1>



<p>Note*<br>Pin header is working on 5V TTL levels. Voltage levels over 5.5V can damage the Controllino permanently.</p>



<h3 class="wp-block-heading">HMI setup</h3>



<p>To set up the Controllino HMI for communication and application we use the iX Software. iX Software is a revolutionary software that features drivers to communicate with your automation equipment, enhanced HMI functionality, state-of-the-art graphics, an intuitive design environment and a truly open platform for today’s automation market. iX Developer is a licensed application that runs on a Windows PC and is used to program iX operator panels.<br>Here we are going to show&nbsp;some steps on how to set it up properly. If you want to check more information and &nbsp;the iX user manual click&nbsp;<a href="https://beijerinc.com/product/ix/" target="_blank" rel="noopener noreferrer">here</a>.</p>



<p>Download the&nbsp;<a href="https://www.controllino.com/wp-content/uploads/2017/09/Controllino_HMI_Modbus_TCP_IP_and_RTU_iX_example.zip">Controllino HMI – TCP/IP</a>&nbsp;example and run it in the iX software.<br>From the left side of the main screen in the iX example there is the&nbsp;<em>Tags</em>&nbsp;button. Open the&nbsp;<em>Tags&nbsp;</em>to set your application addresses. You can see example of this on the next picture:</p>


<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.controllino.com/wp-content/uploads/2017/09/Tags.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2017/09/Tags.jpg" alt="" class="wp-image-2214"/></a></figure>
</div>


<p>For more information about&nbsp;<em>Tags&nbsp;</em>and addressing of them navigate&nbsp;to&nbsp;<em>Controllers/Settings</em>&nbsp;and click on the help&nbsp;button of the&nbsp;<em>Modbus Master</em>&nbsp;controller.</p>



<p>After that&nbsp;go to the&nbsp;<em>Controllers tab&nbsp;</em>to choose the right controller for communication. When we are using the Controllino device we want to choose&nbsp;<em>MODICON -&gt; Modbus Master</em>&nbsp;controller. In this example it is already done and they are named&nbsp;<em>Modbus_TCP&nbsp;</em>and&nbsp;<em>Modbus_RTU</em>.</p>



<p>Press on&nbsp;the&nbsp;<em>Modbus_TCP&nbsp;</em>controller, activate it and click on the&nbsp;<em>Settings</em>&nbsp;button to&nbsp;do the folowing:</p>


<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.controllino.com/wp-content/uploads/2017/09/Controllino-HMI-TCP-settings.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2017/09/Controllino-HMI-TCP-settings.jpg" alt="" class="wp-image-2216"/></a></figure>
</div>


<p>Set communication mode to the Ethernet TCP/IP and the IP address of the station to your Controllino IP address. To get your Controllino IP address and&nbsp;to ensure that the connections work, run the&nbsp;<strong>ArduinoIDE-&gt;File-&gt;Examples-&gt;Ethernet-&gt;DhcpAddressPrinter</strong>&nbsp;example, upload it and open Serial&nbsp;Monitor. If everything works, you should get your IP address on the screen.</p>



<h3 class="wp-block-heading">Code</h3>



<p>Before uploading the program to the Controllino you have to install the Modbus TCP library. You can download it <a href="https://www.controllino.com/wp-content/uploads/2017/09/Mudbus.zip">here</a>. To install it copy the Modbus folder to your <strong>Arduino->libraries</strong> folder.<br>After getting the IP address of the Controllino the new program has to be uploaded to the device.</p>



<div class="wp-block-kevinbatdorf-code-block-pro" style="font-size:.875rem;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="#include &lt;Controllino.h&gt;
#include &lt;SPI.h&gt;
#include &lt;Ethernet.h&gt;

#include &quot;Mudbus.h&quot;

Mudbus Mb;

int D0 = CONTROLLINO_D0;
int D1 = CONTROLLINO_D1;
int R0 = CONTROLLINO_R0;
int A0_ = CONTROLLINO_A0;


//Function codes 1(read coils), 3(read registers), 5(write coil), 6(write register)
//signed int Mb.R[0 to 125] and bool Mb.C[0 to 128] MB_N_R MB_N_C
//Port 502 (defined in Mudbus.h) MB_PORT

void setup()
{
 uint8_t mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
 uint8_t ip[] = { 192, 168, 0, 103 }; // CHANGE this to the IP address of your CONTROLLINO
 uint8_t gateway[] = { 192, 168, 0, 254 };
 uint8_t subnet[] = { 255, 255, 255, 0 };
 Ethernet.begin(mac, ip, gateway, subnet);

 delay(5000);
 Serial.begin(9600);
 Serial.println(&quot;Started&quot;);
 
 pinMode(D0, OUTPUT); 
 pinMode(D1, INPUT); 
 pinMode(R0, OUTPUT); 
 pinMode(A0_, INPUT); 
}

void loop()
{ 
 
 Mb.Run();

 analogWrite(D0, Mb.R[0]);
 digitalWrite(R0, Mb.R[2]);
 Mb.R[1] = digitalRead(D1); 
 Mb.R[3] = analogRead(A0_); 
 
}" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">include</span><span style="color: #8FBCBB"> </span><span style="color: #ECEFF4">&lt;</span><span style="color: #8FBCBB">Controllino.h</span><span style="color: #ECEFF4">&gt;</span></span>
<span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">include</span><span style="color: #8FBCBB"> </span><span style="color: #ECEFF4">&lt;</span><span style="color: #8FBCBB">SPI.h</span><span style="color: #ECEFF4">&gt;</span></span>
<span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">include</span><span style="color: #8FBCBB"> </span><span style="color: #ECEFF4">&lt;</span><span style="color: #8FBCBB">Ethernet.h</span><span style="color: #ECEFF4">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">include</span><span style="color: #8FBCBB"> </span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">Mudbus.h</span><span style="color: #ECEFF4">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">Mudbus Mb</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> D0 </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_D0</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> D1 </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_D1</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> R0 </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_R0</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> A0_ </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_A0</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">//Function codes 1(read coils), 3(read registers), 5(write coil), 6(write register)</span></span>
<span class="line"><span style="color: #616E88">//signed int Mb.R[0 to 125] and bool Mb.C[0 to 128] MB_N_R MB_N_C</span></span>
<span class="line"><span style="color: #616E88">//Port 502 (defined in Mudbus.h) MB_PORT</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">setup</span><span style="color: #ECEFF4">()</span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">uint8_t</span><span style="color: #D8DEE9FF"> mac</span><span style="color: #81A1C1">[]</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">0x</span><span style="color: #B48EAD">00</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">0x</span><span style="color: #B48EAD">AA</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">0x</span><span style="color: #B48EAD">BB</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">0x</span><span style="color: #B48EAD">CC</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">0x</span><span style="color: #B48EAD">DE</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">0x</span><span style="color: #B48EAD">02</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">}</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">uint8_t</span><span style="color: #D8DEE9FF"> ip</span><span style="color: #81A1C1">[]</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">192</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">168</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">103</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">}</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> // CHANGE this to the IP address of your CONTROLLINO</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">uint8_t</span><span style="color: #D8DEE9FF"> gateway</span><span style="color: #81A1C1">[]</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">192</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">168</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">254</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">}</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">uint8_t</span><span style="color: #D8DEE9FF"> subnet</span><span style="color: #81A1C1">[]</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">255</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">255</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">255</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">}</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Ethernet</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">begin</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">mac</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> ip</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> gateway</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> subnet</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">delay</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">5000</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">begin</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">9600</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">println</span><span style="color: #ECEFF4">(</span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">Started</span><span style="color: #ECEFF4">&quot;</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">D0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> OUTPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">D1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> INPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">R0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> OUTPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">A0_</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> INPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">loop</span><span style="color: #ECEFF4">()</span></span>
<span class="line"><span style="color: #ECEFF4">{</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Mb</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">Run</span><span style="color: #ECEFF4">()</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">analogWrite</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">D0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Mb</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">R</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">])</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">digitalWrite</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">R0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Mb</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">R</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">2</span><span style="color: #ECEFF4">])</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Mb</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">R</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">1</span><span style="color: #ECEFF4">]</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">digitalRead</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">D1</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Mb</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">R</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">3</span><span style="color: #ECEFF4">]</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">analogRead</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">A0_</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>



<h2 class="wp-block-heading">MODBUS&nbsp;RTU VIA RS485</h2>



<h3 class="wp-block-heading">Hardware Required</h3>



<ul class="wp-block-list">
<li>Controllino MAXI/MEGA</li>



<li>24V DC Power supply</li>



<li>Controllino HMI</li>



<li>3 wires or serial port adapter (male)</li>
</ul>



<h3 class="wp-block-heading">Circuit</h3>



<figure class="wp-block-image"><a href="https://www.controllino.com/wp-content/uploads/2017/09/Controllino-HMI-RTU-connection.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2017/09/Controllino-HMI-RTU-connection-300x169.jpg" alt="" class="wp-image-2229"/></a></figure>



<p>Note*<br>Pin header is working on 5V TTL levels. Voltage levels over 5.5V can damage the Controllino permanently.</p>



<h3 class="wp-block-heading">HMI setup</h3>



<p>To set up the Controllino HMI for communication and application we use the iX Software. iX Software is a revolutionary software that features drivers to communicate with your automation equipment, enhanced HMI functionality, state-of-the-art graphics, an intuitive design environment and a truly open platform for today’s automation market. iX Developer is a licensed application that runs on a Windows PC and is used to program iX operator panels.<br>Here we are going to show&nbsp;some steps on how to set it up properly. If you want to check more information and &nbsp;the iX user manual click&nbsp;<a href="https://beijerinc.com/product/ix/" target="_blank" rel="noopener noreferrer">here</a>.</p>



<p>Download the&nbsp;<a href="https://www.controllino.com/wp-content/uploads/2017/09/Controllino_HMI_Modbus_TCP_IP_and_RTU_iX_example.zip">Controllino HMI – RTU</a>&nbsp;example and run it in the iX software.<br>From the left side of the main screen in the iX example there is the&nbsp;<em>Tags</em>&nbsp;button. Open the&nbsp;<em>Tags&nbsp;</em>to set your application addresses. You can see example of this on the next picture:</p>


<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.controllino.com/wp-content/uploads/2017/09/Tags.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2017/09/Tags.jpg" alt="" class="wp-image-2214"/></a></figure>
</div>


<p>For more information about&nbsp;<em>Tags&nbsp;</em>and addressing of them navigate&nbsp;to&nbsp;<em>Controllers/Settings</em>&nbsp;and click on the help&nbsp;button of the&nbsp;<em>Modbus Master</em>&nbsp;controller.</p>



<p>Notice here that the Modbus_RTU tags are starting with “5:”.&nbsp;For communication with other stations than the default station, the station number is given as a prefix to the device. This is stated either as a fixed number or as an index register between I1 and I8. The station number is referring to a specific unit id. (5:40001 addresses holding register 40001 in station 5.) &nbsp;In our case the Controllino is slave device on station 5. We can always define his station in the code that we upload.</p>



<p>After that&nbsp;go to the&nbsp;<em>Controllers tab&nbsp;</em>to choose the right controller for communication. When we are using the Controllino device we want to choose&nbsp;<em>MODICON -&gt; Modbus Master</em>&nbsp;controller. In this example it is already done and they are named&nbsp;<em>Modbus_TCP&nbsp;</em>and&nbsp;<em>Modbus_RTU</em>.</p>



<p>Press on&nbsp;the&nbsp;<em>Modbus_RTU&nbsp;</em>controller, activate it and click on the&nbsp;<em>Settings</em>&nbsp;button to&nbsp;do the folowing steps:</p>



<figure class="wp-block-image"><a href="https://www.controllino.com/wp-content/uploads/2017/09/Controllino-HMI-RTU-settings.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2017/09/Controllino-HMI-RTU-settings.jpg" alt="" class="wp-image-2234"/></a></figure>



<p>Set communication mode to the Serial and the COM2 port of&nbsp;your Controllino HMI.&nbsp;Don’t forget to match the baud rate of&nbsp;Controllino and HMI. Choose the COM2 port to be RS-485.</p>



<h3 class="wp-block-heading">Code</h3>



<p>The Controllino HMI is communicating to the Controllino slave device on the station 5 so we have to set it in the line: <strong><em>define SlaveModbusAdd 5</em></strong></p>



<div class="wp-block-kevinbatdorf-code-block-pro" style="font-size:.875rem;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="#include <Controllino.h&gt; /* Usage of CONTROLLINO library allows you to use CONTROLLINO_xx aliases in your sketch. */
#include &quot;ModbusRtu.h&quot; /* Usage of ModBusRtu library allows you to implement the Modbus RTU protocol in your sketch. */
/*
 CONTROLLINO - Modbus RTU protocol Slave example for MAXI and MEGA, Version 01.00
 
 The sketch is relevant only for CONTROLLINO variants MAXI and MEGA (because of necessity of RS485 interface)!

 This sketch is intended as an example of the communication between devices via RS485 with utilization the 
 ModbusRTU protocol.
 In this example the CONTROLLINO is used as the Modbus slave!
 For more information about the Modbus protocol visit the website: https://modbus.org/
 
 Modbus master device can read Modbus 16bit registers (provided by the slave):
 0 - analog CONTROLLINO_A0 value (0 - 1024)
 1 - digital CONTROLLINO_D0 value (0/1)
 2 - Modbus messages received
 3 - Modbus messages transmitted

 Modbus master device can write Modbus 16bit registers:
 4 - relay CONTROLLINO_R0 (0/1)
 5 - relay CONTROLLINO_R1 (0/1)
 6 - relay CONTROLLINO_R2 (0/1)
 7 - relay CONTROLLINO_R3 (0/1)

 To easily evaluate this example you need a second CONTROLLINO as Modbus master running DemoModbusRTUMaster 
 example sketch.
 Please note that both CONTROLLINOs need 12/24V external supply and you need to interconnect GND, -, + signals 
 of RS485 screw terminal.

 Modbus Master-Slave library for Arduino (ModbusRtu.h) was taken from the website: 
 https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino
 It was necessary to modify setting of the PORTJ for pins DE and RE control. These pins are located at the 
 PORJ and on the pins PIN6(DE) and PIN5(RE).

 IMPORTANT INFORMATION!
 Please, select proper target board in Tools-&gt;Board-&gt;Controllino MAXI/MEGA before Upload to your CONTROLLINO.
 (Please, refer to https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library if you do not see the CONTROLLINOs in 
 the Arduino IDE menu Tools-&gt;Board.)

 Created 30 March 2017
 by David


 (Check https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library for the latest CONTROLLINO related software stuff.)
*/
int D0 = CONTROLLINO_D0;
int D1 = CONTROLLINO_D1;
int R0 = CONTROLLINO_R0;
int A0_ = CONTROLLINO_A0;

// This MACRO defines Modbus slave address.
// For any Modbus slave devices are reserved addresses in the range from 1 to 247.
// Important note only address 0 is reserved for a Modbus master device!

#define SlaveModbusAdd 5

// This MACRO defines number of the comport that is used for RS 485 interface.
// For MAXI and MEGA RS485 is reserved UART Serial3.

#define RS485Serial 3

// The object ControllinoModbuSlave of the class Modbus is initialized with three parameters.
// The first parametr specifies the address of the Modbus slave device.
// The second parameter specifies type of the interface used for communication between devices - in this sketch 
// is used RS485.
// The third parameter can be any number. During the initialization of the object this parameter has no effect.

Modbus ControllinoModbusSlave(SlaveModbusAdd, RS485Serial, 0);

// This uint16 array specified internal registers in the Modbus slave device.
// Each Modbus device has particular internal registers that are available for the Modbus master.
// In this example sketch internal registers are defined as follows:
// (ModbusSlaveRegisters 0 - 3 read only and ModbusSlaveRegisters 4 - 7 write only from the Master perspective):
// ModbusSlaveRegisters[0] - Read an analog value from the CONTROLLINO_A0 - returns value in the range from 0 to 1023.
// ModbusSlaveRegisters[1] - Read an digital value from the CONTROLLINO_D0 - returns only the value 0 or 1.
// ModbusSlaveRegisters[2] - Read the number of incoming messages - Communication diagnostic.
// ModbusSlaveRegisters[3] - Read the number of number of outcoming messages - Communication diagnostic.
// ModbusSlaveRegisters[4] - Sets the Relay output CONTROLLINO_R0 - only the value 0 or 1 is accepted.
// ModbusSlaveRegisters[5] - Sets the Relay output CONTROLLINO_R1 - only the value 0 or 1 is accepted.
// ModbusSlaveRegisters[6] - Sets the Relay output CONTROLLINO_R2 - only the value 0 or 1 is accepted.
// ModbusSlaveRegisters[7] - Sets the Relay output CONTROLLINO_R3 - only the value 0 or 1 is accepted.

uint16_t ModbusSlaveRegisters[8];

// The setup function runs once when you press reset (CONTROLLINO RST button) or connect the CONTROLLINO to the PC
// In the setup function is carried out port setting and initialization of communication of the Modbus slave protocol.

void setup()
{
 delay(5000);
 Serial.begin(9600);
 Serial.println(&quot;Started&quot;);
 
 pinMode(D0, OUTPUT); 
 pinMode(D1, INPUT); 
 pinMode(R0, OUTPUT); 
 pinMode(A0_, INPUT); 

 ControllinoModbusSlave.begin( 19200 ); // Start the communication over the ModbusRTU protocol. Baund rate is set at 19200.
 Serial.begin(9600);
 
}

// The loop function runs over and over again forever
void loop()
{
 // This instance of the class Modbus checks if there are any incoming data.
 // If any frame was received. This instance checks if a received frame is Ok.
 // If the received frame is Ok the instance poll writes or reads corresponding values to the internal registers 
 // (ModbusSlaveRegisters).
 // Main parameters of the instance poll are address of the internal registers and number of internal registers.
 
 ControllinoModbusSlave.poll(ModbusSlaveRegisters, 8);

 // While are not received or sent any data, the Modbus slave device periodically reads the values of analog and 
 // digital outputs.
 // Also it updates the other values of registers.

 analogWrite(D0, ModbusSlaveRegisters[0]);
 digitalWrite(R0, ModbusSlaveRegisters[2]);
 ModbusSlaveRegisters[1] = digitalRead(D1); 
 ModbusSlaveRegisters[3] = analogRead(A0_); 
 
}" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">include</span><span style="color: #8FBCBB"> </span><span style="color: #ECEFF4">&lt;</span><span style="color: #8FBCBB">Controllino.h</span><span style="color: #ECEFF4">&gt;</span><span style="color: #8FBCBB"> </span><span style="color: #616E88">/* Usage of CONTROLLINO library allows you to use CONTROLLINO_xx aliases in your sketch. */</span></span>
<span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">include</span><span style="color: #8FBCBB"> </span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">ModbusRtu.h</span><span style="color: #ECEFF4">&quot;</span><span style="color: #8FBCBB"> </span><span style="color: #616E88">/* Usage of ModBusRtu library allows you to implement the Modbus RTU protocol in your sketch. */</span></span>
<span class="line"><span style="color: #616E88">/*</span></span>
<span class="line"><span style="color: #616E88"> CONTROLLINO - Modbus RTU protocol Slave example for MAXI and MEGA, Version 01.00</span></span>
<span class="line"><span style="color: #616E88"> </span></span>
<span class="line"><span style="color: #616E88"> The sketch is relevant only for CONTROLLINO variants MAXI and MEGA (because of necessity of RS485 interface)!</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> This sketch is intended as an example of the communication between devices via RS485 with utilization the </span></span>
<span class="line"><span style="color: #616E88"> ModbusRTU protocol.</span></span>
<span class="line"><span style="color: #616E88"> In this example the CONTROLLINO is used as the Modbus slave!</span></span>
<span class="line"><span style="color: #616E88"> For more information about the Modbus protocol visit the website: https://modbus.org/</span></span>
<span class="line"><span style="color: #616E88"> </span></span>
<span class="line"><span style="color: #616E88"> Modbus master device can read Modbus 16bit registers (provided by the slave):</span></span>
<span class="line"><span style="color: #616E88"> 0 - analog CONTROLLINO_A0 value (0 - 1024)</span></span>
<span class="line"><span style="color: #616E88"> 1 - digital CONTROLLINO_D0 value (0/1)</span></span>
<span class="line"><span style="color: #616E88"> 2 - Modbus messages received</span></span>
<span class="line"><span style="color: #616E88"> 3 - Modbus messages transmitted</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> Modbus master device can write Modbus 16bit registers:</span></span>
<span class="line"><span style="color: #616E88"> 4 - relay CONTROLLINO_R0 (0/1)</span></span>
<span class="line"><span style="color: #616E88"> 5 - relay CONTROLLINO_R1 (0/1)</span></span>
<span class="line"><span style="color: #616E88"> 6 - relay CONTROLLINO_R2 (0/1)</span></span>
<span class="line"><span style="color: #616E88"> 7 - relay CONTROLLINO_R3 (0/1)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> To easily evaluate this example you need a second CONTROLLINO as Modbus master running DemoModbusRTUMaster </span></span>
<span class="line"><span style="color: #616E88"> example sketch.</span></span>
<span class="line"><span style="color: #616E88"> Please note that both CONTROLLINOs need 12/24V external supply and you need to interconnect GND, -, + signals </span></span>
<span class="line"><span style="color: #616E88"> of RS485 screw terminal.</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> Modbus Master-Slave library for Arduino (ModbusRtu.h) was taken from the website: </span></span>
<span class="line"><span style="color: #616E88"> https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino</span></span>
<span class="line"><span style="color: #616E88"> It was necessary to modify setting of the PORTJ for pins DE and RE control. These pins are located at the </span></span>
<span class="line"><span style="color: #616E88"> PORJ and on the pins PIN6(DE) and PIN5(RE).</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> IMPORTANT INFORMATION!</span></span>
<span class="line"><span style="color: #616E88"> Please, select proper target board in Tools-&gt;Board-&gt;Controllino MAXI/MEGA before Upload to your CONTROLLINO.</span></span>
<span class="line"><span style="color: #616E88"> (Please, refer to https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library if you do not see the CONTROLLINOs in </span></span>
<span class="line"><span style="color: #616E88"> the Arduino IDE menu Tools-&gt;Board.)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> Created 30 March 2017</span></span>
<span class="line"><span style="color: #616E88"> by David</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> (Check https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library for the latest CONTROLLINO related software stuff.)</span></span>
<span class="line"><span style="color: #616E88">*/</span></span>
<span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> D0 </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_D0</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> D1 </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_D1</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> R0 </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_R0</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> A0_ </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_A0</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// This MACRO defines Modbus slave address.</span></span>
<span class="line"><span style="color: #616E88">// For any Modbus slave devices are reserved addresses in the range from 1 to 247.</span></span>
<span class="line"><span style="color: #616E88">// Important note only address 0 is reserved for a Modbus master device!</span></span>
<span class="line"></span>
<span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">define</span><span style="color: #5E81AC"> </span><span style="color: #88C0D0">SlaveModbusAdd</span><span style="color: #5E81AC"> </span><span style="color: #B48EAD">5</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// This MACRO defines number of the comport that is used for RS 485 interface.</span></span>
<span class="line"><span style="color: #616E88">// For MAXI and MEGA RS485 is reserved UART Serial3.</span></span>
<span class="line"></span>
<span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">define</span><span style="color: #5E81AC"> </span><span style="color: #88C0D0">RS485Serial</span><span style="color: #5E81AC"> </span><span style="color: #B48EAD">3</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// The object ControllinoModbuSlave of the class Modbus is initialized with three parameters.</span></span>
<span class="line"><span style="color: #616E88">// The first parametr specifies the address of the Modbus slave device.</span></span>
<span class="line"><span style="color: #616E88">// The second parameter specifies type of the interface used for communication between devices - in this sketch </span></span>
<span class="line"><span style="color: #616E88">// is used RS485.</span></span>
<span class="line"><span style="color: #616E88">// The third parameter can be any number. During the initialization of the object this parameter has no effect.</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF">Modbus </span><span style="color: #88C0D0">ControllinoModbusSlave</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">SlaveModbusAdd</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> RS485Serial</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// This uint16 array specified internal registers in the Modbus slave device.</span></span>
<span class="line"><span style="color: #616E88">// Each Modbus device has particular internal registers that are available for the Modbus master.</span></span>
<span class="line"><span style="color: #616E88">// In this example sketch internal registers are defined as follows:</span></span>
<span class="line"><span style="color: #616E88">// (ModbusSlaveRegisters 0 - 3 read only and ModbusSlaveRegisters 4 - 7 write only from the Master perspective):</span></span>
<span class="line"><span style="color: #616E88">// ModbusSlaveRegisters[0] - Read an analog value from the CONTROLLINO_A0 - returns value in the range from 0 to 1023.</span></span>
<span class="line"><span style="color: #616E88">// ModbusSlaveRegisters[1] - Read an digital value from the CONTROLLINO_D0 - returns only the value 0 or 1.</span></span>
<span class="line"><span style="color: #616E88">// ModbusSlaveRegisters[2] - Read the number of incoming messages - Communication diagnostic.</span></span>
<span class="line"><span style="color: #616E88">// ModbusSlaveRegisters[3] - Read the number of number of outcoming messages - Communication diagnostic.</span></span>
<span class="line"><span style="color: #616E88">// ModbusSlaveRegisters[4] - Sets the Relay output CONTROLLINO_R0 - only the value 0 or 1 is accepted.</span></span>
<span class="line"><span style="color: #616E88">// ModbusSlaveRegisters[5] - Sets the Relay output CONTROLLINO_R1 - only the value 0 or 1 is accepted.</span></span>
<span class="line"><span style="color: #616E88">// ModbusSlaveRegisters[6] - Sets the Relay output CONTROLLINO_R2 - only the value 0 or 1 is accepted.</span></span>
<span class="line"><span style="color: #616E88">// ModbusSlaveRegisters[7] - Sets the Relay output CONTROLLINO_R3 - only the value 0 or 1 is accepted.</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">uint16_t</span><span style="color: #D8DEE9FF"> ModbusSlaveRegisters</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">8</span><span style="color: #ECEFF4">]</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// The setup function runs once when you press reset (CONTROLLINO RST button) or connect the CONTROLLINO to the PC</span></span>
<span class="line"><span style="color: #616E88">// In the setup function is carried out port setting and initialization of communication of the Modbus slave protocol.</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">setup</span><span style="color: #ECEFF4">()</span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">delay</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">5000</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">begin</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">9600</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">println</span><span style="color: #ECEFF4">(</span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">Started</span><span style="color: #ECEFF4">&quot;</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">D0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> OUTPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">D1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> INPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">R0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> OUTPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">A0_</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> INPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">ControllinoModbusSlave</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">begin</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">19200</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> // Start the communication over the ModbusRTU protocol. Baund rate is set at 19200.</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">begin</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">9600</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// The loop function runs over and over again forever</span></span>
<span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">loop</span><span style="color: #ECEFF4">()</span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// This instance of the class Modbus checks if there are any incoming data.</span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// If any frame was received. This instance checks if a received frame is Ok.</span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// If the received frame is Ok the instance poll writes or reads corresponding values to the internal registers </span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// (ModbusSlaveRegisters).</span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// Main parameters of the instance poll are address of the internal registers and number of internal registers.</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">ControllinoModbusSlave</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">poll</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">ModbusSlaveRegisters</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">8</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// While are not received or sent any data, the Modbus slave device periodically reads the values of analog and </span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// digital outputs.</span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// Also it updates the other values of registers.</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">analogWrite</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">D0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> ModbusSlaveRegisters</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">])</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">digitalWrite</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">R0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> ModbusSlaveRegisters</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">2</span><span style="color: #ECEFF4">])</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> ModbusSlaveRegisters</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">1</span><span style="color: #ECEFF4">]</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">digitalRead</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">D1</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> ModbusSlaveRegisters</span><span style="color: #ECEFF4">[</span><span style="color: #B48EAD">3</span><span style="color: #ECEFF4">]</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">analogRead</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">A0_</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Port Manipulation</title>
		<link>https://www.controllino.com/port-manipulation/</link>
		
		<dc:creator><![CDATA[marcoriedi]]></dc:creator>
		<pubDate>Tue, 30 May 2023 07:22:00 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[MEGA]]></category>
		<category><![CDATA[MINI]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://page2023.controllino.com/port-manipulation/</guid>

					<description><![CDATA[Intro More information about port manipulation on this site:&#160;https://www.arduino.cc/en/Reference/PortManipulation Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Controllino PLC.&#160;Each port is controlled by three registers, which are also defined variables in the arduino language: DDR and PORT registers may be both written to, and read. PIN [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Intro</h2>



<p>More information about port manipulation on this site:&nbsp;<a rel="noopener noreferrer" href="https://www.arduino.cc/en/Reference/PortManipulation" target="_blank">https://www.arduino.cc/en/Reference/PortManipulation</a></p>



<p>Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Controllino PLC.&nbsp;Each port is controlled by three registers, which are also defined variables in the arduino language:</p>



<ul class="wp-block-list">
<li>DDR register – determines whether the pin is an INPUT or OUTPUT</li>



<li>PORT register – controls whether the pin is HIGH or LOW</li>



<li>PIN register – reads the state of INPUT pins set to input with&nbsp;<em>pinMode()</em></li>
</ul>



<p>DDR and PORT registers may be both written to, and read. PIN registers correspond to the state of inputs and may only be read.</p>



<h3 class="wp-block-heading">Output Parallelization</h3>



<p>There is the possibility to parallelize some digital outputs to drive loads with the need of more current under the following conditions:</p>



<ul class="wp-block-list">
<li>Outputs are controlled from the same processor port (possibility to set it via one instruction)</li>



<li>There is no delay between control signls for parallelized outputs ( shall be managed by the SW)</li>
</ul>



<h3 class="wp-block-heading">Possible outputs for parallelization</h3>



<p>MINI<br>1st group: D0, D1, D2, D3<br>2nd group: D4, D5<br>3rd group: D6, D7</p>



<p>MAXI:<br>1st group: D0, D1, D3<br>2nd group: D2<br>3rd group: D4, D5, D6, D7<br>4th group: D8, D9, D10, D11</p>



<p>MEGA:<br>1st group: D0, D1, D3<br>2nd group: D2<br>3rd group: D4, D5, D6, D7<br>4th group: D8, D9, D10, D11<br>5th group: D12, D13, D14, D15, D16, D17, D18, D19<br>6th group: D20, D21, D22<br>7th group: D23</p>



<h3 class="wp-block-heading">Controllino PORTS</h3>



<p>In order to see which Controllino pin corresponds to which PORT on microprocessor open the Controllino PINOUT tables.<br>Link to PINOUT table is&nbsp;<a href="https://www.controllino.com/downloads/#datasheets">here</a>.</p>



<p>IMPORTANT INFORMATION!<br>Please, select proper target board in&nbsp;<strong>Tools-&gt;Board-&gt;Controllino MINI/MAXI/MEGA</strong>&nbsp;before Upload to your CONTROLLINO.<br>(Please, refer to https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library if you do not see the CONTROLLINOs in the Arduino IDE menu&nbsp;<strong>Tools-&gt;Board</strong>.)</p>



<h2 class="wp-block-heading">Hardware Required</h2>



<ul class="wp-block-list">
<li>Controllino MINI/MAXI/MEGA</li>



<li>12/24V DC Power supply</li>
</ul>



<h2 class="wp-block-heading">Circuit</h2>



<figure class="wp-block-image"><a href="https://www.controllino.com/wp-content/uploads/2017/07/CONTROLLINO-SPS-PLC-Tutorial-Connection.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2017/07/CONTROLLINO-SPS-PLC-Tutorial-Connection-215x300.jpg" alt="" class="wp-image-1997"/></a></figure>



<p>Note*<br>Pin header is working on 5V TTL levels. Voltage levels over 5.5V can damage the Controllino permanently.</p>



<h2 class="wp-block-heading">Code</h2>



<p>To&nbsp; check where is the Overload LED connected we open the PINOUT table of the Controllino and find it.</p>



<figure class="wp-block-image"><a href="https://www.controllino.com/wp-content/uploads/2017/10/Overload-LED.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2017/10/Overload-LED.jpg" alt="" class="wp-image-2269"/></a></figure>



<p>Here we can see that the OVL LED is connected to the 7th bit of the PORT E on ATmega2560. There is no arduino number for this pin so we cannot set it like other arduino i/o pins.<br>The manipulation of this pin is shown in the next example:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" style="font-size:.875rem;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="void setup() 
{

 //Define the LED as an OUTPUT
 DDRE = DDRE | B10000000;
 
}

void loop() 
{

 //Set the 7th bit of the PORT E to HIGH without influence on other bits (OR logic)
 PORTE = PORTE | B10000000;
 delay(1000);
 //Set the 7th bit of the PORT E to LOW without influence on other bits (AND logic)
 PORTE = PORTE &amp; B01111111;
 delay(1000);
 
}" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">setup</span><span style="color: #ECEFF4">()</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">//Define the LED as an OUTPUT</span></span>
<span class="line"><span style="color: #D8DEE9FF"> DDRE </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> DDRE </span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9FF"> B10000000</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">loop</span><span style="color: #ECEFF4">()</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">//Set the 7th bit of the PORT E to HIGH without influence on other bits (OR logic)</span></span>
<span class="line"><span style="color: #D8DEE9FF"> PORTE </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> PORTE </span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9FF"> B10000000</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">delay</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">1000</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">//Set the 7th bit of the PORT E to LOW without influence on other bits (AND logic)</span></span>
<span class="line"><span style="color: #D8DEE9FF"> PORTE </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> PORTE </span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9FF"> B01111111</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">delay</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">1000</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>



<p>To check the state of the&nbsp;Overload LED:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" style="font-size:.875rem;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="void setup() 
{
 Serial.begin(9600);
 DDRE = DDRE &amp; B01111111; //Set PE7 (OVL pin) as INPUT
 Serial.println(&quot;CONTROLLINO Overload read:&quot;);
}

void loop() 
{
 Serial.print(&quot;Overload signal: &quot;);
 int Overload_signal = PINE &gt;&gt; 7;
 if (Overload_signal == 1) Serial.println(&quot;OFF&quot;);
 else Serial.println(&quot;ON&quot;);
 delay(1000);
}" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">setup</span><span style="color: #ECEFF4">()</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">begin</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">9600</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> DDRE </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> DDRE </span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9FF"> B01111111</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> //Set PE7 (OVL pin) as INPUT</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">println</span><span style="color: #ECEFF4">(</span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">CONTROLLINO Overload read:</span><span style="color: #ECEFF4">&quot;</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">loop</span><span style="color: #ECEFF4">()</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">print</span><span style="color: #ECEFF4">(</span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">Overload signal: </span><span style="color: #ECEFF4">&quot;</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> Overload_signal </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> PINE </span><span style="color: #81A1C1">&gt;&gt;</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">7</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">if</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">Overload_signal </span><span style="color: #81A1C1">==</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1</span><span style="color: #ECEFF4">)</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">println</span><span style="color: #ECEFF4">(</span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">OFF</span><span style="color: #ECEFF4">&quot;</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">else</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">Serial</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">println</span><span style="color: #ECEFF4">(</span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">ON</span><span style="color: #ECEFF4">&quot;</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">delay</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">1000</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Current Outputs (MAXI Automation)</title>
		<link>https://www.controllino.com/current-outputs-maxi-automation/</link>
		
		<dc:creator><![CDATA[marcoriedi]]></dc:creator>
		<pubDate>Tue, 30 May 2023 07:22:00 +0000</pubDate>
				<category><![CDATA[MAXI]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://page2023.controllino.com/current-outputs-maxi-automation/</guid>

					<description><![CDATA[Intro The MAXI Automation is the version of Controllino MAXI specifically tailored for the needs of automation specialists! It is the perfect compromise between compact size and big input and output number. The core competence is its flexibility.In this example the usage of Controllino real analog (0-10V) outputs will be shown.Controllino Maxi Automation has special: [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Intro</h2>



<p>The MAXI Automation is the version of Controllino MAXI specifically tailored for the needs of automation specialists! It is the perfect compromise between compact size and big input and output number. The core competence is its flexibility.<br>In this example the usage of Controllino real analog (0-10V) outputs will be shown.<br>Controllino Maxi Automation has special:</p>



<ul class="wp-block-list">
<li><strong>2x Analog Inputs 0-10V</strong></li>



<li><strong>2x Analog Outputs – 0-10V (0-20mA)</strong></li>
</ul>



<p>If you need two current (0-20mA), and not voltage (0-10V) outputs for your project, you can change&nbsp;them into current outputs by simply removing two 0 Ω resistors on&nbsp;Maxi Automation controll board. This process will be shown in next steps.</p>



<h2 class="wp-block-heading">Hardware Required</h2>



<ul class="wp-block-list">
<li>Controllino MAXI Automation</li>



<li>24V DC Power supply</li>



<li>Soldering iron</li>



<li>Tweezers</li>
</ul>



<h2 class="wp-block-heading">Circuit</h2>



<h1 class="wp-block-heading"><a href="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-Maxi-Automation-connection.jpg" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" class="alignnone wp-image-2299 size-medium" src="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-Maxi-Automation-connection-199x300.jpg" sizes="auto, (max-width: 199px) 100vw, 199px" srcset="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-Maxi-Automation-connection-199x300.jpg 199w, https://www.controllino.com/wp-content/uploads/2018/02/Controllino-Maxi-Automation-connection.jpg 626w" width="199" height="300"></a></h1>



<p>Note*<br>Pin header is working on 5V TTL levels. Voltage levels over 5.5V can damage the Controllino permanently.</p>



<h2 class="wp-block-heading">Code</h2>



<h4 class="wp-block-heading">Controllino&nbsp;MAXI Automation</h4>



<p>To set your real analog outputs for your needs you can use the builtin example from Controllino Library, or you can copy the example from below.</p>



<div class="wp-block-kevinbatdorf-code-block-pro" style="font-size:.875rem;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="#include <Controllino.h&gt; /* Usage of CONTROLLINO library allows you to use CONTROLLINO_xx aliases in your sketch. */

// the setup function runs once when you press reset (CONTROLLINO RST button) or connect the CONTROLLINO to the PC
void setup() {
 // initialize all used digital output pins as outputs
 pinMode(CONTROLLINO_AO0, OUTPUT);
 pinMode(CONTROLLINO_AO1, OUTPUT);                            
}

// the loop function runs over and over again forever
void loop() {
 int analogOut0 = 127;                     // 0 - 255 to be set (0 - 10 000 mV, or 0 - 20 000 uA)
 int analogOut1 = 255;                     // 0 - 255 to be set (0 - 10 000 mV, or 0 - 20 000 uA)
 analogWrite(CONTROLLINO_AO0, analogOut0); // set the analog output 0 to 5V or 10mA
 analogWrite(CONTROLLINO_AO1, analogOut1); // set the analog output 1 to 10V or 20mA                      
}" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #5E81AC; font-weight: bold">#</span><span style="color: #81A1C1">include</span><span style="color: #8FBCBB"> </span><span style="color: #ECEFF4">&lt;</span><span style="color: #8FBCBB">Controllino.h</span><span style="color: #ECEFF4">&gt;</span><span style="color: #8FBCBB"> </span><span style="color: #616E88">/* Usage of CONTROLLINO library allows you to use CONTROLLINO_xx aliases in your sketch. */</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// the setup function runs once when you press reset (CONTROLLINO RST button) or connect the CONTROLLINO to the PC</span></span>
<span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">setup</span><span style="color: #ECEFF4">()</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">// initialize all used digital output pins as outputs</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">CONTROLLINO_AO0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> OUTPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">CONTROLLINO_AO1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> OUTPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF">                            </span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// the loop function runs over and over again forever</span></span>
<span class="line"><span style="color: #81A1C1">void</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">loop</span><span style="color: #ECEFF4">()</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> analogOut0 </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">127</span><span style="color: #81A1C1">;</span><span style="color: #616E88">                     // 0 - 255 to be set (0 - 10 000 mV, or 0 - 20 000 uA)</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> analogOut1 </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">255</span><span style="color: #81A1C1">;</span><span style="color: #616E88">                     // 0 - 255 to be set (0 - 10 000 mV, or 0 - 20 000 uA)</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">analogWrite</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">CONTROLLINO_AO0</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> analogOut0</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> // set the analog output 0 to 5V or 10mA</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">analogWrite</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">CONTROLLINO_AO1</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> analogOut1</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> // set the analog output 1 to 10V or 20mA                      </span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>



<p>If you are not able to compile the sketch, choose the Controllino MAXI Automation board!<br>To make the outputs and relays work, CONTROLLINO pins have to be set up as OUTPUTs!</p>



<div class="wp-block-kevinbatdorf-code-block-pro" style="font-size:.875rem;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="pinMode(CONTROLLINO_xx, OUTPUT);" style="color:#d8dee9ff;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">pinMode</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">CONTROLLINO_xx</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> OUTPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span></code></pre></div>



<h2 class="wp-block-heading">Steps</h2>



<p>In the following steps we will show you how to turn the voltage to the current outputs.</p>



<h3 class="wp-block-heading">Step 1:</h3>



<p>Remove the Controllino&nbsp;MAXI Automation cover by lifting marked sides of the cover with flat-head screwdriver:</p>



<figure class="wp-block-image"><a href="https://www.controllino.com/wp-content/uploads/2018/02/CONTROLLINO-MAXI-Automation-Arduino-SPS-PLC-speicherprogrammierbare-Steuerung-programmable-logic-controller-side-white-1024x1024.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2018/02/CONTROLLINO-MAXI-Automation-Arduino-SPS-PLC-speicherprogrammierbare-Steuerung-programmable-logic-controller-side-white-1024x1024-300x300.jpg" alt="" class="wp-image-2298"/></a></figure>



<h3 class="wp-block-heading">Step&nbsp;2:</h3>



<p>Remove the plastic sides and disconnect the Controllino connection board</p>



<figure class="wp-block-image"><a href="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-MAXI-Automation-control-board.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-MAXI-Automation-control-board-1024x431.jpg" alt="" class="wp-image-2305"/></a></figure>



<p>from the Controllino MAXI Automation.</p>



<h3 class="wp-block-heading">Step 3:</h3>



<p>Locate the two 0 Ω resistors&nbsp;of the Controllino relay board:</p>



<figure class="wp-block-image"><a href="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-MAXI-Automation-control-board-resistors-1.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-MAXI-Automation-control-board-resistors-1-1024x543.jpg" alt="" class="wp-image-2308"/></a></figure>



<h3 class="wp-block-heading">Step 4:</h3>



<p>In order to get the two current outputs (0-20 mA) on Controllino MAXI Automation, apply heat and take the tweezers to remove two&nbsp;0 Ω resistors:</p>



<figure class="wp-block-image"><a href="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-MAXI-Automation-control-board-resistors-location-without.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://www.controllino.com/wp-content/uploads/2018/02/Controllino-MAXI-Automation-control-board-resistors-location-without-300x241.jpg" alt="" class="wp-image-2309"/></a></figure>



<p>To get back the voltage outputs (0-10V), simply solder the resistors back on Controllino MAXI Automation control board.</p>



<p>Note*<br>To test the outputs use previous example or example from the CONTROLLINO library for the Controllino MAXI Automation.<br>0-10 V -&gt; 0-20 mA<br>If you are not able to compile the sketch, choose the Controllino MAXI Automation board!</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
