En este post, te explicamos cómo hacer lo básico para trabajar con las entradas analógicas de los controladores lógicos programables de Industrial Shields. Al leer este post, entenderás cómo conectar y configurar las entradas analógicas de tu
industrial Arduino PLC controller.
We recommend you to read the following blogs in order to understand the program of this blog. We have used the following blog posts to do this example:
How to program our industrial PLC with Arduino IDE: Installing Industrial Shields's boards in the Arduino IDE
Configuring the switches
Most of the analog inputs are always connected to the internal Arduino, but in a few cases, the user can choose between a special peripheral configuration or a GPIO by changing the position of the Dip Switches.
Each switch can select only one configuration. For example, in this case, we are watching the GPIOs configuration of an M-Duino 57R+. If we put the switch to the right position (ON) in the upper one, the input I2.1 will be activated and we will be able to work with this as input. If the switch is in the left position (OFF) we will activate the SCL line which will be used for I2C communication. Keep in mind that each switch has two different configurations: you must select the right (ON) or the left (OFF) option.
I2.1 input enabled - SCL disabled
I2.1 input disabled- SCL enabled
In all of the Industrial Shields Arduino based PLCs, analog inputs can work at:
0V - 10V analog input
Analog inputs have a special draw in the case of the PLC:
0V - 10Vdc Analog input
All the analog inputs are not optoisolated (they use the same GNDs as the PLC). The following image shows how to connect an analog input to the PLC:
0V - 10Vdc Analog input
In order to program the analog GPIOs, we must keep in mind that we can read the values with the following command:
This function returns a value between 0 and 1023 depending on the applied voltage level to the input (0V it is equal to 0, and 10V is equal to 1023).
GPIO is the name of the input. Imagine we want to know the state of the "I0.12" input, then, we must write this line:
We must know that we do not need to configure the analog inputs as analog. Industrial Shields' libraries do all the work for us.
You can see a read analog GPIO example in the following paragraph:
// Analog read example// Set the speed of the serial port
// This example reads the I0_12 and shows via serial the value
// Setup function
}int value = analogRead(I0_12);
// Loop function