<?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>MEGA &#8211; CONTROLLINO</title>
	<atom:link href="https://www.controllino.com/category/tutorials/mega/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>MEGA &#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[admin]]></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>Port Manipulation</title>
		<link>https://www.controllino.com/port-manipulation/</link>
		
		<dc:creator><![CDATA[admin]]></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>Interrupts</title>
		<link>https://www.controllino.com/interrupts/</link>
		
		<dc:creator><![CDATA[admin]]></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/interrupts/</guid>

					<description><![CDATA[Intro Interrupts are useful for automatically executing things in microcontroller programs and can solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder or monitoring user input.The Arduino Uno has 2 and the Mega has 6 external interrupt pins available: On the other hand the pin change interrupts can be enabled [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Intro</h2>



<p>Interrupts are useful for automatically executing things in microcontroller programs and can solve timing problems. Good tasks for using an interrupt may include reading a rotary encoder or monitoring user input.<br>The Arduino Uno has 2 and the Mega has 6 external interrupt pins available:</p>



<ul class="wp-block-list">
<li><b>Arduino Uno/Controllino MINI/INT.x interrupt:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2/IN0/INT.0&nbsp; –&nbsp; 3/IN1/INT.1&nbsp;</b></li>



<li><strong>Arduino Mega/Controllino MAXI,MEGA/INT.x interrupt: 2/D0/INT.0&nbsp; –&nbsp; 3/D1/INT.1&nbsp; –&nbsp; 18/IN0/INT.5&nbsp; –&nbsp; 19/IN1/INT.4&nbsp; –&nbsp; 20/SDA/INT.3&nbsp; –&nbsp; 21/SCL/INT.2</strong></li>
</ul>



<p>On the other hand the pin change interrupts can be enabled on many more pins.</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>



<h1 class="wp-block-heading"><a href="https://www.controllino.com/wp-content/uploads/2017/07/CONTROLLINO-SPS-PLC-Tutorial-Connection-Digital-Relay-Blink.jpg" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" class="alignnone wp-image-1967 size-medium" src="https://www.controllino.com/wp-content/uploads/2017/07/CONTROLLINO-SPS-PLC-Tutorial-Connection-Digital-Relay-Blink-215x300.jpg" sizes="auto, (max-width: 215px) 100vw, 215px" srcset="https://www.controllino.com/wp-content/uploads/2017/07/CONTROLLINO-SPS-PLC-Tutorial-Connection-Digital-Relay-Blink-215x300.jpg 215w, https://www.controllino.com/wp-content/uploads/2017/07/CONTROLLINO-SPS-PLC-Tutorial-Connection-Digital-Relay-Blink.jpg 711w" width="215" 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 MINI/MAXI/MEGA</h4>



<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;

const byte digital_output = CONTROLLINO_D0;
const byte interruptPin = CONTROLLINO_IN1;
volatile byte state = LOW;

void setup() {
 pinMode(digital_output, OUTPUT);
 pinMode(interruptPin, INPUT);
 attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}

void loop() {
 digitalWrite(digital_output, state);
}

void blink() {
 state = !state;
}" 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>
<span class="line"><span style="color: #81A1C1">const</span><span style="color: #D8DEE9FF"> byte digital_output </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">const</span><span style="color: #D8DEE9FF"> byte interruptPin </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> CONTROLLINO_IN1</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #81A1C1">volatile</span><span style="color: #D8DEE9FF"> byte state </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> LOW</span><span style="color: #81A1C1">;</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 style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</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">digital_output</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">interruptPin</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> INPUT</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">attachInterrupt</span><span style="color: #ECEFF4">(</span><span style="color: #88C0D0">digitalPinToInterrupt</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">interruptPin</span><span style="color: #ECEFF4">),</span><span style="color: #D8DEE9FF"> blink</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> CHANGE</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 style="color: #ECEFF4">{</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">digital_output</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> state</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">blink</span><span style="color: #ECEFF4">()</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF"> state </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">!</span><span style="color: #D8DEE9FF">state</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Enable D20-D23 Pins (MEGA)</title>
		<link>https://www.controllino.com/enable-d20-d23-pins-mega/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 30 May 2023 07:22:00 +0000</pubDate>
				<category><![CDATA[MEGA]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://page2023.controllino.com/enable-d20-d23-pins-mega/</guid>

					<description><![CDATA[Intro Controllino MEGA has 24 High Side digital outputs available. The first 20 outputs we can control using the standard Arduino functions (e.g. digitalWrite and analogWrite), but for D20-D23 digital outputs we have to know how to use PORT manipulation on ATmega2560. On the connection picture we can see that there are no Arduino pins [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Intro</h2>



<p>Controllino MEGA has 24 High Side digital outputs available. The first 20 outputs we can control using the standard Arduino functions (e.g. digitalWrite and analogWrite), but for D20-D23 digital outputs we have to know how to use PORT manipulation on ATmega2560. On the connection picture we can see that there are no Arduino pins assigned to these outputs.</p>



<p>To see more about PORT manipulation please click&nbsp;<a href="https://www.controllino.com/tutorials/#1539865917706-5df1b6ab-454e">here</a>.</p>



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



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



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



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



<h1 class="wp-block-heading"><a href="https://www.controllino.com/wp-content/uploads/2018/04/Connection_picture-D20-D23.jpg" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" class="alignnone wp-image-2338 size-full" src="https://www.controllino.com/wp-content/uploads/2018/04/Connection_picture-D20-D23.jpg" sizes="auto, (max-width: 1993px) 100vw, 1993px" srcset="https://www.controllino.com/wp-content/uploads/2018/04/Connection_picture-D20-D23.jpg 1993w, https://www.controllino.com/wp-content/uploads/2018/04/Connection_picture-D20-D23-300x145.jpg 300w, https://www.controllino.com/wp-content/uploads/2018/04/Connection_picture-D20-D23-768x371.jpg 768w, https://www.controllino.com/wp-content/uploads/2018/04/Connection_picture-D20-D23-1024x494.jpg 1024w" width="1993" height="962"></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 MEGA</h4>



<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() 
{
 DDRD = DDRD | B01110000; //Set the ports PD4, PD5, PD6 as outputs
 DDRJ = DDRJ | B00010000; //Set the port PJ4 as output
}

void loop() {
 int del = 100;
 //Digital output 20
 PORTD = PORTD | B00010000; //Set HIGH
 delay(del); 
 PORTD = PORTD &amp; B11101111; //Set LOW
 delay(del);

}


/*
//Digital output 21
 PORTD = PORTD | B00100000;
 delay(del); 
 PORTD = PORTD &amp; B11011111;
 delay(del);


//Digital output 22
 PORTD = PORTD | B01000000;
 delay(del); 
 PORTD = PORTD &amp; B10111111;
 delay(del);
 

//Digital output 23
 PORTD = PORTD | B10000000;
 delay(del); 
 PORTD = PORTD &amp; B01111111;
 
 
 PORTJ = PORTJ | B00010000;
 delay(del); 
 PORTJ = PORTJ &amp; B11101111;
 delay(del);

 
 PORTD = PORTD | B01110000; // sets Digital Outputs 20,21,22 in one shot to HIGH
                            // -&gt; turns the LEDs ON
 PORTJ = PORTJ | B00010000; // sets Digital Output 23 in one shot to HIGH 
                            // -&gt; turns the LED ON


 PORTD = PORTD &amp; B10001111; // sets Digital Outputs 20,21,22 in one shot to LOW 
                            // -&gt; turns the LEDs OFF
 PORTJ = PORTJ &amp; B11101111; // sets Digital Output 23 in one shot to LOW
                            // -&gt; turns the LED OFF
*/" 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"> DDRD </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> DDRD </span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9FF"> B01110000</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> //Set the ports PD4, PD5, PD6 as outputs</span></span>
<span class="line"><span style="color: #D8DEE9FF"> DDRJ </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> DDRJ </span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9FF"> B00010000</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> //Set the port PJ4 as output</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 style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> del </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">100</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #ECEFF4"> </span><span style="color: #616E88">//Digital output 20</span></span>
<span class="line"><span style="color: #D8DEE9FF"> PORTD </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> PORTD </span><span style="color: #81A1C1">|</span><span style="color: #D8DEE9FF"> B00010000</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> //Set HIGH</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">delay</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">del</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span><span style="color: #D8DEE9FF"> </span></span>
<span class="line"><span style="color: #D8DEE9FF"> PORTD </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> PORTD </span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9FF"> B11101111</span><span style="color: #81A1C1">;</span><span style="color: #616E88"> //Set LOW</span></span>
<span class="line"><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">delay</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">del</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>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">/*</span></span>
<span class="line"><span style="color: #616E88">//Digital output 21</span></span>
<span class="line"><span style="color: #616E88"> PORTD = PORTD | B00100000;</span></span>
<span class="line"><span style="color: #616E88"> delay(del); </span></span>
<span class="line"><span style="color: #616E88"> PORTD = PORTD &amp; B11011111;</span></span>
<span class="line"><span style="color: #616E88"> delay(del);</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">//Digital output 22</span></span>
<span class="line"><span style="color: #616E88"> PORTD = PORTD | B01000000;</span></span>
<span class="line"><span style="color: #616E88"> delay(del); </span></span>
<span class="line"><span style="color: #616E88"> PORTD = PORTD &amp; B10111111;</span></span>
<span class="line"><span style="color: #616E88"> delay(del);</span></span>
<span class="line"><span style="color: #616E88"> </span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">//Digital output 23</span></span>
<span class="line"><span style="color: #616E88"> PORTD = PORTD | B10000000;</span></span>
<span class="line"><span style="color: #616E88"> delay(del); </span></span>
<span class="line"><span style="color: #616E88"> PORTD = PORTD &amp; B01111111;</span></span>
<span class="line"><span style="color: #616E88"> </span></span>
<span class="line"><span style="color: #616E88"> </span></span>
<span class="line"><span style="color: #616E88"> PORTJ = PORTJ | B00010000;</span></span>
<span class="line"><span style="color: #616E88"> delay(del); </span></span>
<span class="line"><span style="color: #616E88"> PORTJ = PORTJ &amp; B11101111;</span></span>
<span class="line"><span style="color: #616E88"> delay(del);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> </span></span>
<span class="line"><span style="color: #616E88"> PORTD = PORTD | B01110000; // sets Digital Outputs 20,21,22 in one shot to HIGH</span></span>
<span class="line"><span style="color: #616E88">                            // -&gt; turns the LEDs ON</span></span>
<span class="line"><span style="color: #616E88"> PORTJ = PORTJ | B00010000; // sets Digital Output 23 in one shot to HIGH </span></span>
<span class="line"><span style="color: #616E88">                            // -&gt; turns the LED ON</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88"> PORTD = PORTD &amp; B10001111; // sets Digital Outputs 20,21,22 in one shot to LOW </span></span>
<span class="line"><span style="color: #616E88">                            // -&gt; turns the LEDs OFF</span></span>
<span class="line"><span style="color: #616E88"> PORTJ = PORTJ &amp; B11101111; // sets Digital Output 23 in one shot to LOW</span></span>
<span class="line"><span style="color: #616E88">                            // -&gt; turns the LED OFF</span></span>
<span class="line"><span style="color: #616E88">*/</span></span></code></pre></div>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
